cfb_console.c 50 KB

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