Merge branch '2019-10-28-azure-ci-support'
[oweals/u-boot.git] / common / lcd.c
index 06eec4508cc40aa239bcfc199eea9bcb64be389b..b34754fe518ca07208ed7bd8d3d107303dc8d934 100644 (file)
@@ -1,10 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Common LCD routines
  *
  * (C) Copyright 2001-2002
  * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 /* #define DEBUG */
 #include <linux/types.h>
 #include <stdio_dev.h>
 #include <lcd.h>
+#include <mapmem.h>
 #include <watchdog.h>
 #include <asm/unaligned.h>
 #include <splash.h>
 #include <asm/io.h>
 #include <asm/unaligned.h>
-#include <fdt_support.h>
 #include <video_font.h>
 
-#if defined(CONFIG_LCD_DT_SIMPLEFB)
-#include <libfdt.h>
-#endif
-
 #ifdef CONFIG_LCD_LOGO
 #include <bmp_logo.h>
 #include <bmp_logo_data.h>
 #endif
 #endif
 
-#ifdef CONFIG_SANDBOX
-#include <asm/sdl.h>
-#endif
-
 #ifndef CONFIG_LCD_ALIGNMENT
 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
 #endif
@@ -51,7 +42,7 @@
 DECLARE_GLOBAL_DATA_PTR;
 
 static int lcd_init(void *lcdbase);
-static void *lcd_logo(void);
+static void lcd_logo(void);
 static void lcd_setfgcolor(int color);
 static void lcd_setbgcolor(int color);
 
@@ -70,19 +61,12 @@ void lcd_sync(void)
         * architectures do not actually implement it. Is there a way to find
         * out whether it exists? For now, ARM is safe.
         */
-#if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
+#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
        int line_length;
 
        if (lcd_flush_dcache)
-               flush_dcache_range((u32)lcd_base,
-                       (u32)(lcd_base + lcd_get_size(&line_length)));
-#elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
-       static ulong last_sync;
-
-       if (get_timer(last_sync) > 10) {
-               sandbox_sdl_sync(lcd_base);
-               last_sync = get_timer(0);
-       }
+               flush_dcache_range((ulong)lcd_base,
+                       (ulong)(lcd_base + lcd_get_size(&line_length)));
 #endif
 }
 
@@ -104,13 +88,24 @@ static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
 /* Small utility to check that you got the colours right */
 #ifdef LCD_TEST_PATTERN
 
+#if LCD_BPP == LCD_COLOR8
 #define        N_BLK_VERT      2
 #define        N_BLK_HOR       3
 
 static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
        CONSOLE_COLOR_RED,      CONSOLE_COLOR_GREEN,    CONSOLE_COLOR_YELLOW,
        CONSOLE_COLOR_BLUE,     CONSOLE_COLOR_MAGENTA,  CONSOLE_COLOR_CYAN,
+}; /*LCD_BPP == LCD_COLOR8 */
+
+#elif LCD_BPP == LCD_COLOR16
+#define        N_BLK_VERT      2
+#define        N_BLK_HOR       4
+
+static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
+       CONSOLE_COLOR_RED,      CONSOLE_COLOR_GREEN,    CONSOLE_COLOR_YELLOW,   CONSOLE_COLOR_BLUE,
+       CONSOLE_COLOR_MAGENTA,  CONSOLE_COLOR_CYAN,     CONSOLE_COLOR_GREY,     CONSOLE_COLOR_WHITE,
 };
+#endif /*LCD_BPP == LCD_COLOR16 */
 
 static void test_pattern(void)
 {
@@ -119,12 +114,15 @@ static void test_pattern(void)
        ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
        ushort h_step = (h_max + N_BLK_HOR  - 1) / N_BLK_HOR;
        ushort v, h;
+#if LCD_BPP == LCD_COLOR8
        uchar *pix = (uchar *)lcd_base;
+#elif LCD_BPP == LCD_COLOR16
+       ushort *pix = (ushort *)lcd_base;
+#endif
 
        printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
                h_max, v_max, h_step, v_step);
 
