[U-Boot] [PATCH V3 00/12] cleanup and refactor lcd.c

This series is a first step towards an end goal of merging all CONFIG_LCD related functionality into CONFIG_VIDEO code. My plan is to start by refactoring lcd.c into something cleaner (less ifdefs) and more modular (split code into multiple files), then possibly refactor CONFIG_VIDEO code if needed, and then finally: move CONFIG_LCD related functionality over to CONFIG_VIDEO code, replacing as much CONFIG_LCD related code with CONFIG_VIDEO related code as possible.
This specific step eliminates some unused code and refactors lcd console stuff into its own file.
The patches ("lcd: rename console_(row|col)" to "lcd: make lcd_drawchars() independant of lcd_base") are preparatory patches meant to illustrate exactly what changed and where in the transition from lcd.c to lcd_console.c, and are not necesserily code improvements when viewed out of context.
Changes in V3: - Function documentation - Cache values of lcd_get(bg|fg)color() instead of calling the functions multiple times.
The whole series was rebased over current mainline, and compile tested for arm and powerpc.
Cc: Anatolij Gustschin agust@denx.de Cc: Wolfgang Denk wd@denx.de Cc: Simon Glass sjg@chromium.org Cc: Stephen Warren swarren@wwwdotorg.org
Entire series: Tested-by: Stephen Warren swarren@wwwdotorg.org Tested-by: Simon Glass sjg@chromium.org
Nikita Kiryanov (12): lcd: remove CONFIG_SYS_INVERT_COLORS lcd: cleanup lcd_drawchars mpc8xx_lcd: get rid of CONFIG_EDT32F10 lcd: remove LCD_MONOCHROME lcd: rename console_(row|col) lcd: replace CONSOLE_(ROWS|COLS) with variables lcd: expand console api lcd: get rid of COLOR_MASK lcd: introduce getters for bg/fg color lcd: make lcd_drawchars() independant of lcd_base lcd: refactor lcd console stuff into its own file lcd_console: remove unused defines
common/Makefile | 2 +- common/lcd.c | 313 +++++---------------------------------------- common/lcd_console.c | 211 ++++++++++++++++++++++++++++++ drivers/video/mpc8xx_lcd.c | 49 +------ drivers/video/pxa_lcd.c | 15 --- include/configs/R360MPI.h | 1 - include/lcd.h | 25 ++-- include/lcd_console.h | 86 +++++++++++++ 8 files changed, 347 insertions(+), 355 deletions(-) create mode 100644 common/lcd_console.c create mode 100644 include/lcd_console.h

