cfb_console.c 46 KB

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