-       /* WARNING: Code silently assumes 8bit/pixel */
        for (v = 0; v < v_max; ++v) {
                uchar iy = v / v_step;
                for (h = 0; h < h_max; ++h) {
@@ -172,8 +170,9 @@ int drv_lcd_init(void)
 
 void lcd_clear(void)
 {
-       short console_rows, console_cols;
        int bg_color;
+       __maybe_unused ulong addr;
+       static int do_splash = 1;
 #if LCD_BPP == LCD_COLOR8
        /* Setting the palette */
        lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
@@ -213,28 +212,31 @@ void lcd_clear(void)
        }
 #endif
 #endif
+       /* setup text-console */
+       debug("[LCD] setting up console...\n");
+       lcd_init_console(lcd_base,
+                        panel_info.vl_col,
+                        panel_info.vl_row,
+                        panel_info.vl_rot);
        /* Paint the logo and retrieve LCD base address */
        debug("[LCD] Drawing the logo...\n");
+       if (do_splash) {
+               if (splash_display() == 0) {
+                       do_splash = 0;
+                       lcd_sync();
+                       return;
+               }
+       }
+
+       lcd_logo();
 #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
-       console_rows = (panel_info.vl_row - BMP_LOGO_HEIGHT);
-       console_rows /= VIDEO_FONT_HEIGHT;
-#else
-       console_rows = panel_info.vl_row / VIDEO_FONT_HEIGHT;
+       addr = (ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length;
+       lcd_init_console((void *)addr, panel_info.vl_col,
+                        panel_info.vl_row, panel_info.vl_rot);
 #endif
-       console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH;
-       lcd_init_console(lcd_base, console_rows, console_cols);
-       lcd_init_console(lcd_logo(), console_rows, console_cols);
        lcd_sync();
 }
 
-static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
-                       char *const argv[])
-{
-       lcd_clear();
-       return 0;
-}
-U_BOOT_CMD(cls,        1, 1, do_lcd_clear, "clear screen", "");
-
 static int lcd_init(void *lcdbase)
 {
        debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
@@ -327,7 +329,7 @@ __weak void lcd_logo_set_cmap(void)
                *cmap++ = bmp_logo_palette[i];
 }
 
-void bitmap_plot(int x, int y)
+void lcd_logo_plot(int x, int y)
 {
        ushort i, j;
        uchar *bmap = &bmp_logo_bitmap[0];
@@ -369,12 +371,11 @@ void bitmap_plot(int x, int y)
        lcd_sync();
 }
 #else
-static inline void bitmap_plot(int x, int y) {}
+static inline void lcd_logo_plot(int x, int y) {}
 #endif /* CONFIG_LCD_LOGO */
 
 #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
 #ifdef CONFIG_SPLASH_SCREEN_ALIGN
-#define BMP_ALIGN_CENTER       0x7FFF
 
 static void splash_align_axis(int *axis, unsigned long panel_size,
                                        unsigned long picture_size)
@@ -435,8 +436,8 @@ static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
 /*
  * Do not call this function directly, must be called from lcd_display_bitmap.
  */
-static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
-                                   int x_off, int y_off)
+static void lcd_display_rle8_bitmap(struct bmp_image *bmp, ushort *cmap,
+                                   uchar *fb, int x_off, int y_off)
 {
        uchar *bmap;
        ulong width, height;
@@ -535,10 +536,10 @@ __weak void fb_put_word(uchar **fb, uchar **from)
 }
 #endif /* CONFIG_BMP_16BPP */
 
-__weak void lcd_set_cmap(bmp_image_t *bmp, unsigned colors)
+__weak void lcd_set_cmap(struct bmp_image *bmp, unsigned colors)
 {
        int i;
-       bmp_color_table_entry_t cte;
+       struct bmp_color_table_entry cte;
        ushort *cmap = configuration_get_cmap();
 
        for (i = 0; i < colors; ++i) {
@@ -546,11 +547,7 @@ __weak void lcd_set_cmap(bmp_image_t *bmp, unsigned colors)
                *cmap = (((cte.red)   << 8) & 0xf800) |
                        (((cte.green) << 3) & 0x07e0) |
                        (((cte.blue)  >> 3) & 0x001f);
-#if defined(CONFIG_MPC823)
-               cmap--;
-#else
                cmap++;
-#endif
        }
 }
 
@@ -559,12 +556,14 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
        ushort *cmap_base = NULL;
        ushort i, j;
        uchar *fb;
-       bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
+       struct bmp_image *bmp = (struct bmp_image *)map_sysmem(bmp_image, 0);
        uchar *bmap;
        ushort padded_width;
        unsigned long width, height, byte_width;
        unsigned long pwidth = panel_info.vl_col;
        unsigned colors, bpix, bmp_bpix;
+       int hdr_size;
+       struct bmp_color_table_entry *palette;
 
        if (!bmp || !(bmp->header.signature[0] == 'B' &&
                bmp->header.signature[1] == 'M')) {
@@ -573,9 +572,12 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
                return 1;
        }
 
+       palette = bmp->color_table;
        width = get_unaligned_le32(&bmp->header.width);
        height = get_unaligned_le32(&bmp->header.height);
        bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
+       hdr_size = get_unaligned_le16(&bmp->header.size);
+       debug("hdr_size=%d, bmp_bpix=%d\n", hdr_size, bmp_bpix);
 
        colors = 1 << bmp_bpix;
 
@@ -600,8 +602,8 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
                return 1;
        }
 
