2 * Copyright © 2006-2007 Intel Corporation
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.
30 #include <acpi/button.h>
31 #include <linux/acpi.h>
32 #include <linux/dmi.h>
33 #include <linux/i2c.h>
34 #include <linux/slab.h>
35 #include <linux/vga_switcheroo.h>
37 #include <drm/drm_atomic_helper.h>
38 #include <drm/drm_crtc.h>
39 #include <drm/drm_edid.h>
40 #include <drm/drm_probe_helper.h>
44 #include "intel_atomic.h"
45 #include "intel_backlight.h"
46 #include "intel_connector.h"
48 #include "intel_display_types.h"
49 #include "intel_dpll.h"
50 #include "intel_fdi.h"
51 #include "intel_gmbus.h"
52 #include "intel_lvds.h"
53 #include "intel_lvds_regs.h"
54 #include "intel_panel.h"
55 #include "intel_pfit.h"
56 #include "intel_pps_regs.h"
58 /* Private structure for the integrated LVDS support */
59 struct intel_lvds_pps {
60 struct intel_pps_delays delays;
65 bool powerdown_on_reset;
68 struct intel_lvds_encoder {
69 struct intel_encoder base;
75 struct intel_lvds_pps init_pps;
78 struct intel_connector *attached_connector;
81 static struct intel_lvds_encoder *to_lvds_encoder(struct intel_encoder *encoder)
83 return container_of(encoder, struct intel_lvds_encoder, base);
86 bool intel_lvds_port_enabled(struct drm_i915_private *i915,
87 i915_reg_t lvds_reg, enum pipe *pipe)
91 val = intel_de_read(i915, lvds_reg);
93 /* asserts want to know the pipe even if the port is disabled */
94 if (HAS_PCH_CPT(i915))
95 *pipe = REG_FIELD_GET(LVDS_PIPE_SEL_MASK_CPT, val);
97 *pipe = REG_FIELD_GET(LVDS_PIPE_SEL_MASK, val);
99 return val & LVDS_PORT_EN;
102 static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
105 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
106 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(encoder);
107 intel_wakeref_t wakeref;
110 wakeref = intel_display_power_get_if_enabled(i915, encoder->power_domain);
114 ret = intel_lvds_port_enabled(i915, lvds_encoder->reg, pipe);
116 intel_display_power_put(i915, encoder->power_domain, wakeref);
121 static void intel_lvds_get_config(struct intel_encoder *encoder,
122 struct intel_crtc_state *crtc_state)
124 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
125 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(encoder);
128 crtc_state->output_types |= BIT(INTEL_OUTPUT_LVDS);
130 tmp = intel_de_read(dev_priv, lvds_encoder->reg);
131 if (tmp & LVDS_HSYNC_POLARITY)
132 flags |= DRM_MODE_FLAG_NHSYNC;
134 flags |= DRM_MODE_FLAG_PHSYNC;
135 if (tmp & LVDS_VSYNC_POLARITY)
136 flags |= DRM_MODE_FLAG_NVSYNC;
138 flags |= DRM_MODE_FLAG_PVSYNC;
140 crtc_state->hw.adjusted_mode.flags |= flags;
142 if (DISPLAY_VER(dev_priv) < 5)
143 crtc_state->gmch_pfit.lvds_border_bits =
144 tmp & LVDS_BORDER_ENABLE;
146 /* gen2/3 store dither state in pfit control, needs to match */
147 if (DISPLAY_VER(dev_priv) < 4) {
148 tmp = intel_de_read(dev_priv, PFIT_CONTROL(dev_priv));
150 crtc_state->gmch_pfit.control |= tmp & PFIT_PANEL_8TO6_DITHER_ENABLE;
153 crtc_state->hw.adjusted_mode.crtc_clock = crtc_state->port_clock;
156 static void intel_lvds_pps_get_hw_state(struct drm_i915_private *dev_priv,
157 struct intel_lvds_pps *pps)
161 pps->powerdown_on_reset = intel_de_read(dev_priv,
162 PP_CONTROL(dev_priv, 0)) & PANEL_POWER_RESET;
164 val = intel_de_read(dev_priv, PP_ON_DELAYS(dev_priv, 0));
165 pps->port = REG_FIELD_GET(PANEL_PORT_SELECT_MASK, val);
166 pps->delays.power_up = REG_FIELD_GET(PANEL_POWER_UP_DELAY_MASK, val);
167 pps->delays.backlight_on = REG_FIELD_GET(PANEL_LIGHT_ON_DELAY_MASK, val);
169 val = intel_de_read(dev_priv, PP_OFF_DELAYS(dev_priv, 0));
170 pps->delays.power_down = REG_FIELD_GET(PANEL_POWER_DOWN_DELAY_MASK, val);
171 pps->delays.backlight_off = REG_FIELD_GET(PANEL_LIGHT_OFF_DELAY_MASK, val);
173 val = intel_de_read(dev_priv, PP_DIVISOR(dev_priv, 0));
174 pps->divider = REG_FIELD_GET(PP_REFERENCE_DIVIDER_MASK, val);
175 val = REG_FIELD_GET(PANEL_POWER_CYCLE_DELAY_MASK, val);
177 * Remove the BSpec specified +1 (100ms) offset that accounts for a
178 * too short power-cycle delay due to the asynchronous programming of
183 /* Convert from 100ms to 100us units */
184 pps->delays.power_cycle = val * 1000;
186 if (DISPLAY_VER(dev_priv) < 5 &&
187 pps->delays.power_up == 0 &&
188 pps->delays.backlight_on == 0 &&
189 pps->delays.power_down == 0 &&
190 pps->delays.backlight_off == 0) {
191 drm_dbg_kms(&dev_priv->drm,
192 "Panel power timings uninitialized, "
193 "setting defaults\n");
194 /* Set T2 to 40ms and T5 to 200ms in 100 usec units */
195 pps->delays.power_up = 40 * 10;
196 pps->delays.backlight_on = 200 * 10;
197 /* Set T3 to 35ms and Tx to 200ms in 100 usec units */
198 pps->delays.power_down = 35 * 10;
199 pps->delays.backlight_off = 200 * 10;
202 drm_dbg(&dev_priv->drm, "LVDS PPS:power_up %d power_down %d power_cycle %d backlight_on %d backlight_off %d "
203 "divider %d port %d powerdown_on_reset %d\n",
204 pps->delays.power_up, pps->delays.power_down,
205 pps->delays.power_cycle, pps->delays.backlight_on,
206 pps->delays.backlight_off, pps->divider,
207 pps->port, pps->powerdown_on_reset);
210 static void intel_lvds_pps_init_hw(struct drm_i915_private *dev_priv,
211 struct intel_lvds_pps *pps)
215 val = intel_de_read(dev_priv, PP_CONTROL(dev_priv, 0));
216 drm_WARN_ON(&dev_priv->drm,
217 (val & PANEL_UNLOCK_MASK) != PANEL_UNLOCK_REGS);
218 if (pps->powerdown_on_reset)
219 val |= PANEL_POWER_RESET;
220 intel_de_write(dev_priv, PP_CONTROL(dev_priv, 0), val);
222 intel_de_write(dev_priv, PP_ON_DELAYS(dev_priv, 0),
223 REG_FIELD_PREP(PANEL_PORT_SELECT_MASK, pps->port) |
224 REG_FIELD_PREP(PANEL_POWER_UP_DELAY_MASK, pps->delays.power_up) |
225 REG_FIELD_PREP(PANEL_LIGHT_ON_DELAY_MASK, pps->delays.backlight_on));
227 intel_de_write(dev_priv, PP_OFF_DELAYS(dev_priv, 0),
228 REG_FIELD_PREP(PANEL_POWER_DOWN_DELAY_MASK, pps->delays.power_down) |
229 REG_FIELD_PREP(PANEL_LIGHT_OFF_DELAY_MASK, pps->delays.backlight_off));
231 intel_de_write(dev_priv, PP_DIVISOR(dev_priv, 0),
232 REG_FIELD_PREP(PP_REFERENCE_DIVIDER_MASK, pps->divider) |
233 REG_FIELD_PREP(PANEL_POWER_CYCLE_DELAY_MASK,
234 DIV_ROUND_UP(pps->delays.power_cycle, 1000) + 1));
237 static void intel_pre_enable_lvds(struct intel_atomic_state *state,
238 struct intel_encoder *encoder,
239 const struct intel_crtc_state *crtc_state,
240 const struct drm_connector_state *conn_state)
242 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(encoder);
243 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
244 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
245 const struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
246 enum pipe pipe = crtc->pipe;
249 if (HAS_PCH_SPLIT(i915)) {
250 assert_fdi_rx_pll_disabled(i915, pipe);
251 assert_shared_dpll_disabled(i915, crtc_state->shared_dpll);
253 assert_pll_disabled(i915, pipe);
256 intel_lvds_pps_init_hw(i915, &lvds_encoder->init_pps);
258 temp = lvds_encoder->init_lvds_val;
259 temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
261 if (HAS_PCH_CPT(i915)) {
262 temp &= ~LVDS_PIPE_SEL_MASK_CPT;
263 temp |= LVDS_PIPE_SEL_CPT(pipe);
265 temp &= ~LVDS_PIPE_SEL_MASK;
266 temp |= LVDS_PIPE_SEL(pipe);
269 /* set the corresponding LVDS_BORDER bit */
270 temp &= ~LVDS_BORDER_ENABLE;
271 temp |= crtc_state->gmch_pfit.lvds_border_bits;
274 * Set the B0-B3 data pairs corresponding to whether we're going to
275 * set the DPLLs for dual-channel mode or not.
277 if (lvds_encoder->is_dual_link)
278 temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
280 temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
283 * It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
284 * appropriately here, but we need to look more thoroughly into how
285 * panels behave in the two modes. For now, let's just maintain the
286 * value we got from the BIOS.
288 temp &= ~LVDS_A3_POWER_MASK;
289 temp |= lvds_encoder->a3_power;
292 * Set the dithering flag on LVDS as needed, note that there is no
293 * special lvds dither control bit on pch-split platforms, dithering is
294 * only controlled through the TRANSCONF reg.
296 if (DISPLAY_VER(i915) == 4) {
298 * Bspec wording suggests that LVDS port dithering only exists
301 if (crtc_state->dither && crtc_state->pipe_bpp == 18)
302 temp |= LVDS_ENABLE_DITHER;
304 temp &= ~LVDS_ENABLE_DITHER;
306 temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
307 if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
308 temp |= LVDS_HSYNC_POLARITY;
309 if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
310 temp |= LVDS_VSYNC_POLARITY;
312 intel_de_write(i915, lvds_encoder->reg, temp);
316 * Sets the power state for the panel.
318 static void intel_enable_lvds(struct intel_atomic_state *state,
319 struct intel_encoder *encoder,
320 const struct intel_crtc_state *crtc_state,
321 const struct drm_connector_state *conn_state)
323 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(encoder);
324 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
326 intel_de_rmw(dev_priv, lvds_encoder->reg, 0, LVDS_PORT_EN);
328 intel_de_rmw(dev_priv, PP_CONTROL(dev_priv, 0), 0, PANEL_POWER_ON);
329 intel_de_posting_read(dev_priv, lvds_encoder->reg);
331 if (intel_de_wait_for_set(dev_priv, PP_STATUS(dev_priv, 0), PP_ON, 5000))
332 drm_err(&dev_priv->drm,
333 "timed out waiting for panel to power on\n");
335 intel_backlight_enable(crtc_state, conn_state);
338 static void intel_disable_lvds(struct intel_atomic_state *state,
339 struct intel_encoder *encoder,
340 const struct intel_crtc_state *old_crtc_state,
341 const struct drm_connector_state *old_conn_state)
343 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(encoder);
344 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
346 intel_de_rmw(dev_priv, PP_CONTROL(dev_priv, 0), PANEL_POWER_ON, 0);
347 if (intel_de_wait_for_clear(dev_priv, PP_STATUS(dev_priv, 0), PP_ON, 1000))
348 drm_err(&dev_priv->drm,
349 "timed out waiting for panel to power off\n");
351 intel_de_rmw(dev_priv, lvds_encoder->reg, LVDS_PORT_EN, 0);
352 intel_de_posting_read(dev_priv, lvds_encoder->reg);
355 static void gmch_disable_lvds(struct intel_atomic_state *state,
356 struct intel_encoder *encoder,
357 const struct intel_crtc_state *old_crtc_state,
358 const struct drm_connector_state *old_conn_state)
361 intel_backlight_disable(old_conn_state);
363 intel_disable_lvds(state, encoder, old_crtc_state, old_conn_state);
366 static void pch_disable_lvds(struct intel_atomic_state *state,
367 struct intel_encoder *encoder,
368 const struct intel_crtc_state *old_crtc_state,
369 const struct drm_connector_state *old_conn_state)
371 intel_backlight_disable(old_conn_state);
374 static void pch_post_disable_lvds(struct intel_atomic_state *state,
375 struct intel_encoder *encoder,
376 const struct intel_crtc_state *old_crtc_state,
377 const struct drm_connector_state *old_conn_state)
379 intel_disable_lvds(state, encoder, old_crtc_state, old_conn_state);
382 static void intel_lvds_shutdown(struct intel_encoder *encoder)
384 struct drm_i915_private *dev_priv = to_i915(encoder->base.dev);
386 if (intel_de_wait_for_clear(dev_priv, PP_STATUS(dev_priv, 0), PP_CYCLE_DELAY_ACTIVE, 5000))
387 drm_err(&dev_priv->drm,
388 "timed out waiting for panel power cycle delay\n");
391 static enum drm_mode_status
392 intel_lvds_mode_valid(struct drm_connector *_connector,
393 struct drm_display_mode *mode)
395 struct intel_connector *connector = to_intel_connector(_connector);
396 struct drm_i915_private *i915 = to_i915(connector->base.dev);
397 const struct drm_display_mode *fixed_mode =
398 intel_panel_fixed_mode(connector, mode);
399 int max_pixclk = to_i915(connector->base.dev)->display.cdclk.max_dotclk_freq;
400 enum drm_mode_status status;
402 status = intel_cpu_transcoder_mode_valid(i915, mode);
403 if (status != MODE_OK)
406 status = intel_panel_mode_valid(connector, mode);
407 if (status != MODE_OK)
410 if (fixed_mode->clock > max_pixclk)
411 return MODE_CLOCK_HIGH;
416 static int intel_lvds_compute_config(struct intel_encoder *encoder,
417 struct intel_crtc_state *crtc_state,
418 struct drm_connector_state *conn_state)
420 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
421 struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(encoder);
422 struct intel_connector *connector = lvds_encoder->attached_connector;
423 struct drm_display_mode *adjusted_mode = &crtc_state->hw.adjusted_mode;
424 struct intel_crtc *crtc = to_intel_crtc(crtc_state->uapi.crtc);
425 unsigned int lvds_bpp;
428 /* Should never happen!! */
429 if (DISPLAY_VER(i915) < 4 && crtc->pipe == 0) {
430 drm_err(&i915->drm, "Can't support LVDS on pipe A\n");
434 if (HAS_PCH_SPLIT(i915)) {
435 crtc_state->has_pch_encoder = true;
436 if (!intel_fdi_compute_pipe_bpp(crtc_state))
440 if (lvds_encoder->a3_power == LVDS_A3_POWER_UP)
445 /* TODO: Check crtc_state->max_link_bpp_x16 instead of bw_constrained */
446 if (lvds_bpp != crtc_state->pipe_bpp && !crtc_state->bw_constrained) {
447 drm_dbg_kms(&i915->drm,
448 "forcing display bpp (was %d) to LVDS (%d)\n",
449 crtc_state->pipe_bpp, lvds_bpp);
450 crtc_state->pipe_bpp = lvds_bpp;
453 crtc_state->sink_format = INTEL_OUTPUT_FORMAT_RGB;
454 crtc_state->output_format = INTEL_OUTPUT_FORMAT_RGB;
457 * We have timings from the BIOS for the panel, put them in
458 * to the adjusted mode. The CRTC will be set up for this mode,
459 * with the panel scaling set up to source from the H/VDisplay
460 * of the original mode.
462 ret = intel_panel_compute_config(connector, adjusted_mode);
466 if (adjusted_mode->flags & DRM_MODE_FLAG_DBLSCAN)
469 ret = intel_panel_fitting(crtc_state, conn_state);
474 * XXX: It would be nice to support lower refresh rates on the
475 * panels to reduce power consumption, and perhaps match the
476 * user's requested refresh rate.
483 * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
485 static int intel_lvds_get_modes(struct drm_connector *_connector)
487 struct intel_connector *connector = to_intel_connector(_connector);
488 const struct drm_edid *fixed_edid = connector->panel.fixed_edid;
490 /* Use panel fixed edid if we have one */
491 if (!IS_ERR_OR_NULL(fixed_edid)) {
492 drm_edid_connector_update(&connector->base, fixed_edid);
494 return drm_edid_connector_add_modes(&connector->base);
497 return intel_panel_get_modes(connector);
500 static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
501 .get_modes = intel_lvds_get_modes,
502 .mode_valid = intel_lvds_mode_valid,
503 .atomic_check = intel_digital_connector_atomic_check,
506 static const struct drm_connector_funcs intel_lvds_connector_funcs = {
507 .detect = intel_panel_detect,
508 .fill_modes = drm_helper_probe_single_connector_modes,
509 .atomic_get_property = intel_digital_connector_atomic_get_property,
510 .atomic_set_property = intel_digital_connector_atomic_set_property,
511 .late_register = intel_connector_register,
512 .early_unregister = intel_connector_unregister,
513 .destroy = intel_connector_destroy,
514 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
515 .atomic_duplicate_state = intel_digital_connector_duplicate_state,
518 static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
519 .destroy = intel_encoder_destroy,
522 static int intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
524 DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
528 /* These systems claim to have LVDS, but really don't */
529 static const struct dmi_system_id intel_no_lvds[] = {
531 .callback = intel_no_lvds_dmi_callback,
532 .ident = "Apple Mac Mini (Core series)",
534 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
535 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
539 .callback = intel_no_lvds_dmi_callback,
540 .ident = "Apple Mac Mini (Core 2 series)",
542 DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
543 DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
547 .callback = intel_no_lvds_dmi_callback,
548 .ident = "MSI IM-945GSE-A",
550 DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
551 DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
555 .callback = intel_no_lvds_dmi_callback,
556 .ident = "Dell Studio Hybrid",
558 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
559 DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
563 .callback = intel_no_lvds_dmi_callback,
564 .ident = "Dell OptiPlex FX170",
566 DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
567 DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
571 .callback = intel_no_lvds_dmi_callback,
572 .ident = "AOpen Mini PC",
574 DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
575 DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
579 .callback = intel_no_lvds_dmi_callback,
580 .ident = "AOpen Mini PC MP915",
582 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
583 DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
587 .callback = intel_no_lvds_dmi_callback,
588 .ident = "AOpen i915GMm-HFS",
590 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
591 DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
595 .callback = intel_no_lvds_dmi_callback,
596 .ident = "AOpen i45GMx-I",
598 DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
599 DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
603 .callback = intel_no_lvds_dmi_callback,
604 .ident = "Aopen i945GTt-VFA",
606 DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
610 .callback = intel_no_lvds_dmi_callback,
611 .ident = "Clientron U800",
613 DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
614 DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
618 .callback = intel_no_lvds_dmi_callback,
619 .ident = "Clientron E830",
621 DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
622 DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
626 .callback = intel_no_lvds_dmi_callback,
627 .ident = "Asus EeeBox PC EB1007",
629 DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
630 DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
634 .callback = intel_no_lvds_dmi_callback,
635 .ident = "Asus AT5NM10T-I",
637 DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
638 DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
642 .callback = intel_no_lvds_dmi_callback,
643 .ident = "Hewlett-Packard HP t5740",
645 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
646 DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
650 .callback = intel_no_lvds_dmi_callback,
651 .ident = "Hewlett-Packard t5745",
653 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
654 DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
658 .callback = intel_no_lvds_dmi_callback,
659 .ident = "Hewlett-Packard st5747",
661 DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
662 DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
666 .callback = intel_no_lvds_dmi_callback,
667 .ident = "MSI Wind Box DC500",
669 DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
670 DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
674 .callback = intel_no_lvds_dmi_callback,
675 .ident = "Gigabyte GA-D525TUD",
677 DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
678 DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
682 .callback = intel_no_lvds_dmi_callback,
683 .ident = "Supermicro X7SPA-H",
685 DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
686 DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
690 .callback = intel_no_lvds_dmi_callback,
691 .ident = "Fujitsu Esprimo Q900",
693 DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
694 DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
698 .callback = intel_no_lvds_dmi_callback,
699 .ident = "Intel D410PT",
701 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
702 DMI_MATCH(DMI_BOARD_NAME, "D410PT"),
706 .callback = intel_no_lvds_dmi_callback,
707 .ident = "Intel D425KT",
709 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
710 DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"),
714 .callback = intel_no_lvds_dmi_callback,
715 .ident = "Intel D510MO",
717 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
718 DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
722 .callback = intel_no_lvds_dmi_callback,
723 .ident = "Intel D525MW",
725 DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
726 DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
730 .callback = intel_no_lvds_dmi_callback,
731 .ident = "Radiant P845",
733 DMI_MATCH(DMI_SYS_VENDOR, "Radiant Systems Inc"),
734 DMI_MATCH(DMI_PRODUCT_NAME, "P845"),
738 { } /* terminating entry */
741 static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
743 DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
747 static const struct dmi_system_id intel_dual_link_lvds[] = {
749 .callback = intel_dual_link_lvds_callback,
750 .ident = "Apple MacBook Pro 15\" (2010)",
752 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
753 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6,2"),
757 .callback = intel_dual_link_lvds_callback,
758 .ident = "Apple MacBook Pro 15\" (2011)",
760 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
761 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
765 .callback = intel_dual_link_lvds_callback,
766 .ident = "Apple MacBook Pro 15\" (2012)",
768 DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
769 DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,1"),
772 { } /* terminating entry */
775 struct intel_encoder *intel_get_lvds_encoder(struct drm_i915_private *i915)
777 struct intel_encoder *encoder;
779 for_each_intel_encoder(&i915->drm, encoder) {
780 if (encoder->type == INTEL_OUTPUT_LVDS)
787 bool intel_is_dual_link_lvds(struct drm_i915_private *i915)
789 struct intel_encoder *encoder = intel_get_lvds_encoder(i915);
791 return encoder && to_lvds_encoder(encoder)->is_dual_link;
794 static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
796 struct drm_i915_private *i915 = to_i915(lvds_encoder->base.base.dev);
797 struct intel_connector *connector = lvds_encoder->attached_connector;
798 const struct drm_display_mode *fixed_mode =
799 intel_panel_preferred_fixed_mode(connector);
802 /* use the module option value if specified */
803 if (i915->display.params.lvds_channel_mode > 0)
804 return i915->display.params.lvds_channel_mode == 2;
806 /* single channel LVDS is limited to 112 MHz */
807 if (fixed_mode->clock > 112999)
810 if (dmi_check_system(intel_dual_link_lvds))
814 * BIOS should set the proper LVDS register value at boot, but
815 * in reality, it doesn't set the value when the lid is closed;
816 * we need to check "the value to be set" in VBT when LVDS
817 * register is uninitialized.
819 val = intel_de_read(i915, lvds_encoder->reg);
820 if (HAS_PCH_CPT(i915))
821 val &= ~(LVDS_DETECTED | LVDS_PIPE_SEL_MASK_CPT);
823 val &= ~(LVDS_DETECTED | LVDS_PIPE_SEL_MASK);
825 val = connector->panel.vbt.bios_lvds_val;
827 return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
830 static void intel_lvds_add_properties(struct drm_connector *connector)
832 intel_attach_scaling_mode_property(connector);
836 * intel_lvds_init - setup LVDS connectors on this device
839 * Create the connector, register the LVDS DDC bus, and try to figure out what
840 * modes we can display on the LVDS panel (if present).
842 void intel_lvds_init(struct drm_i915_private *i915)
844 struct intel_display *display = &i915->display;
845 struct intel_lvds_encoder *lvds_encoder;
846 struct intel_connector *connector;
847 const struct drm_edid *drm_edid;
848 struct intel_encoder *encoder;
853 /* Skip init on machines we know falsely report LVDS */
854 if (dmi_check_system(intel_no_lvds)) {
855 drm_WARN(&i915->drm, !i915->display.vbt.int_lvds_support,
856 "Useless DMI match. Internal LVDS support disabled by VBT\n");
860 if (!i915->display.vbt.int_lvds_support) {
861 drm_dbg_kms(&i915->drm,
862 "Internal LVDS support disabled by VBT\n");
866 if (HAS_PCH_SPLIT(i915))
871 lvds = intel_de_read(i915, lvds_reg);
873 if (HAS_PCH_SPLIT(i915)) {
874 if ((lvds & LVDS_DETECTED) == 0)
878 ddc_pin = GMBUS_PIN_PANEL;
879 if (!intel_bios_is_lvds_present(display, &ddc_pin)) {
880 if ((lvds & LVDS_PORT_EN) == 0) {
881 drm_dbg_kms(&i915->drm,
882 "LVDS is not present in VBT\n");
885 drm_dbg_kms(&i915->drm,
886 "LVDS is not present in VBT, but enabled anyway\n");
889 lvds_encoder = kzalloc(sizeof(*lvds_encoder), GFP_KERNEL);
893 connector = intel_connector_alloc();
899 lvds_encoder->attached_connector = connector;
900 encoder = &lvds_encoder->base;
902 drm_connector_init_with_ddc(&i915->drm, &connector->base,
903 &intel_lvds_connector_funcs,
904 DRM_MODE_CONNECTOR_LVDS,
905 intel_gmbus_get_adapter(display, ddc_pin));
907 drm_encoder_init(&i915->drm, &encoder->base, &intel_lvds_enc_funcs,
908 DRM_MODE_ENCODER_LVDS, "LVDS");
910 encoder->enable = intel_enable_lvds;
911 encoder->pre_enable = intel_pre_enable_lvds;
912 encoder->compute_config = intel_lvds_compute_config;
913 if (HAS_PCH_SPLIT(i915)) {
914 encoder->disable = pch_disable_lvds;
915 encoder->post_disable = pch_post_disable_lvds;
917 encoder->disable = gmch_disable_lvds;
919 encoder->get_hw_state = intel_lvds_get_hw_state;
920 encoder->get_config = intel_lvds_get_config;
921 encoder->update_pipe = intel_backlight_update;
922 encoder->shutdown = intel_lvds_shutdown;
923 connector->get_hw_state = intel_connector_get_hw_state;
925 intel_connector_attach_encoder(connector, encoder);
927 encoder->type = INTEL_OUTPUT_LVDS;
928 encoder->power_domain = POWER_DOMAIN_PORT_OTHER;
929 encoder->port = PORT_NONE;
930 encoder->cloneable = 0;
931 if (DISPLAY_VER(i915) < 4)
932 encoder->pipe_mask = BIT(PIPE_B);
934 encoder->pipe_mask = ~0;
936 drm_connector_helper_add(&connector->base, &intel_lvds_connector_helper_funcs);
937 connector->base.display_info.subpixel_order = SubPixelHorizontalRGB;
939 lvds_encoder->reg = lvds_reg;
941 intel_lvds_add_properties(&connector->base);
943 intel_lvds_pps_get_hw_state(i915, &lvds_encoder->init_pps);
944 lvds_encoder->init_lvds_val = lvds;
948 * 1) check for EDID on DDC
949 * 2) check for VBT data
950 * 3) check to see if LVDS is already on
951 * if none of the above, no panel
955 * Attempt to get the fixed panel mode from DDC. Assume that the
956 * preferred mode is the right one.
958 mutex_lock(&i915->drm.mode_config.mutex);
959 if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC)
960 drm_edid = drm_edid_read_switcheroo(&connector->base, connector->base.ddc);
962 drm_edid = drm_edid_read_ddc(&connector->base, connector->base.ddc);
964 if (drm_edid_connector_update(&connector->base, drm_edid) ||
965 !drm_edid_connector_add_modes(&connector->base)) {
966 drm_edid_connector_update(&connector->base, NULL);
967 drm_edid_free(drm_edid);
968 drm_edid = ERR_PTR(-EINVAL);
971 drm_edid = ERR_PTR(-ENOENT);
973 intel_bios_init_panel_late(display, &connector->panel, NULL,
974 IS_ERR(drm_edid) ? NULL : drm_edid);
977 intel_panel_add_edid_fixed_modes(connector, true);
979 /* Failed to get EDID, what about VBT? */
980 if (!intel_panel_preferred_fixed_mode(connector))
981 intel_panel_add_vbt_lfp_fixed_mode(connector);
984 * If we didn't get a fixed mode from EDID or VBT, try checking
985 * if the panel is already turned on. If so, assume that
986 * whatever is currently programmed is the correct mode.
988 if (!intel_panel_preferred_fixed_mode(connector))
989 intel_panel_add_encoder_fixed_mode(connector, encoder);
991 mutex_unlock(&i915->drm.mode_config.mutex);
993 /* If we still don't have a mode after all that, give up. */
994 if (!intel_panel_preferred_fixed_mode(connector))
997 intel_panel_init(connector, drm_edid);
999 intel_backlight_setup(connector, INVALID_PIPE);
1001 lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
1002 drm_dbg_kms(&i915->drm, "detected %s-link lvds configuration\n",
1003 lvds_encoder->is_dual_link ? "dual" : "single");
1005 lvds_encoder->a3_power = lvds & LVDS_A3_POWER_MASK;
1010 drm_dbg_kms(&i915->drm, "No LVDS modes found, disabling.\n");
1011 drm_connector_cleanup(&connector->base);
1012 drm_encoder_cleanup(&encoder->base);
1013 kfree(lvds_encoder);
1014 intel_connector_free(connector);