No one is using CONFIG_SYS_INVERT_COLORS; remove related code.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Simon Glass sjg@chromium.org Cc: Anatolij Gustschin agust@denx.de Acked-by: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - No changes.
common/lcd.c | 8 -------- drivers/video/mpc8xx_lcd.c | 4 +--- 2 files changed, 1 insertion(+), 11 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c index 28b3fe7..c7d597e 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -685,11 +685,7 @@ void bitmap_plot(int x, int y) *(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 */ }
@@ -967,11 +963,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 diff --git a/drivers/video/mpc8xx_lcd.c b/drivers/video/mpc8xx_lcd.c index 2bc3ceb..98b9f5e 100644 --- a/drivers/video/mpc8xx_lcd.c +++ b/drivers/video/mpc8xx_lcd.c @@ -373,9 +373,7 @@ lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue) colreg = ((red & 0x0F) << 8) | ((green & 0x0F) << 4) | (blue & 0x0F) ; -#ifdef CONFIG_SYS_INVERT_COLORS - colreg ^= 0x0FFF; -#endif + *cmap_ptr = colreg;
debug ("setcolreg: reg %2d @ %p: R=%02X G=%02X B=%02X => %02X%02X\n",

Remove code duplication from lcd_drawchars().
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Anatolij Gustschin agust@denx.de Cc: Simon Glass sjg@chromium.org Acked-by: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - No changes.
common/lcd.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c index c7d597e..22bb488 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -346,19 +346,7 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
*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 +#else /* LCD_BPP == LCD_COLOR8 or LCD_COLOR16 or LCD_COLOR32 */ for (c = 0; c < 8; ++c) { *d++ = (bits & 0x80) ? lcd_color_fg : lcd_color_bg;

No one is using CONFIG_EDT32F10; remove related code.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Wolfgang Denk wd@denx.de Cc: Anatolij Gustschin agust@denx.de Acked-by: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - No changes.
drivers/video/mpc8xx_lcd.c | 28 ---------------------------- include/configs/R360MPI.h | 1 - 2 files changed, 29 deletions(-)
diff --git a/drivers/video/mpc8xx_lcd.c b/drivers/video/mpc8xx_lcd.c index 98b9f5e..3ea240d 100644 --- a/drivers/video/mpc8xx_lcd.c +++ b/drivers/video/mpc8xx_lcd.c @@ -34,11 +34,6 @@ #define CONFIG_LCD_INFO /* Display Logo, (C) and system info */ #endif
-#if defined(CONFIG_EDT32F10) -#undef CONFIG_LCD_LOGO -#undef CONFIG_LCD_INFO -#endif - /*----------------------------------------------------------------------*/ #ifdef CONFIG_KYOCERA_KCS057QV1AJ /* @@ -224,20 +219,6 @@ vidinfo_t panel_info = { }; #endif /* CONFIG_OPTREX_BW */
-/*-----------------------------------------------------------------*/ -#ifdef CONFIG_EDT32F10 -/* - * Emerging Display Technologies 320x240. Passive, monochrome, single scan. - */ -#define LCD_BPP LCD_MONOCHROME -#define LCD_DF 10 - -vidinfo_t panel_info = { - 320, 240, 0, 0, CONFIG_SYS_HIGH, CONFIG_SYS_HIGH, CONFIG_SYS_HIGH, CONFIG_SYS_HIGH, CONFIG_SYS_LOW, - LCD_BPP, 0, 0, 0, 0, 33, 0, 0, 0 -}; -#endif - /************************************************************************/ /* ----------------- chipset specific functions ----------------------- */ /************************************************************************/ @@ -305,7 +286,6 @@ void lcd_ctrl_init (void *lcdbase) immr->im_clkrst.car_sccr &= ~0x1F; immr->im_clkrst.car_sccr |= LCD_DF; /* was 8 */
-#if !defined(CONFIG_EDT32F10) /* Enable LCD on port D. */ immr->im_ioport.iop_pdpar |= 0x1FFF; @@ -315,14 +295,6 @@ void lcd_ctrl_init (void *lcdbase) */ immr->im_cpm.cp_pbpar |= 0x00005001; immr->im_cpm.cp_pbdir |= 0x00005001; -#else - /* Enable LCD on port D. - */ - immr->im_ioport.iop_pdpar |= 0x1DFF; - immr->im_ioport.iop_pdpar &= ~0x0200; - immr->im_ioport.iop_pddir |= 0x1FFF; - immr->im_ioport.iop_pddat |= 0x0200; -#endif
/* Load the physical address of the linear frame buffer * into the LCD controller. diff --git a/include/configs/R360MPI.h b/include/configs/R360MPI.h index 009d1cf..fbaf6a5 100644 --- a/include/configs/R360MPI.h +++ b/include/configs/R360MPI.h @@ -24,7 +24,6 @@
#define CONFIG_LCD #define CONFIG_MPC8XX_LCD -#undef CONFIG_EDT32F10 #define CONFIG_SHARP_LQ057Q3DC02
#define CONFIG_SPLASH_SCREEN

No one is using LCD_MONOCHROME; remove related code.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Wolfgang Denk wd@denx.de Cc: Anatolij Gustschin agust@denx.de Acked-by: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - No changes.
common/lcd.c | 30 ++---------------------------- drivers/video/mpc8xx_lcd.c | 17 ----------------- drivers/video/pxa_lcd.c | 15 --------------- include/lcd.h | 10 +--------- 4 files changed, 3 insertions(+), 69 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c index 22bb488..ed451a9 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -97,10 +97,7 @@ #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) || \ +#if (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \ (LCD_BPP == LCD_COLOR32) # define COLOR_MASK(c) (c) #else @@ -313,10 +310,6 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) 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) { @@ -330,33 +323,18 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) 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); -#else /* LCD_BPP == LCD_COLOR8 or LCD_COLOR16 or 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 } }
@@ -443,11 +421,7 @@ int drv_lcd_init(void) /*----------------------------------------------------------------------*/ void lcd_clear(void) { -#if LCD_BPP == LCD_MONOCHROME - /* Setting the palette */ - lcd_initcolregs(); - -#elif LCD_BPP == LCD_COLOR8 +#if LCD_BPP == LCD_COLOR8 /* Setting the palette */ lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0); diff --git a/drivers/video/mpc8xx_lcd.c b/drivers/video/mpc8xx_lcd.c index 3ea240d..3c16bf6 100644 --- a/drivers/video/mpc8xx_lcd.c +++ b/drivers/video/mpc8xx_lcd.c @@ -357,23 +357,6 @@ lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue)
/*----------------------------------------------------------------------*/
-#if LCD_BPP == LCD_MONOCHROME -static -void lcd_initcolregs (void) -{ - volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; - volatile cpm8xx_t *cp = &(immr->im_cpm); - ushort regno; - - for (regno = 0; regno < 16; regno++) { - cp->lcd_cmap[regno * 2] = 0; - cp->lcd_cmap[(regno * 2) + 1] = regno & 0x0f; - } -} -#endif - -/*----------------------------------------------------------------------*/ - void lcd_enable (void) { volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; diff --git a/drivers/video/pxa_lcd.c b/drivers/video/pxa_lcd.c index e19f6ac..f66f615 100644 --- a/drivers/video/pxa_lcd.c +++ b/drivers/video/pxa_lcd.c @@ -379,21 +379,6 @@ lcd_setcolreg (ushort regno, ushort red, ushort green, ushort blue) #endif /* LCD_COLOR8 */
/*----------------------------------------------------------------------*/ -#if LCD_BPP == LCD_MONOCHROME -void lcd_initcolregs (void) -{ - struct pxafb_info *fbi = &panel_info.pxa; - cmap = (ushort *)fbi->palette; - ushort regno; - - for (regno = 0; regno < 16; regno++) { - cmap[regno * 2] = 0; - cmap[(regno * 2) + 1] = regno & 0x0f; - } -} -#endif /* LCD_MONOCHROME */ - -/*----------------------------------------------------------------------*/ __weak void lcd_enable(void) { } diff --git a/include/lcd.h b/include/lcd.h index 020d880..01609ac 100644 --- a/include/lcd.h +++ b/include/lcd.h @@ -359,15 +359,7 @@ void lcd_sync(void); /************************************************************************/ /* ** CONSOLE CONSTANTS */ /************************************************************************/ -#if LCD_BPP == LCD_MONOCHROME - -/* - * Simple black/white definitions - */ -# define CONSOLE_COLOR_BLACK 0 -# define CONSOLE_COLOR_WHITE 1 /* Must remain last / highest */ - -#elif LCD_BPP == LCD_COLOR8 +#if LCD_BPP == LCD_COLOR8
/* * 8bpp color definitions

Rename console_(row|col) to console_curr_(row|col) to better distinguish it from console_(rows|cols).
This is a preparatory step for extracting lcd console code into its own file.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Simon Glass sjg@chromium.org Cc: Anatolij Gustschin agust@denx.de Acked-by: Simon Glass sjg@chromium.org Tested-by: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - New patch.
common/lcd.c | 54 +++++++++++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 27 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c index ed451a9..371f4a2 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -122,8 +122,8 @@ int lcd_line_length;
char lcd_is_enabled = 0;
-static short console_col; -static short console_row; +static short console_curr_col; +static short console_curr_row;
static void *lcd_console_address; static void *lcd_base; /* Start of framebuffer memory */ @@ -188,31 +188,31 @@ static void console_scrollup(void) } #endif lcd_sync(); - console_row -= rows; + console_curr_row -= rows; }
/*----------------------------------------------------------------------*/
static inline void console_back(void) { - if (--console_col < 0) { - console_col = CONSOLE_COLS-1 ; - if (--console_row < 0) - console_row = 0; + if (--console_curr_col < 0) { + console_curr_col = CONSOLE_COLS-1; + if (--console_curr_row < 0) + console_curr_row = 0; }
- lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, - console_row * VIDEO_FONT_HEIGHT, ' '); + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, + console_curr_row * VIDEO_FONT_HEIGHT, ' '); }
/*----------------------------------------------------------------------*/
static inline void console_newline(void) { - console_col = 0; + console_curr_col = 0;
/* Check if we need to scroll the terminal */ - if (++console_row >= CONSOLE_ROWS) + if (++console_curr_row >= CONSOLE_ROWS) console_scrollup(); else lcd_sync(); @@ -235,7 +235,7 @@ void lcd_putc(const char c)
switch (c) { case '\r': - console_col = 0; + console_curr_col = 0;
return; case '\n': @@ -243,10 +243,10 @@ void lcd_putc(const char c)
return; case '\t': /* Tab (8 chars alignment) */ - console_col += 8; - console_col &= ~7; + console_curr_col += 8; + console_curr_col &= ~7;
- if (console_col >= CONSOLE_COLS) + if (console_curr_col >= CONSOLE_COLS) console_newline();
return; @@ -255,9 +255,9 @@ void lcd_putc(const char c)
return; default: - lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, - console_row * VIDEO_FONT_HEIGHT, c); - if (++console_col >= CONSOLE_COLS) + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, + console_curr_row * VIDEO_FONT_HEIGHT, c); + if (++console_curr_col >= CONSOLE_COLS) console_newline(); } } @@ -464,8 +464,8 @@ void lcd_clear(void) debug("[LCD] Drawing the logo...\n"); lcd_console_address = lcd_logo();
- console_col = 0; - console_row = 0; + console_curr_col = 0; + console_curr_row = 0; lcd_sync(); }
@@ -508,11 +508,11 @@ static int lcd_init(void *lcdbase) lcd_enable();
/* Initialize the console */ - console_col = 0; + console_curr_col = 0; #ifdef CONFIG_LCD_INFO_BELOW_LOGO - console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; + console_curr_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; #else - console_row = 1; /* leave 1 blank line below logo */ + console_curr_row = 1; /* leave 1 blank line below logo */ #endif
return 0; @@ -1062,8 +1062,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; + console_curr_col = LCD_INFO_X / VIDEO_FONT_WIDTH; + console_curr_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT; lcd_show_board_info(); #endif /* CONFIG_LCD_INFO */
@@ -1100,8 +1100,8 @@ U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
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); + console_curr_col = min_t(short, col, CONSOLE_COLS - 1); + console_curr_row = min_t(short, row, CONSOLE_ROWS - 1); }
int lcd_get_pixel_width(void)