-       debug("Display-bmp: %d x %d  with %d colors\n",
-               (int)width, (int)height, (int)colors);
+       debug("Display-bmp: %d x %d  with %d colors, display %d\n",
+             (int)width, (int)height, (int)colors, 1 << bpix);
 
        if (bmp_bpix == 8)
                lcd_set_cmap(bmp, colors);
@@ -628,6 +630,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
                cmap_base = configuration_get_cmap();
 #ifdef CONFIG_LCD_BMP_RLE8
                u32 compression = get_unaligned_le32(&bmp->header.compression);
+               debug("compressed %d %d\n", compression, BMP_BI_RLE8);
                if (compression == BMP_BI_RLE8) {
                        if (bpix != 16) {
                                /* TODO implement render code for bpix != 16 */
@@ -650,7 +653,19 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
                                if (bpix != 16) {
                                        fb_put_byte(&fb, &bmap);
                                } else {
-                                       *(uint16_t *)fb = cmap_base[*(bmap++)];
+                                       struct bmp_color_table_entry *entry;
+                                       uint val;
+
+                                       if (cmap_base) {
+                                               val = cmap_base[*bmap];
+                                       } else {
+                                               entry = &palette[*bmap];
+                                               val = entry->blue >> 3 |
+                                                       entry->green >> 2 << 5 |
+                                                       entry->red >> 3 << 11;
+                                       }
+                                       *(uint16_t *)fb = val;
+                                       bmap++;
                                        fb += sizeof(uint16_t) / sizeof(*fb);
                                }
                        }
@@ -671,7 +686,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
                }
                break;
 #endif /* CONFIG_BMP_16BPP */
-#if defined(CONFIG_BMP_24BMP)
+#if defined(CONFIG_BMP_24BPP)
        case 24:
                for (i = 0; i < height; ++i) {
                        for (j = 0; j < width; j++) {
@@ -683,7 +698,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
                        fb -= lcd_line_length + width * (bpix / 8);
                }
                break;
-#endif /* CONFIG_BMP_24BMP */
+#endif /* CONFIG_BMP_24BPP */
 #if defined(CONFIG_BMP_32BPP)
        case 32:
                for (i = 0; i < height; ++i) {
@@ -706,42 +721,15 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
 }
 #endif
 
-static void *lcd_logo(void)
+static void lcd_logo(void)
 {
-#ifdef CONFIG_SPLASH_SCREEN
-       char *s;
-       ulong addr;
-       static int do_splash = 1;
-
-       if (do_splash && (s = getenv("splashimage")) != NULL) {
-               int x = 0, y = 0;
-               do_splash = 0;
-
-               if (splash_screen_prepare())
-                       return (void *)lcd_base;
-
-               addr = simple_strtoul (s, NULL, 16);
-
-               splash_get_pos(&x, &y);
-
-               if (bmp_display(addr, x, y) == 0)
-                       return (void *)lcd_base;
-       }
-#endif /* CONFIG_SPLASH_SCREEN */
-
-       bitmap_plot(0, 0);
+       lcd_logo_plot(0, 0);
 
 #ifdef CONFIG_LCD_INFO
        lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH);
        lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT);
        lcd_show_board_info();
 #endif /* CONFIG_LCD_INFO */
-
-#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
-       return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
-#else
-       return (void *)lcd_base;
-#endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
 }
 
 #ifdef CONFIG_SPLASHIMAGE_GUARD
@@ -777,48 +765,3 @@ int lcd_get_pixel_height(void)
 {
        return panel_info.vl_row;
 }
-
-#if defined(CONFIG_LCD_DT_SIMPLEFB)
-static int lcd_dt_simplefb_configure_node(void *blob, int off)
-{
-#if LCD_BPP == LCD_COLOR16
-       return fdt_setup_simplefb_node(blob, off, gd->fb_base,
-                                      panel_info.vl_col, panel_info.vl_row,
-                                      panel_info.vl_col * 2, "r5g6b5");
-#else
-       return -1;
-#endif
-}
-
-int lcd_dt_simplefb_add_node(void *blob)
-{
-       static const char compat[] = "simple-framebuffer";
-       static const char disabled[] = "disabled";
-       int off, ret;
-
-       off = fdt_add_subnode(blob, 0, "framebuffer");
-       if (off < 0)
-               return -1;
-
-       ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
-       if (ret < 0)
-               return -1;
-
-       ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
-       if (ret < 0)
-               return -1;
-
-       return lcd_dt_simplefb_configure_node(blob, off);
-}
-
-int lcd_dt_simplefb_enable_existing_node(void *blob)
-{
-       int off;
-
-       off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
-       if (off < 0)
-               return -1;
-
-       return lcd_dt_simplefb_configure_node(blob, off);
-}
-#endif