Skip to content

Commit edb37a9

Browse files
committed
drm_modes: add of_videomode helpers
Add helper to get drm_display_mode from devicetree. Signed-off-by: Steffen Trumtrar <s.trumtrar@pengutronix.de> Reviewed-by: Thierry Reding <thierry.reding@avionic-design.de> Acked-by: Thierry Reding <thierry.reding@avionic-design.de> Tested-by: Thierry Reding <thierry.reding@avionic-design.de> Tested-by: Philipp Zabel <p.zabel@pengutronix.de> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Tested-by: Afzal Mohammed <Afzal@ti.com> Tested-by: Rob Clark <robclark@gmail.com> Tested-by: Leela Krishna Amudala <leelakrishna.a@gmail.com>
1 parent ebc64e4 commit edb37a9

2 files changed

Lines changed: 37 additions & 0 deletions

File tree

‎drivers/gpu/drm/drm_modes.c‎

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/export.h>
3636
#include <drm/drmP.h>
3737
#include <drm/drm_crtc.h>
38+
#include <video/of_videomode.h>
3839
#include <video/videomode.h>
3940

4041
/**
@@ -541,6 +542,38 @@ int drm_display_mode_from_videomode(const struct videomode *vm,
541542
EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
542543
#endif
543544

545+
#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
546+
/**
547+
* of_get_drm_display_mode - get a drm_display_mode from devicetree
548+
* @np: device_node with the timing specification
549+
* @dmode: will be set to the return value
550+
* @index: index into the list of display timings in devicetree
551+
*
552+
* This function is expensive and should only be used, if only one mode is to be
553+
* read from DT. To get multiple modes start with of_get_display_timings and
554+
* work with that instead.
555+
*/
556+
int of_get_drm_display_mode(struct device_node *np,
557+
struct drm_display_mode *dmode, int index)
558+
{
559+
struct videomode vm;
560+
int ret;
561+
562+
ret = of_get_videomode(np, &vm, index);
563+
if (ret)
564+
return ret;
565+
566+
drm_display_mode_from_videomode(&vm, dmode);
567+
568+
pr_debug("%s: got %dx%d display mode from %s\n",
569+
of_node_full_name(np), vm.hactive, vm.vactive, np->name);
570+
drm_mode_debug_printmodeline(dmode);
571+
572+
return 0;
573+
}
574+
EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
575+
#endif
576+
544577
/**
545578
* drm_mode_set_name - set the name on a mode
546579
* @mode: name will be set in this mode

‎include/drm/drmP.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct module;
8585
struct drm_file;
8686
struct drm_device;
8787

88+
struct device_node;
8889
struct videomode;
8990

9091
#include <drm/drm_os_linux.h>
@@ -1460,6 +1461,9 @@ drm_mode_create_from_cmdline_mode(struct drm_device *dev,
14601461

14611462
extern int drm_display_mode_from_videomode(const struct videomode *vm,
14621463
struct drm_display_mode *dmode);
1464+
extern int of_get_drm_display_mode(struct device_node *np,
1465+
struct drm_display_mode *dmode,
1466+
int index);
14631467

14641468
/* Modesetting support */
14651469
extern void drm_vblank_pre_modeset(struct drm_device *dev, int crtc);

0 commit comments

Comments
 (0)