cfb_console.c 54 KB

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