lcd: logo: move generic cmap setting to lcd_logo_set_cmap()
[oweals/u-boot.git] / common / lcd.c
index 3ed504df50df128180211a39186b55f85074de97..dcee3c0aab10b457c72cf37179c254669a44cdcd 100644 (file)
 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
 #endif
 
-/* By default we scroll by a single line */
-#ifndef CONFIG_CONSOLE_SCROLL_LINES
-#define CONFIG_CONSOLE_SCROLL_LINES 1
-#endif
-
-/************************************************************************/
-/* ** CONSOLE DEFINITIONS & FUNCTIONS                                  */
-/************************************************************************/
-#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
-# define CONSOLE_ROWS          ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
-                                       / VIDEO_FONT_HEIGHT)
-#else
-# define CONSOLE_ROWS          (panel_info.vl_row / VIDEO_FONT_HEIGHT)
-#endif
-
-#define CONSOLE_COLS           (panel_info.vl_col / VIDEO_FONT_WIDTH)
-#define CONSOLE_ROW_SIZE       (VIDEO_FONT_HEIGHT * lcd_line_length)
-#define CONSOLE_ROW_FIRST      lcd_console_address
-#define CONSOLE_ROW_SECOND     (lcd_console_address + CONSOLE_ROW_SIZE)
-#define CONSOLE_ROW_LAST       (lcd_console_address + CONSOLE_SIZE \
-                                       - CONSOLE_ROW_SIZE)
-#define CONSOLE_SIZE           (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
-#define CONSOLE_SCROLL_SIZE    (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
-
-#if LCD_BPP == LCD_MONOCHROME
-# define COLOR_MASK(c)         ((c)      | (c) << 1 | (c) << 2 | (c) << 3 | \
-                                (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
-#elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \
-       (LCD_BPP == LCD_COLOR32)
-# define COLOR_MASK(c)         (c)
-#else
+#if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \
+       (LCD_BPP != LCD_COLOR32)
 # error Unsupported LCD BPP.
 #endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
-static inline void lcd_putc_xy(ushort x, ushort y, uchar  c);
-
 static int lcd_init(void *lcdbase);
 
 static void *lcd_logo(void);
@@ -125,10 +93,6 @@ int lcd_line_length;
 
 char lcd_is_enabled = 0;
 
-static short console_col;
-static short console_row;
-
-static void *lcd_console_address;
 static void *lcd_base;                 /* Start of framebuffer memory  */
 
 static char lcd_flush_dcache;  /* 1 to flush dcache after each lcd update */
@@ -166,217 +130,16 @@ void lcd_set_flush_dcache(int flush)
 
 /*----------------------------------------------------------------------*/
 
-static void console_scrollup(void)
-{
-       const int rows = CONFIG_CONSOLE_SCROLL_LINES;
-
-       /* Copy up rows ignoring those that will be overwritten */
-       memcpy(CONSOLE_ROW_FIRST,
-              lcd_console_address + CONSOLE_ROW_SIZE * rows,
-              CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
-
-       /* Clear the last rows */
-#if (LCD_BPP != LCD_COLOR32)
-       memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
-               COLOR_MASK(lcd_color_bg),
-               CONSOLE_ROW_SIZE * rows);
-#else
-       u32 *ppix = lcd_console_address +
-                   CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
-       u32 i;
-       for (i = 0;
-           i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
-           i++) {
-               *ppix++ = COLOR_MASK(lcd_color_bg);
-       }
-#endif
-       lcd_sync();
-       console_row -= rows;
-}
-
-/*----------------------------------------------------------------------*/
-
-static inline void console_back(void)
-{
-       if (--console_col < 0) {
-               console_col = CONSOLE_COLS-1 ;
-               if (--console_row < 0)
-                       console_row = 0;
-       }
-
-       lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
-               console_row * VIDEO_FONT_HEIGHT, ' ');
-}
-
-/*----------------------------------------------------------------------*/
-
-static inline void console_newline(void)
-{
-       console_col = 0;
-
-       /* Check if we need to scroll the terminal */
-       if (++console_row >= CONSOLE_ROWS)
-               console_scrollup();
-       else
-               lcd_sync();
-}
-
-/*----------------------------------------------------------------------*/
-
 static void lcd_stub_putc(struct stdio_dev *dev, const char c)
 {
        lcd_putc(c);
 }
 
