cfb_console.c 50 KB

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