[Concept,11/42] video: Move setting of the bitmap font into uclass

Message ID 20250919201507.4024144-12-sjg@u-boot.org
State New
Headers
Series video: Support a cursor more generally |

Commit Message

Simon Glass Sept. 19, 2025, 8:14 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Most of this function deals with uclass data, so move it into the
uclass. This will allow truetype to use it too.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/console_core.c      | 18 +-----------------
 drivers/video/vidconsole-uclass.c | 24 ++++++++++++++++++++++++
 include/video_console.h           | 10 ++++++++++
 3 files changed, 35 insertions(+), 17 deletions(-)
  

Patch

diff --git a/drivers/video/console_core.c b/drivers/video/console_core.c
index 4b75a5b6e12..aec51dc809d 100644
--- a/drivers/video/console_core.c
+++ b/drivers/video/console_core.c
@@ -21,25 +21,9 @@ 
 static int console_set_font(struct udevice *dev, struct video_fontdata *fontdata)
 {
 	struct console_simple_priv *priv = dev_get_priv(dev);
-	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
-	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
-
-	debug("console_simple: setting %s font\n", fontdata->name);
-	debug("width: %d\n", fontdata->width);
-	debug("byte width: %d\n", fontdata->byte_width);
-	debug("height: %d\n", fontdata->height);
 
 	priv->fontdata = fontdata;
-	vc_priv->x_charsize = fontdata->width;
-	vc_priv->y_charsize = fontdata->height;
-	if (vid_priv->rot % 2) {
-		vc_priv->cols = vid_priv->ysize / fontdata->width;
-		vc_priv->rows = vid_priv->xsize / fontdata->height;
-		vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
-	} else {
-		vc_priv->cols = vid_priv->xsize / fontdata->width;
-		vc_priv->rows = vid_priv->ysize / fontdata->height;
-	}
+	vidconsole_set_bitmap_font(dev, fontdata);
 
 	return 0;
 }
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index f53d55e81b7..b5f0b79bcf6 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -812,3 +812,27 @@  void vidconsole_set_quiet(struct udevice *dev, bool quiet)
 
 	priv->quiet = quiet;
 }
+
+void vidconsole_set_bitmap_font(struct udevice *dev,
+				struct video_fontdata *fontdata)
+{
+	struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
+	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
+
+	log_debug("console_simple: setting %s font\n", fontdata->name);
+	log_debug("width: %d\n", fontdata->width);
+	log_debug("byte width: %d\n", fontdata->byte_width);
+	log_debug("height: %d\n", fontdata->height);
+
+	vc_priv->x_charsize = fontdata->width;
+	vc_priv->y_charsize = fontdata->height;
+	if (vid_priv->rot % 2) {
+		vc_priv->cols = vid_priv->ysize / fontdata->width;
+		vc_priv->rows = vid_priv->xsize / fontdata->height;
+		vc_priv->xsize_frac = VID_TO_POS(vid_priv->ysize);
+	} else {
+		vc_priv->cols = vid_priv->xsize / fontdata->width;
+		vc_priv->rows = vid_priv->ysize / fontdata->height;
+		/* xsize_frac is set in vidconsole_pre_probe() */
+	}
+}
diff --git a/include/video_console.h b/include/video_console.h
index d3c65a08331..8cd1ccacb0f 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -10,6 +10,7 @@ 
 #include <video.h>
 
 struct abuf;
+struct video_fontdata;
 struct video_priv;
 
 #define VID_FRAC_DIV	256
@@ -603,4 +604,13 @@  int vidconsole_get_font_size(struct udevice *dev, const char **name, uint *sizep
  */
 void vidconsole_set_quiet(struct udevice *dev, bool quiet);
 
+/**
+ * vidconsole_set_bitmap_font() - prepare vidconsole for chosen bitmap font
+ *
+ * @dev		vidconsole device
+ * @fontdata	pointer to font data struct
+ */
+void vidconsole_set_bitmap_font(struct udevice *dev,
+				struct video_fontdata *fontdata);
+
 #endif