video: omap: fix pixel-per-line bitfield setting
[oweals/u-boot.git] / drivers / video / cfb_console.c
index 56d3c15f8e037597fdcc3c6b6c8aec60268e99b5..5442bac4c6f3f294b8c9ac60855a035b04177ab6 100644 (file)
@@ -1,8 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2002 ELTEC Elektronik AG
  * Frank Gottschling <fgottschling@eltec.de>
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /*
  */
 
 #include <common.h>
+#include <cpu_func.h>
+#include <env.h>
 #include <fdtdec.h>
+#include <gzip.h>
 #include <version.h>
 #include <malloc.h>
+#include <video.h>
 #include <linux/compiler.h>
 
-/*
- * Defines for the CT69000 driver
- */
-#ifdef CONFIG_VIDEO_CT69000
-
-#define VIDEO_FB_LITTLE_ENDIAN
-#define VIDEO_HW_RECTFILL
-#define VIDEO_HW_BITBLT
-#endif
-
 #if defined(CONFIG_VIDEO_MXS)
 #define VIDEO_FB_16BPP_WORD_SWAP
 #endif
@@ -235,16 +228,6 @@ void console_cursor(int state);
 #endif
 #endif
 
-#ifdef CONFIG_CONSOLE_EXTRA_INFO
-/*
- * setup a board string: type, speed, etc.
- *
- * line_number:        location to place info string beside logo
- * info:       buffer for info string
- */
-extern void video_get_info_str(int line_number,        char *info);
-#endif
-
 DECLARE_GLOBAL_DATA_PTR;
 
 /* Locals */
@@ -787,7 +770,7 @@ static void parse_putc(const char c)
                break;
 
        case '\n':              /* next line */
-               if (console_col || (!console_col && nl))
+               if (console_col || nl)
                        console_newline(1);
                nl = 1;
                break;
@@ -823,7 +806,7 @@ static void parse_putc(const char c)
                CURSOR_SET;
 }
 
-static void video_putc(struct stdio_dev *dev, const char c)
+static void cfb_video_putc(struct stdio_dev *dev, const char c)
 {
 #ifdef CONFIG_CFB_CONSOLE_ANSI
        int i;
@@ -1037,7 +1020,7 @@ static void video_putc(struct stdio_dev *dev, const char c)
                flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
 }
 
-static void video_puts(struct stdio_dev *dev, const char *s)
+static void cfb_video_puts(struct stdio_dev *dev, const char *s)
 {
        int flush = cfb_do_flush_cache;
        int count = strlen(s);
@@ -1046,7 +1029,7 @@ static void video_puts(struct stdio_dev *dev, const char *s)
        cfb_do_flush_cache = 0;
 
        while (count--)
-               video_putc(dev, *s++);
+               cfb_video_putc(dev, *s++);
 
        if (flush) {
                cfb_do_flush_cache = flush;
@@ -1088,8 +1071,8 @@ __weak void video_set_lut(unsigned int index, unsigned char r,
 }
 
 #define FILL_32BIT_X888RGB(r,g,b) {                    \
-       *(unsigned long *)fb =                          \
-               SWAP32((unsigned long)(((r<<16) |       \
+       *(u32 *)fb =                            \
+               SWAP32((unsigned int)(((r<<16) |        \
                                        (g<<8)  |       \
                                         b)));          \
        fb += 4;                                        \
@@ -1170,7 +1153,7 @@ static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p,
                break;
        case GDF_32BIT_X888RGB:
                for (i = 0; i < cnt; i++) {
-                       *(unsigned long *) addr = p[bm[*off]].ce.dw;
+                       *(u32 *) addr = p[bm[*off]].ce.dw;
                        addr += 4;
                }
                break;
@@ -1317,6 +1300,10 @@ next_run:
                        break;
                }
        }
+
+       if (cfb_do_flush_cache)
+               flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE);
+
        return 0;
 error:
        printf("Error: Too much encoded pixel data, validate your bitmap\n");
@@ -1834,8 +1821,8 @@ static void plot_logo_or_black(void *screen, int x, int y, int black)
                                                         (b >> 3)));
                                break;
                        case GDF_32BIT_X888RGB:
