cfb_console.c 50 KB

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