Commit 904672ee489280cf26793e0a590505a2659dae09

Authored by Nikita Kiryanov
Committed by Anatolij Gustschin
1 parent 88b326a31e

lcd: refactor lcd console stuff into its own file

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>

Showing 5 changed files with 303 additions and 230 deletions Side-by-side Diff

... ... @@ -196,7 +196,7 @@
196 196 obj-$(CONFIG_I2C_EDID) += edid.o
197 197 obj-$(CONFIG_KALLSYMS) += kallsyms.o
198 198 obj-y += splash.o
199   -obj-$(CONFIG_LCD) += lcd.o
  199 +obj-$(CONFIG_LCD) += lcd.o lcd_console.o
200 200 obj-$(CONFIG_LYNXKDI) += lynxkdi.o
201 201 obj-$(CONFIG_MENU) += menu.o
202 202 obj-$(CONFIG_MODEM_SUPPORT) += modem.o
... ... @@ -73,22 +73,6 @@
73 73 #define CONFIG_LCD_ALIGNMENT PAGE_SIZE
74 74 #endif
75 75  
76   -/* By default we scroll by a single line */
77   -#ifndef CONFIG_CONSOLE_SCROLL_LINES
78   -#define CONFIG_CONSOLE_SCROLL_LINES 1
79   -#endif
80   -
81   -/************************************************************************/
82   -/* ** CONSOLE DEFINITIONS & FUNCTIONS */
83   -/************************************************************************/
84   -#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
85   -#define CONSOLE_ROW_FIRST lcd_console_address
86   -#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
87   -#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
88   - - CONSOLE_ROW_SIZE)
89   -#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows)
90   -#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
91   -
92 76 #if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \
93 77 (LCD_BPP != LCD_COLOR32)
94 78 # error Unsupported LCD BPP.
... ... @@ -96,9 +80,6 @@
96 80  
97 81 DECLARE_GLOBAL_DATA_PTR;
98 82  
99   -static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
100   -static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
101   -
102 83 static int lcd_init(void *lcdbase);
103 84  
104 85 static void *lcd_logo(void);
... ... @@ -112,12 +93,6 @@
112 93  
113 94 char lcd_is_enabled = 0;
114 95  
115   -static short console_curr_col;
116   -static short console_curr_row;
117   -static short console_cols;
118   -static short console_rows;
119   -
120   -static void *lcd_console_address;
121 96 static void *lcd_base; /* Start of framebuffer memory */
122 97  
123 98 static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
124 99  
125 100  
126 101  
127 102  
... ... @@ -153,207 +128,19 @@
153 128 lcd_flush_dcache = (flush != 0);
154 129 }
155 130  
156   -void lcd_init_console(void *address, int rows, int cols)
157   -{
158   - console_curr_col = 0;
159   - console_curr_row = 0;
160   - console_cols = cols;
161   - console_rows = rows;
162   - lcd_console_address = address;
163   -}
164   -
165   -void lcd_set_col(short col)
166   -{
167   - console_curr_col = col;
168   -}
169   -
170   -void lcd_set_row(short row)
171   -{
172   - console_curr_row = row;
173   -}
174   -
175 131 /*----------------------------------------------------------------------*/
176 132  
177   -static void console_scrollup(void)
178   -{
179   - const int rows = CONFIG_CONSOLE_SCROLL_LINES;
180   - int bg_color = lcd_getbgcolor();
181   -
182   - /* Copy up rows ignoring those that will be overwritten */
183   - memcpy(CONSOLE_ROW_FIRST,
184   - lcd_console_address + CONSOLE_ROW_SIZE * rows,
185   - CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
186   -
187   - /* Clear the last rows */
188   -#if (LCD_BPP != LCD_COLOR32)
189   - memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
190   - bg_color, CONSOLE_ROW_SIZE * rows);
191   -#else
192   - u32 *ppix = lcd_console_address +
193   - CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
194   - u32 i;
195   - for (i = 0;
196   - i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
197   - i++) {
198   - *ppix++ = bg_color;
199   - }
200   -#endif
201   - lcd_sync();
202   - console_curr_row -= rows;
203   -}
204   -
205   -/*----------------------------------------------------------------------*/
206   -
207   -static inline void console_back(void)
208   -{
209   - if (--console_curr_col < 0) {
210   - console_curr_col = console_cols - 1;
211   - if (--console_curr_row < 0)
212   - console_curr_row = 0;
213   - }
214   -
215   - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
216   - console_curr_row * VIDEO_FONT_HEIGHT, ' ');
217   -}
218   -
219   -/*----------------------------------------------------------------------*/
220   -
221   -static inline void console_newline(void)
222   -{
223   - console_curr_col = 0;
224   -
225   - /* Check if we need to scroll the terminal */
226   - if (++console_curr_row >= console_rows)
227   - console_scrollup();
228   - else
229   - lcd_sync();
230   -}
231   -
232   -/*----------------------------------------------------------------------*/
233   -
234 133 static void lcd_stub_putc(struct stdio_dev *dev, const char c)
235 134 {
236 135 lcd_putc(c);
237 136 }
238 137  
239   -void lcd_putc(const char c)
240   -{
241   - if (!lcd_is_enabled) {
242   - serial_putc(c);
243   -
244   - return;
245   - }
246   -
247   - switch (c) {
248   - case '\r':
249   - console_curr_col = 0;
250   -
251   - return;
252   - case '\n':
253   - console_newline();
254   -
255   - return;
256   - case '\t': /* Tab (8 chars alignment) */
257   - console_curr_col += 8;
258   - console_curr_col &= ~7;
259   -
260   - if (console_curr_col >= console_cols)
261   - console_newline();
262   -
263   - return;
264   - case '\b':
265   - console_back();
266   -
267   - return;
268   - default:
269   - lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
270   - console_curr_row * VIDEO_FONT_HEIGHT, c);
271   - if (++console_curr_col >= console_cols)
272   - console_newline();
273   - }
274   -}
275   -
276   -/*----------------------------------------------------------------------*/
277   -
278 138 static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
279 139 {
280 140 lcd_puts(s);
281 141 }
282 142  
283   -void lcd_puts(const char *s)
284   -{
285   - if (!lcd_is_enabled) {
286   - serial_puts(s);
287   -
288   - return;
289   - }
290   -
291   - while (*s)
292   - lcd_putc(*s++);
293   -
294   - lcd_sync();
295   -}
296   -
297   -/*----------------------------------------------------------------------*/
298   -
299   -void lcd_printf(const char *fmt, ...)
300   -{
301   - va_list args;
302   - char buf[CONFIG_SYS_PBSIZE];
303   -
304   - va_start(args, fmt);
305   - vsprintf(buf, fmt, args);
306   - va_end(args);
307   -
308   - lcd_puts(buf);
309   -}
310   -
311 143 /************************************************************************/
312   -/* ** Low-Level Graphics Routines */
313   -/************************************************************************/
314   -
315   -static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
316   -{
317   - uchar *dest;
318   - ushort row;
319   - int fg_color, bg_color;
320   -
321   - dest = (uchar *)(lcd_console_address +
322   - y * lcd_line_length + x * NBITS(LCD_BPP) / 8);
323   -
324   - for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
325   - uchar *s = str;
326   - int i;
327   -#if LCD_BPP == LCD_COLOR16
328   - ushort *d = (ushort *)dest;
329   -#elif LCD_BPP == LCD_COLOR32
330   - u32 *d = (u32 *)dest;
331   -#else
332   - uchar *d = dest;
333   -#endif
334   -
335   - fg_color = lcd_getfgcolor();
336   - bg_color = lcd_getbgcolor();
337   - for (i = 0; i < count; ++i) {
338   - uchar c, bits;
339   -
340   - c = *s++;
341   - bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
342   -
343   - for (c = 0; c < 8; ++c) {
344   - *d++ = (bits & 0x80) ? fg_color : bg_color;
345   - bits <<= 1;
346   - }
347   - }
348   - }
349   -}
350   -
351   -static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
352   -{
353   - lcd_drawchars(x, y, &c, 1);
354   -}
355   -
356   -/************************************************************************/
357 144 /** Small utility to check that you got the colours right */
358 145 /************************************************************************/
359 146 #ifdef LCD_TEST_PATTERN
... ... @@ -1124,12 +911,6 @@
1124 911 U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1125 912 #endif
1126 913  
1127   -void lcd_position_cursor(unsigned col, unsigned row)
1128   -{
1129   - console_curr_col = min_t(short, col, console_cols - 1);
1130   - console_curr_row = min_t(short, row, console_rows - 1);
1131   -}
1132   -
1133 914 int lcd_get_pixel_width(void)
1134 915 {
1135 916 return panel_info.vl_col;
... ... @@ -1138,16 +919,6 @@
1138 919 int lcd_get_pixel_height(void)
1139 920 {
1140 921 return panel_info.vl_row;
1141   -}
1142   -
1143   -int lcd_get_screen_rows(void)
1144   -{
1145   - return console_rows;
1146   -}
1147   -
1148   -int lcd_get_screen_columns(void)
1149   -{
1150   - return console_cols;
1151 922 }
1152 923  
1153 924 #if defined(CONFIG_LCD_DT_SIMPLEFB)
common/lcd_console.c
  1 +/*
  2 + * (C) Copyright 2001-2014
  3 + * DENX Software Engineering -- wd@denx.de
  4 + * Compulab Ltd - http://compulab.co.il/
  5 + *
  6 + * SPDX-License-Identifier: GPL-2.0+
  7 + */
  8 +
  9 +#include <common.h>
  10 +#include <lcd.h>
  11 +#include <video_font.h> /* Get font data, width and height */
  12 +
  13 +#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
  14 +#define CONSOLE_ROW_FIRST lcd_console_address
  15 +#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
  16 +#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
  17 + - CONSOLE_ROW_SIZE)
  18 +#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * console_rows)
  19 +#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
  20 +
  21 +static short console_curr_col;
  22 +static short console_curr_row;
  23 +static short console_cols;
  24 +static short console_rows;
  25 +static void *lcd_console_address;
  26 +
  27 +void lcd_init_console(void *address, int rows, int cols)
  28 +{
  29 + console_curr_col = 0;
  30 + console_curr_row = 0;
  31 + console_cols = cols;
  32 + console_rows = rows;
  33 + lcd_console_address = address;
  34 +}
  35 +
  36 +void lcd_set_col(short col)
  37 +{
  38 + console_curr_col = col;
  39 +}
  40 +
  41 +void lcd_set_row(short row)
  42 +{
  43 + console_curr_row = row;
  44 +}
  45 +
  46 +void lcd_position_cursor(unsigned col, unsigned row)
  47 +{
  48 + console_curr_col = min_t(short, col, console_cols - 1);
  49 + console_curr_row = min_t(short, row, console_rows - 1);
  50 +}
  51 +
  52 +int lcd_get_screen_rows(void)
  53 +{
  54 + return console_rows;
  55 +}
  56 +
  57 +int lcd_get_screen_columns(void)
  58 +{
  59 + return console_cols;
  60 +}
  61 +
  62 +static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
  63 +{
  64 + uchar *dest;
  65 + ushort row;
  66 + int fg_color, bg_color;
  67 +
  68 + dest = (uchar *)(lcd_console_address +
  69 + y * lcd_line_length + x * NBITS(LCD_BPP) / 8);
  70 +
  71 + for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
  72 + uchar *s = str;
  73 + int i;
  74 +#if LCD_BPP == LCD_COLOR16
  75 + ushort *d = (ushort *)dest;
  76 +#elif LCD_BPP == LCD_COLOR32
  77 + u32 *d = (u32 *)dest;
  78 +#else
  79 + uchar *d = dest;
  80 +#endif
  81 +
  82 + fg_color = lcd_getfgcolor();
  83 + bg_color = lcd_getbgcolor();
  84 + for (i = 0; i < count; ++i) {
  85 + uchar c, bits;
  86 +
  87 + c = *s++;
  88 + bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
  89 +
  90 + for (c = 0; c < 8; ++c) {
  91 + *d++ = (bits & 0x80) ? fg_color : bg_color;
  92 + bits <<= 1;
  93 + }
  94 + }
  95 + }
  96 +}
  97 +
  98 +static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
  99 +{
  100 + lcd_drawchars(x, y, &c, 1);
  101 +}
  102 +
  103 +static void console_scrollup(void)
  104 +{
  105 + const int rows = CONFIG_CONSOLE_SCROLL_LINES;
  106 + int bg_color = lcd_getbgcolor();
  107 +
  108 + /* Copy up rows ignoring those that will be overwritten */
  109 + memcpy(CONSOLE_ROW_FIRST,
  110 + lcd_console_address + CONSOLE_ROW_SIZE * rows,
  111 + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
  112 +
  113 + /* Clear the last rows */
  114 +#if (LCD_BPP != LCD_COLOR32)
  115 + memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
  116 + bg_color, CONSOLE_ROW_SIZE * rows);
  117 +#else
  118 + u32 *ppix = lcd_console_address +
  119 + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
  120 + u32 i;
  121 + for (i = 0;
  122 + i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
  123 + i++) {
  124 + *ppix++ = bg_color;
  125 + }
  126 +#endif
  127 + lcd_sync();
  128 + console_curr_row -= rows;
  129 +}
  130 +
  131 +static inline void console_back(void)
  132 +{
  133 + if (--console_curr_col < 0) {
  134 + console_curr_col = console_cols - 1;
  135 + if (--console_curr_row < 0)
  136 + console_curr_row = 0;
  137 + }
  138 +
  139 + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
  140 + console_curr_row * VIDEO_FONT_HEIGHT, ' ');
  141 +}
  142 +
  143 +static inline void console_newline(void)
  144 +{
  145 + console_curr_col = 0;
  146 +
  147 + /* Check if we need to scroll the terminal */
  148 + if (++console_curr_row >= console_rows)
  149 + console_scrollup();
  150 + else
  151 + lcd_sync();
  152 +}
  153 +
  154 +void lcd_putc(const char c)
  155 +{
  156 + if (!lcd_is_enabled) {
  157 + serial_putc(c);
  158 +
  159 + return;
  160 + }
  161 +
  162 + switch (c) {
  163 + case '\r':
  164 + console_curr_col = 0;
  165 +
  166 + return;
  167 + case '\n':
  168 + console_newline();
  169 +
  170 + return;
  171 + case '\t': /* Tab (8 chars alignment) */
  172 + console_curr_col += 8;
  173 + console_curr_col &= ~7;
  174 +
  175 + if (console_curr_col >= console_cols)
  176 + console_newline();
  177 +
  178 + return;
  179 + case '\b':
  180 + console_back();
  181 +
  182 + return;
  183 + default:
  184 + lcd_putc_xy(console_curr_col * VIDEO_FONT_WIDTH,
  185 + console_curr_row * VIDEO_FONT_HEIGHT, c);
  186 + if (++console_curr_col >= console_cols)
  187 + console_newline();
  188 + }
  189 +}
  190 +
  191 +void lcd_puts(const char *s)
  192 +{
  193 + if (!lcd_is_enabled) {
  194 + serial_puts(s);
  195 +
  196 + return;
  197 + }
  198 +
  199 + while (*s)
  200 + lcd_putc(*s++);
  201 +
  202 + lcd_sync();
  203 +}
  204 +
  205 +void lcd_printf(const char *fmt, ...)
  206 +{
  207 + va_list args;
  208 + char buf[CONFIG_SYS_PBSIZE];
  209 +
  210 + va_start(args, fmt);
  211 + vsprintf(buf, fmt, args);
  212 + va_end(args);
  213 +
  214 + lcd_puts(buf);
  215 +}
