cfb_console.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201
  1. /*
  2. * (C) Copyright 2002 ELTEC Elektronik AG
  3. * Frank Gottschling <fgottschling@eltec.de>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * cfb_console.c
  9. *
  10. * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel.
  11. *
  12. * At the moment only the 8x16 font is tested and the font fore- and
  13. * background color is limited to black/white/gray colors. The Linux
  14. * logo can be placed in the upper left corner and additional board
  15. * information strings (that normally goes to serial port) can be drawn.
  16. *
  17. * The console driver can use a keyboard interface for character input
  18. * but this is deprecated. Only rk51 uses it.
  19. *
  20. * Character output goes to a memory-mapped video
  21. * framebuffer with little or big-endian organisation.
  22. * With environment setting 'console=serial' the console i/o can be
  23. * forced to serial port.
  24. *
  25. * The driver uses graphic specific defines/parameters/functions:
  26. *
  27. * (for SMI LynxE graphic chip)
  28. *
  29. * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian
  30. * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill
  31. * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt
  32. *
  33. * Console Parameters are set by graphic drivers global struct:
  34. *
  35. * VIDEO_VISIBLE_COLS - x resolution
  36. * VIDEO_VISIBLE_ROWS - y resolution
  37. * VIDEO_PIXEL_SIZE - storage size in byte per pixel
  38. * VIDEO_DATA_FORMAT - graphical data format GDF
  39. * VIDEO_FB_ADRS - start of video memory
  40. *
  41. * VIDEO_KBD_INIT_FCT - init function for keyboard
  42. * VIDEO_TSTC_FCT - keyboard_tstc function
  43. * VIDEO_GETC_FCT - keyboard_getc function
  44. *
  45. * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner.
  46. * Use CONFIG_SPLASH_SCREEN_ALIGN with
  47. * environment variable "splashpos" to place
  48. * the logo on other position. In this case
  49. * no CONSOLE_EXTRA_INFO is possible.
  50. * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo
  51. * CONFIG_CONSOLE_EXTRA_INFO - display additional board information
  52. * strings that normaly goes to serial
  53. * port. This define requires a board
  54. * specific function:
  55. * video_drawstring (VIDEO_INFO_X,
  56. * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT,
  57. * info);
  58. * that fills a info buffer at i=row.
  59. * s.a: board/eltec/bab7xx.
  60. *
  61. * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last
  62. * character. No blinking is provided.
  63. * Uses the macros CURSOR_SET and
  64. * CURSOR_OFF.
  65. */
  66. #include <common.h>
  67. #include <fdtdec.h>
  68. #include <version.h>
  69. #include <malloc.h>
  70. #include <video.h>
  71. #include <linux/compiler.h>
  72. /*
  73. * Defines for the CT69000 driver
  74. */
  75. #ifdef CONFIG_VIDEO_CT69000
  76. #define VIDEO_FB_LITTLE_ENDIAN
  77. #define VIDEO_HW_RECTFILL
  78. #define VIDEO_HW_BITBLT
  79. #endif
  80. #if defined(CONFIG_VIDEO_MXS)
  81. #define VIDEO_FB_16BPP_WORD_SWAP
  82. #endif
  83. /*
  84. * Defines for the MB862xx driver
  85. */
  86. #ifdef CONFIG_VIDEO_MB862xx
  87. #ifdef CONFIG_VIDEO_CORALP
  88. #define VIDEO_FB_LITTLE_ENDIAN
  89. #endif
  90. #ifdef CONFIG_VIDEO_MB862xx_ACCEL
  91. #define VIDEO_HW_RECTFILL
  92. #define VIDEO_HW_BITBLT
  93. #endif
  94. #endif
  95. /*
  96. * Defines for the i.MX31 driver (mx3fb.c)
  97. */
  98. #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3)
  99. #define VIDEO_FB_16BPP_WORD_SWAP
  100. #endif
  101. /*
  102. * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc.
  103. */
  104. #include <video_fb.h>
  105. #include <splash.h>
  106. /*
  107. * some Macros
  108. */
  109. #define VIDEO_VISIBLE_COLS (pGD->winSizeX)
  110. #define VIDEO_VISIBLE_ROWS (pGD->winSizeY)
  111. #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP)
  112. #define VIDEO_DATA_FORMAT (pGD->gdfIndex)
  113. #define VIDEO_FB_ADRS (pGD->frameAdrs)
  114. /*
  115. * Console device
  116. */
  117. #include <version.h>
  118. #include <linux/types.h>
  119. #include <stdio_dev.h>
  120. #include <video_font.h>
  121. #if defined(CONFIG_CMD_DATE)
  122. #include <rtc.h>
  123. #endif
  124. #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  125. #include <watchdog.h>
  126. #include <bmp_layout.h>
  127. #include <splash.h>
  128. #endif
  129. #if !defined(CONFIG_VIDEO_SW_CURSOR)
  130. /* no Cursor defined */
  131. #define CURSOR_ON
  132. #define CURSOR_OFF
  133. #define CURSOR_SET
  134. #endif
  135. #if defined(CONFIG_VIDEO_SW_CURSOR)
  136. void console_cursor(int state);
  137. #define CURSOR_ON console_cursor(1)
  138. #define CURSOR_OFF console_cursor(0)
  139. #define CURSOR_SET video_set_cursor()
  140. #endif /* CONFIG_VIDEO_SW_CURSOR */
  141. #ifdef CONFIG_VIDEO_LOGO
  142. #ifdef CONFIG_VIDEO_BMP_LOGO
  143. #include <bmp_logo.h>
  144. #include <bmp_logo_data.h>
  145. #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH
  146. #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT
  147. #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET
  148. #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS
  149. #else /* CONFIG_VIDEO_BMP_LOGO */
  150. #define LINUX_LOGO_WIDTH 80
  151. #define LINUX_LOGO_HEIGHT 80
  152. #define LINUX_LOGO_COLORS 214
  153. #define LINUX_LOGO_LUT_OFFSET 0x20
  154. #define __initdata
  155. #include <linux_logo.h>
  156. #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH
  157. #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT
  158. #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET
  159. #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS
  160. #endif /* CONFIG_VIDEO_BMP_LOGO */
  161. #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH)
  162. #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2)
  163. #else /* CONFIG_VIDEO_LOGO */
  164. #define VIDEO_LOGO_WIDTH 0
  165. #define VIDEO_LOGO_HEIGHT 0
  166. #endif /* CONFIG_VIDEO_LOGO */
  167. #define VIDEO_COLS VIDEO_VISIBLE_COLS
  168. #define VIDEO_ROWS VIDEO_VISIBLE_ROWS
  169. #ifndef VIDEO_LINE_LEN
  170. #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE)
  171. #endif
  172. #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN)
  173. #define VIDEO_BURST_LEN (VIDEO_COLS/8)
  174. #ifdef CONFIG_VIDEO_LOGO
  175. #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT)
  176. #else
  177. #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT)
  178. #endif
  179. #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH)
  180. #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN)
  181. #define CONSOLE_ROW_FIRST (video_console_address)
  182. #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE)
  183. #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE)
  184. #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
  185. /* By default we scroll by a single line */
  186. #ifndef CONFIG_CONSOLE_SCROLL_LINES
  187. #define CONFIG_CONSOLE_SCROLL_LINES 1
  188. #endif
  189. /* Macros */
  190. #ifdef VIDEO_FB_LITTLE_ENDIAN
  191. #define SWAP16(x) ((((x) & 0x00ff) << 8) | \
  192. ((x) >> 8) \
  193. )
  194. #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \
  195. (((x) & 0x0000ff00) << 8) | \
  196. (((x) & 0x00ff0000) >> 8) | \
  197. (((x) & 0xff000000) >> 24) \
  198. )
  199. #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \
  200. (((x) & 0x0000ff00) >> 8) | \
  201. (((x) & 0x00ff0000) << 8) | \
  202. (((x) & 0xff000000) >> 8) \
  203. )
  204. #else
  205. #define SWAP16(x) (x)
  206. #define SWAP32(x) (x)
  207. #if defined(VIDEO_FB_16BPP_WORD_SWAP)
  208. #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16))
  209. #else
  210. #define SHORTSWAP32(x) (x)
  211. #endif
  212. #endif
  213. DECLARE_GLOBAL_DATA_PTR;
  214. /* Locals */
  215. static GraphicDevice *pGD; /* Pointer to Graphic array */
  216. static void *video_fb_address; /* frame buffer address */
  217. static void *video_console_address; /* console buffer start address */
  218. static int video_logo_height = VIDEO_LOGO_HEIGHT;
  219. static int __maybe_unused cursor_state;
  220. static int __maybe_unused old_col;
  221. static int __maybe_unused old_row;
  222. static int console_col; /* cursor col */
  223. static int console_row; /* cursor row */
  224. static u32 eorx, fgx, bgx; /* color pats */
  225. static int cfb_do_flush_cache;
  226. #ifdef CONFIG_CFB_CONSOLE_ANSI
  227. static char ansi_buf[10];
  228. static int ansi_buf_size;
  229. static int ansi_colors_need_revert;
  230. static int ansi_cursor_hidden;
  231. #endif
  232. static const int video_font_draw_table8[] = {
  233. 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff,
  234. 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff,
  235. 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff,
  236. 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff
  237. };
  238. static const int video_font_draw_table15[] = {
  239. 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff
  240. };
  241. static const int video_font_draw_table16[] = {
  242. 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff
  243. };
  244. static const int video_font_draw_table24[16][3] = {
  245. {0x00000000, 0x00000000, 0x00000000},
  246. {0x00000000, 0x00000000, 0x00ffffff},
  247. {0x00000000, 0x0000ffff, 0xff000000},
  248. {0x00000000, 0x0000ffff, 0xffffffff},
  249. {0x000000ff, 0xffff0000, 0x00000000},
  250. {0x000000ff, 0xffff0000, 0x00ffffff},
  251. {0x000000ff, 0xffffffff, 0xff000000},
  252. {0x000000ff, 0xffffffff, 0xffffffff},
  253. {0xffffff00, 0x00000000, 0x00000000},
  254. {0xffffff00, 0x00000000, 0x00ffffff},
  255. {0xffffff00, 0x0000ffff, 0xff000000},
  256. {0xffffff00, 0x0000ffff, 0xffffffff},
  257. {0xffffffff, 0xffff0000, 0x00000000},
  258. {0xffffffff, 0xffff0000, 0x00ffffff},
  259. {0xffffffff, 0xffffffff, 0xff000000},
  260. {0xffffffff, 0xffffffff, 0xffffffff}
  261. };
  262. static const int video_font_draw_table32[16][4] = {
  263. {0x00000000, 0x00000000, 0x00000000, 0x00000000},
  264. {0x00000000, 0x00000000, 0x00000000, 0x00ffffff},
  265. {0x00000000, 0x00000000, 0x00ffffff, 0x00000000},
  266. {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff},
  267. {0x00000000, 0x00ffffff, 0x00000000, 0x00000000},
  268. {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff},
  269. {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000},
  270. {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff},
  271. {0x00ffffff, 0x00000000, 0x00000000, 0x00000000},
  272. {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff},
  273. {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000},
  274. {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff},
  275. {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000},
  276. {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff},
  277. {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000},
  278. {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff}
  279. };
  280. /*
  281. * Implement a weak default function for boards that optionally
  282. * need to skip the cfb initialization.
  283. */
  284. __weak int board_cfb_skip(void)
  285. {
  286. /* As default, don't skip cfb init */
  287. return 0;
  288. }
  289. static void video_drawchars(int xx, int yy, unsigned char *s, int count)
  290. {
  291. u8 *cdat, *dest, *dest0;
  292. int rows, offset, c;
  293. offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE;
  294. dest0 = video_fb_address + offset;
  295. switch (VIDEO_DATA_FORMAT) {
  296. case GDF__8BIT_INDEX:
  297. case GDF__8BIT_332RGB:
  298. while (count--) {
  299. c = *s;
  300. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  301. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  302. rows--; dest += VIDEO_LINE_LEN) {
  303. u8 bits = *cdat++;
  304. ((u32 *) dest)[0] =
  305. (video_font_draw_table8[bits >> 4] &
  306. eorx) ^ bgx;
  307. if (VIDEO_FONT_WIDTH == 4)
  308. continue;
  309. ((u32 *) dest)[1] =
  310. (video_font_draw_table8[bits & 15] &
  311. eorx) ^ bgx;
  312. }
  313. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  314. s++;
  315. }
  316. break;
  317. case GDF_15BIT_555RGB:
  318. while (count--) {
  319. c = *s;
  320. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  321. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  322. rows--; dest += VIDEO_LINE_LEN) {
  323. u8 bits = *cdat++;
  324. ((u32 *) dest)[0] =
  325. SHORTSWAP32((video_font_draw_table15
  326. [bits >> 6] & eorx) ^
  327. bgx);
  328. ((u32 *) dest)[1] =
  329. SHORTSWAP32((video_font_draw_table15
  330. [bits >> 4 & 3] & eorx) ^
  331. bgx);
  332. if (VIDEO_FONT_WIDTH == 4)
  333. continue;
  334. ((u32 *) dest)[2] =
  335. SHORTSWAP32((video_font_draw_table15
  336. [bits >> 2 & 3] & eorx) ^
  337. bgx);
  338. ((u32 *) dest)[3] =
  339. SHORTSWAP32((video_font_draw_table15
  340. [bits & 3] & eorx) ^
  341. bgx);
  342. }
  343. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  344. s++;
  345. }
  346. break;
  347. case GDF_16BIT_565RGB:
  348. while (count--) {
  349. c = *s;
  350. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  351. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  352. rows--; dest += VIDEO_LINE_LEN) {
  353. u8 bits = *cdat++;
  354. ((u32 *) dest)[0] =
  355. SHORTSWAP32((video_font_draw_table16
  356. [bits >> 6] & eorx) ^
  357. bgx);
  358. ((u32 *) dest)[1] =
  359. SHORTSWAP32((video_font_draw_table16
  360. [bits >> 4 & 3] & eorx) ^
  361. bgx);
  362. if (VIDEO_FONT_WIDTH == 4)
  363. continue;
  364. ((u32 *) dest)[2] =
  365. SHORTSWAP32((video_font_draw_table16
  366. [bits >> 2 & 3] & eorx) ^
  367. bgx);
  368. ((u32 *) dest)[3] =
  369. SHORTSWAP32((video_font_draw_table16
  370. [bits & 3] & eorx) ^
  371. bgx);
  372. }
  373. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  374. s++;
  375. }
  376. break;
  377. case GDF_32BIT_X888RGB:
  378. while (count--) {
  379. c = *s;
  380. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  381. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  382. rows--; dest += VIDEO_LINE_LEN) {
  383. u8 bits = *cdat++;
  384. ((u32 *) dest)[0] =
  385. SWAP32((video_font_draw_table32
  386. [bits >> 4][0] & eorx) ^ bgx);
  387. ((u32 *) dest)[1] =
  388. SWAP32((video_font_draw_table32
  389. [bits >> 4][1] & eorx) ^ bgx);
  390. ((u32 *) dest)[2] =
  391. SWAP32((video_font_draw_table32
  392. [bits >> 4][2] & eorx) ^ bgx);
  393. ((u32 *) dest)[3] =
  394. SWAP32((video_font_draw_table32
  395. [bits >> 4][3] & eorx) ^ bgx);
  396. if (VIDEO_FONT_WIDTH == 4)
  397. continue;
  398. ((u32 *) dest)[4] =
  399. SWAP32((video_font_draw_table32
  400. [bits & 15][0] & eorx) ^ bgx);
  401. ((u32 *) dest)[5] =
  402. SWAP32((video_font_draw_table32
  403. [bits & 15][1] & eorx) ^ bgx);
  404. ((u32 *) dest)[6] =
  405. SWAP32((video_font_draw_table32
  406. [bits & 15][2] & eorx) ^ bgx);
  407. ((u32 *) dest)[7] =
  408. SWAP32((video_font_draw_table32
  409. [bits & 15][3] & eorx) ^ bgx);
  410. }
  411. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  412. s++;
  413. }
  414. break;
  415. case GDF_24BIT_888RGB:
  416. while (count--) {
  417. c = *s;
  418. cdat = video_fontdata + c * VIDEO_FONT_HEIGHT;
  419. for (rows = VIDEO_FONT_HEIGHT, dest = dest0;
  420. rows--; dest += VIDEO_LINE_LEN) {
  421. u8 bits = *cdat++;
  422. ((u32 *) dest)[0] =
  423. (video_font_draw_table24[bits >> 4][0]
  424. & eorx) ^ bgx;
  425. ((u32 *) dest)[1] =
  426. (video_font_draw_table24[bits >> 4][1]
  427. & eorx) ^ bgx;
  428. ((u32 *) dest)[2] =
  429. (video_font_draw_table24[bits >> 4][2]
  430. & eorx) ^ bgx;
  431. if (VIDEO_FONT_WIDTH == 4)
  432. continue;
  433. ((u32 *) dest)[3] =
  434. (video_font_draw_table24[bits & 15][0]
  435. & eorx) ^ bgx;
  436. ((u32 *) dest)[4] =
  437. (video_font_draw_table24[bits & 15][1]
  438. & eorx) ^ bgx;
  439. ((u32 *) dest)[5] =
  440. (video_font_draw_table24[bits & 15][2]
  441. & eorx) ^ bgx;
  442. }
  443. dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE;
  444. s++;
  445. }
  446. break;
  447. }
  448. }
  449. static inline void video_drawstring(int xx, int yy, unsigned char *s)
  450. {
  451. video_drawchars(xx, yy, s, strlen((char *) s));
  452. }
  453. static void video_putchar(int xx, int yy, unsigned char c)
  454. {
  455. video_drawchars(xx, yy + video_logo_height, &c, 1);
  456. }
  457. #if defined(CONFIG_VIDEO_SW_CURSOR)
  458. static void video_set_cursor(void)
  459. {
  460. if (cursor_state)
  461. console_cursor(0);
  462. console_cursor(1);
  463. }
  464. static void video_invertchar(int xx, int yy)
  465. {
  466. int firstx = xx * VIDEO_PIXEL_SIZE;
  467. int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE;
  468. int firsty = yy * VIDEO_LINE_LEN;
  469. int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN;
  470. int x, y;
  471. for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) {
  472. for (x = firstx; x < lastx; x++) {
  473. u8 *dest = (u8 *)(video_fb_address) + x + y;
  474. *dest = ~*dest;
  475. }
  476. }
  477. }
  478. void console_cursor(int state)
  479. {
  480. if (cursor_state != state) {
  481. if (cursor_state) {
  482. /* turn off the cursor */
  483. video_invertchar(old_col * VIDEO_FONT_WIDTH,
  484. old_row * VIDEO_FONT_HEIGHT +
  485. video_logo_height);
  486. } else {
  487. /* turn off the cursor and record where it is */
  488. video_invertchar(console_col * VIDEO_FONT_WIDTH,
  489. console_row * VIDEO_FONT_HEIGHT +
  490. video_logo_height);
  491. old_col = console_col;
  492. old_row = console_row;
  493. }
  494. cursor_state = state;
  495. }
  496. if (cfb_do_flush_cache)
  497. flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
  498. }
  499. #endif
  500. #ifndef VIDEO_HW_RECTFILL
  501. static void memsetl(int *p, int c, int v)
  502. {
  503. while (c--)
  504. *(p++) = v;
  505. }
  506. #endif
  507. #ifndef VIDEO_HW_BITBLT
  508. static void memcpyl(int *d, int *s, int c)
  509. {
  510. while (c--)
  511. *(d++) = *(s++);
  512. }
  513. #endif
  514. static void console_clear_line(int line, int begin, int end)
  515. {
  516. #ifdef VIDEO_HW_RECTFILL
  517. video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
  518. VIDEO_FONT_WIDTH * begin, /* dest pos x */
  519. video_logo_height +
  520. VIDEO_FONT_HEIGHT * line, /* dest pos y */
  521. VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */
  522. VIDEO_FONT_HEIGHT, /* frame height */
  523. bgx /* fill color */
  524. );
  525. #else
  526. if (begin == 0 && (end + 1) == CONSOLE_COLS) {
  527. memsetl(CONSOLE_ROW_FIRST +
  528. CONSOLE_ROW_SIZE * line, /* offset of row */
  529. CONSOLE_ROW_SIZE >> 2, /* length of row */
  530. bgx /* fill color */
  531. );
  532. } else {
  533. void *offset;
  534. int i, size;
  535. offset = CONSOLE_ROW_FIRST +
  536. CONSOLE_ROW_SIZE * line + /* offset of row */
  537. VIDEO_FONT_WIDTH *
  538. VIDEO_PIXEL_SIZE * begin; /* offset of col */
  539. size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1);
  540. size >>= 2; /* length to end for memsetl() */
  541. /* fill at col offset of i'th line using bgx as fill color */
  542. for (i = 0; i < VIDEO_FONT_HEIGHT; i++)
  543. memsetl(offset + i * VIDEO_LINE_LEN, size, bgx);
  544. }
  545. #endif
  546. }
  547. static void console_scrollup(void)
  548. {
  549. const int rows = CONFIG_CONSOLE_SCROLL_LINES;
  550. int i;
  551. /* copy up rows ignoring the first one */
  552. #ifdef VIDEO_HW_BITBLT
  553. video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */
  554. 0, /* source pos x */
  555. video_logo_height +
  556. VIDEO_FONT_HEIGHT * rows, /* source pos y */
  557. 0, /* dest pos x */
  558. video_logo_height, /* dest pos y */
  559. VIDEO_VISIBLE_COLS, /* frame width */
  560. VIDEO_VISIBLE_ROWS
  561. - video_logo_height
  562. - VIDEO_FONT_HEIGHT * rows /* frame height */
  563. );
  564. #else
  565. memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE,
  566. (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2);
  567. #endif
  568. /* clear the last one */
  569. for (i = 1; i <= rows; i++)
  570. console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1);
  571. /* Decrement row number */
  572. console_row -= rows;
  573. }
  574. static void console_back(void)
  575. {
  576. console_col--;
  577. if (console_col < 0) {
  578. console_col = CONSOLE_COLS - 1;
  579. console_row--;
  580. if (console_row < 0)
  581. console_row = 0;
  582. }
  583. }
  584. #ifdef CONFIG_CFB_CONSOLE_ANSI
  585. static void console_clear(void)
  586. {
  587. #ifdef VIDEO_HW_RECTFILL
  588. video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
  589. 0, /* dest pos x */
  590. video_logo_height, /* dest pos y */
  591. VIDEO_VISIBLE_COLS, /* frame width */
  592. VIDEO_VISIBLE_ROWS, /* frame height */
  593. bgx /* fill color */
  594. );
  595. #else
  596. memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx);
  597. #endif
  598. }
  599. static void console_cursor_fix(void)
  600. {
  601. if (console_row < 0)
  602. console_row = 0;
  603. if (console_row >= CONSOLE_ROWS)
  604. console_row = CONSOLE_ROWS - 1;
  605. if (console_col < 0)
  606. console_col = 0;
  607. if (console_col >= CONSOLE_COLS)
  608. console_col = CONSOLE_COLS - 1;
  609. }
  610. static void console_cursor_up(int n)
  611. {
  612. console_row -= n;
  613. console_cursor_fix();
  614. }
  615. static void console_cursor_down(int n)
  616. {
  617. console_row += n;
  618. console_cursor_fix();
  619. }
  620. static void console_cursor_left(int n)
  621. {
  622. console_col -= n;
  623. console_cursor_fix();
  624. }
  625. static void console_cursor_right(int n)
  626. {
  627. console_col += n;
  628. console_cursor_fix();
  629. }
  630. static void console_cursor_set_position(int row, int col)
  631. {
  632. if (console_row != -1)
  633. console_row = row;
  634. if (console_col != -1)
  635. console_col = col;
  636. console_cursor_fix();
  637. }
  638. static void console_previousline(int n)
  639. {
  640. /* FIXME: also scroll terminal ? */
  641. console_row -= n;
  642. console_cursor_fix();
  643. }
  644. static void console_swap_colors(void)
  645. {
  646. eorx = fgx;
  647. fgx = bgx;
  648. bgx = eorx;
  649. eorx = fgx ^ bgx;
  650. }
  651. static inline int console_cursor_is_visible(void)
  652. {
  653. return !ansi_cursor_hidden;
  654. }
  655. #else
  656. static inline int console_cursor_is_visible(void)
  657. {
  658. return 1;
  659. }
  660. #endif
  661. static void console_newline(int n)
  662. {
  663. console_row += n;
  664. console_col = 0;
  665. /* Check if we need to scroll the terminal */
  666. if (console_row >= CONSOLE_ROWS) {
  667. /* Scroll everything up */
  668. console_scrollup();
  669. }
  670. }
  671. static void console_cr(void)
  672. {
  673. console_col = 0;
  674. }
  675. static void parse_putc(const char c)
  676. {
  677. static int nl = 1;
  678. if (console_cursor_is_visible())
  679. CURSOR_OFF;
  680. switch (c) {
  681. case 13: /* back to first column */
  682. console_cr();
  683. break;
  684. case '\n': /* next line */
  685. if (console_col || (!console_col && nl))
  686. console_newline(1);
  687. nl = 1;
  688. break;
  689. case 9: /* tab 8 */
  690. console_col |= 0x0008;
  691. console_col &= ~0x0007;
  692. if (console_col >= CONSOLE_COLS)
  693. console_newline(1);
  694. break;
  695. case 8: /* backspace */
  696. console_back();
  697. break;
  698. case 7: /* bell */
  699. break; /* ignored */
  700. default: /* draw the char */
  701. video_putchar(console_col * VIDEO_FONT_WIDTH,
  702. console_row * VIDEO_FONT_HEIGHT, c);
  703. console_col++;
  704. /* check for newline */
  705. if (console_col >= CONSOLE_COLS) {
  706. console_newline(1);
  707. nl = 0;
  708. }
  709. }
  710. if (console_cursor_is_visible())
  711. CURSOR_SET;
  712. }
  713. static void cfb_video_putc(struct stdio_dev *dev, const char c)
  714. {
  715. #ifdef CONFIG_CFB_CONSOLE_ANSI
  716. int i;
  717. if (c == 27) {
  718. for (i = 0; i < ansi_buf_size; ++i)
  719. parse_putc(ansi_buf[i]);
  720. ansi_buf[0] = 27;
  721. ansi_buf_size = 1;
  722. return;
  723. }
  724. if (ansi_buf_size > 0) {
  725. /*
  726. * 0 - ESC
  727. * 1 - [
  728. * 2 - num1
  729. * 3 - ..
  730. * 4 - ;
  731. * 5 - num2
  732. * 6 - ..
  733. * - cchar
  734. */
  735. int next = 0;
  736. int flush = 0;
  737. int fail = 0;
  738. int num1 = 0;
  739. int num2 = 0;
  740. int cchar = 0;
  741. ansi_buf[ansi_buf_size++] = c;
  742. if (ansi_buf_size >= sizeof(ansi_buf))
  743. fail = 1;
  744. for (i = 0; i < ansi_buf_size; ++i) {
  745. if (fail)
  746. break;
  747. switch (next) {
  748. case 0:
  749. if (ansi_buf[i] == 27)
  750. next = 1;
  751. else
  752. fail = 1;
  753. break;
  754. case 1:
  755. if (ansi_buf[i] == '[')
  756. next = 2;
  757. else
  758. fail = 1;
  759. break;
  760. case 2:
  761. if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
  762. num1 = ansi_buf[i]-'0';
  763. next = 3;
  764. } else if (ansi_buf[i] != '?') {
  765. --i;
  766. num1 = 1;
  767. next = 4;
  768. }
  769. break;
  770. case 3:
  771. if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
  772. num1 *= 10;
  773. num1 += ansi_buf[i]-'0';
  774. } else {
  775. --i;
  776. next = 4;
  777. }
  778. break;
  779. case 4:
  780. if (ansi_buf[i] != ';') {
  781. --i;
  782. next = 7;
  783. } else
  784. next = 5;
  785. break;
  786. case 5:
  787. if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
  788. num2 = ansi_buf[i]-'0';
  789. next = 6;
  790. } else
  791. fail = 1;
  792. break;
  793. case 6:
  794. if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') {
  795. num2 *= 10;
  796. num2 += ansi_buf[i]-'0';
  797. } else {
  798. --i;
  799. next = 7;
  800. }
  801. break;
  802. case 7:
  803. if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H')
  804. || ansi_buf[i] == 'J'
  805. || ansi_buf[i] == 'K'
  806. || ansi_buf[i] == 'h'
  807. || ansi_buf[i] == 'l'
  808. || ansi_buf[i] == 'm') {
  809. cchar = ansi_buf[i];
  810. flush = 1;
  811. } else
  812. fail = 1;
  813. break;
  814. }
  815. }
  816. if (fail) {
  817. for (i = 0; i < ansi_buf_size; ++i)
  818. parse_putc(ansi_buf[i]);
  819. ansi_buf_size = 0;
  820. return;
  821. }
  822. if (flush) {
  823. if (!ansi_cursor_hidden)
  824. CURSOR_OFF;
  825. ansi_buf_size = 0;
  826. switch (cchar) {
  827. case 'A':
  828. /* move cursor num1 rows up */
  829. console_cursor_up(num1);
  830. break;
  831. case 'B':
  832. /* move cursor num1 rows down */
  833. console_cursor_down(num1);
  834. break;
  835. case 'C':
  836. /* move cursor num1 columns forward */
  837. console_cursor_right(num1);
  838. break;
  839. case 'D':
  840. /* move cursor num1 columns back */
  841. console_cursor_left(num1);
  842. break;
  843. case 'E':
  844. /* move cursor num1 rows up at begin of row */
  845. console_previousline(num1);
  846. break;
  847. case 'F':
  848. /* move cursor num1 rows down at begin of row */
  849. console_newline(num1);
  850. break;
  851. case 'G':
  852. /* move cursor to column num1 */
  853. console_cursor_set_position(-1, num1-1);
  854. break;
  855. case 'H':
  856. /* move cursor to row num1, column num2 */
  857. console_cursor_set_position(num1-1, num2-1);
  858. break;
  859. case 'J':
  860. /* clear console and move cursor to 0, 0 */
  861. console_clear();
  862. console_cursor_set_position(0, 0);
  863. break;
  864. case 'K':
  865. /* clear line */
  866. if (num1 == 0)
  867. console_clear_line(console_row,
  868. console_col,
  869. CONSOLE_COLS-1);
  870. else if (num1 == 1)
  871. console_clear_line(console_row,
  872. 0, console_col);
  873. else
  874. console_clear_line(console_row,
  875. 0, CONSOLE_COLS-1);
  876. break;
  877. case 'h':
  878. ansi_cursor_hidden = 0;
  879. break;
  880. case 'l':
  881. ansi_cursor_hidden = 1;
  882. break;
  883. case 'm':
  884. if (num1 == 0) { /* reset swapped colors */
  885. if (ansi_colors_need_revert) {
  886. console_swap_colors();
  887. ansi_colors_need_revert = 0;
  888. }
  889. } else if (num1 == 7) { /* once swap colors */
  890. if (!ansi_colors_need_revert) {
  891. console_swap_colors();
  892. ansi_colors_need_revert = 1;
  893. }
  894. }
  895. break;
  896. }
  897. if (!ansi_cursor_hidden)
  898. CURSOR_SET;
  899. }
  900. } else {
  901. parse_putc(c);
  902. }
  903. #else
  904. parse_putc(c);
  905. #endif
  906. if (cfb_do_flush_cache)
  907. flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
  908. }
  909. static void cfb_video_puts(struct stdio_dev *dev, const char *s)
  910. {
  911. int flush = cfb_do_flush_cache;
  912. int count = strlen(s);
  913. /* temporarily disable cache flush */
  914. cfb_do_flush_cache = 0;
  915. while (count--)
  916. cfb_video_putc(dev, *s++);
  917. if (flush) {
  918. cfb_do_flush_cache = flush;
  919. flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
  920. }
  921. }
  922. /*
  923. * Do not enforce drivers (or board code) to provide empty
  924. * video_set_lut() if they do not support 8 bpp format.
  925. * Implement weak default function instead.
  926. */
  927. __weak void video_set_lut(unsigned int index, unsigned char r,
  928. unsigned char g, unsigned char b)
  929. {
  930. }
  931. #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
  932. #define FILL_8BIT_332RGB(r,g,b) { \
  933. *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \
  934. fb ++; \
  935. }
  936. #define FILL_15BIT_555RGB(r,g,b) { \
  937. *(unsigned short *)fb = \
  938. SWAP16((unsigned short)(((r>>3)<<10) | \
  939. ((g>>3)<<5) | \
  940. (b>>3))); \
  941. fb += 2; \
  942. }
  943. #define FILL_16BIT_565RGB(r,g,b) { \
  944. *(unsigned short *)fb = \
  945. SWAP16((unsigned short)((((r)>>3)<<11)| \
  946. (((g)>>2)<<5) | \
  947. ((b)>>3))); \
  948. fb += 2; \
  949. }
  950. #define FILL_32BIT_X888RGB(r,g,b) { \
  951. *(unsigned long *)fb = \
  952. SWAP32((unsigned long)(((r<<16) | \
  953. (g<<8) | \
  954. b))); \
  955. fb += 4; \
  956. }
  957. #ifdef VIDEO_FB_LITTLE_ENDIAN
  958. #define FILL_24BIT_888RGB(r,g,b) { \
  959. fb[0] = b; \
  960. fb[1] = g; \
  961. fb[2] = r; \
  962. fb += 3; \
  963. }
  964. #else
  965. #define FILL_24BIT_888RGB(r,g,b) { \
  966. fb[0] = r; \
  967. fb[1] = g; \
  968. fb[2] = b; \
  969. fb += 3; \
  970. }
  971. #endif
  972. #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
  973. static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b)
  974. {
  975. ushort *dst = (ushort *) fb;
  976. ushort color = (ushort) (((r >> 3) << 10) |
  977. ((g >> 3) << 5) |
  978. (b >> 3));
  979. if (x & 1)
  980. *(--dst) = color;
  981. else
  982. *(++dst) = color;
  983. }
  984. #endif
  985. /*
  986. * RLE8 bitmap support
  987. */
  988. #ifdef CONFIG_VIDEO_BMP_RLE8
  989. /* Pre-calculated color table entry */
  990. struct palette {
  991. union {
  992. unsigned short w; /* word */
  993. unsigned int dw; /* double word */
  994. } ce; /* color entry */
  995. };
  996. /*
  997. * Helper to draw encoded/unencoded run.
  998. */
  999. static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
  1000. int cnt, int enc)
  1001. {
  1002. ulong addr = (ulong) *fb;
  1003. int *off;
  1004. int enc_off = 1;
  1005. int i;
  1006. /*
  1007. * Setup offset of the color index in the bitmap.
  1008. * Color index of encoded run is at offset 1.
  1009. */
  1010. off = enc ? &enc_off : &i;
  1011. switch (VIDEO_DATA_FORMAT) {
  1012. case GDF__8BIT_INDEX:
  1013. for (i = 0; i < cnt; i++)
  1014. *(unsigned char *) addr++ = bm[*off];
  1015. break;
  1016. case GDF_15BIT_555RGB:
  1017. case GDF_16BIT_565RGB:
  1018. /* differences handled while pre-calculating palette */
  1019. for (i = 0; i < cnt; i++) {
  1020. *(unsigned short *) addr = p[bm[*off]].ce.w;
  1021. addr += 2;
  1022. }
  1023. break;
  1024. case GDF_32BIT_X888RGB:
  1025. for (i = 0; i < cnt; i++) {
  1026. *(unsigned long *) addr = p[bm[*off]].ce.dw;
  1027. addr += 4;
  1028. }
  1029. break;
  1030. }
  1031. *fb = (uchar *) addr; /* return modified address */
  1032. }
  1033. static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff,
  1034. int width, int height)
  1035. {
  1036. unsigned char *bm;
  1037. unsigned char *fbp;
  1038. unsigned int cnt, runlen;
  1039. int decode = 1;
  1040. int x, y, bpp, i, ncolors;
  1041. struct palette p[256];
  1042. struct bmp_color_table_entry cte;
  1043. int green_shift, red_off;
  1044. int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS;
  1045. int pixels = 0;
  1046. x = 0;
  1047. y = __le32_to_cpu(img->header.height) - 1;
  1048. ncolors = __le32_to_cpu(img->header.colors_used);
  1049. bpp = VIDEO_PIXEL_SIZE;
  1050. fbp = (unsigned char *) ((unsigned int) video_fb_address +
  1051. (y + yoff) * VIDEO_LINE_LEN +
  1052. xoff * bpp);
  1053. bm = (uchar *) img + __le32_to_cpu(img->header.data_offset);
  1054. /* pre-calculate and setup palette */
  1055. switch (VIDEO_DATA_FORMAT) {
  1056. case GDF__8BIT_INDEX:
  1057. for (i = 0; i < ncolors; i++) {
  1058. cte = img->color_table[i];
  1059. video_set_lut(i, cte.red, cte.green, cte.blue);
  1060. }
  1061. break;
  1062. case GDF_15BIT_555RGB:
  1063. case GDF_16BIT_565RGB:
  1064. if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) {
  1065. green_shift = 3;
  1066. red_off = 10;
  1067. } else {
  1068. green_shift = 2;
  1069. red_off = 11;
  1070. }
  1071. for (i = 0; i < ncolors; i++) {
  1072. cte = img->color_table[i];
  1073. p[i].ce.w = SWAP16((unsigned short)
  1074. (((cte.red >> 3) << red_off) |
  1075. ((cte.green >> green_shift) << 5) |
  1076. cte.blue >> 3));
  1077. }
  1078. break;
  1079. case GDF_32BIT_X888RGB:
  1080. for (i = 0; i < ncolors; i++) {
  1081. cte = img->color_table[i];
  1082. p[i].ce.dw = SWAP32((cte.red << 16) |
  1083. (cte.green << 8) |
  1084. cte.blue);
  1085. }
  1086. break;
  1087. default:
  1088. printf("RLE Bitmap unsupported in video mode 0x%x\n",
  1089. VIDEO_DATA_FORMAT);
  1090. return -1;
  1091. }
  1092. while (decode) {
  1093. switch (bm[0]) {
  1094. case 0:
  1095. switch (bm[1]) {
  1096. case 0:
  1097. /* scan line end marker */
  1098. bm += 2;
  1099. x = 0;
  1100. y--;
  1101. fbp = (unsigned char *)
  1102. ((unsigned int) video_fb_address +
  1103. (y + yoff) * VIDEO_LINE_LEN +
  1104. xoff * bpp);
  1105. continue;
  1106. case 1:
  1107. /* end of bitmap data marker */
  1108. decode = 0;
  1109. break;
  1110. case 2:
  1111. /* run offset marker */
  1112. x += bm[2];
  1113. y -= bm[3];
  1114. fbp = (unsigned char *)
  1115. ((unsigned int) video_fb_address +
  1116. (y + yoff) * VIDEO_LINE_LEN +
  1117. xoff * bpp);
  1118. bm += 4;
  1119. break;
  1120. default:
  1121. /* unencoded run */
  1122. cnt = bm[1];
  1123. runlen = cnt;
  1124. pixels += cnt;
  1125. if (pixels > limit)
  1126. goto error;
  1127. bm += 2;
  1128. if (y < height) {
  1129. if (x >= width) {
  1130. x += runlen;
  1131. goto next_run;
  1132. }
  1133. if (x + runlen > width)
  1134. cnt = width - x;
  1135. draw_bitmap(&fbp, bm, p, cnt, 0);
  1136. x += runlen;
  1137. }
  1138. next_run:
  1139. bm += runlen;
  1140. if (runlen & 1)
  1141. bm++; /* 0 padding if length is odd */
  1142. }
  1143. break;
  1144. default:
  1145. /* encoded run */
  1146. cnt = bm[0];
  1147. runlen = cnt;
  1148. pixels += cnt;
  1149. if (pixels > limit)
  1150. goto error;
  1151. if (y < height) { /* only draw into visible area */
  1152. if (x >= width) {
  1153. x += runlen;
  1154. bm += 2;
  1155. continue;
  1156. }
  1157. if (x + runlen > width)
  1158. cnt = width - x;
  1159. draw_bitmap(&fbp, bm, p, cnt, 1);
  1160. x += runlen;
  1161. }
  1162. bm += 2;
  1163. break;
  1164. }
  1165. }
  1166. return 0;
  1167. error:
  1168. printf("Error: Too much encoded pixel data, validate your bitmap\n");
  1169. return -1;
  1170. }
  1171. #endif
  1172. /*
  1173. * Display the BMP file located at address bmp_image.
  1174. */
  1175. int video_display_bitmap(ulong bmp_image, int x, int y)
  1176. {
  1177. ushort xcount, ycount;
  1178. uchar *fb;
  1179. struct bmp_image *bmp = (struct bmp_image *)bmp_image;
  1180. uchar *bmap;
  1181. ushort padded_line;
  1182. unsigned long width, height, bpp;
  1183. unsigned colors;
  1184. unsigned long compression;
  1185. struct bmp_color_table_entry cte;
  1186. #ifdef CONFIG_VIDEO_BMP_GZIP
  1187. unsigned char *dst = NULL;
  1188. ulong len;
  1189. #endif
  1190. WATCHDOG_RESET();
  1191. if (!((bmp->header.signature[0] == 'B') &&
  1192. (bmp->header.signature[1] == 'M'))) {
  1193. #ifdef CONFIG_VIDEO_BMP_GZIP
  1194. /*
  1195. * Could be a gzipped bmp image, try to decrompress...
  1196. */
  1197. len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE;
  1198. dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE);
  1199. if (dst == NULL) {
  1200. printf("Error: malloc in gunzip failed!\n");
  1201. return 1;
  1202. }
  1203. /*
  1204. * NB: we need to force offset of +2
  1205. * See doc/README.displaying-bmps
  1206. */
  1207. if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2,
  1208. (uchar *) bmp_image,
  1209. &len) != 0) {
  1210. printf("Error: no valid bmp or bmp.gz image at %lx\n",
  1211. bmp_image);
  1212. free(dst);
  1213. return 1;
  1214. }
  1215. if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) {
  1216. printf("Image could be truncated "
  1217. "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n");
  1218. }
  1219. /*
  1220. * Set addr to decompressed image
  1221. */
  1222. bmp = (struct bmp_image *)(dst+2);
  1223. if (!((bmp->header.signature[0] == 'B') &&
  1224. (bmp->header.signature[1] == 'M'))) {
  1225. printf("Error: no valid bmp.gz image at %lx\n",
  1226. bmp_image);
  1227. free(dst);
  1228. return 1;
  1229. }
  1230. #else
  1231. printf("Error: no valid bmp image at %lx\n", bmp_image);
  1232. return 1;
  1233. #endif /* CONFIG_VIDEO_BMP_GZIP */
  1234. }
  1235. width = le32_to_cpu(bmp->header.width);
  1236. height = le32_to_cpu(bmp->header.height);
  1237. bpp = le16_to_cpu(bmp->header.bit_count);
  1238. colors = le32_to_cpu(bmp->header.colors_used);
  1239. compression = le32_to_cpu(bmp->header.compression);
  1240. debug("Display-bmp: %ld x %ld with %d colors\n",
  1241. width, height, colors);
  1242. if (compression != BMP_BI_RGB
  1243. #ifdef CONFIG_VIDEO_BMP_RLE8
  1244. && compression != BMP_BI_RLE8
  1245. #endif
  1246. ) {
  1247. printf("Error: compression type %ld not supported\n",
  1248. compression);
  1249. #ifdef CONFIG_VIDEO_BMP_GZIP
  1250. if (dst)
  1251. free(dst);
  1252. #endif
  1253. return 1;
  1254. }
  1255. padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3;
  1256. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  1257. if (x == BMP_ALIGN_CENTER)
  1258. x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2);
  1259. else if (x < 0)
  1260. x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1));
  1261. if (y == BMP_ALIGN_CENTER)
  1262. y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2);
  1263. else if (y < 0)
  1264. y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1));
  1265. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  1266. /*
  1267. * Just ignore elements which are completely beyond screen
  1268. * dimensions.
  1269. */
  1270. if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS))
  1271. return 0;
  1272. if ((x + width) > VIDEO_VISIBLE_COLS)
  1273. width = VIDEO_VISIBLE_COLS - x;
  1274. if ((y + height) > VIDEO_VISIBLE_ROWS)
  1275. height = VIDEO_VISIBLE_ROWS - y;
  1276. bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
  1277. fb = (uchar *) (video_fb_address +
  1278. ((y + height - 1) * VIDEO_LINE_LEN) +
  1279. x * VIDEO_PIXEL_SIZE);
  1280. #ifdef CONFIG_VIDEO_BMP_RLE8
  1281. if (compression == BMP_BI_RLE8) {
  1282. return display_rle8_bitmap(bmp, x, y, width, height);
  1283. }
  1284. #endif
  1285. /* We handle only 4, 8, or 24 bpp bitmaps */
  1286. switch (le16_to_cpu(bmp->header.bit_count)) {
  1287. case 4:
  1288. padded_line -= width / 2;
  1289. ycount = height;
  1290. switch (VIDEO_DATA_FORMAT) {
  1291. case GDF_32BIT_X888RGB:
  1292. while (ycount--) {
  1293. WATCHDOG_RESET();
  1294. /*
  1295. * Don't assume that 'width' is an
  1296. * even number
  1297. */
  1298. for (xcount = 0; xcount < width; xcount++) {
  1299. uchar idx;
  1300. if (xcount & 1) {
  1301. idx = *bmap & 0xF;
  1302. bmap++;
  1303. } else
  1304. idx = *bmap >> 4;
  1305. cte = bmp->color_table[idx];
  1306. FILL_32BIT_X888RGB(cte.red, cte.green,
  1307. cte.blue);
  1308. }
  1309. bmap += padded_line;
  1310. fb -= VIDEO_LINE_LEN + width *
  1311. VIDEO_PIXEL_SIZE;
  1312. }
  1313. break;
  1314. default:
  1315. puts("4bpp bitmap unsupported with current "
  1316. "video mode\n");
  1317. break;
  1318. }
  1319. break;
  1320. case 8:
  1321. padded_line -= width;
  1322. if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
  1323. /* Copy colormap */
  1324. for (xcount = 0; xcount < colors; ++xcount) {
  1325. cte = bmp->color_table[xcount];
  1326. video_set_lut(xcount, cte.red, cte.green,
  1327. cte.blue);
  1328. }
  1329. }
  1330. ycount = height;
  1331. switch (VIDEO_DATA_FORMAT) {
  1332. case GDF__8BIT_INDEX:
  1333. while (ycount--) {
  1334. WATCHDOG_RESET();
  1335. xcount = width;
  1336. while (xcount--) {
  1337. *fb++ = *bmap++;
  1338. }
  1339. bmap += padded_line;
  1340. fb -= VIDEO_LINE_LEN + width *
  1341. VIDEO_PIXEL_SIZE;
  1342. }
  1343. break;
  1344. case GDF__8BIT_332RGB:
  1345. while (ycount--) {
  1346. WATCHDOG_RESET();
  1347. xcount = width;
  1348. while (xcount--) {
  1349. cte = bmp->color_table[*bmap++];
  1350. FILL_8BIT_332RGB(cte.red, cte.green,
  1351. cte.blue);
  1352. }
  1353. bmap += padded_line;
  1354. fb -= VIDEO_LINE_LEN + width *
  1355. VIDEO_PIXEL_SIZE;
  1356. }
  1357. break;
  1358. case GDF_15BIT_555RGB:
  1359. while (ycount--) {
  1360. #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
  1361. int xpos = x;
  1362. #endif
  1363. WATCHDOG_RESET();
  1364. xcount = width;
  1365. while (xcount--) {
  1366. cte = bmp->color_table[*bmap++];
  1367. #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
  1368. fill_555rgb_pswap(fb, xpos++, cte.red,
  1369. cte.green,
  1370. cte.blue);
  1371. fb += 2;
  1372. #else
  1373. FILL_15BIT_555RGB(cte.red, cte.green,
  1374. cte.blue);
  1375. #endif
  1376. }
  1377. bmap += padded_line;
  1378. fb -= VIDEO_LINE_LEN + width *
  1379. VIDEO_PIXEL_SIZE;
  1380. }
  1381. break;
  1382. case GDF_16BIT_565RGB:
  1383. while (ycount--) {
  1384. WATCHDOG_RESET();
  1385. xcount = width;
  1386. while (xcount--) {
  1387. cte = bmp->color_table[*bmap++];
  1388. FILL_16BIT_565RGB(cte.red, cte.green,
  1389. cte.blue);
  1390. }
  1391. bmap += padded_line;
  1392. fb -= VIDEO_LINE_LEN + width *
  1393. VIDEO_PIXEL_SIZE;
  1394. }
  1395. break;
  1396. case GDF_32BIT_X888RGB:
  1397. while (ycount--) {
  1398. WATCHDOG_RESET();
  1399. xcount = width;
  1400. while (xcount--) {
  1401. cte = bmp->color_table[*bmap++];
  1402. FILL_32BIT_X888RGB(cte.red, cte.green,
  1403. cte.blue);
  1404. }
  1405. bmap += padded_line;
  1406. fb -= VIDEO_LINE_LEN + width *
  1407. VIDEO_PIXEL_SIZE;
  1408. }
  1409. break;
  1410. case GDF_24BIT_888RGB:
  1411. while (ycount--) {
  1412. WATCHDOG_RESET();
  1413. xcount = width;
  1414. while (xcount--) {
  1415. cte = bmp->color_table[*bmap++];
  1416. FILL_24BIT_888RGB(cte.red, cte.green,
  1417. cte.blue);
  1418. }
  1419. bmap += padded_line;
  1420. fb -= VIDEO_LINE_LEN + width *
  1421. VIDEO_PIXEL_SIZE;
  1422. }
  1423. break;
  1424. }
  1425. break;
  1426. case 24:
  1427. padded_line -= 3 * width;
  1428. ycount = height;
  1429. switch (VIDEO_DATA_FORMAT) {
  1430. case GDF__8BIT_332RGB:
  1431. while (ycount--) {
  1432. WATCHDOG_RESET();
  1433. xcount = width;
  1434. while (xcount--) {
  1435. FILL_8BIT_332RGB(bmap[2], bmap[1],
  1436. bmap[0]);
  1437. bmap += 3;
  1438. }
  1439. bmap += padded_line;
  1440. fb -= VIDEO_LINE_LEN + width *
  1441. VIDEO_PIXEL_SIZE;
  1442. }
  1443. break;
  1444. case GDF_15BIT_555RGB:
  1445. while (ycount--) {
  1446. #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
  1447. int xpos = x;
  1448. #endif
  1449. WATCHDOG_RESET();
  1450. xcount = width;
  1451. while (xcount--) {
  1452. #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
  1453. fill_555rgb_pswap(fb, xpos++, bmap[2],
  1454. bmap[1], bmap[0]);
  1455. fb += 2;
  1456. #else
  1457. FILL_15BIT_555RGB(bmap[2], bmap[1],
  1458. bmap[0]);
  1459. #endif
  1460. bmap += 3;
  1461. }
  1462. bmap += padded_line;
  1463. fb -= VIDEO_LINE_LEN + width *
  1464. VIDEO_PIXEL_SIZE;
  1465. }
  1466. break;
  1467. case GDF_16BIT_565RGB:
  1468. while (ycount--) {
  1469. WATCHDOG_RESET();
  1470. xcount = width;
  1471. while (xcount--) {
  1472. FILL_16BIT_565RGB(bmap[2], bmap[1],
  1473. bmap[0]);
  1474. bmap += 3;
  1475. }
  1476. bmap += padded_line;
  1477. fb -= VIDEO_LINE_LEN + width *
  1478. VIDEO_PIXEL_SIZE;
  1479. }
  1480. break;
  1481. case GDF_32BIT_X888RGB:
  1482. while (ycount--) {
  1483. WATCHDOG_RESET();
  1484. xcount = width;
  1485. while (xcount--) {
  1486. FILL_32BIT_X888RGB(bmap[2], bmap[1],
  1487. bmap[0]);
  1488. bmap += 3;
  1489. }
  1490. bmap += padded_line;
  1491. fb -= VIDEO_LINE_LEN + width *
  1492. VIDEO_PIXEL_SIZE;
  1493. }
  1494. break;
  1495. case GDF_24BIT_888RGB:
  1496. while (ycount--) {
  1497. WATCHDOG_RESET();
  1498. xcount = width;
  1499. while (xcount--) {
  1500. FILL_24BIT_888RGB(bmap[2], bmap[1],
  1501. bmap[0]);
  1502. bmap += 3;
  1503. }
  1504. bmap += padded_line;
  1505. fb -= VIDEO_LINE_LEN + width *
  1506. VIDEO_PIXEL_SIZE;
  1507. }
  1508. break;
  1509. default:
  1510. printf("Error: 24 bits/pixel bitmap incompatible "
  1511. "with current video mode\n");
  1512. break;
  1513. }
  1514. break;
  1515. default:
  1516. printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n",
  1517. le16_to_cpu(bmp->header.bit_count));
  1518. break;
  1519. }
  1520. #ifdef CONFIG_VIDEO_BMP_GZIP
  1521. if (dst) {
  1522. free(dst);
  1523. }
  1524. #endif
  1525. if (cfb_do_flush_cache)
  1526. flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
  1527. return (0);
  1528. }
  1529. #endif
  1530. #ifdef CONFIG_VIDEO_LOGO
  1531. static int video_logo_xpos;
  1532. static int video_logo_ypos;
  1533. static void plot_logo_or_black(void *screen, int x, int y, int black);
  1534. static void logo_plot(void *screen, int x, int y)
  1535. {
  1536. plot_logo_or_black(screen, x, y, 0);
  1537. }
  1538. static void logo_black(void)
  1539. {
  1540. plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos,
  1541. 1);
  1542. }
  1543. static int do_clrlogo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  1544. {
  1545. if (argc != 1)
  1546. return cmd_usage(cmdtp);
  1547. logo_black();
  1548. return 0;
  1549. }
  1550. U_BOOT_CMD(
  1551. clrlogo, 1, 0, do_clrlogo,
  1552. "fill the boot logo area with black",
  1553. " "
  1554. );
  1555. static void plot_logo_or_black(void *screen, int x, int y, int black)
  1556. {
  1557. int xcount, i;
  1558. int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE;
  1559. int ycount = video_logo_height;
  1560. unsigned char r, g, b, *logo_red, *logo_blue, *logo_green;
  1561. unsigned char *source;
  1562. unsigned char *dest;
  1563. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  1564. if (x == BMP_ALIGN_CENTER)
  1565. x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2);
  1566. else if (x < 0)
  1567. x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1));
  1568. if (y == BMP_ALIGN_CENTER)
  1569. y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2);
  1570. else if (y < 0)
  1571. y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1));
  1572. #endif /* CONFIG_SPLASH_SCREEN_ALIGN */
  1573. dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE;
  1574. #ifdef CONFIG_VIDEO_BMP_LOGO
  1575. source = bmp_logo_bitmap;
  1576. /* Allocate temporary space for computing colormap */
  1577. logo_red = malloc(BMP_LOGO_COLORS);
  1578. logo_green = malloc(BMP_LOGO_COLORS);
  1579. logo_blue = malloc(BMP_LOGO_COLORS);
  1580. /* Compute color map */
  1581. for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
  1582. logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4;
  1583. logo_green[i] = (bmp_logo_palette[i] & 0x00f0);
  1584. logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4;
  1585. }
  1586. #else
  1587. source = linux_logo;
  1588. logo_red = linux_logo_red;
  1589. logo_green = linux_logo_green;
  1590. logo_blue = linux_logo_blue;
  1591. #endif
  1592. if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) {
  1593. for (i = 0; i < VIDEO_LOGO_COLORS; i++) {
  1594. video_set_lut(i + VIDEO_LOGO_LUT_OFFSET,
  1595. logo_red[i], logo_green[i],
  1596. logo_blue[i]);
  1597. }
  1598. }
  1599. while (ycount--) {
  1600. #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
  1601. int xpos = x;
  1602. #endif
  1603. xcount = VIDEO_LOGO_WIDTH;
  1604. while (xcount--) {
  1605. if (black) {
  1606. r = 0x00;
  1607. g = 0x00;
  1608. b = 0x00;
  1609. } else {
  1610. r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET];
  1611. g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET];
  1612. b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET];
  1613. }
  1614. switch (VIDEO_DATA_FORMAT) {
  1615. case GDF__8BIT_INDEX:
  1616. *dest = *source;
  1617. break;
  1618. case GDF__8BIT_332RGB:
  1619. *dest = ((r >> 5) << 5) |
  1620. ((g >> 5) << 2) |
  1621. (b >> 6);
  1622. break;
  1623. case GDF_15BIT_555RGB:
  1624. #if defined(VIDEO_FB_16BPP_PIXEL_SWAP)
  1625. fill_555rgb_pswap(dest, xpos++, r, g, b);
  1626. #else
  1627. *(unsigned short *) dest =
  1628. SWAP16((unsigned short) (
  1629. ((r >> 3) << 10) |
  1630. ((g >> 3) << 5) |
  1631. (b >> 3)));
  1632. #endif
  1633. break;
  1634. case GDF_16BIT_565RGB:
  1635. *(unsigned short *) dest =
  1636. SWAP16((unsigned short) (
  1637. ((r >> 3) << 11) |
  1638. ((g >> 2) << 5) |
  1639. (b >> 3)));
  1640. break;
  1641. case GDF_32BIT_X888RGB:
  1642. *(unsigned long *) dest =
  1643. SWAP32((unsigned long) (
  1644. (r << 16) |
  1645. (g << 8) |
  1646. b));
  1647. break;
  1648. case GDF_24BIT_888RGB:
  1649. #ifdef VIDEO_FB_LITTLE_ENDIAN
  1650. dest[0] = b;
  1651. dest[1] = g;
  1652. dest[2] = r;
  1653. #else
  1654. dest[0] = r;
  1655. dest[1] = g;
  1656. dest[2] = b;
  1657. #endif
  1658. break;
  1659. }
  1660. source++;
  1661. dest += VIDEO_PIXEL_SIZE;
  1662. }
  1663. dest += skip;
  1664. }
  1665. #ifdef CONFIG_VIDEO_BMP_LOGO
  1666. free(logo_red);
  1667. free(logo_green);
  1668. free(logo_blue);
  1669. #endif
  1670. }
  1671. static void *video_logo(void)
  1672. {
  1673. char info[128];
  1674. __maybe_unused int y_off = 0;
  1675. __maybe_unused ulong addr;
  1676. __maybe_unused char *s;
  1677. __maybe_unused int len, space;
  1678. splash_get_pos(&video_logo_xpos, &video_logo_ypos);
  1679. #ifdef CONFIG_SPLASH_SCREEN
  1680. s = getenv("splashimage");
  1681. if (s != NULL) {
  1682. splash_screen_prepare();
  1683. addr = simple_strtoul(s, NULL, 16);
  1684. if (video_display_bitmap(addr,
  1685. video_logo_xpos,
  1686. video_logo_ypos) == 0) {
  1687. video_logo_height = 0;
  1688. return ((void *) (video_fb_address));
  1689. }
  1690. }
  1691. #endif /* CONFIG_SPLASH_SCREEN */
  1692. logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos);
  1693. #ifdef CONFIG_SPLASH_SCREEN_ALIGN
  1694. /*
  1695. * when using splashpos for video_logo, skip any info
  1696. * output on video console if the logo is not at 0,0
  1697. */
  1698. if (video_logo_xpos || video_logo_ypos) {
  1699. /*
  1700. * video_logo_height is used in text and cursor offset
  1701. * calculations. Since the console is below the logo,
  1702. * we need to adjust the logo height
  1703. */
  1704. if (video_logo_ypos == BMP_ALIGN_CENTER)
  1705. video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS -
  1706. VIDEO_LOGO_HEIGHT) / 2);
  1707. else if (video_logo_ypos > 0)
  1708. video_logo_height += video_logo_ypos;
  1709. return video_fb_address + video_logo_height * VIDEO_LINE_LEN;
  1710. }
  1711. #endif
  1712. if (board_cfb_skip())
  1713. return 0;
  1714. sprintf(info, " %s", version_string);
  1715. #ifndef CONFIG_HIDE_LOGO_VERSION
  1716. space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
  1717. len = strlen(info);
  1718. if (len > space) {
  1719. video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
  1720. (uchar *) info, space);
  1721. video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
  1722. VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
  1723. (uchar *) info + space, len - space);
  1724. y_off = 1;
  1725. } else
  1726. video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
  1727. #ifdef CONFIG_CONSOLE_EXTRA_INFO
  1728. {
  1729. int i, n =
  1730. ((video_logo_height -
  1731. VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT);
  1732. for (i = 1; i < n; i++) {
  1733. video_get_info_str(i, info);
  1734. if (!*info)
  1735. continue;
  1736. len = strlen(info);
  1737. if (len > space) {
  1738. video_drawchars(VIDEO_INFO_X,
  1739. VIDEO_INFO_Y +
  1740. (i + y_off) *
  1741. VIDEO_FONT_HEIGHT,
  1742. (uchar *) info, space);
  1743. y_off++;
  1744. video_drawchars(VIDEO_INFO_X +
  1745. VIDEO_FONT_WIDTH,
  1746. VIDEO_INFO_Y +
  1747. (i + y_off) *
  1748. VIDEO_FONT_HEIGHT,
  1749. (uchar *) info + space,
  1750. len - space);
  1751. } else {
  1752. video_drawstring(VIDEO_INFO_X,
  1753. VIDEO_INFO_Y +
  1754. (i + y_off) *
  1755. VIDEO_FONT_HEIGHT,
  1756. (uchar *) info);
  1757. }
  1758. }
  1759. }
  1760. #endif
  1761. #endif
  1762. return (video_fb_address + video_logo_height * VIDEO_LINE_LEN);
  1763. }
  1764. #endif
  1765. static int cfb_fb_is_in_dram(void)
  1766. {
  1767. bd_t *bd = gd->bd;
  1768. #if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
  1769. defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
  1770. ulong start, end;
  1771. int i;
  1772. for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) {
  1773. start = bd->bi_dram[i].start;
  1774. end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1;
  1775. if ((ulong)video_fb_address >= start &&
  1776. (ulong)video_fb_address < end)
  1777. return 1;
  1778. }
  1779. #else
  1780. if ((ulong)video_fb_address >= bd->bi_memstart &&
  1781. (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize)
  1782. return 1;
  1783. #endif
  1784. return 0;
  1785. }
  1786. void video_clear(void)
  1787. {
  1788. if (!video_fb_address)
  1789. return;
  1790. #ifdef VIDEO_HW_RECTFILL
  1791. video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */
  1792. 0, /* dest pos x */
  1793. 0, /* dest pos y */
  1794. VIDEO_VISIBLE_COLS, /* frame width */
  1795. VIDEO_VISIBLE_ROWS, /* frame height */
  1796. bgx /* fill color */
  1797. );
  1798. #else
  1799. memsetl(video_fb_address,
  1800. (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx);
  1801. #endif
  1802. }
  1803. static int cfg_video_init(void)
  1804. {
  1805. unsigned char color8;
  1806. pGD = video_hw_init();
  1807. if (pGD == NULL)
  1808. return -1;
  1809. video_fb_address = (void *) VIDEO_FB_ADRS;
  1810. cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status();
  1811. /* Init drawing pats */
  1812. switch (VIDEO_DATA_FORMAT) {
  1813. case GDF__8BIT_INDEX:
  1814. video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL,
  1815. CONFIG_SYS_CONSOLE_FG_COL,
  1816. CONFIG_SYS_CONSOLE_FG_COL);
  1817. video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL,
  1818. CONFIG_SYS_CONSOLE_BG_COL,
  1819. CONFIG_SYS_CONSOLE_BG_COL);
  1820. fgx = 0x01010101;
  1821. bgx = 0x00000000;
  1822. break;
  1823. case GDF__8BIT_332RGB:
  1824. color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) |
  1825. ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) |
  1826. CONFIG_SYS_CONSOLE_FG_COL >> 6);
  1827. fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
  1828. color8;
  1829. color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) |
  1830. ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) |
  1831. CONFIG_SYS_CONSOLE_BG_COL >> 6);
  1832. bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) |
  1833. color8;
  1834. break;
  1835. case GDF_15BIT_555RGB:
  1836. fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) |
  1837. ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) |
  1838. ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
  1839. ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) |
  1840. ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) |
  1841. (CONFIG_SYS_CONSOLE_FG_COL >> 3));
  1842. bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) |
  1843. ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) |
  1844. ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
  1845. ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) |
  1846. ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) |
  1847. (CONFIG_SYS_CONSOLE_BG_COL >> 3));
  1848. break;
  1849. case GDF_16BIT_565RGB:
  1850. fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) |
  1851. ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) |
  1852. ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) |
  1853. ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) |
  1854. ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) |
  1855. (CONFIG_SYS_CONSOLE_FG_COL >> 3));
  1856. bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) |
  1857. ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) |
  1858. ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) |
  1859. ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) |
  1860. ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) |
  1861. (CONFIG_SYS_CONSOLE_BG_COL >> 3));
  1862. break;
  1863. case GDF_32BIT_X888RGB:
  1864. fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) |
  1865. (CONFIG_SYS_CONSOLE_FG_COL << 8) |
  1866. CONFIG_SYS_CONSOLE_FG_COL;
  1867. bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) |
  1868. (CONFIG_SYS_CONSOLE_BG_COL << 8) |
  1869. CONFIG_SYS_CONSOLE_BG_COL;
  1870. break;
  1871. case GDF_24BIT_888RGB:
  1872. fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) |
  1873. (CONFIG_SYS_CONSOLE_FG_COL << 16) |
  1874. (CONFIG_SYS_CONSOLE_FG_COL << 8) |
  1875. CONFIG_SYS_CONSOLE_FG_COL;
  1876. bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) |
  1877. (CONFIG_SYS_CONSOLE_BG_COL << 16) |
  1878. (CONFIG_SYS_CONSOLE_BG_COL << 8) |
  1879. CONFIG_SYS_CONSOLE_BG_COL;
  1880. break;
  1881. }
  1882. eorx = fgx ^ bgx;
  1883. video_clear();
  1884. #ifdef CONFIG_VIDEO_LOGO
  1885. /* Plot the logo and get start point of console */
  1886. debug("Video: Drawing the logo ...\n");
  1887. video_console_address = video_logo();
  1888. #else
  1889. video_console_address = video_fb_address;
  1890. #endif
  1891. /* Initialize the console */
  1892. console_col = 0;
  1893. console_row = 0;
  1894. if (cfb_do_flush_cache)
  1895. flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
  1896. return 0;
  1897. }
  1898. /*
  1899. * Implement a weak default function for boards that optionally
  1900. * need to skip the video initialization.
  1901. */
  1902. __weak int board_video_skip(void)
  1903. {
  1904. /* As default, don't skip test */
  1905. return 0;
  1906. }
  1907. int drv_video_init(void)
  1908. {
  1909. struct stdio_dev console_dev;
  1910. bool have_keyboard;
  1911. bool __maybe_unused keyboard_ok = false;
  1912. /* Check if video initialization should be skipped */
  1913. if (board_video_skip())
  1914. return 0;
  1915. /* Init video chip - returns with framebuffer cleared */
  1916. if (cfg_video_init() == -1)
  1917. return 0;
  1918. if (board_cfb_skip())
  1919. return 0;
  1920. #if defined(CONFIG_VGA_AS_SINGLE_DEVICE)
  1921. have_keyboard = false;
  1922. #elif defined(CONFIG_OF_CONTROL)
  1923. have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob,
  1924. "u-boot,no-keyboard");
  1925. #else
  1926. have_keyboard = true;
  1927. #endif
  1928. if (have_keyboard) {
  1929. debug("KBD: Keyboard init ...\n");
  1930. #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
  1931. keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1);
  1932. #endif
  1933. }
  1934. /* Init vga device */
  1935. memset(&console_dev, 0, sizeof(console_dev));
  1936. strcpy(console_dev.name, "vga");
  1937. console_dev.flags = DEV_FLAGS_OUTPUT;
  1938. console_dev.putc = cfb_video_putc; /* 'putc' function */
  1939. console_dev.puts = cfb_video_puts; /* 'puts' function */
  1940. #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
  1941. if (have_keyboard && keyboard_ok) {
  1942. /* Also init console device */
  1943. console_dev.flags |= DEV_FLAGS_INPUT;
  1944. console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */
  1945. console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */
  1946. }
  1947. #endif
  1948. if (stdio_register(&console_dev) != 0)
  1949. return 0;
  1950. /* Return success */
  1951. return 1;
  1952. }
  1953. void video_position_cursor(unsigned col, unsigned row)
  1954. {
  1955. console_col = min(col, CONSOLE_COLS - 1);
  1956. console_row = min(row, CONSOLE_ROWS - 1);
  1957. }
  1958. int video_get_pixel_width(void)
  1959. {
  1960. return VIDEO_VISIBLE_COLS;
  1961. }
  1962. int video_get_pixel_height(void)
  1963. {
  1964. return VIDEO_VISIBLE_ROWS;
  1965. }
  1966. int video_get_screen_rows(void)
  1967. {
  1968. return CONSOLE_ROWS;
  1969. }
  1970. int video_get_screen_columns(void)
  1971. {
  1972. return CONSOLE_COLS;
  1973. }