1379bc100SJani Nikula /*
2379bc100SJani Nikula * Copyright © 2006-2010 Intel Corporation
3379bc100SJani Nikula * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
4379bc100SJani Nikula *
5379bc100SJani Nikula * Permission is hereby granted, free of charge, to any person obtaining a
6379bc100SJani Nikula * copy of this software and associated documentation files (the "Software"),
7379bc100SJani Nikula * to deal in the Software without restriction, including without limitation
8379bc100SJani Nikula * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9379bc100SJani Nikula * and/or sell copies of the Software, and to permit persons to whom the
10379bc100SJani Nikula * Software is furnished to do so, subject to the following conditions:
11379bc100SJani Nikula *
12379bc100SJani Nikula * The above copyright notice and this permission notice (including the next
13379bc100SJani Nikula * paragraph) shall be included in all copies or substantial portions of the
14379bc100SJani Nikula * Software.
15379bc100SJani Nikula *
16379bc100SJani Nikula * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17379bc100SJani Nikula * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18379bc100SJani Nikula * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19379bc100SJani Nikula * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20379bc100SJani Nikula * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21379bc100SJani Nikula * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22379bc100SJani Nikula * DEALINGS IN THE SOFTWARE.
23379bc100SJani Nikula *
24379bc100SJani Nikula * Authors:
25379bc100SJani Nikula * Eric Anholt <eric@anholt.net>
26379bc100SJani Nikula * Dave Airlie <airlied@linux.ie>
27379bc100SJani Nikula * Jesse Barnes <jesse.barnes@intel.com>
28379bc100SJani Nikula * Chris Wilson <chris@chris-wilson.co.uk>
29379bc100SJani Nikula */
30379bc100SJani Nikula
31379bc100SJani Nikula #include <linux/kernel.h>
32379bc100SJani Nikula #include <linux/pwm.h>
33379bc100SJani Nikula
3415d045fdSJani Nikula #include <drm/drm_edid.h>
3515d045fdSJani Nikula
36801543b2SJani Nikula #include "i915_reg.h"
376cc42fbeSJani Nikula #include "intel_backlight.h"
38379bc100SJani Nikula #include "intel_connector.h"
397785ae0bSVille Syrjälä #include "intel_de.h"
401d455f8dSJani Nikula #include "intel_display_types.h"
4105d2d45eSVille Syrjälä #include "intel_drrs.h"
42*16bede13SVille Syrjälä #include "intel_lvds_regs.h"
43379bc100SJani Nikula #include "intel_panel.h"
440c82118bSJani Nikula #include "intel_quirks.h"
45379bc100SJani Nikula #include "intel_vrr.h"
463c6a4a02SJani Nikula
intel_panel_use_ssc(struct drm_i915_private * i915)473c6a4a02SJani Nikula bool intel_panel_use_ssc(struct drm_i915_private *i915)
483c6a4a02SJani Nikula {
493c6a4a02SJani Nikula if (i915->params.panel_use_ssc >= 0)
500c82118bSJani Nikula return i915->params.panel_use_ssc != 0;
510c82118bSJani Nikula return i915->display.vbt.lvds_use_ssc &&
523c6a4a02SJani Nikula !intel_has_quirk(i915, QUIRK_LVDS_SSC_DISABLE);
533c6a4a02SJani Nikula }
5409270678SVille Syrjälä
5543af6743SVille Syrjälä const struct drm_display_mode *
intel_panel_preferred_fixed_mode(struct intel_connector * connector)5643af6743SVille Syrjälä intel_panel_preferred_fixed_mode(struct intel_connector *connector)
57345b7c4bSVille Syrjälä {
58345b7c4bSVille Syrjälä return list_first_entry_or_null(&connector->panel.fixed_modes,
5943af6743SVille Syrjälä struct drm_display_mode, head);
6043af6743SVille Syrjälä }
6143af6743SVille Syrjälä
is_in_vrr_range(struct intel_connector * connector,int vrefresh)6209270678SVille Syrjälä static bool is_in_vrr_range(struct intel_connector *connector, int vrefresh)
6309270678SVille Syrjälä {
6409270678SVille Syrjälä const struct drm_display_info *info = &connector->base.display_info;
65345b7c4bSVille Syrjälä
66345b7c4bSVille Syrjälä return intel_vrr_is_capable(connector) &&
67c5ee2343SVille Syrjälä vrefresh >= info->monitor_range.min_vfreq &&
68345b7c4bSVille Syrjälä vrefresh <= info->monitor_range.max_vfreq;
69345b7c4bSVille Syrjälä }
70345b7c4bSVille Syrjälä
is_best_fixed_mode(struct intel_connector * connector,int vrefresh,int fixed_mode_vrefresh,const struct drm_display_mode * best_mode)71345b7c4bSVille Syrjälä static bool is_best_fixed_mode(struct intel_connector *connector,
72345b7c4bSVille Syrjälä int vrefresh, int fixed_mode_vrefresh,
73345b7c4bSVille Syrjälä const struct drm_display_mode *best_mode)
74345b7c4bSVille Syrjälä {
75345b7c4bSVille Syrjälä /* we want to always return something */
76345b7c4bSVille Syrjälä if (!best_mode)
7709270678SVille Syrjälä return true;
7809270678SVille Syrjälä
796e939738SVille Syrjälä /*
806e939738SVille Syrjälä * With VRR always pick a mode with equal/higher than requested
816e939738SVille Syrjälä * vrefresh, which we can then reduce to match the requested
826e939738SVille Syrjälä * vrefresh by extending the vblank length.
836e939738SVille Syrjälä */
846e939738SVille Syrjälä if (is_in_vrr_range(connector, vrefresh) &&
856e939738SVille Syrjälä is_in_vrr_range(connector, fixed_mode_vrefresh) &&
866e939738SVille Syrjälä fixed_mode_vrefresh < vrefresh)
876e939738SVille Syrjälä return false;
886e939738SVille Syrjälä
89a5810f55SVille Syrjälä /* pick the fixed_mode that is closest in terms of vrefresh */
906e939738SVille Syrjälä return abs(fixed_mode_vrefresh - vrefresh) <
916e939738SVille Syrjälä abs(drm_mode_vrefresh(best_mode) - vrefresh);
922bd0db4bSVille Syrjälä }
932bd0db4bSVille Syrjälä
942bd0db4bSVille Syrjälä const struct drm_display_mode *
intel_panel_fixed_mode(struct intel_connector * connector,const struct drm_display_mode * mode)952bd0db4bSVille Syrjälä intel_panel_fixed_mode(struct intel_connector *connector,
966e939738SVille Syrjälä const struct drm_display_mode *mode)
97a5810f55SVille Syrjälä {
986e939738SVille Syrjälä const struct drm_display_mode *fixed_mode, *best_mode = NULL;
996e939738SVille Syrjälä int vrefresh = drm_mode_vrefresh(mode);
10009270678SVille Syrjälä
10109270678SVille Syrjälä list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) {
10209270678SVille Syrjälä int fixed_mode_vrefresh = drm_mode_vrefresh(fixed_mode);
10309270678SVille Syrjälä
104345b7c4bSVille Syrjälä if (is_best_fixed_mode(connector, vrefresh,
1053cf05076SVille Syrjälä fixed_mode_vrefresh, best_mode))
106949665a6SVille Syrjälä best_mode = fixed_mode;
107c5ee2343SVille Syrjälä }
108345b7c4bSVille Syrjälä
109345b7c4bSVille Syrjälä return best_mode;
110949665a6SVille Syrjälä }
111949665a6SVille Syrjälä
is_alt_drrs_mode(const struct drm_display_mode * mode,const struct drm_display_mode * preferred_mode)1126e939738SVille Syrjälä static bool is_alt_drrs_mode(const struct drm_display_mode *mode,
1136e939738SVille Syrjälä const struct drm_display_mode *preferred_mode)
114949665a6SVille Syrjälä {
115345b7c4bSVille Syrjälä return drm_mode_match(mode, preferred_mode,
116345b7c4bSVille Syrjälä DRM_MODE_MATCH_TIMINGS |
117345b7c4bSVille Syrjälä DRM_MODE_MATCH_FLAGS |
118345b7c4bSVille Syrjälä DRM_MODE_MATCH_3D_FLAGS) &&
119345b7c4bSVille Syrjälä mode->clock != preferred_mode->clock;
12009270678SVille Syrjälä }
12109270678SVille Syrjälä
is_alt_fixed_mode(const struct drm_display_mode * mode,const struct drm_display_mode * preferred_mode)12274d6f31fSVille Syrjälä static bool is_alt_fixed_mode(const struct drm_display_mode *mode,
12374d6f31fSVille Syrjälä const struct drm_display_mode *preferred_mode)
12474d6f31fSVille Syrjälä {
12574d6f31fSVille Syrjälä u32 sync_flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC |
12674d6f31fSVille Syrjälä DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC;
12774d6f31fSVille Syrjälä
12874d6f31fSVille Syrjälä return (mode->flags & ~sync_flags) == (preferred_mode->flags & ~sync_flags) &&
12974d6f31fSVille Syrjälä mode->hdisplay == preferred_mode->hdisplay &&
13074d6f31fSVille Syrjälä mode->vdisplay == preferred_mode->vdisplay;
13174d6f31fSVille Syrjälä }
13274d6f31fSVille Syrjälä
13374d6f31fSVille Syrjälä const struct drm_display_mode *
intel_panel_downclock_mode(struct intel_connector * connector,const struct drm_display_mode * adjusted_mode)13474d6f31fSVille Syrjälä intel_panel_downclock_mode(struct intel_connector *connector,
13574d6f31fSVille Syrjälä const struct drm_display_mode *adjusted_mode)
13674d6f31fSVille Syrjälä {
13753f64f3aSVille Syrjälä const struct drm_display_mode *fixed_mode, *best_mode = NULL;
13853f64f3aSVille Syrjälä int min_vrefresh = connector->panel.vbt.seamless_drrs_min_refresh_rate;
139345b7c4bSVille Syrjälä int max_vrefresh = drm_mode_vrefresh(adjusted_mode);
14053f64f3aSVille Syrjälä
14153f64f3aSVille Syrjälä /* pick the fixed_mode with the lowest refresh rate */
142345b7c4bSVille Syrjälä list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) {
14353f64f3aSVille Syrjälä int vrefresh = drm_mode_vrefresh(fixed_mode);
14453f64f3aSVille Syrjälä
145345b7c4bSVille Syrjälä if (is_alt_drrs_mode(fixed_mode, adjusted_mode) &&
146c5ee2343SVille Syrjälä vrefresh >= min_vrefresh && vrefresh < max_vrefresh) {
147c5ee2343SVille Syrjälä max_vrefresh = vrefresh;
148c5ee2343SVille Syrjälä best_mode = fixed_mode;
149c5ee2343SVille Syrjälä }
150c5ee2343SVille Syrjälä }
151c5ee2343SVille Syrjälä
15253f64f3aSVille Syrjälä return best_mode;
15353f64f3aSVille Syrjälä }
15453f64f3aSVille Syrjälä
155d1af925bSVille Syrjälä const struct drm_display_mode *
intel_panel_highest_mode(struct intel_connector * connector,const struct drm_display_mode * adjusted_mode)156d1af925bSVille Syrjälä intel_panel_highest_mode(struct intel_connector *connector,
157d1af925bSVille Syrjälä const struct drm_display_mode *adjusted_mode)
158d1af925bSVille Syrjälä {
159d1af925bSVille Syrjälä const struct drm_display_mode *fixed_mode, *best_mode = adjusted_mode;
160d1af925bSVille Syrjälä
161d1af925bSVille Syrjälä /* pick the fixed_mode that has the highest clock */
162d1af925bSVille Syrjälä list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) {
163d1af925bSVille Syrjälä if (fixed_mode->clock > best_mode->clock)
164d1af925bSVille Syrjälä best_mode = fixed_mode;
165d1af925bSVille Syrjälä }
166d1af925bSVille Syrjälä
167d1af925bSVille Syrjälä return best_mode;
168d1af925bSVille Syrjälä }
169d1af925bSVille Syrjälä
intel_panel_get_modes(struct intel_connector * connector)170d1af925bSVille Syrjälä int intel_panel_get_modes(struct intel_connector *connector)
171f0a57798SVille Syrjälä {
172f0a57798SVille Syrjälä const struct drm_display_mode *fixed_mode;
1733cf05076SVille Syrjälä int num_modes = 0;
174f0a57798SVille Syrjälä
175f0a57798SVille Syrjälä list_for_each_entry(fixed_mode, &connector->panel.fixed_modes, head) {
176cff4c2c6SVille Syrjälä struct drm_display_mode *mode;
177379bc100SJani Nikula
178379bc100SJani Nikula mode = drm_mode_duplicate(connector->base.dev, fixed_mode);
17909270678SVille Syrjälä if (mode) {
18009270678SVille Syrjälä drm_mode_probed_add(&connector->base, mode);
181cff4c2c6SVille Syrjälä num_modes++;
182cff4c2c6SVille Syrjälä }
183cff4c2c6SVille Syrjälä }
184cff4c2c6SVille Syrjälä
185f5b8c316SVille Syrjälä return num_modes;
186f5b8c316SVille Syrjälä }
187f5b8c316SVille Syrjälä
has_drrs_modes(struct intel_connector * connector)188f5b8c316SVille Syrjälä static bool has_drrs_modes(struct intel_connector *connector)
189f5b8c316SVille Syrjälä {
190f5b8c316SVille Syrjälä const struct drm_display_mode *mode1;
191f5b8c316SVille Syrjälä
192f5b8c316SVille Syrjälä list_for_each_entry(mode1, &connector->panel.fixed_modes, head) {
193f5b8c316SVille Syrjälä const struct drm_display_mode *mode2 = mode1;
194f5b8c316SVille Syrjälä
195f5b8c316SVille Syrjälä list_for_each_entry_continue(mode2, &connector->panel.fixed_modes, head) {
196f5b8c316SVille Syrjälä if (is_alt_drrs_mode(mode1, mode2))
197f5b8c316SVille Syrjälä return true;
198f5b8c316SVille Syrjälä }
199f5b8c316SVille Syrjälä }
200379bc100SJani Nikula
201379bc100SJani Nikula return false;
202379bc100SJani Nikula }
203cff4c2c6SVille Syrjälä
intel_panel_drrs_type(struct intel_connector * connector)204cff4c2c6SVille Syrjälä enum drrs_type intel_panel_drrs_type(struct intel_connector *connector)
205379bc100SJani Nikula {
206379bc100SJani Nikula return connector->panel.vbt.drrs_type;
207a5810f55SVille Syrjälä }
208379bc100SJani Nikula
intel_panel_compute_config(struct intel_connector * connector,struct drm_display_mode * adjusted_mode)209379bc100SJani Nikula int intel_panel_compute_config(struct intel_connector *connector,
210c19909d0SVille Syrjälä struct drm_display_mode *adjusted_mode)
211db10c14aSVille Syrjälä {
2127634bef1SVille Syrjälä const struct drm_display_mode *fixed_mode =
213379bc100SJani Nikula intel_panel_fixed_mode(connector, adjusted_mode);
2147634bef1SVille Syrjälä int vrefresh, fixed_mode_vrefresh;
215a5810f55SVille Syrjälä bool is_vrr;
2167634bef1SVille Syrjälä
217379bc100SJani Nikula if (!fixed_mode)
218e9318906SWambui Karuga return 0;
219c19909d0SVille Syrjälä
220f01bae2dSVille Syrjälä vrefresh = drm_mode_vrefresh(adjusted_mode);
2217634bef1SVille Syrjälä fixed_mode_vrefresh = drm_mode_vrefresh(fixed_mode);
222379bc100SJani Nikula
2237634bef1SVille Syrjälä /*
2247634bef1SVille Syrjälä * Assume that we shouldn't muck about with the
225379bc100SJani Nikula * timings if they don't land in the VRR range.
226379bc100SJani Nikula */
227c19909d0SVille Syrjälä is_vrr = is_in_vrr_range(connector, vrefresh) &&
228379bc100SJani Nikula is_in_vrr_range(connector, fixed_mode_vrefresh);
229379bc100SJani Nikula
230ccaa9101SVille Syrjälä if (!is_vrr) {
231379bc100SJani Nikula /*
232379bc100SJani Nikula * We don't want to lie too much to the user about the refresh
233db10c14aSVille Syrjälä * rate they're going to get. But we have to allow a bit of latitude
234379bc100SJani Nikula * for Xorg since it likes to automagically cook up modes with slightly
235ccaa9101SVille Syrjälä * off refresh rates.
236379bc100SJani Nikula */
237ccaa9101SVille Syrjälä if (abs(vrefresh - fixed_mode_vrefresh) > 1) {
238ccaa9101SVille Syrjälä drm_dbg_kms(connector->base.dev,
239ccaa9101SVille Syrjälä "[CONNECTOR:%d:%s] Requested mode vrefresh (%d Hz) does not match fixed mode vrefresh (%d Hz)\n",
240ccaa9101SVille Syrjälä connector->base.base.id, connector->base.name,
241379bc100SJani Nikula vrefresh, fixed_mode_vrefresh);
242379bc100SJani Nikula
243379bc100SJani Nikula return -EINVAL;
244ccaa9101SVille Syrjälä }
245ccaa9101SVille Syrjälä }
246379bc100SJani Nikula
247e9318906SWambui Karuga drm_mode_copy(adjusted_mode, fixed_mode);
248ccaa9101SVille Syrjälä
249f01bae2dSVille Syrjälä if (is_vrr && fixed_mode_vrefresh != vrefresh)
250ccaa9101SVille Syrjälä adjusted_mode->vtotal =
251f01bae2dSVille Syrjälä DIV_ROUND_CLOSEST(adjusted_mode->clock * 1000,
252379bc100SJani Nikula adjusted_mode->htotal * vrefresh);
253ccaa9101SVille Syrjälä
254ccaa9101SVille Syrjälä drm_mode_set_crtcinfo(adjusted_mode, 0);
255ccaa9101SVille Syrjälä
256ccaa9101SVille Syrjälä return 0;
257ccaa9101SVille Syrjälä }
258ccaa9101SVille Syrjälä
intel_panel_add_edid_alt_fixed_modes(struct intel_connector * connector)259ccaa9101SVille Syrjälä static void intel_panel_add_edid_alt_fixed_modes(struct intel_connector *connector)
260ccaa9101SVille Syrjälä {
261ccaa9101SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
262ccaa9101SVille Syrjälä const struct drm_display_mode *preferred_mode =
263ccaa9101SVille Syrjälä intel_panel_preferred_fixed_mode(connector);
2642db7d421SVille Syrjälä struct drm_display_mode *mode, *next;
2652db7d421SVille Syrjälä
2662db7d421SVille Syrjälä list_for_each_entry_safe(mode, next, &connector->base.probed_modes, head) {
2672db7d421SVille Syrjälä if (!is_alt_fixed_mode(mode, preferred_mode))
268ccaa9101SVille Syrjälä continue;
269ccaa9101SVille Syrjälä
270ccaa9101SVille Syrjälä drm_dbg_kms(&dev_priv->drm,
271379bc100SJani Nikula "[CONNECTOR:%d:%s] using alternate EDID fixed mode: " DRM_MODE_FMT "\n",
272379bc100SJani Nikula connector->base.base.id, connector->base.name,
2736e939738SVille Syrjälä DRM_MODE_ARG(mode));
274eb89e83cSVille Syrjälä
2753a3c4ce9SVille Syrjälä list_move_tail(&mode->head, &connector->panel.fixed_modes);
276c19909d0SVille Syrjälä }
277eb89e83cSVille Syrjälä }
278a5810f55SVille Syrjälä
intel_panel_add_edid_preferred_mode(struct intel_connector * connector)279ccaa9101SVille Syrjälä static void intel_panel_add_edid_preferred_mode(struct intel_connector *connector)
2803a3c4ce9SVille Syrjälä {
2813a3c4ce9SVille Syrjälä struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
28254746f57SVille Syrjälä struct drm_display_mode *scan, *fixed_mode = NULL;
28354746f57SVille Syrjälä
28454746f57SVille Syrjälä if (list_empty(&connector->base.probed_modes))
285379bc100SJani Nikula return;
28654746f57SVille Syrjälä
287379bc100SJani Nikula /* make sure the preferred mode is first */
288379bc100SJani Nikula list_for_each_entry(scan, &connector->base.probed_modes, head) {
289379bc100SJani Nikula if (scan->type & DRM_MODE_TYPE_PREFERRED) {
290db10c14aSVille Syrjälä fixed_mode = scan;
291379bc100SJani Nikula break;
29254746f57SVille Syrjälä }
293379bc100SJani Nikula }
294379bc100SJani Nikula
295379bc100SJani Nikula if (!fixed_mode)
296379bc100SJani Nikula fixed_mode = list_first_entry(&connector->base.probed_modes,
29754746f57SVille Syrjälä typeof(*fixed_mode), head);
29854746f57SVille Syrjälä
29954746f57SVille Syrjälä drm_dbg_kms(&dev_priv->drm,
30054746f57SVille Syrjälä "[CONNECTOR:%d:%s] using %s EDID fixed mode: " DRM_MODE_FMT "\n",
301db10c14aSVille Syrjälä connector->base.base.id, connector->base.name,
302379bc100SJani Nikula fixed_mode->type & DRM_MODE_TYPE_PREFERRED ? "preferred" : "first",
303379bc100SJani Nikula DRM_MODE_ARG(fixed_mode));
30454746f57SVille Syrjälä
30554746f57SVille Syrjälä fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
30654746f57SVille Syrjälä
30754746f57SVille Syrjälä list_move_tail(&fixed_mode->head, &connector->panel.fixed_modes);
30854746f57SVille Syrjälä }
3093cf05076SVille Syrjälä
intel_panel_destroy_probed_modes(struct intel_connector * connector)31054746f57SVille Syrjälä static void intel_panel_destroy_probed_modes(struct intel_connector *connector)
31154746f57SVille Syrjälä {
31254746f57SVille Syrjälä struct drm_i915_private *i915 = to_i915(connector->base.dev);
31354746f57SVille Syrjälä struct drm_display_mode *mode, *next;
31454746f57SVille Syrjälä
31554746f57SVille Syrjälä list_for_each_entry_safe(mode, next, &connector->base.probed_modes, head) {
31654746f57SVille Syrjälä drm_dbg_kms(&i915->drm,
31754746f57SVille Syrjälä "[CONNECTOR:%d:%s] not using EDID mode: " DRM_MODE_FMT "\n",
318db10c14aSVille Syrjälä connector->base.base.id, connector->base.name,
31914daee24SVille Syrjälä DRM_MODE_ARG(mode));
32014daee24SVille Syrjälä list_del(&mode->head);
32154746f57SVille Syrjälä drm_mode_destroy(&i915->drm, mode);
32214daee24SVille Syrjälä }
3233cf05076SVille Syrjälä }
32454746f57SVille Syrjälä
intel_panel_add_edid_fixed_modes(struct intel_connector * connector,bool use_alt_fixed_modes)325db10c14aSVille Syrjälä void intel_panel_add_edid_fixed_modes(struct intel_connector *connector,
32614daee24SVille Syrjälä bool use_alt_fixed_modes)
32754746f57SVille Syrjälä {
32854746f57SVille Syrjälä intel_panel_add_edid_preferred_mode(connector);
32954746f57SVille Syrjälä if (intel_panel_preferred_fixed_mode(connector) && use_alt_fixed_modes)
33014daee24SVille Syrjälä intel_panel_add_edid_alt_fixed_modes(connector);
33114daee24SVille Syrjälä intel_panel_destroy_probed_modes(connector);
332db10c14aSVille Syrjälä }
3335248cc78SVille Syrjälä
intel_panel_add_fixed_mode(struct intel_connector * connector,struct drm_display_mode * fixed_mode,const char * type)3345248cc78SVille Syrjälä static void intel_panel_add_fixed_mode(struct intel_connector *connector,
33554746f57SVille Syrjälä struct drm_display_mode *fixed_mode,
33654746f57SVille Syrjälä const char *type)
33754746f57SVille Syrjälä {
3385248cc78SVille Syrjälä struct drm_i915_private *i915 = to_i915(connector->base.dev);
3395248cc78SVille Syrjälä struct drm_display_info *info = &connector->base.display_info;
340379bc100SJani Nikula
3414b93f49dSJani Nikula if (!fixed_mode)
3424cecc7c0SVille Syrjälä return;
343379bc100SJani Nikula
344f650af72SVille Syrjälä fixed_mode->type |= DRM_MODE_TYPE_PREFERRED | DRM_MODE_TYPE_DRIVER;
345f650af72SVille Syrjälä
34626111a16SVille Syrjälä info->width_mm = fixed_mode->width_mm;
34726111a16SVille Syrjälä info->height_mm = fixed_mode->height_mm;
34835dd95b4SVille Syrjälä
349379bc100SJani Nikula drm_dbg_kms(&i915->drm, "[CONNECTOR:%d:%s] using %s fixed mode: " DRM_MODE_FMT "\n",
350379bc100SJani Nikula connector->base.base.id, connector->base.name, type,
35126111a16SVille Syrjälä DRM_MODE_ARG(fixed_mode));
35226111a16SVille Syrjälä
353f650af72SVille Syrjälä list_add_tail(&fixed_mode->head, &connector->panel.fixed_modes);
354d7ff281cSVille Syrjälä }
355379bc100SJani Nikula
intel_panel_add_vbt_lfp_fixed_mode(struct intel_connector * connector)3564cecc7c0SVille Syrjälä void intel_panel_add_vbt_lfp_fixed_mode(struct intel_connector *connector)
357379bc100SJani Nikula {
35826111a16SVille Syrjälä struct drm_i915_private *i915 = to_i915(connector->base.dev);
35926111a16SVille Syrjälä const struct drm_display_mode *mode;
360379bc100SJani Nikula
361379bc100SJani Nikula mode = connector->panel.vbt.lfp_lvds_vbt_mode;
362379bc100SJani Nikula if (!mode)
363379bc100SJani Nikula return;
364379bc100SJani Nikula
365379bc100SJani Nikula intel_panel_add_fixed_mode(connector,
366379bc100SJani Nikula drm_mode_duplicate(&i915->drm, mode),
36726111a16SVille Syrjälä "VBT LFP");
36826111a16SVille Syrjälä }
369379bc100SJani Nikula
intel_panel_add_vbt_sdvo_fixed_mode(struct intel_connector * connector)37026111a16SVille Syrjälä void intel_panel_add_vbt_sdvo_fixed_mode(struct intel_connector *connector)
371379bc100SJani Nikula {
372379bc100SJani Nikula struct drm_i915_private *i915 = to_i915(connector->base.dev);
373379bc100SJani Nikula const struct drm_display_mode *mode;
374379bc100SJani Nikula
375379bc100SJani Nikula mode = connector->panel.vbt.sdvo_lvds_vbt_mode;
376379bc100SJani Nikula if (!mode)
37726111a16SVille Syrjälä return;
378379bc100SJani Nikula
379379bc100SJani Nikula intel_panel_add_fixed_mode(connector,
380379bc100SJani Nikula drm_mode_duplicate(&i915->drm, mode),
381379bc100SJani Nikula "VBT SDVO");
382379bc100SJani Nikula }
383379bc100SJani Nikula
intel_panel_add_encoder_fixed_mode(struct intel_connector * connector,struct intel_encoder * encoder)384379bc100SJani Nikula void intel_panel_add_encoder_fixed_mode(struct intel_connector *connector,
385379bc100SJani Nikula struct intel_encoder *encoder)
386379bc100SJani Nikula {
387379bc100SJani Nikula intel_panel_add_fixed_mode(connector,
388379bc100SJani Nikula intel_encoder_current_mode(encoder),
389379bc100SJani Nikula "current (BIOS)");
390379bc100SJani Nikula }
3914cecc7c0SVille Syrjälä
39226111a16SVille Syrjälä /* adjusted_mode has been preset to be the panel's fixed mode */
pch_panel_fitting(struct intel_crtc_state * crtc_state,const struct drm_connector_state * conn_state)39326111a16SVille Syrjälä static int pch_panel_fitting(struct intel_crtc_state *crtc_state,
394df561f66SGustavo A. R. Silva const struct drm_connector_state *conn_state)
395379bc100SJani Nikula {
396379bc100SJani Nikula const struct drm_display_mode *adjusted_mode =
397379bc100SJani Nikula &crtc_state->hw.adjusted_mode;
398379bc100SJani Nikula int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
399379bc100SJani Nikula int pipe_src_h = drm_rect_height(&crtc_state->pipe_src);
400379bc100SJani Nikula int x, y, width, height;
401379bc100SJani Nikula
4024cecc7c0SVille Syrjälä /* Native modes don't need fitting */
403d7ff281cSVille Syrjälä if (adjusted_mode->crtc_hdisplay == pipe_src_w &&
404379bc100SJani Nikula adjusted_mode->crtc_vdisplay == pipe_src_h &&
405379bc100SJani Nikula crtc_state->output_format != INTEL_OUTPUT_FORMAT_YCBCR420)
406f650af72SVille Syrjälä return 0;
40735dd95b4SVille Syrjälä
408f650af72SVille Syrjälä switch (conn_state->scaling_mode) {
409d7ff281cSVille Syrjälä case DRM_MODE_SCALE_CENTER:
410d7ff281cSVille Syrjälä width = pipe_src_w;
411379bc100SJani Nikula height = pipe_src_h;
412379bc100SJani Nikula x = (adjusted_mode->crtc_hdisplay - width + 1)/2;
413379bc100SJani Nikula y = (adjusted_mode->crtc_vdisplay - height + 1)/2;
414379bc100SJani Nikula break;
415379bc100SJani Nikula
416379bc100SJani Nikula case DRM_MODE_SCALE_ASPECT:
417379bc100SJani Nikula /* Scale but preserve the aspect ratio */
418379bc100SJani Nikula {
419379bc100SJani Nikula u32 scaled_width = adjusted_mode->crtc_hdisplay * pipe_src_h;
420379bc100SJani Nikula u32 scaled_height = pipe_src_w * adjusted_mode->crtc_vdisplay;
421379bc100SJani Nikula if (scaled_width > scaled_height) { /* pillar */
422379bc100SJani Nikula width = scaled_height / pipe_src_h;
423379bc100SJani Nikula if (width & 1)
424379bc100SJani Nikula width++;
425379bc100SJani Nikula x = (adjusted_mode->crtc_hdisplay - width + 1) / 2;
426379bc100SJani Nikula y = 0;
427379bc100SJani Nikula height = adjusted_mode->crtc_vdisplay;
428379bc100SJani Nikula } else if (scaled_width < scaled_height) { /* letter */
429379bc100SJani Nikula height = scaled_width / pipe_src_w;
430379bc100SJani Nikula if (height & 1)
431379bc100SJani Nikula height++;
432379bc100SJani Nikula y = (adjusted_mode->crtc_vdisplay - height + 1) / 2;
433379bc100SJani Nikula x = 0;
434379bc100SJani Nikula width = adjusted_mode->crtc_hdisplay;
435379bc100SJani Nikula } else {
436379bc100SJani Nikula x = y = 0;
437379bc100SJani Nikula width = adjusted_mode->crtc_hdisplay;
438379bc100SJani Nikula height = adjusted_mode->crtc_vdisplay;
439379bc100SJani Nikula }
440379bc100SJani Nikula }
441379bc100SJani Nikula break;
442379bc100SJani Nikula
443379bc100SJani Nikula case DRM_MODE_SCALE_NONE:
444379bc100SJani Nikula WARN_ON(adjusted_mode->crtc_hdisplay != pipe_src_w);
445379bc100SJani Nikula WARN_ON(adjusted_mode->crtc_vdisplay != pipe_src_h);
446379bc100SJani Nikula fallthrough;
447379bc100SJani Nikula case DRM_MODE_SCALE_FULLSCREEN:
448379bc100SJani Nikula x = y = 0;
449379bc100SJani Nikula width = adjusted_mode->crtc_hdisplay;
450379bc100SJani Nikula height = adjusted_mode->crtc_vdisplay;
451379bc100SJani Nikula break;
452379bc100SJani Nikula
453379bc100SJani Nikula default:
454379bc100SJani Nikula MISSING_CASE(conn_state->scaling_mode);
455379bc100SJani Nikula return -EINVAL;
45681b55ef1SJani Nikula }
457379bc100SJani Nikula
458379bc100SJani Nikula drm_rect_init(&crtc_state->pch_pfit.dst,
459379bc100SJani Nikula x, y, width, height);
460379bc100SJani Nikula crtc_state->pch_pfit.enabled = true;
461379bc100SJani Nikula
462379bc100SJani Nikula return 0;
463379bc100SJani Nikula }
464379bc100SJani Nikula
465379bc100SJani Nikula static void
centre_horizontally(struct drm_display_mode * adjusted_mode,int width)466379bc100SJani Nikula centre_horizontally(struct drm_display_mode *adjusted_mode,
467379bc100SJani Nikula int width)
468379bc100SJani Nikula {
469f650af72SVille Syrjälä u32 border, sync_pos, blank_width, sync_width;
470379bc100SJani Nikula
471379bc100SJani Nikula /* keep the hsync and hblank widths constant */
472f650af72SVille Syrjälä sync_width = adjusted_mode->crtc_hsync_end - adjusted_mode->crtc_hsync_start;
473f650af72SVille Syrjälä blank_width = adjusted_mode->crtc_hblank_end - adjusted_mode->crtc_hblank_start;
47426111a16SVille Syrjälä sync_pos = (blank_width - sync_width + 1) / 2;
47526111a16SVille Syrjälä
47626111a16SVille Syrjälä border = (adjusted_mode->crtc_hdisplay - width + 1) / 2;
47726111a16SVille Syrjälä border += border & 1; /* make the border even */
478379bc100SJani Nikula
479379bc100SJani Nikula adjusted_mode->crtc_hdisplay = width;
480379bc100SJani Nikula adjusted_mode->crtc_hblank_start = width + border;
481379bc100SJani Nikula adjusted_mode->crtc_hblank_end = adjusted_mode->crtc_hblank_start + blank_width;
482379bc100SJani Nikula
483379bc100SJani Nikula adjusted_mode->crtc_hsync_start = adjusted_mode->crtc_hblank_start + sync_pos;
484379bc100SJani Nikula adjusted_mode->crtc_hsync_end = adjusted_mode->crtc_hsync_start + sync_width;
485379bc100SJani Nikula }
48626111a16SVille Syrjälä
487379bc100SJani Nikula static void
centre_vertically(struct drm_display_mode * adjusted_mode,int height)488379bc100SJani Nikula centre_vertically(struct drm_display_mode *adjusted_mode,
489379bc100SJani Nikula int height)
490f650af72SVille Syrjälä {
491379bc100SJani Nikula u32 border, sync_pos, blank_width, sync_width;
492379bc100SJani Nikula
493379bc100SJani Nikula /* keep the vsync and vblank widths constant */
494f650af72SVille Syrjälä sync_width = adjusted_mode->crtc_vsync_end - adjusted_mode->crtc_vsync_start;
49526111a16SVille Syrjälä blank_width = adjusted_mode->crtc_vblank_end - adjusted_mode->crtc_vblank_start;
49626111a16SVille Syrjälä sync_pos = (blank_width - sync_width + 1) / 2;
49726111a16SVille Syrjälä
49826111a16SVille Syrjälä border = (adjusted_mode->crtc_vdisplay - height + 1) / 2;
499379bc100SJani Nikula
500379bc100SJani Nikula adjusted_mode->crtc_vdisplay = height;
501379bc100SJani Nikula adjusted_mode->crtc_vblank_start = height + border;
502379bc100SJani Nikula adjusted_mode->crtc_vblank_end = adjusted_mode->crtc_vblank_start + blank_width;
503379bc100SJani Nikula
504379bc100SJani Nikula adjusted_mode->crtc_vsync_start = adjusted_mode->crtc_vblank_start + sync_pos;
505379bc100SJani Nikula adjusted_mode->crtc_vsync_end = adjusted_mode->crtc_vsync_start + sync_width;
506379bc100SJani Nikula }
507379bc100SJani Nikula
panel_fitter_scaling(u32 source,u32 target)50826111a16SVille Syrjälä static u32 panel_fitter_scaling(u32 source, u32 target)
509379bc100SJani Nikula {
510379bc100SJani Nikula /*
51126111a16SVille Syrjälä * Floating point operation is not supported. So the FACTOR
51226111a16SVille Syrjälä * is defined, which can avoid the floating point computation
513379bc100SJani Nikula * when calculating the panel ratio.
514379bc100SJani Nikula */
515379bc100SJani Nikula #define ACCURACY 12
516379bc100SJani Nikula #define FACTOR (1 << ACCURACY)
517379bc100SJani Nikula u32 ratio = source * FACTOR / target;
518379bc100SJani Nikula return (FACTOR * ratio + FACTOR/2) / FACTOR;
519379bc100SJani Nikula }
520379bc100SJani Nikula
i965_scale_aspect(struct intel_crtc_state * crtc_state,u32 * pfit_control)521379bc100SJani Nikula static void i965_scale_aspect(struct intel_crtc_state *crtc_state,
522379bc100SJani Nikula u32 *pfit_control)
52326111a16SVille Syrjälä {
524379bc100SJani Nikula const struct drm_display_mode *adjusted_mode =
525379bc100SJani Nikula &crtc_state->hw.adjusted_mode;
52626111a16SVille Syrjälä int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
52726111a16SVille Syrjälä int pipe_src_h = drm_rect_height(&crtc_state->pipe_src);
528379bc100SJani Nikula u32 scaled_width = adjusted_mode->crtc_hdisplay * pipe_src_h;
529379bc100SJani Nikula u32 scaled_height = pipe_src_w * adjusted_mode->crtc_vdisplay;
530379bc100SJani Nikula
531379bc100SJani Nikula /* 965+ is easy, it does everything in hw */
532379bc100SJani Nikula if (scaled_width > scaled_height)
533379bc100SJani Nikula *pfit_control |= PFIT_ENABLE |
534379bc100SJani Nikula PFIT_SCALING_PILLAR;
535379bc100SJani Nikula else if (scaled_width < scaled_height)
536379bc100SJani Nikula *pfit_control |= PFIT_ENABLE |
537379bc100SJani Nikula PFIT_SCALING_LETTER;
538379bc100SJani Nikula else if (adjusted_mode->crtc_hdisplay != pipe_src_w)
539379bc100SJani Nikula *pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
540379bc100SJani Nikula }
541379bc100SJani Nikula
i9xx_scale_aspect(struct intel_crtc_state * crtc_state,u32 * pfit_control,u32 * pfit_pgm_ratios,u32 * border)542379bc100SJani Nikula static void i9xx_scale_aspect(struct intel_crtc_state *crtc_state,
543379bc100SJani Nikula u32 *pfit_control, u32 *pfit_pgm_ratios,
544379bc100SJani Nikula u32 *border)
5454b93f49dSJani Nikula {
5464cecc7c0SVille Syrjälä struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
547379bc100SJani Nikula int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
548f650af72SVille Syrjälä int pipe_src_h = drm_rect_height(&crtc_state->pipe_src);
549f650af72SVille Syrjälä u32 scaled_width = adjusted_mode->crtc_hdisplay * pipe_src_h;
550379bc100SJani Nikula u32 scaled_height = pipe_src_w * adjusted_mode->crtc_vdisplay;
551f650af72SVille Syrjälä u32 bits;
55226111a16SVille Syrjälä
55326111a16SVille Syrjälä /*
554379bc100SJani Nikula * For earlier chips we have to calculate the scaling
555379bc100SJani Nikula * ratio by hand and program it into the
55626111a16SVille Syrjälä * PFIT_PGM_RATIO register
55726111a16SVille Syrjälä */
558379bc100SJani Nikula if (scaled_width > scaled_height) { /* pillar */
559379bc100SJani Nikula centre_horizontally(adjusted_mode,
5604cecc7c0SVille Syrjälä scaled_height / pipe_src_h);
561379bc100SJani Nikula
562379bc100SJani Nikula *border = LVDS_BORDER_ENABLE;
563379bc100SJani Nikula if (pipe_src_h != adjusted_mode->crtc_vdisplay) {
564379bc100SJani Nikula bits = panel_fitter_scaling(pipe_src_h,
565379bc100SJani Nikula adjusted_mode->crtc_vdisplay);
56626111a16SVille Syrjälä
56726111a16SVille Syrjälä *pfit_pgm_ratios |= (PFIT_HORIZ_SCALE(bits) |
568379bc100SJani Nikula PFIT_VERT_SCALE(bits));
569379bc100SJani Nikula *pfit_control |= (PFIT_ENABLE |
570379bc100SJani Nikula PFIT_VERT_INTERP_BILINEAR |
571379bc100SJani Nikula PFIT_HORIZ_INTERP_BILINEAR);
572005e9537SMatt Roper }
573f650af72SVille Syrjälä } else if (scaled_width < scaled_height) { /* letter */
574379bc100SJani Nikula centre_vertically(adjusted_mode,
575f650af72SVille Syrjälä scaled_width / pipe_src_w);
576379bc100SJani Nikula
577379bc100SJani Nikula *border = LVDS_BORDER_ENABLE;
578379bc100SJani Nikula if (pipe_src_w != adjusted_mode->crtc_hdisplay) {
579379bc100SJani Nikula bits = panel_fitter_scaling(pipe_src_w,
580379bc100SJani Nikula adjusted_mode->crtc_hdisplay);
581379bc100SJani Nikula
582379bc100SJani Nikula *pfit_pgm_ratios |= (PFIT_HORIZ_SCALE(bits) |
58326111a16SVille Syrjälä PFIT_VERT_SCALE(bits));
58426111a16SVille Syrjälä *pfit_control |= (PFIT_ENABLE |
585379bc100SJani Nikula PFIT_VERT_INTERP_BILINEAR |
586005e9537SMatt Roper PFIT_HORIZ_INTERP_BILINEAR);
587379bc100SJani Nikula }
588379bc100SJani Nikula } else {
589379bc100SJani Nikula /* Aspects match, Let hw scale both directions */
590379bc100SJani Nikula *pfit_control |= (PFIT_ENABLE |
591379bc100SJani Nikula PFIT_VERT_AUTO_SCALE |
592379bc100SJani Nikula PFIT_HORIZ_AUTO_SCALE |
593379bc100SJani Nikula PFIT_VERT_INTERP_BILINEAR |
594379bc100SJani Nikula PFIT_HORIZ_INTERP_BILINEAR);
595379bc100SJani Nikula }
5964cecc7c0SVille Syrjälä }
597d7ff281cSVille Syrjälä
gmch_panel_fitting(struct intel_crtc_state * crtc_state,const struct drm_connector_state * conn_state)598379bc100SJani Nikula static int gmch_panel_fitting(struct intel_crtc_state *crtc_state,
599379bc100SJani Nikula const struct drm_connector_state *conn_state)
600379bc100SJani Nikula {
601379bc100SJani Nikula struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
602005e9537SMatt Roper struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
603f650af72SVille Syrjälä u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
604379bc100SJani Nikula struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
605379bc100SJani Nikula int pipe_src_w = drm_rect_width(&crtc_state->pipe_src);
606379bc100SJani Nikula int pipe_src_h = drm_rect_height(&crtc_state->pipe_src);
607379bc100SJani Nikula
608379bc100SJani Nikula /* Native modes don't need fitting */
609379bc100SJani Nikula if (adjusted_mode->crtc_hdisplay == pipe_src_w &&
610379bc100SJani Nikula adjusted_mode->crtc_vdisplay == pipe_src_h)
611379bc100SJani Nikula goto out;
612005e9537SMatt Roper
613379bc100SJani Nikula switch (conn_state->scaling_mode) {
614379bc100SJani Nikula case DRM_MODE_SCALE_CENTER:
615f650af72SVille Syrjälä /*
616f650af72SVille Syrjälä * For centered modes, we have to calculate border widths &
617f650af72SVille Syrjälä * heights and modify the values programmed into the CRTC.
618d7ff281cSVille Syrjälä */
619d7ff281cSVille Syrjälä centre_horizontally(adjusted_mode, pipe_src_w);
620379bc100SJani Nikula centre_vertically(adjusted_mode, pipe_src_h);
621379bc100SJani Nikula border = LVDS_BORDER_ENABLE;
6224b93f49dSJani Nikula break;
6234b93f49dSJani Nikula case DRM_MODE_SCALE_ASPECT:
6244b93f49dSJani Nikula /* Scale but preserve the aspect ratio */
6254b93f49dSJani Nikula if (DISPLAY_VER(dev_priv) >= 4)
6264b93f49dSJani Nikula i965_scale_aspect(crtc_state, &pfit_control);
6274b93f49dSJani Nikula else
6284b93f49dSJani Nikula i9xx_scale_aspect(crtc_state, &pfit_control,
6294b93f49dSJani Nikula &pfit_pgm_ratios, &border);
6304b93f49dSJani Nikula break;
6314b93f49dSJani Nikula case DRM_MODE_SCALE_FULLSCREEN:
6324b93f49dSJani Nikula /*
6334b93f49dSJani Nikula * Full scaling, even if it changes the aspect ratio.
634b81dddb9SVille Syrjälä * Fortunately this is all done for us in hw.
635b81dddb9SVille Syrjälä */
636b81dddb9SVille Syrjälä if (pipe_src_h != adjusted_mode->crtc_vdisplay ||
637b81dddb9SVille Syrjälä pipe_src_w != adjusted_mode->crtc_hdisplay) {
638b81dddb9SVille Syrjälä pfit_control |= PFIT_ENABLE;
639b81dddb9SVille Syrjälä if (DISPLAY_VER(dev_priv) >= 4)
640b81dddb9SVille Syrjälä pfit_control |= PFIT_SCALING_AUTO;
641b81dddb9SVille Syrjälä else
642b81dddb9SVille Syrjälä pfit_control |= (PFIT_VERT_AUTO_SCALE |
643b81dddb9SVille Syrjälä PFIT_VERT_INTERP_BILINEAR |
644b81dddb9SVille Syrjälä PFIT_HORIZ_AUTO_SCALE |
64508243606SVille Syrjälä PFIT_HORIZ_INTERP_BILINEAR);
64608243606SVille Syrjälä }
64708243606SVille Syrjälä break;
64808243606SVille Syrjälä default:
64909270678SVille Syrjälä MISSING_CASE(conn_state->scaling_mode);
65009270678SVille Syrjälä return -EINVAL;
65108243606SVille Syrjälä }
65208243606SVille Syrjälä
65308243606SVille Syrjälä /* 965+ wants fuzzy fitting */
65408243606SVille Syrjälä /* FIXME: handle multiple panels by failing gracefully */
65508243606SVille Syrjälä if (DISPLAY_VER(dev_priv) >= 4)
65608243606SVille Syrjälä pfit_control |= PFIT_PIPE(crtc->pipe) | PFIT_FILTER_FUZZY;
65708243606SVille Syrjälä
65808243606SVille Syrjälä out:
65908243606SVille Syrjälä if ((pfit_control & PFIT_ENABLE) == 0) {
66008243606SVille Syrjälä pfit_control = 0;
66100fc3787SVille Syrjälä pfit_pgm_ratios = 0;
66200fc3787SVille Syrjälä }
66300fc3787SVille Syrjälä
66408243606SVille Syrjälä /* Make sure pre-965 set dither correctly for 18bpp panels. */
66508243606SVille Syrjälä if (DISPLAY_VER(dev_priv) < 4 && crtc_state->pipe_bpp == 18)
66608243606SVille Syrjälä pfit_control |= PFIT_PANEL_8TO6_DITHER_ENABLE;
667f70f8153SVille Syrjälä
668f70f8153SVille Syrjälä crtc_state->gmch_pfit.control = pfit_control;
669f70f8153SVille Syrjälä crtc_state->gmch_pfit.pgm_ratios = pfit_pgm_ratios;
670f70f8153SVille Syrjälä crtc_state->gmch_pfit.lvds_border_bits = border;
6713f9ffce5SVille Syrjälä
672bf38bba3SVille Syrjälä return 0;
673f70f8153SVille Syrjälä }
674f70f8153SVille Syrjälä
intel_panel_fitting(struct intel_crtc_state * crtc_state,const struct drm_connector_state * conn_state)675f70f8153SVille Syrjälä int intel_panel_fitting(struct intel_crtc_state *crtc_state,
67615d045fdSJani Nikula const struct drm_connector_state *conn_state)
67715d045fdSJani Nikula {
678379bc100SJani Nikula struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
6795d2fd49dSVille Syrjälä struct drm_i915_private *i915 = to_i915(crtc->base.dev);
6805d2fd49dSVille Syrjälä
68115d045fdSJani Nikula if (HAS_GMCH(i915))
68215d045fdSJani Nikula return gmch_panel_fitting(crtc_state, conn_state);
683c0a52f8bSJani Nikula else
684379bc100SJani Nikula return pch_panel_fitting(crtc_state, conn_state);
68522d9a255SVille Syrjälä }
68622d9a255SVille Syrjälä
68722d9a255SVille Syrjälä enum drm_connector_status
intel_panel_detect(struct drm_connector * connector,bool force)68805d2d45eSVille Syrjälä intel_panel_detect(struct drm_connector *connector, bool force)
68905d2d45eSVille Syrjälä {
69005d2d45eSVille Syrjälä struct drm_i915_private *i915 = to_i915(connector->dev);
69105d2d45eSVille Syrjälä
69205d2d45eSVille Syrjälä if (!INTEL_DISPLAY_ENABLED(i915))
693379bc100SJani Nikula return connector_status_disconnected;
694379bc100SJani Nikula
695379bc100SJani Nikula return connector_status_connected;
6965d2fd49dSVille Syrjälä }
697379bc100SJani Nikula
6985d2fd49dSVille Syrjälä enum drm_mode_status
intel_panel_mode_valid(struct intel_connector * connector,const struct drm_display_mode * mode)699345b7c4bSVille Syrjälä intel_panel_mode_valid(struct intel_connector *connector,
700379bc100SJani Nikula const struct drm_display_mode *mode)
70115d045fdSJani Nikula {
70215d045fdSJani Nikula const struct drm_display_mode *fixed_mode =
70315d045fdSJani Nikula intel_panel_fixed_mode(connector, mode);
704c0a52f8bSJani Nikula
705379bc100SJani Nikula if (!fixed_mode)
7063cf05076SVille Syrjälä return MODE_OK;
7073cf05076SVille Syrjälä
708345b7c4bSVille Syrjälä if (mode->hdisplay != fixed_mode->hdisplay)
709345b7c4bSVille Syrjälä return MODE_PANEL;
7105d2fd49dSVille Syrjälä
711345b7c4bSVille Syrjälä if (mode->vdisplay != fixed_mode->vdisplay)
712379bc100SJani Nikula return MODE_PANEL;
713
714 if (drm_mode_vrefresh(mode) != drm_mode_vrefresh(fixed_mode))
715 return MODE_PANEL;
716
717 return MODE_OK;
718 }
719
intel_panel_init_alloc(struct intel_connector * connector)720 void intel_panel_init_alloc(struct intel_connector *connector)
721 {
722 struct intel_panel *panel = &connector->panel;
723
724 connector->panel.vbt.panel_type = -1;
725 connector->panel.vbt.backlight.controller = -1;
726 INIT_LIST_HEAD(&panel->fixed_modes);
727 }
728
intel_panel_init(struct intel_connector * connector,const struct drm_edid * fixed_edid)729 int intel_panel_init(struct intel_connector *connector,
730 const struct drm_edid *fixed_edid)
731 {
732 struct intel_panel *panel = &connector->panel;
733
734 panel->fixed_edid = fixed_edid;
735
736 intel_backlight_init_funcs(panel);
737
738 if (!has_drrs_modes(connector))
739 connector->panel.vbt.drrs_type = DRRS_TYPE_NONE;
740
741 drm_dbg_kms(connector->base.dev,
742 "[CONNECTOR:%d:%s] DRRS type: %s\n",
743 connector->base.base.id, connector->base.name,
744 intel_drrs_type_str(intel_panel_drrs_type(connector)));
745
746 return 0;
747 }
748
intel_panel_fini(struct intel_connector * connector)749 void intel_panel_fini(struct intel_connector *connector)
750 {
751 struct intel_panel *panel = &connector->panel;
752 struct drm_display_mode *fixed_mode, *next;
753
754 if (!IS_ERR_OR_NULL(panel->fixed_edid))
755 drm_edid_free(panel->fixed_edid);
756
757 intel_backlight_destroy(panel);
758
759 intel_bios_fini_panel(panel);
760
761 list_for_each_entry_safe(fixed_mode, next, &panel->fixed_modes, head) {
762 list_del(&fixed_mode->head);
763 drm_mode_destroy(connector->base.dev, fixed_mode);
764 }
765 }
766