Skip to content

Commit ed914f6

Browse files
committed
Merge tag 'of_videomode_helper' of git://git.pengutronix.de/git/str/linux into drm-next
videomode helpers for of + devicetree stuff, required for new kms drivers (not the fbdev maintainer). * tag 'of_videomode_helper' of git://git.pengutronix.de/git/str/linux: drm_modes: add of_videomode helpers drm_modes: add videomode helpers fbmon: add of_videomode helpers fbmon: add videomode helpers video: add of helper for display timings/videomode video: add display_timing and videomode viafb: rename display_timing to via_display_timing
2 parents bb0f78d + edb37a9 commit ed914f6

21 files changed

Lines changed: 894 additions & 13 deletions

File tree

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
display-timing bindings
2+
=======================
3+
4+
display-timings node
5+
--------------------
6+
7+
required properties:
8+
- none
9+
10+
optional properties:
11+
- native-mode: The native mode for the display, in case multiple modes are
12+
provided. When omitted, assume the first node is the native.
13+
14+
timing subnode
15+
--------------
16+
17+
required properties:
18+
- hactive, vactive: display resolution
19+
- hfront-porch, hback-porch, hsync-len: horizontal display timing parameters
20+
in pixels
21+
vfront-porch, vback-porch, vsync-len: vertical display timing parameters in
22+
lines
23+
- clock-frequency: display clock in Hz
24+
25+
optional properties:
26+
- hsync-active: hsync pulse is active low/high/ignored
27+
- vsync-active: vsync pulse is active low/high/ignored
28+
- de-active: data-enable pulse is active low/high/ignored
29+
- pixelclk-active: with
30+
- active high = drive pixel data on rising edge/
31+
sample data on falling edge
32+
- active low = drive pixel data on falling edge/
33+
sample data on rising edge
34+
- ignored = ignored
35+
- interlaced (bool): boolean to enable interlaced mode
36+
- doublescan (bool): boolean to enable doublescan mode
37+
38+
All the optional properties that are not bool follow the following logic:
39+
<1>: high active
40+
<0>: low active
41+
omitted: not used on hardware
42+
43+
There are different ways of describing the capabilities of a display. The
44+
devicetree representation corresponds to the one commonly found in datasheets
45+
for displays. If a display supports multiple signal timings, the native-mode
46+
can be specified.
47+
48+
The parameters are defined as:
49+
50+
+----------+-------------------------------------+----------+-------+
51+
| | ↑ | | |
52+
| | |vback_porch | | |
53+
| | ↓ | | |
54+
+----------#######################################----------+-------+
55+
| # ↑ # | |
56+
| # | # | |
57+
| hback # | # hfront | hsync |
58+
| porch # | hactive # porch | len |
59+
|<-------->#<-------+--------------------------->#<-------->|<----->|
60+
| # | # | |
61+
| # |vactive # | |
62+
| # | # | |
63+
| # ↓ # | |
64+
+----------#######################################----------+-------+
65+
| | ↑ | | |
66+
| | |vfront_porch | | |
67+
| | ↓ | | |
68+
+----------+-------------------------------------+----------+-------+
69+
| | ↑ | | |
70+
| | |vsync_len | | |
71+
| | ↓ | | |
72+
+----------+-------------------------------------+----------+-------+
73+
74+
Example:
75+
76+
display-timings {
77+
native-mode = <&timing0>;
78+
timing0: 1080p24 {
79+
/* 1920x1080p24 */
80+
clock-frequency = <52000000>;
81+
hactive = <1920>;
82+
vactive = <1080>;
83+
hfront-porch = <25>;
84+
hback-porch = <25>;
85+
hsync-len = <25>;
86+
vback-porch = <2>;
87+
vfront-porch = <2>;
88+
vsync-len = <2>;
89+
hsync-active = <1>;
90+
};
91+
};
92+
93+
Every required property also supports the use of ranges, so the commonly used
94+
datasheet description with minimum, typical and maximum values can be used.
95+
96+
Example:
97+
98+
timing1: timing {
99+
/* 1920x1080p24 */
100+
clock-frequency = <148500000>;
101+
hactive = <1920>;
102+
vactive = <1080>;
103+
hsync-len = <0 44 60>;
104+
hfront-porch = <80 88 95>;
105+
hback-porch = <100 148 160>;
106+
vfront-porch = <0 4 6>;
107+
vback-porch = <0 36 50>;
108+
vsync-len = <0 5 6>;
109+
};

‎drivers/gpu/drm/drm_modes.c‎

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

