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 <acpi/button.h>
31 #include <linux/dmi.h>
32 #include <linux/i2c.h>
33 #include <linux/slab.h>
35 #include <drm/drm_crtc.h>
36 #include <drm/drm_edid.h>
37 #include "intel_drv.h"
38 #include <drm/i915_drm.h>
40 #include <linux/acpi.h>
42 /* Private structure for the integrated LVDS support */
43 struct intel_lvds_connector {
44 struct intel_connector base;
46 struct notifier_block lid_notifier;
49 struct intel_lvds_encoder {
50 struct intel_encoder base;
55 struct intel_lvds_connector *attached_connector;
58 static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
60 return container_of(encoder, struct intel_lvds_encoder, base.base);
63 static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
65 return container_of(connector, struct intel_lvds_connector, base.base);
68 static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
71 struct drm_device *dev = encoder->base.dev;
72 struct drm_i915_private *dev_priv = dev->dev_private;
73 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
76 tmp = I915_READ(lvds_encoder->reg);
78 if (!(tmp & LVDS_PORT_EN))
82 *pipe = PORT_TO_PIPE_CPT(tmp);
84 *pipe = PORT_TO_PIPE(tmp);
89 /* The LVDS pin pair needs to be on before the DPLLs are enabled.
90 * This is an exception to the general rule that mode_set doesn't turn
93 static void intel_pre_pll_enable_lvds(struct intel_encoder *encoder)
95 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
96 struct drm_device *dev = encoder->base.dev;
97 struct drm_i915_private *dev_priv = dev->dev_private;
98 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
99 struct drm_display_mode *fixed_mode =
100 lvds_encoder->attached_connector->base.panel.fixed_mode;
101 int pipe = intel_crtc->pipe;
104 temp = I915_READ(lvds_encoder->reg);
105 temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
107 if (HAS_PCH_CPT(dev)) {
108 temp &= ~PORT_TRANS_SEL_MASK;
109 temp |= PORT_TRANS_SEL_CPT(pipe);
112 temp |= LVDS_PIPEB_SELECT;
114 temp &= ~LVDS_PIPEB_SELECT;
118 /* set the corresponsding LVDS_BORDER bit */
119 temp &= ~LVDS_BORDER_ENABLE;
120 temp |= intel_crtc->config.gmch_pfit.lvds_border_bits;
121 /* Set the B0-B3 data pairs corresponding to whether we're going to
122 * set the DPLLs for dual-channel mode or not.
124 if (lvds_encoder->is_dual_link)
125 temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
127 temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
129 /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
130 * appropriately here, but we need to look more thoroughly into how
131 * panels behave in the two modes.
134 /* Set the dithering flag on LVDS as needed, note that there is no
135 * special lvds dither control bit on pch-split platforms, dithering is
136 * only controlled through the PIPECONF reg. */
137 if (INTEL_INFO(dev)->gen == 4) {
138 /* Bspec wording suggests that LVDS port dithering only exists
139 * for 18bpp panels. */
140 if (intel_crtc->config.dither &&
141 intel_crtc->config.pipe_bpp == 18)
142 temp |= LVDS_ENABLE_DITHER;
144 temp &= ~LVDS_ENABLE_DITHER;
146 temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
147 if (fixed_mode->flags & DRM_MODE_FLAG_NHSYNC)
148 temp |= LVDS_HSYNC_POLARITY;
149 if (fixed_mode->flags & DRM_MODE_FLAG_NVSYNC)
150 temp |= LVDS_VSYNC_POLARITY;
152 I915_WRITE(lvds_encoder->reg, temp);
156 * Sets the power state for the panel.
158 static void intel_enable_lvds(struct intel_encoder *encoder)
160 struct drm_device *dev = encoder->base.dev;
161 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
162 struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
163 struct drm_i915_private *dev_priv = dev->dev_private;
164 u32 ctl_reg, stat_reg;
166 if (HAS_PCH_SPLIT(dev)) {
167 ctl_reg = PCH_PP_CONTROL;
168 stat_reg = PCH_PP_STATUS;
170 ctl_reg = PP_CONTROL;
171 stat_reg = PP_STATUS;
174 I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
176 I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
177 POSTING_READ(lvds_encoder->reg);
178 if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
179 DRM_ERROR("timed out waiting for panel to power on\n");
181 intel_panel_enable_backlight(dev, intel_crtc->pipe);
184 static void intel_disable_lvds(struct intel_encoder *encoder)
186 struct drm_device *dev = encoder->base.dev;
187 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
188 struct drm_i915_private *dev_priv = dev->dev_private;
189 u32 ctl_reg, stat_reg;
191 if (HAS_PCH_SPLIT(dev)) {
192 ctl_reg = PCH_PP_CONTROL;
193 stat_reg = PCH_PP_STATUS;
195 ctl_reg = PP_CONTROL;
196 stat_reg = PP_STATUS;
199 intel_panel_disable_backlight(dev);
201 I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
202 if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
203 DRM_ERROR("timed out waiting for panel to power off\n");
205 I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
206 POSTING_READ(lvds_encoder->reg);
209 static int intel_lvds_mode_valid(struct drm_connector *connector,
210 struct drm_display_mode *mode)
212 struct intel_connector *intel_connector = to_intel_connector(connector);
213 struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
215 if (mode->hdisplay > fixed_mode->hdisplay)
217 if (mode->vdisplay > fixed_mode->vdisplay)
223 static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
224 struct intel_crtc_config *pipe_config)
226 struct drm_device *dev = intel_encoder->base.dev;
227 struct drm_i915_private *dev_priv = dev->dev_private;
228 struct intel_lvds_encoder *lvds_encoder =
229 to_lvds_encoder(&intel_encoder->base);
230 struct intel_connector *intel_connector =
231 &lvds_encoder->attached_connector->base;
232 struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
233 struct intel_crtc *intel_crtc = lvds_encoder->base.new_crtc;
234 unsigned int lvds_bpp;
236 /* Should never happen!! */
237 if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
238 DRM_ERROR("Can't support LVDS on pipe A\n");
242 if (intel_encoder_check_is_cloned(&lvds_encoder->base))
245 if ((I915_READ(lvds_encoder->reg) & LVDS_A3_POWER_MASK) ==
251 if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) {
252 DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
253 pipe_config->pipe_bpp, lvds_bpp);
254 pipe_config->pipe_bpp = lvds_bpp;
258 * We have timings from the BIOS for the panel, put them in
259 * to the adjusted mode. The CRTC will be set up for this mode,
260 * with the panel scaling set up to source from the H/VDisplay
261 * of the original mode.
263 intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
266 if (HAS_PCH_SPLIT(dev)) {
267 pipe_config->has_pch_encoder = true;
269 intel_pch_panel_fitting(intel_crtc, pipe_config,
270 intel_connector->panel.fitting_mode);
273 intel_gmch_panel_fitting(intel_crtc, pipe_config,
274 intel_connector->panel.fitting_mode);
277 drm_mode_set_crtcinfo(adjusted_mode, 0);
278 pipe_config->timings_set = true;
281 * XXX: It would be nice to support lower refresh rates on the
282 * panels to reduce power consumption, and perhaps match the
283 * user's requested refresh rate.
289 static void intel_lvds_mode_set(struct drm_encoder *encoder,
290 struct drm_display_mode *mode,
291 struct drm_display_mode *adjusted_mode)
294 * The LVDS pin pair will already have been turned on in the
295 * intel_crtc_mode_set since it has a large impact on the DPLL
301 * Detect the LVDS connection.
303 * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
304 * connected and closed means disconnected. We also send hotplug events as
305 * needed, using lid status notification from the input layer.
307 static enum drm_connector_status
308 intel_lvds_detect(struct drm_connector *connector, bool force)
310 struct drm_device *dev = connector->dev;
311 enum drm_connector_status status;
313 status = intel_panel_detect(dev);
314 if (status != connector_status_unknown)
317 return connector_status_connected;
321 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
323 static int intel_lvds_get_modes(struct drm_connector *connector)
325 struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
326 struct drm_device *dev = connector->dev;
327 struct drm_display_mode *mode;
329 /* use cached edid if we have one */
330 if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
331 return drm_add_edid_modes(connector, lvds_connector->base.edid);
333 mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
337 drm_mode_probed_add(connector, mode);
341 static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
343 DRM_INFO("Skipping forced modeset for %s\n", id->ident);
347 /* The GPU hangs up on these systems if modeset is performed on LID open */
348 static const struct dmi_system_id intel_no_modeset_on_lid[] = {
350 .callback = intel_no_modeset_on_lid_dmi_callback,
351 .ident = "Toshiba Tecra A11",
353 DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
354 DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
358 { } /* terminating entry */
362 * Lid events. Note the use of 'modeset':
363 * - we set it to MODESET_ON_LID_OPEN on lid close,
364 * and set it to MODESET_DONE on open
365 * - we use it as a "only once" bit (ie we ignore
366 * duplicate events where it was already properly set)
367 * - the suspend/resume paths will set it to
368 * MODESET_SUSPENDED and ignore the lid open event,
369 * because they restore the mode ("lid open").
371 static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
374 struct intel_lvds_connector *lvds_connector =
375 container_of(nb, struct intel_lvds_connector, lid_notifier);
376 struct drm_connector *connector = &lvds_connector->base.base;
377 struct drm_device *dev = connector->dev;
378 struct drm_i915_private *dev_priv = dev->dev_private;
380 if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
383 mutex_lock(&dev_priv->modeset_restore_lock);
384 if (dev_priv->modeset_restore == MODESET_SUSPENDED)
387 * check and update the status of LVDS connector after receiving
388 * the LID nofication event.
390 connector->status = connector->funcs->detect(connector, false);
392 /* Don't force modeset on machines where it causes a GPU lockup */
393 if (dmi_check_system(intel_no_modeset_on_lid))
395 if (!acpi_lid_open()) {
396 /* do modeset on next lid open event */
397 dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
401 if (dev_priv->modeset_restore == MODESET_DONE)
404 drm_modeset_lock_all(dev);
405 intel_modeset_setup_hw_state(dev, true);
406 drm_modeset_unlock_all(dev);
408 dev_priv->modeset_restore = MODESET_DONE;
411 mutex_unlock(&dev_priv->modeset_restore_lock);
416 * intel_lvds_destroy - unregister and free LVDS structures
417 * @connector: connector to free
419 * Unregister the DDC bus for this connector then free the driver private
422 static void intel_lvds_destroy(struct drm_connector *connector)
424 struct intel_lvds_connector *lvds_connector =
425 to_lvds_connector(connector);
427 if (lvds_connector->lid_notifier.notifier_call)
428 acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
430 if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
431 kfree(lvds_connector->base.edid);
433 intel_panel_fini(&lvds_connector->base.panel);
435 drm_sysfs_connector_remove(connector);
436 drm_connector_cleanup(connector);
440 static int intel_lvds_set_property(struct drm_connector *connector,
441 struct drm_property *property,
444 struct intel_connector *intel_connector = to_intel_connector(connector);
445 struct drm_device *dev = connector->dev;
447 if (property == dev->mode_config.scaling_mode_property) {
448 struct drm_crtc *crtc;
450 if (value == DRM_MODE_SCALE_NONE) {
451 DRM_DEBUG_KMS("no scaling not supported\n");
455 if (intel_connector->panel.fitting_mode == value) {
456 /* the LVDS scaling property is not changed */
459 intel_connector->panel.fitting_mode = value;
461 crtc = intel_attached_encoder(connector)->base.crtc;
462 if (crtc && crtc->enabled) {
464 * If the CRTC is enabled, the display will be changed
465 * according to the new panel fitting mode.
467 intel_crtc_restore_mode(crtc);
474 static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
475 .mode_set = intel_lvds_mode_set,
478 static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
479 .get_modes = intel_lvds_get_modes,
480 .mode_valid = intel_lvds_mode_valid,
481 .best_encoder = intel_best_encoder,
484 static const struct drm_connector_funcs intel_lvds_connector_funcs = {
485 .dpms = intel_connector_dpms,
486 .detect = intel_lvds_detect,
487 .fill_modes = drm_helper_probe_single_connector_modes,
488 .set_property = intel_lvds_set_property,
489 .destroy = intel_lvds_destroy,
492 static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
493 .destroy = intel_encoder_destroy,
496 static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
498 DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
502 /* These systems claim to have LVDS, but really don't */
503 static const struct dmi_system_id intel_no_lvds[] = {
505 .callback = intel_no_lvds_dmi_callback,
506 .ident = "Apple Mac Mini (Core series)",
508 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
509 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
513 .callback = intel_no_lvds_dmi_callback,
514 .ident = "Apple Mac Mini (Core 2 series)",
516 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
517 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
521 .callback = intel_no_lvds_dmi_callback,
522 .ident = "MSI IM-945GSE-A",
524 DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
525 DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
529 .callback = intel_no_lvds_dmi_callback,
530 .ident = "Dell Studio Hybrid",
532 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
533 DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
537 .callback = intel_no_lvds_dmi_callback,
538 .ident = "Dell OptiPlex FX170",
540 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
541 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
545 .callback = intel_no_lvds_dmi_callback,
546 .ident = "AOpen Mini PC",
548 DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
549 DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
553 .callback = intel_no_lvds_dmi_callback,
554 .ident = "AOpen Mini PC MP915",
556 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
557 DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
561 .callback = intel_no_lvds_dmi_callback,
562 .ident = "AOpen i915GMm-HFS",
564 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
565 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
569 .callback = intel_no_lvds_dmi_callback,
570 .ident = "AOpen i45GMx-I",
572 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
573 DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
577 .callback = intel_no_lvds_dmi_callback,
578 .ident = "Aopen i945GTt-VFA",
580 DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
584 .callback = intel_no_lvds_dmi_callback,
585 .ident = "Clientron U800",
587 DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
588 DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
592 .callback = intel_no_lvds_dmi_callback,
593 .ident = "Clientron E830",
595 DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
596 DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
600 .callback = intel_no_lvds_dmi_callback,
601 .ident = "Asus EeeBox PC EB1007",
603 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
604 DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
608 .callback = intel_no_lvds_dmi_callback,
609 .ident = "Asus AT5NM10T-I",
611 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
612 DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
616 .callback = intel_no_lvds_dmi_callback,
617 .ident = "Hewlett-Packard HP t5740e Thin Client",
619 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
620 DMI_MATCH(DMI_PRODUCT_NAME, "HP t5740e Thin Client"),
624 .callback = intel_no_lvds_dmi_callback,
625 .ident = "Hewlett-Packard t5745",
627 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
628 DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
632 .callback = intel_no_lvds_dmi_callback,
633 .ident = "Hewlett-Packard st5747",
635 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
636 DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
640 .callback = intel_no_lvds_dmi_callback,
641 .ident = "MSI Wind Box DC500",
643 DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
644 DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
648 .callback = intel_no_lvds_dmi_callback,
649 .ident = "Gigabyte GA-D525TUD",
651 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
652 DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
656 .callback = intel_no_lvds_dmi_callback,
657 .ident = "Supermicro X7SPA-H",
659 DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
660 DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
664 .callback = intel_no_lvds_dmi_callback,
665 .ident = "Fujitsu Esprimo Q900",
667 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
668 DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
672 { } /* terminating entry */
676 * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
678 * @connector: LVDS connector
680 * Find the reduced downclock for LVDS in EDID.
682 static void intel_find_lvds_downclock(struct drm_device *dev,
683 struct drm_display_mode *fixed_mode,
684 struct drm_connector *connector)
686 struct drm_i915_private *dev_priv = dev->dev_private;
687 struct drm_display_mode *scan;
690 temp_downclock = fixed_mode->clock;
691 list_for_each_entry(scan, &connector->probed_modes, head) {
693 * If one mode has the same resolution with the fixed_panel
694 * mode while they have the different refresh rate, it means
695 * that the reduced downclock is found for the LVDS. In such
696 * case we can set the different FPx0/1 to dynamically select
697 * between low and high frequency.
699 if (scan->hdisplay == fixed_mode->hdisplay &&
700 scan->hsync_start == fixed_mode->hsync_start &&
701 scan->hsync_end == fixed_mode->hsync_end &&
702 scan->htotal == fixed_mode->htotal &&
703 scan->vdisplay == fixed_mode->vdisplay &&
704 scan->vsync_start == fixed_mode->vsync_start &&
705 scan->vsync_end == fixed_mode->vsync_end &&
706 scan->vtotal == fixed_mode->vtotal) {
707 if (scan->clock < temp_downclock) {
709 * The downclock is already found. But we
710 * expect to find the lower downclock.
712 temp_downclock = scan->clock;
716 if (temp_downclock < fixed_mode->clock && i915_lvds_downclock) {
717 /* We found the downclock for LVDS. */
718 dev_priv->lvds_downclock_avail = 1;
719 dev_priv->lvds_downclock = temp_downclock;
720 DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
721 "Normal clock %dKhz, downclock %dKhz\n",
722 fixed_mode->clock, temp_downclock);
727 * Enumerate the child dev array parsed from VBT to check whether
728 * the LVDS is present.
729 * If it is present, return 1.
730 * If it is not present, return false.
731 * If no child dev is parsed from VBT, it assumes that the LVDS is present.
733 static bool lvds_is_present_in_vbt(struct drm_device *dev,
736 struct drm_i915_private *dev_priv = dev->dev_private;
739 if (!dev_priv->vbt.child_dev_num)
742 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
743 struct child_device_config *child = dev_priv->vbt.child_dev + i;
745 /* If the device type is not LFP, continue.
746 * We have to check both the new identifiers as well as the
747 * old for compatibility with some BIOSes.
749 if (child->device_type != DEVICE_TYPE_INT_LFP &&
750 child->device_type != DEVICE_TYPE_LFP)
753 if (intel_gmbus_is_port_valid(child->i2c_pin))
754 *i2c_pin = child->i2c_pin;
756 /* However, we cannot trust the BIOS writers to populate
757 * the VBT correctly. Since LVDS requires additional
758 * information from AIM blocks, a non-zero addin offset is
759 * a good indicator that the LVDS is actually present.
761 if (child->addin_offset)
764 /* But even then some BIOS writers perform some black magic
765 * and instantiate the device without reference to any
766 * additional data. Trust that if the VBT was written into
767 * the OpRegion then they have validated the LVDS's existence.
769 if (dev_priv->opregion.vbt)
776 static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
778 DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
782 static const struct dmi_system_id intel_dual_link_lvds[] = {
784 .callback = intel_dual_link_lvds_callback,
785 .ident = "Apple MacBook Pro (Core i5/i7 Series)",
787 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
788 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
791 { } /* terminating entry */
794 bool intel_is_dual_link_lvds(struct drm_device *dev)
796 struct intel_encoder *encoder;
797 struct intel_lvds_encoder *lvds_encoder;
799 list_for_each_entry(encoder, &dev->mode_config.encoder_list,
801 if (encoder->type == INTEL_OUTPUT_LVDS) {
802 lvds_encoder = to_lvds_encoder(&encoder->base);
804 return lvds_encoder->is_dual_link;
811 static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
813 struct drm_device *dev = lvds_encoder->base.base.dev;
815 struct drm_i915_private *dev_priv = dev->dev_private;
817 /* use the module option value if specified */
818 if (i915_lvds_channel_mode > 0)
819 return i915_lvds_channel_mode == 2;
821 if (dmi_check_system(intel_dual_link_lvds))
824 /* BIOS should set the proper LVDS register value at boot, but
825 * in reality, it doesn't set the value when the lid is closed;
826 * we need to check "the value to be set" in VBT when LVDS
827 * register is uninitialized.
829 val = I915_READ(lvds_encoder->reg);
830 if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
831 val = dev_priv->vbt.bios_lvds_val;
833 return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
836 static bool intel_lvds_supported(struct drm_device *dev)
838 /* With the introduction of the PCH we gained a dedicated
839 * LVDS presence pin, use it. */
840 if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
843 /* Otherwise LVDS was only attached to mobile products,
844 * except for the inglorious 830gm */
845 if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
852 * intel_lvds_init - setup LVDS connectors on this device
855 * Create the connector, register the LVDS DDC bus, and try to figure out what
856 * modes we can display on the LVDS panel (if present).
858 bool intel_lvds_init(struct drm_device *dev)
860 struct drm_i915_private *dev_priv = dev->dev_private;
861 struct intel_lvds_encoder *lvds_encoder;
862 struct intel_encoder *intel_encoder;
863 struct intel_lvds_connector *lvds_connector;
864 struct intel_connector *intel_connector;
865 struct drm_connector *connector;
866 struct drm_encoder *encoder;
867 struct drm_display_mode *scan; /* *modes, *bios_mode; */
868 struct drm_display_mode *fixed_mode = NULL;
870 struct drm_crtc *crtc;
875 if (!intel_lvds_supported(dev))
878 /* Skip init on machines we know falsely report LVDS */
879 if (dmi_check_system(intel_no_lvds))
882 pin = GMBUS_PORT_PANEL;
883 if (!lvds_is_present_in_vbt(dev, &pin)) {
884 DRM_DEBUG_KMS("LVDS is not present in VBT\n");
888 if (HAS_PCH_SPLIT(dev)) {
889 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
891 if (dev_priv->vbt.edp_support) {
892 DRM_DEBUG_KMS("disable LVDS for eDP support\n");
897 lvds_encoder = kzalloc(sizeof(struct intel_lvds_encoder), GFP_KERNEL);
901 lvds_connector = kzalloc(sizeof(struct intel_lvds_connector), GFP_KERNEL);
902 if (!lvds_connector) {
907 lvds_encoder->attached_connector = lvds_connector;
909 intel_encoder = &lvds_encoder->base;
910 encoder = &intel_encoder->base;
911 intel_connector = &lvds_connector->base;
912 connector = &intel_connector->base;
913 drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
914 DRM_MODE_CONNECTOR_LVDS);
916 drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
917 DRM_MODE_ENCODER_LVDS);
919 intel_encoder->enable = intel_enable_lvds;
920 intel_encoder->pre_pll_enable = intel_pre_pll_enable_lvds;
921 intel_encoder->compute_config = intel_lvds_compute_config;
922 intel_encoder->disable = intel_disable_lvds;
923 intel_encoder->get_hw_state = intel_lvds_get_hw_state;
924 intel_connector->get_hw_state = intel_connector_get_hw_state;
926 intel_connector_attach_encoder(intel_connector, intel_encoder);
927 intel_encoder->type = INTEL_OUTPUT_LVDS;
929 intel_encoder->cloneable = false;
930 if (HAS_PCH_SPLIT(dev))
931 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
932 else if (IS_GEN4(dev))
933 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
935 intel_encoder->crtc_mask = (1 << 1);
937 drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
938 drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
939 connector->display_info.subpixel_order = SubPixelHorizontalRGB;
940 connector->interlace_allowed = false;
941 connector->doublescan_allowed = false;
943 if (HAS_PCH_SPLIT(dev)) {
944 lvds_encoder->reg = PCH_LVDS;
946 lvds_encoder->reg = LVDS;
949 /* create the scaling mode property */
950 drm_mode_create_scaling_mode_property(dev);
951 drm_object_attach_property(&connector->base,
952 dev->mode_config.scaling_mode_property,
953 DRM_MODE_SCALE_ASPECT);
954 intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
957 * 1) check for EDID on DDC
958 * 2) check for VBT data
959 * 3) check to see if LVDS is already on
960 * if none of the above, no panel
961 * 4) make sure lid is open
962 * if closed, act like it's not there for now
966 * Attempt to get the fixed panel mode from DDC. Assume that the
967 * preferred mode is the right one.
969 edid = drm_get_edid(connector, intel_gmbus_get_adapter(dev_priv, pin));
971 if (drm_add_edid_modes(connector, edid)) {
972 drm_mode_connector_update_edid_property(connector,
976 edid = ERR_PTR(-EINVAL);
979 edid = ERR_PTR(-ENOENT);
981 lvds_connector->base.edid = edid;
983 if (IS_ERR_OR_NULL(edid)) {
984 /* Didn't get an EDID, so
985 * Set wide sync ranges so we get all modes
986 * handed to valid_mode for checking
988 connector->display_info.min_vfreq = 0;
989 connector->display_info.max_vfreq = 200;
990 connector->display_info.min_hfreq = 0;
991 connector->display_info.max_hfreq = 200;
994 list_for_each_entry(scan, &connector->probed_modes, head) {
995 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
996 DRM_DEBUG_KMS("using preferred mode from EDID: ");
997 drm_mode_debug_printmodeline(scan);
999 fixed_mode = drm_mode_duplicate(dev, scan);
1001 intel_find_lvds_downclock(dev, fixed_mode,
1008 /* Failed to get EDID, what about VBT? */
1009 if (dev_priv->vbt.lfp_lvds_vbt_mode) {
1010 DRM_DEBUG_KMS("using mode from VBT: ");
1011 drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
1013 fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
1015 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1021 * If we didn't get EDID, try checking if the panel is already turned
1022 * on. If so, assume that whatever is currently programmed is the
1026 /* Ironlake: FIXME if still fail, not try pipe mode now */
1027 if (HAS_PCH_SPLIT(dev))
1030 lvds = I915_READ(LVDS);
1031 pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
1032 crtc = intel_get_crtc_for_pipe(dev, pipe);
1034 if (crtc && (lvds & LVDS_PORT_EN)) {
1035 fixed_mode = intel_crtc_mode_get(dev, crtc);
1037 DRM_DEBUG_KMS("using current (BIOS) mode: ");
1038 drm_mode_debug_printmodeline(fixed_mode);
1039 fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1044 /* If we still don't have a mode after all that, give up. */
1049 lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
1050 DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
1051 lvds_encoder->is_dual_link ? "dual" : "single");
1054 * Unlock registers and just
1055 * leave them unlocked
1057 if (HAS_PCH_SPLIT(dev)) {
1058 I915_WRITE(PCH_PP_CONTROL,
1059 I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
1061 I915_WRITE(PP_CONTROL,
1062 I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
1064 lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
1065 if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
1066 DRM_DEBUG_KMS("lid notifier registration failed\n");
1067 lvds_connector->lid_notifier.notifier_call = NULL;
1069 drm_sysfs_connector_add(connector);
1071 intel_panel_init(&intel_connector->panel, fixed_mode);
1072 intel_panel_setup_backlight(connector);
1077 DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
1078 drm_connector_cleanup(connector);
1079 drm_encoder_cleanup(encoder);
1081 drm_mode_destroy(dev, fixed_mode);
1082 kfree(lvds_encoder);
1083 kfree(lvds_connector);