cfb_console.c 50 KB

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