[Concept,11/36] video: Pass context to vidconsole_newline/back()

Message ID 20260120231814.2033069-12-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 ctx parameter to the internal vidconsole_newline() and
vidconsole_back() functions to allow passing in a specific vidconsole
context. This prepares for supporting per-object contexts in the expo
text-input code.

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

 drivers/video/vidconsole-uclass.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
  

Patch

diff --git a/drivers/video/vidconsole-uclass.c b/drivers/video/vidconsole-uclass.c
index 8590219ae64..29a1accb64c 100644
--- a/drivers/video/vidconsole-uclass.c
+++ b/drivers/video/vidconsole-uclass.c
@@ -90,11 +90,12 @@  static int vidconsole_back(struct udevice *dev, struct vidconsole_ctx *ctx)
 	return video_sync(dev->parent, false);
 }
 
-/* Move to a newline, scrolling the display if necessary */
-static void vidconsole_newline(struct udevice *dev)
+/*
+ * Move to a newline, scrolling the display if necessary.
+ * ctx must be non-NULL
+ */
+static void vidconsole_newline(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 udevice *vid_dev = dev->parent;
 	struct video_priv *vid_priv = dev_get_uclass_priv(vid_dev);
 	const int rows = CONFIG_VAL(CONSOLE_SCROLL_LINES);
@@ -469,7 +470,7 @@  static int vidconsole_output_glyph(struct udevice *dev, int ch)
 	 */
 	ret = vidconsole_putc_xy(dev, ctx->xcur_frac, ctx->ycur, ch);
 	if (ret == -EAGAIN) {
-		vidconsole_newline(dev);
+		vidconsole_newline(dev, ctx);
 		ret = vidconsole_putc_xy(dev, ctx->xcur_frac, ctx->ycur, ch);
 	}
 	if (ret < 0)
@@ -477,7 +478,7 @@  static int vidconsole_output_glyph(struct udevice *dev, int ch)
 	ctx->xcur_frac += ret;
 	ctx->last_ch = ch;
 	if (ctx->xcur_frac >= ctx->xsize_frac)
-		vidconsole_newline(dev);
+		vidconsole_newline(dev, ctx);
 	cli_index_adjust(ctx, 1);
 
 	return 0;
@@ -510,7 +511,7 @@  int vidconsole_put_char(struct udevice *dev, char ch)
 		ctx->xcur_frac = ctx->xstart_frac;
 		break;
 	case '\n':
-		vidconsole_newline(dev);
+		vidconsole_newline(dev, ctx);
 		vidconsole_entry_start(dev, NULL);
 		break;
 	case '\t':	/* Tab (8 chars alignment) */
@@ -518,7 +519,7 @@  int vidconsole_put_char(struct udevice *dev, char ch)
 				+ 1) * ctx->tab_width_frac;
 
 		if (ctx->xcur_frac >= ctx->xsize_frac)
-			vidconsole_newline(dev);
+			vidconsole_newline(dev, ctx);
 		break;
 	case '\b':
 		vidconsole_back(dev, ctx);