-                               *(unsigned long *) dest =
-                                       SWAP32((unsigned long) (
+                               *(u32 *) dest =
+                                       SWAP32((u32) (
                                                        (r << 16) |
                                                        (g <<  8) |
                                                         b));
@@ -1870,14 +1857,16 @@ static void *video_logo(void)
        __maybe_unused int y_off = 0;
        __maybe_unused ulong addr;
        __maybe_unused char *s;
-       __maybe_unused int len, space;
+       __maybe_unused int len, ret, space;
 
        splash_get_pos(&video_logo_xpos, &video_logo_ypos);
 
 #ifdef CONFIG_SPLASH_SCREEN
-       s = getenv("splashimage");
+       s = env_get("splashimage");
        if (s != NULL) {
-               splash_screen_prepare();
+               ret = splash_screen_prepare();
+               if (ret < 0)
+                       return video_fb_address;
                addr = simple_strtoul(s, NULL, 16);
 
                if (video_display_bitmap(addr,
@@ -1917,16 +1906,32 @@ static void *video_logo(void)
        sprintf(info, " %s", version_string);
 
 #ifndef CONFIG_HIDE_LOGO_VERSION
-       space = (VIDEO_LINE_LEN / 2 - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
+       space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH;
        len = strlen(info);
 
        if (len > space) {
-               video_drawchars(VIDEO_INFO_X, VIDEO_INFO_Y,
-                               (uchar *) info, space);
-               video_drawchars(VIDEO_INFO_X + VIDEO_FONT_WIDTH,
-                               VIDEO_INFO_Y + VIDEO_FONT_HEIGHT,
-                               (uchar *) info + space, len - space);
-               y_off = 1;
+               int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y;
+               uchar *p = (uchar *) info;
+
+               while (len) {
+                       if (len > space) {
+                               video_drawchars(xx, yy, p, space);
+                               len -= space;
+
+                               p = (uchar *)p + space;
+
+                               if (!y_off) {
+                                       xx += VIDEO_FONT_WIDTH;
+                                       space--;
+                               }
+                               yy += VIDEO_FONT_HEIGHT;
+
+                               y_off++;
+                       } else {
+                               video_drawchars(xx, yy, p, len);
+                               len = 0;
+                       }
+               }
        } else
                video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info);
 
@@ -1975,7 +1980,7 @@ static void *video_logo(void)
 static int cfb_fb_is_in_dram(void)
 {
        bd_t *bd = gd->bd;
-#if defined(CONFIG_ARM) || defined(CONFIG_AVR32) || defined(COFNIG_NDS32) || \
+#if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \
 defined(CONFIG_SANDBOX) || defined(CONFIG_X86)
        ulong start, end;
        int i;
@@ -2013,7 +2018,7 @@ void video_clear(void)
 #endif
 }
 
-static int video_init(void)
+static int cfg_video_init(void)
 {
        unsigned char color8;
 
@@ -2098,7 +2103,8 @@ static int video_init(void)
        }
        eorx = fgx ^ bgx;
 
-       video_clear();
+       if (!CONFIG_IS_ENABLED(NO_FB_CLEAR))
+               video_clear();
 
 #ifdef CONFIG_VIDEO_LOGO
        /* Plot the logo and get start point of console */
@@ -2139,7 +2145,7 @@ int drv_video_init(void)
                return 0;
 
        /* Init video chip - returns with framebuffer cleared */
-       if (video_init() == -1)
+       if (cfg_video_init() == -1)
                return 0;
 
        if (board_cfb_skip())
@@ -2164,8 +2170,8 @@ int drv_video_init(void)
        memset(&console_dev, 0, sizeof(console_dev));
        strcpy(console_dev.name, "vga");
        console_dev.flags = DEV_FLAGS_OUTPUT;
-       console_dev.putc = video_putc;  /* 'putc' function */
-       console_dev.puts = video_puts;  /* 'puts' function */
+       console_dev.putc = cfb_video_putc;      /* 'putc' function */
+       console_dev.puts = cfb_video_puts;      /* 'puts' function */
 
 #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE)
        if (have_keyboard && keyboard_ok) {