1 From ab0dac9b018f82dfb5696e9671734178d226872f Mon Sep 17 00:00:00 2001
2 From: =?UTF-8?q?Noralf=20Tr=C3=B8nnes?= <noralf@tronnes.org>
3 Date: Sun, 27 Feb 2022 13:47:11 +0100
4 Subject: [PATCH] drm/modes: Add of_get_drm_panel_display_mode()
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 commit 95ae342 upstream.
11 Add a function to get a drm_display_mode from a panel-timing
14 Suggested-by: Sam Ravnborg <sam@ravnborg.org>
15 Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
16 Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
17 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
18 Link: https://patchwork.freedesktop.org/patch/msgid/20220227124713.39766-4-noralf@tronnes.org
20 drivers/gpu/drm/drm_modes.c | 49 +++++++++++++++++++++++++++++++++++++
21 include/drm/drm_modes.h | 8 ++++++
22 2 files changed, 57 insertions(+)
24 --- a/drivers/gpu/drm/drm_modes.c
25 +++ b/drivers/gpu/drm/drm_modes.c
27 #include <linux/list_sort.h>
28 #include <linux/export.h>
30 +#include <video/of_display_timing.h>
31 #include <video/of_videomode.h>
32 #include <video/videomode.h>
34 @@ -727,6 +728,54 @@ int of_get_drm_display_mode(struct devic
37 EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
40 + * of_get_drm_panel_display_mode - get a panel-timing drm_display_mode from devicetree
41 + * @np: device_node with the panel-timing specification
42 + * @dmode: will be set to the return value
43 + * @bus_flags: information about pixelclk, sync and DE polarity
45 + * The Device Tree properties width-mm and height-mm will be read and set on
46 + * the display mode if they are present.
49 + * Zero on success, negative error code on failure.
51 +int of_get_drm_panel_display_mode(struct device_node *np,
52 + struct drm_display_mode *dmode, u32 *bus_flags)
54 + u32 width_mm = 0, height_mm = 0;
55 + struct display_timing timing;
56 + struct videomode vm;
59 + ret = of_get_display_timing(np, "panel-timing", &timing);
63 + videomode_from_timing(&timing, &vm);
65 + memset(dmode, 0, sizeof(*dmode));
66 + drm_display_mode_from_videomode(&vm, dmode);
68 + drm_bus_flags_from_videomode(&vm, bus_flags);
70 + ret = of_property_read_u32(np, "width-mm", &width_mm);
71 + if (ret && ret != -EINVAL)
74 + ret = of_property_read_u32(np, "height-mm", &height_mm);
75 + if (ret && ret != -EINVAL)
78 + dmode->width_mm = width_mm;
79 + dmode->height_mm = height_mm;
81 + drm_mode_debug_printmodeline(dmode);
85 +EXPORT_SYMBOL_GPL(of_get_drm_panel_display_mode);
86 #endif /* CONFIG_OF */
87 #endif /* CONFIG_VIDEOMODE_HELPERS */
89 --- a/include/drm/drm_modes.h
90 +++ b/include/drm/drm_modes.h
91 @@ -466,6 +466,8 @@ void drm_bus_flags_from_videomode(const
92 int of_get_drm_display_mode(struct device_node *np,
93 struct drm_display_mode *dmode, u32 *bus_flags,
95 +int of_get_drm_panel_display_mode(struct device_node *np,
96 + struct drm_display_mode *dmode, u32 *bus_flags);
98 static inline int of_get_drm_display_mode(struct device_node *np,
99 struct drm_display_mode *dmode,
100 @@ -473,6 +475,12 @@ static inline int of_get_drm_display_mod
105 +static inline int of_get_drm_panel_display_mode(struct device_node *np,
106 + struct drm_display_mode *dmode, u32 *bus_flags)
112 void drm_mode_set_name(struct drm_display_mode *mode);