-void lcd_putc(const char c)
-{
-       if (!lcd_is_enabled) {
-               serial_putc(c);
-
-               return;
-       }
-
-       switch (c) {
-       case '\r':
-               console_col = 0;
-
-               return;
-       case '\n':
-               console_newline();
-
-               return;
-       case '\t':      /* Tab (8 chars alignment) */
-               console_col +=  8;
-               console_col &= ~7;
-
-               if (console_col >= CONSOLE_COLS)
-                       console_newline();
-
-               return;
-       case '\b':
-               console_back();
-
-               return;
-       default:
-               lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
-                       console_row * VIDEO_FONT_HEIGHT, c);
-               if (++console_col >= CONSOLE_COLS)
-                       console_newline();
-       }
-}
-
-/*----------------------------------------------------------------------*/
-
 static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
 {
        lcd_puts(s);
 }
 
-void lcd_puts(const char *s)
-{
-       if (!lcd_is_enabled) {
-               serial_puts(s);
-
-               return;
-       }
-
-       while (*s)
-               lcd_putc(*s++);
-
-       lcd_sync();
-}
-
-/*----------------------------------------------------------------------*/
-
-void lcd_printf(const char *fmt, ...)
-{
-       va_list args;
-       char buf[CONFIG_SYS_PBSIZE];
-
-       va_start(args, fmt);
-       vsprintf(buf, fmt, args);
-       va_end(args);
-
-       lcd_puts(buf);
-}
-
-/************************************************************************/
-/* ** Low-Level Graphics Routines                                      */
-/************************************************************************/
-
-static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
-{
-       uchar *dest;
-       ushort row;
-
-#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
-       y += BMP_LOGO_HEIGHT;
-#endif
-
-#if LCD_BPP == LCD_MONOCHROME
-       ushort off  = x * (1 << LCD_BPP) % 8;
-#endif
-
-       dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8);
-
-       for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
-               uchar *s = str;
-               int i;
-#if LCD_BPP == LCD_COLOR16
-               ushort *d = (ushort *)dest;
-#elif LCD_BPP == LCD_COLOR32
-               u32 *d = (u32 *)dest;
-#else
-               uchar *d = dest;
-#endif
-
-#if LCD_BPP == LCD_MONOCHROME
-               uchar rest = *d & -(1 << (8 - off));
-               uchar sym;
-#endif
-               for (i = 0; i < count; ++i) {
-                       uchar c, bits;
-
-                       c = *s++;
-                       bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
-
-#if LCD_BPP == LCD_MONOCHROME
-                       sym  = (COLOR_MASK(lcd_color_fg) & bits) |
-                               (COLOR_MASK(lcd_color_bg) & ~bits);
-
-                       *d++ = rest | (sym >> off);
-                       rest = sym << (8-off);
-#elif LCD_BPP == LCD_COLOR8
-                       for (c = 0; c < 8; ++c) {
-                               *d++ = (bits & 0x80) ?
-                                               lcd_color_fg : lcd_color_bg;
-                               bits <<= 1;
-                       }
-#elif LCD_BPP == LCD_COLOR16
-                       for (c = 0; c < 8; ++c) {
-                               *d++ = (bits & 0x80) ?
-                                               lcd_color_fg : lcd_color_bg;
-                               bits <<= 1;
-                       }
-#elif LCD_BPP == LCD_COLOR32
-                       for (c = 0; c < 8; ++c) {
-                               *d++ = (bits & 0x80) ?
-                                               lcd_color_fg : lcd_color_bg;
-                               bits <<= 1;
-                       }
-#endif
-               }
-#if LCD_BPP == LCD_MONOCHROME
-               *d  = rest | (*d & ((1 << (8 - off)) - 1));
-#endif
-       }
-}
-
-static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
-{
-       lcd_drawchars(x, y, &c, 1);
-}
-
 /************************************************************************/
 /**  Small utility to check that you got the colours right             */
 /************************************************************************/
