aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Glass2022-10-06 08:36:03 -0600
committerAnatolij Gustschin2022-10-30 08:43:24 +0100
commita032e4b55ea717fb931dd0d4754cf72b9bafe2f4 (patch)
tree503fc51df906b9bb0920be7d241af3495fc1883b
parentdb2c8ed3a5850e64fcf612d099ce7b22c480a752 (diff)
video: Move console colours to the video uclass
At present these are attached to vidconsole which means that the video uclass requires that a console is enabled. This is not the intention. The colours are a reasonable way of indexing common colours in any case, so move them to the video uclass instead. Rename vid_console_color() to video_index_to_colour() now that it is more generic. Also fix the inconsistent spelling in these functions. Signed-off-by: Simon Glass <sjg@chromium.org>
-rw-r--r--drivers/video/vidconsole-uclass.c74
-rw-r--r--drivers/video/video-uclass.c66
-rw-r--r--include/video.h35
-rw-r--r--include/video_console.h37
4 files changed, 104 insertions, 108 deletions
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index f42db40d4cd..f67027c67be 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -19,15 +19,6 @@
#include <video_font.h> /* Bitmap font for code page 437 */
#include <linux/ctype.h>
-/*
- * Structure to describe a console color
- */
-struct vid_rgb {
- u32 r;
- u32 g;
- u32 b;
-};
-
/* By default we scroll by a single line */
#ifndef CONFIG_CONSOLE_SCROLL_LINES
#define CONFIG_CONSOLE_SCROLL_LINES 1
@@ -124,61 +115,6 @@ static void vidconsole_newline(struct udevice *dev)
}
}
-static const struct vid_rgb colors[VID_COLOR_COUNT] = {
- { 0x00, 0x00, 0x00 }, /* black */
- { 0xc0, 0x00, 0x00 }, /* red */
- { 0x00, 0xc0, 0x00 }, /* green */
- { 0xc0, 0x60, 0x00 }, /* brown */
- { 0x00, 0x00, 0xc0 }, /* blue */
- { 0xc0, 0x00, 0xc0 }, /* magenta */
- { 0x00, 0xc0, 0xc0 }, /* cyan */
- { 0xc0, 0xc0, 0xc0 }, /* light gray */
- { 0x80, 0x80, 0x80 }, /* gray */
- { 0xff, 0x00, 0x00 }, /* bright red */
- { 0x00, 0xff, 0x00 }, /* bright green */
- { 0xff, 0xff, 0x00 }, /* yellow */
- { 0x00, 0x00, 0xff }, /* bright blue */
- { 0xff, 0x00, 0xff }, /* bright magenta */
- { 0x00, 0xff, 0xff }, /* bright cyan */
- { 0xff, 0xff, 0xff }, /* white */
-};
-
-u32 vid_console_color(struct video_priv *priv, unsigned int idx)
-{
- switch (priv->bpix) {
- case VIDEO_BPP16:
- if (CONFIG_IS_ENABLED(VIDEO_BPP16)) {
- return ((colors[idx].r >> 3) << 11) |
- ((colors[idx].g >> 2) << 5) |
- ((colors[idx].b >> 3) << 0);
- }
- break;
- case VIDEO_BPP32:
- if (CONFIG_IS_ENABLED(VIDEO_BPP32)) {
- if (priv->format == VIDEO_X2R10G10B10)
- return (colors[idx].r << 22) |
- (colors[idx].g << 12) |
- (colors[idx].b << 2);
- else
- return (colors[idx].r << 16) |
- (colors[idx].g << 8) |
- (colors[idx].b << 0);
- }
- break;
- default:
- break;
- }
-
- /*
- * For unknown bit arrangements just support
- * black and white.
- */
- if (idx)
- return 0xffffff; /* white */
-
- return 0x000000; /* black */
-}
-
static char *parsenum(char *s, int *num)
{
char *end;
@@ -441,28 +377,28 @@ static void vidconsole_escape_char(struct udevice *dev, char ch)
case 1:
/* bold */
vid_priv->fg_col_idx |= 8;
- vid_priv->colour_fg = vid_console_color(
+ vid_priv->colour_fg = video_index_to_colour(
vid_priv, vid_priv->fg_col_idx);
break;
case 7:
/* reverse video */
- vid_priv->colour_fg = vid_console_color(
+ vid_priv->colour_fg = video_index_to_colour(
vid_priv, vid_priv->bg_col_idx);
- vid_priv->colour_bg = vid_console_color(
+ vid_priv->colour_bg = video_index_to_colour(
vid_priv, vid_priv->fg_col_idx);
break;
case 30 ... 37:
/* foreground color */
vid_priv->fg_col_idx &= ~7;
vid_priv->fg_col_idx |= val - 30;
- vid_priv->colour_fg = vid_console_color(
+ vid_priv->colour_fg = video_index_to_colour(
vid_priv, vid_priv->fg_col_idx);
break;
case 40 ... 47:
/* background color, also mask the bold bit */
vid_priv->bg_col_idx &= ~0xf;
vid_priv->bg_col_idx |= val - 40;
- vid_priv->colour_bg = vid_console_color(
+ vid_priv->colour_bg = video_index_to_colour(
vid_priv, vid_priv->bg_col_idx);
break;
default:
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 01e8af5ac67..b258a8a00fc 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -64,6 +64,13 @@ struct video_uc_priv {
ulong video_ptr;
};
+/** struct vid_rgb - Describes a video colour */
+struct vid_rgb {
+ u32 r;
+ u32 g;
+ u32 b;
+};
+
void video_set_flush_dcache(struct udevice *dev, bool flush)
{
struct video_priv *priv = dev_get_uclass_priv(dev);
@@ -154,6 +161,61 @@ int video_clear(struct udevice *dev)
return video_sync(dev, false);
}
+static const struct vid_rgb colours[VID_COLOUR_COUNT] = {
+ { 0x00, 0x00, 0x00 }, /* black */
+ { 0xc0, 0x00, 0x00 }, /* red */
+ { 0x00, 0xc0, 0x00 }, /* green */
+ { 0xc0, 0x60, 0x00 }, /* brown */
+ { 0x00, 0x00, 0xc0 }, /* blue */
+ { 0xc0, 0x00, 0xc0 }, /* magenta */
+ { 0x00, 0xc0, 0xc0 }, /* cyan */
+ { 0xc0, 0xc0, 0xc0 }, /* light gray */
+ { 0x80, 0x80, 0x80 }, /* gray */
+ { 0xff, 0x00, 0x00 }, /* bright red */
+ { 0x00, 0xff, 0x00 }, /* bright green */
+ { 0xff, 0xff, 0x00 }, /* yellow */
+ { 0x00, 0x00, 0xff }, /* bright blue */
+ { 0xff, 0x00, 0xff }, /* bright magenta */
+ { 0x00, 0xff, 0xff }, /* bright cyan */
+ { 0xff, 0xff, 0xff }, /* white */
+};
+
+u32 video_index_to_colour(struct video_priv *priv, unsigned int idx)
+{
+ switch (priv->bpix) {
+ case VIDEO_BPP16:
+ if (CONFIG_IS_ENABLED(VIDEO_BPP16)) {
+ return ((colours[idx].r >> 3) << 11) |
+ ((colours[idx].g >> 2) << 5) |
+ ((colours[idx].b >> 3) << 0);
+ }
+ break;
+ case VIDEO_BPP32:
+ if (CONFIG_IS_ENABLED(VIDEO_BPP32)) {
+ if (priv->format == VIDEO_X2R10G10B10)
+ return (colours[idx].r << 22) |
+ (colours[idx].g << 12) |
+ (colours[idx].b << 2);
+ else
+ return (colours[idx].r << 16) |
+ (colours[idx].g << 8) |
+ (colours[idx].b << 0);
+ }
+ break;
+ default:
+ break;
+ }
+
+ /*
+ * For unknown bit arrangements just support
+ * black and white.
+ */
+ if (idx)
+ return 0xffffff; /* white */
+
+ return 0x000000; /* black */
+}
+
void video_set_default_colors(struct udevice *dev, bool invert)
{
struct video_priv *priv = dev_get_uclass_priv(dev);
@@ -176,8 +238,8 @@ void video_set_default_colors(struct udevice *dev, bool invert)
}
priv->fg_col_idx = fore;
priv->bg_col_idx = back;
- priv->colour_fg = vid_console_color(priv, fore);
- priv->colour_bg = vid_console_color(priv, back);
+ priv->colour_fg = video_index_to_colour(priv, fore);
+ priv->colour_bg = video_index_to_colour(priv, back);
}
/* Flush video activity to the caches */
diff --git a/include/video.h b/include/video.h
index 43e2c899778..1c30aea73c0 100644
--- a/include/video.h
+++ b/include/video.h
@@ -131,6 +131,41 @@ struct video_ops {
#define video_get_ops(dev) ((struct video_ops *)(dev)->driver->ops)
+/** enum colour_idx - the 16 colors supported by consoles */
+enum colour_idx {
+ VID_BLACK = 0,
+ VID_RED,
+ VID_GREEN,
+ VID_BROWN,
+ VID_BLUE,
+ VID_MAGENTA,
+ VID_CYAN,
+ VID_LIGHT_GRAY,
+ VID_GRAY,
+ VID_LIGHT_RED,
+ VID_LIGHT_GREEN,
+ VID_YELLOW,
+ VID_LIGHT_BLUE,
+ VID_LIGHT_MAGENTA,
+ VID_LIGHT_CYAN,
+ VID_WHITE,
+
+ VID_COLOUR_COUNT
+};
+
+/**
+ * video_index_to_colour() - convert a color code to a pixel's internal
+ * representation
+ *
+ * The caller has to guarantee that the color index is less than
+ * VID_COLOR_COUNT.
+ *
+ * @priv private data of the console device
+ * @idx color index
+ * Return: color value
+ */
+u32 video_index_to_colour(struct video_priv *priv, unsigned int idx);
+
/**
* video_reserve() - Reserve frame-buffer memory for video devices
*
diff --git a/include/video_console.h b/include/video_console.h
index 5921767fbf0..72edd419191 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -15,30 +15,6 @@ struct video_priv;
#define VID_TO_PIXEL(x) ((x) / VID_FRAC_DIV)
#define VID_TO_POS(x) ((x) * VID_FRAC_DIV)
-/*
- * The 16 colors supported by the console
- */
-enum color_idx {
- VID_BLACK = 0,
- VID_RED,
- VID_GREEN,
- VID_BROWN,
- VID_BLUE,
- VID_MAGENTA,
- VID_CYAN,
- VID_LIGHT_GRAY,
- VID_GRAY,
- VID_LIGHT_RED,
- VID_LIGTH_GREEN,
- VID_YELLOW,
- VID_LIGHT_BLUE,
- VID_LIGHT_MAGENTA,
- VID_LIGHT_CYAN,
- VID_WHITE,
-
- VID_COLOR_COUNT
-};
-
/**
* struct vidconsole_priv - uclass-private data about a console device
*
@@ -243,19 +219,6 @@ int vidconsole_put_string(struct udevice *dev, const char *str);
void vidconsole_position_cursor(struct udevice *dev, unsigned col,
unsigned row);
-/**
- * vid_console_color() - convert a color code to a pixel's internal
- * representation
- *
- * The caller has to guarantee that the color index is less than
- * VID_COLOR_COUNT.
- *
- * @priv private data of the console device
- * @idx color index
- * Return: color value
- */
-u32 vid_console_color(struct video_priv *priv, unsigned int idx);
-
#ifdef CONFIG_VIDEO_COPY
/**
* vidconsole_sync_copy() - Sync back to the copy framebuffer