video: Add a function to select the truetype metrics
authorSimon Glass <sjg@chromium.org>
Thu, 6 Oct 2022 14:36:13 +0000 (08:36 -0600)
committerAnatolij Gustschin <agust@denx.de>
Sun, 30 Oct 2022 19:01:40 +0000 (20:01 +0100)
Move this code into a function so we can call it later when we want to
change the font.

Signed-off-by: Simon Glass <sjg@chromium.org>
drivers/video/console_truetype.c

index 6ef3fae..5fc737a 100644 (file)
@@ -624,10 +624,25 @@ static int vidconsole_add_metrics(struct udevice *dev, const char *font_name,
        return priv->num_metrics++;
 }
 
-static int console_truetype_probe(struct udevice *dev)
+static void select_metrics(struct udevice *dev, struct console_tt_metrics *met)
 {
        struct vidconsole_priv *vc_priv = dev_get_uclass_priv(dev);
        struct console_tt_priv *priv = dev_get_priv(dev);
+       struct udevice *vid_dev = dev_get_parent(dev);
+       struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
+
+       priv->cur_met = met;
+       vc_priv->x_charsize = met->font_size;
+       vc_priv->y_charsize = met->font_size;
+       vc_priv->xstart_frac = VID_TO_POS(2);
+       vc_priv->cols = vid_priv->xsize / met->font_size;
+       vc_priv->rows = vid_priv->ysize / met->font_size;
+       vc_priv->tab_width_frac = VID_TO_POS(met->font_size) * 8 / 2;
+}
+
+static int console_truetype_probe(struct udevice *dev)
+{
+       struct console_tt_priv *priv = dev_get_priv(dev);
        struct udevice *vid_dev = dev->parent;
        struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
        struct font_info *tab;
@@ -650,12 +665,7 @@ static int console_truetype_probe(struct udevice *dev)
                return log_msg_ret("add", ret);
        priv->cur_met = &priv->metrics[ret];
 
-       vc_priv->x_charsize = font_size;
-       vc_priv->y_charsize = font_size;
-       vc_priv->xstart_frac = VID_TO_POS(2);
-       vc_priv->cols = vid_priv->xsize / font_size;
-       vc_priv->rows = vid_priv->ysize / font_size;
-       vc_priv->tab_width_frac = VID_TO_POS(font_size) * 8 / 2;
+       select_metrics(dev, &priv->metrics[ret]);
 
        debug("%s: ready\n", __func__);