[Concept,18/22] video: Add flags parameter to sync() operation

Message ID 20251003165525.440173-19-sjg@u-boot.org
State New
Headers
Series video: Enhancements to support a pointer |

Commit Message

Simon Glass Oct. 3, 2025, 4:55 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Add an enum video_sync_flags with VIDSYNC_FORCE, VIDSYNC_FLUSH, and
VIDSYNC_COPY flags and update the sync() operation in struct video_ops
to accept a flags parameter. This allows for more flexible control of
video sync behavior.

The VIDSYNC_FLUSH flag is set when a full flush should be performed, and
the VIDSYNC_COPY flag indicates whether the framebuffer should be
flushed to the copy buffer.

The logic is now calculated before calling sync() so drivers can
observe these states.

Co-developed-by: Claude <noreply@anthropic.com>
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 drivers/video/efi.c          |  2 +-
 drivers/video/mcde_simple.c  |  2 +-
 drivers/video/seps525.c      |  2 +-
 drivers/video/video-uclass.c | 14 +++++++++++---
 include/video.h              | 15 ++++++++++++++-
 5 files changed, 28 insertions(+), 7 deletions(-)
  

Patch

diff --git a/drivers/video/efi.c b/drivers/video/efi.c
index 578392c3908..b5e472395e9 100644
--- a/drivers/video/efi.c
+++ b/drivers/video/efi.c
@@ -43,7 +43,7 @@  struct efi_video_priv {
 	bool use_blit;
 };
 
-static int efi_video_sync(struct udevice *dev)
+static int efi_video_sync(struct udevice *dev, uint flags)
 {
 	struct video_priv *vid_priv = dev_get_uclass_priv(dev);
 	struct efi_video_priv *priv = dev_get_priv(dev);
diff --git a/drivers/video/mcde_simple.c b/drivers/video/mcde_simple.c
index 7591e088e38..9dd9c382644 100644
--- a/drivers/video/mcde_simple.c
+++ b/drivers/video/mcde_simple.c
@@ -94,7 +94,7 @@  static int mcde_simple_probe(struct udevice *dev)
 	return 0;
 }
 
-static int mcde_simple_video_sync(struct udevice *dev)
+static int mcde_simple_video_sync(struct udevice *dev, uint flags)
 {
 	struct mcde_simple_priv *priv = dev_get_priv(dev);
 	unsigned int val;
diff --git a/drivers/video/seps525.c b/drivers/video/seps525.c
index 11293872a5c..aaf716cb65d 100644
--- a/drivers/video/seps525.c
+++ b/drivers/video/seps525.c
@@ -221,7 +221,7 @@  static int seps525_spi_startup(struct udevice *dev)
 	return 0;
 }
 
-static int seps525_sync(struct udevice *vid)
+static int seps525_sync(struct udevice *vid, uint flags)
 {
 	struct video_priv *uc_priv = dev_get_uclass_priv(vid);
 	struct seps525_priv *priv = dev_get_priv(vid);
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index f8ba3abc5f4..8f5689a8a51 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -505,23 +505,31 @@  int video_sync(struct udevice *vid, bool force)
 	struct video_priv *priv = dev_get_uclass_priv(vid);
 	struct video_uc_priv *uc_priv = uclass_get_priv(vid->uclass);
 	struct video_ops *ops = video_get_ops(vid);
+	uint flags = 0;
 	int ret;
 
 	/* Skip sync if manual-sync mode is active */
 	if (uc_priv->manual_sync)
 		return 0;
 
+	if (force)
+		flags |= VIDSYNC_FORCE;
+
+	/* Check if sync should do full flush */
+	if (!CONFIG_IS_ENABLED(CYCLIC) || force ||
+	    get_timer(priv->last_sync) >= CONFIG_VIDEO_SYNC_MS)
+		flags |= VIDSYNC_FLUSH;
+
 	if (IS_ENABLED(CONFIG_VIDEO_COPY))
 		video_flush_copy(vid);
 
 	if (ops && ops->sync) {
-		ret = ops->sync(vid);
+		ret = ops->sync(vid, flags);
 		if (ret)
 			return ret;
 	}
 
-	if (CONFIG_IS_ENABLED(CYCLIC) && !force &&
-	    get_timer(priv->last_sync) < CONFIG_VIDEO_SYNC_MS)
+	if (!(flags & VIDSYNC_FLUSH))
 		return 0;
 
 	video_flush_dcache(vid, false);
diff --git a/include/video.h b/include/video.h
index 3f5c8cbd45a..d08781d3a78 100644
--- a/include/video.h
+++ b/include/video.h
@@ -10,6 +10,7 @@ 
 #include <linker_lists.h>
 #include <stdio_dev.h>
 #include <video_defs.h>
+#include <linux/bitops.h>
 #ifdef CONFIG_SANDBOX
 #include <asm/state.h>
 #endif
@@ -74,6 +75,17 @@  enum video_format {
 	VIDEO_X2R10G10B10,
 };
 
+/**
+ * enum video_sync_flags - Flags for video_sync() operations
+ *
+ * @VIDSYNC_FORCE: Force sync even if recently synced or in manual-sync mode
+ * @VIDSYNC_FLUSH: Flush dcache and perform full sync operations
+ */
+enum video_sync_flags {
+	VIDSYNC_FORCE = BIT(0),
+	VIDSYNC_FLUSH = BIT(1),
+};
+
 /**
  * struct video_priv - Device information used by the video uclass
  *
@@ -146,9 +158,10 @@  struct video_ops {
 	 * to optimise the region to redraw.
 	 *
 	 * @dev: Video device
+	 * @flags: Flags for the sync operation (enum video_sync_flags)
 	 * Return 0 on success, or -ve error code
 	 */
-	int (*sync)(struct udevice *dev);
+	int (*sync)(struct udevice *dev, uint flags);
 };
 
 #define video_get_ops(dev)        ((struct video_ops *)(dev)->driver->ops)