cfb_console.c 50 KB

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