[PATCH] video: Add copy_fb_to_hw op

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] video: Add copy_fb_to_hw op

Frederik Aalund
Some devices have their own framebuffer memory that is not
shared directly with the CPU. For said devices, we need to
copy U-boot's framebuffer (priv->fb) to the device's own
framebuffer memory. E.g., via SPI.

To support these devices, I've added the copy_fb_to_hw op.
It's optional, so existing drivers do not need to define this
op.

I've used this new op to add support for the
SSD2119 display panel driver over 4-wire SPI. I'll add this
video driver in a subsequent patch.

Signed-off-by: Frederik Aalund <[hidden email]>
Cc: [hidden email]

---
 drivers/video/video-uclass.c | 14 ++++++++++++++
 include/video.h              |  8 +++++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 12057c8a5b..6921f1ec2b 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -147,6 +147,8 @@ void video_set_default_colors(struct udevice *dev, bool invert)
 /* Flush video activity to the caches */
 void video_sync(struct udevice *vid, bool force)
 {
+ int ret;
+ struct video_ops *ops = video_get_ops(vid);
  /*
  * flush_dcache_range() is declared in common.h but it seems that some
  * architectures do not actually implement it. Is there a way to find
@@ -169,6 +171,18 @@ void video_sync(struct udevice *vid, bool force)
  last_sync = get_timer(0);
  }
 #endif
+ /*
+ * Some devices have their own framebuffer memory that is not
+ * shared directly with the CPU. For said devices, we need to
+ * copy U-boot's framebuffer (priv->fb) to the device's own
+ * framebuffer memory. E.g., via SPI.
+ */
+ if (ops->copy_fb_to_hw) {
+ ret = ops->copy_fb_to_hw(vid);
+ if (ret) {
+ dev_err(vid, "Could not copy frame buffer to hardware: %d\n", ret);
+ }
+ }
 }
 
 void video_sync_all(void)
diff --git a/include/video.h b/include/video.h
index 485071d072..a72807e3cb 100644
--- a/include/video.h
+++ b/include/video.h
@@ -96,8 +96,14 @@ struct video_priv {
  u8 bg_col_idx;
 };
 
-/* Placeholder - there are no video operations at present */
 struct video_ops {
+ /**
+ * copy_fb_to_hw() - Copy the current frame buffer to the hardware
+ *
+ * @dev: Video device
+ * @return 0 if OK, -ve on error
+ */
+ int (*copy_fb_to_hw)(struct udevice *dev);
 };
 
 #define video_get_ops(dev)        ((struct video_ops *)(dev)->driver->ops)
--
2.25.1

Reply | Threaded
Open this post in threaded view
|

[PATCH v2] video: Add copy_fb_to_hw op

Anatolij Gustschin
From: Frederik Aalund <[hidden email]>

Some devices have their own framebuffer memory that is not
shared directly with the CPU. For said devices, we need to
copy U-boot's framebuffer (priv->fb) to the device's own
framebuffer memory. E.g., via SPI.

To support these devices, I've added the copy_fb_to_hw op.
It's optional, so existing drivers do not need to define this
op.

I've used this new op to add support for the SSD2119 display
panel driver over 4-wire SPI. I'll add this video driver in
a subsequent patch.

Signed-off-by: Frederik Aalund <[hidden email]>
[agust: add Kconfig option]
Signed-off-by: Anatolij Gustschin <[hidden email]>
---
Changes in v2:
 - make this copy op optional and add Kconfig entry
 - check 'ops' pointer before dereferencing

 drivers/video/Kconfig        | 10 ++++++++++
 drivers/video/video-uclass.c | 18 ++++++++++++++++++
 include/video.h              |  8 +++++++-
 3 files changed, 35 insertions(+), 1 deletion(-)

diff --git a/drivers/video/Kconfig b/drivers/video/Kconfig
index e2e1f9c476..bb8c033d3d 100644
--- a/drivers/video/Kconfig
+++ b/drivers/video/Kconfig
@@ -53,6 +53,16 @@ config VIDEO_COPY
   To use this, your video driver must set @copy_base in
   struct video_uc_platdata.
 
+config VIDEO_COPY_TO_HW
+ bool "Enable copying the frame buffer to external display hardware"
+ depends on DM_VIDEO
+ help
+  Some devices have their own framebuffer memory that is not
+  shared directly with the CPU. For such devices, the framebuffer
+  must be copied to the device's own framebuffer memory, e.g. via SPI.
+  Enable this option and implement video_ops copy_fb_to_hw() to
+  support this feature.
+
 config BACKLIGHT_PWM
  bool "Generic PWM based Backlight Driver"
  depends on BACKLIGHT && DM_PWM
diff --git a/drivers/video/video-uclass.c b/drivers/video/video-uclass.c
index 650891e49d..00e861bd55 100644
--- a/drivers/video/video-uclass.c
+++ b/drivers/video/video-uclass.c
@@ -196,6 +196,24 @@ void video_sync(struct udevice *vid, bool force)
  last_sync = get_timer(0);
  }
 #endif
+ /*
+ * Some devices have their own framebuffer memory that is not
+ * shared directly with the CPU. For said devices, we need to
+ * copy U-Boot's framebuffer (priv->fb) to the device's own
+ * framebuffer memory. E.g., via SPI.
+ */
+ if (IS_ENABLED(CONFIG_VIDEO_COPY_TO_HW)) {
+ struct video_ops *ops = video_get_ops(vid);
+ int ret;
+
+ if (ops && ops->copy_fb_to_hw) {
+ ret = ops->copy_fb_to_hw(vid);
+ if (ret) {
+ dev_err(vid, "Could not copy frame buffer to hardware: %d\n",
+ ret);
+ }
+ }
+ }
 }
 
 void video_sync_all(void)
diff --git a/include/video.h b/include/video.h
index 9d09d2409a..91ade65a73 100644
--- a/include/video.h
+++ b/include/video.h
@@ -114,8 +114,14 @@ struct video_priv {
  u8 bg_col_idx;
 };
 
-/* Placeholder - there are no video operations at present */
 struct video_ops {
+ /**
+ * copy_fb_to_hw() - Copy the current frame buffer to the hardware
+ *
+ * @dev: Video device
+ * @return 0 if OK, -ve on error
+ */
+ int (*copy_fb_to_hw)(struct udevice *dev);
 };
 
 #define video_get_ops(dev)        ((struct video_ops *)(dev)->driver->ops)
--
2.17.1