2 * Copyright © 2006-2007 Intel Corporation
3 * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
25 * Eric Anholt <eric@anholt.net>
26 * Dave Airlie <airlied@linux.ie>
27 * Jesse Barnes <jesse.barnes@intel.com>
30 #include <linux/dmi.h>
31 #include <linux/i2c.h>
33 #include <drm/drm_crtc.h>
34 #include <drm/drm_edid.h>
35 #include "intel_drv.h"
36 #include <drm/i915_drm.h>
39 /* Private structure for the integrated LVDS support */
40 struct intel_lvds_connector {
41 struct intel_connector base;
44 struct notifier_block lid_notifier;
48 struct intel_lvds_encoder {
49 struct intel_encoder base;
54 struct intel_lvds_connector *attached_connector;
57 static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
59 return container_of(encoder, struct intel_lvds_encoder, base.base);
62 static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
64 return container_of(connector, struct intel_lvds_connector, base.base);
67 static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
70 struct drm_device *dev = encoder->base.dev;
71 struct drm_i915_private *dev_priv = dev->dev_private;
72 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
75 tmp = I915_READ(lvds_encoder->reg);
77 if (!(tmp & LVDS_PORT_EN))
81 *pipe = PORT_TO_PIPE_CPT(tmp);
83 *pipe = PORT_TO_PIPE(tmp);
88 static void intel_lvds_get_config(struct intel_encoder *encoder,
89 struct intel_crtc_config *pipe_config)
91 struct drm_device *dev = encoder->base.dev;
92 struct drm_i915_private *dev_priv = dev->dev_private;
93 u32 lvds_reg, tmp, flags = 0;
95 if (HAS_PCH_SPLIT(dev))
100 tmp = I915_READ(lvds_reg);
101 if (tmp & LVDS_HSYNC_POLARITY)
102 flags |= DRM_MODE_FLAG_NHSYNC;
104 flags |= DRM_MODE_FLAG_PHSYNC;
105 if (tmp & LVDS_VSYNC_POLARITY)
106 flags |= DRM_MODE_FLAG_NVSYNC;
108 flags |= DRM_MODE_FLAG_PVSYNC;
110 pipe_config->adjusted_mode.flags |= flags;
112 /* gen2/3 store dither state in pfit control, needs to match */
113 if (INTEL_INFO(dev)->gen < 4) {
114 tmp = I915_READ(PFIT_CONTROL);
116 pipe_config->gmch_pfit.control |= tmp & PANEL_8TO6_DITHER_ENABLE;
120 /* The LVDS pin pair needs to be on before the DPLLs are enabled.
121 * This is an exception to the general rule that mode_set doesn't turn
124 static void intel_pre_pll_enable_lvds(struct intel_encoder *encoder)
126 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
127 struct drm_device *dev = encoder->base.dev;
128 struct drm_i915_private *dev_priv = dev->dev_private;
129 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
130 struct drm_display_mode *fixed_mode =
131 lvds_encoder->attached_connector->base.panel.fixed_mode;
132 int pipe = intel_crtc->pipe;
135 temp = I915_READ(lvds_encoder->reg);
136 temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
138 if (HAS_PCH_CPT(dev)) {
139 temp &= ~PORT_TRANS_SEL_MASK;
140 temp |= PORT_TRANS_SEL_CPT(pipe);
143 temp |= LVDS_PIPEB_SELECT;
145 temp &= ~LVDS_PIPEB_SELECT;
149 /* set the corresponsding LVDS_BORDER bit */
150 temp &= ~LVDS_BORDER_ENABLE;
151 temp |= intel_crtc->config.gmch_pfit.lvds_border_bits;
152 /* Set the B0-B3 data pairs corresponding to whether we're going to
153 * set the DPLLs for dual-channel mode or not.
155 if (lvds_encoder->is_dual_link)
156 temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
158 temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
160 /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
161 * appropriately here, but we need to look more thoroughly into how
162 * panels behave in the two modes.
165 /* Set the dithering flag on LVDS as needed, note that there is no
166 * special lvds dither control bit on pch-split platforms, dithering is
167 * only controlled through the PIPECONF reg. */
168 if (INTEL_INFO(dev)->gen == 4) {
169 /* Bspec wording suggests that LVDS port dithering only exists
170 * for 18bpp panels. */
171 if (intel_crtc->config.dither &&
172 intel_crtc->config.pipe_bpp == 18)
173 temp |= LVDS_ENABLE_DITHER;
175 temp &= ~LVDS_ENABLE_DITHER;
177 temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
178 if (fixed_mode->flags & DRM_MODE_FLAG_NHSYNC)
179 temp |= LVDS_HSYNC_POLARITY;
180 if (fixed_mode->flags & DRM_MODE_FLAG_NVSYNC)
181 temp |= LVDS_VSYNC_POLARITY;
183 I915_WRITE(lvds_encoder->reg, temp);
187 * Sets the power state for the panel.
189 static void intel_enable_lvds(struct intel_encoder *encoder)
191 struct drm_device *dev = encoder->base.dev;
192 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
193 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
194 struct drm_i915_private *dev_priv = dev->dev_private;
195 u32 ctl_reg, stat_reg;
197 if (HAS_PCH_SPLIT(dev)) {
198 ctl_reg = PCH_PP_CONTROL;
199 stat_reg = PCH_PP_STATUS;
201 ctl_reg = PP_CONTROL;
202 stat_reg = PP_STATUS;
205 I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
207 I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
208 POSTING_READ(lvds_encoder->reg);
209 if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
210 DRM_ERROR("timed out waiting for panel to power on\n");
212 intel_panel_enable_backlight(dev, intel_crtc->pipe);
215 static void intel_disable_lvds(struct intel_encoder *encoder)
217 struct drm_device *dev = encoder->base.dev;
218 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
219 struct drm_i915_private *dev_priv = dev->dev_private;
220 u32 ctl_reg, stat_reg;
222 if (HAS_PCH_SPLIT(dev)) {
223 ctl_reg = PCH_PP_CONTROL;
224 stat_reg = PCH_PP_STATUS;
226 ctl_reg = PP_CONTROL;
227 stat_reg = PP_STATUS;
230 intel_panel_disable_backlight(dev);
232 I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
233 if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
234 DRM_ERROR("timed out waiting for panel to power off\n");
236 I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
237 POSTING_READ(lvds_encoder->reg);
240 static int intel_lvds_mode_valid(struct drm_connector *connector,
241 struct drm_display_mode *mode)
243 struct intel_connector *intel_connector = to_intel_connector(connector);
244 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
246 if (mode->hdisplay > fixed_mode->hdisplay)
248 if (mode->vdisplay > fixed_mode->vdisplay)
254 static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
255 struct intel_crtc_config *pipe_config)
257 struct drm_device *dev = intel_encoder->base.dev;
258 struct drm_i915_private *dev_priv = dev->dev_private;
259 struct intel_lvds_encoder *lvds_encoder =
260 to_lvds_encoder(&intel_encoder->base);
261 struct intel_connector *intel_connector =
262 &lvds_encoder->attached_connector->base;
263 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
264 struct intel_crtc *intel_crtc = lvds_encoder->base.new_crtc;
265 unsigned int lvds_bpp;
267 /* Should never happen!! */
268 if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
269 DRM_ERROR("Can't support LVDS on pipe A\n");
273 if ((I915_READ(lvds_encoder->reg) & LVDS_A3_POWER_MASK) ==
279 if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) {
280 DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
281 pipe_config->pipe_bpp, lvds_bpp);
282 pipe_config->pipe_bpp = lvds_bpp;
286 * We have timings from the BIOS for the panel, put them in
287 * to the adjusted mode. The CRTC will be set up for this mode,
288 * with the panel scaling set up to source from the H/VDisplay
289 * of the original mode.
291 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
294 if (HAS_PCH_SPLIT(dev)) {
295 pipe_config->has_pch_encoder = true;
297 intel_pch_panel_fitting(intel_crtc, pipe_config,
298 intel_connector->panel.fitting_mode);
300 intel_gmch_panel_fitting(intel_crtc, pipe_config,
301 intel_connector->panel.fitting_mode);
306 * XXX: It would be nice to support lower refresh rates on the
307 * panels to reduce power consumption, and perhaps match the
308 * user's requested refresh rate.
314 static void intel_lvds_mode_set(struct drm_encoder *encoder,
315 struct drm_display_mode *mode,
316 struct drm_display_mode *adjusted_mode)
319 * The LVDS pin pair will already have been turned on in the
320 * intel_crtc_mode_set since it has a large impact on the DPLL
326 * Detect the LVDS connection.
328 * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
329 * connected and closed means disconnected. We also send hotplug events as
330 * needed, using lid status notification from the input layer.
332 static enum drm_connector_status
333 intel_lvds_detect(struct drm_connector *connector, bool force)
335 struct drm_device *dev = connector->dev;
336 enum drm_connector_status status;
338 status = intel_panel_detect(dev);
339 if (status != connector_status_unknown)
342 return connector_status_connected;
346 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
348 static int intel_lvds_get_modes(struct drm_connector *connector)
350 struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
351 struct drm_device *dev = connector->dev;
352 struct drm_display_mode *mode;
354 /* use cached edid if we have one */
355 if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
356 return drm_add_edid_modes(connector, lvds_connector->base.edid);
358 mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
362 drm_mode_probed_add(connector, mode);
366 static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
368 DRM_INFO("Skipping forced modeset for %s\n", id->ident);
372 /* The GPU hangs up on these systems if modeset is performed on LID open */
373 static const struct dmi_system_id intel_no_modeset_on_lid[] = {
375 .callback = intel_no_modeset_on_lid_dmi_callback,
376 .ident = "Toshiba Tecra A11",
378 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
379 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
383 { } /* terminating entry */
388 * Lid events. Note the use of 'modeset':
389 * - we set it to MODESET_ON_LID_OPEN on lid close,
390 * and set it to MODESET_DONE on open
391 * - we use it as a "only once" bit (ie we ignore
392 * duplicate events where it was already properly set)
393 * - the suspend/resume paths will set it to
394 * MODESET_SUSPENDED and ignore the lid open event,
395 * because they restore the mode ("lid open").
397 static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
400 struct intel_lvds_connector *lvds_connector =
401 container_of(nb, struct intel_lvds_connector, lid_notifier);
402 struct drm_connector *connector = &lvds_connector->base.base;
403 struct drm_device *dev = connector->dev;
404 struct drm_i915_private *dev_priv = dev->dev_private;
406 if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
409 mutex_lock(&dev_priv->modeset_restore_lock);
410 if (dev_priv->modeset_restore == MODESET_SUSPENDED)
413 * check and update the status of LVDS connector after receiving
414 * the LID nofication event.
416 connector->status = connector->funcs->detect(connector, false);
418 /* Don't force modeset on machines where it causes a GPU lockup */
419 if (dmi_check_system(intel_no_modeset_on_lid))
421 if (!acpi_lid_open()) {
422 /* do modeset on next lid open event */
423 dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
427 if (dev_priv->modeset_restore == MODESET_DONE)
430 drm_modeset_lock_all(dev);
431 intel_modeset_setup_hw_state(dev, true);
432 drm_modeset_unlock_all(dev);
434 dev_priv->modeset_restore = MODESET_DONE;
437 mutex_unlock(&dev_priv->modeset_restore_lock);
443 * intel_lvds_destroy - unregister and free LVDS structures
444 * @connector: connector to free
446 * Unregister the DDC bus for this connector then free the driver private
449 static void intel_lvds_destroy(struct drm_connector *connector)
451 struct intel_lvds_connector *lvds_connector =
452 to_lvds_connector(connector);
455 if (lvds_connector->lid_notifier.notifier_call)
456 acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
459 if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
460 kfree(lvds_connector->base.edid);
462 intel_panel_fini(&lvds_connector->base.panel);
465 drm_sysfs_connector_remove(connector);
467 drm_connector_cleanup(connector);
471 static int intel_lvds_set_property(struct drm_connector *connector,
472 struct drm_property *property,
475 struct intel_connector *intel_connector = to_intel_connector(connector);
476 struct drm_device *dev = connector->dev;
478 if (property == dev->mode_config.scaling_mode_property) {
479 struct drm_crtc *crtc;
481 if (value == DRM_MODE_SCALE_NONE) {
482 DRM_DEBUG_KMS("no scaling not supported\n");
486 if (intel_connector->panel.fitting_mode == value) {
487 /* the LVDS scaling property is not changed */
490 intel_connector->panel.fitting_mode = value;
492 crtc = intel_attached_encoder(connector)->base.crtc;
493 if (crtc && crtc->enabled) {
495 * If the CRTC is enabled, the display will be changed
496 * according to the new panel fitting mode.
498 intel_crtc_restore_mode(crtc);
505 static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
506 .mode_set = intel_lvds_mode_set,
509 static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
510 .get_modes = intel_lvds_get_modes,
511 .mode_valid = intel_lvds_mode_valid,
512 .best_encoder = intel_best_encoder,
515 static const struct drm_connector_funcs intel_lvds_connector_funcs = {
516 .dpms = intel_connector_dpms,
517 .detect = intel_lvds_detect,
518 .fill_modes = drm_helper_probe_single_connector_modes,
519 .set_property = intel_lvds_set_property,
520 .destroy = intel_lvds_destroy,
523 static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
524 .destroy = intel_encoder_destroy,
527 static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
529 DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
533 /* These systems claim to have LVDS, but really don't */
534 static const struct dmi_system_id intel_no_lvds[] = {
536 .callback = intel_no_lvds_dmi_callback,
537 .ident = "Apple Mac Mini (Core series)",
539 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
540 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
544 .callback = intel_no_lvds_dmi_callback,
545 .ident = "Apple Mac Mini (Core 2 series)",
547 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
548 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
552 .callback = intel_no_lvds_dmi_callback,
553 .ident = "MSI IM-945GSE-A",
555 DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
556 DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
560 .callback = intel_no_lvds_dmi_callback,
561 .ident = "Dell Studio Hybrid",
563 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
564 DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
568 .callback = intel_no_lvds_dmi_callback,
569 .ident = "Dell OptiPlex FX170",
571 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
572 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
576 .callback = intel_no_lvds_dmi_callback,
577 .ident = "AOpen Mini PC",
579 DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
580 DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
584 .callback = intel_no_lvds_dmi_callback,
585 .ident = "AOpen Mini PC MP915",
587 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
588 DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
592 .callback = intel_no_lvds_dmi_callback,
593 .ident = "AOpen i915GMm-HFS",
595 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
596 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
600 .callback = intel_no_lvds_dmi_callback,
601 .ident = "AOpen i45GMx-I",
603 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
604 DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
608 .callback = intel_no_lvds_dmi_callback,
609 .ident = "Aopen i945GTt-VFA",
611 DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
615 .callback = intel_no_lvds_dmi_callback,
616 .ident = "Clientron U800",
618 DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
619 DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
623 .callback = intel_no_lvds_dmi_callback,
624 .ident = "Clientron E830",
626 DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
627 DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
631 .callback = intel_no_lvds_dmi_callback,
632 .ident = "Asus EeeBox PC EB1007",
634 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
635 DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
639 .callback = intel_no_lvds_dmi_callback,
640 .ident = "Asus AT5NM10T-I",
642 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
643 DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
647 .callback = intel_no_lvds_dmi_callback,
648 .ident = "Hewlett-Packard HP t5740",
650 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
651 DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
655 .callback = intel_no_lvds_dmi_callback,
656 .ident = "Hewlett-Packard t5745",
658 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
659 DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
663 .callback = intel_no_lvds_dmi_callback,
664 .ident = "Hewlett-Packard st5747",
666 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
667 DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
671 .callback = intel_no_lvds_dmi_callback,
672 .ident = "MSI Wind Box DC500",
674 DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
675 DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
679 .callback = intel_no_lvds_dmi_callback,
680 .ident = "Gigabyte GA-D525TUD",
682 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
683 DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
687 .callback = intel_no_lvds_dmi_callback,
688 .ident = "Supermicro X7SPA-H",
690 DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
691 DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
695 .callback = intel_no_lvds_dmi_callback,
696 .ident = "Fujitsu Esprimo Q900",
698 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
699 DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
703 .callback = intel_no_lvds_dmi_callback,
704 .ident = "Intel D510MO",
706 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
707 DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
711 .callback = intel_no_lvds_dmi_callback,
712 .ident = "Intel D525MW",
714 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
715 DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
719 { } /* terminating entry */
723 * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
725 * @connector: LVDS connector
727 * Find the reduced downclock for LVDS in EDID.
729 static void intel_find_lvds_downclock(struct drm_device *dev,
730 struct drm_display_mode *fixed_mode,
731 struct drm_connector *connector)
733 struct drm_i915_private *dev_priv = dev->dev_private;
734 struct drm_display_mode *scan;
737 temp_downclock = fixed_mode->clock;
738 list_for_each_entry(scan, &connector->probed_modes, head) {
740 * If one mode has the same resolution with the fixed_panel
741 * mode while they have the different refresh rate, it means
742 * that the reduced downclock is found for the LVDS. In such
743 * case we can set the different FPx0/1 to dynamically select
744 * between low and high frequency.
746 if (scan->hdisplay == fixed_mode->hdisplay &&
747 scan->hsync_start == fixed_mode->hsync_start &&
748 scan->hsync_end == fixed_mode->hsync_end &&
749 scan->htotal == fixed_mode->htotal &&
750 scan->vdisplay == fixed_mode->vdisplay &&
751 scan->vsync_start == fixed_mode->vsync_start &&
752 scan->vsync_end == fixed_mode->vsync_end &&
753 scan->vtotal == fixed_mode->vtotal) {
754 if (scan->clock < temp_downclock) {
756 * The downclock is already found. But we
757 * expect to find the lower downclock.
759 temp_downclock = scan->clock;
763 if (temp_downclock < fixed_mode->clock && i915_lvds_downclock) {
764 /* We found the downclock for LVDS. */
765 dev_priv->lvds_downclock_avail = 1;
766 dev_priv->lvds_downclock = temp_downclock;
767 DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
768 "Normal clock %dKhz, downclock %dKhz\n",
769 fixed_mode->clock, temp_downclock);
774 * Enumerate the child dev array parsed from VBT to check whether
775 * the LVDS is present.
776 * If it is present, return 1.
777 * If it is not present, return false.
778 * If no child dev is parsed from VBT, it assumes that the LVDS is present.
780 static bool lvds_is_present_in_vbt(struct drm_device *dev,
783 struct drm_i915_private *dev_priv = dev->dev_private;
786 if (!dev_priv->vbt.child_dev_num)
789 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
790 struct child_device_config *child = dev_priv->vbt.child_dev + i;
792 /* If the device type is not LFP, continue.
793 * We have to check both the new identifiers as well as the
794 * old for compatibility with some BIOSes.
796 if (child->device_type != DEVICE_TYPE_INT_LFP &&
797 child->device_type != DEVICE_TYPE_LFP)
800 if (intel_gmbus_is_port_valid(child->i2c_pin))
801 *i2c_pin = child->i2c_pin;
803 /* However, we cannot trust the BIOS writers to populate
804 * the VBT correctly. Since LVDS requires additional
805 * information from AIM blocks, a non-zero addin offset is
806 * a good indicator that the LVDS is actually present.
808 if (child->addin_offset)
811 /* But even then some BIOS writers perform some black magic
812 * and instantiate the device without reference to any
813 * additional data. Trust that if the VBT was written into
814 * the OpRegion then they have validated the LVDS's existence.
816 if (dev_priv->opregion.vbt)
823 static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
825 DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
829 static const struct dmi_system_id intel_dual_link_lvds[] = {
831 .callback = intel_dual_link_lvds_callback,
832 .ident = "Apple MacBook Pro (Core i5/i7 Series)",
834 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
835 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
838 { } /* terminating entry */
841 bool intel_is_dual_link_lvds(struct drm_device *dev)
843 struct intel_encoder *encoder;
844 struct intel_lvds_encoder *lvds_encoder;
846 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
848 if (encoder->type == INTEL_OUTPUT_LVDS) {
849 lvds_encoder = to_lvds_encoder(&encoder->base);
851 return lvds_encoder->is_dual_link;
858 static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
860 struct drm_device *dev = lvds_encoder->base.base.dev;
862 struct drm_i915_private *dev_priv = dev->dev_private;
864 /* use the module option value if specified */
865 if (i915_lvds_channel_mode > 0)
866 return i915_lvds_channel_mode == 2;
868 if (dmi_check_system(intel_dual_link_lvds))
871 /* BIOS should set the proper LVDS register value at boot, but
872 * in reality, it doesn't set the value when the lid is closed;
873 * we need to check "the value to be set" in VBT when LVDS
874 * register is uninitialized.
876 val = I915_READ(lvds_encoder->reg);
877 if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
878 val = dev_priv->vbt.bios_lvds_val;
880 return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
883 static bool intel_lvds_supported(struct drm_device *dev)
885 /* With the introduction of the PCH we gained a dedicated
886 * LVDS presence pin, use it. */
887 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
890 /* Otherwise LVDS was only attached to mobile products,
891 * except for the inglorious 830gm */
892 if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
899 * intel_lvds_init - setup LVDS connectors on this device
902 * Create the connector, register the LVDS DDC bus, and try to figure out what
903 * modes we can display on the LVDS panel (if present).
905 void intel_lvds_init(struct drm_device *dev)
907 struct drm_i915_private *dev_priv = dev->dev_private;
908 struct intel_lvds_encoder *lvds_encoder;
909 struct intel_encoder *intel_encoder;
910 struct intel_lvds_connector *lvds_connector;
911 struct intel_connector *intel_connector;
912 struct drm_connector *connector;
913 struct drm_encoder *encoder;
914 struct drm_display_mode *scan; /* *modes, *bios_mode; */
915 struct drm_display_mode *fixed_mode = NULL;
917 struct drm_crtc *crtc;
922 if (!intel_lvds_supported(dev))
925 /* Skip init on machines we know falsely report LVDS */
926 if (dmi_check_system(intel_no_lvds))
929 pin = GMBUS_PORT_PANEL;
930 if (!lvds_is_present_in_vbt(dev, &pin)) {
931 DRM_DEBUG_KMS("LVDS is not present in VBT\n");
935 if (HAS_PCH_SPLIT(dev)) {
936 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
938 if (dev_priv->vbt.edp_support) {
939 DRM_DEBUG_KMS("disable LVDS for eDP support\n");
944 lvds_encoder = kzalloc(sizeof(struct intel_lvds_encoder), GFP_KERNEL);
948 lvds_connector = kzalloc(sizeof(struct intel_lvds_connector), GFP_KERNEL);
949 if (!lvds_connector) {
954 lvds_encoder->attached_connector = lvds_connector;
956 intel_encoder = &lvds_encoder->base;
957 encoder = &intel_encoder->base;
958 intel_connector = &lvds_connector->base;
959 connector = &intel_connector->base;
960 drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
961 DRM_MODE_CONNECTOR_LVDS);
963 drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
964 DRM_MODE_ENCODER_LVDS);
966 intel_encoder->enable = intel_enable_lvds;
967 intel_encoder->pre_pll_enable = intel_pre_pll_enable_lvds;
968 intel_encoder->compute_config = intel_lvds_compute_config;
969 intel_encoder->disable = intel_disable_lvds;
970 intel_encoder->get_hw_state = intel_lvds_get_hw_state;
971 intel_encoder->get_config = intel_lvds_get_config;
972 intel_connector->get_hw_state = intel_connector_get_hw_state;
974 intel_connector_attach_encoder(intel_connector, intel_encoder);
975 intel_encoder->type = INTEL_OUTPUT_LVDS;
977 intel_encoder->cloneable = false;
978 if (HAS_PCH_SPLIT(dev))
979 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
980 else if (IS_GEN4(dev))
981 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
983 intel_encoder->crtc_mask = (1 << 1);
985 drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
986 drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
987 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
988 connector->interlace_allowed = false;
989 connector->doublescan_allowed = false;
991 if (HAS_PCH_SPLIT(dev)) {
992 lvds_encoder->reg = PCH_LVDS;
994 lvds_encoder->reg = LVDS;
997 /* create the scaling mode property */
998 drm_mode_create_scaling_mode_property(dev);
999 drm_object_attach_property(&connector->base,
1000 dev->mode_config.scaling_mode_property,
1001 DRM_MODE_SCALE_ASPECT);
1002 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
1005 * 1) check for EDID on DDC
1006 * 2) check for VBT data
1007 * 3) check to see if LVDS is already on
1008 * if none of the above, no panel
1009 * 4) make sure lid is open
1010 * if closed, act like it's not there for now
1014 * Attempt to get the fixed panel mode from DDC. Assume that the
1015 * preferred mode is the right one.
1017 edid = drm_get_edid(connector, intel_gmbus_get_adapter(dev_priv, pin));
1019 if (drm_add_edid_modes(connector, edid)) {
1020 drm_mode_connector_update_edid_property(connector,
1024 edid = ERR_PTR(-EINVAL);
1027 edid = ERR_PTR(-ENOENT);
1029 lvds_connector->base.edid = edid;
1031 if (IS_ERR_OR_NULL(edid)) {
1032 /* Didn't get an EDID, so
1033 * Set wide sync ranges so we get all modes
1034 * handed to valid_mode for checking
1036 connector->display_info.min_vfreq = 0;
1037 connector->display_info.max_vfreq = 200;
1038 connector->display_info.min_hfreq = 0;
1039 connector->display_info.max_hfreq = 200;
1042 list_for_each_entry(scan, &connector->probed_modes, head) {
1043 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
1044 DRM_DEBUG_KMS("using preferred mode from EDID: ");
1045 drm_mode_debug_printmodeline(scan);
1047 fixed_mode = drm_mode_duplicate(dev, scan);
1049 intel_find_lvds_downclock(dev, fixed_mode,
1056 /* Failed to get EDID, what about VBT? */
1057 if (dev_priv->vbt.lfp_lvds_vbt_mode) {
1058 DRM_DEBUG_KMS("using mode from VBT: ");
1059 drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
1061 fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
1063 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1069 * If we didn't get EDID, try checking if the panel is already turned
1070 * on. If so, assume that whatever is currently programmed is the
1074 /* Ironlake: FIXME if still fail, not try pipe mode now */
1075 if (HAS_PCH_SPLIT(dev))
1078 lvds = I915_READ(LVDS);
1079 pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
1080 crtc = intel_get_crtc_for_pipe(dev, pipe);
1082 if (crtc && (lvds & LVDS_PORT_EN)) {
1083 fixed_mode = intel_crtc_mode_get(dev, crtc);
1085 DRM_DEBUG_KMS("using current (BIOS) mode: ");
1086 drm_mode_debug_printmodeline(fixed_mode);
1087 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1092 /* If we still don't have a mode after all that, give up. */
1097 lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
1098 DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
1099 lvds_encoder->is_dual_link ? "dual" : "single");
1102 * Unlock registers and just
1103 * leave them unlocked
1105 if (HAS_PCH_SPLIT(dev)) {
1106 I915_WRITE(PCH_PP_CONTROL,
1107 I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
1109 I915_WRITE(PP_CONTROL,
1110 I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
1113 lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
1114 if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
1115 DRM_DEBUG_KMS("lid notifier registration failed\n");
1116 lvds_connector->lid_notifier.notifier_call = NULL;
1118 drm_sysfs_connector_add(connector);
1121 intel_panel_init(&intel_connector->panel, fixed_mode);
1122 intel_panel_setup_backlight(connector);
1127 DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
1128 drm_connector_cleanup(connector);
1129 drm_encoder_cleanup(encoder);
1131 drm_mode_destroy(dev, fixed_mode);
1132 kfree(lvds_encoder);
1133 kfree(lvds_connector);