2008-11-08 05:05:41 +07:00
|
|
|
/*
|
|
|
|
* Copyright © 1997-2003 by The XFree86 Project, Inc.
|
|
|
|
* Copyright © 2007 Dave Airlie
|
|
|
|
* Copyright © 2007-2008 Intel Corporation
|
|
|
|
* Jesse Barnes <jesse.barnes@intel.com>
|
2009-06-22 12:17:08 +07:00
|
|
|
* Copyright 2005-2006 Luc Verhaegen
|
2009-06-22 12:17:09 +07:00
|
|
|
* Copyright (c) 2001, Andy Ritger aritger@nvidia.com
|
2008-11-08 05:05:41 +07:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Except as contained in this notice, the name of the copyright holder(s)
|
|
|
|
* and author(s) shall not be used in advertising or otherwise to promote
|
|
|
|
* the sale, use or other dealings in this Software without prior written
|
|
|
|
* authorization from the copyright holder(s) and author(s).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
2010-01-12 13:39:16 +07:00
|
|
|
#include <linux/list_sort.h>
|
2011-08-31 05:16:33 +07:00
|
|
|
#include <linux/export.h>
|
2012-10-03 00:01:07 +07:00
|
|
|
#include <drm/drmP.h>
|
|
|
|
#include <drm/drm_crtc.h>
|
2012-10-29 00:28:06 +07:00
|
|
|
#include <video/of_videomode.h>
|
2012-11-14 17:22:52 +07:00
|
|
|
#include <video/videomode.h>
|
2014-01-23 21:52:20 +07:00
|
|
|
#include <drm/drm_modes.h>
|
2008-11-08 05:05:41 +07:00
|
|
|
|
2014-01-23 21:35:24 +07:00
|
|
|
#include "drm_crtc_internal.h"
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
/**
|
2014-01-23 21:06:15 +07:00
|
|
|
* drm_mode_debug_printmodeline - print a mode to dmesg
|
2008-11-08 05:05:41 +07:00
|
|
|
* @mode: mode to print
|
|
|
|
*
|
|
|
|
* Describe @mode using DRM_DEBUG.
|
|
|
|
*/
|
2012-10-26 01:05:05 +07:00
|
|
|
void drm_mode_debug_printmodeline(const struct drm_display_mode *mode)
|
2008-11-08 05:05:41 +07:00
|
|
|
{
|
2016-11-05 22:08:06 +07:00
|
|
|
DRM_DEBUG_KMS("Modeline " DRM_MODE_FMT "\n", DRM_MODE_ARG(mode));
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_debug_printmodeline);
|
|
|
|
|
2014-01-23 21:35:24 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_create - create a new display mode
|
|
|
|
* @dev: DRM device
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Create a new, cleared drm_display_mode with kzalloc, allocate an ID for it
|
|
|
|
* and return it.
|
2014-01-23 21:35:24 +07:00
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Returns:
|
2014-01-23 21:35:24 +07:00
|
|
|
* Pointer to new mode on success, NULL on error.
|
|
|
|
*/
|
|
|
|
struct drm_display_mode *drm_mode_create(struct drm_device *dev)
|
|
|
|
{
|
|
|
|
struct drm_display_mode *nmode;
|
|
|
|
|
|
|
|
nmode = kzalloc(sizeof(struct drm_display_mode), GFP_KERNEL);
|
|
|
|
if (!nmode)
|
|
|
|
return NULL;
|
|
|
|
|
2017-02-28 21:46:37 +07:00
|
|
|
if (drm_mode_object_add(dev, &nmode->base, DRM_MODE_OBJECT_MODE)) {
|
2014-01-23 21:35:24 +07:00
|
|
|
kfree(nmode);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nmode;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_create);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_destroy - remove a mode
|
|
|
|
* @dev: DRM device
|
|
|
|
* @mode: mode to remove
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Release @mode's unique ID, then free it @mode structure itself using kfree.
|
2014-01-23 21:35:24 +07:00
|
|
|
*/
|
|
|
|
void drm_mode_destroy(struct drm_device *dev, struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
if (!mode)
|
|
|
|
return;
|
|
|
|
|
2016-04-15 12:10:32 +07:00
|
|
|
drm_mode_object_unregister(dev, &mode->base);
|
2014-01-23 21:35:24 +07:00
|
|
|
|
|
|
|
kfree(mode);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_destroy);
|
|
|
|
|
|
|
|
/**
|
2014-01-24 02:05:00 +07:00
|
|
|
* drm_mode_probed_add - add a mode to a connector's probed_mode list
|
2014-01-23 21:35:24 +07:00
|
|
|
* @connector: connector the new mode
|
|
|
|
* @mode: mode data
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Add @mode to @connector's probed_mode list for later use. This list should
|
|
|
|
* then in a second step get filtered and all the modes actually supported by
|
|
|
|
* the hardware moved to the @connector's modes list.
|
2014-01-23 21:35:24 +07:00
|
|
|
*/
|
|
|
|
void drm_mode_probed_add(struct drm_connector *connector,
|
|
|
|
struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
WARN_ON(!mutex_is_locked(&connector->dev->mode_config.mutex));
|
|
|
|
|
|
|
|
list_add_tail(&mode->head, &connector->probed_modes);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_probed_add);
|
|
|
|
|
2009-06-22 12:17:08 +07:00
|
|
|
/**
|
2014-01-24 02:05:00 +07:00
|
|
|
* drm_cvt_mode -create a modeline based on the CVT algorithm
|
|
|
|
* @dev: drm device
|
2009-06-22 12:17:08 +07:00
|
|
|
* @hdisplay: hdisplay size
|
|
|
|
* @vdisplay: vdisplay size
|
2014-01-24 02:05:00 +07:00
|
|
|
* @vrefresh: vrefresh rate
|
|
|
|
* @reduced: whether to use reduced blanking
|
|
|
|
* @interlaced: whether to compute an interlaced mode
|
|
|
|
* @margins: whether to add margins (borders)
|
2009-06-22 12:17:08 +07:00
|
|
|
*
|
|
|
|
* This function is called to generate the modeline based on CVT algorithm
|
|
|
|
* according to the hdisplay, vdisplay, vrefresh.
|
|
|
|
* It is based from the VESA(TM) Coordinated Video Timing Generator by
|
|
|
|
* Graham Loveridge April 9, 2003 available at
|
2010-10-18 16:03:14 +07:00
|
|
|
* http://www.elo.utfsm.cl/~elo212/docs/CVTd6r1.xls
|
2009-06-22 12:17:08 +07:00
|
|
|
*
|
|
|
|
* And it is copied from xf86CVTmode in xserver/hw/xfree86/modes/xf86cvt.c.
|
|
|
|
* What I have done is to translate it by using integer calculation.
|
2014-01-24 02:05:00 +07:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The modeline based on the CVT algorithm stored in a drm_display_mode object.
|
|
|
|
* The display mode object is allocated with drm_mode_create(). Returns NULL
|
|
|
|
* when no mode could be allocated.
|
2009-06-22 12:17:08 +07:00
|
|
|
*/
|
|
|
|
struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, int hdisplay,
|
|
|
|
int vdisplay, int vrefresh,
|
drm/kms: start adding command line interface using fb.
[note this requires an fb patch posted to linux-fbdev-devel already]
This uses the normal video= command line option to control the kms
output setup at boot time. It is used to override the autodetection
done by kms.
video= normally takes a framebuffer as the first parameter, in kms
it will take a connector name, DVI-I-1, or LVDS-1 etc. If no output
connector is specified the mode string will apply to all connectors.
The mode specification used will match down the probed modes, and if
no mode is found it will add a CVT mode that matches.
video=1024x768 - all connectors match a 1024x768 mode or add a CVT on
video=VGA-1:1024x768, VGA-1 connector gets mode only.
The same strings as used in current fb modedb.c are used, except I've
added three more letters, e, D, d, e = enable, D = enable Digital,
d = disable, which allow a connector to be forced into a certain state.
Signed-off-by: Dave Airlie <airlied@redhat.com>
2009-09-23 11:44:08 +07:00
|
|
|
bool reduced, bool interlaced, bool margins)
|
2009-06-22 12:17:08 +07:00
|
|
|
{
|
2014-01-23 21:06:15 +07:00
|
|
|
#define HV_FACTOR 1000
|
2009-06-22 12:17:08 +07:00
|
|
|
/* 1) top/bottom margin size (% of height) - default: 1.8, */
|
|
|
|
#define CVT_MARGIN_PERCENTAGE 18
|
|
|
|
/* 2) character cell horizontal granularity (pixels) - default 8 */
|
|
|
|
#define CVT_H_GRANULARITY 8
|
|
|
|
/* 3) Minimum vertical porch (lines) - default 3 */
|
|
|
|
#define CVT_MIN_V_PORCH 3
|
|
|
|
/* 4) Minimum number of vertical back porch lines - default 6 */
|
|
|
|
#define CVT_MIN_V_BPORCH 6
|
|
|
|
/* Pixel Clock step (kHz) */
|
|
|
|
#define CVT_CLOCK_STEP 250
|
|
|
|
struct drm_display_mode *drm_mode;
|
|
|
|
unsigned int vfieldrate, hperiod;
|
|
|
|
int hdisplay_rnd, hmargin, vdisplay_rnd, vmargin, vsync;
|
|
|
|
int interlace;
|
2016-10-21 21:15:40 +07:00
|
|
|
u64 tmp;
|
2009-06-22 12:17:08 +07:00
|
|
|
|
|
|
|
/* allocate the drm_display_mode structure. If failure, we will
|
|
|
|
* return directly
|
|
|
|
*/
|
|
|
|
drm_mode = drm_mode_create(dev);
|
|
|
|
if (!drm_mode)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* the CVT default refresh rate is 60Hz */
|
|
|
|
if (!vrefresh)
|
|
|
|
vrefresh = 60;
|
|
|
|
|
|
|
|
/* the required field fresh rate */
|
|
|
|
if (interlaced)
|
|
|
|
vfieldrate = vrefresh * 2;
|
|
|
|
else
|
|
|
|
vfieldrate = vrefresh;
|
|
|
|
|
|
|
|
/* horizontal pixels */
|
|
|
|
hdisplay_rnd = hdisplay - (hdisplay % CVT_H_GRANULARITY);
|
|
|
|
|
|
|
|
/* determine the left&right borders */
|
|
|
|
hmargin = 0;
|
|
|
|
if (margins) {
|
|
|
|
hmargin = hdisplay_rnd * CVT_MARGIN_PERCENTAGE / 1000;
|
|
|
|
hmargin -= hmargin % CVT_H_GRANULARITY;
|
|
|
|
}
|
|
|
|
/* find the total active pixels */
|
|
|
|
drm_mode->hdisplay = hdisplay_rnd + 2 * hmargin;
|
|
|
|
|
|
|
|
/* find the number of lines per field */
|
|
|
|
if (interlaced)
|
|
|
|
vdisplay_rnd = vdisplay / 2;
|
|
|
|
else
|
|
|
|
vdisplay_rnd = vdisplay;
|
|
|
|
|
|
|
|
/* find the top & bottom borders */
|
|
|
|
vmargin = 0;
|
|
|
|
if (margins)
|
|
|
|
vmargin = vdisplay_rnd * CVT_MARGIN_PERCENTAGE / 1000;
|
|
|
|
|
2009-08-12 07:30:09 +07:00
|
|
|
drm_mode->vdisplay = vdisplay + 2 * vmargin;
|
2009-06-22 12:17:08 +07:00
|
|
|
|
|
|
|
/* Interlaced */
|
|
|
|
if (interlaced)
|
|
|
|
interlace = 1;
|
|
|
|
else
|
|
|
|
interlace = 0;
|
|
|
|
|
|
|
|
/* Determine VSync Width from aspect ratio */
|
|
|
|
if (!(vdisplay % 3) && ((vdisplay * 4 / 3) == hdisplay))
|
|
|
|
vsync = 4;
|
|
|
|
else if (!(vdisplay % 9) && ((vdisplay * 16 / 9) == hdisplay))
|
|
|
|
vsync = 5;
|
|
|
|
else if (!(vdisplay % 10) && ((vdisplay * 16 / 10) == hdisplay))
|
|
|
|
vsync = 6;
|
|
|
|
else if (!(vdisplay % 4) && ((vdisplay * 5 / 4) == hdisplay))
|
|
|
|
vsync = 7;
|
|
|
|
else if (!(vdisplay % 9) && ((vdisplay * 15 / 9) == hdisplay))
|
|
|
|
vsync = 7;
|
|
|
|
else /* custom */
|
|
|
|
vsync = 10;
|
|
|
|
|
|
|
|
if (!reduced) {
|
|
|
|
/* simplify the GTF calculation */
|
|
|
|
/* 4) Minimum time of vertical sync + back porch interval (µs)
|
|
|
|
* default 550.0
|
|
|
|
*/
|
|
|
|
int tmp1, tmp2;
|
|
|
|
#define CVT_MIN_VSYNC_BP 550
|
|
|
|
/* 3) Nominal HSync width (% of line period) - default 8 */
|
|
|
|
#define CVT_HSYNC_PERCENTAGE 8
|
|
|
|
unsigned int hblank_percentage;
|
|
|
|
int vsyncandback_porch, vback_porch, hblank;
|
|
|
|
|
|
|
|
/* estimated the horizontal period */
|
|
|
|
tmp1 = HV_FACTOR * 1000000 -
|
|
|
|
CVT_MIN_VSYNC_BP * HV_FACTOR * vfieldrate;
|
|
|
|
tmp2 = (vdisplay_rnd + 2 * vmargin + CVT_MIN_V_PORCH) * 2 +
|
|
|
|
interlace;
|
|
|
|
hperiod = tmp1 * 2 / (tmp2 * vfieldrate);
|
|
|
|
|
|
|
|
tmp1 = CVT_MIN_VSYNC_BP * HV_FACTOR / hperiod + 1;
|
|
|
|
/* 9. Find number of lines in sync + backporch */
|
|
|
|
if (tmp1 < (vsync + CVT_MIN_V_PORCH))
|
|
|
|
vsyncandback_porch = vsync + CVT_MIN_V_PORCH;
|
|
|
|
else
|
|
|
|
vsyncandback_porch = tmp1;
|
|
|
|
/* 10. Find number of lines in back porch */
|
|
|
|
vback_porch = vsyncandback_porch - vsync;
|
|
|
|
drm_mode->vtotal = vdisplay_rnd + 2 * vmargin +
|
|
|
|
vsyncandback_porch + CVT_MIN_V_PORCH;
|
|
|
|
/* 5) Definition of Horizontal blanking time limitation */
|
|
|
|
/* Gradient (%/kHz) - default 600 */
|
|
|
|
#define CVT_M_FACTOR 600
|
|
|
|
/* Offset (%) - default 40 */
|
|
|
|
#define CVT_C_FACTOR 40
|
|
|
|
/* Blanking time scaling factor - default 128 */
|
|
|
|
#define CVT_K_FACTOR 128
|
|
|
|
/* Scaling factor weighting - default 20 */
|
|
|
|
#define CVT_J_FACTOR 20
|
|
|
|
#define CVT_M_PRIME (CVT_M_FACTOR * CVT_K_FACTOR / 256)
|
|
|
|
#define CVT_C_PRIME ((CVT_C_FACTOR - CVT_J_FACTOR) * CVT_K_FACTOR / 256 + \
|
|
|
|
CVT_J_FACTOR)
|
|
|
|
/* 12. Find ideal blanking duty cycle from formula */
|
|
|
|
hblank_percentage = CVT_C_PRIME * HV_FACTOR - CVT_M_PRIME *
|
|
|
|
hperiod / 1000;
|
|
|
|
/* 13. Blanking time */
|
|
|
|
if (hblank_percentage < 20 * HV_FACTOR)
|
|
|
|
hblank_percentage = 20 * HV_FACTOR;
|
|
|
|
hblank = drm_mode->hdisplay * hblank_percentage /
|
|
|
|
(100 * HV_FACTOR - hblank_percentage);
|
|
|
|
hblank -= hblank % (2 * CVT_H_GRANULARITY);
|
2015-03-04 15:30:09 +07:00
|
|
|
/* 14. find the total pixels per line */
|
2009-06-22 12:17:08 +07:00
|
|
|
drm_mode->htotal = drm_mode->hdisplay + hblank;
|
|
|
|
drm_mode->hsync_end = drm_mode->hdisplay + hblank / 2;
|
|
|
|
drm_mode->hsync_start = drm_mode->hsync_end -
|
|
|
|
(drm_mode->htotal * CVT_HSYNC_PERCENTAGE) / 100;
|
|
|
|
drm_mode->hsync_start += CVT_H_GRANULARITY -
|
|
|
|
drm_mode->hsync_start % CVT_H_GRANULARITY;
|
|
|
|
/* fill the Vsync values */
|
|
|
|
drm_mode->vsync_start = drm_mode->vdisplay + CVT_MIN_V_PORCH;
|
|
|
|
drm_mode->vsync_end = drm_mode->vsync_start + vsync;
|
|
|
|
} else {
|
|
|
|
/* Reduced blanking */
|
|
|
|
/* Minimum vertical blanking interval time (µs)- default 460 */
|
|
|
|
#define CVT_RB_MIN_VBLANK 460
|
|
|
|
/* Fixed number of clocks for horizontal sync */
|
|
|
|
#define CVT_RB_H_SYNC 32
|
|
|
|
/* Fixed number of clocks for horizontal blanking */
|
|
|
|
#define CVT_RB_H_BLANK 160
|
|
|
|
/* Fixed number of lines for vertical front porch - default 3*/
|
|
|
|
#define CVT_RB_VFPORCH 3
|
|
|
|
int vbilines;
|
|
|
|
int tmp1, tmp2;
|
|
|
|
/* 8. Estimate Horizontal period. */
|
|
|
|
tmp1 = HV_FACTOR * 1000000 -
|
|
|
|
CVT_RB_MIN_VBLANK * HV_FACTOR * vfieldrate;
|
|
|
|
tmp2 = vdisplay_rnd + 2 * vmargin;
|
|
|
|
hperiod = tmp1 / (tmp2 * vfieldrate);
|
|
|
|
/* 9. Find number of lines in vertical blanking */
|
|
|
|
vbilines = CVT_RB_MIN_VBLANK * HV_FACTOR / hperiod + 1;
|
|
|
|
/* 10. Check if vertical blanking is sufficient */
|
|
|
|
if (vbilines < (CVT_RB_VFPORCH + vsync + CVT_MIN_V_BPORCH))
|
|
|
|
vbilines = CVT_RB_VFPORCH + vsync + CVT_MIN_V_BPORCH;
|
|
|
|
/* 11. Find total number of lines in vertical field */
|
|
|
|
drm_mode->vtotal = vdisplay_rnd + 2 * vmargin + vbilines;
|
|
|
|
/* 12. Find total number of pixels in a line */
|
|
|
|
drm_mode->htotal = drm_mode->hdisplay + CVT_RB_H_BLANK;
|
|
|
|
/* Fill in HSync values */
|
|
|
|
drm_mode->hsync_end = drm_mode->hdisplay + CVT_RB_H_BLANK / 2;
|
2010-08-23 21:19:14 +07:00
|
|
|
drm_mode->hsync_start = drm_mode->hsync_end - CVT_RB_H_SYNC;
|
|
|
|
/* Fill in VSync values */
|
|
|
|
drm_mode->vsync_start = drm_mode->vdisplay + CVT_RB_VFPORCH;
|
|
|
|
drm_mode->vsync_end = drm_mode->vsync_start + vsync;
|
2009-06-22 12:17:08 +07:00
|
|
|
}
|
|
|
|
/* 15/13. Find pixel clock frequency (kHz for xf86) */
|
2016-10-21 21:15:40 +07:00
|
|
|
tmp = drm_mode->htotal; /* perform intermediate calcs in u64 */
|
|
|
|
tmp *= HV_FACTOR * 1000;
|
|
|
|
do_div(tmp, hperiod);
|
|
|
|
tmp -= drm_mode->clock % CVT_CLOCK_STEP;
|
|
|
|
drm_mode->clock = tmp;
|
2009-06-22 12:17:08 +07:00
|
|
|
/* 18/16. Find actual vertical frame frequency */
|
|
|
|
/* ignore - just set the mode flag for interlaced */
|
2010-03-30 04:43:31 +07:00
|
|
|
if (interlaced) {
|
2009-06-22 12:17:08 +07:00
|
|
|
drm_mode->vtotal *= 2;
|
2010-03-30 04:43:31 +07:00
|
|
|
drm_mode->flags |= DRM_MODE_FLAG_INTERLACE;
|
|
|
|
}
|
2009-06-22 12:17:08 +07:00
|
|
|
/* Fill the mode line name */
|
|
|
|
drm_mode_set_name(drm_mode);
|
|
|
|
if (reduced)
|
|
|
|
drm_mode->flags |= (DRM_MODE_FLAG_PHSYNC |
|
|
|
|
DRM_MODE_FLAG_NVSYNC);
|
|
|
|
else
|
|
|
|
drm_mode->flags |= (DRM_MODE_FLAG_PVSYNC |
|
|
|
|
DRM_MODE_FLAG_NHSYNC);
|
|
|
|
|
2010-03-30 04:43:31 +07:00
|
|
|
return drm_mode;
|
2009-06-22 12:17:08 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_cvt_mode);
|
|
|
|
|
2009-06-22 12:17:09 +07:00
|
|
|
/**
|
2014-01-24 02:05:00 +07:00
|
|
|
* drm_gtf_mode_complex - create the modeline based on the full GTF algorithm
|
|
|
|
* @dev: drm device
|
|
|
|
* @hdisplay: hdisplay size
|
|
|
|
* @vdisplay: vdisplay size
|
|
|
|
* @vrefresh: vrefresh rate.
|
|
|
|
* @interlaced: whether to compute an interlaced mode
|
|
|
|
* @margins: desired margin (borders) size
|
2014-01-23 21:06:15 +07:00
|
|
|
* @GTF_M: extended GTF formula parameters
|
|
|
|
* @GTF_2C: extended GTF formula parameters
|
|
|
|
* @GTF_K: extended GTF formula parameters
|
|
|
|
* @GTF_2J: extended GTF formula parameters
|
2009-06-22 12:17:09 +07:00
|
|
|
*
|
2010-03-30 04:43:30 +07:00
|
|
|
* GTF feature blocks specify C and J in multiples of 0.5, so we pass them
|
|
|
|
* in here multiplied by two. For a C of 40, pass in 80.
|
2014-01-24 02:05:00 +07:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The modeline based on the full GTF algorithm stored in a drm_display_mode object.
|
|
|
|
* The display mode object is allocated with drm_mode_create(). Returns NULL
|
|
|
|
* when no mode could be allocated.
|
2009-06-22 12:17:09 +07:00
|
|
|
*/
|
2010-03-30 04:43:30 +07:00
|
|
|
struct drm_display_mode *
|
|
|
|
drm_gtf_mode_complex(struct drm_device *dev, int hdisplay, int vdisplay,
|
|
|
|
int vrefresh, bool interlaced, int margins,
|
|
|
|
int GTF_M, int GTF_2C, int GTF_K, int GTF_2J)
|
|
|
|
{ /* 1) top/bottom margin size (% of height) - default: 1.8, */
|
2009-06-22 12:17:09 +07:00
|
|
|
#define GTF_MARGIN_PERCENTAGE 18
|
|
|
|
/* 2) character cell horizontal granularity (pixels) - default 8 */
|
|
|
|
#define GTF_CELL_GRAN 8
|
|
|
|
/* 3) Minimum vertical porch (lines) - default 3 */
|
|
|
|
#define GTF_MIN_V_PORCH 1
|
|
|
|
/* width of vsync in lines */
|
|
|
|
#define V_SYNC_RQD 3
|
|
|
|
/* width of hsync as % of total line */
|
|
|
|
#define H_SYNC_PERCENT 8
|
|
|
|
/* min time of vsync + back porch (microsec) */
|
|
|
|
#define MIN_VSYNC_PLUS_BP 550
|
|
|
|
/* C' and M' are part of the Blanking Duty Cycle computation */
|
2010-03-30 04:43:30 +07:00
|
|
|
#define GTF_C_PRIME ((((GTF_2C - GTF_2J) * GTF_K / 256) + GTF_2J) / 2)
|
|
|
|
#define GTF_M_PRIME (GTF_K * GTF_M / 256)
|
2009-06-22 12:17:09 +07:00
|
|
|
struct drm_display_mode *drm_mode;
|
|
|
|
unsigned int hdisplay_rnd, vdisplay_rnd, vfieldrate_rqd;
|
|
|
|
int top_margin, bottom_margin;
|
|
|
|
int interlace;
|
|
|
|
unsigned int hfreq_est;
|
|
|
|
int vsync_plus_bp, vback_porch;
|
|
|
|
unsigned int vtotal_lines, vfieldrate_est, hperiod;
|
|
|
|
unsigned int vfield_rate, vframe_rate;
|
|
|
|
int left_margin, right_margin;
|
|
|
|
unsigned int total_active_pixels, ideal_duty_cycle;
|
|
|
|
unsigned int hblank, total_pixels, pixel_freq;
|
|
|
|
int hsync, hfront_porch, vodd_front_porch_lines;
|
|
|
|
unsigned int tmp1, tmp2;
|
|
|
|
|
|
|
|
drm_mode = drm_mode_create(dev);
|
|
|
|
if (!drm_mode)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/* 1. In order to give correct results, the number of horizontal
|
|
|
|
* pixels requested is first processed to ensure that it is divisible
|
|
|
|
* by the character size, by rounding it to the nearest character
|
|
|
|
* cell boundary:
|
|
|
|
*/
|
|
|
|
hdisplay_rnd = (hdisplay + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN;
|
|
|
|
hdisplay_rnd = hdisplay_rnd * GTF_CELL_GRAN;
|
|
|
|
|
|
|
|
/* 2. If interlace is requested, the number of vertical lines assumed
|
|
|
|
* by the calculation must be halved, as the computation calculates
|
|
|
|
* the number of vertical lines per field.
|
|
|
|
*/
|
|
|
|
if (interlaced)
|
|
|
|
vdisplay_rnd = vdisplay / 2;
|
|
|
|
else
|
|
|
|
vdisplay_rnd = vdisplay;
|
|
|
|
|
|
|
|
/* 3. Find the frame rate required: */
|
|
|
|
if (interlaced)
|
|
|
|
vfieldrate_rqd = vrefresh * 2;
|
|
|
|
else
|
|
|
|
vfieldrate_rqd = vrefresh;
|
|
|
|
|
|
|
|
/* 4. Find number of lines in Top margin: */
|
|
|
|
top_margin = 0;
|
|
|
|
if (margins)
|
|
|
|
top_margin = (vdisplay_rnd * GTF_MARGIN_PERCENTAGE + 500) /
|
|
|
|
1000;
|
|
|
|
/* 5. Find number of lines in bottom margin: */
|
|
|
|
bottom_margin = top_margin;
|
|
|
|
|
|
|
|
/* 6. If interlace is required, then set variable interlace: */
|
|
|
|
if (interlaced)
|
|
|
|
interlace = 1;
|
|
|
|
else
|
|
|
|
interlace = 0;
|
|
|
|
|
|
|
|
/* 7. Estimate the Horizontal frequency */
|
|
|
|
{
|
|
|
|
tmp1 = (1000000 - MIN_VSYNC_PLUS_BP * vfieldrate_rqd) / 500;
|
|
|
|
tmp2 = (vdisplay_rnd + 2 * top_margin + GTF_MIN_V_PORCH) *
|
|
|
|
2 + interlace;
|
|
|
|
hfreq_est = (tmp2 * 1000 * vfieldrate_rqd) / tmp1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 8. Find the number of lines in V sync + back porch */
|
|
|
|
/* [V SYNC+BP] = RINT(([MIN VSYNC+BP] * hfreq_est / 1000000)) */
|
|
|
|
vsync_plus_bp = MIN_VSYNC_PLUS_BP * hfreq_est / 1000;
|
|
|
|
vsync_plus_bp = (vsync_plus_bp + 500) / 1000;
|
|
|
|
/* 9. Find the number of lines in V back porch alone: */
|
|
|
|
vback_porch = vsync_plus_bp - V_SYNC_RQD;
|
|
|
|
/* 10. Find the total number of lines in Vertical field period: */
|
|
|
|
vtotal_lines = vdisplay_rnd + top_margin + bottom_margin +
|
|
|
|
vsync_plus_bp + GTF_MIN_V_PORCH;
|
|
|
|
/* 11. Estimate the Vertical field frequency: */
|
|
|
|
vfieldrate_est = hfreq_est / vtotal_lines;
|
|
|
|
/* 12. Find the actual horizontal period: */
|
|
|
|
hperiod = 1000000 / (vfieldrate_rqd * vtotal_lines);
|
|
|
|
|
|
|
|
/* 13. Find the actual Vertical field frequency: */
|
|
|
|
vfield_rate = hfreq_est / vtotal_lines;
|
|
|
|
/* 14. Find the Vertical frame frequency: */
|
|
|
|
if (interlaced)
|
|
|
|
vframe_rate = vfield_rate / 2;
|
|
|
|
else
|
|
|
|
vframe_rate = vfield_rate;
|
|
|
|
/* 15. Find number of pixels in left margin: */
|
|
|
|
if (margins)
|
|
|
|
left_margin = (hdisplay_rnd * GTF_MARGIN_PERCENTAGE + 500) /
|
|
|
|
1000;
|
|
|
|
else
|
|
|
|
left_margin = 0;
|
|
|
|
|
|
|
|
/* 16.Find number of pixels in right margin: */
|
|
|
|
right_margin = left_margin;
|
|
|
|
/* 17.Find total number of active pixels in image and left and right */
|
|
|
|
total_active_pixels = hdisplay_rnd + left_margin + right_margin;
|
|
|
|
/* 18.Find the ideal blanking duty cycle from blanking duty cycle */
|
|
|
|
ideal_duty_cycle = GTF_C_PRIME * 1000 -
|
|
|
|
(GTF_M_PRIME * 1000000 / hfreq_est);
|
|
|
|
/* 19.Find the number of pixels in the blanking time to the nearest
|
|
|
|
* double character cell: */
|
|
|
|
hblank = total_active_pixels * ideal_duty_cycle /
|
|
|
|
(100000 - ideal_duty_cycle);
|
|
|
|
hblank = (hblank + GTF_CELL_GRAN) / (2 * GTF_CELL_GRAN);
|
|
|
|
hblank = hblank * 2 * GTF_CELL_GRAN;
|
|
|
|
/* 20.Find total number of pixels: */
|
|
|
|
total_pixels = total_active_pixels + hblank;
|
|
|
|
/* 21.Find pixel clock frequency: */
|
|
|
|
pixel_freq = total_pixels * hfreq_est / 1000;
|
|
|
|
/* Stage 1 computations are now complete; I should really pass
|
|
|
|
* the results to another function and do the Stage 2 computations,
|
|
|
|
* but I only need a few more values so I'll just append the
|
|
|
|
* computations here for now */
|
|
|
|
/* 17. Find the number of pixels in the horizontal sync period: */
|
|
|
|
hsync = H_SYNC_PERCENT * total_pixels / 100;
|
|
|
|
hsync = (hsync + GTF_CELL_GRAN / 2) / GTF_CELL_GRAN;
|
|
|
|
hsync = hsync * GTF_CELL_GRAN;
|
|
|
|
/* 18. Find the number of pixels in horizontal front porch period */
|
|
|
|
hfront_porch = hblank / 2 - hsync;
|
|
|
|
/* 36. Find the number of lines in the odd front porch period: */
|
|
|
|
vodd_front_porch_lines = GTF_MIN_V_PORCH ;
|
|
|
|
|
|
|
|
/* finally, pack the results in the mode struct */
|
|
|
|
drm_mode->hdisplay = hdisplay_rnd;
|
|
|
|
drm_mode->hsync_start = hdisplay_rnd + hfront_porch;
|
|
|
|
drm_mode->hsync_end = drm_mode->hsync_start + hsync;
|
|
|
|
drm_mode->htotal = total_pixels;
|
|
|
|
drm_mode->vdisplay = vdisplay_rnd;
|
|
|
|
drm_mode->vsync_start = vdisplay_rnd + vodd_front_porch_lines;
|
|
|
|
drm_mode->vsync_end = drm_mode->vsync_start + V_SYNC_RQD;
|
|
|
|
drm_mode->vtotal = vtotal_lines;
|
|
|
|
|
|
|
|
drm_mode->clock = pixel_freq;
|
|
|
|
|
|
|
|
if (interlaced) {
|
|
|
|
drm_mode->vtotal *= 2;
|
|
|
|
drm_mode->flags |= DRM_MODE_FLAG_INTERLACE;
|
|
|
|
}
|
|
|
|
|
2010-03-30 04:43:31 +07:00
|
|
|
drm_mode_set_name(drm_mode);
|
2010-04-09 02:00:30 +07:00
|
|
|
if (GTF_M == 600 && GTF_2C == 80 && GTF_K == 128 && GTF_2J == 40)
|
|
|
|
drm_mode->flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC;
|
|
|
|
else
|
|
|
|
drm_mode->flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC;
|
2010-03-30 04:43:31 +07:00
|
|
|
|
2009-06-22 12:17:09 +07:00
|
|
|
return drm_mode;
|
|
|
|
}
|
2010-03-30 04:43:30 +07:00
|
|
|
EXPORT_SYMBOL(drm_gtf_mode_complex);
|
|
|
|
|
|
|
|
/**
|
2014-01-24 02:05:00 +07:00
|
|
|
* drm_gtf_mode - create the modeline based on the GTF algorithm
|
|
|
|
* @dev: drm device
|
|
|
|
* @hdisplay: hdisplay size
|
|
|
|
* @vdisplay: vdisplay size
|
|
|
|
* @vrefresh: vrefresh rate.
|
|
|
|
* @interlaced: whether to compute an interlaced mode
|
|
|
|
* @margins: desired margin (borders) size
|
2010-03-30 04:43:30 +07:00
|
|
|
*
|
|
|
|
* return the modeline based on GTF algorithm
|
|
|
|
*
|
|
|
|
* This function is to create the modeline based on the GTF algorithm.
|
|
|
|
* Generalized Timing Formula is derived from:
|
2016-06-02 04:40:36 +07:00
|
|
|
*
|
2010-03-30 04:43:30 +07:00
|
|
|
* GTF Spreadsheet by Andy Morrish (1/5/97)
|
|
|
|
* available at http://www.vesa.org
|
|
|
|
*
|
|
|
|
* And it is copied from the file of xserver/hw/xfree86/modes/xf86gtf.c.
|
|
|
|
* What I have done is to translate it by using integer calculation.
|
|
|
|
* I also refer to the function of fb_get_mode in the file of
|
|
|
|
* drivers/video/fbmon.c
|
|
|
|
*
|
2016-06-01 03:55:13 +07:00
|
|
|
* Standard GTF parameters::
|
|
|
|
*
|
2015-11-26 00:07:55 +07:00
|
|
|
* M = 600
|
|
|
|
* C = 40
|
|
|
|
* K = 128
|
|
|
|
* J = 20
|
2014-01-24 02:05:00 +07:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The modeline based on the GTF algorithm stored in a drm_display_mode object.
|
|
|
|
* The display mode object is allocated with drm_mode_create(). Returns NULL
|
|
|
|
* when no mode could be allocated.
|
2010-03-30 04:43:30 +07:00
|
|
|
*/
|
|
|
|
struct drm_display_mode *
|
|
|
|
drm_gtf_mode(struct drm_device *dev, int hdisplay, int vdisplay, int vrefresh,
|
2014-01-23 21:06:15 +07:00
|
|
|
bool interlaced, int margins)
|
2010-03-30 04:43:30 +07:00
|
|
|
{
|
2014-01-23 21:06:15 +07:00
|
|
|
return drm_gtf_mode_complex(dev, hdisplay, vdisplay, vrefresh,
|
|
|
|
interlaced, margins,
|
|
|
|
600, 40 * 2, 128, 20 * 2);
|
2010-03-30 04:43:30 +07:00
|
|
|
}
|
2009-06-22 12:17:09 +07:00
|
|
|
EXPORT_SYMBOL(drm_gtf_mode);
|
2010-03-30 04:43:30 +07:00
|
|
|
|
2013-03-12 15:15:43 +07:00
|
|
|
#ifdef CONFIG_VIDEOMODE_HELPERS
|
2014-01-24 02:05:00 +07:00
|
|
|
/**
|
|
|
|
* drm_display_mode_from_videomode - fill in @dmode using @vm,
|
|
|
|
* @vm: videomode structure to use as source
|
|
|
|
* @dmode: drm_display_mode structure to use as destination
|
|
|
|
*
|
|
|
|
* Fills out @dmode using the display mode specified in @vm.
|
|
|
|
*/
|
2014-01-23 22:28:50 +07:00
|
|
|
void drm_display_mode_from_videomode(const struct videomode *vm,
|
|
|
|
struct drm_display_mode *dmode)
|
2012-11-14 17:22:52 +07:00
|
|
|
{
|
|
|
|
dmode->hdisplay = vm->hactive;
|
|
|
|
dmode->hsync_start = dmode->hdisplay + vm->hfront_porch;
|
|
|
|
dmode->hsync_end = dmode->hsync_start + vm->hsync_len;
|
|
|
|
dmode->htotal = dmode->hsync_end + vm->hback_porch;
|
|
|
|
|
|
|
|
dmode->vdisplay = vm->vactive;
|
|
|
|
dmode->vsync_start = dmode->vdisplay + vm->vfront_porch;
|
|
|
|
dmode->vsync_end = dmode->vsync_start + vm->vsync_len;
|
|
|
|
dmode->vtotal = dmode->vsync_end + vm->vback_porch;
|
|
|
|
|
|
|
|
dmode->clock = vm->pixelclock / 1000;
|
|
|
|
|
|
|
|
dmode->flags = 0;
|
2013-03-12 15:26:45 +07:00
|
|
|
if (vm->flags & DISPLAY_FLAGS_HSYNC_HIGH)
|
2012-11-14 17:22:52 +07:00
|
|
|
dmode->flags |= DRM_MODE_FLAG_PHSYNC;
|
2013-03-12 15:26:45 +07:00
|
|
|
else if (vm->flags & DISPLAY_FLAGS_HSYNC_LOW)
|
2012-11-14 17:22:52 +07:00
|
|
|
dmode->flags |= DRM_MODE_FLAG_NHSYNC;
|
2013-03-12 15:26:45 +07:00
|
|
|
if (vm->flags & DISPLAY_FLAGS_VSYNC_HIGH)
|
2012-11-14 17:22:52 +07:00
|
|
|
dmode->flags |= DRM_MODE_FLAG_PVSYNC;
|
2013-03-12 15:26:45 +07:00
|
|
|
else if (vm->flags & DISPLAY_FLAGS_VSYNC_LOW)
|
2012-11-14 17:22:52 +07:00
|
|
|
dmode->flags |= DRM_MODE_FLAG_NVSYNC;
|
2013-03-12 15:26:45 +07:00
|
|
|
if (vm->flags & DISPLAY_FLAGS_INTERLACED)
|
2012-11-14 17:22:52 +07:00
|
|
|
dmode->flags |= DRM_MODE_FLAG_INTERLACE;
|
2013-03-12 15:26:45 +07:00
|
|
|
if (vm->flags & DISPLAY_FLAGS_DOUBLESCAN)
|
2012-11-14 17:22:52 +07:00
|
|
|
dmode->flags |= DRM_MODE_FLAG_DBLSCAN;
|
2013-05-27 19:33:35 +07:00
|
|
|
if (vm->flags & DISPLAY_FLAGS_DOUBLECLK)
|
|
|
|
dmode->flags |= DRM_MODE_FLAG_DBLCLK;
|
2012-11-14 17:22:52 +07:00
|
|
|
drm_mode_set_name(dmode);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(drm_display_mode_from_videomode);
|
|
|
|
|
2014-12-19 09:00:22 +07:00
|
|
|
/**
|
|
|
|
* drm_display_mode_to_videomode - fill in @vm using @dmode,
|
|
|
|
* @dmode: drm_display_mode structure to use as source
|
|
|
|
* @vm: videomode structure to use as destination
|
|
|
|
*
|
|
|
|
* Fills out @vm using the display mode specified in @dmode.
|
|
|
|
*/
|
|
|
|
void drm_display_mode_to_videomode(const struct drm_display_mode *dmode,
|
|
|
|
struct videomode *vm)
|
|
|
|
{
|
|
|
|
vm->hactive = dmode->hdisplay;
|
|
|
|
vm->hfront_porch = dmode->hsync_start - dmode->hdisplay;
|
|
|
|
vm->hsync_len = dmode->hsync_end - dmode->hsync_start;
|
|
|
|
vm->hback_porch = dmode->htotal - dmode->hsync_end;
|
|
|
|
|
|
|
|
vm->vactive = dmode->vdisplay;
|
|
|
|
vm->vfront_porch = dmode->vsync_start - dmode->vdisplay;
|
|
|
|
vm->vsync_len = dmode->vsync_end - dmode->vsync_start;
|
|
|
|
vm->vback_porch = dmode->vtotal - dmode->vsync_end;
|
|
|
|
|
|
|
|
vm->pixelclock = dmode->clock * 1000;
|
|
|
|
|
|
|
|
vm->flags = 0;
|
|
|
|
if (dmode->flags & DRM_MODE_FLAG_PHSYNC)
|
|
|
|
vm->flags |= DISPLAY_FLAGS_HSYNC_HIGH;
|
|
|
|
else if (dmode->flags & DRM_MODE_FLAG_NHSYNC)
|
|
|
|
vm->flags |= DISPLAY_FLAGS_HSYNC_LOW;
|
|
|
|
if (dmode->flags & DRM_MODE_FLAG_PVSYNC)
|
|
|
|
vm->flags |= DISPLAY_FLAGS_VSYNC_HIGH;
|
|
|
|
else if (dmode->flags & DRM_MODE_FLAG_NVSYNC)
|
|
|
|
vm->flags |= DISPLAY_FLAGS_VSYNC_LOW;
|
|
|
|
if (dmode->flags & DRM_MODE_FLAG_INTERLACE)
|
|
|
|
vm->flags |= DISPLAY_FLAGS_INTERLACED;
|
|
|
|
if (dmode->flags & DRM_MODE_FLAG_DBLSCAN)
|
|
|
|
vm->flags |= DISPLAY_FLAGS_DOUBLESCAN;
|
|
|
|
if (dmode->flags & DRM_MODE_FLAG_DBLCLK)
|
|
|
|
vm->flags |= DISPLAY_FLAGS_DOUBLECLK;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(drm_display_mode_to_videomode);
|
|
|
|
|
2016-08-16 20:34:37 +07:00
|
|
|
/**
|
|
|
|
* drm_bus_flags_from_videomode - extract information about pixelclk and
|
|
|
|
* DE polarity from videomode and store it in a separate variable
|
|
|
|
* @vm: videomode structure to use
|
2018-06-18 20:22:34 +07:00
|
|
|
* @bus_flags: information about pixelclk, sync and DE polarity will be stored
|
|
|
|
* here
|
2016-08-16 20:34:37 +07:00
|
|
|
*
|
2018-06-18 20:22:34 +07:00
|
|
|
* Sets DRM_BUS_FLAG_DE_(LOW|HIGH), DRM_BUS_FLAG_PIXDATA_(POS|NEG)EDGE and
|
|
|
|
* DISPLAY_FLAGS_SYNC_(POS|NEG)EDGE in @bus_flags according to DISPLAY_FLAGS
|
|
|
|
* found in @vm
|
2016-08-16 20:34:37 +07:00
|
|
|
*/
|
2016-07-12 20:30:02 +07:00
|
|
|
void drm_bus_flags_from_videomode(const struct videomode *vm, u32 *bus_flags)
|
|
|
|
{
|
|
|
|
*bus_flags = 0;
|
|
|
|
if (vm->flags & DISPLAY_FLAGS_PIXDATA_POSEDGE)
|
|
|
|
*bus_flags |= DRM_BUS_FLAG_PIXDATA_POSEDGE;
|
|
|
|
if (vm->flags & DISPLAY_FLAGS_PIXDATA_NEGEDGE)
|
|
|
|
*bus_flags |= DRM_BUS_FLAG_PIXDATA_NEGEDGE;
|
|
|
|
|
2018-06-18 20:22:34 +07:00
|
|
|
if (vm->flags & DISPLAY_FLAGS_SYNC_POSEDGE)
|
|
|
|
*bus_flags |= DRM_BUS_FLAG_SYNC_POSEDGE;
|
|
|
|
if (vm->flags & DISPLAY_FLAGS_SYNC_NEGEDGE)
|
|
|
|
*bus_flags |= DRM_BUS_FLAG_SYNC_NEGEDGE;
|
|
|
|
|
2016-07-12 20:30:02 +07:00
|
|
|
if (vm->flags & DISPLAY_FLAGS_DE_LOW)
|
|
|
|
*bus_flags |= DRM_BUS_FLAG_DE_LOW;
|
|
|
|
if (vm->flags & DISPLAY_FLAGS_DE_HIGH)
|
|
|
|
*bus_flags |= DRM_BUS_FLAG_DE_HIGH;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(drm_bus_flags_from_videomode);
|
|
|
|
|
2013-03-12 15:15:43 +07:00
|
|
|
#ifdef CONFIG_OF
|
2012-10-29 00:28:06 +07:00
|
|
|
/**
|
|
|
|
* of_get_drm_display_mode - get a drm_display_mode from devicetree
|
|
|
|
* @np: device_node with the timing specification
|
|
|
|
* @dmode: will be set to the return value
|
2018-06-18 20:22:34 +07:00
|
|
|
* @bus_flags: information about pixelclk, sync and DE polarity
|
2012-10-29 00:28:06 +07:00
|
|
|
* @index: index into the list of display timings in devicetree
|
|
|
|
*
|
|
|
|
* This function is expensive and should only be used, if only one mode is to be
|
|
|
|
* read from DT. To get multiple modes start with of_get_display_timings and
|
|
|
|
* work with that instead.
|
2014-01-24 02:05:00 +07:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 on success, a negative errno code when no of videomode node was found.
|
2012-10-29 00:28:06 +07:00
|
|
|
*/
|
|
|
|
int of_get_drm_display_mode(struct device_node *np,
|
2016-07-12 20:30:03 +07:00
|
|
|
struct drm_display_mode *dmode, u32 *bus_flags,
|
|
|
|
int index)
|
2012-10-29 00:28:06 +07:00
|
|
|
{
|
|
|
|
struct videomode vm;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = of_get_videomode(np, &vm, index);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
drm_display_mode_from_videomode(&vm, dmode);
|
2016-07-12 20:30:03 +07:00
|
|
|
if (bus_flags)
|
|
|
|
drm_bus_flags_from_videomode(&vm, bus_flags);
|
2012-10-29 00:28:06 +07:00
|
|
|
|
2018-09-29 05:50:44 +07:00
|
|
|
pr_debug("%pOF: got %dx%d display mode\n",
|
|
|
|
np, vm.hactive, vm.vactive);
|
2012-10-29 00:28:06 +07:00
|
|
|
drm_mode_debug_printmodeline(dmode);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(of_get_drm_display_mode);
|
2013-03-12 15:15:43 +07:00
|
|
|
#endif /* CONFIG_OF */
|
|
|
|
#endif /* CONFIG_VIDEOMODE_HELPERS */
|
2012-10-29 00:28:06 +07:00
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_set_name - set the name on a mode
|
|
|
|
* @mode: name will be set in this mode
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Set the name of @mode to a standard format which is <hdisplay>x<vdisplay>
|
|
|
|
* with an optional 'i' suffix for interlaced modes.
|
2008-11-08 05:05:41 +07:00
|
|
|
*/
|
|
|
|
void drm_mode_set_name(struct drm_display_mode *mode)
|
|
|
|
{
|
2010-03-30 04:43:31 +07:00
|
|
|
bool interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE);
|
|
|
|
|
|
|
|
snprintf(mode->name, DRM_DISPLAY_MODE_LEN, "%dx%d%s",
|
|
|
|
mode->hdisplay, mode->vdisplay,
|
|
|
|
interlaced ? "i" : "");
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_set_name);
|
|
|
|
|
2015-12-09 15:29:36 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_hsync - get the hsync of a mode
|
2009-12-04 05:44:37 +07:00
|
|
|
* @mode: mode
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Returns:
|
|
|
|
* @modes's hsync rate in kHz, rounded to the nearest integer. Calculates the
|
|
|
|
* value first if it is not yet set.
|
2009-12-04 05:44:37 +07:00
|
|
|
*/
|
2011-01-26 16:49:47 +07:00
|
|
|
int drm_mode_hsync(const struct drm_display_mode *mode)
|
2009-12-04 05:44:37 +07:00
|
|
|
{
|
|
|
|
unsigned int calc_val;
|
|
|
|
|
|
|
|
if (mode->hsync)
|
|
|
|
return mode->hsync;
|
|
|
|
|
|
|
|
if (mode->htotal < 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
calc_val = (mode->clock * 1000) / mode->htotal; /* hsync in Hz */
|
|
|
|
calc_val += 500; /* round to 1000Hz */
|
|
|
|
calc_val /= 1000; /* truncate to kHz */
|
|
|
|
|
|
|
|
return calc_val;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_hsync);
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_vrefresh - get the vrefresh of a mode
|
|
|
|
* @mode: mode
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Returns:
|
|
|
|
* @modes's vrefresh rate in Hz, rounded to the nearest integer. Calculates the
|
|
|
|
* value first if it is not yet set.
|
2008-11-08 05:05:41 +07:00
|
|
|
*/
|
2011-01-26 16:49:47 +07:00
|
|
|
int drm_mode_vrefresh(const struct drm_display_mode *mode)
|
2008-11-08 05:05:41 +07:00
|
|
|
{
|
|
|
|
int refresh = 0;
|
|
|
|
|
|
|
|
if (mode->vrefresh > 0)
|
|
|
|
refresh = mode->vrefresh;
|
|
|
|
else if (mode->htotal > 0 && mode->vtotal > 0) {
|
2018-03-13 22:07:58 +07:00
|
|
|
unsigned int num, den;
|
|
|
|
|
|
|
|
num = mode->clock * 1000;
|
|
|
|
den = mode->htotal * mode->vtotal;
|
2008-11-08 05:05:41 +07:00
|
|
|
|
|
|
|
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
|
2018-03-13 22:07:58 +07:00
|
|
|
num *= 2;
|
2008-11-08 05:05:41 +07:00
|
|
|
if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
|
2018-03-13 22:07:58 +07:00
|
|
|
den *= 2;
|
2008-11-08 05:05:41 +07:00
|
|
|
if (mode->vscan > 1)
|
2018-03-13 22:07:58 +07:00
|
|
|
den *= mode->vscan;
|
|
|
|
|
|
|
|
refresh = DIV_ROUND_CLOSEST(num, den);
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
|
|
|
return refresh;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_vrefresh);
|
|
|
|
|
2017-01-25 13:26:56 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_get_hv_timing - Fetches hdisplay/vdisplay for given mode
|
|
|
|
* @mode: mode to query
|
|
|
|
* @hdisplay: hdisplay value to fill in
|
|
|
|
* @vdisplay: vdisplay value to fill in
|
|
|
|
*
|
|
|
|
* The vdisplay value will be doubled if the specified mode is a stereo mode of
|
|
|
|
* the appropriate layout.
|
|
|
|
*/
|
|
|
|
void drm_mode_get_hv_timing(const struct drm_display_mode *mode,
|
|
|
|
int *hdisplay, int *vdisplay)
|
|
|
|
{
|
2017-01-26 18:44:09 +07:00
|
|
|
struct drm_display_mode adjusted = *mode;
|
2017-01-25 13:26:56 +07:00
|
|
|
|
|
|
|
drm_mode_set_crtcinfo(&adjusted, CRTC_STEREO_DOUBLE_ONLY);
|
|
|
|
*hdisplay = adjusted.crtc_hdisplay;
|
|
|
|
*vdisplay = adjusted.crtc_vdisplay;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_get_hv_timing);
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
/**
|
2014-01-24 02:05:00 +07:00
|
|
|
* drm_mode_set_crtcinfo - set CRTC modesetting timing parameters
|
2008-11-08 05:05:41 +07:00
|
|
|
* @p: mode
|
2013-09-25 22:45:35 +07:00
|
|
|
* @adjust_flags: a combination of adjustment flags
|
2008-11-08 05:05:41 +07:00
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Setup the CRTC modesetting timing parameters for @p, adjusting if necessary.
|
2013-09-25 22:45:35 +07:00
|
|
|
*
|
|
|
|
* - The CRTC_INTERLACE_HALVE_V flag can be used to halve vertical timings of
|
|
|
|
* interlaced modes.
|
|
|
|
* - The CRTC_STEREO_DOUBLE flag can be used to compute the timings for
|
|
|
|
* buffers containing two eyes (only adjust the timings when needed, eg. for
|
|
|
|
* "frame packing" or "side by side full").
|
2014-12-02 06:40:09 +07:00
|
|
|
* - The CRTC_NO_DBLSCAN and CRTC_NO_VSCAN flags request that adjustment *not*
|
|
|
|
* be performed for doublescan and vscan > 1 modes respectively.
|
2008-11-08 05:05:41 +07:00
|
|
|
*/
|
|
|
|
void drm_mode_set_crtcinfo(struct drm_display_mode *p, int adjust_flags)
|
|
|
|
{
|
2017-11-15 01:32:54 +07:00
|
|
|
if (!p)
|
2008-11-08 05:05:41 +07:00
|
|
|
return;
|
|
|
|
|
2013-09-25 22:45:34 +07:00
|
|
|
p->crtc_clock = p->clock;
|
2008-11-08 05:05:41 +07:00
|
|
|
p->crtc_hdisplay = p->hdisplay;
|
|
|
|
p->crtc_hsync_start = p->hsync_start;
|
|
|
|
p->crtc_hsync_end = p->hsync_end;
|
|
|
|
p->crtc_htotal = p->htotal;
|
|
|
|
p->crtc_hskew = p->hskew;
|
|
|
|
p->crtc_vdisplay = p->vdisplay;
|
|
|
|
p->crtc_vsync_start = p->vsync_start;
|
|
|
|
p->crtc_vsync_end = p->vsync_end;
|
|
|
|
p->crtc_vtotal = p->vtotal;
|
|
|
|
|
|
|
|
if (p->flags & DRM_MODE_FLAG_INTERLACE) {
|
|
|
|
if (adjust_flags & CRTC_INTERLACE_HALVE_V) {
|
|
|
|
p->crtc_vdisplay /= 2;
|
|
|
|
p->crtc_vsync_start /= 2;
|
|
|
|
p->crtc_vsync_end /= 2;
|
|
|
|
p->crtc_vtotal /= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 06:40:09 +07:00
|
|
|
if (!(adjust_flags & CRTC_NO_DBLSCAN)) {
|
|
|
|
if (p->flags & DRM_MODE_FLAG_DBLSCAN) {
|
|
|
|
p->crtc_vdisplay *= 2;
|
|
|
|
p->crtc_vsync_start *= 2;
|
|
|
|
p->crtc_vsync_end *= 2;
|
|
|
|
p->crtc_vtotal *= 2;
|
|
|
|
}
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
|
|
|
|
2014-12-02 06:40:09 +07:00
|
|
|
if (!(adjust_flags & CRTC_NO_VSCAN)) {
|
|
|
|
if (p->vscan > 1) {
|
|
|
|
p->crtc_vdisplay *= p->vscan;
|
|
|
|
p->crtc_vsync_start *= p->vscan;
|
|
|
|
p->crtc_vsync_end *= p->vscan;
|
|
|
|
p->crtc_vtotal *= p->vscan;
|
|
|
|
}
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
|
|
|
|
2013-09-25 22:45:35 +07:00
|
|
|
if (adjust_flags & CRTC_STEREO_DOUBLE) {
|
|
|
|
unsigned int layout = p->flags & DRM_MODE_FLAG_3D_MASK;
|
|
|
|
|
|
|
|
switch (layout) {
|
|
|
|
case DRM_MODE_FLAG_3D_FRAME_PACKING:
|
|
|
|
p->crtc_clock *= 2;
|
|
|
|
p->crtc_vdisplay += p->crtc_vtotal;
|
|
|
|
p->crtc_vsync_start += p->crtc_vtotal;
|
|
|
|
p->crtc_vsync_end += p->crtc_vtotal;
|
|
|
|
p->crtc_vtotal += p->crtc_vtotal;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
p->crtc_vblank_start = min(p->crtc_vsync_start, p->crtc_vdisplay);
|
|
|
|
p->crtc_vblank_end = max(p->crtc_vsync_end, p->crtc_vtotal);
|
|
|
|
p->crtc_hblank_start = min(p->crtc_hsync_start, p->crtc_hdisplay);
|
|
|
|
p->crtc_hblank_end = max(p->crtc_hsync_end, p->crtc_htotal);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_set_crtcinfo);
|
|
|
|
|
2012-03-13 17:35:51 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_copy - copy the mode
|
|
|
|
* @dst: mode to overwrite
|
|
|
|
* @src: mode to copy
|
|
|
|
*
|
2013-05-31 19:17:06 +07:00
|
|
|
* Copy an existing mode into another mode, preserving the object id and
|
|
|
|
* list head of the destination mode.
|
2012-03-13 17:35:51 +07:00
|
|
|
*/
|
|
|
|
void drm_mode_copy(struct drm_display_mode *dst, const struct drm_display_mode *src)
|
|
|
|
{
|
|
|
|
int id = dst->base.id;
|
2013-05-31 19:17:06 +07:00
|
|
|
struct list_head head = dst->head;
|
2012-03-13 17:35:51 +07:00
|
|
|
|
|
|
|
*dst = *src;
|
|
|
|
dst->base.id = id;
|
2013-05-31 19:17:06 +07:00
|
|
|
dst->head = head;
|
2012-03-13 17:35:51 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_copy);
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_duplicate - allocate and duplicate an existing mode
|
2014-01-23 21:06:15 +07:00
|
|
|
* @dev: drm_device to allocate the duplicated mode for
|
|
|
|
* @mode: mode to duplicate
|
2008-11-08 05:05:41 +07:00
|
|
|
*
|
|
|
|
* Just allocate a new mode, copy the existing mode into it, and return
|
|
|
|
* a pointer to it. Used to create new instances of established modes.
|
2014-01-24 02:05:00 +07:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Pointer to duplicated mode on success, NULL on error.
|
2008-11-08 05:05:41 +07:00
|
|
|
*/
|
|
|
|
struct drm_display_mode *drm_mode_duplicate(struct drm_device *dev,
|
2011-01-26 16:49:47 +07:00
|
|
|
const struct drm_display_mode *mode)
|
2008-11-08 05:05:41 +07:00
|
|
|
{
|
|
|
|
struct drm_display_mode *nmode;
|
|
|
|
|
|
|
|
nmode = drm_mode_create(dev);
|
|
|
|
if (!nmode)
|
|
|
|
return NULL;
|
|
|
|
|
2012-03-13 17:35:51 +07:00
|
|
|
drm_mode_copy(nmode, mode);
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
return nmode;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_duplicate);
|
|
|
|
|
2018-05-08 18:09:36 +07:00
|
|
|
static bool drm_mode_match_timings(const struct drm_display_mode *mode1,
|
|
|
|
const struct drm_display_mode *mode2)
|
|
|
|
{
|
|
|
|
return mode1->hdisplay == mode2->hdisplay &&
|
|
|
|
mode1->hsync_start == mode2->hsync_start &&
|
|
|
|
mode1->hsync_end == mode2->hsync_end &&
|
|
|
|
mode1->htotal == mode2->htotal &&
|
|
|
|
mode1->hskew == mode2->hskew &&
|
|
|
|
mode1->vdisplay == mode2->vdisplay &&
|
|
|
|
mode1->vsync_start == mode2->vsync_start &&
|
|
|
|
mode1->vsync_end == mode2->vsync_end &&
|
|
|
|
mode1->vtotal == mode2->vtotal &&
|
|
|
|
mode1->vscan == mode2->vscan;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool drm_mode_match_clock(const struct drm_display_mode *mode1,
|
|
|
|
const struct drm_display_mode *mode2)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* do clock check convert to PICOS
|
|
|
|
* so fb modes get matched the same
|
|
|
|
*/
|
|
|
|
if (mode1->clock && mode2->clock)
|
|
|
|
return KHZ2PICOS(mode1->clock) == KHZ2PICOS(mode2->clock);
|
|
|
|
else
|
|
|
|
return mode1->clock == mode2->clock;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool drm_mode_match_flags(const struct drm_display_mode *mode1,
|
|
|
|
const struct drm_display_mode *mode2)
|
|
|
|
{
|
|
|
|
return (mode1->flags & ~DRM_MODE_FLAG_3D_MASK) ==
|
|
|
|
(mode2->flags & ~DRM_MODE_FLAG_3D_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool drm_mode_match_3d_flags(const struct drm_display_mode *mode1,
|
|
|
|
const struct drm_display_mode *mode2)
|
|
|
|
{
|
|
|
|
return (mode1->flags & DRM_MODE_FLAG_3D_MASK) ==
|
|
|
|
(mode2->flags & DRM_MODE_FLAG_3D_MASK);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool drm_mode_match_aspect_ratio(const struct drm_display_mode *mode1,
|
|
|
|
const struct drm_display_mode *mode2)
|
|
|
|
{
|
|
|
|
return mode1->picture_aspect_ratio == mode2->picture_aspect_ratio;
|
|
|
|
}
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
/**
|
2018-05-08 18:09:36 +07:00
|
|
|
* drm_mode_match - test modes for (partial) equality
|
2008-11-08 05:05:41 +07:00
|
|
|
* @mode1: first mode
|
|
|
|
* @mode2: second mode
|
2018-05-08 18:09:36 +07:00
|
|
|
* @match_flags: which parts need to match (DRM_MODE_MATCH_*)
|
2008-11-08 05:05:41 +07:00
|
|
|
*
|
|
|
|
* Check to see if @mode1 and @mode2 are equivalent.
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Returns:
|
2018-05-08 18:09:36 +07:00
|
|
|
* True if the modes are (partially) equal, false otherwise.
|
2008-11-08 05:05:41 +07:00
|
|
|
*/
|
2018-05-08 18:09:36 +07:00
|
|
|
bool drm_mode_match(const struct drm_display_mode *mode1,
|
|
|
|
const struct drm_display_mode *mode2,
|
|
|
|
unsigned int match_flags)
|
2008-11-08 05:05:41 +07:00
|
|
|
{
|
2015-03-19 11:33:02 +07:00
|
|
|
if (!mode1 && !mode2)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (!mode1 || !mode2)
|
|
|
|
return false;
|
|
|
|
|
2018-05-08 18:09:36 +07:00
|
|
|
if (match_flags & DRM_MODE_MATCH_TIMINGS &&
|
|
|
|
!drm_mode_match_timings(mode1, mode2))
|
2008-11-08 05:05:41 +07:00
|
|
|
return false;
|
|
|
|
|
2018-05-08 18:09:36 +07:00
|
|
|
if (match_flags & DRM_MODE_MATCH_CLOCK &&
|
|
|
|
!drm_mode_match_clock(mode1, mode2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (match_flags & DRM_MODE_MATCH_FLAGS &&
|
|
|
|
!drm_mode_match_flags(mode1, mode2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (match_flags & DRM_MODE_MATCH_3D_FLAGS &&
|
|
|
|
!drm_mode_match_3d_flags(mode1, mode2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (match_flags & DRM_MODE_MATCH_ASPECT_RATIO &&
|
|
|
|
!drm_mode_match_aspect_ratio(mode1, mode2))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_match);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_equal - test modes for equality
|
|
|
|
* @mode1: first mode
|
|
|
|
* @mode2: second mode
|
|
|
|
*
|
|
|
|
* Check to see if @mode1 and @mode2 are equivalent.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* True if the modes are equal, false otherwise.
|
|
|
|
*/
|
|
|
|
bool drm_mode_equal(const struct drm_display_mode *mode1,
|
|
|
|
const struct drm_display_mode *mode2)
|
|
|
|
{
|
|
|
|
return drm_mode_match(mode1, mode2,
|
|
|
|
DRM_MODE_MATCH_TIMINGS |
|
|
|
|
DRM_MODE_MATCH_CLOCK |
|
|
|
|
DRM_MODE_MATCH_FLAGS |
|
drm: Add aspect ratio parsing in DRM layer
Current DRM layer functions don't parse aspect ratio information
while converting a user mode->kernel mode or vice versa. This
causes modeset to pick mode with wrong aspect ratio, eventually
causing failures in HDMI compliance test cases, due to wrong VIC.
This patch adds aspect ratio information in DRM's mode conversion
and mode comparision functions, to make sure kernel picks mode
with right aspect ratio (as per the VIC).
Background:
This patch was once reviewed and merged, and later reverted due to
lack of DRM cap protection. This is a re-spin of this patch, this
time with DRM cap protection, to avoid aspect ratio information, when
the client doesn't request for it.
Review link: https://pw-emeril.freedesktop.org/patch/104068/
Background discussion: https://patchwork.kernel.org/patch/9379057/
Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Lin, Jia <lin.a.jia@intel.com>
Signed-off-by: Akashdeep Sharma <akashdeep.sharma@intel.com>
Reviewed-by: Jim Bride <jim.bride@linux.intel.com> (V2)
Reviewed-by: Jose Abreu <Jose.Abreu@synopsys.com> (V4)
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: Jim Bride <jim.bride@linux.intel.com>
Cc: Jose Abreu <Jose.Abreu@synopsys.com>
Cc: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
V3: modified the aspect-ratio check in drm_mode_equal as per new flags
provided by Ville. https://patchwork.freedesktop.org/patch/188043/
V4: rebase
V5: rebase
V6: As recommended by Ville, avoided matching of aspect-ratio in
drm_fb_helper, while trying to find a common mode among connectors
for the target clone mode.
V7: rebase
V8: rebase
V9: rebase
V10: rebase
V11: rebase
V12: rebase
V13: rebase
V14: rebase
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/1525777785-9740-10-git-send-email-ankit.k.nautiyal@intel.com
2018-05-08 18:09:44 +07:00
|
|
|
DRM_MODE_MATCH_3D_FLAGS|
|
|
|
|
DRM_MODE_MATCH_ASPECT_RATIO);
|
2015-11-17 02:05:12 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_equal);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_equal_no_clocks - test modes for equality
|
|
|
|
* @mode1: first mode
|
|
|
|
* @mode2: second mode
|
|
|
|
*
|
|
|
|
* Check to see if @mode1 and @mode2 are equivalent, but
|
|
|
|
* don't check the pixel clocks.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* True if the modes are equal, false otherwise.
|
|
|
|
*/
|
2018-05-08 18:09:36 +07:00
|
|
|
bool drm_mode_equal_no_clocks(const struct drm_display_mode *mode1,
|
|
|
|
const struct drm_display_mode *mode2)
|
2015-11-17 02:05:12 +07:00
|
|
|
{
|
2018-05-08 18:09:36 +07:00
|
|
|
return drm_mode_match(mode1, mode2,
|
|
|
|
DRM_MODE_MATCH_TIMINGS |
|
|
|
|
DRM_MODE_MATCH_FLAGS |
|
|
|
|
DRM_MODE_MATCH_3D_FLAGS);
|
2013-04-24 23:07:16 +07:00
|
|
|
}
|
2015-11-17 02:05:12 +07:00
|
|
|
EXPORT_SYMBOL(drm_mode_equal_no_clocks);
|
2013-04-24 23:07:16 +07:00
|
|
|
|
|
|
|
/**
|
2013-09-25 22:45:27 +07:00
|
|
|
* drm_mode_equal_no_clocks_no_stereo - test modes for equality
|
2013-04-24 23:07:16 +07:00
|
|
|
* @mode1: first mode
|
|
|
|
* @mode2: second mode
|
|
|
|
*
|
|
|
|
* Check to see if @mode1 and @mode2 are equivalent, but
|
2013-09-25 22:45:27 +07:00
|
|
|
* don't check the pixel clocks nor the stereo layout.
|
2013-04-24 23:07:16 +07:00
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Returns:
|
2013-04-24 23:07:16 +07:00
|
|
|
* True if the modes are equal, false otherwise.
|
|
|
|
*/
|
2013-09-25 22:45:27 +07:00
|
|
|
bool drm_mode_equal_no_clocks_no_stereo(const struct drm_display_mode *mode1,
|
|
|
|
const struct drm_display_mode *mode2)
|
2013-04-24 23:07:16 +07:00
|
|
|
{
|
2018-05-08 18:09:36 +07:00
|
|
|
return drm_mode_match(mode1, mode2,
|
|
|
|
DRM_MODE_MATCH_TIMINGS |
|
|
|
|
DRM_MODE_MATCH_FLAGS);
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
2013-09-25 22:45:27 +07:00
|
|
|
EXPORT_SYMBOL(drm_mode_equal_no_clocks_no_stereo);
|
2008-11-08 05:05:41 +07:00
|
|
|
|
2017-11-15 01:32:57 +07:00
|
|
|
static enum drm_mode_status
|
2014-12-17 18:56:23 +07:00
|
|
|
drm_mode_validate_basic(const struct drm_display_mode *mode)
|
|
|
|
{
|
2017-11-15 22:49:13 +07:00
|
|
|
if (mode->type & ~DRM_MODE_TYPE_ALL)
|
|
|
|
return MODE_BAD;
|
|
|
|
|
|
|
|
if (mode->flags & ~DRM_MODE_FLAG_ALL)
|
|
|
|
return MODE_BAD;
|
|
|
|
|
2017-11-15 01:32:49 +07:00
|
|
|
if ((mode->flags & DRM_MODE_FLAG_3D_MASK) > DRM_MODE_FLAG_3D_MAX)
|
|
|
|
return MODE_BAD;
|
|
|
|
|
2014-12-17 18:56:23 +07:00
|
|
|
if (mode->clock == 0)
|
|
|
|
return MODE_CLOCK_LOW;
|
|
|
|
|
|
|
|
if (mode->hdisplay == 0 ||
|
|
|
|
mode->hsync_start < mode->hdisplay ||
|
|
|
|
mode->hsync_end < mode->hsync_start ||
|
|
|
|
mode->htotal < mode->hsync_end)
|
|
|
|
return MODE_H_ILLEGAL;
|
|
|
|
|
|
|
|
if (mode->vdisplay == 0 ||
|
|
|
|
mode->vsync_start < mode->vdisplay ||
|
|
|
|
mode->vsync_end < mode->vsync_start ||
|
|
|
|
mode->vtotal < mode->vsync_end)
|
|
|
|
return MODE_V_ILLEGAL;
|
|
|
|
|
|
|
|
return MODE_OK;
|
|
|
|
}
|
2017-11-15 01:32:57 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_validate_driver - make sure the mode is somewhat sane
|
|
|
|
* @dev: drm device
|
|
|
|
* @mode: mode to check
|
|
|
|
*
|
|
|
|
* First do basic validation on the mode, and then allow the driver
|
|
|
|
* to check for device/driver specific limitations via the optional
|
|
|
|
* &drm_mode_config_helper_funcs.mode_valid hook.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The mode status
|
|
|
|
*/
|
|
|
|
enum drm_mode_status
|
|
|
|
drm_mode_validate_driver(struct drm_device *dev,
|
|
|
|
const struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
enum drm_mode_status status;
|
|
|
|
|
|
|
|
status = drm_mode_validate_basic(mode);
|
|
|
|
if (status != MODE_OK)
|
|
|
|
return status;
|
|
|
|
|
|
|
|
if (dev->mode_config.funcs->mode_valid)
|
|
|
|
return dev->mode_config.funcs->mode_valid(dev, mode);
|
|
|
|
else
|
|
|
|
return MODE_OK;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_validate_driver);
|
2014-12-17 18:56:23 +07:00
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_validate_size - make sure modes adhere to size constraints
|
2014-12-17 18:56:22 +07:00
|
|
|
* @mode: mode to check
|
2008-11-08 05:05:41 +07:00
|
|
|
* @maxX: maximum width
|
|
|
|
* @maxY: maximum height
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* This function is a helper which can be used to validate modes against size
|
|
|
|
* limitations of the DRM device/connector. If a mode is too big its status
|
2014-10-20 21:53:13 +07:00
|
|
|
* member is updated with the appropriate validation failure code. The list
|
2014-01-24 02:05:00 +07:00
|
|
|
* itself is not changed.
|
2014-12-17 18:56:22 +07:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The mode status
|
2008-11-08 05:05:41 +07:00
|
|
|
*/
|
2014-12-17 18:56:22 +07:00
|
|
|
enum drm_mode_status
|
|
|
|
drm_mode_validate_size(const struct drm_display_mode *mode,
|
|
|
|
int maxX, int maxY)
|
2008-11-08 05:05:41 +07:00
|
|
|
{
|
2014-12-17 18:56:22 +07:00
|
|
|
if (maxX > 0 && mode->hdisplay > maxX)
|
|
|
|
return MODE_VIRTUAL_X;
|
2008-11-08 05:05:41 +07:00
|
|
|
|
2014-12-17 18:56:22 +07:00
|
|
|
if (maxY > 0 && mode->vdisplay > maxY)
|
|
|
|
return MODE_VIRTUAL_Y;
|
2008-11-08 05:05:41 +07:00
|
|
|
|
2014-12-17 18:56:22 +07:00
|
|
|
return MODE_OK;
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_validate_size);
|
|
|
|
|
2017-07-13 22:33:11 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_validate_ycbcr420 - add 'ycbcr420-only' modes only when allowed
|
|
|
|
* @mode: mode to check
|
|
|
|
* @connector: drm connector under action
|
|
|
|
*
|
|
|
|
* This function is a helper which can be used to filter out any YCBCR420
|
|
|
|
* only mode, when the source doesn't support it.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* The mode status
|
|
|
|
*/
|
|
|
|
enum drm_mode_status
|
|
|
|
drm_mode_validate_ycbcr420(const struct drm_display_mode *mode,
|
|
|
|
struct drm_connector *connector)
|
|
|
|
{
|
|
|
|
u8 vic = drm_match_cea_mode(mode);
|
|
|
|
enum drm_mode_status status = MODE_OK;
|
|
|
|
struct drm_hdmi_info *hdmi = &connector->display_info.hdmi;
|
|
|
|
|
|
|
|
if (test_bit(vic, hdmi->y420_vdb_modes)) {
|
|
|
|
if (!connector->ycbcr_420_allowed)
|
|
|
|
status = MODE_NO_420;
|
|
|
|
}
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_validate_ycbcr420);
|
|
|
|
|
2015-02-03 00:13:57 +07:00
|
|
|
#define MODE_STATUS(status) [MODE_ ## status + 3] = #status
|
|
|
|
|
|
|
|
static const char * const drm_mode_status_names[] = {
|
|
|
|
MODE_STATUS(OK),
|
|
|
|
MODE_STATUS(HSYNC),
|
|
|
|
MODE_STATUS(VSYNC),
|
|
|
|
MODE_STATUS(H_ILLEGAL),
|
|
|
|
MODE_STATUS(V_ILLEGAL),
|
|
|
|
MODE_STATUS(BAD_WIDTH),
|
|
|
|
MODE_STATUS(NOMODE),
|
|
|
|
MODE_STATUS(NO_INTERLACE),
|
|
|
|
MODE_STATUS(NO_DBLESCAN),
|
|
|
|
MODE_STATUS(NO_VSCAN),
|
|
|
|
MODE_STATUS(MEM),
|
|
|
|
MODE_STATUS(VIRTUAL_X),
|
|
|
|
MODE_STATUS(VIRTUAL_Y),
|
|
|
|
MODE_STATUS(MEM_VIRT),
|
|
|
|
MODE_STATUS(NOCLOCK),
|
|
|
|
MODE_STATUS(CLOCK_HIGH),
|
|
|
|
MODE_STATUS(CLOCK_LOW),
|
|
|
|
MODE_STATUS(CLOCK_RANGE),
|
|
|
|
MODE_STATUS(BAD_HVALUE),
|
|
|
|
MODE_STATUS(BAD_VVALUE),
|
|
|
|
MODE_STATUS(BAD_VSCAN),
|
|
|
|
MODE_STATUS(HSYNC_NARROW),
|
|
|
|
MODE_STATUS(HSYNC_WIDE),
|
|
|
|
MODE_STATUS(HBLANK_NARROW),
|
|
|
|
MODE_STATUS(HBLANK_WIDE),
|
|
|
|
MODE_STATUS(VSYNC_NARROW),
|
|
|
|
MODE_STATUS(VSYNC_WIDE),
|
|
|
|
MODE_STATUS(VBLANK_NARROW),
|
|
|
|
MODE_STATUS(VBLANK_WIDE),
|
|
|
|
MODE_STATUS(PANEL),
|
|
|
|
MODE_STATUS(INTERLACE_WIDTH),
|
|
|
|
MODE_STATUS(ONE_WIDTH),
|
|
|
|
MODE_STATUS(ONE_HEIGHT),
|
|
|
|
MODE_STATUS(ONE_SIZE),
|
|
|
|
MODE_STATUS(NO_REDUCED),
|
|
|
|
MODE_STATUS(NO_STEREO),
|
2017-07-13 22:33:11 +07:00
|
|
|
MODE_STATUS(NO_420),
|
2015-12-11 03:39:08 +07:00
|
|
|
MODE_STATUS(STALE),
|
2015-02-03 00:13:57 +07:00
|
|
|
MODE_STATUS(BAD),
|
|
|
|
MODE_STATUS(ERROR),
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef MODE_STATUS
|
|
|
|
|
2018-06-12 02:34:02 +07:00
|
|
|
const char *drm_get_mode_status_name(enum drm_mode_status status)
|
2015-02-03 00:13:57 +07:00
|
|
|
{
|
|
|
|
int index = status + 3;
|
|
|
|
|
|
|
|
if (WARN_ON(index < 0 || index >= ARRAY_SIZE(drm_mode_status_names)))
|
|
|
|
return "";
|
|
|
|
|
|
|
|
return drm_mode_status_names[index];
|
|
|
|
}
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_prune_invalid - remove invalid modes from mode list
|
|
|
|
* @dev: DRM device
|
|
|
|
* @mode_list: list of modes to check
|
|
|
|
* @verbose: be verbose about it
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* This helper function can be used to prune a display mode list after
|
|
|
|
* validation has been completed. All modes who's status is not MODE_OK will be
|
|
|
|
* removed from the list, and if @verbose the status code and mode name is also
|
|
|
|
* printed to dmesg.
|
2008-11-08 05:05:41 +07:00
|
|
|
*/
|
|
|
|
void drm_mode_prune_invalid(struct drm_device *dev,
|
|
|
|
struct list_head *mode_list, bool verbose)
|
|
|
|
{
|
|
|
|
struct drm_display_mode *mode, *t;
|
|
|
|
|
|
|
|
list_for_each_entry_safe(mode, t, mode_list, head) {
|
|
|
|
if (mode->status != MODE_OK) {
|
|
|
|
list_del(&mode->head);
|
|
|
|
if (verbose) {
|
|
|
|
drm_mode_debug_printmodeline(mode);
|
2015-02-03 00:13:57 +07:00
|
|
|
DRM_DEBUG_KMS("Not using %s mode: %s\n",
|
|
|
|
mode->name,
|
|
|
|
drm_get_mode_status_name(mode->status));
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
|
|
|
drm_mode_destroy(dev, mode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_prune_invalid);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_compare - compare modes for favorability
|
2010-01-12 13:39:16 +07:00
|
|
|
* @priv: unused
|
2008-11-08 05:05:41 +07:00
|
|
|
* @lh_a: list_head for first mode
|
|
|
|
* @lh_b: list_head for second mode
|
|
|
|
*
|
|
|
|
* Compare two modes, given by @lh_a and @lh_b, returning a value indicating
|
|
|
|
* which is better.
|
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Returns:
|
2008-11-08 05:05:41 +07:00
|
|
|
* Negative if @lh_a is better than @lh_b, zero if they're equivalent, or
|
|
|
|
* positive if @lh_b is better than @lh_a.
|
|
|
|
*/
|
2010-01-12 13:39:16 +07:00
|
|
|
static int drm_mode_compare(void *priv, struct list_head *lh_a, struct list_head *lh_b)
|
2008-11-08 05:05:41 +07:00
|
|
|
{
|
|
|
|
struct drm_display_mode *a = list_entry(lh_a, struct drm_display_mode, head);
|
|
|
|
struct drm_display_mode *b = list_entry(lh_b, struct drm_display_mode, head);
|
|
|
|
int diff;
|
|
|
|
|
|
|
|
diff = ((b->type & DRM_MODE_TYPE_PREFERRED) != 0) -
|
|
|
|
((a->type & DRM_MODE_TYPE_PREFERRED) != 0);
|
|
|
|
if (diff)
|
|
|
|
return diff;
|
|
|
|
diff = b->hdisplay * b->vdisplay - a->hdisplay * a->vdisplay;
|
|
|
|
if (diff)
|
|
|
|
return diff;
|
2013-05-31 19:17:08 +07:00
|
|
|
|
|
|
|
diff = b->vrefresh - a->vrefresh;
|
|
|
|
if (diff)
|
|
|
|
return diff;
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
diff = b->clock - a->clock;
|
|
|
|
return diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_sort - sort mode list
|
2014-01-24 02:05:00 +07:00
|
|
|
* @mode_list: list of drm_display_mode structures to sort
|
2008-11-08 05:05:41 +07:00
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* Sort @mode_list by favorability, moving good modes to the head of the list.
|
2008-11-08 05:05:41 +07:00
|
|
|
*/
|
|
|
|
void drm_mode_sort(struct list_head *mode_list)
|
|
|
|
{
|
2010-01-12 13:39:16 +07:00
|
|
|
list_sort(NULL, mode_list, drm_mode_compare);
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_sort);
|
|
|
|
|
|
|
|
/**
|
2018-07-09 15:40:08 +07:00
|
|
|
* drm_connector_list_update - update the mode list for the connector
|
2008-11-08 05:05:41 +07:00
|
|
|
* @connector: the connector to update
|
|
|
|
*
|
|
|
|
* This moves the modes from the @connector probed_modes list
|
|
|
|
* to the actual mode list. It compares the probed mode against the current
|
2014-01-24 02:05:00 +07:00
|
|
|
* list and only adds different/new modes.
|
|
|
|
*
|
|
|
|
* This is just a helper functions doesn't validate any modes itself and also
|
|
|
|
* doesn't prune any invalid modes. Callers need to do that themselves.
|
2008-11-08 05:05:41 +07:00
|
|
|
*/
|
2018-07-09 15:40:08 +07:00
|
|
|
void drm_connector_list_update(struct drm_connector *connector)
|
2008-11-08 05:05:41 +07:00
|
|
|
{
|
|
|
|
struct drm_display_mode *pmode, *pt;
|
|
|
|
|
2014-01-23 21:14:15 +07:00
|
|
|
WARN_ON(!mutex_is_locked(&connector->dev->mode_config.mutex));
|
|
|
|
|
2015-12-04 04:14:12 +07:00
|
|
|
list_for_each_entry_safe(pmode, pt, &connector->probed_modes, head) {
|
|
|
|
struct drm_display_mode *mode;
|
|
|
|
bool found_it = false;
|
|
|
|
|
2008-11-08 05:05:41 +07:00
|
|
|
/* go through current modes checking for the new probed mode */
|
|
|
|
list_for_each_entry(mode, &connector->modes, head) {
|
2015-12-04 04:14:12 +07:00
|
|
|
if (!drm_mode_equal(pmode, mode))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
found_it = true;
|
drm: Only merge mode type bits between new probed modes
Currently most drivers request that any mode appearing on both the
old mode list and the new probed_modes list get their type bits ORed
together if the modes are deemed to otherwise match each other.
I don't know why anyone would want to merge in the mode type bits
from any mode left over from a previous probe. For instance, you
could never get rid of ther preferred bit if a matching non-preferred
mode is returned by the new probe. So let's not merge anything from
the stale old modes, and just replace them outright with matching new
modes.
If multiple matching modes are produced by the same probe, merging
the type bits between them would seem like a sensible thing to do.
For a bit of extra finesse if two modes are considered equal we can
pick the actual timings from the one marked as preferrred. And if
multiple preferred modes are produced by the same probe somehow, we
can just favor the first one added to the probed_modes list.
You may be asking yourself why we bother with the merging at all if
nothing from the old list survives in practice. The only answer I have
is "debug output". That is we want to print out a list of pruned modes,
which is why we still want to look for duplicates with the old modes.
There was a previous attempt to get rid of the mode type merging
entirely, but it caused some kind of regression on Daniels's G33
machine. Apparently the sdvo transcoder on said machine started to
die at around the same time and has since rotted away totally, so
it may have been a red herring. So we don't have to worry about
it anymore. The relevant commits are:
commit 3fbd6439e463 ("drm: copy mode type in drm_mode_connector_list_update()")
commit abce1ec9b08a ("Revert "drm: copy mode type in drm_mode_connector_list_update()"")
It was then decided in
commit b87577b7c768 ("drm: try harder to avoid regression when merging mode bits")
that just qxl virtio are excluded from the merging, while everyone
else does it. That is not changed, although now even qxl and virtio
will be subject to the previously mentioned logic to choose which
actual timings are picked for the new mode.
v2: Fix typos in commit message, and clarify the details on
the G33 regression from the previous attempt (Daniel)
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Adam Jackson <ajax@redhat.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1449234781-22332-1-git-send-email-ville.syrjala@linux.intel.com
2015-12-04 20:13:01 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* If the old matching mode is stale (ie. left over
|
|
|
|
* from a previous probe) just replace it outright.
|
|
|
|
* Otherwise just merge the type bits between all
|
|
|
|
* equal probed modes.
|
|
|
|
*
|
|
|
|
* If two probed modes are considered equal, pick the
|
|
|
|
* actual timings from the one that's marked as
|
|
|
|
* preferred (in case the match isn't 100%). If
|
|
|
|
* multiple or zero preferred modes are present, favor
|
|
|
|
* the mode added to the probed_modes list first.
|
|
|
|
*/
|
|
|
|
if (mode->status == MODE_STALE) {
|
|
|
|
drm_mode_copy(mode, pmode);
|
|
|
|
} else if ((mode->type & DRM_MODE_TYPE_PREFERRED) == 0 &&
|
|
|
|
(pmode->type & DRM_MODE_TYPE_PREFERRED) != 0) {
|
2015-12-04 04:14:14 +07:00
|
|
|
pmode->type |= mode->type;
|
drm: Only merge mode type bits between new probed modes
Currently most drivers request that any mode appearing on both the
old mode list and the new probed_modes list get their type bits ORed
together if the modes are deemed to otherwise match each other.
I don't know why anyone would want to merge in the mode type bits
from any mode left over from a previous probe. For instance, you
could never get rid of ther preferred bit if a matching non-preferred
mode is returned by the new probe. So let's not merge anything from
the stale old modes, and just replace them outright with matching new
modes.
If multiple matching modes are produced by the same probe, merging
the type bits between them would seem like a sensible thing to do.
For a bit of extra finesse if two modes are considered equal we can
pick the actual timings from the one marked as preferrred. And if
multiple preferred modes are produced by the same probe somehow, we
can just favor the first one added to the probed_modes list.
You may be asking yourself why we bother with the merging at all if
nothing from the old list survives in practice. The only answer I have
is "debug output". That is we want to print out a list of pruned modes,
which is why we still want to look for duplicates with the old modes.
There was a previous attempt to get rid of the mode type merging
entirely, but it caused some kind of regression on Daniels's G33
machine. Apparently the sdvo transcoder on said machine started to
die at around the same time and has since rotted away totally, so
it may have been a red herring. So we don't have to worry about
it anymore. The relevant commits are:
commit 3fbd6439e463 ("drm: copy mode type in drm_mode_connector_list_update()")
commit abce1ec9b08a ("Revert "drm: copy mode type in drm_mode_connector_list_update()"")
It was then decided in
commit b87577b7c768 ("drm: try harder to avoid regression when merging mode bits")
that just qxl virtio are excluded from the merging, while everyone
else does it. That is not changed, although now even qxl and virtio
will be subject to the previously mentioned logic to choose which
actual timings are picked for the new mode.
v2: Fix typos in commit message, and clarify the details on
the G33 regression from the previous attempt (Daniel)
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Adam Jackson <ajax@redhat.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1449234781-22332-1-git-send-email-ville.syrjala@linux.intel.com
2015-12-04 20:13:01 +07:00
|
|
|
drm_mode_copy(mode, pmode);
|
|
|
|
} else {
|
2015-12-04 04:14:14 +07:00
|
|
|
mode->type |= pmode->type;
|
drm: Only merge mode type bits between new probed modes
Currently most drivers request that any mode appearing on both the
old mode list and the new probed_modes list get their type bits ORed
together if the modes are deemed to otherwise match each other.
I don't know why anyone would want to merge in the mode type bits
from any mode left over from a previous probe. For instance, you
could never get rid of ther preferred bit if a matching non-preferred
mode is returned by the new probe. So let's not merge anything from
the stale old modes, and just replace them outright with matching new
modes.
If multiple matching modes are produced by the same probe, merging
the type bits between them would seem like a sensible thing to do.
For a bit of extra finesse if two modes are considered equal we can
pick the actual timings from the one marked as preferrred. And if
multiple preferred modes are produced by the same probe somehow, we
can just favor the first one added to the probed_modes list.
You may be asking yourself why we bother with the merging at all if
nothing from the old list survives in practice. The only answer I have
is "debug output". That is we want to print out a list of pruned modes,
which is why we still want to look for duplicates with the old modes.
There was a previous attempt to get rid of the mode type merging
entirely, but it caused some kind of regression on Daniels's G33
machine. Apparently the sdvo transcoder on said machine started to
die at around the same time and has since rotted away totally, so
it may have been a red herring. So we don't have to worry about
it anymore. The relevant commits are:
commit 3fbd6439e463 ("drm: copy mode type in drm_mode_connector_list_update()")
commit abce1ec9b08a ("Revert "drm: copy mode type in drm_mode_connector_list_update()"")
It was then decided in
commit b87577b7c768 ("drm: try harder to avoid regression when merging mode bits")
that just qxl virtio are excluded from the merging, while everyone
else does it. That is not changed, although now even qxl and virtio
will be subject to the previously mentioned logic to choose which
actual timings are picked for the new mode.
v2: Fix typos in commit message, and clarify the details on
the G33 regression from the previous attempt (Daniel)
Cc: Marc-André Lureau <marcandre.lureau@redhat.com>
Cc: Dave Airlie <airlied@redhat.com>
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Cc: Adam Jackson <ajax@redhat.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: http://patchwork.freedesktop.org/patch/msgid/1449234781-22332-1-git-send-email-ville.syrjala@linux.intel.com
2015-12-04 20:13:01 +07:00
|
|
|
}
|
|
|
|
|
2015-12-04 04:14:12 +07:00
|
|
|
list_del(&pmode->head);
|
|
|
|
drm_mode_destroy(connector->dev, pmode);
|
|
|
|
break;
|
2008-11-08 05:05:41 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!found_it) {
|
|
|
|
list_move_tail(&pmode->head, &connector->modes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-09 15:40:08 +07:00
|
|
|
EXPORT_SYMBOL(drm_connector_list_update);
|
2011-04-17 13:43:32 +07:00
|
|
|
|
|
|
|
/**
|
2014-01-24 02:05:00 +07:00
|
|
|
* drm_mode_parse_command_line_for_connector - parse command line modeline for connector
|
|
|
|
* @mode_option: optional per connector mode option
|
|
|
|
* @connector: connector to parse modeline for
|
|
|
|
* @mode: preallocated drm_cmdline_mode structure to fill out
|
|
|
|
*
|
|
|
|
* This parses @mode_option command line modeline for modes and options to
|
|
|
|
* configure the connector. If @mode_option is NULL the default command line
|
|
|
|
* modeline in fb_mode_option will be parsed instead.
|
2011-04-17 13:43:32 +07:00
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* This uses the same parameters as the fb modedb.c, except for an extra
|
2018-02-20 05:53:55 +07:00
|
|
|
* force-enable, force-enable-digital and force-disable bit at the end::
|
2011-04-17 13:43:32 +07:00
|
|
|
*
|
2018-02-20 05:53:55 +07:00
|
|
|
* <xres>x<yres>[M][R][-<bpp>][@<refresh>][i][m][eDd]
|
2011-04-17 13:43:32 +07:00
|
|
|
*
|
2014-01-24 02:05:00 +07:00
|
|
|
* The intermediate drm_cmdline_mode structure is required to store additional
|
2015-03-04 15:30:09 +07:00
|
|
|
* options from the command line modline like the force-enable/disable flag.
|
2014-01-24 02:05:00 +07:00
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* True if a valid modeline has been parsed, false otherwise.
|
2011-04-17 13:43:32 +07:00
|
|
|
*/
|
|
|
|
bool drm_mode_parse_command_line_for_connector(const char *mode_option,
|
|
|
|
struct drm_connector *connector,
|
|
|
|
struct drm_cmdline_mode *mode)
|
|
|
|
{
|
|
|
|
const char *name;
|
|
|
|
unsigned int namelen;
|
2011-06-15 16:27:02 +07:00
|
|
|
bool res_specified = false, bpp_specified = false, refresh_specified = false;
|
2011-04-17 13:43:32 +07:00
|
|
|
unsigned int xres = 0, yres = 0, bpp = 32, refresh = 0;
|
2011-06-15 16:27:02 +07:00
|
|
|
bool yres_specified = false, cvt = false, rb = false;
|
|
|
|
bool interlace = false, margins = false, was_digit = false;
|
2015-12-11 19:58:59 +07:00
|
|
|
int i;
|
2011-04-17 13:43:32 +07:00
|
|
|
enum drm_connector_force force = DRM_FORCE_UNSPECIFIED;
|
|
|
|
|
2011-05-04 10:08:58 +07:00
|
|
|
#ifdef CONFIG_FB
|
2011-04-17 13:43:32 +07:00
|
|
|
if (!mode_option)
|
|
|
|
mode_option = fb_mode_option;
|
2011-05-04 10:08:58 +07:00
|
|
|
#endif
|
2011-04-17 13:43:32 +07:00
|
|
|
|
|
|
|
if (!mode_option) {
|
|
|
|
mode->specified = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
name = mode_option;
|
|
|
|
namelen = strlen(name);
|
|
|
|
for (i = namelen-1; i >= 0; i--) {
|
|
|
|
switch (name[i]) {
|
|
|
|
case '@':
|
|
|
|
if (!refresh_specified && !bpp_specified &&
|
2011-06-15 16:27:02 +07:00
|
|
|
!yres_specified && !cvt && !rb && was_digit) {
|
2015-12-11 19:58:59 +07:00
|
|
|
refresh = simple_strtol(&name[i+1], NULL, 10);
|
2011-06-15 16:27:02 +07:00
|
|
|
refresh_specified = true;
|
|
|
|
was_digit = false;
|
2011-04-17 13:43:32 +07:00
|
|
|
} else
|
|
|
|
goto done;
|
|
|
|
break;
|
|
|
|
case '-':
|
2011-06-15 16:27:02 +07:00
|
|
|
if (!bpp_specified && !yres_specified && !cvt &&
|
|
|
|
!rb && was_digit) {
|
2015-12-11 19:58:59 +07:00
|
|
|
bpp = simple_strtol(&name[i+1], NULL, 10);
|
2011-06-15 16:27:02 +07:00
|
|
|
bpp_specified = true;
|
|
|
|
was_digit = false;
|
2011-04-17 13:43:32 +07:00
|
|
|
} else
|
|
|
|
goto done;
|
|
|
|
break;
|
|
|
|
case 'x':
|
2011-06-15 16:27:02 +07:00
|
|
|
if (!yres_specified && was_digit) {
|
2015-12-11 19:58:59 +07:00
|
|
|
yres = simple_strtol(&name[i+1], NULL, 10);
|
2011-06-15 16:27:02 +07:00
|
|
|
yres_specified = true;
|
|
|
|
was_digit = false;
|
2011-04-17 13:43:32 +07:00
|
|
|
} else
|
|
|
|
goto done;
|
2013-05-08 23:03:30 +07:00
|
|
|
break;
|
2011-04-17 13:43:32 +07:00
|
|
|
case '0' ... '9':
|
2011-06-15 16:27:02 +07:00
|
|
|
was_digit = true;
|
2011-04-17 13:43:32 +07:00
|
|
|
break;
|
|
|
|
case 'M':
|
2011-06-15 16:27:02 +07:00
|
|
|
if (yres_specified || cvt || was_digit)
|
|
|
|
goto done;
|
|
|
|
cvt = true;
|
2011-04-17 13:43:32 +07:00
|
|
|
break;
|
|
|
|
case 'R':
|
2011-06-15 16:27:02 +07:00
|
|
|
if (yres_specified || cvt || rb || was_digit)
|
|
|
|
goto done;
|
|
|
|
rb = true;
|
2011-04-17 13:43:32 +07:00
|
|
|
break;
|
|
|
|
case 'm':
|
2011-06-15 16:27:02 +07:00
|
|
|
if (cvt || yres_specified || was_digit)
|
|
|
|
goto done;
|
|
|
|
margins = true;
|
2011-04-17 13:43:32 +07:00
|
|
|
break;
|
|
|
|
case 'i':
|
2011-06-15 16:27:02 +07:00
|
|
|
if (cvt || yres_specified || was_digit)
|
|
|
|
goto done;
|
|
|
|
interlace = true;
|
2011-04-17 13:43:32 +07:00
|
|
|
break;
|
|
|
|
case 'e':
|
2011-06-15 16:27:02 +07:00
|
|
|
if (yres_specified || bpp_specified || refresh_specified ||
|
|
|
|
was_digit || (force != DRM_FORCE_UNSPECIFIED))
|
|
|
|
goto done;
|
|
|
|
|
2011-04-17 13:43:32 +07:00
|
|
|
force = DRM_FORCE_ON;
|
|
|
|
break;
|
|
|
|
case 'D':
|
2011-06-15 16:27:02 +07:00
|
|
|
if (yres_specified || bpp_specified || refresh_specified ||
|
|
|
|
was_digit || (force != DRM_FORCE_UNSPECIFIED))
|
|
|
|
goto done;
|
|
|
|
|
2011-04-17 13:43:32 +07:00
|
|
|
if ((connector->connector_type != DRM_MODE_CONNECTOR_DVII) &&
|
|
|
|
(connector->connector_type != DRM_MODE_CONNECTOR_HDMIB))
|
|
|
|
force = DRM_FORCE_ON;
|
|
|
|
else
|
|
|
|
force = DRM_FORCE_ON_DIGITAL;
|
|
|
|
break;
|
|
|
|
case 'd':
|
2011-06-15 16:27:02 +07:00
|
|
|
if (yres_specified || bpp_specified || refresh_specified ||
|
|
|
|
was_digit || (force != DRM_FORCE_UNSPECIFIED))
|
|
|
|
goto done;
|
|
|
|
|
2011-04-17 13:43:32 +07:00
|
|
|
force = DRM_FORCE_OFF;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
goto done;
|
|
|
|
}
|
|
|
|
}
|
2011-06-15 16:27:02 +07:00
|
|
|
|
2011-04-17 13:43:32 +07:00
|
|
|
if (i < 0 && yres_specified) {
|
2011-06-15 16:27:02 +07:00
|
|
|
char *ch;
|
|
|
|
xres = simple_strtol(name, &ch, 10);
|
|
|
|
if ((ch != NULL) && (*ch == 'x'))
|
|
|
|
res_specified = true;
|
|
|
|
else
|
|
|
|
i = ch - name;
|
|
|
|
} else if (!yres_specified && was_digit) {
|
|
|
|
/* catch mode that begins with digits but has no 'x' */
|
|
|
|
i = 0;
|
2011-04-17 13:43:32 +07:00
|
|
|
}
|
|
|
|
done:
|
2011-06-15 16:27:02 +07:00
|
|
|
if (i >= 0) {
|
2016-02-04 21:03:52 +07:00
|
|
|
pr_warn("[drm] parse error at position %i in video mode '%s'\n",
|
2011-06-15 16:27:02 +07:00
|
|
|
i, name);
|
|
|
|
mode->specified = false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-17 13:43:32 +07:00
|
|
|
if (res_specified) {
|
|
|
|
mode->specified = true;
|
|
|
|
mode->xres = xres;
|
|
|
|
mode->yres = yres;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (refresh_specified) {
|
|
|
|
mode->refresh_specified = true;
|
|
|
|
mode->refresh = refresh;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bpp_specified) {
|
|
|
|
mode->bpp_specified = true;
|
|
|
|
mode->bpp = bpp;
|
|
|
|
}
|
2011-06-15 16:27:02 +07:00
|
|
|
mode->rb = rb;
|
|
|
|
mode->cvt = cvt;
|
|
|
|
mode->interlace = interlace;
|
|
|
|
mode->margins = margins;
|
2011-04-17 13:43:32 +07:00
|
|
|
mode->force = force;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_parse_command_line_for_connector);
|
|
|
|
|
2014-01-24 02:05:00 +07:00
|
|
|
/**
|
|
|
|
* drm_mode_create_from_cmdline_mode - convert a command line modeline into a DRM display mode
|
|
|
|
* @dev: DRM device to create the new mode for
|
|
|
|
* @cmd: input command line modeline
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Pointer to converted mode on success, NULL on error.
|
|
|
|
*/
|
2011-04-17 13:43:32 +07:00
|
|
|
struct drm_display_mode *
|
|
|
|
drm_mode_create_from_cmdline_mode(struct drm_device *dev,
|
|
|
|
struct drm_cmdline_mode *cmd)
|
|
|
|
{
|
|
|
|
struct drm_display_mode *mode;
|
|
|
|
|
|
|
|
if (cmd->cvt)
|
|
|
|
mode = drm_cvt_mode(dev,
|
|
|
|
cmd->xres, cmd->yres,
|
|
|
|
cmd->refresh_specified ? cmd->refresh : 60,
|
|
|
|
cmd->rb, cmd->interlace,
|
|
|
|
cmd->margins);
|
|
|
|
else
|
|
|
|
mode = drm_gtf_mode(dev,
|
|
|
|
cmd->xres, cmd->yres,
|
|
|
|
cmd->refresh_specified ? cmd->refresh : 60,
|
|
|
|
cmd->interlace,
|
|
|
|
cmd->margins);
|
|
|
|
if (!mode)
|
|
|
|
return NULL;
|
|
|
|
|
2014-08-06 15:08:32 +07:00
|
|
|
mode->type |= DRM_MODE_TYPE_USERDEF;
|
drm: Fix broken VT switch with video=1366x768 option
I noticed that the VT switch doesn't work any longer with a Dell
laptop with 1366x768 eDP when the machine is connected with a DP
monitor. It behaves as if VT were switched, but the graphics remain
frozen. Actually the keyboard works, so I could switch back to VT7
again.
I tried to track down the problem, and encountered a long story until
we reach to this error:
- The machine is booted with video=1366x768 option (the distro
installer seems to add it as default).
- Recently, drm_helper_probe_single_connector_modes() deals with
cmdline modes, and it tries to create a new mode when no
matching mode is found.
- The drm_mode_create_from_cmdline_mode() creates a mode based on
either CVT of GFT according to the given cmdline mode; in our case,
it's 1366x768.
- Since both CVT and GFT can't express the width 1366 due to
alignment, the resultant mode becomes 1368x768, slightly larger than
the given size.
- Later on, the atomic commit is performed, and in
drm_atomic_check_only(), the size of each plane is checked.
- The size check of 1366x768 fails due to the above, and eventually
the whole VT switch fails.
Back in the history, we've had a manual fix-up of 1368x768 in various
places via c09dedb7a50e ("drm/edid: Add a workaround for 1366x768 HD
panel"), but they have been all in drm_edid.c at probing the modes
from EDID. For addressing the problem above, we need a similar hack
to the mode newly created from cmdline, manually adjusting the width
when the expected size is 1366 while we get 1368 instead.
Fixes: eaf99c749d43 ("drm: Perform cmdline mode parsing during...")
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: http://patchwork.freedesktop.org/patch/msgid/20170109145614.29454-1-tiwai@suse.de
Reviewed-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
2017-01-09 21:56:14 +07:00
|
|
|
/* fix up 1368x768: GFT/CVT can't express 1366 width due to alignment */
|
2017-01-17 23:43:29 +07:00
|
|
|
if (cmd->xres == 1366)
|
|
|
|
drm_mode_fixup_1366x768(mode);
|
2011-04-17 13:43:32 +07:00
|
|
|
drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V);
|
|
|
|
return mode;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_create_from_cmdline_mode);
|
2015-05-22 19:34:48 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_crtc_convert_to_umode - convert a drm_display_mode into a modeinfo
|
|
|
|
* @out: drm_mode_modeinfo struct to return to the user
|
|
|
|
* @in: drm_display_mode to use
|
|
|
|
*
|
|
|
|
* Convert a drm_display_mode into a drm_mode_modeinfo structure to return to
|
|
|
|
* the user.
|
|
|
|
*/
|
|
|
|
void drm_mode_convert_to_umode(struct drm_mode_modeinfo *out,
|
|
|
|
const struct drm_display_mode *in)
|
|
|
|
{
|
|
|
|
WARN(in->hdisplay > USHRT_MAX || in->hsync_start > USHRT_MAX ||
|
|
|
|
in->hsync_end > USHRT_MAX || in->htotal > USHRT_MAX ||
|
|
|
|
in->hskew > USHRT_MAX || in->vdisplay > USHRT_MAX ||
|
|
|
|
in->vsync_start > USHRT_MAX || in->vsync_end > USHRT_MAX ||
|
|
|
|
in->vtotal > USHRT_MAX || in->vscan > USHRT_MAX,
|
|
|
|
"timing values too large for mode info\n");
|
|
|
|
|
|
|
|
out->clock = in->clock;
|
|
|
|
out->hdisplay = in->hdisplay;
|
|
|
|
out->hsync_start = in->hsync_start;
|
|
|
|
out->hsync_end = in->hsync_end;
|
|
|
|
out->htotal = in->htotal;
|
|
|
|
out->hskew = in->hskew;
|
|
|
|
out->vdisplay = in->vdisplay;
|
|
|
|
out->vsync_start = in->vsync_start;
|
|
|
|
out->vsync_end = in->vsync_end;
|
|
|
|
out->vtotal = in->vtotal;
|
|
|
|
out->vscan = in->vscan;
|
|
|
|
out->vrefresh = in->vrefresh;
|
|
|
|
out->flags = in->flags;
|
|
|
|
out->type = in->type;
|
drm: Add aspect ratio parsing in DRM layer
Current DRM layer functions don't parse aspect ratio information
while converting a user mode->kernel mode or vice versa. This
causes modeset to pick mode with wrong aspect ratio, eventually
causing failures in HDMI compliance test cases, due to wrong VIC.
This patch adds aspect ratio information in DRM's mode conversion
and mode comparision functions, to make sure kernel picks mode
with right aspect ratio (as per the VIC).
Background:
This patch was once reviewed and merged, and later reverted due to
lack of DRM cap protection. This is a re-spin of this patch, this
time with DRM cap protection, to avoid aspect ratio information, when
the client doesn't request for it.
Review link: https://pw-emeril.freedesktop.org/patch/104068/
Background discussion: https://patchwork.kernel.org/patch/9379057/
Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Lin, Jia <lin.a.jia@intel.com>
Signed-off-by: Akashdeep Sharma <akashdeep.sharma@intel.com>
Reviewed-by: Jim Bride <jim.bride@linux.intel.com> (V2)
Reviewed-by: Jose Abreu <Jose.Abreu@synopsys.com> (V4)
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: Jim Bride <jim.bride@linux.intel.com>
Cc: Jose Abreu <Jose.Abreu@synopsys.com>
Cc: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
V3: modified the aspect-ratio check in drm_mode_equal as per new flags
provided by Ville. https://patchwork.freedesktop.org/patch/188043/
V4: rebase
V5: rebase
V6: As recommended by Ville, avoided matching of aspect-ratio in
drm_fb_helper, while trying to find a common mode among connectors
for the target clone mode.
V7: rebase
V8: rebase
V9: rebase
V10: rebase
V11: rebase
V12: rebase
V13: rebase
V14: rebase
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/1525777785-9740-10-git-send-email-ankit.k.nautiyal@intel.com
2018-05-08 18:09:44 +07:00
|
|
|
|
|
|
|
switch (in->picture_aspect_ratio) {
|
|
|
|
case HDMI_PICTURE_ASPECT_4_3:
|
|
|
|
out->flags |= DRM_MODE_FLAG_PIC_AR_4_3;
|
|
|
|
break;
|
|
|
|
case HDMI_PICTURE_ASPECT_16_9:
|
|
|
|
out->flags |= DRM_MODE_FLAG_PIC_AR_16_9;
|
|
|
|
break;
|
2018-05-08 18:09:45 +07:00
|
|
|
case HDMI_PICTURE_ASPECT_64_27:
|
|
|
|
out->flags |= DRM_MODE_FLAG_PIC_AR_64_27;
|
|
|
|
break;
|
|
|
|
case HDMI_PICTURE_ASPECT_256_135:
|
|
|
|
out->flags |= DRM_MODE_FLAG_PIC_AR_256_135;
|
|
|
|
break;
|
drm: Add aspect ratio parsing in DRM layer
Current DRM layer functions don't parse aspect ratio information
while converting a user mode->kernel mode or vice versa. This
causes modeset to pick mode with wrong aspect ratio, eventually
causing failures in HDMI compliance test cases, due to wrong VIC.
This patch adds aspect ratio information in DRM's mode conversion
and mode comparision functions, to make sure kernel picks mode
with right aspect ratio (as per the VIC).
Background:
This patch was once reviewed and merged, and later reverted due to
lack of DRM cap protection. This is a re-spin of this patch, this
time with DRM cap protection, to avoid aspect ratio information, when
the client doesn't request for it.
Review link: https://pw-emeril.freedesktop.org/patch/104068/
Background discussion: https://patchwork.kernel.org/patch/9379057/
Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Lin, Jia <lin.a.jia@intel.com>
Signed-off-by: Akashdeep Sharma <akashdeep.sharma@intel.com>
Reviewed-by: Jim Bride <jim.bride@linux.intel.com> (V2)
Reviewed-by: Jose Abreu <Jose.Abreu@synopsys.com> (V4)
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: Jim Bride <jim.bride@linux.intel.com>
Cc: Jose Abreu <Jose.Abreu@synopsys.com>
Cc: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
V3: modified the aspect-ratio check in drm_mode_equal as per new flags
provided by Ville. https://patchwork.freedesktop.org/patch/188043/
V4: rebase
V5: rebase
V6: As recommended by Ville, avoided matching of aspect-ratio in
drm_fb_helper, while trying to find a common mode among connectors
for the target clone mode.
V7: rebase
V8: rebase
V9: rebase
V10: rebase
V11: rebase
V12: rebase
V13: rebase
V14: rebase
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/1525777785-9740-10-git-send-email-ankit.k.nautiyal@intel.com
2018-05-08 18:09:44 +07:00
|
|
|
case HDMI_PICTURE_ASPECT_RESERVED:
|
|
|
|
default:
|
|
|
|
out->flags |= DRM_MODE_FLAG_PIC_AR_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-05-22 19:34:48 +07:00
|
|
|
strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
|
|
|
|
out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_crtc_convert_umode - convert a modeinfo into a drm_display_mode
|
2017-11-15 01:32:57 +07:00
|
|
|
* @dev: drm device
|
2015-05-22 19:34:48 +07:00
|
|
|
* @out: drm_display_mode to return to the user
|
|
|
|
* @in: drm_mode_modeinfo to use
|
|
|
|
*
|
|
|
|
* Convert a drm_mode_modeinfo into a drm_display_mode structure to return to
|
|
|
|
* the caller.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Zero on success, negative errno on failure.
|
|
|
|
*/
|
2017-11-15 01:32:57 +07:00
|
|
|
int drm_mode_convert_umode(struct drm_device *dev,
|
|
|
|
struct drm_display_mode *out,
|
2015-05-22 19:34:48 +07:00
|
|
|
const struct drm_mode_modeinfo *in)
|
|
|
|
{
|
2018-03-13 22:07:57 +07:00
|
|
|
if (in->clock > INT_MAX || in->vrefresh > INT_MAX)
|
|
|
|
return -ERANGE;
|
2015-05-22 19:34:48 +07:00
|
|
|
|
|
|
|
out->clock = in->clock;
|
|
|
|
out->hdisplay = in->hdisplay;
|
|
|
|
out->hsync_start = in->hsync_start;
|
|
|
|
out->hsync_end = in->hsync_end;
|
|
|
|
out->htotal = in->htotal;
|
|
|
|
out->hskew = in->hskew;
|
|
|
|
out->vdisplay = in->vdisplay;
|
|
|
|
out->vsync_start = in->vsync_start;
|
|
|
|
out->vsync_end = in->vsync_end;
|
|
|
|
out->vtotal = in->vtotal;
|
|
|
|
out->vscan = in->vscan;
|
|
|
|
out->vrefresh = in->vrefresh;
|
|
|
|
out->flags = in->flags;
|
2018-03-22 04:12:46 +07:00
|
|
|
/*
|
|
|
|
* Old xf86-video-vmware (possibly others too) used to
|
|
|
|
* leave 'type' unititialized. Just ignore any bits we
|
|
|
|
* don't like. It's a just hint after all, and more
|
|
|
|
* useful for the kernel->userspace direction anyway.
|
|
|
|
*/
|
|
|
|
out->type = in->type & DRM_MODE_TYPE_ALL;
|
2015-05-22 19:34:48 +07:00
|
|
|
strncpy(out->name, in->name, DRM_DISPLAY_MODE_LEN);
|
|
|
|
out->name[DRM_DISPLAY_MODE_LEN-1] = 0;
|
|
|
|
|
drm: Add aspect ratio parsing in DRM layer
Current DRM layer functions don't parse aspect ratio information
while converting a user mode->kernel mode or vice versa. This
causes modeset to pick mode with wrong aspect ratio, eventually
causing failures in HDMI compliance test cases, due to wrong VIC.
This patch adds aspect ratio information in DRM's mode conversion
and mode comparision functions, to make sure kernel picks mode
with right aspect ratio (as per the VIC).
Background:
This patch was once reviewed and merged, and later reverted due to
lack of DRM cap protection. This is a re-spin of this patch, this
time with DRM cap protection, to avoid aspect ratio information, when
the client doesn't request for it.
Review link: https://pw-emeril.freedesktop.org/patch/104068/
Background discussion: https://patchwork.kernel.org/patch/9379057/
Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Lin, Jia <lin.a.jia@intel.com>
Signed-off-by: Akashdeep Sharma <akashdeep.sharma@intel.com>
Reviewed-by: Jim Bride <jim.bride@linux.intel.com> (V2)
Reviewed-by: Jose Abreu <Jose.Abreu@synopsys.com> (V4)
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: Jim Bride <jim.bride@linux.intel.com>
Cc: Jose Abreu <Jose.Abreu@synopsys.com>
Cc: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
V3: modified the aspect-ratio check in drm_mode_equal as per new flags
provided by Ville. https://patchwork.freedesktop.org/patch/188043/
V4: rebase
V5: rebase
V6: As recommended by Ville, avoided matching of aspect-ratio in
drm_fb_helper, while trying to find a common mode among connectors
for the target clone mode.
V7: rebase
V8: rebase
V9: rebase
V10: rebase
V11: rebase
V12: rebase
V13: rebase
V14: rebase
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/1525777785-9740-10-git-send-email-ankit.k.nautiyal@intel.com
2018-05-08 18:09:44 +07:00
|
|
|
/* Clearing picture aspect ratio bits from out flags,
|
|
|
|
* as the aspect-ratio information is not stored in
|
|
|
|
* flags for kernel-mode, but in picture_aspect_ratio.
|
|
|
|
*/
|
|
|
|
out->flags &= ~DRM_MODE_FLAG_PIC_AR_MASK;
|
|
|
|
|
|
|
|
switch (in->flags & DRM_MODE_FLAG_PIC_AR_MASK) {
|
|
|
|
case DRM_MODE_FLAG_PIC_AR_4_3:
|
|
|
|
out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_4_3;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_FLAG_PIC_AR_16_9:
|
|
|
|
out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_16_9;
|
|
|
|
break;
|
2018-05-08 18:09:45 +07:00
|
|
|
case DRM_MODE_FLAG_PIC_AR_64_27:
|
|
|
|
out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_64_27;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_FLAG_PIC_AR_256_135:
|
|
|
|
out->picture_aspect_ratio |= HDMI_PICTURE_ASPECT_256_135;
|
|
|
|
break;
|
drm: Add aspect ratio parsing in DRM layer
Current DRM layer functions don't parse aspect ratio information
while converting a user mode->kernel mode or vice versa. This
causes modeset to pick mode with wrong aspect ratio, eventually
causing failures in HDMI compliance test cases, due to wrong VIC.
This patch adds aspect ratio information in DRM's mode conversion
and mode comparision functions, to make sure kernel picks mode
with right aspect ratio (as per the VIC).
Background:
This patch was once reviewed and merged, and later reverted due to
lack of DRM cap protection. This is a re-spin of this patch, this
time with DRM cap protection, to avoid aspect ratio information, when
the client doesn't request for it.
Review link: https://pw-emeril.freedesktop.org/patch/104068/
Background discussion: https://patchwork.kernel.org/patch/9379057/
Signed-off-by: Shashank Sharma <shashank.sharma@intel.com>
Signed-off-by: Lin, Jia <lin.a.jia@intel.com>
Signed-off-by: Akashdeep Sharma <akashdeep.sharma@intel.com>
Reviewed-by: Jim Bride <jim.bride@linux.intel.com> (V2)
Reviewed-by: Jose Abreu <Jose.Abreu@synopsys.com> (V4)
Cc: Ville Syrjala <ville.syrjala@linux.intel.com>
Cc: Jim Bride <jim.bride@linux.intel.com>
Cc: Jose Abreu <Jose.Abreu@synopsys.com>
Cc: Ankit Nautiyal <ankit.k.nautiyal@intel.com>
V3: modified the aspect-ratio check in drm_mode_equal as per new flags
provided by Ville. https://patchwork.freedesktop.org/patch/188043/
V4: rebase
V5: rebase
V6: As recommended by Ville, avoided matching of aspect-ratio in
drm_fb_helper, while trying to find a common mode among connectors
for the target clone mode.
V7: rebase
V8: rebase
V9: rebase
V10: rebase
V11: rebase
V12: rebase
V13: rebase
V14: rebase
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/1525777785-9740-10-git-send-email-ankit.k.nautiyal@intel.com
2018-05-08 18:09:44 +07:00
|
|
|
default:
|
|
|
|
out->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-15 01:32:57 +07:00
|
|
|
out->status = drm_mode_validate_driver(dev, out);
|
2015-05-22 19:34:48 +07:00
|
|
|
if (out->status != MODE_OK)
|
2018-03-13 22:07:57 +07:00
|
|
|
return -EINVAL;
|
2015-05-22 19:34:48 +07:00
|
|
|
|
2016-05-31 19:03:15 +07:00
|
|
|
drm_mode_set_crtcinfo(out, CRTC_INTERLACE_HALVE_V);
|
|
|
|
|
2018-03-13 22:07:57 +07:00
|
|
|
return 0;
|
2015-11-26 00:07:55 +07:00
|
|
|
}
|
2017-07-13 22:33:14 +07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_is_420_only - if a given videomode can be only supported in YCBCR420
|
|
|
|
* output format
|
|
|
|
*
|
2017-07-21 00:47:40 +07:00
|
|
|
* @display: display under action
|
2017-07-13 22:33:14 +07:00
|
|
|
* @mode: video mode to be tested.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* true if the mode can be supported in YCBCR420 format
|
|
|
|
* false if not.
|
|
|
|
*/
|
|
|
|
bool drm_mode_is_420_only(const struct drm_display_info *display,
|
|
|
|
const struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
u8 vic = drm_match_cea_mode(mode);
|
|
|
|
|
|
|
|
return test_bit(vic, display->hdmi.y420_vdb_modes);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_is_420_only);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_mode_is_420_also - if a given videomode can be supported in YCBCR420
|
|
|
|
* output format also (along with RGB/YCBCR444/422)
|
|
|
|
*
|
|
|
|
* @display: display under action.
|
|
|
|
* @mode: video mode to be tested.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* true if the mode can be support YCBCR420 format
|
|
|
|
* false if not.
|
|
|
|
*/
|
|
|
|
bool drm_mode_is_420_also(const struct drm_display_info *display,
|
|
|
|
const struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
u8 vic = drm_match_cea_mode(mode);
|
|
|
|
|
|
|
|
return test_bit(vic, display->hdmi.y420_cmdb_modes);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_is_420_also);
|
|
|
|
/**
|
|
|
|
* drm_mode_is_420 - if a given videomode can be supported in YCBCR420
|
|
|
|
* output format
|
|
|
|
*
|
|
|
|
* @display: display under action.
|
|
|
|
* @mode: video mode to be tested.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* true if the mode can be supported in YCBCR420 format
|
|
|
|
* false if not.
|
|
|
|
*/
|
|
|
|
bool drm_mode_is_420(const struct drm_display_info *display,
|
|
|
|
const struct drm_display_mode *mode)
|
|
|
|
{
|
|
|
|
return drm_mode_is_420_only(display, mode) ||
|
|
|
|
drm_mode_is_420_also(display, mode);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_mode_is_420);
|