3941
/**
4042
* drm_mode_debug_printmodeline - debug print a mode
@@ -504,6 +506,74 @@ drm_gtf_mode(struct drm_device *dev, int hdisplay, int vdisplay, int vrefresh,
504506
}
505507
EXPORT_SYMBOL(drm_gtf_mode);
506508

509+
#if IS_ENABLED(CONFIG_VIDEOMODE)
510+
int drm_display_mode_from_videomode(const struct videomode *vm,
511+
struct drm_display_mode *dmode)
512+
{
513+
dmode->hdisplay = vm->hactive;
514+
dmode->hsync_start = dmode->hdisplay + vm->hfront_porch;
515+
dmode->hsync_end = dmode->hsync_start + vm->hsync_len;
516+
dmode->htotal = dmode->hsync_end + vm->hback_porch;
517+
518+
dmode->vdisplay = vm->vactive;
519+
dmode->vsync_start = dmode->vdisplay + vm->vfront_porch;
520+
dmode->vsync_end = dmode->vsync_start + vm->vsync_len;
521+
dmode->vtotal = dmode->vsync_end + vm->vback_porch;
522+
523+
dmode->clock = vm->pixelclock / 1000;
524+
525+
dmode->flags = 0;
526+
if (vm->dmt_flags & VESA_DMT_HSYNC_HIGH)
527+
dmode->flags |= DRM_MODE_FLAG_PHSYNC;
528+
else if (vm->dmt_flags & VESA_DMT_HSYNC_LOW)
529+
dmode->flags |= DRM_MODE_FLAG_NHSYNC;
530+
if (vm->dmt_flags & VESA_DMT_VSYNC_HIGH)
531+
dmode->flags |= DRM_MODE_FLAG_PVSYNC;
532+
else if (vm->dmt_flags & VESA_DMT_VSYNC_LOW)
533+
dmode->flags |= DRM_MODE_FLAG_NVSYNC;
534+
if (vm->data_flags & DISPLAY_FLAGS_INTERLACED)
535+
dmode->flags |= DRM_MODE_FLAG_INTERLACE;
536+
if (vm->data_flags & DISPLAY_FLAGS_DOUBLESCAN)
537+
dmode->flags |= DRM_MODE_FLAG_DBLSCAN;
538+
drm_mode_set_name(dmode);
539+
540+
return 0;
541+
}
542+
EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
543+
#endif
544+
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+
507577
/**
508578
* drm_mode_set_name - set the name on a mode
509579
* @mode: name will be set in this mode

‎drivers/video/Kconfig‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,27 @@ config VIDEO_OUTPUT_CONTROL
3333
This framework adds support for low-level control of the video
3434
output switch.
3535

36+
config DISPLAY_TIMING
37+
bool
38+
39+
config VIDEOMODE
40+
bool
41+
42+
config OF_DISPLAY_TIMING
43+
bool "Enable device tree display timing support"
44+
depends on OF
45+
select DISPLAY_TIMING
46+
help
47+
helper to parse display timings from the devicetree
48+
49+
config OF_VIDEOMODE
50+
bool "Enable device tree videomode support"
51+
depends on OF
52+
select VIDEOMODE
53+
select OF_DISPLAY_TIMING
54+
help
55+
helper to get videomodes from the devicetree
56+
3657
menuconfig FB
3758
tristate "Support for frame buffer devices"
3859
---help---

‎drivers/video/Makefile‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,7 @@ obj-$(CONFIG_FB_VIRTUAL) += vfb.o
168168

169169
#video output switch sysfs driver
170170
obj-$(CONFIG_VIDEO_OUTPUT_CONTROL) += output.o
171+
obj-$(CONFIG_DISPLAY_TIMING) += display_timing.o
172+
obj-$(CONFIG_OF_DISPLAY_TIMING) += of_display_timing.o
173+
obj-$(CONFIG_VIDEOMODE) += videomode.o
174+
obj-$(CONFIG_OF_VIDEOMODE) += of_videomode.o

‎drivers/video/display_timing.c‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* generic display timing functions
3+
*
4+
* Copyright (c) 2012 Steffen Trumtrar <s.trumtrar@pengutronix.de>, Pengutronix
5+
*
6+
* This file is released under the GPLv2
7+
*/
8+
9+
#include <linux/export.h>
10+
#include <linux/slab.h>
11+
#include <video/display_timing.h>
12+
13+
void display_timings_release(struct display_timings *disp)
14+
{
15+
if (disp->timings) {
16+
unsigned int i;
17+
18+
for (i = 0; i < disp->num_timings; i++)
19+
kfree(disp->timings[i]);
20+
kfree(disp->timings);
21+
}
22+
kfree(disp);
23+
}
24+
EXPORT_SYMBOL_GPL(display_timings_release);

