cfb_console.c 50 KB

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