@@ -455,11 +218,9 @@ int drv_lcd_init(void)
 /*----------------------------------------------------------------------*/
 void lcd_clear(void)
 {
-#if LCD_BPP == LCD_MONOCHROME
-       /* Setting the palette */
-       lcd_initcolregs();
-
-#elif LCD_BPP == LCD_COLOR8
+       short console_rows, console_cols;
+       int bg_color;
+#if LCD_BPP == LCD_COLOR8
        /* Setting the palette */
        lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
        lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
@@ -475,9 +236,11 @@ void lcd_clear(void)
 #ifndef CONFIG_SYS_WHITE_ON_BLACK
        lcd_setfgcolor(CONSOLE_COLOR_BLACK);
        lcd_setbgcolor(CONSOLE_COLOR_WHITE);
+       bg_color = CONSOLE_COLOR_WHITE;
 #else
        lcd_setfgcolor(CONSOLE_COLOR_WHITE);
        lcd_setbgcolor(CONSOLE_COLOR_BLACK);
+       bg_color = CONSOLE_COLOR_BLACK;
 #endif /* CONFIG_SYS_WHITE_ON_BLACK */
 
 #ifdef LCD_TEST_PATTERN
@@ -485,25 +248,28 @@ void lcd_clear(void)
 #else
        /* set framebuffer to background color */
 #if (LCD_BPP != LCD_COLOR32)
-       memset((char *)lcd_base,
-               COLOR_MASK(lcd_color_bg),
-               lcd_line_length * panel_info.vl_row);
+       memset((char *)lcd_base, bg_color, lcd_line_length * panel_info.vl_row);
 #else
        u32 *ppix = lcd_base;
        u32 i;
        for (i = 0;
           i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
           i++) {
-               *ppix++ = COLOR_MASK(lcd_color_bg);
+               *ppix++ = bg_color;
        }
 #endif
 #endif
        /* Paint the logo and retrieve LCD base address */
        debug("[LCD] Drawing the logo...\n");
-       lcd_console_address = lcd_logo();
-
-       console_col = 0;
-       console_row = 0;
+#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;
+#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();
 }
 
@@ -546,11 +312,11 @@ static int lcd_init(void *lcdbase)
        lcd_enable();
 
        /* Initialize the console */
-       console_col = 0;
+       lcd_set_col(0);
 #ifdef CONFIG_LCD_INFO_BELOW_LOGO
-       console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
+       lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT);
 #else
-       console_row = 1;        /* leave 1 blank line below logo */
+       lcd_set_row(1); /* leave 1 blank line below logo */
 #endif
 
        return 0;
@@ -597,6 +363,11 @@ static void lcd_setfgcolor(int color)
        lcd_color_fg = color;
 }
 
+int lcd_getfgcolor(void)
+{
+       return lcd_color_fg;
+}
+
 /*----------------------------------------------------------------------*/
 
 static void lcd_setbgcolor(int color)
@@ -604,95 +375,42 @@ static void lcd_setbgcolor(int color)
        lcd_color_bg = color;
 }
 
+int lcd_getbgcolor(void)
+{
+       return lcd_color_bg;
+}
+
 /************************************************************************/
 /* ** Chipset depending Bitmap / Logo stuff...                          */
 /************************************************************************/
-static inline ushort *configuration_get_cmap(void)
+
+#ifdef CONFIG_LCD_LOGO
+__weak void lcd_logo_set_cmap(void)
 {
-#if defined CONFIG_CPU_PXA
-       struct pxafb_info *fbi = &panel_info.pxa;
-       return (ushort *)fbi->palette;
-#elif defined(CONFIG_MPC823)
-       immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
-       cpm8xx_t *cp = &(immr->im_cpm);
-       return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
-#elif defined(CONFIG_ATMEL_LCD)
-       return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
-#elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
-       return panel_info.cmap;
-#elif defined(CONFIG_LCD_LOGO)
-       return bmp_logo_palette;
-#else
-       return NULL;
-#endif
+       int i;
+       ushort *cmap = configuration_get_cmap();
+
+       for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i)
+               *cmap++ = bmp_logo_palette[i];
 }
 