‎drivers/video/fbmon.c‎

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
#include <linux/pci.h>
3232
#include <linux/slab.h>
3333
#include <video/edid.h>
34+
#include <video/of_videomode.h>
35+
#include <video/videomode.h>
3436
#ifdef CONFIG_PPC_OF
3537
#include <asm/prom.h>
3638
#include <asm/pci-bridge.h>
@@ -1373,6 +1375,98 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_inf
13731375
kfree(timings);
13741376
return err;
13751377
}
1378+
1379+
#if IS_ENABLED(CONFIG_VIDEOMODE)
1380+
int fb_videomode_from_videomode(const struct videomode *vm,
1381+
struct fb_videomode *fbmode)
1382+
{
1383+
unsigned int htotal, vtotal;
1384+
1385+
fbmode->xres = vm->hactive;
1386+
fbmode->left_margin = vm->hback_porch;
1387+
fbmode->right_margin = vm->hfront_porch;
1388+
fbmode->hsync_len = vm->hsync_len;
1389+
1390+
fbmode->yres = vm->vactive;
1391+
fbmode->upper_margin = vm->vback_porch;
1392+
fbmode->lower_margin = vm->vfront_porch;
1393+
fbmode->vsync_len = vm->vsync_len;
1394+
1395+
/* prevent division by zero in KHZ2PICOS macro */
1396+
fbmode->pixclock = vm->pixelclock ?
1397+
KHZ2PICOS(vm->pixelclock / 1000) : 0;
1398+
1399+
fbmode->sync = 0;
1400+
fbmode->vmode = 0;
1401+
if (vm->dmt_flags & VESA_DMT_HSYNC_HIGH)
1402+
fbmode->sync |= FB_SYNC_HOR_HIGH_ACT;
1403+
if (vm->dmt_flags & VESA_DMT_HSYNC_HIGH)
1404+
fbmode->sync |= FB_SYNC_VERT_HIGH_ACT;
1405+
if (vm->data_flags & DISPLAY_FLAGS_INTERLACED)
1406+
fbmode->vmode |= FB_VMODE_INTERLACED;
1407+
if (vm->data_flags & DISPLAY_FLAGS_DOUBLESCAN)
1408+
fbmode->vmode |= FB_VMODE_DOUBLE;
1409+
fbmode->flag = 0;
1410+
1411+
htotal = vm->hactive + vm->hfront_porch + vm->hback_porch +
1412+
vm->hsync_len;
1413+
vtotal = vm->vactive + vm->vfront_porch + vm->vback_porch +
1414+
vm->vsync_len;
1415+
/* prevent division by zero */
1416+
if (htotal && vtotal) {
1417+
fbmode->refresh = vm->pixelclock / (htotal * vtotal);
1418+
/* a mode must have htotal and vtotal != 0 or it is invalid */
1419+
} else {
1420+
fbmode->refresh = 0;
1421+
return -EINVAL;
1422+
}
1423+
1424+
return 0;
1425+
}
1426+
EXPORT_SYMBOL_GPL(fb_videomode_from_videomode);
1427+
#endif
1428+
1429+
#if IS_ENABLED(CONFIG_OF_VIDEOMODE)
1430+
static inline void dump_fb_videomode(const struct fb_videomode *m)
1431+
{
1432+
pr_debug("fb_videomode = %ux%u@%uHz (%ukHz) %u %u %u %u %u %u %u %u %u\n",
1433+
m->xres, m->yres, m->refresh, m->pixclock, m->left_margin,
1434+
m->right_margin, m->upper_margin, m->lower_margin,
1435+
m->hsync_len, m->vsync_len, m->sync, m->vmode, m->flag);
1436+
}
1437+
1438+
/**
1439+
* of_get_fb_videomode - get a fb_videomode from devicetree
1440+
* @np: device_node with the timing specification
1441+
* @fb: will be set to the return value
1442+
* @index: index into the list of display timings in devicetree
1443+
*
1444+
* DESCRIPTION:
1445+
* This function is expensive and should only be used, if only one mode is to be
1446+
* read from DT. To get multiple modes start with of_get_display_timings ond
1447+
* work with that instead.
1448+
*/
1449+
int of_get_fb_videomode(struct device_node *np, struct fb_videomode *fb,
1450+
int index)
1451+
{
1452+
struct videomode vm;
1453+
int ret;
1454+
1455+
ret = of_get_videomode(np, &vm, index);
1456+
if (ret)
1457+
return ret;
1458+
1459+
fb_videomode_from_videomode(&vm, fb);
1460+
1461+
pr_debug("%s: got %dx%d display mode from %s\n",
1462+
of_node_full_name(np), vm.hactive, vm.vactive, np->name);
1463+
dump_fb_videomode(fb);
1464+
1465+
return 0;
1466+
}
1467+
EXPORT_SYMBOL_GPL(of_get_fb_videomode);
1468+
#endif
1469+
13761470
#else
13771471
int fb_parse_edid(unsigned char *edid, struct fb_var_screeninfo *var)
13781472
{

0 commit comments

Comments
 (0)