2010-08-07 10:01:28 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2006-2010 Intel Corporation
|
|
|
|
* Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
|
|
|
|
*
|
|
|
|
* 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 (including the next
|
|
|
|
* paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Eric Anholt <eric@anholt.net>
|
|
|
|
* Dave Airlie <airlied@linux.ie>
|
|
|
|
* Jesse Barnes <jesse.barnes@intel.com>
|
|
|
|
* Chris Wilson <chris@chris-wilson.co.uk>
|
|
|
|
*/
|
|
|
|
|
2015-04-16 19:43:45 +00:00
|
|
|
#include <linux/kernel.h>
|
2015-06-26 09:02:10 +00:00
|
|
|
#include <linux/pwm.h>
|
2019-04-05 11:00:06 +00:00
|
|
|
|
2021-08-25 11:06:50 +00:00
|
|
|
#include "intel_backlight.h"
|
2019-04-05 11:00:06 +00:00
|
|
|
#include "intel_connector.h"
|
2021-04-30 14:39:44 +00:00
|
|
|
#include "intel_de.h"
|
2019-08-06 11:39:33 +00:00
|
|
|
#include "intel_display_types.h"
|
2019-04-05 11:00:14 +00:00
|
|
|
#include "intel_panel.h"
|
2010-08-07 10:01:28 +00:00
|
|
|
|
2021-08-18 10:11:08 +00:00
|
|
|
bool intel_panel_use_ssc(struct drm_i915_private *i915)
|
|
|
|
{
|
|
|
|
if (i915->params.panel_use_ssc >= 0)
|
|
|
|
return i915->params.panel_use_ssc != 0;
|
|
|
|
return i915->vbt.lvds_use_ssc
|
|
|
|
&& !(i915->quirks & QUIRK_LVDS_SSC_DISABLE);
|
|
|
|
}
|
|
|
|
|
2021-08-25 11:06:52 +00:00
|
|
|
void intel_panel_fixed_mode(const struct drm_display_mode *fixed_mode,
|
|
|
|
struct drm_display_mode *adjusted_mode)
|
2010-08-07 10:01:28 +00:00
|
|
|
{
|
2013-09-02 18:13:39 +00:00
|
|
|
drm_mode_copy(adjusted_mode, fixed_mode);
|
2013-08-27 09:24:09 +00:00
|
|
|
|
|
|
|
drm_mode_set_crtcinfo(adjusted_mode, 0);
|
2010-08-07 10:01:28 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 13:24:45 +00:00
|
|
|
static bool is_downclock_mode(const struct drm_display_mode *downclock_mode,
|
|
|
|
const struct drm_display_mode *fixed_mode)
|
|
|
|
{
|
|
|
|
return drm_mode_match(downclock_mode, fixed_mode,
|
|
|
|
DRM_MODE_MATCH_TIMINGS |
|
|
|
|
DRM_MODE_MATCH_FLAGS |
|
|
|
|
DRM_MODE_MATCH_3D_FLAGS) &&
|
|
|
|
downclock_mode->clock < fixed_mode->clock;
|
|
|
|
}
|
|
|
|
|
2014-04-29 20:30:48 +00:00
|
|
|
struct drm_display_mode *
|
2019-03-21 13:24:46 +00:00
|
|
|
intel_panel_edid_downclock_mode(struct intel_connector *connector,
|
|
|
|
const struct drm_display_mode *fixed_mode)
|
2014-04-29 20:30:48 +00:00
|
|
|
{
|
2019-03-21 13:24:46 +00:00
|
|
|
struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
|
2019-03-21 13:24:45 +00:00
|
|
|
const struct drm_display_mode *scan, *best_mode = NULL;
|
2019-03-21 13:24:46 +00:00
|
|
|
struct drm_display_mode *downclock_mode;
|
2019-03-21 13:24:45 +00:00
|
|
|
int best_clock = fixed_mode->clock;
|
2014-04-29 20:30:48 +00:00
|
|
|
|
2019-03-21 13:24:46 +00:00
|
|
|
list_for_each_entry(scan, &connector->base.probed_modes, head) {
|
2014-04-29 20:30:48 +00:00
|
|
|
/*
|
|
|
|
* If one mode has the same resolution with the fixed_panel
|
|
|
|
* mode while they have the different refresh rate, it means
|
|
|
|
* that the reduced downclock is found. In such
|
|
|
|
* case we can set the different FPx0/1 to dynamically select
|
|
|
|
* between low and high frequency.
|
|
|
|
*/
|
2019-03-21 13:24:45 +00:00
|
|
|
if (is_downclock_mode(scan, fixed_mode) &&
|
|
|
|
scan->clock < best_clock) {
|
|
|
|
/*
|
|
|
|
* The downclock is already found. But we
|
|
|
|
* expect to find the lower downclock.
|
|
|
|
*/
|
|
|
|
best_clock = scan->clock;
|
|
|
|
best_mode = scan;
|
2014-04-29 20:30:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-21 13:24:46 +00:00
|
|
|
if (!best_mode)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
downclock_mode = drm_mode_duplicate(&dev_priv->drm, best_mode);
|
|
|
|
if (!downclock_mode)
|
|
|
|
return NULL;
|
|
|
|
|
drm/i915/panel: automatic conversion to drm_device based logging macros.
Converts various instances of the printk based drm logging macros to the
struct drm_device based logging macros in i915/display/intel_panel.c
using the following coccinelle script that transforms based on the
existence of a struct drm_i915_private device pointer:
@@
identifier fn, T;
@@
fn(...) {
...
struct drm_i915_private *T = ...;
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
@@
identifier fn, T;
@@
fn(...,struct drm_i915_private *T,...) {
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
Checkpatch warnings were addressed manually.
Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200130083229.12889-13-wambui.karugax@gmail.com
2020-01-30 08:32:29 +00:00
|
|
|
drm_dbg_kms(&dev_priv->drm,
|
|
|
|
"[CONNECTOR:%d:%s] using downclock mode from EDID: ",
|
|
|
|
connector->base.base.id, connector->base.name);
|
2019-03-21 13:24:46 +00:00
|
|
|
drm_mode_debug_printmodeline(downclock_mode);
|
2019-03-21 13:24:45 +00:00
|
|
|
|
2019-03-21 13:24:46 +00:00
|
|
|
return downclock_mode;
|
2014-04-29 20:30:48 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 13:24:41 +00:00
|
|
|
struct drm_display_mode *
|
|
|
|
intel_panel_edid_fixed_mode(struct intel_connector *connector)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
|
|
|
|
const struct drm_display_mode *scan;
|
2019-03-21 13:24:42 +00:00
|
|
|
struct drm_display_mode *fixed_mode;
|
|
|
|
|
|
|
|
if (list_empty(&connector->base.probed_modes))
|
|
|
|
return NULL;
|
2019-03-21 13:24:41 +00:00
|
|
|
|
|
|
|
/* prefer fixed mode from EDID if available */
|
|
|
|
list_for_each_entry(scan, &connector->base.probed_modes, head) {
|
|
|
|
if ((scan->type & DRM_MODE_TYPE_PREFERRED) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
fixed_mode = drm_mode_duplicate(&dev_priv->drm, scan);
|
|
|
|
if (!fixed_mode)
|
|
|
|
return NULL;
|
|
|
|
|
drm/i915/panel: automatic conversion to drm_device based logging macros.
Converts various instances of the printk based drm logging macros to the
struct drm_device based logging macros in i915/display/intel_panel.c
using the following coccinelle script that transforms based on the
existence of a struct drm_i915_private device pointer:
@@
identifier fn, T;
@@
fn(...) {
...
struct drm_i915_private *T = ...;
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
@@
identifier fn, T;
@@
fn(...,struct drm_i915_private *T,...) {
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
Checkpatch warnings were addressed manually.
Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200130083229.12889-13-wambui.karugax@gmail.com
2020-01-30 08:32:29 +00:00
|
|
|
drm_dbg_kms(&dev_priv->drm,
|
|
|
|
"[CONNECTOR:%d:%s] using preferred mode from EDID: ",
|
|
|
|
connector->base.base.id, connector->base.name);
|
2019-03-21 13:24:41 +00:00
|
|
|
drm_mode_debug_printmodeline(fixed_mode);
|
|
|
|
|
|
|
|
return fixed_mode;
|
|
|
|
}
|
|
|
|
|
2019-03-21 13:24:42 +00:00
|
|
|
scan = list_first_entry(&connector->base.probed_modes,
|
|
|
|
typeof(*scan), head);
|
|
|
|
|
|
|
|
fixed_mode = drm_mode_duplicate(&dev_priv->drm, scan);
|
|
|
|
if (!fixed_mode)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
|
|
|
|
|
drm/i915/panel: automatic conversion to drm_device based logging macros.
Converts various instances of the printk based drm logging macros to the
struct drm_device based logging macros in i915/display/intel_panel.c
using the following coccinelle script that transforms based on the
existence of a struct drm_i915_private device pointer:
@@
identifier fn, T;
@@
fn(...) {
...
struct drm_i915_private *T = ...;
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
@@
identifier fn, T;
@@
fn(...,struct drm_i915_private *T,...) {
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
Checkpatch warnings were addressed manually.
Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200130083229.12889-13-wambui.karugax@gmail.com
2020-01-30 08:32:29 +00:00
|
|
|
drm_dbg_kms(&dev_priv->drm,
|
|
|
|
"[CONNECTOR:%d:%s] using first mode from EDID: ",
|
|
|
|
connector->base.base.id, connector->base.name);
|
2019-03-21 13:24:42 +00:00
|
|
|
drm_mode_debug_printmodeline(fixed_mode);
|
|
|
|
|
|
|
|
return fixed_mode;
|
2019-03-21 13:24:41 +00:00
|
|
|
}
|
|
|
|
|
2019-03-21 13:24:43 +00:00
|
|
|
struct drm_display_mode *
|
|
|
|
intel_panel_vbt_fixed_mode(struct intel_connector *connector)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
|
|
|
|
struct drm_display_info *info = &connector->base.display_info;
|
|
|
|
struct drm_display_mode *fixed_mode;
|
|
|
|
|
|
|
|
if (!dev_priv->vbt.lfp_lvds_vbt_mode)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fixed_mode = drm_mode_duplicate(&dev_priv->drm,
|
|
|
|
dev_priv->vbt.lfp_lvds_vbt_mode);
|
|
|
|
if (!fixed_mode)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
|
|
|
|
|
drm/i915/panel: automatic conversion to drm_device based logging macros.
Converts various instances of the printk based drm logging macros to the
struct drm_device based logging macros in i915/display/intel_panel.c
using the following coccinelle script that transforms based on the
existence of a struct drm_i915_private device pointer:
@@
identifier fn, T;
@@
fn(...) {
...
struct drm_i915_private *T = ...;
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
@@
identifier fn, T;
@@
fn(...,struct drm_i915_private *T,...) {
<+...
(
-DRM_INFO(
+drm_info(&T->drm,
...)
|
-DRM_ERROR(
+drm_err(&T->drm,
...)
|
-DRM_WARN(
+drm_warn(&T->drm,
...)
|
-DRM_DEBUG(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_DRIVER(
+drm_dbg(&T->drm,
...)
|
-DRM_DEBUG_KMS(
+drm_dbg_kms(&T->drm,
...)
|
-DRM_DEBUG_ATOMIC(
+drm_dbg_atomic(&T->drm,
...)
)
...+>
}
Checkpatch warnings were addressed manually.
Signed-off-by: Wambui Karuga <wambui.karugax@gmail.com>
Signed-off-by: Jani Nikula <jani.nikula@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200130083229.12889-13-wambui.karugax@gmail.com
2020-01-30 08:32:29 +00:00
|
|
|
drm_dbg_kms(&dev_priv->drm, "[CONNECTOR:%d:%s] using mode from VBT: ",
|
|
|
|
connector->base.base.id, connector->base.name);
|
2019-03-21 13:24:43 +00:00
|
|
|
drm_mode_debug_printmodeline(fixed_mode);
|
|
|
|
|
|
|
|
info->width_mm = fixed_mode->width_mm;
|
|
|
|
info->height_mm = fixed_mode->height_mm;
|
|
|
|
|
|
|
|
return fixed_mode;
|
|
|
|
}
|
|
|
|
|
2010-08-07 10:01:28 +00:00
|
|
|
/* adjusted_mode has been preset to be the panel's fixed mode */
|
2021-08-25 11:06:52 +00:00
|
|
|
static int pch_panel_fitting(struct intel_crtc_state *crtc_state,
|
|
|
|
const struct drm_connector_state *conn_state)
|
2010-08-07 10:01:28 +00:00
|
|
|
{
|
2020-04-22 16:19:15 +00:00
|
|
|
const struct drm_display_mode *adjusted_mode =
|
|
|
|
&crtc_state->hw.adjusted_mode;
|
2020-04-22 16:19:14 +00:00
|
|
|
int x, y, width, height;
|
2010-08-07 10:01:28 +00:00
|
|
|
|
|
|
|
/* Native modes don't need fitting */
|
2020-04-22 16:19:15 +00:00
|
|
|
if (adjusted_mode->crtc_hdisplay == crtc_state->pipe_src_w &&
|
|
|
|
adjusted_mode->crtc_vdisplay == crtc_state->pipe_src_h &&
|
|
|
|
crtc_state->output_format != INTEL_OUTPUT_FORMAT_YCBCR420)
|
2020-04-22 16:19:17 +00:00
|
|
|
return 0;
|
2010-08-07 10:01:28 +00:00
|
|
|
|
2020-04-22 16:19:16 +00:00
|
|
|
switch (conn_state->scaling_mode) {
|
2010-08-07 10:01:28 +00:00
|
|
|
case DRM_MODE_SCALE_CENTER:
|
2020-04-22 16:19:15 +00:00
|
|
|
width = crtc_state->pipe_src_w;
|
|
|
|
height = crtc_state->pipe_src_h;
|
2015-09-25 13:38:56 +00:00
|
|
|
x = (adjusted_mode->crtc_hdisplay - width + 1)/2;
|
|
|
|
y = (adjusted_mode->crtc_vdisplay - height + 1)/2;
|
2010-08-07 10:01:28 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DRM_MODE_SCALE_ASPECT:
|
|
|
|
/* Scale but preserve the aspect ratio */
|
|
|
|
{
|
2015-09-25 13:38:56 +00:00
|
|
|
u32 scaled_width = adjusted_mode->crtc_hdisplay
|
2020-04-22 16:19:15 +00:00
|
|
|
* crtc_state->pipe_src_h;
|
|
|
|
u32 scaled_height = crtc_state->pipe_src_w
|
2015-09-25 13:38:56 +00:00
|
|
|
* adjusted_mode->crtc_vdisplay;
|
2010-08-07 10:01:28 +00:00
|
|
|
if (scaled_width > scaled_height) { /* pillar */
|
2020-04-22 16:19:15 +00:00
|
|
|
width = scaled_height / crtc_state->pipe_src_h;
|
drm/i915/pch: Fix integer math bugs in panel fitting
Consider a 1600x900 panel, upscaling a 1360x768 mode, full-aspect. The
old math would give you:
scaled_width = 1600 * 768; /* 1228800 */
scaled_height = 1360 * 900; /* 1224000 */
if (scaled_width > scaled_height) { /* pillarbox, and true */
width = 1224000 / 768; /* int(1593.75) = 1593 */
x = (1600 - 1593 + 1) / 2; /* 4 */
y = 0;
height = 768;
} /* ... */
This is broken. The total width of scanout would then be 1593 + 4 + 4,
or 1601, which is wider than the panel itself. The hardware very
dutifully implements this, and you end up with a black 45° diagonal from
the top-left corner to the bottom edge of the screen. It's a cool
effect and all, but not what you wanted. Similar things happen for the
letterbox case.
The problem is that you have an integer number of pixels, which means
it's usually impossible to upscale equally on both axes. 1360/768 is
1.7708, 1600/900 is 1.7777. Since we're constrained on the one axis,
the other one wants to come out as an even number of pixels (the panel
is almost certainly even on both axes, and the x/y offsets will be
applied on both sides). In the math above, if 'width' comes out even,
rounding down is correct; if it's odd, you'd rather round up. So just
increment width/height in those cases.
Tested on a Lenovo T500 (Ironlake).
Signed-off-by: Adam Jackson <ajax@redhat.com>
Tested-By: Daniel Manrique <daniel.manrique@canonical.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38851
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: stable@kernel.org
Signed-off-by: Keith Packard <keithp@keithp.com>
2011-07-13 20:32:32 +00:00
|
|
|
if (width & 1)
|
2011-08-16 19:34:10 +00:00
|
|
|
width++;
|
2015-09-25 13:38:56 +00:00
|
|
|
x = (adjusted_mode->crtc_hdisplay - width + 1) / 2;
|
2010-08-07 10:01:28 +00:00
|
|
|
y = 0;
|
2015-09-25 13:38:56 +00:00
|
|
|
height = adjusted_mode->crtc_vdisplay;
|
2010-08-07 10:01:28 +00:00
|
|
|
} else if (scaled_width < scaled_height) { /* letter */
|
2020-04-22 16:19:15 +00:00
|
|
|
height = scaled_width / crtc_state->pipe_src_w;
|
drm/i915/pch: Fix integer math bugs in panel fitting
Consider a 1600x900 panel, upscaling a 1360x768 mode, full-aspect. The
old math would give you:
scaled_width = 1600 * 768; /* 1228800 */
scaled_height = 1360 * 900; /* 1224000 */
if (scaled_width > scaled_height) { /* pillarbox, and true */
width = 1224000 / 768; /* int(1593.75) = 1593 */
x = (1600 - 1593 + 1) / 2; /* 4 */
y = 0;
height = 768;
} /* ... */
This is broken. The total width of scanout would then be 1593 + 4 + 4,
or 1601, which is wider than the panel itself. The hardware very
dutifully implements this, and you end up with a black 45° diagonal from
the top-left corner to the bottom edge of the screen. It's a cool
effect and all, but not what you wanted. Similar things happen for the
letterbox case.
The problem is that you have an integer number of pixels, which means
it's usually impossible to upscale equally on both axes. 1360/768 is
1.7708, 1600/900 is 1.7777. Since we're constrained on the one axis,
the other one wants to come out as an even number of pixels (the panel
is almost certainly even on both axes, and the x/y offsets will be
applied on both sides). In the math above, if 'width' comes out even,
rounding down is correct; if it's odd, you'd rather round up. So just
increment width/height in those cases.
Tested on a Lenovo T500 (Ironlake).
Signed-off-by: Adam Jackson <ajax@redhat.com>
Tested-By: Daniel Manrique <daniel.manrique@canonical.com>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=38851
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: stable@kernel.org
Signed-off-by: Keith Packard <keithp@keithp.com>
2011-07-13 20:32:32 +00:00
|
|
|
if (height & 1)
|
|
|
|
height++;
|
2015-09-25 13:38:56 +00:00
|
|
|
y = (adjusted_mode->crtc_vdisplay - height + 1) / 2;
|
2010-08-07 10:01:28 +00:00
|
|
|
x = 0;
|
2015-09-25 13:38:56 +00:00
|
|
|
width = adjusted_mode->crtc_hdisplay;
|
2010-08-07 10:01:28 +00:00
|
|
|
} else {
|
|
|
|
x = y = 0;
|
2015-09-25 13:38:56 +00:00
|
|
|
width = adjusted_mode->crtc_hdisplay;
|
|
|
|
height = adjusted_mode->crtc_vdisplay;
|
2010-08-07 10:01:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-04-22 16:19:16 +00:00
|
|
|
case DRM_MODE_SCALE_NONE:
|
|
|
|
WARN_ON(adjusted_mode->crtc_hdisplay != crtc_state->pipe_src_w);
|
|
|
|
WARN_ON(adjusted_mode->crtc_vdisplay != crtc_state->pipe_src_h);
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2010-08-07 10:01:28 +00:00
|
|
|
case DRM_MODE_SCALE_FULLSCREEN:
|
|
|
|
x = y = 0;
|
2015-09-25 13:38:56 +00:00
|
|
|
width = adjusted_mode->crtc_hdisplay;
|
|
|
|
height = adjusted_mode->crtc_vdisplay;
|
2010-08-07 10:01:28 +00:00
|
|
|
break;
|
2013-04-25 19:55:03 +00:00
|
|
|
|
|
|
|
default:
|
2020-04-22 16:19:16 +00:00
|
|
|
MISSING_CASE(conn_state->scaling_mode);
|
2020-04-22 16:19:17 +00:00
|
|
|
return -EINVAL;
|
2010-08-07 10:01:28 +00:00
|
|
|
}
|
|
|
|
|
2020-04-22 16:19:15 +00:00
|
|
|
drm_rect_init(&crtc_state->pch_pfit.dst,
|
2020-04-22 16:19:14 +00:00
|
|
|
x, y, width, height);
|
2020-04-22 16:19:15 +00:00
|
|
|
crtc_state->pch_pfit.enabled = true;
|
2020-04-22 16:19:17 +00:00
|
|
|
|
|
|
|
return 0;
|
2010-08-07 10:01:28 +00:00
|
|
|
}
|
2010-08-22 12:18:16 +00:00
|
|
|
|
2013-04-25 19:55:01 +00:00
|
|
|
static void
|
2015-09-25 13:37:43 +00:00
|
|
|
centre_horizontally(struct drm_display_mode *adjusted_mode,
|
2013-04-25 19:55:01 +00:00
|
|
|
int width)
|
|
|
|
{
|
|
|
|
u32 border, sync_pos, blank_width, sync_width;
|
|
|
|
|
|
|
|
/* keep the hsync and hblank widths constant */
|
2015-09-25 13:37:43 +00:00
|
|
|
sync_width = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
|
|
|
|
blank_width = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start;
|
2013-04-25 19:55:01 +00:00
|
|
|
sync_pos = (blank_width - sync_width + 1) / 2;
|
|
|
|
|
2015-09-25 13:38:56 +00:00
|
|
|
border = (adjusted_mode->crtc_hdisplay - width + 1) / 2;
|
2013-04-25 19:55:01 +00:00
|
|
|
border += border & 1; /* make the border even */
|
|
|
|
|
2015-09-25 13:37:43 +00:00
|
|
|
adjusted_mode->crtc_hdisplay = width;
|
|
|
|
adjusted_mode->crtc_hblank_start = width + border;
|
|
|
|
adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_hblank_start + blank_width;
|
2013-04-25 19:55:01 +00:00
|
|
|
|
2015-09-25 13:37:43 +00:00
|
|
|
adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hblank_start + sync_pos;
|
|
|
|
adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + sync_width;
|
2013-04-25 19:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2015-09-25 13:37:43 +00:00
|
|
|
centre_vertically(struct drm_display_mode *adjusted_mode,
|
2013-04-25 19:55:01 +00:00
|
|
|
int height)
|
|
|
|
{
|
|
|
|
u32 border, sync_pos, blank_width, sync_width;
|
|
|
|
|
|
|
|
/* keep the vsync and vblank widths constant */
|
2015-09-25 13:37:43 +00:00
|
|
|
sync_width = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
|
|
|
|
blank_width = adjusted_mode->crtc_vblank_end - adjusted_mode->crtc_vblank_start;
|
2013-04-25 19:55:01 +00:00
|
|
|
sync_pos = (blank_width - sync_width + 1) / 2;
|
|
|
|
|
2015-09-25 13:38:56 +00:00
|
|
|
border = (adjusted_mode->crtc_vdisplay - height + 1) / 2;
|
2013-04-25 19:55:01 +00:00
|
|
|
|
2015-09-25 13:37:43 +00:00
|
|
|
adjusted_mode->crtc_vdisplay = height;
|
|
|
|
adjusted_mode->crtc_vblank_start = height + border;
|
|
|
|
adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vblank_start + blank_width;
|
2013-04-25 19:55:01 +00:00
|
|
|
|
2015-09-25 13:37:43 +00:00
|
|
|
adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vblank_start + sync_pos;
|
|
|
|
adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + sync_width;
|
2013-04-25 19:55:01 +00:00
|
|
|
}
|
|
|
|
|
2020-04-20 14:04:38 +00:00
|
|
|
static u32 panel_fitter_scaling(u32 source, u32 target)
|
2013-04-25 19:55:01 +00:00
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Floating point operation is not supported. So the FACTOR
|
|
|
|
* is defined, which can avoid the floating point computation
|
|
|
|
* when calculating the panel ratio.
|
|
|
|
*/
|
|
|
|
#define ACCURACY 12
|
|
|
|
#define FACTOR (1 << ACCURACY)
|
|
|
|
u32 ratio = source * FACTOR / target;
|
|
|
|
return (FACTOR * ratio + FACTOR/2) / FACTOR;
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:19:15 +00:00
|
|
|
static void i965_scale_aspect(struct intel_crtc_state *crtc_state,
|
2013-09-16 21:43:45 +00:00
|
|
|
u32 *pfit_control)
|
|
|
|
{
|
2020-04-22 16:19:15 +00:00
|
|
|
const struct drm_display_mode *adjusted_mode =
|
|
|
|
&crtc_state->hw.adjusted_mode;
|
2015-09-25 13:38:56 +00:00
|
|
|
u32 scaled_width = adjusted_mode->crtc_hdisplay *
|
2020-04-22 16:19:15 +00:00
|
|
|
crtc_state->pipe_src_h;
|
|
|
|
u32 scaled_height = crtc_state->pipe_src_w *
|
2015-09-25 13:38:56 +00:00
|
|
|
adjusted_mode->crtc_vdisplay;
|
2013-09-16 21:43:45 +00:00
|
|
|
|
|
|
|
/* 965+ is easy, it does everything in hw */
|
|
|
|
if (scaled_width > scaled_height)
|
|
|
|
*pfit_control |= PFIT_ENABLE |
|
|
|
|
PFIT_SCALING_PILLAR;
|
|
|
|
else if (scaled_width < scaled_height)
|
|
|
|
*pfit_control |= PFIT_ENABLE |
|
|
|
|
PFIT_SCALING_LETTER;
|
2020-04-22 16:19:15 +00:00
|
|
|
else if (adjusted_mode->crtc_hdisplay != crtc_state->pipe_src_w)
|
2013-09-16 21:43:45 +00:00
|
|
|
*pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
|
|
|
|
}
|
|
|
|
|
2020-04-22 16:19:15 +00:00
|
|
|
static void i9xx_scale_aspect(struct intel_crtc_state *crtc_state,
|
2013-09-16 21:43:45 +00:00
|
|
|
u32 *pfit_control, u32 *pfit_pgm_ratios,
|
|
|
|
u32 *border)
|
|
|
|
{
|
2020-04-22 16:19:15 +00:00
|
|
|
struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
|
2015-09-25 13:38:56 +00:00
|
|
|
u32 scaled_width = adjusted_mode->crtc_hdisplay *
|
2020-04-22 16:19:15 +00:00
|
|
|
crtc_state->pipe_src_h;
|
|
|
|
u32 scaled_height = crtc_state->pipe_src_w *
|
2015-09-25 13:38:56 +00:00
|
|
|
adjusted_mode->crtc_vdisplay;
|
2013-09-16 21:43:45 +00:00
|
|
|
u32 bits;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For earlier chips we have to calculate the scaling
|
|
|
|
* ratio by hand and program it into the
|
|
|
|
* PFIT_PGM_RATIO register
|
|
|
|
*/
|
|
|
|
if (scaled_width > scaled_height) { /* pillar */
|
|
|
|
centre_horizontally(adjusted_mode,
|
|
|
|
scaled_height /
|
2020-04-22 16:19:15 +00:00
|
|
|
crtc_state->pipe_src_h);
|
2013-09-16 21:43:45 +00:00
|
|
|
|
|
|
|
*border = LVDS_BORDER_ENABLE;
|
2020-04-22 16:19:15 +00:00
|
|
|
if (crtc_state->pipe_src_h != adjusted_mode->crtc_vdisplay) {
|
|
|
|
bits = panel_fitter_scaling(crtc_state->pipe_src_h,
|
2015-09-25 13:38:56 +00:00
|
|
|
adjusted_mode->crtc_vdisplay);
|
2013-09-16 21:43:45 +00:00
|
|
|
|
|
|
|
*pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
|
|
|
|
bits << PFIT_VERT_SCALE_SHIFT);
|
|
|
|
*pfit_control |= (PFIT_ENABLE |
|
|
|
|
VERT_INTERP_BILINEAR |
|
|
|
|
HORIZ_INTERP_BILINEAR);
|
|
|
|
}
|
|
|
|
} else if (scaled_width < scaled_height) { /* letter */
|
|
|
|
centre_vertically(adjusted_mode,
|
|
|
|
scaled_width /
|
2020-04-22 16:19:15 +00:00
|
|
|
crtc_state->pipe_src_w);
|
2013-09-16 21:43:45 +00:00
|
|
|
|
|
|
|
*border = LVDS_BORDER_ENABLE;
|
2020-04-22 16:19:15 +00:00
|
|
|
if (crtc_state->pipe_src_w != adjusted_mode->crtc_hdisplay) {
|
|
|
|
bits = panel_fitter_scaling(crtc_state->pipe_src_w,
|
2015-09-25 13:38:56 +00:00
|
|
|
adjusted_mode->crtc_hdisplay);
|
2013-09-16 21:43:45 +00:00
|
|
|
|
|
|
|
*pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
|
|
|
|
bits << PFIT_VERT_SCALE_SHIFT);
|
|
|
|
*pfit_control |= (PFIT_ENABLE |
|
|
|
|
VERT_INTERP_BILINEAR |
|
|
|
|
HORIZ_INTERP_BILINEAR);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* Aspects match, Let hw scale both directions */
|
|
|
|
*pfit_control |= (PFIT_ENABLE |
|
|
|
|
VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
|
|
|
|
VERT_INTERP_BILINEAR |
|
|
|
|
HORIZ_INTERP_BILINEAR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-25 11:06:52 +00:00
|
|
|
static int gmch_panel_fitting(struct intel_crtc_state *crtc_state,
|
|
|
|
const struct drm_connector_state *conn_state)
|
2013-04-25 19:55:01 +00:00
|
|
|
{
|
2020-04-22 16:19:15 +00:00
|
|
|
struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
|
|
|
|
struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
|
2013-04-25 19:55:01 +00:00
|
|
|
u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
|
2020-04-22 16:19:15 +00:00
|
|
|
struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
|
2013-04-25 19:55:01 +00:00
|
|
|
|
|
|
|
/* Native modes don't need fitting */
|
2020-04-22 16:19:15 +00:00
|
|
|
if (adjusted_mode->crtc_hdisplay == crtc_state->pipe_src_w &&
|
|
|
|
adjusted_mode->crtc_vdisplay == crtc_state->pipe_src_h)
|
2013-04-25 19:55:01 +00:00
|
|
|
goto out;
|
|
|
|
|
2020-04-22 16:19:16 +00:00
|
|
|
switch (conn_state->scaling_mode) {
|
2013-04-25 19:55:01 +00:00
|
|
|
case DRM_MODE_SCALE_CENTER:
|
|
|
|
/*
|
|
|
|
* For centered modes, we have to calculate border widths &
|
|
|
|
* heights and modify the values programmed into the CRTC.
|
|
|
|
*/
|
2020-04-22 16:19:15 +00:00
|
|
|
centre_horizontally(adjusted_mode, crtc_state->pipe_src_w);
|
|
|
|
centre_vertically(adjusted_mode, crtc_state->pipe_src_h);
|
2013-04-25 19:55:01 +00:00
|
|
|
border = LVDS_BORDER_ENABLE;
|
|
|
|
break;
|
|
|
|
case DRM_MODE_SCALE_ASPECT:
|
|
|
|
/* Scale but preserve the aspect ratio */
|
2021-03-20 04:42:42 +00:00
|
|
|
if (DISPLAY_VER(dev_priv) >= 4)
|
2020-04-22 16:19:15 +00:00
|
|
|
i965_scale_aspect(crtc_state, &pfit_control);
|
2013-09-16 21:43:45 +00:00
|
|
|
else
|
2020-04-22 16:19:15 +00:00
|
|
|
i9xx_scale_aspect(crtc_state, &pfit_control,
|
2013-09-16 21:43:45 +00:00
|
|
|
&pfit_pgm_ratios, &border);
|
2013-04-25 19:55:01 +00:00
|
|
|
break;
|
|
|
|
case DRM_MODE_SCALE_FULLSCREEN:
|
|
|
|
/*
|
|
|
|
* Full scaling, even if it changes the aspect ratio.
|
|
|
|
* Fortunately this is all done for us in hw.
|
|
|
|
*/
|
2020-04-22 16:19:15 +00:00
|
|
|
if (crtc_state->pipe_src_h != adjusted_mode->crtc_vdisplay ||
|
|
|
|
crtc_state->pipe_src_w != adjusted_mode->crtc_hdisplay) {
|
2013-04-25 19:55:01 +00:00
|
|
|
pfit_control |= PFIT_ENABLE;
|
2021-03-20 04:42:42 +00:00
|
|
|
if (DISPLAY_VER(dev_priv) >= 4)
|
2013-04-25 19:55:01 +00:00
|
|
|
pfit_control |= PFIT_SCALING_AUTO;
|
|
|
|
else
|
|
|
|
pfit_control |= (VERT_AUTO_SCALE |
|
|
|
|
VERT_INTERP_BILINEAR |
|
|
|
|
HORIZ_AUTO_SCALE |
|
|
|
|
HORIZ_INTERP_BILINEAR);
|
|
|
|
}
|
|
|
|
break;
|
2013-04-25 19:55:03 +00:00
|
|
|
default:
|
2020-04-22 16:19:16 +00:00
|
|
|
MISSING_CASE(conn_state->scaling_mode);
|
2020-04-22 16:19:17 +00:00
|
|
|
return -EINVAL;
|
2013-04-25 19:55:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 965+ wants fuzzy fitting */
|
|
|
|
/* FIXME: handle multiple panels by failing gracefully */
|
2021-03-20 04:42:42 +00:00
|
|
|
if (DISPLAY_VER(dev_priv) >= 4)
|
2020-04-22 16:19:15 +00:00
|
|
|
pfit_control |= PFIT_PIPE(crtc->pipe) | PFIT_FILTER_FUZZY;
|
2013-04-25 19:55:01 +00:00
|
|
|
|
|
|
|
out:
|
|
|
|
if ((pfit_control & PFIT_ENABLE) == 0) {
|
|
|
|
pfit_control = 0;
|
|
|
|
pfit_pgm_ratios = 0;
|
|
|
|
}
|
|
|
|
|
2014-07-09 20:35:53 +00:00
|
|
|
/* Make sure pre-965 set dither correctly for 18bpp panels. */
|
2021-03-20 04:42:42 +00:00
|
|
|
if (DISPLAY_VER(dev_priv) < 4 && crtc_state->pipe_bpp == 18)
|
2014-07-09 20:35:53 +00:00
|
|
|
pfit_control |= PANEL_8TO6_DITHER_ENABLE;
|
|
|
|
|
2020-04-22 16:19:15 +00:00
|
|
|
crtc_state->gmch_pfit.control = pfit_control;
|
|
|
|
crtc_state->gmch_pfit.pgm_ratios = pfit_pgm_ratios;
|
|
|
|
crtc_state->gmch_pfit.lvds_border_bits = border;
|
2020-04-22 16:19:17 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-04-25 19:55:01 +00:00
|
|
|
}
|
|
|
|
|
2021-08-25 11:06:52 +00:00
|
|
|
int intel_panel_fitting(struct intel_crtc_state *crtc_state,
|
|
|
|
const struct drm_connector_state *conn_state)
|
|
|
|
{
|
|
|
|
struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
|
|
|
|
struct drm_i915_private *i915 = to_i915(crtc->base.dev);
|
|
|
|
|
|
|
|
if (HAS_GMCH(i915))
|
|
|
|
return gmch_panel_fitting(crtc_state, conn_state);
|
|
|
|
else
|
|
|
|
return pch_panel_fitting(crtc_state, conn_state);
|
|
|
|
}
|
|
|
|
|
2020-09-10 16:42:56 +00:00
|
|
|
enum drm_connector_status
|
|
|
|
intel_panel_detect(struct drm_connector *connector, bool force)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *i915 = to_i915(connector->dev);
|
|
|
|
|
|
|
|
if (!INTEL_DISPLAY_ENABLED(i915))
|
|
|
|
return connector_status_disconnected;
|
|
|
|
|
|
|
|
return connector_status_connected;
|
|
|
|
}
|
|
|
|
|
2012-10-19 11:51:50 +00:00
|
|
|
int intel_panel_init(struct intel_panel *panel,
|
2014-02-11 08:56:36 +00:00
|
|
|
struct drm_display_mode *fixed_mode,
|
|
|
|
struct drm_display_mode *downclock_mode)
|
2012-10-19 11:51:49 +00:00
|
|
|
{
|
2021-08-25 11:06:51 +00:00
|
|
|
intel_backlight_init_funcs(panel);
|
2015-09-14 11:03:48 +00:00
|
|
|
|
2012-10-19 11:51:50 +00:00
|
|
|
panel->fixed_mode = fixed_mode;
|
2014-02-11 08:56:36 +00:00
|
|
|
panel->downclock_mode = downclock_mode;
|
2012-10-19 11:51:50 +00:00
|
|
|
|
2012-10-19 11:51:49 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void intel_panel_fini(struct intel_panel *panel)
|
|
|
|
{
|
2012-10-19 11:51:50 +00:00
|
|
|
struct intel_connector *intel_connector =
|
|
|
|
container_of(panel, struct intel_connector, panel);
|
|
|
|
|
2021-08-25 11:06:51 +00:00
|
|
|
intel_backlight_destroy(panel);
|
2018-10-08 13:46:40 +00:00
|
|
|
|
2012-10-19 11:51:50 +00:00
|
|
|
if (panel->fixed_mode)
|
|
|
|
drm_mode_destroy(intel_connector->base.dev, panel->fixed_mode);
|
2013-12-10 08:07:36 +00:00
|
|
|
|
|
|
|
if (panel->downclock_mode)
|
|
|
|
drm_mode_destroy(intel_connector->base.dev,
|
|
|
|
panel->downclock_mode);
|
2012-10-19 11:51:49 +00:00
|
|
|
}
|