cfb_console.c 48 KB

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