Skip to content

Commit

Permalink
drm/modes: Add initializer macro DRM_MODE_INIT()
Browse files Browse the repository at this point in the history
The macro DRM_MODE_INIT() initializes an instance of
struct drm_display_mode with typical parameters. Convert simpledrm
and also update the macro DRM_SIMPLE_MODE().

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
  • Loading branch information
Thomas Zimmermann authored and intel-lab-lkp committed Aug 16, 2022
1 parent 9a1046f commit 25770aa
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
23 changes: 9 additions & 14 deletions drivers/gpu/drm/tiny/simpledrm.c
Expand Up @@ -30,16 +30,6 @@
#define DRIVER_MAJOR 1
#define DRIVER_MINOR 0

/*
* Assume a monitor resolution of 96 dpi to
* get a somewhat reasonable screen size.
*/
#define RES_MM(d) \
(((d) * 254ul) / (96ul * 10ul))

#define SIMPLEDRM_MODE(hd, vd) \
DRM_SIMPLE_MODE(hd, vd, RES_MM(hd), RES_MM(vd))

/*
* Helpers for simplefb
*/
Expand Down Expand Up @@ -641,10 +631,15 @@ static const struct drm_mode_config_funcs simpledrm_mode_config_funcs = {
static struct drm_display_mode simpledrm_mode(unsigned int width,
unsigned int height)
{
struct drm_display_mode mode = { SIMPLEDRM_MODE(width, height) };

mode.clock = mode.hdisplay * mode.vdisplay * 60 / 1000 /* kHz */;
drm_mode_set_name(&mode);
/*
* Assume a monitor resolution of 96 dpi to
* get a somewhat reasonable screen size.
*/
const struct drm_display_mode mode = {
DRM_MODE_INIT(60, width, height,
DRM_MODE_RES_MM(width, 96ul),
DRM_MODE_RES_MM(height, 96ul))
};

return mode;
}
Expand Down
35 changes: 30 additions & 5 deletions include/drm/drm_modes.h
Expand Up @@ -138,6 +138,35 @@ enum drm_mode_status {
.vsync_start = (vss), .vsync_end = (vse), .vtotal = (vt), \
.vscan = (vs), .flags = (f)

/**
* DRM_MODE_RES_MM - Calculates the display size from resolution and DPI
* @res: The resolution in pixel
* @dpi: The number of dots per inch
*/
#define DRM_MODE_RES_MM(res, dpi) \
(((res) * 254ul) / ((dpi) * 10ul))

#define __DRM_MODE_INIT(pix, hd, vd, hd_mm, vd_mm) \
.type = DRM_MODE_TYPE_DRIVER, .clock = (pix), \
.hdisplay = (hd), .hsync_start = (hd), .hsync_end = (hd), \
.htotal = (hd), .vdisplay = (vd), .vsync_start = (vd), \
.vsync_end = (vd), .vtotal = (vd), .width_mm = (hd_mm), \
.height_mm = (vd_mm)

/**
* DRM_SIMPLE_MODE_INIT - Initialize display mode
* @hz: Vertical refresh rate in Hertz
* @hd: Horizontal resolution, width
* @vd: Vertical resolution, height
* @hd_mm: Display width in millimeters
* @vd_mm: Display height in millimeters
*
* This macro initializes a &drm_display_mode that contains information about
* refresh rate, resolution and physical size.
*/
#define DRM_MODE_INIT(hz, hd, vd, hd_mm, vd_mm) \
__DRM_MODE_INIT((hd) * (vd) * (hz) / 1000 /* kHz */, hd, vd, hd_mm, vd_mm)

/**
* DRM_SIMPLE_MODE - Simple display mode
* @hd: Horizontal resolution, width
Expand All @@ -149,11 +178,7 @@ enum drm_mode_status {
* resolution and physical size.
*/
#define DRM_SIMPLE_MODE(hd, vd, hd_mm, vd_mm) \
.type = DRM_MODE_TYPE_DRIVER, .clock = 1 /* pass validation */, \
.hdisplay = (hd), .hsync_start = (hd), .hsync_end = (hd), \
.htotal = (hd), .vdisplay = (vd), .vsync_start = (vd), \
.vsync_end = (vd), .vtotal = (vd), .width_mm = (hd_mm), \
.height_mm = (vd_mm)
__DRM_MODE_INIT(1 /* pass validation */, hd, vd, hd_mm, vd_mm)

#define CRTC_INTERLACE_HALVE_V (1 << 0) /* halve V values for interlacing */
#define CRTC_STEREO_DOUBLE (1 << 1) /* adjust timings for stereo modes */
Expand Down

0 comments on commit 25770aa

Please sign in to comment.