... ... @@ -12,6 +12,7 @@
12 12  
13 13 #ifndef _LCD_H_
14 14 #define _LCD_H_
  15 +#include <lcd_console.h>
15 16  
16 17 extern char lcd_is_enabled;
17 18  
include/lcd_console.h
  1 +/*
  2 + * Copyright (C) 2014, Compulab Ltd - http://compulab.co.il/
  3 + *
  4 + * SPDX-License-Identifier: GPL-2.0+
  5 + */
  6 +
  7 +/* By default we scroll by a single line */
  8 +#ifndef CONFIG_CONSOLE_SCROLL_LINES
  9 +#define CONFIG_CONSOLE_SCROLL_LINES 1
  10 +#endif
  11 +
  12 +/**
  13 + * lcd_init_console() - Initialize lcd console parameters
  14 + *
  15 + * Setup the address of console base, and the number of rows and columns the
  16 + * console has.
  17 + *
  18 + * @address: Console base address
  19 + * @rows: Number of rows in the console
  20 + * @cols: Number of columns in the console
  21 + */
  22 +void lcd_init_console(void *address, int rows, int cols);
  23 +
  24 +/**
  25 + * lcd_set_col() - Set the number of the current lcd console column
  26 + *
  27 + * Set the number of the console column where the cursor is.
  28 + *
  29 + * @col: Column number
  30 + */
  31 +void lcd_set_col(short col);
  32 +
  33 +/**
  34 + * lcd_set_row() - Set the number of the current lcd console row
  35 + *
  36 + * Set the number of the console row where the cursor is.
  37 + *
  38 + * @row: Row number
  39 + */
  40 +void lcd_set_row(short row);
  41 +
  42 +/**
  43 + * lcd_position_cursor() - Position the cursor on the screen
  44 + *
  45 + * Position the cursor at the given coordinates on the screen.
  46 + *
  47 + * @col: Column number
  48 + * @row: Row number
  49 + */
  50 +void lcd_position_cursor(unsigned col, unsigned row);
  51 +
  52 +/**
  53 + * lcd_get_screen_rows() - Get the total number of screen rows
  54 + *
  55 + * @return: Number of screen rows
  56 + */
  57 +int lcd_get_screen_rows(void);
  58 +
  59 +/**
  60 + * lcd_get_screen_columns() - Get the total number of screen columns
  61 + *
  62 + * @return: Number of screen columns
  63 + */
  64 +int lcd_get_screen_columns(void);
  65 +
  66 +/**
  67 + * lcd_putc() - Print to screen a single character at the location of the cursor
  68 + *
  69 + * @c: The character to print
  70 + */
  71 +void lcd_putc(const char c);
  72 +
  73 +/**
  74 + * lcd_puts() - Print to screen a string at the location of the cursor
  75 + *
  76 + * @s: The string to print
  77 + */
  78 +void lcd_puts(const char *s);
  79 +
  80 +/**
  81 + * lcd_printf() - Print to screen a formatted string at location of the cursor
  82 + *
  83 + * @fmt: The formatted string to print
  84 + * @...: The arguments for the formatted string
  85 + */
  86 +void lcd_printf(const char *fmt, ...);