cfb_console.c 50 KB

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