Replace CONSOLE_(ROWS|COLS) macros with variables, and assign the original macro values.
This is a preparatory step for extracting lcd console code into its own file.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Anatolij Gustschin agust@denx.de Cc: Simon Glass sjg@chromium.org Acked-by: Simon Glass sjg@chromium.org Tested-by: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - New patch.
common/lcd.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c index 371f4a2..f8fff90 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -81,20 +81,12 @@ /************************************************************************/ /* ** 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_SIZE (CONSOLE_ROW_SIZE * console_rows) #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
#if (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \ @@ -124,6 +116,8 @@ char lcd_is_enabled = 0;
static short console_curr_col; static short console_curr_row; +static short console_cols; +static short console_rows;
static void *lcd_console_address; static void *lcd_base; /* Start of framebuffer memory */ @@ -196,7 +190,7 @@ static void console_scrollup(void) static inline void console_back(void) { if (--console_curr_col < 0) { - console_curr_col = CONSOLE_COLS-1; + console_curr_col = console_cols - 1; if (--console_curr_row < 0) console_curr_row = 0; } @@ -212,7 +206,7 @@ static inline void console_newline(void) console_curr_col = 0;
/* Check if we need to scroll the terminal */ - if (++console_curr_row >= CONSOLE_ROWS) + if (++console_curr_row >= console_rows) console_scrollup(); else lcd_sync(); @@ -246,7 +240,7 @@ void lcd_putc(const char c) console_curr_col += 8; console_curr_col &= ~7;
- if (console_curr_col >= CONSOLE_COLS) + if (console_curr_col >= console_cols) console_newline();
return; @@ -257,7 +251,7 @@ void lcd_putc(const char c) default: lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, console_curr_row * VIDEO_FONT_HEIGHT, c); - if (++console_curr_col >= CONSOLE_COLS) + if (++console_curr_col >= console_cols) console_newline(); } } @@ -464,6 +458,13 @@ void lcd_clear(void) debug("[LCD] Drawing the logo...\n"); lcd_console_address = 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; +#endif + console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH; console_curr_col = 0; console_curr_row = 0; lcd_sync(); @@ -1100,8 +1101,8 @@ U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
void lcd_position_cursor(unsigned col, unsigned row) { - console_curr_col = min_t(short, col, CONSOLE_COLS - 1); - console_curr_row = min_t(short, row, CONSOLE_ROWS - 1); + console_curr_col = min_t(short, col, console_cols - 1); + console_curr_row = min_t(short, row, console_rows - 1); }
int lcd_get_pixel_width(void) @@ -1116,12 +1117,12 @@ int lcd_get_pixel_height(void)
int lcd_get_screen_rows(void) { - return CONSOLE_ROWS; + return console_rows; }
int lcd_get_screen_columns(void) { - return CONSOLE_COLS; + return console_cols; }
#if defined(CONFIG_LCD_DT_SIMPLEFB)

