[PATCH v2 2/4] panel: Lightweight support of get_modes()
Markus Schneider-Pargmann (TI.com)
msp at baylibre.com
Wed Dec 3 11:19:11 CET 2025
Linux uses get_modes() to fetch all available panel modes from the
driver. This is also used to fetch the modes from Linux's simple panel
implementation where a list of drm_display_mode structs is used to
define the different possible panels.
To make our work easier, create a compatible way of fetching and
defining these modes in u-boot. get_modes() fetches the available modes
from the panel driver. The get_display_timing() call maps the
drm_display_mode properties to the display_timing struct. This call now
uses whatever panel operation is available, get_display_timing() or
get_modes().
Signed-off-by: Markus Schneider-Pargmann (TI.com) <msp at baylibre.com>
---
drivers/video/panel-uclass.c | 38 ++++++++++++++++++++++--
include/panel.h | 69 ++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 104 insertions(+), 3 deletions(-)
diff --git a/drivers/video/panel-uclass.c b/drivers/video/panel-uclass.c
index 52a3466dc8c1203731dfcb62ebf4e63ed390bbb4..82e8339dde1bcd2cb8d93c7f7d75a29790089fb3 100644
--- a/drivers/video/panel-uclass.c
+++ b/drivers/video/panel-uclass.c
@@ -37,15 +37,47 @@ int panel_set_backlight(struct udevice *dev, int percent)
return ops->set_backlight(dev, percent);
}
+static void drm_mode_to_display_timing(const struct drm_display_mode *mode,
+ struct display_timing *timing)
+{
+ timing->pixelclock.typ = mode->clock * 1000; /* kHz to Hz */
+ timing->hactive.typ = mode->hdisplay;
+ timing->hfront_porch.typ = mode->hsync_start - mode->hdisplay;
+ timing->hsync_len.typ = mode->hsync_end - mode->hsync_start;
+ timing->hback_porch.typ = mode->htotal - mode->hsync_end;
+ timing->vactive.typ = mode->vdisplay;
+ timing->vfront_porch.typ = mode->vsync_start - mode->vdisplay;
+ timing->vsync_len.typ = mode->vsync_end - mode->vsync_start;
+ timing->vback_porch.typ = mode->vtotal - mode->vsync_end;
+
+ /* DRM_MODE_FLAG_* defines are already mapped to u-boot DISPLAY_FLAGS */
+ timing->flags = mode->flags;
+}
+
int panel_get_display_timing(struct udevice *dev,
struct display_timing *timings)
{
struct panel_ops *ops = panel_get_ops(dev);
+ const struct drm_display_mode *modes;
+ int ret = -ENOSYS;
- if (!ops->get_display_timing)
- return -ENOSYS;
+ if (ops->get_display_timing) {
+ ret = ops->get_display_timing(dev, timings);
+ if (ret != -ENODEV)
+ return ret;
+ }
- return ops->get_display_timing(dev, timings);
+ if (!ops->get_modes)
+ return ret;
+
+ ret = ops->get_modes(dev, &modes);
+ if (ret < 0)
+ return ret;
+ else if (ret == 0)
+ return -ENODEV;
+
+ drm_mode_to_display_timing(&modes[0], timings);
+ return 0;
}
UCLASS_DRIVER(panel) = {
diff --git a/include/panel.h b/include/panel.h
index 6c5e2c000fc79f271876daa179455f16da5bc3af..65411efbddf60e11d13c9a91b308bd2ead88c6b1 100644
--- a/include/panel.h
+++ b/include/panel.h
@@ -7,6 +7,62 @@
#ifndef _PANEL_H
#define _PANEL_H
+#include <video.h>
+#include <fdtdec.h>
+
+/* DRM mode flags mapped to U-Boot DISPLAY_FLAGS for direct compatibility */
+#define DRM_MODE_FLAG_NHSYNC DISPLAY_FLAGS_HSYNC_LOW
+#define DRM_MODE_FLAG_PHSYNC DISPLAY_FLAGS_HSYNC_HIGH
+#define DRM_MODE_FLAG_NVSYNC DISPLAY_FLAGS_VSYNC_LOW
+#define DRM_MODE_FLAG_PVSYNC DISPLAY_FLAGS_VSYNC_HIGH
+#define DRM_MODE_FLAG_INTERLACE DISPLAY_FLAGS_INTERLACED
+#define DRM_MODE_FLAG_DBLSCAN DISPLAY_FLAGS_DOUBLESCAN
+#define DRM_MODE_FLAG_DBLCLK DISPLAY_FLAGS_DOUBLECLK
+
+/**
+ * struct drm_display_mode - DRM kernel-internal display mode structure
+ * simplified for U-Boot
+ * @hdisplay: horizontal display size
+ * @hsync_start: horizontal sync start
+ * @hsync_end: horizontal sync end
+ * @htotal: horizontal total size
+ * @vdisplay: vertical display size
+ * @vsync_start: vertical sync start
+ * @vsync_end: vertical sync end
+ * @vtotal: vertical total size
+ *
+ * The horizontal and vertical timings are defined per the following diagram.
+ *
+ * ::
+ *
+ *
+ * Active Front Sync Back
+ * Region Porch Porch
+ * <-----------------------><----------------><-------------><-------------->
+ * //////////////////////|
+ * ////////////////////// |
+ * ////////////////////// |.................. ................
+ * _______________
+ * <----- [hv]display ----->
+ * <------------- [hv]sync_start ------------>
+ * <--------------------- [hv]sync_end --------------------->
+ * <-------------------------------- [hv]total ----------------------------->*
+ */
+struct drm_display_mode {
+ unsigned int clock; /* in kHz */
+
+ u16 hdisplay;
+ u16 hsync_start;
+ u16 hsync_end;
+ u16 htotal;
+ u16 vdisplay;
+ u16 vsync_start;
+ u16 vsync_end;
+ u16 vtotal;
+
+ u32 flags;
+};
+
struct panel_ops {
/**
* enable_backlight() - Enable the panel backlight
@@ -34,6 +90,19 @@ struct panel_ops {
*/
int (*get_display_timing)(struct udevice *dev,
struct display_timing *timing);
+
+ /**
+ * get_modes() - Get display modes from panel
+ *
+ * Returns an array of display modes supported by the panel.
+ * Similar to Linux's drm_panel_funcs->get_modes().
+ *
+ * @dev: Panel device
+ * @modes: Pointer to an array of modes
+ * @return number of modes if OK, -ve on error
+ */
+ int (*get_modes)(struct udevice *dev,
+ const struct drm_display_mode **modes);
};
#define panel_get_ops(dev) ((struct panel_ops *)(dev)->driver->ops)
--
2.51.0
More information about the U-Boot
mailing list