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