[Concept,10/36] video: Pass context to backspace() method

Message ID 20260120231814.2033069-11-sjg@u-boot.org
State New
Headers
Series video: Add multiple-context support to vidconsole (part F) |

Commit Message

Simon Glass Jan. 20, 2026, 11:17 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

The backspace() driver method currently uses the default context. Update
it to accept a context parameter so callers can specify which context to
use for the backspace operation. This is needed for text-input objects
which have their own vidconsole context.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 drivers/video/console_truetype.c  |  5 +++--
 drivers/video/vidconsole-uclass.c | 10 ++++------
 include/video_console.h           |  3 ++-
 3 files changed, 9 insertions(+), 9 deletions(-)
  

Patch

diff --git a/drivers/video/console_truetype.c b/drivers/video/console_truetype.c
index 106da0e086d..519b8f88843 100644
--- a/drivers/video/console_truetype.c
+++ b/drivers/video/console_truetype.c
@@ -660,12 +660,13 @@  static int console_truetype_putc_xy(struct udevice *dev, uint x, uint y,
  * not been entered.
  *
  * @dev:	Device to update
+ * @vctx:	Vidconsole context to use
  * Return: 0 if OK, -ENOSYS if not supported
  */
-static int console_truetype_backspace(struct udevice *dev)
+static int console_truetype_backspace(struct udevice *dev, void *vctx)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev->parent);
-	struct console_tt_ctx *ctx = vidconsole_ctx(dev);
+	struct console_tt_ctx *ctx = vctx;
 	struct vidconsole_ctx *com = &ctx->com;
 	struct pos_info *pos;
 	int xend;
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index ca21cb8154f..8590219ae64 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -61,16 +61,14 @@  int vidconsole_entry_start(struct udevice *dev, void *ctx)
 	return ops->entry_start(dev, ctx);
 }
 
-/* Move backwards one space */
-static int vidconsole_back(struct udevice *dev)
+/* Move backwards one space, ctx must be non-NULL */
+static int vidconsole_back(struct udevice *dev, struct vidconsole_ctx *ctx)
 {
-	struct vidconsole_priv *priv = dev_get_uclass_priv(dev);
-	struct vidconsole_ctx *ctx = vidconsole_ctx_from_priv(priv);
 	struct vidconsole_ops *ops = vidconsole_get_ops(dev);
 	int ret;
 
 	if (ops->backspace) {
-		ret = ops->backspace(dev);
+		ret = ops->backspace(dev, ctx);
 		if (ret != -ENOSYS)
 			return ret;
 	}
@@ -523,7 +521,7 @@  int vidconsole_put_char(struct udevice *dev, char ch)
 			vidconsole_newline(dev);
 		break;
 	case '\b':
-		vidconsole_back(dev);
+		vidconsole_back(dev, ctx);
 		ctx->last_ch = 0;
 		break;
 	default:
diff --git a/include/video_console.h b/include/video_console.h
index c6cc050e054..3390d4fe1a7 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -294,6 +294,7 @@  struct vidconsole_ops {
 	 * backspace() - Handle erasing the last character
 	 *
 	 * @dev:	Device to adjust
+	 * @ctx:	Vidconsole context to use
 	 * Returns: 0 on success, -ve on error
 	 *
 	 * With proportional fonts the vidconsole uclass cannot itself erase
@@ -305,7 +306,7 @@  struct vidconsole_ops {
 	 * If not implement, default behaviour will work for fixed-width
 	 * characters.
 	 */
-	int (*backspace)(struct udevice *dev);
+	int (*backspace)(struct udevice *dev, void *ctx);
 
 	/**
 	 * get_font() - Obtain information about a font (optional)