cfb_console.c 54 KB

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