-#ifdef CONFIG_LCD_LOGO
 void bitmap_plot(int x, int y)
 {
-#ifdef CONFIG_ATMEL_LCD
-       uint *cmap = (uint *)bmp_logo_palette;
-#else
-       ushort *cmap = (ushort *)bmp_logo_palette;
-#endif
        ushort i, j;
        uchar *bmap;
        uchar *fb;
        ushort *fb16;
-#if defined(CONFIG_MPC823)
-       immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
-       cpm8xx_t *cp = &(immr->im_cpm);
-#endif
        unsigned bpix = NBITS(panel_info.vl_bpix);
 
-       debug("Logo: width %d  height %d  colors %d  cmap %d\n",
-               BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
-               ARRAY_SIZE(bmp_logo_palette));
+       debug("Logo: width %d  height %d  colors %d\n",
+             BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS);
 
        bmap = &bmp_logo_bitmap[0];
        fb   = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
 
        if (bpix < 12) {
-               /* Leave room for default color map
-                * default case: generic system with no cmap (most likely 16bpp)
-                * cmap was set to the source palette, so no change is done.
-                * This avoids even more ifdefs in the next stanza
-                */
-#if defined(CONFIG_MPC823)
-               cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
-#elif defined(CONFIG_ATMEL_LCD)
-               cmap = (uint *)configuration_get_cmap();
-#else
-               cmap = configuration_get_cmap();
-#endif
-
                WATCHDOG_RESET();
-
-               /* Set color map */
-               for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
-                       ushort colreg = bmp_logo_palette[i];
-#ifdef CONFIG_ATMEL_LCD
-                       uint lut_entry;
-#ifdef CONFIG_ATMEL_LCD_BGR555
-                       lut_entry = ((colreg & 0x000F) << 11) |
-                                       ((colreg & 0x00F0) <<  2) |
-                                       ((colreg & 0x0F00) >>  7);
-#else /* CONFIG_ATMEL_LCD_RGB565 */
-                       lut_entry = ((colreg & 0x000F) << 1) |
-                                       ((colreg & 0x00F0) << 3) |
-                                       ((colreg & 0x0F00) << 4);
-#endif
-                       *(cmap + BMP_LOGO_OFFSET) = lut_entry;
-                       cmap++;
-#else /* !CONFIG_ATMEL_LCD */
-#ifdef  CONFIG_SYS_INVERT_COLORS
-                       *cmap++ = 0xffff - colreg;
-#else
-                       *cmap++ = colreg;
-#endif
-#endif /* CONFIG_ATMEL_LCD */
-               }
-
+               lcd_logo_set_cmap();
                WATCHDOG_RESET();
 
                for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
@@ -882,27 +600,17 @@ static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
 }
 #endif
 
-#if defined(CONFIG_MPC823)
-#define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
-#else
-#define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
-#endif
-
-#if defined(CONFIG_BMP_16BPP)
-#if defined(CONFIG_ATMEL_LCD_BGR555)
-static inline void fb_put_word(uchar **fb, uchar **from)
+__weak void fb_put_byte(uchar **fb, uchar **from)
 {
-       *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
-       *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
-       *from += 2;
+       *(*fb)++ = *(*from)++;
 }
-#else
-static inline void fb_put_word(uchar **fb, uchar **from)
+
+#if defined(CONFIG_BMP_16BPP)
+__weak void fb_put_word(uchar **fb, uchar **from)
 {
        *(*fb)++ = *(*from)++;
        *(*fb)++ = *(*from)++;
 }
-#endif
 #endif /* CONFIG_BMP_16BPP */
 
 int lcd_display_bitmap(ulong bmp_image, int x, int y)
@@ -967,11 +675,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
                                ( ((cte.red)   << 8) & 0xf800) |
                                ( ((cte.green) << 3) & 0x07e0) |
                                ( ((cte.blue)  >> 3) & 0x001f) ;
-#ifdef CONFIG_SYS_INVERT_COLORS
-                       *cmap = 0xffff - colreg;
-#else
                        *cmap = colreg;
-#endif
 #if defined(CONFIG_MPC823)
                        cmap--;
 #else
@@ -1024,7 +728,7 @@ int lcd_display_bitmap(ulong bmp_image, int x, int y)
                        WATCHDOG_RESET();
                        for (j = 0; j < width; j++) {
                                if (bpix != 16) {
-                                       FB_PUT_BYTE(fb, bmap);
+                                       fb_put_byte(&fb, &bmap);
                                } else {
                                        *(uint16_t *)fb = cmap_base[*(bmap++)];
                                        fb += sizeof(uint16_t) / sizeof(*fb);
@@ -1108,8 +812,8 @@ static void *lcd_logo(void)
        bitmap_plot(0, 0);
 
 #ifdef CONFIG_LCD_INFO
-       console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
-       console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
+       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 */
 
@@ -1144,12 +848,6 @@ static int on_splashimage(const char *name, const char *value, enum env_op op,
 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
 #endif
 
-void lcd_position_cursor(unsigned col, unsigned row)
-{
-       console_col = min_t(short, col, CONSOLE_COLS - 1);
-       console_row = min_t(short, row, CONSOLE_ROWS - 1);
-}
-
 int lcd_get_pixel_width(void)
 {
        return panel_info.vl_col;
@@ -1160,16 +858,6 @@ int lcd_get_pixel_height(void)
        return panel_info.vl_row;
 }
 
-int lcd_get_screen_rows(void)
-{
-       return CONSOLE_ROWS;
-}
-
-int lcd_get_screen_columns(void)
-{
-       return CONSOLE_COLS;
-}
-
 #if defined(CONFIG_LCD_DT_SIMPLEFB)
 static int lcd_dt_simplefb_configure_node(void *blob, int off)
 {