cfb_console.c 52 KB

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