regulator: as3722: Fix incorrect parameter initialization
[linux-drm-fsl-dcu.git] / drivers / gpu / drm / i915 / intel_lvds.c
1 /*
2  * Copyright © 2006-2007 Intel Corporation
3  * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
4  *
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:
11  *
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
14  * Software.
15  *
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.
23  *
24  * Authors:
25  *      Eric Anholt <eric@anholt.net>
26  *      Dave Airlie <airlied@linux.ie>
27  *      Jesse Barnes <jesse.barnes@intel.com>
28  */
29
30 #include <acpi/button.h>
31 #include <linux/dmi.h>
32 #include <linux/i2c.h>
33 #include <linux/slab.h>
34 #include <drm/drmP.h>
35 #include <drm/drm_crtc.h>
36 #include <drm/drm_edid.h>
37 #include "intel_drv.h"
38 #include <drm/i915_drm.h>
39 #include "i915_drv.h"
40 #include <linux/acpi.h>
41
42 /* Private structure for the integrated LVDS support */
43 struct intel_lvds_connector {
44         struct intel_connector base;
45
46         struct notifier_block lid_notifier;
47 };
48
49 struct intel_lvds_encoder {
50         struct intel_encoder base;
51
52         bool is_dual_link;
53         u32 reg;
54
55         struct intel_lvds_connector *attached_connector;
56 };
57
58 static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
59 {
60         return container_of(encoder, struct intel_lvds_encoder, base.base);
61 }
62
63 static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
64 {
65         return container_of(connector, struct intel_lvds_connector, base.base);
66 }
67
68 static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
69                                     enum pipe *pipe)
70 {
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);
74         u32 tmp;
75
76         tmp = I915_READ(lvds_encoder->reg);
77
78         if (!(tmp & LVDS_PORT_EN))
79                 return false;
80
81         if (HAS_PCH_CPT(dev))
82                 *pipe = PORT_TO_PIPE_CPT(tmp);
83         else
84                 *pipe = PORT_TO_PIPE(tmp);
85
86         return true;
87 }
88
89 static void intel_lvds_get_config(struct intel_encoder *encoder,
90                                   struct intel_crtc_config *pipe_config)
91 {
92         struct drm_device *dev = encoder->base.dev;
93         struct drm_i915_private *dev_priv = dev->dev_private;
94         u32 lvds_reg, tmp, flags = 0;
95         int dotclock;
96
97         if (HAS_PCH_SPLIT(dev))
98                 lvds_reg = PCH_LVDS;
99         else
100                 lvds_reg = LVDS;
101
102         tmp = I915_READ(lvds_reg);
103         if (tmp & LVDS_HSYNC_POLARITY)
104                 flags |= DRM_MODE_FLAG_NHSYNC;
105         else
106                 flags |= DRM_MODE_FLAG_PHSYNC;
107         if (tmp & LVDS_VSYNC_POLARITY)
108                 flags |= DRM_MODE_FLAG_NVSYNC;
109         else
110                 flags |= DRM_MODE_FLAG_PVSYNC;
111
112         pipe_config->adjusted_mode.flags |= flags;
113
114         dotclock = pipe_config->port_clock;
115
116         if (HAS_PCH_SPLIT(dev_priv->dev))
117                 ironlake_check_encoder_dotclock(pipe_config, dotclock);
118
119         pipe_config->adjusted_mode.crtc_clock = dotclock;
120 }
121
122 static void intel_pre_enable_lvds(struct intel_encoder *encoder)
123 {
124         struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
125         struct drm_device *dev = encoder->base.dev;
126         struct drm_i915_private *dev_priv = dev->dev_private;
127         struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
128         const struct drm_display_mode *adjusted_mode =
129                 &crtc->config.adjusted_mode;
130         int pipe = crtc->pipe;
131         u32 temp;
132
133         if (HAS_PCH_SPLIT(dev)) {
134                 assert_fdi_rx_pll_disabled(dev_priv, pipe);
135                 assert_shared_dpll_disabled(dev_priv,
136                                             intel_crtc_to_shared_dpll(crtc));
137         } else {
138                 assert_pll_disabled(dev_priv, pipe);
139         }
140
141         temp = I915_READ(lvds_encoder->reg);
142         temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
143
144         if (HAS_PCH_CPT(dev)) {
145                 temp &= ~PORT_TRANS_SEL_MASK;
146                 temp |= PORT_TRANS_SEL_CPT(pipe);
147         } else {
148                 if (pipe == 1) {
149                         temp |= LVDS_PIPEB_SELECT;
150                 } else {
151                         temp &= ~LVDS_PIPEB_SELECT;
152                 }
153         }
154
155         /* set the corresponsding LVDS_BORDER bit */
156         temp &= ~LVDS_BORDER_ENABLE;
157         temp |= crtc->config.gmch_pfit.lvds_border_bits;
158         /* Set the B0-B3 data pairs corresponding to whether we're going to
159          * set the DPLLs for dual-channel mode or not.
160          */
161         if (lvds_encoder->is_dual_link)
162                 temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
163         else
164                 temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
165
166         /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
167          * appropriately here, but we need to look more thoroughly into how
168          * panels behave in the two modes.
169          */
170
171         /* Set the dithering flag on LVDS as needed, note that there is no
172          * special lvds dither control bit on pch-split platforms, dithering is
173          * only controlled through the PIPECONF reg. */
174         if (INTEL_INFO(dev)->gen == 4) {
175                 /* Bspec wording suggests that LVDS port dithering only exists
176                  * for 18bpp panels. */
177                 if (crtc->config.dither && crtc->config.pipe_bpp == 18)
178                         temp |= LVDS_ENABLE_DITHER;
179                 else
180                         temp &= ~LVDS_ENABLE_DITHER;
181         }
182         temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
183         if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
184                 temp |= LVDS_HSYNC_POLARITY;
185         if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
186                 temp |= LVDS_VSYNC_POLARITY;
187
188         I915_WRITE(lvds_encoder->reg, temp);
189 }
190
191 /**
192  * Sets the power state for the panel.
193  */
194 static void intel_enable_lvds(struct intel_encoder *encoder)
195 {
196         struct drm_device *dev = encoder->base.dev;
197         struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
198         struct intel_connector *intel_connector =
199                 &lvds_encoder->attached_connector->base;
200         struct drm_i915_private *dev_priv = dev->dev_private;
201         u32 ctl_reg, stat_reg;
202
203         if (HAS_PCH_SPLIT(dev)) {
204                 ctl_reg = PCH_PP_CONTROL;
205                 stat_reg = PCH_PP_STATUS;
206         } else {
207                 ctl_reg = PP_CONTROL;
208                 stat_reg = PP_STATUS;
209         }
210
211         I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
212
213         I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
214         POSTING_READ(lvds_encoder->reg);
215         if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
216                 DRM_ERROR("timed out waiting for panel to power on\n");
217
218         intel_panel_enable_backlight(intel_connector);
219 }
220
221 static void intel_disable_lvds(struct intel_encoder *encoder)
222 {
223         struct drm_device *dev = encoder->base.dev;
224         struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
225         struct intel_connector *intel_connector =
226                 &lvds_encoder->attached_connector->base;
227         struct drm_i915_private *dev_priv = dev->dev_private;
228         u32 ctl_reg, stat_reg;
229
230         if (HAS_PCH_SPLIT(dev)) {
231                 ctl_reg = PCH_PP_CONTROL;
232                 stat_reg = PCH_PP_STATUS;
233         } else {
234                 ctl_reg = PP_CONTROL;
235                 stat_reg = PP_STATUS;
236         }
237
238         intel_panel_disable_backlight(intel_connector);
239
240         I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
241         if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
242                 DRM_ERROR("timed out waiting for panel to power off\n");
243
244         I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
245         POSTING_READ(lvds_encoder->reg);
246 }
247
248 static enum drm_mode_status
249 intel_lvds_mode_valid(struct drm_connector *connector,
250                       struct drm_display_mode *mode)
251 {
252         struct intel_connector *intel_connector = to_intel_connector(connector);
253         struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
254
255         if (mode->hdisplay > fixed_mode->hdisplay)
256                 return MODE_PANEL;
257         if (mode->vdisplay > fixed_mode->vdisplay)
258                 return MODE_PANEL;
259
260         return MODE_OK;
261 }
262
263 static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
264                                       struct intel_crtc_config *pipe_config)
265 {
266         struct drm_device *dev = intel_encoder->base.dev;
267         struct drm_i915_private *dev_priv = dev->dev_private;
268         struct intel_lvds_encoder *lvds_encoder =
269                 to_lvds_encoder(&intel_encoder->base);
270         struct intel_connector *intel_connector =
271                 &lvds_encoder->attached_connector->base;
272         struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
273         struct intel_crtc *intel_crtc = lvds_encoder->base.new_crtc;
274         unsigned int lvds_bpp;
275
276         /* Should never happen!! */
277         if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
278                 DRM_ERROR("Can't support LVDS on pipe A\n");
279                 return false;
280         }
281
282         if ((I915_READ(lvds_encoder->reg) & LVDS_A3_POWER_MASK) ==
283             LVDS_A3_POWER_UP)
284                 lvds_bpp = 8*3;
285         else
286                 lvds_bpp = 6*3;
287
288         if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) {
289                 DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
290                               pipe_config->pipe_bpp, lvds_bpp);
291                 pipe_config->pipe_bpp = lvds_bpp;
292         }
293
294         /*
295          * We have timings from the BIOS for the panel, put them in
296          * to the adjusted mode.  The CRTC will be set up for this mode,
297          * with the panel scaling set up to source from the H/VDisplay
298          * of the original mode.
299          */
300         intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
301                                adjusted_mode);
302
303         if (HAS_PCH_SPLIT(dev)) {
304                 pipe_config->has_pch_encoder = true;
305
306                 intel_pch_panel_fitting(intel_crtc, pipe_config,
307                                         intel_connector->panel.fitting_mode);
308         } else {
309                 intel_gmch_panel_fitting(intel_crtc, pipe_config,
310                                          intel_connector->panel.fitting_mode);
311
312         }
313
314         /*
315          * XXX: It would be nice to support lower refresh rates on the
316          * panels to reduce power consumption, and perhaps match the
317          * user's requested refresh rate.
318          */
319
320         return true;
321 }
322
323 /**
324  * Detect the LVDS connection.
325  *
326  * Since LVDS doesn't have hotlug, we use the lid as a proxy.  Open means
327  * connected and closed means disconnected.  We also send hotplug events as
328  * needed, using lid status notification from the input layer.
329  */
330 static enum drm_connector_status
331 intel_lvds_detect(struct drm_connector *connector, bool force)
332 {
333         struct drm_device *dev = connector->dev;
334         enum drm_connector_status status;
335
336         DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
337                       connector->base.id, connector->name);
338
339         status = intel_panel_detect(dev);
340         if (status != connector_status_unknown)
341                 return status;
342
343         return connector_status_connected;
344 }
345
346 /**
347  * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
348  */
349 static int intel_lvds_get_modes(struct drm_connector *connector)
350 {
351         struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
352         struct drm_device *dev = connector->dev;
353         struct drm_display_mode *mode;
354
355         /* use cached edid if we have one */
356         if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
357                 return drm_add_edid_modes(connector, lvds_connector->base.edid);
358
359         mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
360         if (mode == NULL)
361                 return 0;
362
363         drm_mode_probed_add(connector, mode);
364         return 1;
365 }
366
367 static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
368 {
369         DRM_INFO("Skipping forced modeset for %s\n", id->ident);
370         return 1;
371 }
372
373 /* The GPU hangs up on these systems if modeset is performed on LID open */
374 static const struct dmi_system_id intel_no_modeset_on_lid[] = {
375         {
376                 .callback = intel_no_modeset_on_lid_dmi_callback,
377                 .ident = "Toshiba Tecra A11",
378                 .matches = {
379                         DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
380                         DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
381                 },
382         },
383
384         { }     /* terminating entry */
385 };
386
387 /*
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").
396  */
397 static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
398                             void *unused)
399 {
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;
405
406         if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
407                 return NOTIFY_OK;
408
409         mutex_lock(&dev_priv->modeset_restore_lock);
410         if (dev_priv->modeset_restore == MODESET_SUSPENDED)
411                 goto exit;
412         /*
413          * check and update the status of LVDS connector after receiving
414          * the LID nofication event.
415          */
416         connector->status = connector->funcs->detect(connector, false);
417
418         /* Don't force modeset on machines where it causes a GPU lockup */
419         if (dmi_check_system(intel_no_modeset_on_lid))
420                 goto exit;
421         if (!acpi_lid_open()) {
422                 /* do modeset on next lid open event */
423                 dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
424                 goto exit;
425         }
426
427         if (dev_priv->modeset_restore == MODESET_DONE)
428                 goto exit;
429
430         /*
431          * Some old platform's BIOS love to wreak havoc while the lid is closed.
432          * We try to detect this here and undo any damage. The split for PCH
433          * platforms is rather conservative and a bit arbitrary expect that on
434          * those platforms VGA disabling requires actual legacy VGA I/O access,
435          * and as part of the cleanup in the hw state restore we also redisable
436          * the vga plane.
437          */
438         if (!HAS_PCH_SPLIT(dev)) {
439                 drm_modeset_lock_all(dev);
440                 intel_modeset_setup_hw_state(dev, true);
441                 drm_modeset_unlock_all(dev);
442         }
443
444         dev_priv->modeset_restore = MODESET_DONE;
445
446 exit:
447         mutex_unlock(&dev_priv->modeset_restore_lock);
448         return NOTIFY_OK;
449 }
450
451 /**
452  * intel_lvds_destroy - unregister and free LVDS structures
453  * @connector: connector to free
454  *
455  * Unregister the DDC bus for this connector then free the driver private
456  * structure.
457  */
458 static void intel_lvds_destroy(struct drm_connector *connector)
459 {
460         struct intel_lvds_connector *lvds_connector =
461                 to_lvds_connector(connector);
462
463         if (lvds_connector->lid_notifier.notifier_call)
464                 acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
465
466         if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
467                 kfree(lvds_connector->base.edid);
468
469         intel_panel_fini(&lvds_connector->base.panel);
470
471         drm_connector_cleanup(connector);
472         kfree(connector);
473 }
474
475 static int intel_lvds_set_property(struct drm_connector *connector,
476                                    struct drm_property *property,
477                                    uint64_t value)
478 {
479         struct intel_connector *intel_connector = to_intel_connector(connector);
480         struct drm_device *dev = connector->dev;
481
482         if (property == dev->mode_config.scaling_mode_property) {
483                 struct drm_crtc *crtc;
484
485                 if (value == DRM_MODE_SCALE_NONE) {
486                         DRM_DEBUG_KMS("no scaling not supported\n");
487                         return -EINVAL;
488                 }
489
490                 if (intel_connector->panel.fitting_mode == value) {
491                         /* the LVDS scaling property is not changed */
492                         return 0;
493                 }
494                 intel_connector->panel.fitting_mode = value;
495
496                 crtc = intel_attached_encoder(connector)->base.crtc;
497                 if (crtc && crtc->enabled) {
498                         /*
499                          * If the CRTC is enabled, the display will be changed
500                          * according to the new panel fitting mode.
501                          */
502                         intel_crtc_restore_mode(crtc);
503                 }
504         }
505
506         return 0;
507 }
508
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,
513 };
514
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,
521 };
522
523 static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
524         .destroy = intel_encoder_destroy,
525 };
526
527 static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
528 {
529         DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
530         return 1;
531 }
532
533 /* These systems claim to have LVDS, but really don't */
534 static const struct dmi_system_id intel_no_lvds[] = {
535         {
536                 .callback = intel_no_lvds_dmi_callback,
537                 .ident = "Apple Mac Mini (Core series)",
538                 .matches = {
539                         DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
540                         DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
541                 },
542         },
543         {
544                 .callback = intel_no_lvds_dmi_callback,
545                 .ident = "Apple Mac Mini (Core 2 series)",
546                 .matches = {
547                         DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
548                         DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
549                 },
550         },
551         {
552                 .callback = intel_no_lvds_dmi_callback,
553                 .ident = "MSI IM-945GSE-A",
554                 .matches = {
555                         DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
556                         DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
557                 },
558         },
559         {
560                 .callback = intel_no_lvds_dmi_callback,
561                 .ident = "Dell Studio Hybrid",
562                 .matches = {
563                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
564                         DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
565                 },
566         },
567         {
568                 .callback = intel_no_lvds_dmi_callback,
569                 .ident = "Dell OptiPlex FX170",
570                 .matches = {
571                         DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
572                         DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
573                 },
574         },
575         {
576                 .callback = intel_no_lvds_dmi_callback,
577                 .ident = "AOpen Mini PC",
578                 .matches = {
579                         DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
580                         DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
581                 },
582         },
583         {
584                 .callback = intel_no_lvds_dmi_callback,
585                 .ident = "AOpen Mini PC MP915",
586                 .matches = {
587                         DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
588                         DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
589                 },
590         },
591         {
592                 .callback = intel_no_lvds_dmi_callback,
593                 .ident = "AOpen i915GMm-HFS",
594                 .matches = {
595                         DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
596                         DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
597                 },
598         },
599         {
600                 .callback = intel_no_lvds_dmi_callback,
601                 .ident = "AOpen i45GMx-I",
602                 .matches = {
603                         DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
604                         DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
605                 },
606         },
607         {
608                 .callback = intel_no_lvds_dmi_callback,
609                 .ident = "Aopen i945GTt-VFA",
610                 .matches = {
611                         DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
612                 },
613         },
614         {
615                 .callback = intel_no_lvds_dmi_callback,
616                 .ident = "Clientron U800",
617                 .matches = {
618                         DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
619                         DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
620                 },
621         },
622         {
623                 .callback = intel_no_lvds_dmi_callback,
624                 .ident = "Clientron E830",
625                 .matches = {
626                         DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
627                         DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
628                 },
629         },
630         {
631                 .callback = intel_no_lvds_dmi_callback,
632                 .ident = "Asus EeeBox PC EB1007",
633                 .matches = {
634                         DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
635                         DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
636                 },
637         },
638         {
639                 .callback = intel_no_lvds_dmi_callback,
640                 .ident = "Asus AT5NM10T-I",
641                 .matches = {
642                         DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
643                         DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
644                 },
645         },
646         {
647                 .callback = intel_no_lvds_dmi_callback,
648                 .ident = "Hewlett-Packard HP t5740",
649                 .matches = {
650                         DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
651                         DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
652                 },
653         },
654         {
655                 .callback = intel_no_lvds_dmi_callback,
656                 .ident = "Hewlett-Packard t5745",
657                 .matches = {
658                         DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
659                         DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
660                 },
661         },
662         {
663                 .callback = intel_no_lvds_dmi_callback,
664                 .ident = "Hewlett-Packard st5747",
665                 .matches = {
666                         DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
667                         DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
668                 },
669         },
670         {
671                 .callback = intel_no_lvds_dmi_callback,
672                 .ident = "MSI Wind Box DC500",
673                 .matches = {
674                         DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
675                         DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
676                 },
677         },
678         {
679                 .callback = intel_no_lvds_dmi_callback,
680                 .ident = "Gigabyte GA-D525TUD",
681                 .matches = {
682                         DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
683                         DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
684                 },
685         },
686         {
687                 .callback = intel_no_lvds_dmi_callback,
688                 .ident = "Supermicro X7SPA-H",
689                 .matches = {
690                         DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
691                         DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
692                 },
693         },
694         {
695                 .callback = intel_no_lvds_dmi_callback,
696                 .ident = "Fujitsu Esprimo Q900",
697                 .matches = {
698                         DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
699                         DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
700                 },
701         },
702         {
703                 .callback = intel_no_lvds_dmi_callback,
704                 .ident = "Intel D410PT",
705                 .matches = {
706                         DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
707                         DMI_MATCH(DMI_BOARD_NAME, "D410PT"),
708                 },
709         },
710         {
711                 .callback = intel_no_lvds_dmi_callback,
712                 .ident = "Intel D425KT",
713                 .matches = {
714                         DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
715                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"),
716                 },
717         },
718         {
719                 .callback = intel_no_lvds_dmi_callback,
720                 .ident = "Intel D510MO",
721                 .matches = {
722                         DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
723                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
724                 },
725         },
726         {
727                 .callback = intel_no_lvds_dmi_callback,
728                 .ident = "Intel D525MW",
729                 .matches = {
730                         DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
731                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
732                 },
733         },
734
735         { }     /* terminating entry */
736 };
737
738 /*
739  * Enumerate the child dev array parsed from VBT to check whether
740  * the LVDS is present.
741  * If it is present, return 1.
742  * If it is not present, return false.
743  * If no child dev is parsed from VBT, it assumes that the LVDS is present.
744  */
745 static bool lvds_is_present_in_vbt(struct drm_device *dev,
746                                    u8 *i2c_pin)
747 {
748         struct drm_i915_private *dev_priv = dev->dev_private;
749         int i;
750
751         if (!dev_priv->vbt.child_dev_num)
752                 return true;
753
754         for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
755                 union child_device_config *uchild = dev_priv->vbt.child_dev + i;
756                 struct old_child_dev_config *child = &uchild->old;
757
758                 /* If the device type is not LFP, continue.
759                  * We have to check both the new identifiers as well as the
760                  * old for compatibility with some BIOSes.
761                  */
762                 if (child->device_type != DEVICE_TYPE_INT_LFP &&
763                     child->device_type != DEVICE_TYPE_LFP)
764                         continue;
765
766                 if (intel_gmbus_is_port_valid(child->i2c_pin))
767                         *i2c_pin = child->i2c_pin;
768
769                 /* However, we cannot trust the BIOS writers to populate
770                  * the VBT correctly.  Since LVDS requires additional
771                  * information from AIM blocks, a non-zero addin offset is
772                  * a good indicator that the LVDS is actually present.
773                  */
774                 if (child->addin_offset)
775                         return true;
776
777                 /* But even then some BIOS writers perform some black magic
778                  * and instantiate the device without reference to any
779                  * additional data.  Trust that if the VBT was written into
780                  * the OpRegion then they have validated the LVDS's existence.
781                  */
782                 if (dev_priv->opregion.vbt)
783                         return true;
784         }
785
786         return false;
787 }
788
789 static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
790 {
791         DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
792         return 1;
793 }
794
795 static const struct dmi_system_id intel_dual_link_lvds[] = {
796         {
797                 .callback = intel_dual_link_lvds_callback,
798                 .ident = "Apple MacBook Pro (Core i5/i7 Series)",
799                 .matches = {
800                         DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
801                         DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
802                 },
803         },
804         { }     /* terminating entry */
805 };
806
807 bool intel_is_dual_link_lvds(struct drm_device *dev)
808 {
809         struct intel_encoder *encoder;
810         struct intel_lvds_encoder *lvds_encoder;
811
812         list_for_each_entry(encoder, &dev->mode_config.encoder_list,
813                             base.head) {
814                 if (encoder->type == INTEL_OUTPUT_LVDS) {
815                         lvds_encoder = to_lvds_encoder(&encoder->base);
816
817                         return lvds_encoder->is_dual_link;
818                 }
819         }
820
821         return false;
822 }
823
824 static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
825 {
826         struct drm_device *dev = lvds_encoder->base.base.dev;
827         unsigned int val;
828         struct drm_i915_private *dev_priv = dev->dev_private;
829
830         /* use the module option value if specified */
831         if (i915.lvds_channel_mode > 0)
832                 return i915.lvds_channel_mode == 2;
833
834         if (dmi_check_system(intel_dual_link_lvds))
835                 return true;
836
837         /* BIOS should set the proper LVDS register value at boot, but
838          * in reality, it doesn't set the value when the lid is closed;
839          * we need to check "the value to be set" in VBT when LVDS
840          * register is uninitialized.
841          */
842         val = I915_READ(lvds_encoder->reg);
843         if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
844                 val = dev_priv->vbt.bios_lvds_val;
845
846         return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
847 }
848
849 static bool intel_lvds_supported(struct drm_device *dev)
850 {
851         /* With the introduction of the PCH we gained a dedicated
852          * LVDS presence pin, use it. */
853         if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
854                 return true;
855
856         /* Otherwise LVDS was only attached to mobile products,
857          * except for the inglorious 830gm */
858         if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
859                 return true;
860
861         return false;
862 }
863
864 /**
865  * intel_lvds_init - setup LVDS connectors on this device
866  * @dev: drm device
867  *
868  * Create the connector, register the LVDS DDC bus, and try to figure out what
869  * modes we can display on the LVDS panel (if present).
870  */
871 void intel_lvds_init(struct drm_device *dev)
872 {
873         struct drm_i915_private *dev_priv = dev->dev_private;
874         struct intel_lvds_encoder *lvds_encoder;
875         struct intel_encoder *intel_encoder;
876         struct intel_lvds_connector *lvds_connector;
877         struct intel_connector *intel_connector;
878         struct drm_connector *connector;
879         struct drm_encoder *encoder;
880         struct drm_display_mode *scan; /* *modes, *bios_mode; */
881         struct drm_display_mode *fixed_mode = NULL;
882         struct drm_display_mode *downclock_mode = NULL;
883         struct edid *edid;
884         struct drm_crtc *crtc;
885         u32 lvds;
886         int pipe;
887         u8 pin;
888
889         if (!intel_lvds_supported(dev))
890                 return;
891
892         /* Skip init on machines we know falsely report LVDS */
893         if (dmi_check_system(intel_no_lvds))
894                 return;
895
896         pin = GMBUS_PORT_PANEL;
897         if (!lvds_is_present_in_vbt(dev, &pin)) {
898                 DRM_DEBUG_KMS("LVDS is not present in VBT\n");
899                 return;
900         }
901
902         if (HAS_PCH_SPLIT(dev)) {
903                 if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
904                         return;
905                 if (dev_priv->vbt.edp_support) {
906                         DRM_DEBUG_KMS("disable LVDS for eDP support\n");
907                         return;
908                 }
909         }
910
911         lvds_encoder = kzalloc(sizeof(*lvds_encoder), GFP_KERNEL);
912         if (!lvds_encoder)
913                 return;
914
915         lvds_connector = kzalloc(sizeof(*lvds_connector), GFP_KERNEL);
916         if (!lvds_connector) {
917                 kfree(lvds_encoder);
918                 return;
919         }
920
921         lvds_encoder->attached_connector = lvds_connector;
922
923         intel_encoder = &lvds_encoder->base;
924         encoder = &intel_encoder->base;
925         intel_connector = &lvds_connector->base;
926         connector = &intel_connector->base;
927         drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
928                            DRM_MODE_CONNECTOR_LVDS);
929
930         drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
931                          DRM_MODE_ENCODER_LVDS);
932
933         intel_encoder->enable = intel_enable_lvds;
934         intel_encoder->pre_enable = intel_pre_enable_lvds;
935         intel_encoder->compute_config = intel_lvds_compute_config;
936         intel_encoder->disable = intel_disable_lvds;
937         intel_encoder->get_hw_state = intel_lvds_get_hw_state;
938         intel_encoder->get_config = intel_lvds_get_config;
939         intel_connector->get_hw_state = intel_connector_get_hw_state;
940         intel_connector->unregister = intel_connector_unregister;
941
942         intel_connector_attach_encoder(intel_connector, intel_encoder);
943         intel_encoder->type = INTEL_OUTPUT_LVDS;
944
945         intel_encoder->cloneable = 0;
946         if (HAS_PCH_SPLIT(dev))
947                 intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
948         else if (IS_GEN4(dev))
949                 intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
950         else
951                 intel_encoder->crtc_mask = (1 << 1);
952
953         drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
954         connector->display_info.subpixel_order = SubPixelHorizontalRGB;
955         connector->interlace_allowed = false;
956         connector->doublescan_allowed = false;
957
958         if (HAS_PCH_SPLIT(dev)) {
959                 lvds_encoder->reg = PCH_LVDS;
960         } else {
961                 lvds_encoder->reg = LVDS;
962         }
963
964         /* create the scaling mode property */
965         drm_mode_create_scaling_mode_property(dev);
966         drm_object_attach_property(&connector->base,
967                                       dev->mode_config.scaling_mode_property,
968                                       DRM_MODE_SCALE_ASPECT);
969         intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
970         /*
971          * LVDS discovery:
972          * 1) check for EDID on DDC
973          * 2) check for VBT data
974          * 3) check to see if LVDS is already on
975          *    if none of the above, no panel
976          * 4) make sure lid is open
977          *    if closed, act like it's not there for now
978          */
979
980         /*
981          * Attempt to get the fixed panel mode from DDC.  Assume that the
982          * preferred mode is the right one.
983          */
984         mutex_lock(&dev->mode_config.mutex);
985         edid = drm_get_edid(connector, intel_gmbus_get_adapter(dev_priv, pin));
986         if (edid) {
987                 if (drm_add_edid_modes(connector, edid)) {
988                         drm_mode_connector_update_edid_property(connector,
989                                                                 edid);
990                 } else {
991                         kfree(edid);
992                         edid = ERR_PTR(-EINVAL);
993                 }
994         } else {
995                 edid = ERR_PTR(-ENOENT);
996         }
997         lvds_connector->base.edid = edid;
998
999         if (IS_ERR_OR_NULL(edid)) {
1000                 /* Didn't get an EDID, so
1001                  * Set wide sync ranges so we get all modes
1002                  * handed to valid_mode for checking
1003                  */
1004                 connector->display_info.min_vfreq = 0;
1005                 connector->display_info.max_vfreq = 200;
1006                 connector->display_info.min_hfreq = 0;
1007                 connector->display_info.max_hfreq = 200;
1008         }
1009
1010         list_for_each_entry(scan, &connector->probed_modes, head) {
1011                 if (scan->type & DRM_MODE_TYPE_PREFERRED) {
1012                         DRM_DEBUG_KMS("using preferred mode from EDID: ");
1013                         drm_mode_debug_printmodeline(scan);
1014
1015                         fixed_mode = drm_mode_duplicate(dev, scan);
1016                         if (fixed_mode) {
1017                                 downclock_mode =
1018                                         intel_find_panel_downclock(dev,
1019                                         fixed_mode, connector);
1020                                 if (downclock_mode != NULL &&
1021                                         i915.lvds_downclock) {
1022                                         /* We found the downclock for LVDS. */
1023                                         dev_priv->lvds_downclock_avail = true;
1024                                         dev_priv->lvds_downclock =
1025                                                 downclock_mode->clock;
1026                                         DRM_DEBUG_KMS("LVDS downclock is found"
1027                                         " in EDID. Normal clock %dKhz, "
1028                                         "downclock %dKhz\n",
1029                                         fixed_mode->clock,
1030                                         dev_priv->lvds_downclock);
1031                                 }
1032                                 goto out;
1033                         }
1034                 }
1035         }
1036
1037         /* Failed to get EDID, what about VBT? */
1038         if (dev_priv->vbt.lfp_lvds_vbt_mode) {
1039                 DRM_DEBUG_KMS("using mode from VBT: ");
1040                 drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
1041
1042                 fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
1043                 if (fixed_mode) {
1044                         fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1045                         goto out;
1046                 }
1047         }
1048
1049         /*
1050          * If we didn't get EDID, try checking if the panel is already turned
1051          * on.  If so, assume that whatever is currently programmed is the
1052          * correct mode.
1053          */
1054
1055         /* Ironlake: FIXME if still fail, not try pipe mode now */
1056         if (HAS_PCH_SPLIT(dev))
1057                 goto failed;
1058
1059         lvds = I915_READ(LVDS);
1060         pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
1061         crtc = intel_get_crtc_for_pipe(dev, pipe);
1062
1063         if (crtc && (lvds & LVDS_PORT_EN)) {
1064                 fixed_mode = intel_crtc_mode_get(dev, crtc);
1065                 if (fixed_mode) {
1066                         DRM_DEBUG_KMS("using current (BIOS) mode: ");
1067                         drm_mode_debug_printmodeline(fixed_mode);
1068                         fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
1069                         goto out;
1070                 }
1071         }
1072
1073         /* If we still don't have a mode after all that, give up. */
1074         if (!fixed_mode)
1075                 goto failed;
1076
1077 out:
1078         mutex_unlock(&dev->mode_config.mutex);
1079
1080         lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
1081         DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
1082                       lvds_encoder->is_dual_link ? "dual" : "single");
1083
1084         /*
1085          * Unlock registers and just
1086          * leave them unlocked
1087          */
1088         if (HAS_PCH_SPLIT(dev)) {
1089                 I915_WRITE(PCH_PP_CONTROL,
1090                            I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
1091         } else {
1092                 I915_WRITE(PP_CONTROL,
1093                            I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
1094         }
1095         lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
1096         if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
1097                 DRM_DEBUG_KMS("lid notifier registration failed\n");
1098                 lvds_connector->lid_notifier.notifier_call = NULL;
1099         }
1100         drm_sysfs_connector_add(connector);
1101
1102         intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
1103         intel_panel_setup_backlight(connector);
1104
1105         return;
1106
1107 failed:
1108         mutex_unlock(&dev->mode_config.mutex);
1109
1110         DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
1111         drm_connector_cleanup(connector);
1112         drm_encoder_cleanup(encoder);
1113         kfree(lvds_encoder);
1114         kfree(lvds_connector);
1115         return;
1116 }