[PATCH v2 4/8] video console: add select font logic to vidconsole uclass driver
Dzmitry Sankouski
dsankouski at gmail.com
Mon Feb 13 17:56:56 CET 2023
Select font logic at runtime needed to unit test different fonts.
This commit is a preparation to enable runtime font selection in
console_simple driver.
- move console true type select font logic to driver ops
- add select font logic to vidconsole-uclass.c
Signed-off-by: Dzmitry Sankouski <dsankouski at gmail.com>
---
Changes for v2: N/A
cmd/font.c | 7 ++++++-
drivers/video/console_truetype.c | 6 ++++--
drivers/video/vidconsole-uclass.c | 22 ++++++++++++++++++++++
include/video.h | 1 +
include/video_console.h | 18 +++++++++++++++++-
5 files changed, 50 insertions(+), 4 deletions(-)
diff --git a/cmd/font.c b/cmd/font.c
index 3e522f3aaa..769796c5ec 100644
--- a/cmd/font.c
+++ b/cmd/font.c
@@ -15,7 +15,12 @@
static int do_font_list(struct cmd_tbl *cmdtp, int flag, int argc,
char *const argv[])
{
- vidconsole_list_fonts();
+ struct udevice *dev;
+
+ if (uclass_first_device_err(UCLASS_VIDEO_CONSOLE, &dev))
+ return CMD_RET_FAILURE;
+
+ vidconsole_list_fonts(dev);
return 0;
}
diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 6859c9fa11..389fa483fc 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -584,7 +584,7 @@ static struct font_info *console_truetype_find_font(void)
return NULL;
}
-void vidconsole_list_fonts(void)
+void console_truetype_list_fonts(struct udevice __maybe_unused *dev)
{
struct font_info *tab;
@@ -674,7 +674,7 @@ static void select_metrics(struct udevice *dev, struct console_tt_metrics *met)
vc_priv->tab_width_frac = VID_TO_POS(met->font_size) * 8 / 2;
}
-int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+int console_truetype_select_font(struct udevice *dev, const char *name, uint size)
{
struct console_tt_priv *priv = dev_get_priv(dev);
struct console_tt_metrics *met;
@@ -763,6 +763,8 @@ struct vidconsole_ops console_truetype_ops = {
.set_row = console_truetype_set_row,
.backspace = console_truetype_backspace,
.entry_start = console_truetype_entry_start,
+ .list_fonts = console_truetype_list_fonts,
+ .select_font = console_truetype_select_font,
};
U_BOOT_DRIVER(vidconsole_truetype) = {
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 6bdfb6e37d..5a08fdd689 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -85,6 +85,28 @@ static int vidconsole_back(struct udevice *dev)
return video_sync(dev->parent, false);
}
+void vidconsole_list_fonts(struct udevice *dev)
+{
+ struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+
+ if (ops->select_font)
+ ops->list_fonts(dev);
+}
+
+int vidconsole_select_font(struct udevice *dev, const char *name, uint size)
+{
+ struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+ int ret;
+
+ if (ops->select_font) {
+ ret = ops->select_font(dev, name, size);
+ if (ret != -ENOSYS)
+ return ret;
+ }
+
+ return 0;
+}
+
/* Move to a newline, scrolling the display if necessary */
static void vidconsole_newline(struct udevice *dev)
{
diff --git a/include/video.h b/include/video.h
index 43f2e2c02f..91c05fa9f0 100644
--- a/include/video.h
+++ b/include/video.h
@@ -115,6 +115,7 @@ struct video_priv {
bool flush_dcache;
u8 fg_col_idx;
u8 bg_col_idx;
+ struct video_fontdata *fontdata;
};
/**
diff --git a/include/video_console.h b/include/video_console.h
index d755eb73cf..fc702cc165 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -133,6 +133,22 @@ struct vidconsole_ops {
* characters.
*/
int (*backspace)(struct udevice *dev);
+
+ /**
+ * list_fonts() - List the available fonts
+ *
+ * This shows a list on the console
+ */
+ void (*list_fonts)(struct udevice *dev);
+
+ /**
+ * select_font() - Select a font to use
+ *
+ * @dev: vidconsole device
+ * @name: Font name
+ * @size: Size of the font (norminal pixel height) or 0 for default
+ */
+ int (*select_font)(struct udevice *dev, const char *name, uint size);
};
/* Get a pointer to the driver operations for a video console device */
@@ -236,7 +252,7 @@ void vidconsole_set_cursor_pos(struct udevice *dev, int x, int y);
*
* This shows a list on the console
*/
-void vidconsole_list_fonts(void);
+void vidconsole_list_fonts(struct udevice *dev);
/**
* vidconsole_select_font() - Select a font to use
--
2.30.2
More information about the U-Boot
mailing list