From: Simon Glass <simon.glass@canonical.com>
Both console_core.c and console_truetype.c call console_alloc_cursor()
to set up the cursor-save buffer. This duplication can be avoided by
moving the call into vidconsole_post_probe() where it benefits all
drivers.
Move cursor allocation into the uclass and remove the calls from the
individual drivers.
Also reorder vidconsole_free_ctx() to free the cursor save_data before
calling ctx_dispose(), since the cursor is now owned by the uclass
rather than the driver.
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---
drivers/video/console_core.c | 6 ------
drivers/video/console_truetype.c | 4 ----
drivers/video/vidconsole-uclass.c | 12 ++++++++++--
3 files changed, 10 insertions(+), 12 deletions(-)
@@ -310,12 +310,6 @@ int console_probe(struct udevice *dev)
if (ret)
return ret;
- if (CONFIG_IS_ENABLED(CURSOR) && xpl_phase() == PHASE_BOARD_R) {
- ret = console_alloc_cursor(dev, vidconsole_ctx(dev));
- if (ret)
- return ret;
- }
-
return 0;
}
@@ -1302,10 +1302,6 @@ static int console_truetype_probe(struct udevice *dev)
debug("%s: ready\n", __func__);
- ret = console_alloc_cursor(dev, &ctx->com);
- if (ret)
- return ret;
-
return 0;
}
@@ -13,9 +13,10 @@
#include <charset.h>
#include <command.h>
#include <console.h>
+#include <dm.h>
#include <log.h>
#include <malloc.h>
-#include <dm.h>
+#include <spl.h>
#include <video.h>
#include <video_console.h>
#include "vidconsole_internal.h"
@@ -748,9 +749,9 @@ static void vidconsole_free_ctx(struct udevice *dev, struct vidconsole_ctx *ctx)
{
struct vidconsole_ops *ops = vidconsole_get_ops(dev);
+ free(ctx->curs.save_data);
if (ops->ctx_dispose)
ops->ctx_dispose(dev, ctx);
- free(ctx->curs.save_data);
}
int vidconsole_ctx_dispose(struct udevice *dev, void *vctx)
@@ -947,6 +948,13 @@ static int vidconsole_post_probe(struct udevice *dev)
struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
struct stdio_dev *sdev = &priv->sdev;
+ int ret;
+
+ if (CONFIG_IS_ENABLED(CURSOR) && xpl_phase() == PHASE_BOARD_R) {
+ ret = console_alloc_cursor(dev, ctx);
+ if (ret)
+ return ret;
+ }
if (!ctx->tab_width_frac)
ctx->tab_width_frac = VID_TO_POS(ctx->x_charsize) * 8;