Introduce set_console_row(), set_console_col(), and lcd_init_console(). Use these functions in lcd functions: lcd_init(), lcd_clear(), lcd_logo().
This is a preparatory step for extracting lcd console code into its own file.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Anatolij Gustschin agust@denx.de Cc: Simon Glass sjg@chromium.org Acked-by: Simon Glass sjg@chromium.org Tested-by: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - New patch.
common/lcd.c | 35 ++++++++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 9 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c index f8fff90..bc15c78 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -155,6 +155,25 @@ void lcd_set_flush_dcache(int flush) lcd_flush_dcache = (flush != 0); }
+void lcd_init_console(void *address, int rows, int cols) +{ + console_curr_col = 0; + console_curr_row = 0; + console_cols = cols; + console_rows = rows; + lcd_console_address = address; +} + +void lcd_set_col(short col) +{ + console_curr_col = col; +} + +void lcd_set_row(short row) +{ + console_curr_row = row; +} + /*----------------------------------------------------------------------*/
static void console_scrollup(void) @@ -415,6 +434,7 @@ int drv_lcd_init(void) /*----------------------------------------------------------------------*/ void lcd_clear(void) { + short console_rows, console_cols; #if LCD_BPP == LCD_COLOR8 /* Setting the palette */ lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); @@ -456,8 +476,6 @@ void lcd_clear(void) #endif /* Paint the logo and retrieve LCD base address */ debug("[LCD] Drawing the logo...\n"); - lcd_console_address = 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; @@ -465,8 +483,7 @@ void lcd_clear(void) console_rows = panel_info.vl_row / VIDEO_FONT_HEIGHT; #endif console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH; - console_curr_col = 0; - console_curr_row = 0; + lcd_init_console(lcd_logo(), console_rows, console_cols); lcd_sync(); }
@@ -509,11 +526,11 @@ static int lcd_init(void *lcdbase) lcd_enable();
/* Initialize the console */ - console_curr_col = 0; + lcd_set_col(0); #ifdef CONFIG_LCD_INFO_BELOW_LOGO - console_curr_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; + lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT); #else - console_curr_row = 1; /* leave 1 blank line below logo */ + lcd_set_row(1); /* leave 1 blank line below logo */ #endif
return 0; @@ -1063,8 +1080,8 @@ static void *lcd_logo(void) bitmap_plot(0, 0);
#ifdef CONFIG_LCD_INFO - console_curr_col = LCD_INFO_X / VIDEO_FONT_WIDTH; - console_curr_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 */

COLOR_MASK macro doesn't do anything; Remove it to reduce visual complexity.
This is a preparatory step for extracting lcd console code into its own file.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Anatolij Gustschin agust@denx.de Cc: Simon Glass sjg@chromium.org Acked-by: Simon Glass sjg@chromium.org Tested-by: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - New patch.
common/lcd.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c index bc15c78..f98aaaf 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -89,10 +89,8 @@ #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows) #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
-#if (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
@@ -188,7 +186,7 @@ static void console_scrollup(void) /* Clear the last rows */ #if (LCD_BPP != LCD_COLOR32) memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows, - COLOR_MASK(lcd_color_bg), + lcd_color_bg, CONSOLE_ROW_SIZE * rows); #else u32 *ppix = lcd_console_address + @@ -197,7 +195,7 @@ static void console_scrollup(void) for (i = 0; i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix); i++) { - *ppix++ = COLOR_MASK(lcd_color_bg); + *ppix++ = lcd_color_bg; } #endif lcd_sync(); @@ -462,7 +460,7 @@ void lcd_clear(void) /* set framebuffer to background color */ #if (LCD_BPP != LCD_COLOR32) memset((char *)lcd_base, - COLOR_MASK(lcd_color_bg), + lcd_color_bg, lcd_line_length * panel_info.vl_row); #else u32 *ppix = lcd_base; @@ -470,7 +468,7 @@ void lcd_clear(void) for (i = 0; i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix); i++) { - *ppix++ = COLOR_MASK(lcd_color_bg); + *ppix++ = lcd_color_bg; } #endif #endif

Introduce lcd_getbgcolor() and lcd_getfgcolor(), and use them where applicable.
This is a preparatory step for extracting lcd console code into its own file.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Anatolij Gustschin agust@denx.de Cc: Simon Glass sjg@chromium.org --- Changes in V3: - Instead of invoking lcd_get(bg|fg)color() each time, do it only once and cache the value. This is done in console_scrollup(), lcd_drawchars(), and drv_lcd_init().
Changes in V2: - New patch.
common/lcd.c | 31 ++++++++++++++++++++++--------- include/lcd.h | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c index f98aaaf..a29e7a2 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -177,6 +177,7 @@ void lcd_set_row(short row) static void console_scrollup(void) { const int rows = CONFIG_CONSOLE_SCROLL_LINES; + int bg_color = lcd_getbgcolor();
/* Copy up rows ignoring those that will be overwritten */ memcpy(CONSOLE_ROW_FIRST, @@ -186,8 +187,7 @@ static void console_scrollup(void) /* Clear the last rows */ #if (LCD_BPP != LCD_COLOR32) memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows, - lcd_color_bg, - CONSOLE_ROW_SIZE * rows); + bg_color, CONSOLE_ROW_SIZE * rows); #else u32 *ppix = lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows; @@ -195,7 +195,7 @@ static void console_scrollup(void) for (i = 0; i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix); i++) { - *ppix++ = lcd_color_bg; + *ppix++ = bg_color; } #endif lcd_sync(); @@ -316,6 +316,7 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) { uchar *dest; ushort row; + int fg_color, bg_color;
#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) y += BMP_LOGO_HEIGHT; @@ -334,6 +335,8 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) uchar *d = dest; #endif
+ fg_color = lcd_getfgcolor(); + bg_color = lcd_getbgcolor(); for (i = 0; i < count; ++i) { uchar c, bits;
@@ -341,8 +344,7 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
for (c = 0; c < 8; ++c) { - *d++ = (bits & 0x80) ? - lcd_color_fg : lcd_color_bg; + *d++ = (bits & 0x80) ? fg_color : bg_color; bits <<= 1; } } @@ -433,6 +435,7 @@ int drv_lcd_init(void) void lcd_clear(void) { short console_rows, console_cols; + int bg_color; #if LCD_BPP == LCD_COLOR8 /* Setting the palette */ lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); @@ -449,9 +452,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 @@ -459,16 +464,14 @@ void lcd_clear(void) #else /* set framebuffer to background color */ #if (LCD_BPP != LCD_COLOR32) - memset((char *)lcd_base, - 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++ = lcd_color_bg; + *ppix++ = bg_color; } #endif #endif @@ -575,6 +578,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) @@ -582,6 +590,11 @@ static void lcd_setbgcolor(int color) lcd_color_bg = color; }
+int lcd_getbgcolor(void) +{ + return lcd_color_bg; +} + /************************************************************************/ /* ** Chipset depending Bitmap / Logo stuff... */ /************************************************************************/ diff --git a/include/lcd.h b/include/lcd.h index 01609ac..2235b9b 100644 --- a/include/lcd.h +++ b/include/lcd.h @@ -291,6 +291,20 @@ int lcd_get_screen_rows(void); int lcd_get_screen_columns(void);
/** + * Get the background color of the LCD + * + * @return background color value + */ +int lcd_getbgcolor(void); + +/** + * Get the foreground color of the LCD + * + * @return foreground color value + */ +int lcd_getfgcolor(void); + +/** * Set the position of the text cursor * * @param col Column to place cursor (0 = left side)

On 8 December 2014 at 08:14, Nikita Kiryanov nikita@compulab.co.il wrote:
Introduce lcd_getbgcolor() and lcd_getfgcolor(), and use them where applicable.
This is a preparatory step for extracting lcd console code into its own file.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Anatolij Gustschin agust@denx.de Cc: Simon Glass sjg@chromium.org
Acked-by: Simon Glass sjg@chromium.org
Changes in V3: - Instead of invoking lcd_get(bg|fg)color() each time, do it only once and cache the value. This is done in console_scrollup(), lcd_drawchars(), and drv_lcd_init().
Changes in V2: - New patch.
common/lcd.c | 31 ++++++++++++++++++++++--------- include/lcd.h | 14 ++++++++++++++ 2 files changed, 36 insertions(+), 9 deletions(-)

lcd_logo() has the following return value:
#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
This return value gets assigned to lcd_console_address. lcd_console_address is not assigned or modified anywhere else. Thus:
#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO): y' = BMP_LOGO_HEIGHT + y; lcd_base + y' * lcd_line_length == lcd_base + (BMP_LOGO_HEIGHT + y) * lcd_line_length == lcd_base + BMP_LOGO_HEIGHT * lcd_line_length + y * lcd_line_length == lcd_console_address + y * lcd_line_length #else lcd_base + y * lcd_line_length == lcd_console_address + y * lcd_line_length #endif
This is a preparatory step for extracting lcd console code into its own file.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Anatolij Gustschin agust@denx.de Cc: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - New patch.
common/lcd.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c index a29e7a2..0c90502 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -318,11 +318,8 @@ static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) ushort row; int fg_color, bg_color;
-#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) - y += BMP_LOGO_HEIGHT; -#endif - - dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8); + dest = (uchar *)(lcd_console_address + + y * lcd_line_length + x * NBITS(LCD_BPP) / 8);
for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { uchar *s = str;

common/lcd.c is a mix of code portions that do different but related things. To improve modularity, the various code portions should be split into their own modules. Separate lcd console code into its own file.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Anatolij Gustschin agust@denx.de Cc: Simon Glass sjg@chromium.org Cc: Stephen Warren swarren@wwwdotorg.org Acked-by: Simon Glass sjg@chromium.org Tested-by: Simon Glass sjg@chromium.org --- Changes in V3: - Updated comment for lcd_printf().
Changes in V2: - New patch.
common/Makefile | 2 +- common/lcd.c | 229 -------------------------------------------------- common/lcd_console.c | 215 +++++++++++++++++++++++++++++++++++++++++++++++ include/lcd.h | 1 + include/lcd_console.h | 86 +++++++++++++++++++ 5 files changed, 303 insertions(+), 230 deletions(-) create mode 100644 common/lcd_console.c create mode 100644 include/lcd_console.h
diff --git a/common/Makefile b/common/Makefile index 9c47e20..66584fc 100644 --- a/common/Makefile +++ b/common/Makefile @@ -206,7 +206,7 @@ obj-$(CONFIG_CMD_KGDB) += kgdb.o kgdb_stubs.o obj-$(CONFIG_I2C_EDID) += edid.o obj-$(CONFIG_KALLSYMS) += kallsyms.o obj-y += splash.o -obj-$(CONFIG_LCD) += lcd.o +obj-$(CONFIG_LCD) += lcd.o lcd_console.o obj-$(CONFIG_LYNXKDI) += lynxkdi.o obj-$(CONFIG_MENU) += menu.o obj-$(CONFIG_MODEM_SUPPORT) += modem.o diff --git a/common/lcd.c b/common/lcd.c index 0c90502..bef8079 100644 --- a/common/lcd.c +++ b/common/lcd.c @@ -73,22 +73,6 @@ #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 */ -/************************************************************************/ -#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_COLOR8) && (LCD_BPP != LCD_COLOR16) && \ (LCD_BPP != LCD_COLOR32) # error Unsupported LCD BPP. @@ -96,9 +80,6 @@
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); @@ -112,12 +93,6 @@ int lcd_line_length;
char lcd_is_enabled = 0;
-static short console_curr_col; -static short console_curr_row; -static short console_cols; -static short console_rows; - -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 */ @@ -153,82 +128,6 @@ void lcd_set_flush_dcache(int flush) lcd_flush_dcache = (flush != 0); }
-void lcd_init_console(void *address, int rows, int cols) -{ - console_curr_col = 0; - console_curr_row = 0; - console_cols = cols; - console_rows = rows; - lcd_console_address = address; -} - -void lcd_set_col(short col) -{ - console_curr_col = col; -} - -void lcd_set_row(short row) -{ - console_curr_row = row; -} - -/*----------------------------------------------------------------------*/ - -static void console_scrollup(void) -{ - const int rows = CONFIG_CONSOLE_SCROLL_LINES; - int bg_color = lcd_getbgcolor(); - - /* 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, - bg_color, 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++ = bg_color; - } -#endif - lcd_sync(); - console_curr_row -= rows; -} - -/*----------------------------------------------------------------------*/ - -static inline void console_back(void) -{ - if (--console_curr_col < 0) { - console_curr_col = console_cols - 1; - if (--console_curr_row < 0) - console_curr_row = 0; - } - - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, - console_curr_row * VIDEO_FONT_HEIGHT, ' '); -} - -/*----------------------------------------------------------------------*/ - -static inline void console_newline(void) -{ - console_curr_col = 0; - - /* Check if we need to scroll the terminal */ - if (++console_curr_row >= console_rows) - console_scrollup(); - else - lcd_sync(); -} - /*----------------------------------------------------------------------*/
static void lcd_stub_putc(struct stdio_dev *dev, const char c) @@ -236,123 +135,11 @@ 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_curr_col = 0; - - return; - case '\n': - console_newline(); - - return; - case '\t': /* Tab (8 chars alignment) */ - console_curr_col += 8; - console_curr_col &= ~7; - - if (console_curr_col >= console_cols) - console_newline(); - - return; - case '\b': - console_back(); - - return; - default: - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, - console_curr_row * VIDEO_FONT_HEIGHT, c); - if (++console_curr_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; - int fg_color, bg_color; - - dest = (uchar *)(lcd_console_address + - 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 - - fg_color = lcd_getfgcolor(); - bg_color = lcd_getbgcolor(); - for (i = 0; i < count; ++i) { - uchar c, bits; - - c = *s++; - bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; - - for (c = 0; c < 8; ++c) { - *d++ = (bits & 0x80) ? fg_color : bg_color; - bits <<= 1; - } - } - } -} - -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 */ /************************************************************************/ @@ -1124,12 +911,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_curr_col = min_t(short, col, console_cols - 1); - console_curr_row = min_t(short, row, console_rows - 1); -} - int lcd_get_pixel_width(void) { return panel_info.vl_col; @@ -1140,16 +921,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) { diff --git a/common/lcd_console.c b/common/lcd_console.c new file mode 100644 index 0000000..f948e5a --- /dev/null +++ b/common/lcd_console.c @@ -0,0 +1,215 @@ +/* + * (C) Copyright 2001-2014 + * DENX Software Engineering -- wd@denx.de + * Compulab Ltd - http://compulab.co.il/ + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include <common.h> +#include <lcd.h> +#include <video_font.h> /* Get font data, width and height */ + +#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) + +static short console_curr_col; +static short console_curr_row; +static short console_cols; +static short console_rows; +static void *lcd_console_address; + +void lcd_init_console(void *address, int rows, int cols) +{ + console_curr_col = 0; + console_curr_row = 0; + console_cols = cols; + console_rows = rows; + lcd_console_address = address; +} + +void lcd_set_col(short col) +{ + console_curr_col = col; +} + +void lcd_set_row(short row) +{ + console_curr_row = row; +} + +void lcd_position_cursor(unsigned col, unsigned row) +{ + console_curr_col = min_t(short, col, console_cols - 1); + console_curr_row = min_t(short, row, console_rows - 1); +} + +int lcd_get_screen_rows(void) +{ + return console_rows; +} + +int lcd_get_screen_columns(void) +{ + return console_cols; +} + +static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) +{ + uchar *dest; + ushort row; + int fg_color, bg_color; + + dest = (uchar *)(lcd_console_address + + 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 + + fg_color = lcd_getfgcolor(); + bg_color = lcd_getbgcolor(); + for (i = 0; i < count; ++i) { + uchar c, bits; + + c = *s++; + bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; + + for (c = 0; c < 8; ++c) { + *d++ = (bits & 0x80) ? fg_color : bg_color; + bits <<= 1; + } + } + } +} + +static inline void lcd_putc_xy(ushort x, ushort y, uchar c) +{ + lcd_drawchars(x, y, &c, 1); +} + +static void console_scrollup(void) +{ + const int rows = CONFIG_CONSOLE_SCROLL_LINES; + int bg_color = lcd_getbgcolor(); + + /* 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, + bg_color, 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++ = bg_color; + } +#endif + lcd_sync(); + console_curr_row -= rows; +} + +static inline void console_back(void) +{ + if (--console_curr_col < 0) { + console_curr_col = console_cols - 1; + if (--console_curr_row < 0) + console_curr_row = 0; + } + + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, + console_curr_row * VIDEO_FONT_HEIGHT, ' '); +} + +static inline void console_newline(void) +{ + console_curr_col = 0; + + /* Check if we need to scroll the terminal */ + if (++console_curr_row >= console_rows) + console_scrollup(); + else + lcd_sync(); +} + +void lcd_putc(const char c) +{ + if (!lcd_is_enabled) { + serial_putc(c); + + return; + } + + switch (c) { + case '\r': + console_curr_col = 0; + + return; + case '\n': + console_newline(); + + return; + case '\t': /* Tab (8 chars alignment) */ + console_curr_col += 8; + console_curr_col &= ~7; + + if (console_curr_col >= console_cols) + console_newline(); + + return; + case '\b': + console_back(); + + return; + default: + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH, + console_curr_row * VIDEO_FONT_HEIGHT, c); + if (++console_curr_col >= console_cols) + console_newline(); + } +} + +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); +} diff --git a/include/lcd.h b/include/lcd.h index 2235b9b..160f940 100644 --- a/include/lcd.h +++ b/include/lcd.h @@ -12,6 +12,7 @@
#ifndef _LCD_H_ #define _LCD_H_ +#include <lcd_console.h>
extern char lcd_is_enabled;
diff --git a/include/lcd_console.h b/include/lcd_console.h new file mode 100644 index 0000000..429214d --- /dev/null +++ b/include/lcd_console.h @@ -0,0 +1,86 @@ +/* + * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/ + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +/* By default we scroll by a single line */ +#ifndef CONFIG_CONSOLE_SCROLL_LINES +#define CONFIG_CONSOLE_SCROLL_LINES 1 +#endif + +/** + * lcd_init_console() - Initialize lcd console parameters + * + * Setup the address of console base, and the number of rows and columns the + * console has. + * + * @address: Console base address + * @rows: Number of rows in the console + * @cols: Number of columns in the console + */ +void lcd_init_console(void *address, int rows, int cols); + +/** + * lcd_set_col() - Set the number of the current lcd console column + * + * Set the number of the console column where the cursor is. + * + * @col: Column number + */ +void lcd_set_col(short col); + +/** + * lcd_set_row() - Set the number of the current lcd console row + * + * Set the number of the console row where the cursor is. + * + * @row: Row number + */ +void lcd_set_row(short row); + +/** + * lcd_position_cursor() - Position the cursor on the screen + * + * Position the cursor at the given coordinates on the screen. + * + * @col: Column number + * @row: Row number + */ +void lcd_position_cursor(unsigned col, unsigned row); + +/** + * lcd_get_screen_rows() - Get the total number of screen rows + * + * @return: Number of screen rows + */ +int lcd_get_screen_rows(void); + +/** + * lcd_get_screen_columns() - Get the total number of screen columns + * + * @return: Number of screen columns + */ +int lcd_get_screen_columns(void); + +/** + * lcd_putc() - Print to screen a single character at the location of the cursor + * + * @c: The character to print + */ +void lcd_putc(const char c); + +/** + * lcd_puts() - Print to screen a string at the location of the cursor + * + * @s: The string to print + */ +void lcd_puts(const char *s); + +/** + * lcd_printf() - Print to screen a formatted string at location of the cursor + * + * @fmt: The formatted string to print + * @...: The arguments for the formatted string + */ +void lcd_printf(const char *fmt, ...);

CONSOLE_ROW_SECOND, CONSOLE_ROW_LAST, and CONSOLE_SCROLL_SIZE are unused. Remove them.
Signed-off-by: Nikita Kiryanov nikita@compulab.co.il Cc: Anatolij Gustschin agust@denx.de Cc: Simon Glass sjg@chromium.org Acked-by: Simon Glass sjg@chromium.org Tested-by: Simon Glass sjg@chromium.org --- Changes in V3: - No changes.
Changes in V2: - New patch.
common/lcd_console.c | 4 ---- 1 file changed, 4 deletions(-)
diff --git a/common/lcd_console.c b/common/lcd_console.c index f948e5a..74c388a 100644 --- a/common/lcd_console.c +++ b/common/lcd_console.c @@ -12,11 +12,7 @@
#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)
static short console_curr_col; static short console_curr_row;

Gentle ping.
On 12/08/2014 05:14 PM, Nikita Kiryanov wrote:
This series is a first step towards an end goal of merging all CONFIG_LCD related functionality into CONFIG_VIDEO code. My plan is to start by refactoring lcd.c into something cleaner (less ifdefs) and more modular (split code into multiple files), then possibly refactor CONFIG_VIDEO code if needed, and then finally: move CONFIG_LCD related functionality over to CONFIG_VIDEO code, replacing as much CONFIG_LCD related code with CONFIG_VIDEO related code as possible.
This specific step eliminates some unused code and refactors lcd console stuff into its own file.
The patches ("lcd: rename console_(row|col)" to "lcd: make lcd_drawchars() independant of lcd_base") are preparatory patches meant to illustrate exactly what changed and where in the transition from lcd.c to lcd_console.c, and are not necesserily code improvements when viewed out of context.
Changes in V3:
- Function documentation
- Cache values of lcd_get(bg|fg)color() instead of calling the functions multiple times.
The whole series was rebased over current mainline, and compile tested for arm and powerpc.
Cc: Anatolij Gustschin agust@denx.de Cc: Wolfgang Denk wd@denx.de Cc: Simon Glass sjg@chromium.org Cc: Stephen Warren swarren@wwwdotorg.org
Entire series: Tested-by: Stephen Warren swarren@wwwdotorg.org Tested-by: Simon Glass sjg@chromium.org
Nikita Kiryanov (12): lcd: remove CONFIG_SYS_INVERT_COLORS lcd: cleanup lcd_drawchars mpc8xx_lcd: get rid of CONFIG_EDT32F10 lcd: remove LCD_MONOCHROME lcd: rename console_(row|col) lcd: replace CONSOLE_(ROWS|COLS) with variables lcd: expand console api lcd: get rid of COLOR_MASK lcd: introduce getters for bg/fg color lcd: make lcd_drawchars() independant of lcd_base lcd: refactor lcd console stuff into its own file lcd_console: remove unused defines
common/Makefile | 2 +- common/lcd.c | 313 +++++---------------------------------------- common/lcd_console.c | 211 ++++++++++++++++++++++++++++++ drivers/video/mpc8xx_lcd.c | 49 +------ drivers/video/pxa_lcd.c | 15 --- include/configs/R360MPI.h | 1 - include/lcd.h | 25 ++-- include/lcd_console.h | 86 +++++++++++++ 8 files changed, 347 insertions(+), 355 deletions(-) create mode 100644 common/lcd_console.c create mode 100644 include/lcd_console.h

Hi Nikita,
On 15 December 2014 at 05:02, Nikita Kiryanov nikita@compulab.co.il wrote:
Gentle ping.
On 12/08/2014 05:14 PM, Nikita Kiryanov wrote:
This series is a first step towards an end goal of merging all CONFIG_LCD related functionality into CONFIG_VIDEO code. My plan is to start by refactoring lcd.c into something cleaner (less ifdefs) and more modular (split code into multiple files), then possibly refactor CONFIG_VIDEO code if needed, and then finally: move CONFIG_LCD related functionality over to CONFIG_VIDEO code, replacing as much CONFIG_LCD related code with CONFIG_VIDEO related code as possible.
This specific step eliminates some unused code and refactors lcd console stuff into its own file.
The patches ("lcd: rename console_(row|col)" to "lcd: make lcd_drawchars() independant of lcd_base") are preparatory patches meant to illustrate exactly what changed and where in the transition from lcd.c to lcd_console.c, and are not necesserily code improvements when viewed out of context.
Changes in V3: - Function documentation - Cache values of lcd_get(bg|fg)color() instead of calling the functions multiple times.
The whole series was rebased over current mainline, and compile tested for arm and powerpc.
Cc: Anatolij Gustschin agust@denx.de Cc: Wolfgang Denk wd@denx.de Cc: Simon Glass sjg@chromium.org Cc: Stephen Warren swarren@wwwdotorg.org
Entire series: Tested-by: Stephen Warren swarren@wwwdotorg.org Tested-by: Simon Glass sjg@chromium.org
Nikita Kiryanov (12): lcd: remove CONFIG_SYS_INVERT_COLORS lcd: cleanup lcd_drawchars mpc8xx_lcd: get rid of CONFIG_EDT32F10 lcd: remove LCD_MONOCHROME lcd: rename console_(row|col) lcd: replace CONSOLE_(ROWS|COLS) with variables lcd: expand console api lcd: get rid of COLOR_MASK lcd: introduce getters for bg/fg color lcd: make lcd_drawchars() independant of lcd_base lcd: refactor lcd console stuff into its own file lcd_console: remove unused defines
common/Makefile | 2 +- common/lcd.c | 313 +++++---------------------------------------- common/lcd_console.c | 211 ++++++++++++++++++++++++++++++ drivers/video/mpc8xx_lcd.c | 49 +------ drivers/video/pxa_lcd.c | 15 --- include/configs/R360MPI.h | 1 - include/lcd.h | 25 ++-- include/lcd_console.h | 86 +++++++++++++ 8 files changed, 347 insertions(+), 355 deletions(-) create mode 100644 common/lcd_console.c create mode 100644 include/lcd_console.h
I think Anatolij will be applying this. Does it go into this release?
Regards, Simon

Gentle ping.
On 12/08/2014 05:14 PM, Nikita Kiryanov wrote:
This series is a first step towards an end goal of merging all CONFIG_LCD related functionality into CONFIG_VIDEO code. My plan is to start by refactoring lcd.c into something cleaner (less ifdefs) and more modular (split code into multiple files), then possibly refactor CONFIG_VIDEO code if needed, and then finally: move CONFIG_LCD related functionality over to CONFIG_VIDEO code, replacing as much CONFIG_LCD related code with CONFIG_VIDEO related code as possible.
This specific step eliminates some unused code and refactors lcd console stuff into its own file.
The patches ("lcd: rename console_(row|col)" to "lcd: make lcd_drawchars() independant of lcd_base") are preparatory patches meant to illustrate exactly what changed and where in the transition from lcd.c to lcd_console.c, and are not necesserily code improvements when viewed out of context.
Changes in V3:
- Function documentation
- Cache values of lcd_get(bg|fg)color() instead of calling the functions multiple times.
The whole series was rebased over current mainline, and compile tested for arm and powerpc.
Cc: Anatolij Gustschin agust@denx.de Cc: Wolfgang Denk wd@denx.de Cc: Simon Glass sjg@chromium.org Cc: Stephen Warren swarren@wwwdotorg.org
Entire series: Tested-by: Stephen Warren swarren@wwwdotorg.org Tested-by: Simon Glass sjg@chromium.org
Nikita Kiryanov (12): lcd: remove CONFIG_SYS_INVERT_COLORS lcd: cleanup lcd_drawchars mpc8xx_lcd: get rid of CONFIG_EDT32F10 lcd: remove LCD_MONOCHROME lcd: rename console_(row|col) lcd: replace CONSOLE_(ROWS|COLS) with variables lcd: expand console api lcd: get rid of COLOR_MASK lcd: introduce getters for bg/fg color lcd: make lcd_drawchars() independant of lcd_base lcd: refactor lcd console stuff into its own file lcd_console: remove unused defines
common/Makefile | 2 +- common/lcd.c | 313 +++++---------------------------------------- common/lcd_console.c | 211 ++++++++++++++++++++++++++++++ drivers/video/mpc8xx_lcd.c | 49 +------ drivers/video/pxa_lcd.c | 15 --- include/configs/R360MPI.h | 1 - include/lcd.h | 25 ++-- include/lcd_console.h | 86 +++++++++++++ 8 files changed, 347 insertions(+), 355 deletions(-) create mode 100644 common/lcd_console.c create mode 100644 include/lcd_console.h

Hi Nikita,
On Thu, 08 Jan 2015 14:26:06 +0200 Nikita Kiryanov nikita@compulab.co.il wrote:
Gentle ping.
sorry for delay and thanks for your patience. Series now applied to u-boot-video/next.
Thanks,
Anatolij
participants (3)
-
Anatolij Gustschin
-
Nikita Kiryanov
-
Simon Glass