summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2022-10-06 17:36:03 +0300
committerAnatolij Gustschin <agust@denx.de>2022-10-30 10:43:24 +0300
commita032e4b55ea717fb931dd0d4754cf72b9bafe2f4 (patch)
tree503fc51df906b9bb0920be7d241af3495fc1883b /drivers
parentdb2c8ed3a5850e64fcf612d099ce7b22c480a752 (diff)
downloadu-boot-a032e4b55ea717fb931dd0d4754cf72b9bafe2f4.tar.xz
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/video/vidconsole-uclass.c74
-rw-r--r--drivers/video/video-uclass.c66
2 files changed, 69 insertions, 71 deletions
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index f42db40d4c..f67027c67b 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 01e8af5ac6..b258a8a00f 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 */