[Concept,06/36] video: Pass context to vidconsole_readline_start/end()

Message ID 20260120231814.2033069-7-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>

Add a vctx parameter to vidconsole_readline_start() and
vidconsole_readline_end() to allow callers to specify which vidconsole
context to use. If NULL is passed, the function falls back to using the
default context from the device.

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

 boot/scene_txtin.c                |  4 ++--
 drivers/video/vidconsole-uclass.c | 12 ++++++------
 include/video_console.h           | 13 ++++++++-----
 3 files changed, 16 insertions(+), 13 deletions(-)
  

Patch

diff --git a/boot/scene_txtin.c b/boot/scene_txtin.c
index 2b72ecaed39..3944bce9a96 100644
--- a/boot/scene_txtin.c
+++ b/boot/scene_txtin.c
@@ -107,7 +107,7 @@  static void scene_txtin_putch(struct cli_line_state *cls, int ch)
 void scene_txtin_close(struct scene *scn)
 {
 	/* cursor is not needed now */
-	vidconsole_readline_end(scn->expo->cons);
+	vidconsole_readline_end(scn->expo->cons, NULL);
 }
 
 int scene_txtin_open(struct scene *scn, struct scene_obj *obj,
@@ -137,7 +137,7 @@  int scene_txtin_open(struct scene *scn, struct scene_obj *obj,
 		return log_msg_ret("sav", ret);
 
 	/* make sure the cursor is visible */
-	vidconsole_readline_start(cons, true);
+	vidconsole_readline_start(cons, NULL, true);
 
 	return 0;
 }
diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 200bc60c55b..ca21cb8154f 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -1019,18 +1019,18 @@  void vidconsole_idle(struct udevice *dev)
 }
 
 #ifdef CONFIG_CURSOR
-void vidconsole_readline_start(struct udevice *dev, bool indent)
+void vidconsole_readline_start(struct udevice *dev, void *vctx, bool indent)
 {
-	struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
+	struct vidconsole_ctx *ctx = vctx ?: vidconsole_ctx(dev);
 
 	ctx->curs.indent = indent;
 	ctx->curs.enabled = true;
 	vidconsole_mark_start(dev);
 }
 
-void vidconsole_readline_end(struct udevice *dev)
+void vidconsole_readline_end(struct udevice *dev, void *vctx)
 {
-	struct vidconsole_ctx *ctx = vidconsole_ctx(dev);
+	struct vidconsole_ctx *ctx = vctx ?: vidconsole_ctx(dev);
 
 	ctx->curs.enabled = false;
 }
@@ -1041,7 +1041,7 @@  void vidconsole_readline_start_all(bool indent)
 	struct udevice *dev;
 
 	uclass_id_foreach_dev(UCLASS_VIDEO_CONSOLE, dev, uc)
-		vidconsole_readline_start(dev, indent);
+		vidconsole_readline_start(dev, NULL, indent);
 }
 
 void vidconsole_readline_end_all(void)
@@ -1050,7 +1050,7 @@  void vidconsole_readline_end_all(void)
 	struct udevice *dev;
 
 	uclass_id_foreach_dev(UCLASS_VIDEO_CONSOLE, dev, uc)
-		vidconsole_readline_end(dev);
+		vidconsole_readline_end(dev, NULL);
 }
 #endif /* CURSOR */
 
diff --git a/include/video_console.h b/include/video_console.h
index 663f89b25f2..c6cc050e054 100644
--- a/include/video_console.h
+++ b/include/video_console.h
@@ -278,7 +278,7 @@  struct vidconsole_ops {
 	 * entry_start() - Indicate that text entry is starting afresh
 	 *
 	 * @dev:	Device to adjust
-	 * @ctx:	Vidconsole context to use
+	 * @ctx:	Vidconsole context to use (cannot be NULL)
 	 * Returns: 0 on success, -ve on error
 	 *
 	 * Consoles which use proportional fonts need to track the position of
@@ -596,9 +596,10 @@  int vidconsole_hide_cursor(struct udevice *dev);
  * Called at the start of command line input to show the cursor
  *
  * @dev: vidconsole device
+ * @vctx: vidconsole context to use, or NULL to use the default
  * @indent: indent subsequent lines to the same position as the first line
  */
-void vidconsole_readline_start(struct udevice *dev, bool indent);
+void vidconsole_readline_start(struct udevice *dev, void *vctx, bool indent);
 
 /**
  * vidconsole_readline_end() - Disable cursor for a video console
@@ -606,8 +607,9 @@  void vidconsole_readline_start(struct udevice *dev, bool indent);
  * Called at the end of command line input to hide the cursor
  *
  * @dev: vidconsole device
+ * @vctx: vidconsole context to use, or NULL to use the default
  */
-void vidconsole_readline_end(struct udevice *dev);
+void vidconsole_readline_end(struct udevice *dev, void *vctx);
 
 /**
  * vidconsole_readline_start_all() - Enable cursor for all video consoles
@@ -637,11 +639,12 @@  static inline int vidconsole_hide_cursor(struct udevice *dev)
 	return 0;
 }
 
-static inline void vidconsole_readline_start(struct udevice *dev, bool indent)
+static inline void vidconsole_readline_start(struct udevice *dev, void *vctx,
+					     bool indent)
 {
 }
 
-static inline void vidconsole_readline_end(struct udevice *dev)
+static inline void vidconsole_readline_end(struct udevice *dev, void *vctx)
 {
 }