2 * Copyright © 2006 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 * Eric Anholt <eric@anholt.net>
28 #include <drm/drm_dp_helper.h>
29 #include <drm/i915_drm.h>
31 #include "intel_bios.h"
33 #define SLAVE_ADDR1 0x70
34 #define SLAVE_ADDR2 0x72
36 static int panel_type;
39 find_section(struct bdb_header *bdb, int section_id)
43 u16 total, current_size;
46 /* skip to first section */
47 index += bdb->header_size;
48 total = bdb->bdb_size;
50 /* walk the sections looking for section_id */
51 while (index < total) {
52 current_id = *(base + index);
54 current_size = *((u16 *)(base + index));
56 if (current_id == section_id)
58 index += current_size;
65 get_blocksize(void *p)
67 u16 *block_ptr, block_size;
69 block_ptr = (u16 *)((char *)p - 2);
70 block_size = *block_ptr;
75 fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
76 const struct lvds_dvo_timing *dvo_timing)
78 panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
79 dvo_timing->hactive_lo;
80 panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
81 ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
82 panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
83 dvo_timing->hsync_pulse_width;
84 panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
85 ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
87 panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
88 dvo_timing->vactive_lo;
89 panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
90 dvo_timing->vsync_off;
91 panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
92 dvo_timing->vsync_pulse_width;
93 panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
94 ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
95 panel_fixed_mode->clock = dvo_timing->clock * 10;
96 panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
98 if (dvo_timing->hsync_positive)
99 panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
101 panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
103 if (dvo_timing->vsync_positive)
104 panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
106 panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
108 /* Some VBTs have bogus h/vtotal values */
109 if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
110 panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
111 if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
112 panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
114 drm_mode_set_name(panel_fixed_mode);
118 lvds_dvo_timing_equal_size(const struct lvds_dvo_timing *a,
119 const struct lvds_dvo_timing *b)
121 if (a->hactive_hi != b->hactive_hi ||
122 a->hactive_lo != b->hactive_lo)
125 if (a->hsync_off_hi != b->hsync_off_hi ||
126 a->hsync_off_lo != b->hsync_off_lo)
129 if (a->hsync_pulse_width != b->hsync_pulse_width)
132 if (a->hblank_hi != b->hblank_hi ||
133 a->hblank_lo != b->hblank_lo)
136 if (a->vactive_hi != b->vactive_hi ||
137 a->vactive_lo != b->vactive_lo)
140 if (a->vsync_off != b->vsync_off)
143 if (a->vsync_pulse_width != b->vsync_pulse_width)
146 if (a->vblank_hi != b->vblank_hi ||
147 a->vblank_lo != b->vblank_lo)
153 static const struct lvds_dvo_timing *
154 get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
155 const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
159 * the size of fp_timing varies on the different platform.
160 * So calculate the DVO timing relative offset in LVDS data
161 * entry to get the DVO timing entry
165 lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
166 lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
167 int dvo_timing_offset =
168 lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
169 lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
170 const char *entry = (const char *)lvds_lfp_data->data + lfp_data_size * index;
172 return (const struct lvds_dvo_timing *)(entry + dvo_timing_offset);
175 /* get lvds_fp_timing entry
176 * this function may return NULL if the corresponding entry is invalid
178 static const struct lvds_fp_timing *
179 get_lvds_fp_timing(const struct bdb_header *bdb,
180 const struct bdb_lvds_lfp_data *data,
181 const struct bdb_lvds_lfp_data_ptrs *ptrs,
184 size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
185 u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
188 if (index >= ARRAY_SIZE(ptrs->ptr))
190 ofs = ptrs->ptr[index].fp_timing_offset;
191 if (ofs < data_ofs ||
192 ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
194 return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
197 /* Try to find integrated panel data */
199 parse_lfp_panel_data(struct drm_i915_private *dev_priv,
200 struct bdb_header *bdb)
202 const struct bdb_lvds_options *lvds_options;
203 const struct bdb_lvds_lfp_data *lvds_lfp_data;
204 const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
205 const struct lvds_dvo_timing *panel_dvo_timing;
206 const struct lvds_fp_timing *fp_timing;
207 struct drm_display_mode *panel_fixed_mode;
210 lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
214 dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
215 if (lvds_options->panel_type == 0xff)
218 panel_type = lvds_options->panel_type;
220 lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
224 lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
225 if (!lvds_lfp_data_ptrs)
228 dev_priv->vbt.lvds_vbt = 1;
230 panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
232 lvds_options->panel_type);
234 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
235 if (!panel_fixed_mode)
238 fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
240 dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
242 DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
243 drm_mode_debug_printmodeline(panel_fixed_mode);
246 * Iterate over the LVDS panel timing info to find the lowest clock
247 * for the native resolution.
249 downclock = panel_dvo_timing->clock;
250 for (i = 0; i < 16; i++) {
251 const struct lvds_dvo_timing *dvo_timing;
253 dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
256 if (lvds_dvo_timing_equal_size(dvo_timing, panel_dvo_timing) &&
257 dvo_timing->clock < downclock)
258 downclock = dvo_timing->clock;
261 if (downclock < panel_dvo_timing->clock && i915_lvds_downclock) {
262 dev_priv->lvds_downclock_avail = 1;
263 dev_priv->lvds_downclock = downclock * 10;
264 DRM_DEBUG_KMS("LVDS downclock is found in VBT. "
265 "Normal Clock %dKHz, downclock %dKHz\n",
266 panel_fixed_mode->clock, 10*downclock);
269 fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
271 lvds_options->panel_type);
273 /* check the resolution, just to be sure */
274 if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
275 fp_timing->y_res == panel_fixed_mode->vdisplay) {
276 dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
277 DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
278 dev_priv->vbt.bios_lvds_val);
284 parse_lfp_backlight(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
286 const struct bdb_lfp_backlight_data *backlight_data;
287 const struct bdb_lfp_backlight_data_entry *entry;
289 backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
293 if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
294 DRM_DEBUG_KMS("Unsupported backlight data entry size %u\n",
295 backlight_data->entry_size);
299 entry = &backlight_data->data[panel_type];
301 dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
302 dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
303 DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
304 "active %s, min brightness %u, level %u\n",
305 dev_priv->vbt.backlight.pwm_freq_hz,
306 dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
307 entry->min_brightness,
308 backlight_data->level[panel_type]);
311 /* Try to find sdvo panel data */
313 parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
314 struct bdb_header *bdb)
316 struct lvds_dvo_timing *dvo_timing;
317 struct drm_display_mode *panel_fixed_mode;
320 index = i915_vbt_sdvo_panel_type;
322 DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
327 struct bdb_sdvo_lvds_options *sdvo_lvds_options;
329 sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
330 if (!sdvo_lvds_options)
333 index = sdvo_lvds_options->panel_type;
336 dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
340 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
341 if (!panel_fixed_mode)
344 fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
346 dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
348 DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
349 drm_mode_debug_printmodeline(panel_fixed_mode);
352 static int intel_bios_ssc_frequency(struct drm_device *dev,
355 switch (INTEL_INFO(dev)->gen) {
357 return alternate ? 66667 : 48000;
360 return alternate ? 100000 : 96000;
362 return alternate ? 100000 : 120000;
367 parse_general_features(struct drm_i915_private *dev_priv,
368 struct bdb_header *bdb)
370 struct drm_device *dev = dev_priv->dev;
371 struct bdb_general_features *general;
373 general = find_section(bdb, BDB_GENERAL_FEATURES);
375 dev_priv->vbt.int_tv_support = general->int_tv_support;
376 dev_priv->vbt.int_crt_support = general->int_crt_support;
377 dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
378 dev_priv->vbt.lvds_ssc_freq =
379 intel_bios_ssc_frequency(dev, general->ssc_freq);
380 dev_priv->vbt.display_clock_mode = general->display_clock_mode;
381 dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
382 DRM_DEBUG_KMS("BDB_GENERAL_FEATURES int_tv_support %d int_crt_support %d lvds_use_ssc %d lvds_ssc_freq %d display_clock_mode %d fdi_rx_polarity_inverted %d\n",
383 dev_priv->vbt.int_tv_support,
384 dev_priv->vbt.int_crt_support,
385 dev_priv->vbt.lvds_use_ssc,
386 dev_priv->vbt.lvds_ssc_freq,
387 dev_priv->vbt.display_clock_mode,
388 dev_priv->vbt.fdi_rx_polarity_inverted);
393 parse_general_definitions(struct drm_i915_private *dev_priv,
394 struct bdb_header *bdb)
396 struct bdb_general_definitions *general;
398 general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
400 u16 block_size = get_blocksize(general);
401 if (block_size >= sizeof(*general)) {
402 int bus_pin = general->crt_ddc_gmbus_pin;
403 DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
404 if (intel_gmbus_is_port_valid(bus_pin))
405 dev_priv->vbt.crt_ddc_pin = bus_pin;
407 DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
414 parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
415 struct bdb_header *bdb)
417 struct sdvo_device_mapping *p_mapping;
418 struct bdb_general_definitions *p_defs;
419 union child_device_config *p_child;
420 int i, child_device_num, count;
423 p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
425 DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
428 /* judge whether the size of child device meets the requirements.
429 * If the child device size obtained from general definition block
430 * is different with sizeof(struct child_device_config), skip the
431 * parsing of sdvo device info
433 if (p_defs->child_dev_size != sizeof(*p_child)) {
434 /* different child dev size . Ignore it */
435 DRM_DEBUG_KMS("different child size is found. Invalid.\n");
438 /* get the block size of general definitions */
439 block_size = get_blocksize(p_defs);
440 /* get the number of child device */
441 child_device_num = (block_size - sizeof(*p_defs)) /
444 for (i = 0; i < child_device_num; i++) {
445 p_child = &(p_defs->devices[i]);
446 if (!p_child->old.device_type) {
447 /* skip the device block if device type is invalid */
450 if (p_child->old.slave_addr != SLAVE_ADDR1 &&
451 p_child->old.slave_addr != SLAVE_ADDR2) {
453 * If the slave address is neither 0x70 nor 0x72,
454 * it is not a SDVO device. Skip it.
458 if (p_child->old.dvo_port != DEVICE_PORT_DVOB &&
459 p_child->old.dvo_port != DEVICE_PORT_DVOC) {
460 /* skip the incorrect SDVO port */
461 DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
464 DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
466 p_child->old.slave_addr,
467 (p_child->old.dvo_port == DEVICE_PORT_DVOB) ?
469 p_mapping = &(dev_priv->sdvo_mappings[p_child->old.dvo_port - 1]);
470 if (!p_mapping->initialized) {
471 p_mapping->dvo_port = p_child->old.dvo_port;
472 p_mapping->slave_addr = p_child->old.slave_addr;
473 p_mapping->dvo_wiring = p_child->old.dvo_wiring;
474 p_mapping->ddc_pin = p_child->old.ddc_pin;
475 p_mapping->i2c_pin = p_child->old.i2c_pin;
476 p_mapping->initialized = 1;
477 DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
479 p_mapping->slave_addr,
480 p_mapping->dvo_wiring,
484 DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
485 "two SDVO device.\n");
487 if (p_child->old.slave2_addr) {
488 /* Maybe this is a SDVO device with multiple inputs */
489 /* And the mapping info is not added */
490 DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
491 " is a SDVO device with multiple inputs.\n");
497 /* No SDVO device info is found */
498 DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
504 parse_driver_features(struct drm_i915_private *dev_priv,
505 struct bdb_header *bdb)
507 struct bdb_driver_features *driver;
509 driver = find_section(bdb, BDB_DRIVER_FEATURES);
513 if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
514 dev_priv->vbt.edp_support = 1;
516 if (driver->dual_frequency)
517 dev_priv->render_reclock_avail = true;
521 parse_edp(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
524 struct edp_power_seq *edp_pps;
525 struct edp_link_params *edp_link_params;
527 edp = find_section(bdb, BDB_EDP);
529 if (dev_priv->vbt.edp_support)
530 DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
534 switch ((edp->color_depth >> (panel_type * 2)) & 3) {
536 dev_priv->vbt.edp_bpp = 18;
539 dev_priv->vbt.edp_bpp = 24;
542 dev_priv->vbt.edp_bpp = 30;
546 /* Get the eDP sequencing and link info */
547 edp_pps = &edp->power_seqs[panel_type];
548 edp_link_params = &edp->link_params[panel_type];
550 dev_priv->vbt.edp_pps = *edp_pps;
552 dev_priv->vbt.edp_rate = edp_link_params->rate ? DP_LINK_BW_2_7 :
554 switch (edp_link_params->lanes) {
556 dev_priv->vbt.edp_lanes = 1;
559 dev_priv->vbt.edp_lanes = 2;
563 dev_priv->vbt.edp_lanes = 4;
566 switch (edp_link_params->preemphasis) {
568 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_0;
571 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_3_5;
574 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_6;
577 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_9_5;
580 switch (edp_link_params->vswing) {
582 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_400;
585 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_600;
588 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_800;
591 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_1200;
597 parse_mipi(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
599 struct bdb_mipi *mipi;
601 mipi = find_section(bdb, BDB_MIPI);
603 DRM_DEBUG_KMS("No MIPI BDB found");
607 /* XXX: add more info */
608 dev_priv->vbt.dsi.panel_id = mipi->panel_id;
611 static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
612 struct bdb_header *bdb)
614 union child_device_config *it, *child = NULL;
615 struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
616 uint8_t hdmi_level_shift;
618 bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
620 /* Each DDI port can have more than one value on the "DVO Port" field,
621 * so look for all the possible values for each port and abort if more
622 * than one is found. */
623 int dvo_ports[][2] = {
624 {DVO_PORT_HDMIA, DVO_PORT_DPA},
625 {DVO_PORT_HDMIB, DVO_PORT_DPB},
626 {DVO_PORT_HDMIC, DVO_PORT_DPC},
627 {DVO_PORT_HDMID, DVO_PORT_DPD},
628 {DVO_PORT_CRT, -1 /* Port E can only be DVO_PORT_CRT */ },
631 /* Find the child device to use, abort if more than one found. */
632 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
633 it = dev_priv->vbt.child_dev + i;
635 for (j = 0; j < 2; j++) {
636 if (dvo_ports[port][j] == -1)
639 if (it->common.dvo_port == dvo_ports[port][j]) {
641 DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
652 aux_channel = child->raw[25];
654 is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
655 is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
656 is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
657 is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
658 is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
660 info->supports_dvi = is_dvi;
661 info->supports_hdmi = is_hdmi;
662 info->supports_dp = is_dp;
664 DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
665 port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
667 if (is_edp && is_dvi)
668 DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
670 if (is_crt && port != PORT_E)
671 DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
672 if (is_crt && (is_dvi || is_dp))
673 DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
675 if (is_dvi && (port == PORT_A || port == PORT_E))
676 DRM_DEBUG_KMS("Port %c is TMDS compabile\n", port_name(port));
677 if (!is_dvi && !is_dp && !is_crt)
678 DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
680 if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
681 DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
684 if (child->common.ddc_pin == 0x05 && port != PORT_B)
685 DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
686 if (child->common.ddc_pin == 0x04 && port != PORT_C)
687 DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
688 if (child->common.ddc_pin == 0x06 && port != PORT_D)
689 DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
693 if (aux_channel == 0x40 && port != PORT_A)
694 DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
695 if (aux_channel == 0x10 && port != PORT_B)
696 DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
697 if (aux_channel == 0x20 && port != PORT_C)
698 DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
699 if (aux_channel == 0x30 && port != PORT_D)
700 DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
703 if (bdb->version >= 158) {
704 /* The VBT HDMI level shift values match the table we have. */
705 hdmi_level_shift = child->raw[7] & 0xF;
706 if (hdmi_level_shift < 0xC) {
707 DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
710 info->hdmi_level_shift = hdmi_level_shift;
715 static void parse_ddi_ports(struct drm_i915_private *dev_priv,
716 struct bdb_header *bdb)
718 struct drm_device *dev = dev_priv->dev;
724 if (!dev_priv->vbt.child_dev_num)
727 if (bdb->version < 155)
730 for (port = PORT_A; port < I915_MAX_PORTS; port++)
731 parse_ddi_port(dev_priv, port, bdb);
735 parse_device_mapping(struct drm_i915_private *dev_priv,
736 struct bdb_header *bdb)
738 struct bdb_general_definitions *p_defs;
739 union child_device_config *p_child, *child_dev_ptr;
740 int i, child_device_num, count;
743 p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
745 DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
748 /* judge whether the size of child device meets the requirements.
749 * If the child device size obtained from general definition block
750 * is different with sizeof(struct child_device_config), skip the
751 * parsing of sdvo device info
753 if (p_defs->child_dev_size != sizeof(*p_child)) {
754 /* different child dev size . Ignore it */
755 DRM_DEBUG_KMS("different child size is found. Invalid.\n");
758 /* get the block size of general definitions */
759 block_size = get_blocksize(p_defs);
760 /* get the number of child device */
761 child_device_num = (block_size - sizeof(*p_defs)) /
764 /* get the number of child device that is present */
765 for (i = 0; i < child_device_num; i++) {
766 p_child = &(p_defs->devices[i]);
767 if (!p_child->common.device_type) {
768 /* skip the device block if device type is invalid */
774 DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
777 dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
778 if (!dev_priv->vbt.child_dev) {
779 DRM_DEBUG_KMS("No memory space for child device\n");
783 dev_priv->vbt.child_dev_num = count;
785 for (i = 0; i < child_device_num; i++) {
786 p_child = &(p_defs->devices[i]);
787 if (!p_child->common.device_type) {
788 /* skip the device block if device type is invalid */
791 child_dev_ptr = dev_priv->vbt.child_dev + count;
793 memcpy((void *)child_dev_ptr, (void *)p_child,
800 init_vbt_defaults(struct drm_i915_private *dev_priv)
802 struct drm_device *dev = dev_priv->dev;
805 dev_priv->vbt.crt_ddc_pin = GMBUS_PORT_VGADDC;
808 dev_priv->vbt.lvds_dither = 1;
809 dev_priv->vbt.lvds_vbt = 0;
811 /* SDVO panel data */
812 dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
814 /* general features */
815 dev_priv->vbt.int_tv_support = 1;
816 dev_priv->vbt.int_crt_support = 1;
818 /* Default to using SSC */
819 dev_priv->vbt.lvds_use_ssc = 1;
821 * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
824 dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev,
825 !HAS_PCH_SPLIT(dev));
826 DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
828 for (port = PORT_A; port < I915_MAX_PORTS; port++) {
829 struct ddi_vbt_port_info *info =
830 &dev_priv->vbt.ddi_port_info[port];
832 /* Recommended BSpec default: 800mV 0dB. */
833 info->hdmi_level_shift = 6;
835 info->supports_dvi = (port != PORT_A && port != PORT_E);
836 info->supports_hdmi = info->supports_dvi;
837 info->supports_dp = (port != PORT_E);
841 static int __init intel_no_opregion_vbt_callback(const struct dmi_system_id *id)
843 DRM_DEBUG_KMS("Falling back to manually reading VBT from "
844 "VBIOS ROM for %s\n",
849 static const struct dmi_system_id intel_no_opregion_vbt[] = {
851 .callback = intel_no_opregion_vbt_callback,
852 .ident = "ThinkCentre A57",
854 DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
855 DMI_MATCH(DMI_PRODUCT_NAME, "97027RG"),
862 * intel_parse_bios - find VBT and initialize settings from the BIOS
865 * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
866 * to appropriate values.
868 * Returns 0 on success, nonzero on failure.
871 intel_parse_bios(struct drm_device *dev)
873 struct drm_i915_private *dev_priv = dev->dev_private;
874 struct bdb_header *bdb = NULL;
875 u8 __iomem *bios = NULL;
877 if (HAS_PCH_NOP(dev))
880 init_vbt_defaults(dev_priv);
882 /* XXX Should this validation be moved to intel_opregion.c? */
883 if (!dmi_check_system(intel_no_opregion_vbt) && dev_priv->opregion.vbt) {
884 struct vbt_header *vbt = dev_priv->opregion.vbt;
885 if (memcmp(vbt->signature, "$VBT", 4) == 0) {
886 DRM_DEBUG_KMS("Using VBT from OpRegion: %20s\n",
888 bdb = (struct bdb_header *)((char *)vbt + vbt->bdb_offset);
890 dev_priv->opregion.vbt = NULL;
901 struct vbt_header *vbt = NULL;
905 bios = pci_map_rom(pdev, &size);
909 /* Scour memory looking for the VBT signature */
910 for (i = 0; i + 4 < size; i++) {
911 if (!memcmp(bios + i, "$VBT", 4)) {
912 vbt = (struct vbt_header *)(bios + i);
918 DRM_DEBUG_DRIVER("VBT signature missing\n");
919 pci_unmap_rom(pdev, bios);
923 bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
927 /* Grab useful general definitions */
928 parse_general_features(dev_priv, bdb);
929 parse_general_definitions(dev_priv, bdb);
930 parse_lfp_panel_data(dev_priv, bdb);
931 parse_lfp_backlight(dev_priv, bdb);
932 parse_sdvo_panel_data(dev_priv, bdb);
933 parse_sdvo_device_mapping(dev_priv, bdb);
934 parse_device_mapping(dev_priv, bdb);
935 parse_driver_features(dev_priv, bdb);
936 parse_edp(dev_priv, bdb);
937 parse_mipi(dev_priv, bdb);
938 parse_ddi_ports(dev_priv, bdb);
942 pci_unmap_rom(pdev, bios);
948 /* Ensure that vital registers have been initialised, even if the BIOS
949 * is absent or just failing to do its job.
951 void intel_setup_bios(struct drm_device *dev)
953 struct drm_i915_private *dev_priv = dev->dev_private;
955 /* Set the Panel Power On/Off timings if uninitialized. */
956 if (!HAS_PCH_SPLIT(dev) &&
957 I915_READ(PP_ON_DELAYS) == 0 && I915_READ(PP_OFF_DELAYS) == 0) {
958 /* Set T2 to 40ms and T5 to 200ms */
959 I915_WRITE(PP_ON_DELAYS, 0x019007d0);
961 /* Set T3 to 35ms and Tx to 200ms */
962 I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);