bcm27xx: switch to kernel v6.1
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0793-drm-modes-Add-of_get_drm_panel_display_mode.patch
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()
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 commit 95ae342 upstream.
10
11 Add a function to get a drm_display_mode from a panel-timing
12 device tree subnode.
13
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
19 ---
20 drivers/gpu/drm/drm_modes.c | 49 +++++++++++++++++++++++++++++++++++++
21 include/drm/drm_modes.h | 8 ++++++
22 2 files changed, 57 insertions(+)
23
24 --- a/drivers/gpu/drm/drm_modes.c
25 +++ b/drivers/gpu/drm/drm_modes.c
26 @@ -35,6 +35,7 @@
27 #include <linux/list_sort.h>
28 #include <linux/export.h>
29
30 +#include <video/of_display_timing.h>
31 #include <video/of_videomode.h>
32 #include <video/videomode.h>
33
34 @@ -727,6 +728,54 @@ int of_get_drm_display_mode(struct devic
35 return 0;
36 }
37 EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
38 +
39 +/**
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
44 + *
45 + * The Device Tree properties width-mm and height-mm will be read and set on
46 + * the display mode if they are present.
47 + *
48 + * Returns:
49 + * Zero on success, negative error code on failure.
50 + */
51 +int of_get_drm_panel_display_mode(struct device_node *np,
52 + struct drm_display_mode *dmode, u32 *bus_flags)
53 +{
54 + u32 width_mm = 0, height_mm = 0;
55 + struct display_timing timing;
56 + struct videomode vm;
57 + int ret;
58 +
59 + ret = of_get_display_timing(np, "panel-timing", &timing);
60 + if (ret)
61 + return ret;
62 +
63 + videomode_from_timing(&timing, &vm);
64 +
65 + memset(dmode, 0, sizeof(*dmode));
66 + drm_display_mode_from_videomode(&vm, dmode);
67 + if (bus_flags)
68 + drm_bus_flags_from_videomode(&vm, bus_flags);
69 +
70 + ret = of_property_read_u32(np, "width-mm", &width_mm);
71 + if (ret && ret != -EINVAL)
72 + return ret;
73 +
74 + ret = of_property_read_u32(np, "height-mm", &height_mm);
75 + if (ret && ret != -EINVAL)
76 + return ret;
77 +
78 + dmode->width_mm = width_mm;
79 + dmode->height_mm = height_mm;
80 +
81 + drm_mode_debug_printmodeline(dmode);
82 +
83 + return 0;
84 +}
85 +EXPORT_SYMBOL_GPL(of_get_drm_panel_display_mode);
86 #endif /* CONFIG_OF */
87 #endif /* CONFIG_VIDEOMODE_HELPERS */
88
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,
94 int index);
95 +int of_get_drm_panel_display_mode(struct device_node *np,
96 + struct drm_display_mode *dmode, u32 *bus_flags);
97 #else
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
101 {
102 return -EINVAL;
103 }
104 +
105 +static inline int of_get_drm_panel_display_mode(struct device_node *np,
106 + struct drm_display_mode *dmode, u32 *bus_flags)
107 +{
108 + return -EINVAL;
109 +}
110 #endif
111
112 void drm_mode_set_name(struct drm_display_mode *mode);