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>
30 #include <drm/i915_drm.h>
32 #include <linux/dmi.h>
34 #define _INTEL_BIOS_PRIVATE
35 #include "intel_vbt_defs.h"
38 * DOC: Video BIOS Table (VBT)
40 * The Video BIOS Table, or VBT, provides platform and board specific
41 * configuration information to the driver that is not discoverable or available
42 * through other means. The configuration is mostly related to display
43 * hardware. The VBT is available via the ACPI OpRegion or, on older systems, in
46 * The VBT consists of a VBT Header (defined as &struct vbt_header), a BDB
47 * Header (&struct bdb_header), and a number of BIOS Data Blocks (BDB) that
48 * contain the actual configuration information. The VBT Header, and thus the
49 * VBT, begins with "$VBT" signature. The VBT Header contains the offset of the
50 * BDB Header. The data blocks are concatenated after the BDB Header. The data
51 * blocks have a 1-byte Block ID, 2-byte Block Size, and Block Size bytes of
52 * data. (Block 53, the MIPI Sequence Block is an exception.)
54 * The driver parses the VBT during load. The relevant information is stored in
55 * driver private data for ease of use, and the actual VBT is not read after
59 #define SLAVE_ADDR1 0x70
60 #define SLAVE_ADDR2 0x72
62 /* Get BDB block size given a pointer to Block ID. */
63 static u32
_get_blocksize(const u8
*block_base
)
65 /* The MIPI Sequence Block v3+ has a separate size field. */
66 if (*block_base
== BDB_MIPI_SEQUENCE
&& *(block_base
+ 3) >= 3)
67 return *((const u32
*)(block_base
+ 4));
69 return *((const u16
*)(block_base
+ 1));
72 /* Get BDB block size give a pointer to data after Block ID and Block Size. */
73 static u32
get_blocksize(const void *block_data
)
75 return _get_blocksize(block_data
- 3);
79 find_section(const void *_bdb
, int section_id
)
81 const struct bdb_header
*bdb
= _bdb
;
82 const u8
*base
= _bdb
;
84 u32 total
, current_size
;
87 /* skip to first section */
88 index
+= bdb
->header_size
;
89 total
= bdb
->bdb_size
;
91 /* walk the sections looking for section_id */
92 while (index
+ 3 < total
) {
93 current_id
= *(base
+ index
);
94 current_size
= _get_blocksize(base
+ index
);
97 if (index
+ current_size
> total
)
100 if (current_id
== section_id
)
103 index
+= current_size
;
110 fill_detail_timing_data(struct drm_display_mode
*panel_fixed_mode
,
111 const struct lvds_dvo_timing
*dvo_timing
)
113 panel_fixed_mode
->hdisplay
= (dvo_timing
->hactive_hi
<< 8) |
114 dvo_timing
->hactive_lo
;
115 panel_fixed_mode
->hsync_start
= panel_fixed_mode
->hdisplay
+
116 ((dvo_timing
->hsync_off_hi
<< 8) | dvo_timing
->hsync_off_lo
);
117 panel_fixed_mode
->hsync_end
= panel_fixed_mode
->hsync_start
+
118 ((dvo_timing
->hsync_pulse_width_hi
<< 8) |
119 dvo_timing
->hsync_pulse_width_lo
);
120 panel_fixed_mode
->htotal
= panel_fixed_mode
->hdisplay
+
121 ((dvo_timing
->hblank_hi
<< 8) | dvo_timing
->hblank_lo
);
123 panel_fixed_mode
->vdisplay
= (dvo_timing
->vactive_hi
<< 8) |
124 dvo_timing
->vactive_lo
;
125 panel_fixed_mode
->vsync_start
= panel_fixed_mode
->vdisplay
+
126 ((dvo_timing
->vsync_off_hi
<< 4) | dvo_timing
->vsync_off_lo
);
127 panel_fixed_mode
->vsync_end
= panel_fixed_mode
->vsync_start
+
128 ((dvo_timing
->vsync_pulse_width_hi
<< 4) |
129 dvo_timing
->vsync_pulse_width_lo
);
130 panel_fixed_mode
->vtotal
= panel_fixed_mode
->vdisplay
+
131 ((dvo_timing
->vblank_hi
<< 8) | dvo_timing
->vblank_lo
);
132 panel_fixed_mode
->clock
= dvo_timing
->clock
* 10;
133 panel_fixed_mode
->type
= DRM_MODE_TYPE_PREFERRED
;
135 if (dvo_timing
->hsync_positive
)
136 panel_fixed_mode
->flags
|= DRM_MODE_FLAG_PHSYNC
;
138 panel_fixed_mode
->flags
|= DRM_MODE_FLAG_NHSYNC
;
140 if (dvo_timing
->vsync_positive
)
141 panel_fixed_mode
->flags
|= DRM_MODE_FLAG_PVSYNC
;
143 panel_fixed_mode
->flags
|= DRM_MODE_FLAG_NVSYNC
;
145 panel_fixed_mode
->width_mm
= (dvo_timing
->himage_hi
<< 8) |
146 dvo_timing
->himage_lo
;
147 panel_fixed_mode
->height_mm
= (dvo_timing
->vimage_hi
<< 8) |
148 dvo_timing
->vimage_lo
;
150 /* Some VBTs have bogus h/vtotal values */
151 if (panel_fixed_mode
->hsync_end
> panel_fixed_mode
->htotal
)
152 panel_fixed_mode
->htotal
= panel_fixed_mode
->hsync_end
+ 1;
153 if (panel_fixed_mode
->vsync_end
> panel_fixed_mode
->vtotal
)
154 panel_fixed_mode
->vtotal
= panel_fixed_mode
->vsync_end
+ 1;
156 drm_mode_set_name(panel_fixed_mode
);
159 static const struct lvds_dvo_timing
*
160 get_lvds_dvo_timing(const struct bdb_lvds_lfp_data
*lvds_lfp_data
,
161 const struct bdb_lvds_lfp_data_ptrs
*lvds_lfp_data_ptrs
,
165 * the size of fp_timing varies on the different platform.
166 * So calculate the DVO timing relative offset in LVDS data
167 * entry to get the DVO timing entry
171 lvds_lfp_data_ptrs
->ptr
[1].dvo_timing_offset
-
172 lvds_lfp_data_ptrs
->ptr
[0].dvo_timing_offset
;
173 int dvo_timing_offset
=
174 lvds_lfp_data_ptrs
->ptr
[0].dvo_timing_offset
-
175 lvds_lfp_data_ptrs
->ptr
[0].fp_timing_offset
;
176 char *entry
= (char *)lvds_lfp_data
->data
+ lfp_data_size
* index
;
178 return (struct lvds_dvo_timing
*)(entry
+ dvo_timing_offset
);
181 /* get lvds_fp_timing entry
182 * this function may return NULL if the corresponding entry is invalid
184 static const struct lvds_fp_timing
*
185 get_lvds_fp_timing(const struct bdb_header
*bdb
,
186 const struct bdb_lvds_lfp_data
*data
,
187 const struct bdb_lvds_lfp_data_ptrs
*ptrs
,
190 size_t data_ofs
= (const u8
*)data
- (const u8
*)bdb
;
191 u16 data_size
= ((const u16
*)data
)[-1]; /* stored in header */
194 if (index
>= ARRAY_SIZE(ptrs
->ptr
))
196 ofs
= ptrs
->ptr
[index
].fp_timing_offset
;
197 if (ofs
< data_ofs
||
198 ofs
+ sizeof(struct lvds_fp_timing
) > data_ofs
+ data_size
)
200 return (const struct lvds_fp_timing
*)((const u8
*)bdb
+ ofs
);
203 /* Try to find integrated panel data */
205 parse_lfp_panel_data(struct drm_i915_private
*dev_priv
,
206 const struct bdb_header
*bdb
)
208 const struct bdb_lvds_options
*lvds_options
;
209 const struct bdb_lvds_lfp_data
*lvds_lfp_data
;
210 const struct bdb_lvds_lfp_data_ptrs
*lvds_lfp_data_ptrs
;
211 const struct lvds_dvo_timing
*panel_dvo_timing
;
212 const struct lvds_fp_timing
*fp_timing
;
213 struct drm_display_mode
*panel_fixed_mode
;
218 lvds_options
= find_section(bdb
, BDB_LVDS_OPTIONS
);
222 dev_priv
->vbt
.lvds_dither
= lvds_options
->pixel_dither
;
224 ret
= intel_opregion_get_panel_type(dev_priv
);
228 DRM_DEBUG_KMS("Panel type: %d (OpRegion)\n", panel_type
);
230 if (lvds_options
->panel_type
> 0xf) {
231 DRM_DEBUG_KMS("Invalid VBT panel type 0x%x\n",
232 lvds_options
->panel_type
);
235 panel_type
= lvds_options
->panel_type
;
236 DRM_DEBUG_KMS("Panel type: %d (VBT)\n", panel_type
);
239 dev_priv
->vbt
.panel_type
= panel_type
;
241 drrs_mode
= (lvds_options
->dps_panel_type_bits
242 >> (panel_type
* 2)) & MODE_MASK
;
244 * VBT has static DRRS = 0 and seamless DRRS = 2.
245 * The below piece of code is required to adjust vbt.drrs_type
246 * to match the enum drrs_support_type.
250 dev_priv
->vbt
.drrs_type
= STATIC_DRRS_SUPPORT
;
251 DRM_DEBUG_KMS("DRRS supported mode is static\n");
254 dev_priv
->vbt
.drrs_type
= SEAMLESS_DRRS_SUPPORT
;
255 DRM_DEBUG_KMS("DRRS supported mode is seamless\n");
258 dev_priv
->vbt
.drrs_type
= DRRS_NOT_SUPPORTED
;
259 DRM_DEBUG_KMS("DRRS not supported (VBT input)\n");
263 lvds_lfp_data
= find_section(bdb
, BDB_LVDS_LFP_DATA
);
267 lvds_lfp_data_ptrs
= find_section(bdb
, BDB_LVDS_LFP_DATA_PTRS
);
268 if (!lvds_lfp_data_ptrs
)
271 dev_priv
->vbt
.lvds_vbt
= 1;
273 panel_dvo_timing
= get_lvds_dvo_timing(lvds_lfp_data
,
277 panel_fixed_mode
= kzalloc(sizeof(*panel_fixed_mode
), GFP_KERNEL
);
278 if (!panel_fixed_mode
)
281 fill_detail_timing_data(panel_fixed_mode
, panel_dvo_timing
);
283 dev_priv
->vbt
.lfp_lvds_vbt_mode
= panel_fixed_mode
;
285 DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
286 drm_mode_debug_printmodeline(panel_fixed_mode
);
288 fp_timing
= get_lvds_fp_timing(bdb
, lvds_lfp_data
,
292 /* check the resolution, just to be sure */
293 if (fp_timing
->x_res
== panel_fixed_mode
->hdisplay
&&
294 fp_timing
->y_res
== panel_fixed_mode
->vdisplay
) {
295 dev_priv
->vbt
.bios_lvds_val
= fp_timing
->lvds_reg_val
;
296 DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
297 dev_priv
->vbt
.bios_lvds_val
);
303 parse_lfp_backlight(struct drm_i915_private
*dev_priv
,
304 const struct bdb_header
*bdb
)
306 const struct bdb_lfp_backlight_data
*backlight_data
;
307 const struct bdb_lfp_backlight_data_entry
*entry
;
308 int panel_type
= dev_priv
->vbt
.panel_type
;
310 backlight_data
= find_section(bdb
, BDB_LVDS_BACKLIGHT
);
314 if (backlight_data
->entry_size
!= sizeof(backlight_data
->data
[0])) {
315 DRM_DEBUG_KMS("Unsupported backlight data entry size %u\n",
316 backlight_data
->entry_size
);
320 entry
= &backlight_data
->data
[panel_type
];
322 dev_priv
->vbt
.backlight
.present
= entry
->type
== BDB_BACKLIGHT_TYPE_PWM
;
323 if (!dev_priv
->vbt
.backlight
.present
) {
324 DRM_DEBUG_KMS("PWM backlight not present in VBT (type %u)\n",
329 dev_priv
->vbt
.backlight
.type
= INTEL_BACKLIGHT_DISPLAY_DDI
;
330 if (bdb
->version
>= 191 &&
331 get_blocksize(backlight_data
) >= sizeof(*backlight_data
)) {
332 const struct bdb_lfp_backlight_control_method
*method
;
334 method
= &backlight_data
->backlight_control
[panel_type
];
335 dev_priv
->vbt
.backlight
.type
= method
->type
;
336 dev_priv
->vbt
.backlight
.controller
= method
->controller
;
339 dev_priv
->vbt
.backlight
.pwm_freq_hz
= entry
->pwm_freq_hz
;
340 dev_priv
->vbt
.backlight
.active_low_pwm
= entry
->active_low_pwm
;
341 dev_priv
->vbt
.backlight
.min_brightness
= entry
->min_brightness
;
342 DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
343 "active %s, min brightness %u, level %u, controller %u\n",
344 dev_priv
->vbt
.backlight
.pwm_freq_hz
,
345 dev_priv
->vbt
.backlight
.active_low_pwm
? "low" : "high",
346 dev_priv
->vbt
.backlight
.min_brightness
,
347 backlight_data
->level
[panel_type
],
348 dev_priv
->vbt
.backlight
.controller
);
351 /* Try to find sdvo panel data */
353 parse_sdvo_panel_data(struct drm_i915_private
*dev_priv
,
354 const struct bdb_header
*bdb
)
356 const struct lvds_dvo_timing
*dvo_timing
;
357 struct drm_display_mode
*panel_fixed_mode
;
360 index
= i915
.vbt_sdvo_panel_type
;
362 DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
367 const struct bdb_sdvo_lvds_options
*sdvo_lvds_options
;
369 sdvo_lvds_options
= find_section(bdb
, BDB_SDVO_LVDS_OPTIONS
);
370 if (!sdvo_lvds_options
)
373 index
= sdvo_lvds_options
->panel_type
;
376 dvo_timing
= find_section(bdb
, BDB_SDVO_PANEL_DTDS
);
380 panel_fixed_mode
= kzalloc(sizeof(*panel_fixed_mode
), GFP_KERNEL
);
381 if (!panel_fixed_mode
)
384 fill_detail_timing_data(panel_fixed_mode
, dvo_timing
+ index
);
386 dev_priv
->vbt
.sdvo_lvds_vbt_mode
= panel_fixed_mode
;
388 DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
389 drm_mode_debug_printmodeline(panel_fixed_mode
);
392 static int intel_bios_ssc_frequency(struct drm_i915_private
*dev_priv
,
395 switch (INTEL_INFO(dev_priv
)->gen
) {
397 return alternate
? 66667 : 48000;
400 return alternate
? 100000 : 96000;
402 return alternate
? 100000 : 120000;
407 parse_general_features(struct drm_i915_private
*dev_priv
,
408 const struct bdb_header
*bdb
)
410 const struct bdb_general_features
*general
;
412 general
= find_section(bdb
, BDB_GENERAL_FEATURES
);
416 dev_priv
->vbt
.int_tv_support
= general
->int_tv_support
;
417 /* int_crt_support can't be trusted on earlier platforms */
418 if (bdb
->version
>= 155 &&
419 (HAS_DDI(dev_priv
) || IS_VALLEYVIEW(dev_priv
)))
420 dev_priv
->vbt
.int_crt_support
= general
->int_crt_support
;
421 dev_priv
->vbt
.lvds_use_ssc
= general
->enable_ssc
;
422 dev_priv
->vbt
.lvds_ssc_freq
=
423 intel_bios_ssc_frequency(dev_priv
, general
->ssc_freq
);
424 dev_priv
->vbt
.display_clock_mode
= general
->display_clock_mode
;
425 dev_priv
->vbt
.fdi_rx_polarity_inverted
= general
->fdi_rx_polarity_inverted
;
426 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",
427 dev_priv
->vbt
.int_tv_support
,
428 dev_priv
->vbt
.int_crt_support
,
429 dev_priv
->vbt
.lvds_use_ssc
,
430 dev_priv
->vbt
.lvds_ssc_freq
,
431 dev_priv
->vbt
.display_clock_mode
,
432 dev_priv
->vbt
.fdi_rx_polarity_inverted
);
436 parse_general_definitions(struct drm_i915_private
*dev_priv
,
437 const struct bdb_header
*bdb
)
439 const struct bdb_general_definitions
*general
;
441 general
= find_section(bdb
, BDB_GENERAL_DEFINITIONS
);
443 u16 block_size
= get_blocksize(general
);
444 if (block_size
>= sizeof(*general
)) {
445 int bus_pin
= general
->crt_ddc_gmbus_pin
;
446 DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin
);
447 if (intel_gmbus_is_valid_pin(dev_priv
, bus_pin
))
448 dev_priv
->vbt
.crt_ddc_pin
= bus_pin
;
450 DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
456 static const union child_device_config
*
457 child_device_ptr(const struct bdb_general_definitions
*p_defs
, int i
)
459 return (const void *) &p_defs
->devices
[i
* p_defs
->child_dev_size
];
463 parse_sdvo_device_mapping(struct drm_i915_private
*dev_priv
,
464 const struct bdb_header
*bdb
)
466 struct sdvo_device_mapping
*p_mapping
;
467 const struct bdb_general_definitions
*p_defs
;
468 const struct old_child_dev_config
*child
; /* legacy */
469 int i
, child_device_num
, count
;
472 p_defs
= find_section(bdb
, BDB_GENERAL_DEFINITIONS
);
474 DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
479 * Only parse SDVO mappings when the general definitions block child
480 * device size matches that of the *legacy* child device config
481 * struct. Thus, SDVO mapping will be skipped for newer VBT.
483 if (p_defs
->child_dev_size
!= sizeof(*child
)) {
484 DRM_DEBUG_KMS("Unsupported child device size for SDVO mapping.\n");
487 /* get the block size of general definitions */
488 block_size
= get_blocksize(p_defs
);
489 /* get the number of child device */
490 child_device_num
= (block_size
- sizeof(*p_defs
)) /
491 p_defs
->child_dev_size
;
493 for (i
= 0; i
< child_device_num
; i
++) {
494 child
= &child_device_ptr(p_defs
, i
)->old
;
495 if (!child
->device_type
) {
496 /* skip the device block if device type is invalid */
499 if (child
->slave_addr
!= SLAVE_ADDR1
&&
500 child
->slave_addr
!= SLAVE_ADDR2
) {
502 * If the slave address is neither 0x70 nor 0x72,
503 * it is not a SDVO device. Skip it.
507 if (child
->dvo_port
!= DEVICE_PORT_DVOB
&&
508 child
->dvo_port
!= DEVICE_PORT_DVOC
) {
509 /* skip the incorrect SDVO port */
510 DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
513 DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
516 (child
->dvo_port
== DEVICE_PORT_DVOB
) ?
518 p_mapping
= &dev_priv
->vbt
.sdvo_mappings
[child
->dvo_port
- 1];
519 if (!p_mapping
->initialized
) {
520 p_mapping
->dvo_port
= child
->dvo_port
;
521 p_mapping
->slave_addr
= child
->slave_addr
;
522 p_mapping
->dvo_wiring
= child
->dvo_wiring
;
523 p_mapping
->ddc_pin
= child
->ddc_pin
;
524 p_mapping
->i2c_pin
= child
->i2c_pin
;
525 p_mapping
->initialized
= 1;
526 DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
528 p_mapping
->slave_addr
,
529 p_mapping
->dvo_wiring
,
533 DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
534 "two SDVO device.\n");
536 if (child
->slave2_addr
) {
537 /* Maybe this is a SDVO device with multiple inputs */
538 /* And the mapping info is not added */
539 DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
540 " is a SDVO device with multiple inputs.\n");
546 /* No SDVO device info is found */
547 DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
553 parse_driver_features(struct drm_i915_private
*dev_priv
,
554 const struct bdb_header
*bdb
)
556 const struct bdb_driver_features
*driver
;
558 driver
= find_section(bdb
, BDB_DRIVER_FEATURES
);
562 if (driver
->lvds_config
== BDB_DRIVER_FEATURE_EDP
)
563 dev_priv
->vbt
.edp
.support
= 1;
565 DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver
->drrs_enabled
);
567 * If DRRS is not supported, drrs_type has to be set to 0.
568 * This is because, VBT is configured in such a way that
569 * static DRRS is 0 and DRRS not supported is represented by
570 * driver->drrs_enabled=false
572 if (!driver
->drrs_enabled
)
573 dev_priv
->vbt
.drrs_type
= DRRS_NOT_SUPPORTED
;
577 parse_edp(struct drm_i915_private
*dev_priv
, const struct bdb_header
*bdb
)
579 const struct bdb_edp
*edp
;
580 const struct edp_power_seq
*edp_pps
;
581 const struct edp_link_params
*edp_link_params
;
582 int panel_type
= dev_priv
->vbt
.panel_type
;
584 edp
= find_section(bdb
, BDB_EDP
);
586 if (dev_priv
->vbt
.edp
.support
)
587 DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
591 switch ((edp
->color_depth
>> (panel_type
* 2)) & 3) {
593 dev_priv
->vbt
.edp
.bpp
= 18;
596 dev_priv
->vbt
.edp
.bpp
= 24;
599 dev_priv
->vbt
.edp
.bpp
= 30;
603 /* Get the eDP sequencing and link info */
604 edp_pps
= &edp
->power_seqs
[panel_type
];
605 edp_link_params
= &edp
->link_params
[panel_type
];
607 dev_priv
->vbt
.edp
.pps
= *edp_pps
;
609 switch (edp_link_params
->rate
) {
611 dev_priv
->vbt
.edp
.rate
= DP_LINK_BW_1_62
;
614 dev_priv
->vbt
.edp
.rate
= DP_LINK_BW_2_7
;
617 DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
618 edp_link_params
->rate
);
622 switch (edp_link_params
->lanes
) {
624 dev_priv
->vbt
.edp
.lanes
= 1;
627 dev_priv
->vbt
.edp
.lanes
= 2;
630 dev_priv
->vbt
.edp
.lanes
= 4;
633 DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
634 edp_link_params
->lanes
);
638 switch (edp_link_params
->preemphasis
) {
639 case EDP_PREEMPHASIS_NONE
:
640 dev_priv
->vbt
.edp
.preemphasis
= DP_TRAIN_PRE_EMPH_LEVEL_0
;
642 case EDP_PREEMPHASIS_3_5dB
:
643 dev_priv
->vbt
.edp
.preemphasis
= DP_TRAIN_PRE_EMPH_LEVEL_1
;
645 case EDP_PREEMPHASIS_6dB
:
646 dev_priv
->vbt
.edp
.preemphasis
= DP_TRAIN_PRE_EMPH_LEVEL_2
;
648 case EDP_PREEMPHASIS_9_5dB
:
649 dev_priv
->vbt
.edp
.preemphasis
= DP_TRAIN_PRE_EMPH_LEVEL_3
;
652 DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
653 edp_link_params
->preemphasis
);
657 switch (edp_link_params
->vswing
) {
658 case EDP_VSWING_0_4V
:
659 dev_priv
->vbt
.edp
.vswing
= DP_TRAIN_VOLTAGE_SWING_LEVEL_0
;
661 case EDP_VSWING_0_6V
:
662 dev_priv
->vbt
.edp
.vswing
= DP_TRAIN_VOLTAGE_SWING_LEVEL_1
;
664 case EDP_VSWING_0_8V
:
665 dev_priv
->vbt
.edp
.vswing
= DP_TRAIN_VOLTAGE_SWING_LEVEL_2
;
667 case EDP_VSWING_1_2V
:
668 dev_priv
->vbt
.edp
.vswing
= DP_TRAIN_VOLTAGE_SWING_LEVEL_3
;
671 DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
672 edp_link_params
->vswing
);
676 if (bdb
->version
>= 173) {
679 /* Don't read from VBT if module parameter has valid value*/
680 if (i915
.edp_vswing
) {
681 dev_priv
->vbt
.edp
.low_vswing
= i915
.edp_vswing
== 1;
683 vswing
= (edp
->edp_vswing_preemph
>> (panel_type
* 4)) & 0xF;
684 dev_priv
->vbt
.edp
.low_vswing
= vswing
== 0;
690 parse_psr(struct drm_i915_private
*dev_priv
, const struct bdb_header
*bdb
)
692 const struct bdb_psr
*psr
;
693 const struct psr_table
*psr_table
;
694 int panel_type
= dev_priv
->vbt
.panel_type
;
696 psr
= find_section(bdb
, BDB_PSR
);
698 DRM_DEBUG_KMS("No PSR BDB found.\n");
702 psr_table
= &psr
->psr_table
[panel_type
];
704 dev_priv
->vbt
.psr
.full_link
= psr_table
->full_link
;
705 dev_priv
->vbt
.psr
.require_aux_wakeup
= psr_table
->require_aux_to_wakeup
;
707 /* Allowed VBT values goes from 0 to 15 */
708 dev_priv
->vbt
.psr
.idle_frames
= psr_table
->idle_frames
< 0 ? 0 :
709 psr_table
->idle_frames
> 15 ? 15 : psr_table
->idle_frames
;
711 switch (psr_table
->lines_to_wait
) {
713 dev_priv
->vbt
.psr
.lines_to_wait
= PSR_0_LINES_TO_WAIT
;
716 dev_priv
->vbt
.psr
.lines_to_wait
= PSR_1_LINE_TO_WAIT
;
719 dev_priv
->vbt
.psr
.lines_to_wait
= PSR_4_LINES_TO_WAIT
;
722 dev_priv
->vbt
.psr
.lines_to_wait
= PSR_8_LINES_TO_WAIT
;
725 DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
726 psr_table
->lines_to_wait
);
730 dev_priv
->vbt
.psr
.tp1_wakeup_time
= psr_table
->tp1_wakeup_time
;
731 dev_priv
->vbt
.psr
.tp2_tp3_wakeup_time
= psr_table
->tp2_tp3_wakeup_time
;
735 parse_mipi_config(struct drm_i915_private
*dev_priv
,
736 const struct bdb_header
*bdb
)
738 const struct bdb_mipi_config
*start
;
739 const struct mipi_config
*config
;
740 const struct mipi_pps_data
*pps
;
741 int panel_type
= dev_priv
->vbt
.panel_type
;
743 /* parse MIPI blocks only if LFP type is MIPI */
744 if (!intel_bios_is_dsi_present(dev_priv
, NULL
))
747 /* Initialize this to undefined indicating no generic MIPI support */
748 dev_priv
->vbt
.dsi
.panel_id
= MIPI_DSI_UNDEFINED_PANEL_ID
;
750 /* Block #40 is already parsed and panel_fixed_mode is
751 * stored in dev_priv->lfp_lvds_vbt_mode
752 * resuse this when needed
755 /* Parse #52 for panel index used from panel_type already
758 start
= find_section(bdb
, BDB_MIPI_CONFIG
);
760 DRM_DEBUG_KMS("No MIPI config BDB found");
764 DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
768 * get hold of the correct configuration block and pps data as per
769 * the panel_type as index
771 config
= &start
->config
[panel_type
];
772 pps
= &start
->pps
[panel_type
];
774 /* store as of now full data. Trim when we realise all is not needed */
775 dev_priv
->vbt
.dsi
.config
= kmemdup(config
, sizeof(struct mipi_config
), GFP_KERNEL
);
776 if (!dev_priv
->vbt
.dsi
.config
)
779 dev_priv
->vbt
.dsi
.pps
= kmemdup(pps
, sizeof(struct mipi_pps_data
), GFP_KERNEL
);
780 if (!dev_priv
->vbt
.dsi
.pps
) {
781 kfree(dev_priv
->vbt
.dsi
.config
);
786 * These fields are introduced from the VBT version 197 onwards,
787 * so making sure that these bits are set zero in the previous
790 if (dev_priv
->vbt
.dsi
.config
->dual_link
&& bdb
->version
< 197) {
791 dev_priv
->vbt
.dsi
.config
->dl_dcs_cabc_ports
= 0;
792 dev_priv
->vbt
.dsi
.config
->dl_dcs_backlight_ports
= 0;
795 /* We have mandatory mipi config blocks. Initialize as generic panel */
796 dev_priv
->vbt
.dsi
.panel_id
= MIPI_DSI_GENERIC_PANEL_ID
;
799 /* Find the sequence block and size for the given panel. */
801 find_panel_sequence_block(const struct bdb_mipi_sequence
*sequence
,
802 u16 panel_id
, u32
*seq_size
)
804 u32 total
= get_blocksize(sequence
);
805 const u8
*data
= &sequence
->data
[0];
808 int header_size
= sequence
->version
>= 3 ? 5 : 3;
812 /* skip new block size */
813 if (sequence
->version
>= 3)
816 for (i
= 0; i
< MAX_MIPI_CONFIGURATIONS
&& index
< total
; i
++) {
817 if (index
+ header_size
> total
) {
818 DRM_ERROR("Invalid sequence block (header)\n");
822 current_id
= *(data
+ index
);
823 if (sequence
->version
>= 3)
824 current_size
= *((const u32
*)(data
+ index
+ 1));
826 current_size
= *((const u16
*)(data
+ index
+ 1));
828 index
+= header_size
;
830 if (index
+ current_size
> total
) {
831 DRM_ERROR("Invalid sequence block\n");
835 if (current_id
== panel_id
) {
836 *seq_size
= current_size
;
840 index
+= current_size
;
843 DRM_ERROR("Sequence block detected but no valid configuration\n");
848 static int goto_next_sequence(const u8
*data
, int index
, int total
)
852 /* Skip Sequence Byte. */
853 for (index
= index
+ 1; index
< total
; index
+= len
) {
854 u8 operation_byte
= *(data
+ index
);
857 switch (operation_byte
) {
858 case MIPI_SEQ_ELEM_END
:
860 case MIPI_SEQ_ELEM_SEND_PKT
:
861 if (index
+ 4 > total
)
864 len
= *((const u16
*)(data
+ index
+ 2)) + 4;
866 case MIPI_SEQ_ELEM_DELAY
:
869 case MIPI_SEQ_ELEM_GPIO
:
872 case MIPI_SEQ_ELEM_I2C
:
873 if (index
+ 7 > total
)
875 len
= *(data
+ index
+ 6) + 7;
878 DRM_ERROR("Unknown operation byte\n");
886 static int goto_next_sequence_v3(const u8
*data
, int index
, int total
)
890 u32 size_of_sequence
;
893 * Could skip sequence based on Size of Sequence alone, but also do some
894 * checking on the structure.
897 DRM_ERROR("Too small sequence size\n");
901 /* Skip Sequence Byte. */
905 * Size of Sequence. Excludes the Sequence Byte and the size itself,
906 * includes MIPI_SEQ_ELEM_END byte, excludes the final MIPI_SEQ_END
909 size_of_sequence
= *((const uint32_t *)(data
+ index
));
912 seq_end
= index
+ size_of_sequence
;
913 if (seq_end
> total
) {
914 DRM_ERROR("Invalid sequence size\n");
918 for (; index
< total
; index
+= len
) {
919 u8 operation_byte
= *(data
+ index
);
922 if (operation_byte
== MIPI_SEQ_ELEM_END
) {
923 if (index
!= seq_end
) {
924 DRM_ERROR("Invalid element structure\n");
930 len
= *(data
+ index
);
934 * FIXME: Would be nice to check elements like for v1/v2 in
935 * goto_next_sequence() above.
937 switch (operation_byte
) {
938 case MIPI_SEQ_ELEM_SEND_PKT
:
939 case MIPI_SEQ_ELEM_DELAY
:
940 case MIPI_SEQ_ELEM_GPIO
:
941 case MIPI_SEQ_ELEM_I2C
:
942 case MIPI_SEQ_ELEM_SPI
:
943 case MIPI_SEQ_ELEM_PMIC
:
946 DRM_ERROR("Unknown operation byte %u\n",
956 parse_mipi_sequence(struct drm_i915_private
*dev_priv
,
957 const struct bdb_header
*bdb
)
959 int panel_type
= dev_priv
->vbt
.panel_type
;
960 const struct bdb_mipi_sequence
*sequence
;
966 /* Only our generic panel driver uses the sequence block. */
967 if (dev_priv
->vbt
.dsi
.panel_id
!= MIPI_DSI_GENERIC_PANEL_ID
)
970 sequence
= find_section(bdb
, BDB_MIPI_SEQUENCE
);
972 DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
976 /* Fail gracefully for forward incompatible sequence block. */
977 if (sequence
->version
>= 4) {
978 DRM_ERROR("Unable to parse MIPI Sequence Block v%u\n",
983 DRM_DEBUG_DRIVER("Found MIPI sequence block v%u\n", sequence
->version
);
985 seq_data
= find_panel_sequence_block(sequence
, panel_type
, &seq_size
);
989 data
= kmemdup(seq_data
, seq_size
, GFP_KERNEL
);
993 /* Parse the sequences, store pointers to each sequence. */
995 u8 seq_id
= *(data
+ index
);
996 if (seq_id
== MIPI_SEQ_END
)
999 if (seq_id
>= MIPI_SEQ_MAX
) {
1000 DRM_ERROR("Unknown sequence %u\n", seq_id
);
1004 /* Log about presence of sequences we won't run. */
1005 if (seq_id
== MIPI_SEQ_TEAR_ON
|| seq_id
== MIPI_SEQ_TEAR_OFF
)
1006 DRM_DEBUG_KMS("Unsupported sequence %u\n", seq_id
);
1008 dev_priv
->vbt
.dsi
.sequence
[seq_id
] = data
+ index
;
1010 if (sequence
->version
>= 3)
1011 index
= goto_next_sequence_v3(data
, index
, seq_size
);
1013 index
= goto_next_sequence(data
, index
, seq_size
);
1015 DRM_ERROR("Invalid sequence %u\n", seq_id
);
1020 dev_priv
->vbt
.dsi
.data
= data
;
1021 dev_priv
->vbt
.dsi
.size
= seq_size
;
1022 dev_priv
->vbt
.dsi
.seq_version
= sequence
->version
;
1024 DRM_DEBUG_DRIVER("MIPI related VBT parsing complete\n");
1029 memset(dev_priv
->vbt
.dsi
.sequence
, 0, sizeof(dev_priv
->vbt
.dsi
.sequence
));
1032 static u8
translate_iboost(u8 val
)
1034 static const u8 mapping
[] = { 1, 3, 7 }; /* See VBT spec */
1036 if (val
>= ARRAY_SIZE(mapping
)) {
1037 DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val
);
1040 return mapping
[val
];
1043 static void sanitize_ddc_pin(struct drm_i915_private
*dev_priv
,
1046 const struct ddi_vbt_port_info
*info
=
1047 &dev_priv
->vbt
.ddi_port_info
[port
];
1050 if (!info
->alternate_ddc_pin
)
1053 for_each_port_masked(p
, (1 << port
) - 1) {
1054 struct ddi_vbt_port_info
*i
= &dev_priv
->vbt
.ddi_port_info
[p
];
1056 if (info
->alternate_ddc_pin
!= i
->alternate_ddc_pin
)
1059 DRM_DEBUG_KMS("port %c trying to use the same DDC pin (0x%x) as port %c, "
1060 "disabling port %c DVI/HDMI support\n",
1061 port_name(p
), i
->alternate_ddc_pin
,
1062 port_name(port
), port_name(p
));
1065 * If we have multiple ports supposedly sharing the
1066 * pin, then dvi/hdmi couldn't exist on the shared
1067 * port. Otherwise they share the same ddc bin and
1068 * system couldn't communicate with them separately.
1070 * Due to parsing the ports in alphabetical order,
1071 * a higher port will always clobber a lower one.
1073 i
->supports_dvi
= false;
1074 i
->supports_hdmi
= false;
1075 i
->alternate_ddc_pin
= 0;
1079 static void sanitize_aux_ch(struct drm_i915_private
*dev_priv
,
1082 const struct ddi_vbt_port_info
*info
=
1083 &dev_priv
->vbt
.ddi_port_info
[port
];
1086 if (!info
->alternate_aux_channel
)
1089 for_each_port_masked(p
, (1 << port
) - 1) {
1090 struct ddi_vbt_port_info
*i
= &dev_priv
->vbt
.ddi_port_info
[p
];
1092 if (info
->alternate_aux_channel
!= i
->alternate_aux_channel
)
1095 DRM_DEBUG_KMS("port %c trying to use the same AUX CH (0x%x) as port %c, "
1096 "disabling port %c DP support\n",
1097 port_name(p
), i
->alternate_aux_channel
,
1098 port_name(port
), port_name(p
));
1101 * If we have multiple ports supposedlt sharing the
1102 * aux channel, then DP couldn't exist on the shared
1103 * port. Otherwise they share the same aux channel
1104 * and system couldn't communicate with them separately.
1106 * Due to parsing the ports in alphabetical order,
1107 * a higher port will always clobber a lower one.
1109 i
->supports_dp
= false;
1110 i
->alternate_aux_channel
= 0;
1114 static void parse_ddi_port(struct drm_i915_private
*dev_priv
, enum port port
,
1115 const struct bdb_header
*bdb
)
1117 union child_device_config
*it
, *child
= NULL
;
1118 struct ddi_vbt_port_info
*info
= &dev_priv
->vbt
.ddi_port_info
[port
];
1119 uint8_t hdmi_level_shift
;
1121 bool is_dvi
, is_hdmi
, is_dp
, is_edp
, is_crt
;
1122 uint8_t aux_channel
, ddc_pin
;
1123 /* Each DDI port can have more than one value on the "DVO Port" field,
1124 * so look for all the possible values for each port.
1126 int dvo_ports
[][3] = {
1127 {DVO_PORT_HDMIA
, DVO_PORT_DPA
, -1},
1128 {DVO_PORT_HDMIB
, DVO_PORT_DPB
, -1},
1129 {DVO_PORT_HDMIC
, DVO_PORT_DPC
, -1},
1130 {DVO_PORT_HDMID
, DVO_PORT_DPD
, -1},
1131 {DVO_PORT_CRT
, DVO_PORT_HDMIE
, DVO_PORT_DPE
},
1135 * Find the first child device to reference the port, report if more
1138 for (i
= 0; i
< dev_priv
->vbt
.child_dev_num
; i
++) {
1139 it
= dev_priv
->vbt
.child_dev
+ i
;
1141 for (j
= 0; j
< 3; j
++) {
1142 if (dvo_ports
[port
][j
] == -1)
1145 if (it
->common
.dvo_port
== dvo_ports
[port
][j
]) {
1147 DRM_DEBUG_KMS("More than one child device for port %c in VBT, using the first.\n",
1158 aux_channel
= child
->common
.aux_channel
;
1160 is_dvi
= child
->common
.device_type
& DEVICE_TYPE_TMDS_DVI_SIGNALING
;
1161 is_dp
= child
->common
.device_type
& DEVICE_TYPE_DISPLAYPORT_OUTPUT
;
1162 is_crt
= child
->common
.device_type
& DEVICE_TYPE_ANALOG_OUTPUT
;
1163 is_hdmi
= is_dvi
&& (child
->common
.device_type
& DEVICE_TYPE_NOT_HDMI_OUTPUT
) == 0;
1164 is_edp
= is_dp
&& (child
->common
.device_type
& DEVICE_TYPE_INTERNAL_CONNECTOR
);
1166 if (port
== PORT_A
&& is_dvi
) {
1167 DRM_DEBUG_KMS("VBT claims port A supports DVI%s, ignoring\n",
1168 is_hdmi
? "/HDMI" : "");
1173 info
->supports_dvi
= is_dvi
;
1174 info
->supports_hdmi
= is_hdmi
;
1175 info
->supports_dp
= is_dp
;
1176 info
->supports_edp
= is_edp
;
1178 DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
1179 port_name(port
), is_dp
, is_hdmi
, is_dvi
, is_edp
, is_crt
);
1181 if (is_edp
&& is_dvi
)
1182 DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
1184 if (is_crt
&& port
!= PORT_E
)
1185 DRM_DEBUG_KMS("Port %c is analog\n", port_name(port
));
1186 if (is_crt
&& (is_dvi
|| is_dp
))
1187 DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
1189 if (is_dvi
&& (port
== PORT_A
|| port
== PORT_E
))
1190 DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port
));
1191 if (!is_dvi
&& !is_dp
&& !is_crt
)
1192 DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
1194 if (is_edp
&& (port
== PORT_B
|| port
== PORT_C
|| port
== PORT_E
))
1195 DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port
));
1198 ddc_pin
= child
->common
.ddc_pin
;
1199 if (intel_gmbus_is_valid_pin(dev_priv
, ddc_pin
)) {
1200 info
->alternate_ddc_pin
= ddc_pin
;
1201 sanitize_ddc_pin(dev_priv
, port
);
1203 DRM_DEBUG_KMS("Port %c has invalid DDC pin %d, "
1204 "sticking to defaults\n",
1205 port_name(port
), ddc_pin
);
1210 info
->alternate_aux_channel
= aux_channel
;
1212 sanitize_aux_ch(dev_priv
, port
);
1215 if (bdb
->version
>= 158) {
1216 /* The VBT HDMI level shift values match the table we have. */
1217 hdmi_level_shift
= child
->raw
[7] & 0xF;
1218 DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
1221 info
->hdmi_level_shift
= hdmi_level_shift
;
1224 /* Parse the I_boost config for SKL and above */
1225 if (bdb
->version
>= 196 && child
->common
.iboost
) {
1226 info
->dp_boost_level
= translate_iboost(child
->common
.iboost_level
& 0xF);
1227 DRM_DEBUG_KMS("VBT (e)DP boost level for port %c: %d\n",
1228 port_name(port
), info
->dp_boost_level
);
1229 info
->hdmi_boost_level
= translate_iboost(child
->common
.iboost_level
>> 4);
1230 DRM_DEBUG_KMS("VBT HDMI boost level for port %c: %d\n",
1231 port_name(port
), info
->hdmi_boost_level
);
1235 static void parse_ddi_ports(struct drm_i915_private
*dev_priv
,
1236 const struct bdb_header
*bdb
)
1240 if (!HAS_DDI(dev_priv
) && !IS_CHERRYVIEW(dev_priv
))
1243 if (!dev_priv
->vbt
.child_dev_num
)
1246 if (bdb
->version
< 155)
1249 for (port
= PORT_A
; port
< I915_MAX_PORTS
; port
++)
1250 parse_ddi_port(dev_priv
, port
, bdb
);
1254 parse_device_mapping(struct drm_i915_private
*dev_priv
,
1255 const struct bdb_header
*bdb
)
1257 const struct bdb_general_definitions
*p_defs
;
1258 const union child_device_config
*p_child
;
1259 union child_device_config
*child_dev_ptr
;
1260 int i
, child_device_num
, count
;
1264 p_defs
= find_section(bdb
, BDB_GENERAL_DEFINITIONS
);
1266 DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
1269 if (bdb
->version
< 106) {
1271 } else if (bdb
->version
< 111) {
1273 } else if (bdb
->version
< 195) {
1274 BUILD_BUG_ON(sizeof(struct old_child_dev_config
) != 33);
1275 expected_size
= sizeof(struct old_child_dev_config
);
1276 } else if (bdb
->version
== 195) {
1278 } else if (bdb
->version
<= 197) {
1282 BUILD_BUG_ON(sizeof(*p_child
) < 38);
1283 DRM_DEBUG_DRIVER("Expected child device config size for VBT version %u not known; assuming %u\n",
1284 bdb
->version
, expected_size
);
1287 /* Flag an error for unexpected size, but continue anyway. */
1288 if (p_defs
->child_dev_size
!= expected_size
)
1289 DRM_ERROR("Unexpected child device config size %u (expected %u for VBT version %u)\n",
1290 p_defs
->child_dev_size
, expected_size
, bdb
->version
);
1292 /* The legacy sized child device config is the minimum we need. */
1293 if (p_defs
->child_dev_size
< sizeof(struct old_child_dev_config
)) {
1294 DRM_DEBUG_KMS("Child device config size %u is too small.\n",
1295 p_defs
->child_dev_size
);
1299 /* get the block size of general definitions */
1300 block_size
= get_blocksize(p_defs
);
1301 /* get the number of child device */
1302 child_device_num
= (block_size
- sizeof(*p_defs
)) /
1303 p_defs
->child_dev_size
;
1305 /* get the number of child device that is present */
1306 for (i
= 0; i
< child_device_num
; i
++) {
1307 p_child
= child_device_ptr(p_defs
, i
);
1308 if (!p_child
->common
.device_type
) {
1309 /* skip the device block if device type is invalid */
1315 DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
1318 dev_priv
->vbt
.child_dev
= kcalloc(count
, sizeof(*p_child
), GFP_KERNEL
);
1319 if (!dev_priv
->vbt
.child_dev
) {
1320 DRM_DEBUG_KMS("No memory space for child device\n");
1324 dev_priv
->vbt
.child_dev_num
= count
;
1326 for (i
= 0; i
< child_device_num
; i
++) {
1327 p_child
= child_device_ptr(p_defs
, i
);
1328 if (!p_child
->common
.device_type
) {
1329 /* skip the device block if device type is invalid */
1333 child_dev_ptr
= dev_priv
->vbt
.child_dev
+ count
;
1337 * Copy as much as we know (sizeof) and is available
1338 * (child_dev_size) of the child device. Accessing the data must
1339 * depend on VBT version.
1341 memcpy(child_dev_ptr
, p_child
,
1342 min_t(size_t, p_defs
->child_dev_size
, sizeof(*p_child
)));
1345 * copied full block, now init values when they are not
1346 * available in current version
1348 if (bdb
->version
< 196) {
1349 /* Set default values for bits added from v196 */
1350 child_dev_ptr
->common
.iboost
= 0;
1351 child_dev_ptr
->common
.hpd_invert
= 0;
1354 if (bdb
->version
< 192)
1355 child_dev_ptr
->common
.lspcon
= 0;
1360 /* Common defaults which may be overridden by VBT. */
1362 init_vbt_defaults(struct drm_i915_private
*dev_priv
)
1366 dev_priv
->vbt
.crt_ddc_pin
= GMBUS_PIN_VGADDC
;
1368 /* Default to having backlight */
1369 dev_priv
->vbt
.backlight
.present
= true;
1371 /* LFP panel data */
1372 dev_priv
->vbt
.lvds_dither
= 1;
1373 dev_priv
->vbt
.lvds_vbt
= 0;
1375 /* SDVO panel data */
1376 dev_priv
->vbt
.sdvo_lvds_vbt_mode
= NULL
;
1378 /* general features */
1379 dev_priv
->vbt
.int_tv_support
= 1;
1380 dev_priv
->vbt
.int_crt_support
= 1;
1382 /* Default to using SSC */
1383 dev_priv
->vbt
.lvds_use_ssc
= 1;
1385 * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
1388 dev_priv
->vbt
.lvds_ssc_freq
= intel_bios_ssc_frequency(dev_priv
,
1389 !HAS_PCH_SPLIT(dev_priv
));
1390 DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv
->vbt
.lvds_ssc_freq
);
1392 for (port
= PORT_A
; port
< I915_MAX_PORTS
; port
++) {
1393 struct ddi_vbt_port_info
*info
=
1394 &dev_priv
->vbt
.ddi_port_info
[port
];
1396 info
->hdmi_level_shift
= HDMI_LEVEL_SHIFT_UNKNOWN
;
1400 /* Defaults to initialize only if there is no VBT. */
1402 init_vbt_missing_defaults(struct drm_i915_private
*dev_priv
)
1406 for (port
= PORT_A
; port
< I915_MAX_PORTS
; port
++) {
1407 struct ddi_vbt_port_info
*info
=
1408 &dev_priv
->vbt
.ddi_port_info
[port
];
1410 info
->supports_dvi
= (port
!= PORT_A
&& port
!= PORT_E
);
1411 info
->supports_hdmi
= info
->supports_dvi
;
1412 info
->supports_dp
= (port
!= PORT_E
);
1416 static const struct bdb_header
*get_bdb_header(const struct vbt_header
*vbt
)
1418 const void *_vbt
= vbt
;
1420 return _vbt
+ vbt
->bdb_offset
;
1424 * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
1425 * @buf: pointer to a buffer to validate
1426 * @size: size of the buffer
1428 * Returns true on valid VBT.
1430 bool intel_bios_is_valid_vbt(const void *buf
, size_t size
)
1432 const struct vbt_header
*vbt
= buf
;
1433 const struct bdb_header
*bdb
;
1438 if (sizeof(struct vbt_header
) > size
) {
1439 DRM_DEBUG_DRIVER("VBT header incomplete\n");
1443 if (memcmp(vbt
->signature
, "$VBT", 4)) {
1444 DRM_DEBUG_DRIVER("VBT invalid signature\n");
1448 if (range_overflows_t(size_t,
1450 sizeof(struct bdb_header
),
1452 DRM_DEBUG_DRIVER("BDB header incomplete\n");
1456 bdb
= get_bdb_header(vbt
);
1457 if (range_overflows_t(size_t, vbt
->bdb_offset
, bdb
->bdb_size
, size
)) {
1458 DRM_DEBUG_DRIVER("BDB incomplete\n");
1465 static const struct vbt_header
*find_vbt(void __iomem
*bios
, size_t size
)
1469 /* Scour memory looking for the VBT signature. */
1470 for (i
= 0; i
+ 4 < size
; i
++) {
1473 if (ioread32(bios
+ i
) != *((const u32
*) "$VBT"))
1477 * This is the one place where we explicitly discard the address
1478 * space (__iomem) of the BIOS/VBT.
1480 vbt
= (void __force
*) bios
+ i
;
1481 if (intel_bios_is_valid_vbt(vbt
, size
- i
))
1490 #define DRM_DMI_PRODUCT_VERSION 0x6
1492 static void parse_product_info(struct drm_i915_private
*dev_priv
)
1494 const char *product_ver
= dmi_get_system_info(DRM_DMI_PRODUCT_VERSION
);
1498 if (!strncmp(product_ver
, "ThinkPad X1", 11)) {
1499 DRM_DEBUG_KMS("dmi: %s, Bypassing TMDS_OE write\n", product_ver
);
1500 dev_priv
->bypass_tmds_oe
= true;
1507 * intel_bios_init - find VBT and initialize settings from the BIOS
1508 * @dev_priv: i915 device instance
1510 * Parse and initialize settings from the Video BIOS Tables (VBT). If the VBT
1511 * was not found in ACPI OpRegion, try to find it in PCI ROM first. Also
1512 * initialize some defaults if the VBT is not present at all.
1514 void intel_bios_init(struct drm_i915_private
*dev_priv
)
1516 struct pci_dev
*pdev
= dev_priv
->drm
.pdev
;
1517 const struct vbt_header
*vbt
= dev_priv
->opregion
.vbt
;
1518 const struct bdb_header
*bdb
;
1519 u8 __iomem
*bios
= NULL
;
1521 if (HAS_PCH_NOP(dev_priv
)) {
1522 DRM_DEBUG_KMS("Skipping VBT init due to disabled display.\n");
1526 init_vbt_defaults(dev_priv
);
1528 /* If the OpRegion does not have VBT, look in PCI ROM. */
1532 bios
= pci_map_rom(pdev
, &size
);
1536 vbt
= find_vbt(bios
, size
);
1540 DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
1543 bdb
= get_bdb_header(vbt
);
1545 DRM_DEBUG_KMS("VBT signature \"%.*s\", BDB version %d\n",
1546 (int)sizeof(vbt
->signature
), vbt
->signature
, bdb
->version
);
1548 /* Grab useful general definitions */
1549 parse_general_features(dev_priv
, bdb
);
1550 parse_general_definitions(dev_priv
, bdb
);
1551 parse_lfp_panel_data(dev_priv
, bdb
);
1552 parse_lfp_backlight(dev_priv
, bdb
);
1553 parse_sdvo_panel_data(dev_priv
, bdb
);
1554 parse_sdvo_device_mapping(dev_priv
, bdb
);
1555 parse_device_mapping(dev_priv
, bdb
);
1556 parse_driver_features(dev_priv
, bdb
);
1557 parse_edp(dev_priv
, bdb
);
1558 parse_psr(dev_priv
, bdb
);
1559 parse_mipi_config(dev_priv
, bdb
);
1560 parse_mipi_sequence(dev_priv
, bdb
);
1561 parse_ddi_ports(dev_priv
, bdb
);
1562 parse_product_info(dev_priv
);
1566 DRM_INFO("Failed to find VBIOS tables (VBT)\n");
1567 init_vbt_missing_defaults(dev_priv
);
1571 pci_unmap_rom(pdev
, bios
);
1575 * intel_bios_is_tv_present - is integrated TV present in VBT
1576 * @dev_priv: i915 device instance
1578 * Return true if TV is present. If no child devices were parsed from VBT,
1579 * assume TV is present.
1581 bool intel_bios_is_tv_present(struct drm_i915_private
*dev_priv
)
1583 union child_device_config
*p_child
;
1586 if (!dev_priv
->vbt
.int_tv_support
)
1589 if (!dev_priv
->vbt
.child_dev_num
)
1592 for (i
= 0; i
< dev_priv
->vbt
.child_dev_num
; i
++) {
1593 p_child
= dev_priv
->vbt
.child_dev
+ i
;
1595 * If the device type is not TV, continue.
1597 switch (p_child
->old
.device_type
) {
1598 case DEVICE_TYPE_INT_TV
:
1599 case DEVICE_TYPE_TV
:
1600 case DEVICE_TYPE_TV_SVIDEO_COMPOSITE
:
1605 /* Only when the addin_offset is non-zero, it is regarded
1608 if (p_child
->old
.addin_offset
)
1616 * intel_bios_is_lvds_present - is LVDS present in VBT
1617 * @dev_priv: i915 device instance
1618 * @i2c_pin: i2c pin for LVDS if present
1620 * Return true if LVDS is present. If no child devices were parsed from VBT,
1621 * assume LVDS is present.
1623 bool intel_bios_is_lvds_present(struct drm_i915_private
*dev_priv
, u8
*i2c_pin
)
1627 if (!dev_priv
->vbt
.child_dev_num
)
1630 for (i
= 0; i
< dev_priv
->vbt
.child_dev_num
; i
++) {
1631 union child_device_config
*uchild
= dev_priv
->vbt
.child_dev
+ i
;
1632 struct old_child_dev_config
*child
= &uchild
->old
;
1634 /* If the device type is not LFP, continue.
1635 * We have to check both the new identifiers as well as the
1636 * old for compatibility with some BIOSes.
1638 if (child
->device_type
!= DEVICE_TYPE_INT_LFP
&&
1639 child
->device_type
!= DEVICE_TYPE_LFP
)
1642 if (intel_gmbus_is_valid_pin(dev_priv
, child
->i2c_pin
))
1643 *i2c_pin
= child
->i2c_pin
;
1645 /* However, we cannot trust the BIOS writers to populate
1646 * the VBT correctly. Since LVDS requires additional
1647 * information from AIM blocks, a non-zero addin offset is
1648 * a good indicator that the LVDS is actually present.
1650 if (child
->addin_offset
)
1653 /* But even then some BIOS writers perform some black magic
1654 * and instantiate the device without reference to any
1655 * additional data. Trust that if the VBT was written into
1656 * the OpRegion then they have validated the LVDS's existence.
1658 if (dev_priv
->opregion
.vbt
)
1666 * intel_bios_is_port_present - is the specified digital port present
1667 * @dev_priv: i915 device instance
1668 * @port: port to check
1670 * Return true if the device in %port is present.
1672 bool intel_bios_is_port_present(struct drm_i915_private
*dev_priv
, enum port port
)
1674 static const struct {
1676 } port_mapping
[] = {
1677 [PORT_B
] = { DVO_PORT_DPB
, DVO_PORT_HDMIB
, },
1678 [PORT_C
] = { DVO_PORT_DPC
, DVO_PORT_HDMIC
, },
1679 [PORT_D
] = { DVO_PORT_DPD
, DVO_PORT_HDMID
, },
1680 [PORT_E
] = { DVO_PORT_DPE
, DVO_PORT_HDMIE
, },
1684 /* FIXME maybe deal with port A as well? */
1685 if (WARN_ON(port
== PORT_A
) || port
>= ARRAY_SIZE(port_mapping
))
1688 if (!dev_priv
->vbt
.child_dev_num
)
1691 for (i
= 0; i
< dev_priv
->vbt
.child_dev_num
; i
++) {
1692 const union child_device_config
*p_child
=
1693 &dev_priv
->vbt
.child_dev
[i
];
1694 if ((p_child
->common
.dvo_port
== port_mapping
[port
].dp
||
1695 p_child
->common
.dvo_port
== port_mapping
[port
].hdmi
) &&
1696 (p_child
->common
.device_type
& (DEVICE_TYPE_TMDS_DVI_SIGNALING
|
1697 DEVICE_TYPE_DISPLAYPORT_OUTPUT
)))
1705 * intel_bios_is_port_edp - is the device in given port eDP
1706 * @dev_priv: i915 device instance
1707 * @port: port to check
1709 * Return true if the device in %port is eDP.
1711 bool intel_bios_is_port_edp(struct drm_i915_private
*dev_priv
, enum port port
)
1713 union child_device_config
*p_child
;
1714 static const short port_mapping
[] = {
1715 [PORT_B
] = DVO_PORT_DPB
,
1716 [PORT_C
] = DVO_PORT_DPC
,
1717 [PORT_D
] = DVO_PORT_DPD
,
1718 [PORT_E
] = DVO_PORT_DPE
,
1722 if (HAS_DDI(dev_priv
))
1723 return dev_priv
->vbt
.ddi_port_info
[port
].supports_edp
;
1725 if (!dev_priv
->vbt
.child_dev_num
)
1728 for (i
= 0; i
< dev_priv
->vbt
.child_dev_num
; i
++) {
1729 p_child
= dev_priv
->vbt
.child_dev
+ i
;
1731 if (p_child
->common
.dvo_port
== port_mapping
[port
] &&
1732 (p_child
->common
.device_type
& DEVICE_TYPE_eDP_BITS
) ==
1733 (DEVICE_TYPE_eDP
& DEVICE_TYPE_eDP_BITS
))
1740 static bool child_dev_is_dp_dual_mode(const union child_device_config
*p_child
,
1743 static const struct {
1745 } port_mapping
[] = {
1747 * Buggy VBTs may declare DP ports as having
1748 * HDMI type dvo_port :( So let's check both.
1750 [PORT_B
] = { DVO_PORT_DPB
, DVO_PORT_HDMIB
, },
1751 [PORT_C
] = { DVO_PORT_DPC
, DVO_PORT_HDMIC
, },
1752 [PORT_D
] = { DVO_PORT_DPD
, DVO_PORT_HDMID
, },
1753 [PORT_E
] = { DVO_PORT_DPE
, DVO_PORT_HDMIE
, },
1756 if (port
== PORT_A
|| port
>= ARRAY_SIZE(port_mapping
))
1759 if ((p_child
->common
.device_type
& DEVICE_TYPE_DP_DUAL_MODE_BITS
) !=
1760 (DEVICE_TYPE_DP_DUAL_MODE
& DEVICE_TYPE_DP_DUAL_MODE_BITS
))
1763 if (p_child
->common
.dvo_port
== port_mapping
[port
].dp
)
1766 /* Only accept a HDMI dvo_port as DP++ if it has an AUX channel */
1767 if (p_child
->common
.dvo_port
== port_mapping
[port
].hdmi
&&
1768 p_child
->common
.aux_channel
!= 0)
1774 bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private
*dev_priv
,
1779 for (i
= 0; i
< dev_priv
->vbt
.child_dev_num
; i
++) {
1780 const union child_device_config
*p_child
=
1781 &dev_priv
->vbt
.child_dev
[i
];
1783 if (child_dev_is_dp_dual_mode(p_child
, port
))
1791 * intel_bios_is_dsi_present - is DSI present in VBT
1792 * @dev_priv: i915 device instance
1793 * @port: port for DSI if present
1795 * Return true if DSI is present, and return the port in %port.
1797 bool intel_bios_is_dsi_present(struct drm_i915_private
*dev_priv
,
1800 union child_device_config
*p_child
;
1804 for (i
= 0; i
< dev_priv
->vbt
.child_dev_num
; i
++) {
1805 p_child
= dev_priv
->vbt
.child_dev
+ i
;
1807 if (!(p_child
->common
.device_type
& DEVICE_TYPE_MIPI_OUTPUT
))
1810 dvo_port
= p_child
->common
.dvo_port
;
1813 case DVO_PORT_MIPIA
:
1814 case DVO_PORT_MIPIC
:
1816 *port
= dvo_port
- DVO_PORT_MIPIA
;
1818 case DVO_PORT_MIPIB
:
1819 case DVO_PORT_MIPID
:
1820 DRM_DEBUG_KMS("VBT has unsupported DSI port %c\n",
1821 port_name(dvo_port
- DVO_PORT_MIPIA
));
1830 * intel_bios_is_port_hpd_inverted - is HPD inverted for %port
1831 * @dev_priv: i915 device instance
1832 * @port: port to check
1834 * Return true if HPD should be inverted for %port.
1837 intel_bios_is_port_hpd_inverted(struct drm_i915_private
*dev_priv
,
1842 if (WARN_ON_ONCE(!IS_GEN9_LP(dev_priv
)))
1845 for (i
= 0; i
< dev_priv
->vbt
.child_dev_num
; i
++) {
1846 if (!dev_priv
->vbt
.child_dev
[i
].common
.hpd_invert
)
1849 switch (dev_priv
->vbt
.child_dev
[i
].common
.dvo_port
) {
1851 case DVO_PORT_HDMIA
:
1856 case DVO_PORT_HDMIB
:
1861 case DVO_PORT_HDMIC
:
1874 * intel_bios_is_lspcon_present - if LSPCON is attached on %port
1875 * @dev_priv: i915 device instance
1876 * @port: port to check
1878 * Return true if LSPCON is present on this port
1881 intel_bios_is_lspcon_present(struct drm_i915_private
*dev_priv
,
1886 if (!HAS_LSPCON(dev_priv
))
1889 for (i
= 0; i
< dev_priv
->vbt
.child_dev_num
; i
++) {
1890 if (!dev_priv
->vbt
.child_dev
[i
].common
.lspcon
)
1893 switch (dev_priv
->vbt
.child_dev
[i
].common
.dvo_port
) {
1895 case DVO_PORT_HDMIA
:
1900 case DVO_PORT_HDMIB
:
1905 case DVO_PORT_HDMIC
:
1910 case DVO_PORT_HDMID
: