[Concept,v2,07/16] sandbox: Provide a way to tell if the video is visible

Message ID 20250825162727.3185381-8-sjg@u-boot.org
State New
Headers
Series console: Refactor in preparation for the pager |

Commit Message

Simon Glass Aug. 25, 2025, 4:27 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Sandbox is often run with the display disabled, so even though it has a
video device, it is not being shown. Provide a way to detect this. For
all other platforms, we assume the display is shown, when there is a
video device.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Add new patch to provide a way to tell if the video is visible

 arch/sandbox/cpu/state.c         |  7 +++++++
 arch/sandbox/include/asm/state.h |  7 +++++++
 include/video.h                  | 21 +++++++++++++++++++++
 3 files changed, 35 insertions(+)
  

Patch

diff --git a/arch/sandbox/cpu/state.c b/arch/sandbox/cpu/state.c
index d883cf2132a..e492855755b 100644
--- a/arch/sandbox/cpu/state.c
+++ b/arch/sandbox/cpu/state.c
@@ -483,6 +483,13 @@  bool sandbox_serial_is_tty(void)
 	return state->serial_is_tty;
 }
 
+bool sandbox_video_is_visible(void)
+{
+	struct sandbox_state *state = state_get_current();
+
+	return state->show_lcd;
+}
+
 int state_init(void)
 {
 	state = &main_state;
diff --git a/arch/sandbox/include/asm/state.h b/arch/sandbox/include/asm/state.h
index 5350ee6b8fa..a9c4c889bd9 100644
--- a/arch/sandbox/include/asm/state.h
+++ b/arch/sandbox/include/asm/state.h
@@ -385,6 +385,13 @@  int state_load_other_fdt(const char **bufp, int *sizep);
  */
 bool sandbox_serial_is_tty(void);
 
+/*
+ * sandbox_video_is_visible() - check if video display is showing
+ *
+ * Return: true if display is active, false if just using the serial console
+ */
+bool sandbox_video_is_visible(void);
+
 /**
  * Initialize the test system state
  */
diff --git a/include/video.h b/include/video.h
index 5b539eafb89..b2eaecf5866 100644
--- a/include/video.h
+++ b/include/video.h
@@ -8,6 +8,9 @@ 
 #define _VIDEO_H_
 
 #include <stdio_dev.h>
+#ifdef CONFIG_SANDBOX
+#include <asm/state.h>
+#endif
 
 struct udevice;
 
@@ -460,4 +463,22 @@  int video_reserve_from_bloblist(struct video_handoff *ho);
  */
 ulong video_get_fb(void);
 
+/**
+ * video_is_visible() - check if the video display is being used
+ *
+ * This does not indicate that there is actually a display, only that if there
+ * is one, we can assume it is present
+ *
+ * Return: true if any display is likely visible, false if not
+ */
+static inline bool video_is_visible(void)
+{
+#ifdef CONFIG_SANDBOX
+	return sandbox_video_is_visible();
+#else
+	/* assume that it is! */
+	return true;
+#endif
+}
+
 #endif