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 "display/intel_display.h"
31 #include "display/intel_display_types.h"
32 #include "display/intel_gmbus.h"
36 #define _INTEL_BIOS_PRIVATE
37 #include "intel_vbt_defs.h"
40 * DOC: Video BIOS Table (VBT)
42 * The Video BIOS Table, or VBT, provides platform and board specific
43 * configuration information to the driver that is not discoverable or available
44 * through other means. The configuration is mostly related to display
45 * hardware. The VBT is available via the ACPI OpRegion or, on older systems, in
48 * The VBT consists of a VBT Header (defined as &struct vbt_header), a BDB
49 * Header (&struct bdb_header), and a number of BIOS Data Blocks (BDB) that
50 * contain the actual configuration information. The VBT Header, and thus the
51 * VBT, begins with "$VBT" signature. The VBT Header contains the offset of the
52 * BDB Header. The data blocks are concatenated after the BDB Header. The data
53 * blocks have a 1-byte Block ID, 2-byte Block Size, and Block Size bytes of
54 * data. (Block 53, the MIPI Sequence Block is an exception.)
56 * The driver parses the VBT during load. The relevant information is stored in
57 * driver private data for ease of use, and the actual VBT is not read after
61 /* Wrapper for VBT child device config */
62 struct intel_bios_encoder_data {
63 struct drm_i915_private *i915;
65 struct child_device_config child;
66 struct dsc_compression_parameters_entry *dsc;
67 struct list_head node;
70 #define SLAVE_ADDR1 0x70
71 #define SLAVE_ADDR2 0x72
73 /* Get BDB block size given a pointer to Block ID. */
74 static u32 _get_blocksize(const u8 *block_base)
76 /* The MIPI Sequence Block v3+ has a separate size field. */
77 if (*block_base == BDB_MIPI_SEQUENCE && *(block_base + 3) >= 3)
78 return *((const u32 *)(block_base + 4));
80 return *((const u16 *)(block_base + 1));
83 /* Get BDB block size give a pointer to data after Block ID and Block Size. */
84 static u32 get_blocksize(const void *block_data)
86 return _get_blocksize(block_data - 3);
90 find_section(const void *_bdb, enum bdb_block_id section_id)
92 const struct bdb_header *bdb = _bdb;
93 const u8 *base = _bdb;
95 u32 total, current_size;
96 enum bdb_block_id current_id;
98 /* skip to first section */
99 index += bdb->header_size;
100 total = bdb->bdb_size;
102 /* walk the sections looking for section_id */
103 while (index + 3 < total) {
104 current_id = *(base + index);
105 current_size = _get_blocksize(base + index);
108 if (index + current_size > total)
111 if (current_id == section_id)
114 index += current_size;
121 fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
122 const struct lvds_dvo_timing *dvo_timing)
124 panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
125 dvo_timing->hactive_lo;
126 panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
127 ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
128 panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
129 ((dvo_timing->hsync_pulse_width_hi << 8) |
130 dvo_timing->hsync_pulse_width_lo);
131 panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
132 ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
134 panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
135 dvo_timing->vactive_lo;
136 panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
137 ((dvo_timing->vsync_off_hi << 4) | dvo_timing->vsync_off_lo);
138 panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
139 ((dvo_timing->vsync_pulse_width_hi << 4) |
140 dvo_timing->vsync_pulse_width_lo);
141 panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
142 ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
143 panel_fixed_mode->clock = dvo_timing->clock * 10;
144 panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
146 if (dvo_timing->hsync_positive)
147 panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
149 panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
151 if (dvo_timing->vsync_positive)
152 panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
154 panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
156 panel_fixed_mode->width_mm = (dvo_timing->himage_hi << 8) |
157 dvo_timing->himage_lo;
158 panel_fixed_mode->height_mm = (dvo_timing->vimage_hi << 8) |
159 dvo_timing->vimage_lo;
161 /* Some VBTs have bogus h/vtotal values */
162 if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
163 panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
164 if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
165 panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
167 drm_mode_set_name(panel_fixed_mode);
170 static const struct lvds_dvo_timing *
171 get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
172 const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
176 * the size of fp_timing varies on the different platform.
177 * So calculate the DVO timing relative offset in LVDS data
178 * entry to get the DVO timing entry
182 lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
183 lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
184 int dvo_timing_offset =
185 lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
186 lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
187 char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
189 return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
192 /* get lvds_fp_timing entry
193 * this function may return NULL if the corresponding entry is invalid
195 static const struct lvds_fp_timing *
196 get_lvds_fp_timing(const struct bdb_header *bdb,
197 const struct bdb_lvds_lfp_data *data,
198 const struct bdb_lvds_lfp_data_ptrs *ptrs,
201 size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
202 u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
205 if (index >= ARRAY_SIZE(ptrs->ptr))
207 ofs = ptrs->ptr[index].fp_timing_offset;
208 if (ofs < data_ofs ||
209 ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
211 return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
214 /* Parse general panel options */
216 parse_panel_options(struct drm_i915_private *i915,
217 const struct bdb_header *bdb)
219 const struct bdb_lvds_options *lvds_options;
224 lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
228 i915->vbt.lvds_dither = lvds_options->pixel_dither;
230 ret = intel_opregion_get_panel_type(i915);
232 drm_WARN_ON(&i915->drm, ret > 0xf);
234 drm_dbg_kms(&i915->drm, "Panel type: %d (OpRegion)\n",
237 if (lvds_options->panel_type > 0xf) {
238 drm_dbg_kms(&i915->drm,
239 "Invalid VBT panel type 0x%x\n",
240 lvds_options->panel_type);
243 panel_type = lvds_options->panel_type;
244 drm_dbg_kms(&i915->drm, "Panel type: %d (VBT)\n",
248 i915->vbt.panel_type = panel_type;
250 drrs_mode = (lvds_options->dps_panel_type_bits
251 >> (panel_type * 2)) & MODE_MASK;
253 * VBT has static DRRS = 0 and seamless DRRS = 2.
254 * The below piece of code is required to adjust vbt.drrs_type
255 * to match the enum drrs_support_type.
259 i915->vbt.drrs_type = STATIC_DRRS_SUPPORT;
260 drm_dbg_kms(&i915->drm, "DRRS supported mode is static\n");
263 i915->vbt.drrs_type = SEAMLESS_DRRS_SUPPORT;
264 drm_dbg_kms(&i915->drm,
265 "DRRS supported mode is seamless\n");
268 i915->vbt.drrs_type = DRRS_NOT_SUPPORTED;
269 drm_dbg_kms(&i915->drm,
270 "DRRS not supported (VBT input)\n");
275 /* Try to find integrated panel timing data */
277 parse_lfp_panel_dtd(struct drm_i915_private *i915,
278 const struct bdb_header *bdb)
280 const struct bdb_lvds_lfp_data *lvds_lfp_data;
281 const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
282 const struct lvds_dvo_timing *panel_dvo_timing;
283 const struct lvds_fp_timing *fp_timing;
284 struct drm_display_mode *panel_fixed_mode;
285 int panel_type = i915->vbt.panel_type;
287 lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
291 lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
292 if (!lvds_lfp_data_ptrs)
295 panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
299 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
300 if (!panel_fixed_mode)
303 fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
305 i915->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
307 drm_dbg_kms(&i915->drm,
308 "Found panel mode in BIOS VBT legacy lfp table:\n");
309 drm_mode_debug_printmodeline(panel_fixed_mode);
311 fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
315 /* check the resolution, just to be sure */
316 if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
317 fp_timing->y_res == panel_fixed_mode->vdisplay) {
318 i915->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
319 drm_dbg_kms(&i915->drm,
320 "VBT initial LVDS value %x\n",
321 i915->vbt.bios_lvds_val);
327 parse_generic_dtd(struct drm_i915_private *i915,
328 const struct bdb_header *bdb)
330 const struct bdb_generic_dtd *generic_dtd;
331 const struct generic_dtd_entry *dtd;
332 struct drm_display_mode *panel_fixed_mode;
335 generic_dtd = find_section(bdb, BDB_GENERIC_DTD);
339 if (generic_dtd->gdtd_size < sizeof(struct generic_dtd_entry)) {
340 drm_err(&i915->drm, "GDTD size %u is too small.\n",
341 generic_dtd->gdtd_size);
343 } else if (generic_dtd->gdtd_size !=
344 sizeof(struct generic_dtd_entry)) {
345 drm_err(&i915->drm, "Unexpected GDTD size %u\n",
346 generic_dtd->gdtd_size);
347 /* DTD has unknown fields, but keep going */
350 num_dtd = (get_blocksize(generic_dtd) -
351 sizeof(struct bdb_generic_dtd)) / generic_dtd->gdtd_size;
352 if (i915->vbt.panel_type >= num_dtd) {
354 "Panel type %d not found in table of %d DTD's\n",
355 i915->vbt.panel_type, num_dtd);
359 dtd = &generic_dtd->dtd[i915->vbt.panel_type];
361 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
362 if (!panel_fixed_mode)
365 panel_fixed_mode->hdisplay = dtd->hactive;
366 panel_fixed_mode->hsync_start =
367 panel_fixed_mode->hdisplay + dtd->hfront_porch;
368 panel_fixed_mode->hsync_end =
369 panel_fixed_mode->hsync_start + dtd->hsync;
370 panel_fixed_mode->htotal =
371 panel_fixed_mode->hdisplay + dtd->hblank;
373 panel_fixed_mode->vdisplay = dtd->vactive;
374 panel_fixed_mode->vsync_start =
375 panel_fixed_mode->vdisplay + dtd->vfront_porch;
376 panel_fixed_mode->vsync_end =
377 panel_fixed_mode->vsync_start + dtd->vsync;
378 panel_fixed_mode->vtotal =
379 panel_fixed_mode->vdisplay + dtd->vblank;
381 panel_fixed_mode->clock = dtd->pixel_clock;
382 panel_fixed_mode->width_mm = dtd->width_mm;
383 panel_fixed_mode->height_mm = dtd->height_mm;
385 panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
386 drm_mode_set_name(panel_fixed_mode);
388 if (dtd->hsync_positive_polarity)
389 panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
391 panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
393 if (dtd->vsync_positive_polarity)
394 panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
396 panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
398 drm_dbg_kms(&i915->drm,
399 "Found panel mode in BIOS VBT generic dtd table:\n");
400 drm_mode_debug_printmodeline(panel_fixed_mode);
402 i915->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
406 parse_panel_dtd(struct drm_i915_private *i915,
407 const struct bdb_header *bdb)
410 * Older VBTs provided provided DTD information for internal displays
411 * through the "LFP panel DTD" block (42). As of VBT revision 229,
412 * that block is now deprecated and DTD information should be provided
413 * via a newer "generic DTD" block (58). Just to be safe, we'll
414 * try the new generic DTD block first on VBT >= 229, but still fall
415 * back to trying the old LFP block if that fails.
417 if (bdb->version >= 229)
418 parse_generic_dtd(i915, bdb);
419 if (!i915->vbt.lfp_lvds_vbt_mode)
420 parse_lfp_panel_dtd(i915, bdb);
424 parse_lfp_backlight(struct drm_i915_private *i915,
425 const struct bdb_header *bdb)
427 const struct bdb_lfp_backlight_data *backlight_data;
428 const struct lfp_backlight_data_entry *entry;
429 int panel_type = i915->vbt.panel_type;
432 backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
436 if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
437 drm_dbg_kms(&i915->drm,
438 "Unsupported backlight data entry size %u\n",
439 backlight_data->entry_size);
443 entry = &backlight_data->data[panel_type];
445 i915->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
446 if (!i915->vbt.backlight.present) {
447 drm_dbg_kms(&i915->drm,
448 "PWM backlight not present in VBT (type %u)\n",
453 i915->vbt.backlight.type = INTEL_BACKLIGHT_DISPLAY_DDI;
454 if (bdb->version >= 191) {
457 if (bdb->version >= 236)
458 exp_size = sizeof(struct bdb_lfp_backlight_data);
459 else if (bdb->version >= 234)
460 exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_234;
462 exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_191;
464 if (get_blocksize(backlight_data) >= exp_size) {
465 const struct lfp_backlight_control_method *method;
467 method = &backlight_data->backlight_control[panel_type];
468 i915->vbt.backlight.type = method->type;
469 i915->vbt.backlight.controller = method->controller;
473 i915->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
474 i915->vbt.backlight.active_low_pwm = entry->active_low_pwm;
476 if (bdb->version >= 234) {
480 level = backlight_data->brightness_level[panel_type].level;
481 min_level = backlight_data->brightness_min_level[panel_type].level;
483 if (bdb->version >= 236)
484 scale = backlight_data->brightness_precision_bits[panel_type] == 16;
489 min_level = min_level / 255;
491 if (min_level > 255) {
492 drm_warn(&i915->drm, "Brightness min level > 255\n");
495 i915->vbt.backlight.min_brightness = min_level;
497 i915->vbt.backlight.brightness_precision_bits =
498 backlight_data->brightness_precision_bits[panel_type];
500 level = backlight_data->level[panel_type];
501 i915->vbt.backlight.min_brightness = entry->min_brightness;
504 drm_dbg_kms(&i915->drm,
505 "VBT backlight PWM modulation frequency %u Hz, "
506 "active %s, min brightness %u, level %u, controller %u\n",
507 i915->vbt.backlight.pwm_freq_hz,
508 i915->vbt.backlight.active_low_pwm ? "low" : "high",
509 i915->vbt.backlight.min_brightness,
511 i915->vbt.backlight.controller);
514 /* Try to find sdvo panel data */
516 parse_sdvo_panel_data(struct drm_i915_private *i915,
517 const struct bdb_header *bdb)
519 const struct bdb_sdvo_panel_dtds *dtds;
520 struct drm_display_mode *panel_fixed_mode;
523 index = i915->params.vbt_sdvo_panel_type;
525 drm_dbg_kms(&i915->drm,
526 "Ignore SDVO panel mode from BIOS VBT tables.\n");
531 const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
533 sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
534 if (!sdvo_lvds_options)
537 index = sdvo_lvds_options->panel_type;
540 dtds = find_section(bdb, BDB_SDVO_PANEL_DTDS);
544 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
545 if (!panel_fixed_mode)
548 fill_detail_timing_data(panel_fixed_mode, &dtds->dtds[index]);
550 i915->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
552 drm_dbg_kms(&i915->drm,
553 "Found SDVO panel mode in BIOS VBT tables:\n");
554 drm_mode_debug_printmodeline(panel_fixed_mode);
557 static int intel_bios_ssc_frequency(struct drm_i915_private *i915,
560 switch (DISPLAY_VER(i915)) {
562 return alternate ? 66667 : 48000;
565 return alternate ? 100000 : 96000;
567 return alternate ? 100000 : 120000;
572 parse_general_features(struct drm_i915_private *i915,
573 const struct bdb_header *bdb)
575 const struct bdb_general_features *general;
577 general = find_section(bdb, BDB_GENERAL_FEATURES);
581 i915->vbt.int_tv_support = general->int_tv_support;
582 /* int_crt_support can't be trusted on earlier platforms */
583 if (bdb->version >= 155 &&
584 (HAS_DDI(i915) || IS_VALLEYVIEW(i915)))
585 i915->vbt.int_crt_support = general->int_crt_support;
586 i915->vbt.lvds_use_ssc = general->enable_ssc;
587 i915->vbt.lvds_ssc_freq =
588 intel_bios_ssc_frequency(i915, general->ssc_freq);
589 i915->vbt.display_clock_mode = general->display_clock_mode;
590 i915->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
591 if (bdb->version >= 181) {
592 i915->vbt.orientation = general->rotate_180 ?
593 DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP :
594 DRM_MODE_PANEL_ORIENTATION_NORMAL;
596 i915->vbt.orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
598 drm_dbg_kms(&i915->drm,
599 "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",
600 i915->vbt.int_tv_support,
601 i915->vbt.int_crt_support,
602 i915->vbt.lvds_use_ssc,
603 i915->vbt.lvds_ssc_freq,
604 i915->vbt.display_clock_mode,
605 i915->vbt.fdi_rx_polarity_inverted);
608 static const struct child_device_config *
609 child_device_ptr(const struct bdb_general_definitions *defs, int i)
611 return (const void *) &defs->devices[i * defs->child_dev_size];
615 parse_sdvo_device_mapping(struct drm_i915_private *i915)
617 struct sdvo_device_mapping *mapping;
618 const struct intel_bios_encoder_data *devdata;
619 const struct child_device_config *child;
623 * Only parse SDVO mappings on gens that could have SDVO. This isn't
624 * accurate and doesn't have to be, as long as it's not too strict.
626 if (!IS_DISPLAY_VER(i915, 3, 7)) {
627 drm_dbg_kms(&i915->drm, "Skipping SDVO device mapping\n");
631 list_for_each_entry(devdata, &i915->vbt.display_devices, node) {
632 child = &devdata->child;
634 if (child->slave_addr != SLAVE_ADDR1 &&
635 child->slave_addr != SLAVE_ADDR2) {
637 * If the slave address is neither 0x70 nor 0x72,
638 * it is not a SDVO device. Skip it.
642 if (child->dvo_port != DEVICE_PORT_DVOB &&
643 child->dvo_port != DEVICE_PORT_DVOC) {
644 /* skip the incorrect SDVO port */
645 drm_dbg_kms(&i915->drm,
646 "Incorrect SDVO port. Skip it\n");
649 drm_dbg_kms(&i915->drm,
650 "the SDVO device with slave addr %2x is found on"
653 (child->dvo_port == DEVICE_PORT_DVOB) ?
655 mapping = &i915->vbt.sdvo_mappings[child->dvo_port - 1];
656 if (!mapping->initialized) {
657 mapping->dvo_port = child->dvo_port;
658 mapping->slave_addr = child->slave_addr;
659 mapping->dvo_wiring = child->dvo_wiring;
660 mapping->ddc_pin = child->ddc_pin;
661 mapping->i2c_pin = child->i2c_pin;
662 mapping->initialized = 1;
663 drm_dbg_kms(&i915->drm,
664 "SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
665 mapping->dvo_port, mapping->slave_addr,
666 mapping->dvo_wiring, mapping->ddc_pin,
669 drm_dbg_kms(&i915->drm,
670 "Maybe one SDVO port is shared by "
671 "two SDVO device.\n");
673 if (child->slave2_addr) {
674 /* Maybe this is a SDVO device with multiple inputs */
675 /* And the mapping info is not added */
676 drm_dbg_kms(&i915->drm,
677 "there exists the slave2_addr. Maybe this"
678 " is a SDVO device with multiple inputs.\n");
684 /* No SDVO device info is found */
685 drm_dbg_kms(&i915->drm,
686 "No SDVO device info is found in VBT\n");
691 parse_driver_features(struct drm_i915_private *i915,
692 const struct bdb_header *bdb)
694 const struct bdb_driver_features *driver;
696 driver = find_section(bdb, BDB_DRIVER_FEATURES);
700 if (DISPLAY_VER(i915) >= 5) {
702 * Note that we consider BDB_DRIVER_FEATURE_INT_SDVO_LVDS
703 * to mean "eDP". The VBT spec doesn't agree with that
704 * interpretation, but real world VBTs seem to.
706 if (driver->lvds_config != BDB_DRIVER_FEATURE_INT_LVDS)
707 i915->vbt.int_lvds_support = 0;
710 * FIXME it's not clear which BDB version has the LVDS config
711 * bits defined. Revision history in the VBT spec says:
712 * "0.92 | Add two definitions for VBT value of LVDS Active
713 * Config (00b and 11b values defined) | 06/13/2005"
714 * but does not the specify the BDB version.
716 * So far version 134 (on i945gm) is the oldest VBT observed
717 * in the wild with the bits correctly populated. Version
718 * 108 (on i85x) does not have the bits correctly populated.
720 if (bdb->version >= 134 &&
721 driver->lvds_config != BDB_DRIVER_FEATURE_INT_LVDS &&
722 driver->lvds_config != BDB_DRIVER_FEATURE_INT_SDVO_LVDS)
723 i915->vbt.int_lvds_support = 0;
726 if (bdb->version < 228) {
727 drm_dbg_kms(&i915->drm, "DRRS State Enabled:%d\n",
728 driver->drrs_enabled);
730 * If DRRS is not supported, drrs_type has to be set to 0.
731 * This is because, VBT is configured in such a way that
732 * static DRRS is 0 and DRRS not supported is represented by
733 * driver->drrs_enabled=false
735 if (!driver->drrs_enabled)
736 i915->vbt.drrs_type = DRRS_NOT_SUPPORTED;
738 i915->vbt.psr.enable = driver->psr_enabled;
743 parse_power_conservation_features(struct drm_i915_private *i915,
744 const struct bdb_header *bdb)
746 const struct bdb_lfp_power *power;
747 u8 panel_type = i915->vbt.panel_type;
749 if (bdb->version < 228)
752 power = find_section(bdb, BDB_LFP_POWER);
756 i915->vbt.psr.enable = power->psr & BIT(panel_type);
759 * If DRRS is not supported, drrs_type has to be set to 0.
760 * This is because, VBT is configured in such a way that
761 * static DRRS is 0 and DRRS not supported is represented by
762 * power->drrs & BIT(panel_type)=false
764 if (!(power->drrs & BIT(panel_type)))
765 i915->vbt.drrs_type = DRRS_NOT_SUPPORTED;
767 if (bdb->version >= 232)
768 i915->vbt.edp.hobl = power->hobl & BIT(panel_type);
772 parse_edp(struct drm_i915_private *i915, const struct bdb_header *bdb)
774 const struct bdb_edp *edp;
775 const struct edp_power_seq *edp_pps;
776 const struct edp_fast_link_params *edp_link_params;
777 int panel_type = i915->vbt.panel_type;
779 edp = find_section(bdb, BDB_EDP);
783 switch ((edp->color_depth >> (panel_type * 2)) & 3) {
785 i915->vbt.edp.bpp = 18;
788 i915->vbt.edp.bpp = 24;
791 i915->vbt.edp.bpp = 30;
795 /* Get the eDP sequencing and link info */
796 edp_pps = &edp->power_seqs[panel_type];
797 edp_link_params = &edp->fast_link_params[panel_type];
799 i915->vbt.edp.pps = *edp_pps;
801 switch (edp_link_params->rate) {
803 i915->vbt.edp.rate = DP_LINK_BW_1_62;
806 i915->vbt.edp.rate = DP_LINK_BW_2_7;
809 drm_dbg_kms(&i915->drm,
810 "VBT has unknown eDP link rate value %u\n",
811 edp_link_params->rate);
815 switch (edp_link_params->lanes) {
817 i915->vbt.edp.lanes = 1;
820 i915->vbt.edp.lanes = 2;
823 i915->vbt.edp.lanes = 4;
826 drm_dbg_kms(&i915->drm,
827 "VBT has unknown eDP lane count value %u\n",
828 edp_link_params->lanes);
832 switch (edp_link_params->preemphasis) {
833 case EDP_PREEMPHASIS_NONE:
834 i915->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
836 case EDP_PREEMPHASIS_3_5dB:
837 i915->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
839 case EDP_PREEMPHASIS_6dB:
840 i915->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
842 case EDP_PREEMPHASIS_9_5dB:
843 i915->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
846 drm_dbg_kms(&i915->drm,
847 "VBT has unknown eDP pre-emphasis value %u\n",
848 edp_link_params->preemphasis);
852 switch (edp_link_params->vswing) {
853 case EDP_VSWING_0_4V:
854 i915->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
856 case EDP_VSWING_0_6V:
857 i915->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
859 case EDP_VSWING_0_8V:
860 i915->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
862 case EDP_VSWING_1_2V:
863 i915->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
866 drm_dbg_kms(&i915->drm,
867 "VBT has unknown eDP voltage swing value %u\n",
868 edp_link_params->vswing);
872 if (bdb->version >= 173) {
875 /* Don't read from VBT if module parameter has valid value*/
876 if (i915->params.edp_vswing) {
877 i915->vbt.edp.low_vswing =
878 i915->params.edp_vswing == 1;
880 vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
881 i915->vbt.edp.low_vswing = vswing == 0;
887 parse_psr(struct drm_i915_private *i915, const struct bdb_header *bdb)
889 const struct bdb_psr *psr;
890 const struct psr_table *psr_table;
891 int panel_type = i915->vbt.panel_type;
893 psr = find_section(bdb, BDB_PSR);
895 drm_dbg_kms(&i915->drm, "No PSR BDB found.\n");
899 psr_table = &psr->psr_table[panel_type];
901 i915->vbt.psr.full_link = psr_table->full_link;
902 i915->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
904 /* Allowed VBT values goes from 0 to 15 */
905 i915->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
906 psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
908 switch (psr_table->lines_to_wait) {
910 i915->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
913 i915->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
916 i915->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
919 i915->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
922 drm_dbg_kms(&i915->drm,
923 "VBT has unknown PSR lines to wait %u\n",
924 psr_table->lines_to_wait);
929 * New psr options 0=500us, 1=100us, 2=2500us, 3=0us
930 * Old decimal value is wake up time in multiples of 100 us.
932 if (bdb->version >= 205 &&
933 (DISPLAY_VER(i915) >= 9 && !IS_BROXTON(i915))) {
934 switch (psr_table->tp1_wakeup_time) {
936 i915->vbt.psr.tp1_wakeup_time_us = 500;
939 i915->vbt.psr.tp1_wakeup_time_us = 100;
942 i915->vbt.psr.tp1_wakeup_time_us = 0;
945 drm_dbg_kms(&i915->drm,
946 "VBT tp1 wakeup time value %d is outside range[0-3], defaulting to max value 2500us\n",
947 psr_table->tp1_wakeup_time);
950 i915->vbt.psr.tp1_wakeup_time_us = 2500;
954 switch (psr_table->tp2_tp3_wakeup_time) {
956 i915->vbt.psr.tp2_tp3_wakeup_time_us = 500;
959 i915->vbt.psr.tp2_tp3_wakeup_time_us = 100;
962 i915->vbt.psr.tp2_tp3_wakeup_time_us = 0;
965 drm_dbg_kms(&i915->drm,
966 "VBT tp2_tp3 wakeup time value %d is outside range[0-3], defaulting to max value 2500us\n",
967 psr_table->tp2_tp3_wakeup_time);
970 i915->vbt.psr.tp2_tp3_wakeup_time_us = 2500;
974 i915->vbt.psr.tp1_wakeup_time_us = psr_table->tp1_wakeup_time * 100;
975 i915->vbt.psr.tp2_tp3_wakeup_time_us = psr_table->tp2_tp3_wakeup_time * 100;
978 if (bdb->version >= 226) {
979 u32 wakeup_time = psr->psr2_tp2_tp3_wakeup_time;
981 wakeup_time = (wakeup_time >> (2 * panel_type)) & 0x3;
982 switch (wakeup_time) {
997 i915->vbt.psr.psr2_tp2_tp3_wakeup_time_us = wakeup_time;
999 /* Reusing PSR1 wakeup time for PSR2 in older VBTs */
1000 i915->vbt.psr.psr2_tp2_tp3_wakeup_time_us = i915->vbt.psr.tp2_tp3_wakeup_time_us;
1004 static void parse_dsi_backlight_ports(struct drm_i915_private *i915,
1005 u16 version, enum port port)
1007 if (!i915->vbt.dsi.config->dual_link || version < 197) {
1008 i915->vbt.dsi.bl_ports = BIT(port);
1009 if (i915->vbt.dsi.config->cabc_supported)
1010 i915->vbt.dsi.cabc_ports = BIT(port);
1015 switch (i915->vbt.dsi.config->dl_dcs_backlight_ports) {
1017 i915->vbt.dsi.bl_ports = BIT(PORT_A);
1020 i915->vbt.dsi.bl_ports = BIT(PORT_C);
1023 case DL_DCS_PORT_A_AND_C:
1024 i915->vbt.dsi.bl_ports = BIT(PORT_A) | BIT(PORT_C);
1028 if (!i915->vbt.dsi.config->cabc_supported)
1031 switch (i915->vbt.dsi.config->dl_dcs_cabc_ports) {
1033 i915->vbt.dsi.cabc_ports = BIT(PORT_A);
1036 i915->vbt.dsi.cabc_ports = BIT(PORT_C);
1039 case DL_DCS_PORT_A_AND_C:
1040 i915->vbt.dsi.cabc_ports =
1041 BIT(PORT_A) | BIT(PORT_C);
1047 parse_mipi_config(struct drm_i915_private *i915,
1048 const struct bdb_header *bdb)
1050 const struct bdb_mipi_config *start;
1051 const struct mipi_config *config;
1052 const struct mipi_pps_data *pps;
1053 int panel_type = i915->vbt.panel_type;
1056 /* parse MIPI blocks only if LFP type is MIPI */
1057 if (!intel_bios_is_dsi_present(i915, &port))
1060 /* Initialize this to undefined indicating no generic MIPI support */
1061 i915->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
1063 /* Block #40 is already parsed and panel_fixed_mode is
1064 * stored in i915->lfp_lvds_vbt_mode
1065 * resuse this when needed
1068 /* Parse #52 for panel index used from panel_type already
1071 start = find_section(bdb, BDB_MIPI_CONFIG);
1073 drm_dbg_kms(&i915->drm, "No MIPI config BDB found");
1077 drm_dbg(&i915->drm, "Found MIPI Config block, panel index = %d\n",
1081 * get hold of the correct configuration block and pps data as per
1082 * the panel_type as index
1084 config = &start->config[panel_type];
1085 pps = &start->pps[panel_type];
1087 /* store as of now full data. Trim when we realise all is not needed */
1088 i915->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
1089 if (!i915->vbt.dsi.config)
1092 i915->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
1093 if (!i915->vbt.dsi.pps) {
1094 kfree(i915->vbt.dsi.config);
1098 parse_dsi_backlight_ports(i915, bdb->version, port);
1100 /* FIXME is the 90 vs. 270 correct? */
1101 switch (config->rotation) {
1102 case ENABLE_ROTATION_0:
1104 * Most (all?) VBTs claim 0 degrees despite having
1105 * an upside down panel, thus we do not trust this.
1107 i915->vbt.dsi.orientation =
1108 DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
1110 case ENABLE_ROTATION_90:
1111 i915->vbt.dsi.orientation =
1112 DRM_MODE_PANEL_ORIENTATION_RIGHT_UP;
1114 case ENABLE_ROTATION_180:
1115 i915->vbt.dsi.orientation =
1116 DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP;
1118 case ENABLE_ROTATION_270:
1119 i915->vbt.dsi.orientation =
1120 DRM_MODE_PANEL_ORIENTATION_LEFT_UP;
1124 /* We have mandatory mipi config blocks. Initialize as generic panel */
1125 i915->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
1128 /* Find the sequence block and size for the given panel. */
1130 find_panel_sequence_block(const struct bdb_mipi_sequence *sequence,
1131 u16 panel_id, u32 *seq_size)
1133 u32 total = get_blocksize(sequence);
1134 const u8 *data = &sequence->data[0];
1137 int header_size = sequence->version >= 3 ? 5 : 3;
1141 /* skip new block size */
1142 if (sequence->version >= 3)
1145 for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index < total; i++) {
1146 if (index + header_size > total) {
1147 DRM_ERROR("Invalid sequence block (header)\n");
1151 current_id = *(data + index);
1152 if (sequence->version >= 3)
1153 current_size = *((const u32 *)(data + index + 1));
1155 current_size = *((const u16 *)(data + index + 1));
1157 index += header_size;
1159 if (index + current_size > total) {
1160 DRM_ERROR("Invalid sequence block\n");
1164 if (current_id == panel_id) {
1165 *seq_size = current_size;
1166 return data + index;
1169 index += current_size;
1172 DRM_ERROR("Sequence block detected but no valid configuration\n");
1177 static int goto_next_sequence(const u8 *data, int index, int total)
1181 /* Skip Sequence Byte. */
1182 for (index = index + 1; index < total; index += len) {
1183 u8 operation_byte = *(data + index);
1186 switch (operation_byte) {
1187 case MIPI_SEQ_ELEM_END:
1189 case MIPI_SEQ_ELEM_SEND_PKT:
1190 if (index + 4 > total)
1193 len = *((const u16 *)(data + index + 2)) + 4;
1195 case MIPI_SEQ_ELEM_DELAY:
1198 case MIPI_SEQ_ELEM_GPIO:
1201 case MIPI_SEQ_ELEM_I2C:
1202 if (index + 7 > total)
1204 len = *(data + index + 6) + 7;
1207 DRM_ERROR("Unknown operation byte\n");
1215 static int goto_next_sequence_v3(const u8 *data, int index, int total)
1219 u32 size_of_sequence;
1222 * Could skip sequence based on Size of Sequence alone, but also do some
1223 * checking on the structure.
1226 DRM_ERROR("Too small sequence size\n");
1230 /* Skip Sequence Byte. */
1234 * Size of Sequence. Excludes the Sequence Byte and the size itself,
1235 * includes MIPI_SEQ_ELEM_END byte, excludes the final MIPI_SEQ_END
1238 size_of_sequence = *((const u32 *)(data + index));
1241 seq_end = index + size_of_sequence;
1242 if (seq_end > total) {
1243 DRM_ERROR("Invalid sequence size\n");
1247 for (; index < total; index += len) {
1248 u8 operation_byte = *(data + index);
1251 if (operation_byte == MIPI_SEQ_ELEM_END) {
1252 if (index != seq_end) {
1253 DRM_ERROR("Invalid element structure\n");
1259 len = *(data + index);
1263 * FIXME: Would be nice to check elements like for v1/v2 in
1264 * goto_next_sequence() above.
1266 switch (operation_byte) {
1267 case MIPI_SEQ_ELEM_SEND_PKT:
1268 case MIPI_SEQ_ELEM_DELAY:
1269 case MIPI_SEQ_ELEM_GPIO:
1270 case MIPI_SEQ_ELEM_I2C:
1271 case MIPI_SEQ_ELEM_SPI:
1272 case MIPI_SEQ_ELEM_PMIC:
1275 DRM_ERROR("Unknown operation byte %u\n",
1285 * Get len of pre-fixed deassert fragment from a v1 init OTP sequence,
1286 * skip all delay + gpio operands and stop at the first DSI packet op.
1288 static int get_init_otp_deassert_fragment_len(struct drm_i915_private *i915)
1290 const u8 *data = i915->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP];
1293 if (drm_WARN_ON(&i915->drm,
1294 !data || i915->vbt.dsi.seq_version != 1))
1297 /* index = 1 to skip sequence byte */
1298 for (index = 1; data[index] != MIPI_SEQ_ELEM_END; index += len) {
1299 switch (data[index]) {
1300 case MIPI_SEQ_ELEM_SEND_PKT:
1301 return index == 1 ? 0 : index;
1302 case MIPI_SEQ_ELEM_DELAY:
1303 len = 5; /* 1 byte for operand + uint32 */
1305 case MIPI_SEQ_ELEM_GPIO:
1306 len = 3; /* 1 byte for op, 1 for gpio_nr, 1 for value */
1317 * Some v1 VBT MIPI sequences do the deassert in the init OTP sequence.
1318 * The deassert must be done before calling intel_dsi_device_ready, so for
1319 * these devices we split the init OTP sequence into a deassert sequence and
1320 * the actual init OTP part.
1322 static void fixup_mipi_sequences(struct drm_i915_private *i915)
1327 /* Limit this to VLV for now. */
1328 if (!IS_VALLEYVIEW(i915))
1331 /* Limit this to v1 vid-mode sequences */
1332 if (i915->vbt.dsi.config->is_cmd_mode ||
1333 i915->vbt.dsi.seq_version != 1)
1336 /* Only do this if there are otp and assert seqs and no deassert seq */
1337 if (!i915->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] ||
1338 !i915->vbt.dsi.sequence[MIPI_SEQ_ASSERT_RESET] ||
1339 i915->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET])
1342 /* The deassert-sequence ends at the first DSI packet */
1343 len = get_init_otp_deassert_fragment_len(i915);
1347 drm_dbg_kms(&i915->drm,
1348 "Using init OTP fragment to deassert reset\n");
1350 /* Copy the fragment, update seq byte and terminate it */
1351 init_otp = (u8 *)i915->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP];
1352 i915->vbt.dsi.deassert_seq = kmemdup(init_otp, len + 1, GFP_KERNEL);
1353 if (!i915->vbt.dsi.deassert_seq)
1355 i915->vbt.dsi.deassert_seq[0] = MIPI_SEQ_DEASSERT_RESET;
1356 i915->vbt.dsi.deassert_seq[len] = MIPI_SEQ_ELEM_END;
1357 /* Use the copy for deassert */
1358 i915->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET] =
1359 i915->vbt.dsi.deassert_seq;
1360 /* Replace the last byte of the fragment with init OTP seq byte */
1361 init_otp[len - 1] = MIPI_SEQ_INIT_OTP;
1362 /* And make MIPI_MIPI_SEQ_INIT_OTP point to it */
1363 i915->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] = init_otp + len - 1;
1367 parse_mipi_sequence(struct drm_i915_private *i915,
1368 const struct bdb_header *bdb)
1370 int panel_type = i915->vbt.panel_type;
1371 const struct bdb_mipi_sequence *sequence;
1377 /* Only our generic panel driver uses the sequence block. */
1378 if (i915->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
1381 sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
1383 drm_dbg_kms(&i915->drm,
1384 "No MIPI Sequence found, parsing complete\n");
1388 /* Fail gracefully for forward incompatible sequence block. */
1389 if (sequence->version >= 4) {
1391 "Unable to parse MIPI Sequence Block v%u\n",
1396 drm_dbg(&i915->drm, "Found MIPI sequence block v%u\n",
1399 seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size);
1403 data = kmemdup(seq_data, seq_size, GFP_KERNEL);
1407 /* Parse the sequences, store pointers to each sequence. */
1409 u8 seq_id = *(data + index);
1410 if (seq_id == MIPI_SEQ_END)
1413 if (seq_id >= MIPI_SEQ_MAX) {
1414 drm_err(&i915->drm, "Unknown sequence %u\n",
1419 /* Log about presence of sequences we won't run. */
1420 if (seq_id == MIPI_SEQ_TEAR_ON || seq_id == MIPI_SEQ_TEAR_OFF)
1421 drm_dbg_kms(&i915->drm,
1422 "Unsupported sequence %u\n", seq_id);
1424 i915->vbt.dsi.sequence[seq_id] = data + index;
1426 if (sequence->version >= 3)
1427 index = goto_next_sequence_v3(data, index, seq_size);
1429 index = goto_next_sequence(data, index, seq_size);
1431 drm_err(&i915->drm, "Invalid sequence %u\n",
1437 i915->vbt.dsi.data = data;
1438 i915->vbt.dsi.size = seq_size;
1439 i915->vbt.dsi.seq_version = sequence->version;
1441 fixup_mipi_sequences(i915);
1443 drm_dbg(&i915->drm, "MIPI related VBT parsing complete\n");
1448 memset(i915->vbt.dsi.sequence, 0, sizeof(i915->vbt.dsi.sequence));
1452 parse_compression_parameters(struct drm_i915_private *i915,
1453 const struct bdb_header *bdb)
1455 const struct bdb_compression_parameters *params;
1456 struct intel_bios_encoder_data *devdata;
1457 const struct child_device_config *child;
1461 if (bdb->version < 198)
1464 params = find_section(bdb, BDB_COMPRESSION_PARAMETERS);
1467 if (params->entry_size != sizeof(params->data[0])) {
1468 drm_dbg_kms(&i915->drm,
1469 "VBT: unsupported compression param entry size\n");
1473 block_size = get_blocksize(params);
1474 if (block_size < sizeof(*params)) {
1475 drm_dbg_kms(&i915->drm,
1476 "VBT: expected 16 compression param entries\n");
1481 list_for_each_entry(devdata, &i915->vbt.display_devices, node) {
1482 child = &devdata->child;
1484 if (!child->compression_enable)
1488 drm_dbg_kms(&i915->drm,
1489 "VBT: compression params not available\n");
1493 if (child->compression_method_cps) {
1494 drm_dbg_kms(&i915->drm,
1495 "VBT: CPS compression not supported\n");
1499 index = child->compression_structure_index;
1501 devdata->dsc = kmemdup(¶ms->data[index],
1502 sizeof(*devdata->dsc), GFP_KERNEL);
1506 static u8 translate_iboost(u8 val)
1508 static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
1510 if (val >= ARRAY_SIZE(mapping)) {
1511 DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
1514 return mapping[val];
1517 static const u8 cnp_ddc_pin_map[] = {
1519 [DDC_BUS_DDI_B] = GMBUS_PIN_1_BXT,
1520 [DDC_BUS_DDI_C] = GMBUS_PIN_2_BXT,
1521 [DDC_BUS_DDI_D] = GMBUS_PIN_4_CNP, /* sic */
1522 [DDC_BUS_DDI_F] = GMBUS_PIN_3_BXT, /* sic */
1525 static const u8 icp_ddc_pin_map[] = {
1526 [ICL_DDC_BUS_DDI_A] = GMBUS_PIN_1_BXT,
1527 [ICL_DDC_BUS_DDI_B] = GMBUS_PIN_2_BXT,
1528 [TGL_DDC_BUS_DDI_C] = GMBUS_PIN_3_BXT,
1529 [ICL_DDC_BUS_PORT_1] = GMBUS_PIN_9_TC1_ICP,
1530 [ICL_DDC_BUS_PORT_2] = GMBUS_PIN_10_TC2_ICP,
1531 [ICL_DDC_BUS_PORT_3] = GMBUS_PIN_11_TC3_ICP,
1532 [ICL_DDC_BUS_PORT_4] = GMBUS_PIN_12_TC4_ICP,
1533 [TGL_DDC_BUS_PORT_5] = GMBUS_PIN_13_TC5_TGP,
1534 [TGL_DDC_BUS_PORT_6] = GMBUS_PIN_14_TC6_TGP,
1537 static const u8 rkl_pch_tgp_ddc_pin_map[] = {
1538 [ICL_DDC_BUS_DDI_A] = GMBUS_PIN_1_BXT,
1539 [ICL_DDC_BUS_DDI_B] = GMBUS_PIN_2_BXT,
1540 [RKL_DDC_BUS_DDI_D] = GMBUS_PIN_9_TC1_ICP,
1541 [RKL_DDC_BUS_DDI_E] = GMBUS_PIN_10_TC2_ICP,
1544 static const u8 adls_ddc_pin_map[] = {
1545 [ICL_DDC_BUS_DDI_A] = GMBUS_PIN_1_BXT,
1546 [ADLS_DDC_BUS_PORT_TC1] = GMBUS_PIN_9_TC1_ICP,
1547 [ADLS_DDC_BUS_PORT_TC2] = GMBUS_PIN_10_TC2_ICP,
1548 [ADLS_DDC_BUS_PORT_TC3] = GMBUS_PIN_11_TC3_ICP,
1549 [ADLS_DDC_BUS_PORT_TC4] = GMBUS_PIN_12_TC4_ICP,
1552 static const u8 gen9bc_tgp_ddc_pin_map[] = {
1553 [DDC_BUS_DDI_B] = GMBUS_PIN_2_BXT,
1554 [DDC_BUS_DDI_C] = GMBUS_PIN_9_TC1_ICP,
1555 [DDC_BUS_DDI_D] = GMBUS_PIN_10_TC2_ICP,
1558 static const u8 adlp_ddc_pin_map[] = {
1559 [ICL_DDC_BUS_DDI_A] = GMBUS_PIN_1_BXT,
1560 [ICL_DDC_BUS_DDI_B] = GMBUS_PIN_2_BXT,
1561 [ADLP_DDC_BUS_PORT_TC1] = GMBUS_PIN_9_TC1_ICP,
1562 [ADLP_DDC_BUS_PORT_TC2] = GMBUS_PIN_10_TC2_ICP,
1563 [ADLP_DDC_BUS_PORT_TC3] = GMBUS_PIN_11_TC3_ICP,
1564 [ADLP_DDC_BUS_PORT_TC4] = GMBUS_PIN_12_TC4_ICP,
1567 static u8 map_ddc_pin(struct drm_i915_private *i915, u8 vbt_pin)
1569 const u8 *ddc_pin_map;
1572 if (IS_ALDERLAKE_P(i915)) {
1573 ddc_pin_map = adlp_ddc_pin_map;
1574 n_entries = ARRAY_SIZE(adlp_ddc_pin_map);
1575 } else if (IS_ALDERLAKE_S(i915)) {
1576 ddc_pin_map = adls_ddc_pin_map;
1577 n_entries = ARRAY_SIZE(adls_ddc_pin_map);
1578 } else if (INTEL_PCH_TYPE(i915) >= PCH_DG1) {
1580 } else if (IS_ROCKETLAKE(i915) && INTEL_PCH_TYPE(i915) == PCH_TGP) {
1581 ddc_pin_map = rkl_pch_tgp_ddc_pin_map;
1582 n_entries = ARRAY_SIZE(rkl_pch_tgp_ddc_pin_map);
1583 } else if (HAS_PCH_TGP(i915) && DISPLAY_VER(i915) == 9) {
1584 ddc_pin_map = gen9bc_tgp_ddc_pin_map;
1585 n_entries = ARRAY_SIZE(gen9bc_tgp_ddc_pin_map);
1586 } else if (INTEL_PCH_TYPE(i915) >= PCH_ICP) {
1587 ddc_pin_map = icp_ddc_pin_map;
1588 n_entries = ARRAY_SIZE(icp_ddc_pin_map);
1589 } else if (HAS_PCH_CNP(i915)) {
1590 ddc_pin_map = cnp_ddc_pin_map;
1591 n_entries = ARRAY_SIZE(cnp_ddc_pin_map);
1593 /* Assuming direct map */
1597 if (vbt_pin < n_entries && ddc_pin_map[vbt_pin] != 0)
1598 return ddc_pin_map[vbt_pin];
1600 drm_dbg_kms(&i915->drm,
1601 "Ignoring alternate pin: VBT claims DDC pin %d, which is not valid for this platform\n",
1606 static enum port get_port_by_ddc_pin(struct drm_i915_private *i915, u8 ddc_pin)
1608 const struct intel_bios_encoder_data *devdata;
1614 for_each_port(port) {
1615 devdata = i915->vbt.ports[port];
1617 if (devdata && ddc_pin == devdata->child.ddc_pin)
1624 static void sanitize_ddc_pin(struct intel_bios_encoder_data *devdata,
1627 struct drm_i915_private *i915 = devdata->i915;
1628 struct child_device_config *child;
1632 if (!devdata->child.ddc_pin)
1635 mapped_ddc_pin = map_ddc_pin(i915, devdata->child.ddc_pin);
1636 if (!intel_gmbus_is_valid_pin(i915, mapped_ddc_pin)) {
1637 drm_dbg_kms(&i915->drm,
1638 "Port %c has invalid DDC pin %d, "
1639 "sticking to defaults\n",
1640 port_name(port), mapped_ddc_pin);
1641 devdata->child.ddc_pin = 0;
1645 p = get_port_by_ddc_pin(i915, devdata->child.ddc_pin);
1649 drm_dbg_kms(&i915->drm,
1650 "port %c trying to use the same DDC pin (0x%x) as port %c, "
1651 "disabling port %c DVI/HDMI support\n",
1652 port_name(port), mapped_ddc_pin,
1653 port_name(p), port_name(p));
1656 * If we have multiple ports supposedly sharing the pin, then dvi/hdmi
1657 * couldn't exist on the shared port. Otherwise they share the same ddc
1658 * pin and system couldn't communicate with them separately.
1660 * Give inverse child device order the priority, last one wins. Yes,
1661 * there are real machines (eg. Asrock B250M-HDV) where VBT has both
1662 * port A and port E with the same AUX ch and we must pick port E :(
1664 child = &i915->vbt.ports[p]->child;
1666 child->device_type &= ~DEVICE_TYPE_TMDS_DVI_SIGNALING;
1667 child->device_type |= DEVICE_TYPE_NOT_HDMI_OUTPUT;
1672 static enum port get_port_by_aux_ch(struct drm_i915_private *i915, u8 aux_ch)
1674 const struct intel_bios_encoder_data *devdata;
1680 for_each_port(port) {
1681 devdata = i915->vbt.ports[port];
1683 if (devdata && aux_ch == devdata->child.aux_channel)
1690 static void sanitize_aux_ch(struct intel_bios_encoder_data *devdata,
1693 struct drm_i915_private *i915 = devdata->i915;
1694 struct child_device_config *child;
1697 p = get_port_by_aux_ch(i915, devdata->child.aux_channel);
1701 drm_dbg_kms(&i915->drm,
1702 "port %c trying to use the same AUX CH (0x%x) as port %c, "
1703 "disabling port %c DP support\n",
1704 port_name(port), devdata->child.aux_channel,
1705 port_name(p), port_name(p));
1708 * If we have multiple ports supposedly sharing the aux channel, then DP
1709 * couldn't exist on the shared port. Otherwise they share the same aux
1710 * channel and system couldn't communicate with them separately.
1712 * Give inverse child device order the priority, last one wins. Yes,
1713 * there are real machines (eg. Asrock B250M-HDV) where VBT has both
1714 * port A and port E with the same AUX ch and we must pick port E :(
1716 child = &i915->vbt.ports[p]->child;
1718 child->device_type &= ~DEVICE_TYPE_DISPLAYPORT_OUTPUT;
1719 child->aux_channel = 0;
1722 static u8 dvo_port_type(u8 dvo_port)
1725 case DVO_PORT_HDMIA:
1726 case DVO_PORT_HDMIB:
1727 case DVO_PORT_HDMIC:
1728 case DVO_PORT_HDMID:
1729 case DVO_PORT_HDMIE:
1730 case DVO_PORT_HDMIF:
1731 case DVO_PORT_HDMIG:
1732 case DVO_PORT_HDMIH:
1733 case DVO_PORT_HDMII:
1734 return DVO_PORT_HDMIA;
1744 return DVO_PORT_DPA;
1745 case DVO_PORT_MIPIA:
1746 case DVO_PORT_MIPIB:
1747 case DVO_PORT_MIPIC:
1748 case DVO_PORT_MIPID:
1749 return DVO_PORT_MIPIA;
1755 static enum port __dvo_port_to_port(int n_ports, int n_dvo,
1756 const int port_mapping[][3], u8 dvo_port)
1761 for (port = PORT_A; port < n_ports; port++) {
1762 for (i = 0; i < n_dvo; i++) {
1763 if (port_mapping[port][i] == -1)
1766 if (dvo_port == port_mapping[port][i])
1774 static enum port dvo_port_to_port(struct drm_i915_private *i915,
1778 * Each DDI port can have more than one value on the "DVO Port" field,
1779 * so look for all the possible values for each port.
1781 static const int port_mapping[][3] = {
1782 [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
1783 [PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
1784 [PORT_C] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
1785 [PORT_D] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
1786 [PORT_E] = { DVO_PORT_HDMIE, DVO_PORT_DPE, DVO_PORT_CRT },
1787 [PORT_F] = { DVO_PORT_HDMIF, DVO_PORT_DPF, -1 },
1788 [PORT_G] = { DVO_PORT_HDMIG, DVO_PORT_DPG, -1 },
1789 [PORT_H] = { DVO_PORT_HDMIH, DVO_PORT_DPH, -1 },
1790 [PORT_I] = { DVO_PORT_HDMII, DVO_PORT_DPI, -1 },
1793 * RKL VBT uses PHY based mapping. Combo PHYs A,B,C,D
1794 * map to DDI A,B,TC1,TC2 respectively.
1796 static const int rkl_port_mapping[][3] = {
1797 [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
1798 [PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
1800 [PORT_TC1] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
1801 [PORT_TC2] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
1804 * Alderlake S ports used in the driver are PORT_A, PORT_D, PORT_E,
1805 * PORT_F and PORT_G, we need to map that to correct VBT sections.
1807 static const int adls_port_mapping[][3] = {
1808 [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
1811 [PORT_TC1] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
1812 [PORT_TC2] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
1813 [PORT_TC3] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
1814 [PORT_TC4] = { DVO_PORT_HDMIE, DVO_PORT_DPE, -1 },
1816 static const int xelpd_port_mapping[][3] = {
1817 [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
1818 [PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
1819 [PORT_C] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
1820 [PORT_D_XELPD] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
1821 [PORT_E_XELPD] = { DVO_PORT_HDMIE, DVO_PORT_DPE, -1 },
1822 [PORT_TC1] = { DVO_PORT_HDMIF, DVO_PORT_DPF, -1 },
1823 [PORT_TC2] = { DVO_PORT_HDMIG, DVO_PORT_DPG, -1 },
1824 [PORT_TC3] = { DVO_PORT_HDMIH, DVO_PORT_DPH, -1 },
1825 [PORT_TC4] = { DVO_PORT_HDMII, DVO_PORT_DPI, -1 },
1828 if (DISPLAY_VER(i915) == 13)
1829 return __dvo_port_to_port(ARRAY_SIZE(xelpd_port_mapping),
1830 ARRAY_SIZE(xelpd_port_mapping[0]),
1833 else if (IS_ALDERLAKE_S(i915))
1834 return __dvo_port_to_port(ARRAY_SIZE(adls_port_mapping),
1835 ARRAY_SIZE(adls_port_mapping[0]),
1838 else if (IS_DG1(i915) || IS_ROCKETLAKE(i915))
1839 return __dvo_port_to_port(ARRAY_SIZE(rkl_port_mapping),
1840 ARRAY_SIZE(rkl_port_mapping[0]),
1844 return __dvo_port_to_port(ARRAY_SIZE(port_mapping),
1845 ARRAY_SIZE(port_mapping[0]),
1850 static int parse_bdb_230_dp_max_link_rate(const int vbt_max_link_rate)
1852 switch (vbt_max_link_rate) {
1854 case BDB_230_VBT_DP_MAX_LINK_RATE_DEF:
1856 case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR20:
1858 case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR13P5:
1860 case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR10:
1862 case BDB_230_VBT_DP_MAX_LINK_RATE_HBR3:
1864 case BDB_230_VBT_DP_MAX_LINK_RATE_HBR2:
1866 case BDB_230_VBT_DP_MAX_LINK_RATE_HBR:
1868 case BDB_230_VBT_DP_MAX_LINK_RATE_LBR:
1873 static int parse_bdb_216_dp_max_link_rate(const int vbt_max_link_rate)
1875 switch (vbt_max_link_rate) {
1877 case BDB_216_VBT_DP_MAX_LINK_RATE_HBR3:
1879 case BDB_216_VBT_DP_MAX_LINK_RATE_HBR2:
1881 case BDB_216_VBT_DP_MAX_LINK_RATE_HBR:
1883 case BDB_216_VBT_DP_MAX_LINK_RATE_LBR:
1888 static int _intel_bios_dp_max_link_rate(const struct intel_bios_encoder_data *devdata)
1890 if (!devdata || devdata->i915->vbt.version < 216)
1893 if (devdata->i915->vbt.version >= 230)
1894 return parse_bdb_230_dp_max_link_rate(devdata->child.dp_max_link_rate);
1896 return parse_bdb_216_dp_max_link_rate(devdata->child.dp_max_link_rate);
1899 static void sanitize_device_type(struct intel_bios_encoder_data *devdata,
1902 struct drm_i915_private *i915 = devdata->i915;
1905 if (port != PORT_A || DISPLAY_VER(i915) >= 12)
1908 if (!(devdata->child.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING))
1911 is_hdmi = !(devdata->child.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT);
1913 drm_dbg_kms(&i915->drm, "VBT claims port A supports DVI%s, ignoring\n",
1914 is_hdmi ? "/HDMI" : "");
1916 devdata->child.device_type &= ~DEVICE_TYPE_TMDS_DVI_SIGNALING;
1917 devdata->child.device_type |= DEVICE_TYPE_NOT_HDMI_OUTPUT;
1921 intel_bios_encoder_supports_crt(const struct intel_bios_encoder_data *devdata)
1923 return devdata->child.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
1927 intel_bios_encoder_supports_dvi(const struct intel_bios_encoder_data *devdata)
1929 return devdata->child.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
1933 intel_bios_encoder_supports_hdmi(const struct intel_bios_encoder_data *devdata)
1935 return intel_bios_encoder_supports_dvi(devdata) &&
1936 (devdata->child.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
1940 intel_bios_encoder_supports_dp(const struct intel_bios_encoder_data *devdata)
1942 return devdata->child.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
1946 intel_bios_encoder_supports_edp(const struct intel_bios_encoder_data *devdata)
1948 return intel_bios_encoder_supports_dp(devdata) &&
1949 devdata->child.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR;
1952 static int _intel_bios_hdmi_level_shift(const struct intel_bios_encoder_data *devdata)
1954 if (!devdata || devdata->i915->vbt.version < 158)
1957 return devdata->child.hdmi_level_shifter_value;
1960 static int _intel_bios_max_tmds_clock(const struct intel_bios_encoder_data *devdata)
1962 if (!devdata || devdata->i915->vbt.version < 204)
1965 switch (devdata->child.hdmi_max_data_rate) {
1967 MISSING_CASE(devdata->child.hdmi_max_data_rate);
1969 case HDMI_MAX_DATA_RATE_PLATFORM:
1971 case HDMI_MAX_DATA_RATE_297:
1973 case HDMI_MAX_DATA_RATE_165:
1978 static bool is_port_valid(struct drm_i915_private *i915, enum port port)
1981 * On some ICL SKUs port F is not present, but broken VBTs mark
1982 * the port as present. Only try to initialize port F for the
1983 * SKUs that may actually have it.
1985 if (port == PORT_F && IS_ICELAKE(i915))
1986 return IS_ICL_WITH_PORT_F(i915);
1991 static void parse_ddi_port(struct drm_i915_private *i915,
1992 struct intel_bios_encoder_data *devdata)
1994 const struct child_device_config *child = &devdata->child;
1995 bool is_dvi, is_hdmi, is_dp, is_edp, is_crt, supports_typec_usb, supports_tbt;
1996 int dp_boost_level, dp_max_link_rate, hdmi_boost_level, hdmi_level_shift, max_tmds_clock;
1999 port = dvo_port_to_port(i915, child->dvo_port);
2000 if (port == PORT_NONE)
2003 if (!is_port_valid(i915, port)) {
2004 drm_dbg_kms(&i915->drm,
2005 "VBT reports port %c as supported, but that can't be true: skipping\n",
2010 if (i915->vbt.ports[port]) {
2011 drm_dbg_kms(&i915->drm,
2012 "More than one child device for port %c in VBT, using the first.\n",
2017 sanitize_device_type(devdata, port);
2019 is_dvi = intel_bios_encoder_supports_dvi(devdata);
2020 is_dp = intel_bios_encoder_supports_dp(devdata);
2021 is_crt = intel_bios_encoder_supports_crt(devdata);
2022 is_hdmi = intel_bios_encoder_supports_hdmi(devdata);
2023 is_edp = intel_bios_encoder_supports_edp(devdata);
2025 supports_typec_usb = intel_bios_encoder_supports_typec_usb(devdata);
2026 supports_tbt = intel_bios_encoder_supports_tbt(devdata);
2028 drm_dbg_kms(&i915->drm,
2029 "Port %c VBT info: CRT:%d DVI:%d HDMI:%d DP:%d eDP:%d LSPCON:%d USB-Type-C:%d TBT:%d DSC:%d\n",
2030 port_name(port), is_crt, is_dvi, is_hdmi, is_dp, is_edp,
2031 HAS_LSPCON(i915) && child->lspcon,
2032 supports_typec_usb, supports_tbt,
2033 devdata->dsc != NULL);
2036 sanitize_ddc_pin(devdata, port);
2039 sanitize_aux_ch(devdata, port);
2041 hdmi_level_shift = _intel_bios_hdmi_level_shift(devdata);
2042 if (hdmi_level_shift >= 0) {
2043 drm_dbg_kms(&i915->drm,
2044 "Port %c VBT HDMI level shift: %d\n",
2045 port_name(port), hdmi_level_shift);
2048 max_tmds_clock = _intel_bios_max_tmds_clock(devdata);
2050 drm_dbg_kms(&i915->drm,
2051 "Port %c VBT HDMI max TMDS clock: %d kHz\n",
2052 port_name(port), max_tmds_clock);
2054 /* I_boost config for SKL and above */
2055 dp_boost_level = intel_bios_encoder_dp_boost_level(devdata);
2057 drm_dbg_kms(&i915->drm,
2058 "Port %c VBT (e)DP boost level: %d\n",
2059 port_name(port), dp_boost_level);
2061 hdmi_boost_level = intel_bios_encoder_hdmi_boost_level(devdata);
2062 if (hdmi_boost_level)
2063 drm_dbg_kms(&i915->drm,
2064 "Port %c VBT HDMI boost level: %d\n",
2065 port_name(port), hdmi_boost_level);
2067 dp_max_link_rate = _intel_bios_dp_max_link_rate(devdata);
2068 if (dp_max_link_rate)
2069 drm_dbg_kms(&i915->drm,
2070 "Port %c VBT DP max link rate: %d\n",
2071 port_name(port), dp_max_link_rate);
2073 i915->vbt.ports[port] = devdata;
2076 static void parse_ddi_ports(struct drm_i915_private *i915)
2078 struct intel_bios_encoder_data *devdata;
2080 if (!HAS_DDI(i915) && !IS_CHERRYVIEW(i915))
2083 if (i915->vbt.version < 155)
2086 list_for_each_entry(devdata, &i915->vbt.display_devices, node)
2087 parse_ddi_port(i915, devdata);
2091 parse_general_definitions(struct drm_i915_private *i915,
2092 const struct bdb_header *bdb)
2094 const struct bdb_general_definitions *defs;
2095 struct intel_bios_encoder_data *devdata;
2096 const struct child_device_config *child;
2097 int i, child_device_num;
2102 defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
2104 drm_dbg_kms(&i915->drm,
2105 "No general definition block is found, no devices defined.\n");
2109 block_size = get_blocksize(defs);
2110 if (block_size < sizeof(*defs)) {
2111 drm_dbg_kms(&i915->drm,
2112 "General definitions block too small (%u)\n",
2117 bus_pin = defs->crt_ddc_gmbus_pin;
2118 drm_dbg_kms(&i915->drm, "crt_ddc_bus_pin: %d\n", bus_pin);
2119 if (intel_gmbus_is_valid_pin(i915, bus_pin))
2120 i915->vbt.crt_ddc_pin = bus_pin;
2122 if (bdb->version < 106) {
2124 } else if (bdb->version < 111) {
2126 } else if (bdb->version < 195) {
2127 expected_size = LEGACY_CHILD_DEVICE_CONFIG_SIZE;
2128 } else if (bdb->version == 195) {
2130 } else if (bdb->version <= 215) {
2132 } else if (bdb->version <= 237) {
2135 expected_size = sizeof(*child);
2136 BUILD_BUG_ON(sizeof(*child) < 39);
2138 "Expected child device config size for VBT version %u not known; assuming %u\n",
2139 bdb->version, expected_size);
2142 /* Flag an error for unexpected size, but continue anyway. */
2143 if (defs->child_dev_size != expected_size)
2145 "Unexpected child device config size %u (expected %u for VBT version %u)\n",
2146 defs->child_dev_size, expected_size, bdb->version);
2148 /* The legacy sized child device config is the minimum we need. */
2149 if (defs->child_dev_size < LEGACY_CHILD_DEVICE_CONFIG_SIZE) {
2150 drm_dbg_kms(&i915->drm,
2151 "Child device config size %u is too small.\n",
2152 defs->child_dev_size);
2156 /* get the number of child device */
2157 child_device_num = (block_size - sizeof(*defs)) / defs->child_dev_size;
2159 for (i = 0; i < child_device_num; i++) {
2160 child = child_device_ptr(defs, i);
2161 if (!child->device_type)
2164 drm_dbg_kms(&i915->drm,
2165 "Found VBT child device with type 0x%x\n",
2166 child->device_type);
2168 devdata = kzalloc(sizeof(*devdata), GFP_KERNEL);
2172 devdata->i915 = i915;
2175 * Copy as much as we know (sizeof) and is available
2176 * (child_dev_size) of the child device config. Accessing the
2177 * data must depend on VBT version.
2179 memcpy(&devdata->child, child,
2180 min_t(size_t, defs->child_dev_size, sizeof(*child)));
2182 list_add_tail(&devdata->node, &i915->vbt.display_devices);
2185 if (list_empty(&i915->vbt.display_devices))
2186 drm_dbg_kms(&i915->drm,
2187 "no child dev is parsed from VBT\n");
2190 /* Common defaults which may be overridden by VBT. */
2192 init_vbt_defaults(struct drm_i915_private *i915)
2194 i915->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
2196 /* Default to having backlight */
2197 i915->vbt.backlight.present = true;
2199 /* LFP panel data */
2200 i915->vbt.lvds_dither = 1;
2202 /* SDVO panel data */
2203 i915->vbt.sdvo_lvds_vbt_mode = NULL;
2205 /* general features */
2206 i915->vbt.int_tv_support = 1;
2207 i915->vbt.int_crt_support = 1;
2209 /* driver features */
2210 i915->vbt.int_lvds_support = 1;
2212 /* Default to using SSC */
2213 i915->vbt.lvds_use_ssc = 1;
2215 * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
2218 i915->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(i915,
2219 !HAS_PCH_SPLIT(i915));
2220 drm_dbg_kms(&i915->drm, "Set default to SSC at %d kHz\n",
2221 i915->vbt.lvds_ssc_freq);
2224 /* Defaults to initialize only if there is no VBT. */
2226 init_vbt_missing_defaults(struct drm_i915_private *i915)
2229 int ports = BIT(PORT_A) | BIT(PORT_B) | BIT(PORT_C) |
2230 BIT(PORT_D) | BIT(PORT_E) | BIT(PORT_F);
2232 if (!HAS_DDI(i915) && !IS_CHERRYVIEW(i915))
2235 for_each_port_masked(port, ports) {
2236 struct intel_bios_encoder_data *devdata;
2237 struct child_device_config *child;
2238 enum phy phy = intel_port_to_phy(i915, port);
2241 * VBT has the TypeC mode (native,TBT/USB) and we don't want
2244 if (intel_phy_is_tc(i915, phy))
2247 /* Create fake child device config */
2248 devdata = kzalloc(sizeof(*devdata), GFP_KERNEL);
2252 devdata->i915 = i915;
2253 child = &devdata->child;
2256 child->dvo_port = DVO_PORT_HDMIF;
2257 else if (port == PORT_E)
2258 child->dvo_port = DVO_PORT_HDMIE;
2260 child->dvo_port = DVO_PORT_HDMIA + port;
2262 if (port != PORT_A && port != PORT_E)
2263 child->device_type |= DEVICE_TYPE_TMDS_DVI_SIGNALING;
2266 child->device_type |= DEVICE_TYPE_DISPLAYPORT_OUTPUT;
2269 child->device_type |= DEVICE_TYPE_INTERNAL_CONNECTOR;
2271 list_add_tail(&devdata->node, &i915->vbt.display_devices);
2273 drm_dbg_kms(&i915->drm,
2274 "Generating default VBT child device with type 0x04%x on port %c\n",
2275 child->device_type, port_name(port));
2278 /* Bypass some minimum baseline VBT version checks */
2279 i915->vbt.version = 155;
2282 static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
2284 const void *_vbt = vbt;
2286 return _vbt + vbt->bdb_offset;
2290 * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
2291 * @buf: pointer to a buffer to validate
2292 * @size: size of the buffer
2294 * Returns true on valid VBT.
2296 bool intel_bios_is_valid_vbt(const void *buf, size_t size)
2298 const struct vbt_header *vbt = buf;
2299 const struct bdb_header *bdb;
2304 if (sizeof(struct vbt_header) > size) {
2305 DRM_DEBUG_DRIVER("VBT header incomplete\n");
2309 if (memcmp(vbt->signature, "$VBT", 4)) {
2310 DRM_DEBUG_DRIVER("VBT invalid signature\n");
2314 if (vbt->vbt_size > size) {
2315 DRM_DEBUG_DRIVER("VBT incomplete (vbt_size overflows)\n");
2319 size = vbt->vbt_size;
2321 if (range_overflows_t(size_t,
2323 sizeof(struct bdb_header),
2325 DRM_DEBUG_DRIVER("BDB header incomplete\n");
2329 bdb = get_bdb_header(vbt);
2330 if (range_overflows_t(size_t, vbt->bdb_offset, bdb->bdb_size, size)) {
2331 DRM_DEBUG_DRIVER("BDB incomplete\n");
2338 static struct vbt_header *spi_oprom_get_vbt(struct drm_i915_private *i915)
2340 u32 count, data, found, store = 0;
2341 u32 static_region, oprom_offset;
2342 u32 oprom_size = 0x200000;
2346 static_region = intel_uncore_read(&i915->uncore, SPI_STATIC_REGIONS);
2347 static_region &= OPTIONROM_SPI_REGIONID_MASK;
2348 intel_uncore_write(&i915->uncore, PRIMARY_SPI_REGIONID, static_region);
2350 oprom_offset = intel_uncore_read(&i915->uncore, OROM_OFFSET);
2351 oprom_offset &= OROM_OFFSET_MASK;
2353 for (count = 0; count < oprom_size; count += 4) {
2354 intel_uncore_write(&i915->uncore, PRIMARY_SPI_ADDRESS, oprom_offset + count);
2355 data = intel_uncore_read(&i915->uncore, PRIMARY_SPI_TRIGGER);
2357 if (data == *((const u32 *)"$VBT")) {
2358 found = oprom_offset + count;
2363 if (count >= oprom_size)
2366 /* Get VBT size and allocate space for the VBT */
2367 intel_uncore_write(&i915->uncore, PRIMARY_SPI_ADDRESS, found +
2368 offsetof(struct vbt_header, vbt_size));
2369 vbt_size = intel_uncore_read(&i915->uncore, PRIMARY_SPI_TRIGGER);
2372 vbt = kzalloc(round_up(vbt_size, 4), GFP_KERNEL);
2376 for (count = 0; count < vbt_size; count += 4) {
2377 intel_uncore_write(&i915->uncore, PRIMARY_SPI_ADDRESS, found + count);
2378 data = intel_uncore_read(&i915->uncore, PRIMARY_SPI_TRIGGER);
2379 *(vbt + store++) = data;
2382 if (!intel_bios_is_valid_vbt(vbt, vbt_size))
2385 drm_dbg_kms(&i915->drm, "Found valid VBT in SPI flash\n");
2387 return (struct vbt_header *)vbt;
2395 static struct vbt_header *oprom_get_vbt(struct drm_i915_private *i915)
2397 struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
2398 void __iomem *p = NULL, *oprom;
2399 struct vbt_header *vbt;
2403 oprom = pci_map_rom(pdev, &size);
2407 /* Scour memory looking for the VBT signature. */
2408 for (i = 0; i + 4 < size; i += 4) {
2409 if (ioread32(oprom + i) != *((const u32 *)"$VBT"))
2418 goto err_unmap_oprom;
2420 if (sizeof(struct vbt_header) > size) {
2421 drm_dbg(&i915->drm, "VBT header incomplete\n");
2422 goto err_unmap_oprom;
2425 vbt_size = ioread16(p + offsetof(struct vbt_header, vbt_size));
2426 if (vbt_size > size) {
2428 "VBT incomplete (vbt_size overflows)\n");
2429 goto err_unmap_oprom;
2432 /* The rest will be validated by intel_bios_is_valid_vbt() */
2433 vbt = kmalloc(vbt_size, GFP_KERNEL);
2435 goto err_unmap_oprom;
2437 memcpy_fromio(vbt, p, vbt_size);
2439 if (!intel_bios_is_valid_vbt(vbt, vbt_size))
2442 pci_unmap_rom(pdev, oprom);
2444 drm_dbg_kms(&i915->drm, "Found valid VBT in PCI ROM\n");
2451 pci_unmap_rom(pdev, oprom);
2457 * intel_bios_init - find VBT and initialize settings from the BIOS
2458 * @i915: i915 device instance
2460 * Parse and initialize settings from the Video BIOS Tables (VBT). If the VBT
2461 * was not found in ACPI OpRegion, try to find it in PCI ROM first. Also
2462 * initialize some defaults if the VBT is not present at all.
2464 void intel_bios_init(struct drm_i915_private *i915)
2466 const struct vbt_header *vbt = i915->opregion.vbt;
2467 struct vbt_header *oprom_vbt = NULL;
2468 const struct bdb_header *bdb;
2470 INIT_LIST_HEAD(&i915->vbt.display_devices);
2472 if (!HAS_DISPLAY(i915)) {
2473 drm_dbg_kms(&i915->drm,
2474 "Skipping VBT init due to disabled display.\n");
2478 init_vbt_defaults(i915);
2481 * If the OpRegion does not have VBT, look in SPI flash through MMIO or
2484 if (!vbt && IS_DGFX(i915)) {
2485 oprom_vbt = spi_oprom_get_vbt(i915);
2490 oprom_vbt = oprom_get_vbt(i915);
2497 bdb = get_bdb_header(vbt);
2498 i915->vbt.version = bdb->version;
2500 drm_dbg_kms(&i915->drm,
2501 "VBT signature \"%.*s\", BDB version %d\n",
2502 (int)sizeof(vbt->signature), vbt->signature, bdb->version);
2504 /* Grab useful general definitions */
2505 parse_general_features(i915, bdb);
2506 parse_general_definitions(i915, bdb);
2507 parse_panel_options(i915, bdb);
2508 parse_panel_dtd(i915, bdb);
2509 parse_lfp_backlight(i915, bdb);
2510 parse_sdvo_panel_data(i915, bdb);
2511 parse_driver_features(i915, bdb);
2512 parse_power_conservation_features(i915, bdb);
2513 parse_edp(i915, bdb);
2514 parse_psr(i915, bdb);
2515 parse_mipi_config(i915, bdb);
2516 parse_mipi_sequence(i915, bdb);
2518 /* Depends on child device list */
2519 parse_compression_parameters(i915, bdb);
2523 drm_info(&i915->drm,
2524 "Failed to find VBIOS tables (VBT)\n");
2525 init_vbt_missing_defaults(i915);
2528 /* Further processing on pre-parsed or generated child device data */
2529 parse_sdvo_device_mapping(i915);
2530 parse_ddi_ports(i915);
2536 * intel_bios_driver_remove - Free any resources allocated by intel_bios_init()
2537 * @i915: i915 device instance
2539 void intel_bios_driver_remove(struct drm_i915_private *i915)
2541 struct intel_bios_encoder_data *devdata, *n;
2543 list_for_each_entry_safe(devdata, n, &i915->vbt.display_devices, node) {
2544 list_del(&devdata->node);
2545 kfree(devdata->dsc);
2549 kfree(i915->vbt.sdvo_lvds_vbt_mode);
2550 i915->vbt.sdvo_lvds_vbt_mode = NULL;
2551 kfree(i915->vbt.lfp_lvds_vbt_mode);
2552 i915->vbt.lfp_lvds_vbt_mode = NULL;
2553 kfree(i915->vbt.dsi.data);
2554 i915->vbt.dsi.data = NULL;
2555 kfree(i915->vbt.dsi.pps);
2556 i915->vbt.dsi.pps = NULL;
2557 kfree(i915->vbt.dsi.config);
2558 i915->vbt.dsi.config = NULL;
2559 kfree(i915->vbt.dsi.deassert_seq);
2560 i915->vbt.dsi.deassert_seq = NULL;
2564 * intel_bios_is_tv_present - is integrated TV present in VBT
2565 * @i915: i915 device instance
2567 * Return true if TV is present. If no child devices were parsed from VBT,
2568 * assume TV is present.
2570 bool intel_bios_is_tv_present(struct drm_i915_private *i915)
2572 const struct intel_bios_encoder_data *devdata;
2573 const struct child_device_config *child;
2575 if (!i915->vbt.int_tv_support)
2578 if (list_empty(&i915->vbt.display_devices))
2581 list_for_each_entry(devdata, &i915->vbt.display_devices, node) {
2582 child = &devdata->child;
2585 * If the device type is not TV, continue.
2587 switch (child->device_type) {
2588 case DEVICE_TYPE_INT_TV:
2589 case DEVICE_TYPE_TV:
2590 case DEVICE_TYPE_TV_SVIDEO_COMPOSITE:
2595 /* Only when the addin_offset is non-zero, it is regarded
2598 if (child->addin_offset)
2606 * intel_bios_is_lvds_present - is LVDS present in VBT
2607 * @i915: i915 device instance
2608 * @i2c_pin: i2c pin for LVDS if present
2610 * Return true if LVDS is present. If no child devices were parsed from VBT,
2611 * assume LVDS is present.
2613 bool intel_bios_is_lvds_present(struct drm_i915_private *i915, u8 *i2c_pin)
2615 const struct intel_bios_encoder_data *devdata;
2616 const struct child_device_config *child;
2618 if (list_empty(&i915->vbt.display_devices))
2621 list_for_each_entry(devdata, &i915->vbt.display_devices, node) {
2622 child = &devdata->child;
2624 /* If the device type is not LFP, continue.
2625 * We have to check both the new identifiers as well as the
2626 * old for compatibility with some BIOSes.
2628 if (child->device_type != DEVICE_TYPE_INT_LFP &&
2629 child->device_type != DEVICE_TYPE_LFP)
2632 if (intel_gmbus_is_valid_pin(i915, child->i2c_pin))
2633 *i2c_pin = child->i2c_pin;
2635 /* However, we cannot trust the BIOS writers to populate
2636 * the VBT correctly. Since LVDS requires additional
2637 * information from AIM blocks, a non-zero addin offset is
2638 * a good indicator that the LVDS is actually present.
2640 if (child->addin_offset)
2643 /* But even then some BIOS writers perform some black magic
2644 * and instantiate the device without reference to any
2645 * additional data. Trust that if the VBT was written into
2646 * the OpRegion then they have validated the LVDS's existence.
2648 if (i915->opregion.vbt)
2656 * intel_bios_is_port_present - is the specified digital port present
2657 * @i915: i915 device instance
2658 * @port: port to check
2660 * Return true if the device in %port is present.
2662 bool intel_bios_is_port_present(struct drm_i915_private *i915, enum port port)
2664 const struct intel_bios_encoder_data *devdata;
2665 const struct child_device_config *child;
2666 static const struct {
2668 } port_mapping[] = {
2669 [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
2670 [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
2671 [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
2672 [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
2673 [PORT_F] = { DVO_PORT_DPF, DVO_PORT_HDMIF, },
2677 return i915->vbt.ports[port];
2679 /* FIXME maybe deal with port A as well? */
2680 if (drm_WARN_ON(&i915->drm,
2681 port == PORT_A) || port >= ARRAY_SIZE(port_mapping))
2684 list_for_each_entry(devdata, &i915->vbt.display_devices, node) {
2685 child = &devdata->child;
2687 if ((child->dvo_port == port_mapping[port].dp ||
2688 child->dvo_port == port_mapping[port].hdmi) &&
2689 (child->device_type & (DEVICE_TYPE_TMDS_DVI_SIGNALING |
2690 DEVICE_TYPE_DISPLAYPORT_OUTPUT)))
2698 * intel_bios_is_port_edp - is the device in given port eDP
2699 * @i915: i915 device instance
2700 * @port: port to check
2702 * Return true if the device in %port is eDP.
2704 bool intel_bios_is_port_edp(struct drm_i915_private *i915, enum port port)
2706 const struct intel_bios_encoder_data *devdata;
2707 const struct child_device_config *child;
2708 static const short port_mapping[] = {
2709 [PORT_B] = DVO_PORT_DPB,
2710 [PORT_C] = DVO_PORT_DPC,
2711 [PORT_D] = DVO_PORT_DPD,
2712 [PORT_E] = DVO_PORT_DPE,
2713 [PORT_F] = DVO_PORT_DPF,
2716 if (HAS_DDI(i915)) {
2717 const struct intel_bios_encoder_data *devdata;
2719 devdata = intel_bios_encoder_data_lookup(i915, port);
2721 return devdata && intel_bios_encoder_supports_edp(devdata);
2724 list_for_each_entry(devdata, &i915->vbt.display_devices, node) {
2725 child = &devdata->child;
2727 if (child->dvo_port == port_mapping[port] &&
2728 (child->device_type & DEVICE_TYPE_eDP_BITS) ==
2729 (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
2736 static bool child_dev_is_dp_dual_mode(const struct child_device_config *child)
2738 if ((child->device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) !=
2739 (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
2742 if (dvo_port_type(child->dvo_port) == DVO_PORT_DPA)
2745 /* Only accept a HDMI dvo_port as DP++ if it has an AUX channel */
2746 if (dvo_port_type(child->dvo_port) == DVO_PORT_HDMIA &&
2747 child->aux_channel != 0)
2753 bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *i915,
2756 static const struct {
2758 } port_mapping[] = {
2760 * Buggy VBTs may declare DP ports as having
2761 * HDMI type dvo_port :( So let's check both.
2763 [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
2764 [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
2765 [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
2766 [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
2767 [PORT_F] = { DVO_PORT_DPF, DVO_PORT_HDMIF, },
2769 const struct intel_bios_encoder_data *devdata;
2771 if (HAS_DDI(i915)) {
2772 const struct intel_bios_encoder_data *devdata;
2774 devdata = intel_bios_encoder_data_lookup(i915, port);
2776 return devdata && child_dev_is_dp_dual_mode(&devdata->child);
2779 if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
2782 list_for_each_entry(devdata, &i915->vbt.display_devices, node) {
2783 if ((devdata->child.dvo_port == port_mapping[port].dp ||
2784 devdata->child.dvo_port == port_mapping[port].hdmi) &&
2785 child_dev_is_dp_dual_mode(&devdata->child))
2793 * intel_bios_is_dsi_present - is DSI present in VBT
2794 * @i915: i915 device instance
2795 * @port: port for DSI if present
2797 * Return true if DSI is present, and return the port in %port.
2799 bool intel_bios_is_dsi_present(struct drm_i915_private *i915,
2802 const struct intel_bios_encoder_data *devdata;
2803 const struct child_device_config *child;
2806 list_for_each_entry(devdata, &i915->vbt.display_devices, node) {
2807 child = &devdata->child;
2809 if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT))
2812 dvo_port = child->dvo_port;
2814 if (dvo_port == DVO_PORT_MIPIA ||
2815 (dvo_port == DVO_PORT_MIPIB && DISPLAY_VER(i915) >= 11) ||
2816 (dvo_port == DVO_PORT_MIPIC && DISPLAY_VER(i915) < 11)) {
2818 *port = dvo_port - DVO_PORT_MIPIA;
2820 } else if (dvo_port == DVO_PORT_MIPIB ||
2821 dvo_port == DVO_PORT_MIPIC ||
2822 dvo_port == DVO_PORT_MIPID) {
2823 drm_dbg_kms(&i915->drm,
2824 "VBT has unsupported DSI port %c\n",
2825 port_name(dvo_port - DVO_PORT_MIPIA));
2832 static void fill_dsc(struct intel_crtc_state *crtc_state,
2833 struct dsc_compression_parameters_entry *dsc,
2836 struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config;
2839 vdsc_cfg->dsc_version_major = dsc->version_major;
2840 vdsc_cfg->dsc_version_minor = dsc->version_minor;
2842 if (dsc->support_12bpc && dsc_max_bpc >= 12)
2844 else if (dsc->support_10bpc && dsc_max_bpc >= 10)
2846 else if (dsc->support_8bpc && dsc_max_bpc >= 8)
2849 DRM_DEBUG_KMS("VBT: Unsupported BPC %d for DCS\n",
2852 crtc_state->pipe_bpp = bpc * 3;
2854 crtc_state->dsc.compressed_bpp = min(crtc_state->pipe_bpp,
2855 VBT_DSC_MAX_BPP(dsc->max_bpp));
2858 * FIXME: This is ugly, and slice count should take DSC engine
2859 * throughput etc. into account.
2861 * Also, per spec DSI supports 1, 2, 3 or 4 horizontal slices.
2863 if (dsc->slices_per_line & BIT(2)) {
2864 crtc_state->dsc.slice_count = 4;
2865 } else if (dsc->slices_per_line & BIT(1)) {
2866 crtc_state->dsc.slice_count = 2;
2869 if (!(dsc->slices_per_line & BIT(0)))
2870 DRM_DEBUG_KMS("VBT: Unsupported DSC slice count for DSI\n");
2872 crtc_state->dsc.slice_count = 1;
2875 if (crtc_state->hw.adjusted_mode.crtc_hdisplay %
2876 crtc_state->dsc.slice_count != 0)
2877 DRM_DEBUG_KMS("VBT: DSC hdisplay %d not divisible by slice count %d\n",
2878 crtc_state->hw.adjusted_mode.crtc_hdisplay,
2879 crtc_state->dsc.slice_count);
2882 * The VBT rc_buffer_block_size and rc_buffer_size definitions
2883 * correspond to DP 1.4 DPCD offsets 0x62 and 0x63.
2885 vdsc_cfg->rc_model_size = drm_dsc_dp_rc_buffer_size(dsc->rc_buffer_block_size,
2886 dsc->rc_buffer_size);
2888 /* FIXME: DSI spec says bpc + 1 for this one */
2889 vdsc_cfg->line_buf_depth = VBT_DSC_LINE_BUFFER_DEPTH(dsc->line_buffer_depth);
2891 vdsc_cfg->block_pred_enable = dsc->block_prediction_enable;
2893 vdsc_cfg->slice_height = dsc->slice_height;
2896 /* FIXME: initially DSI specific */
2897 bool intel_bios_get_dsc_params(struct intel_encoder *encoder,
2898 struct intel_crtc_state *crtc_state,
2901 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
2902 const struct intel_bios_encoder_data *devdata;
2903 const struct child_device_config *child;
2905 list_for_each_entry(devdata, &i915->vbt.display_devices, node) {
2906 child = &devdata->child;
2908 if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT))
2911 if (child->dvo_port - DVO_PORT_MIPIA == encoder->port) {
2916 fill_dsc(crtc_state, devdata->dsc, dsc_max_bpc);
2926 * intel_bios_is_port_hpd_inverted - is HPD inverted for %port
2927 * @i915: i915 device instance
2928 * @port: port to check
2930 * Return true if HPD should be inverted for %port.
2933 intel_bios_is_port_hpd_inverted(const struct drm_i915_private *i915,
2936 const struct intel_bios_encoder_data *devdata = i915->vbt.ports[port];
2938 if (drm_WARN_ON_ONCE(&i915->drm,
2939 !IS_GEMINILAKE(i915) && !IS_BROXTON(i915)))
2942 return devdata && devdata->child.hpd_invert;
2946 * intel_bios_is_lspcon_present - if LSPCON is attached on %port
2947 * @i915: i915 device instance
2948 * @port: port to check
2950 * Return true if LSPCON is present on this port
2953 intel_bios_is_lspcon_present(const struct drm_i915_private *i915,
2956 const struct intel_bios_encoder_data *devdata = i915->vbt.ports[port];
2958 return HAS_LSPCON(i915) && devdata && devdata->child.lspcon;
2962 * intel_bios_is_lane_reversal_needed - if lane reversal needed on port
2963 * @i915: i915 device instance
2964 * @port: port to check
2966 * Return true if port requires lane reversal
2969 intel_bios_is_lane_reversal_needed(const struct drm_i915_private *i915,
2972 const struct intel_bios_encoder_data *devdata = i915->vbt.ports[port];
2974 return devdata && devdata->child.lane_reversal;
2977 enum aux_ch intel_bios_port_aux_ch(struct drm_i915_private *i915,
2980 const struct intel_bios_encoder_data *devdata = i915->vbt.ports[port];
2983 if (!devdata || !devdata->child.aux_channel) {
2984 aux_ch = (enum aux_ch)port;
2986 drm_dbg_kms(&i915->drm,
2987 "using AUX %c for port %c (platform default)\n",
2988 aux_ch_name(aux_ch), port_name(port));
2993 * RKL/DG1 VBT uses PHY based mapping. Combo PHYs A,B,C,D
2994 * map to DDI A,B,TC1,TC2 respectively.
2996 * ADL-S VBT uses PHY based mapping. Combo PHYs A,B,C,D,E
2997 * map to DDI A,TC1,TC2,TC3,TC4 respectively.
2999 switch (devdata->child.aux_channel) {
3004 if (IS_ALDERLAKE_S(i915))
3005 aux_ch = AUX_CH_USBC1;
3010 if (IS_ALDERLAKE_S(i915))
3011 aux_ch = AUX_CH_USBC2;
3012 else if (IS_DG1(i915) || IS_ROCKETLAKE(i915))
3013 aux_ch = AUX_CH_USBC1;
3018 if (DISPLAY_VER(i915) == 13)
3019 aux_ch = AUX_CH_D_XELPD;
3020 else if (IS_ALDERLAKE_S(i915))
3021 aux_ch = AUX_CH_USBC3;
3022 else if (IS_DG1(i915) || IS_ROCKETLAKE(i915))
3023 aux_ch = AUX_CH_USBC2;
3028 if (DISPLAY_VER(i915) == 13)
3029 aux_ch = AUX_CH_E_XELPD;
3030 else if (IS_ALDERLAKE_S(i915))
3031 aux_ch = AUX_CH_USBC4;
3036 if (DISPLAY_VER(i915) == 13)
3037 aux_ch = AUX_CH_USBC1;
3042 if (DISPLAY_VER(i915) == 13)
3043 aux_ch = AUX_CH_USBC2;
3048 if (DISPLAY_VER(i915) == 13)
3049 aux_ch = AUX_CH_USBC3;
3054 if (DISPLAY_VER(i915) == 13)
3055 aux_ch = AUX_CH_USBC4;
3060 MISSING_CASE(devdata->child.aux_channel);
3065 drm_dbg_kms(&i915->drm, "using AUX %c for port %c (VBT)\n",
3066 aux_ch_name(aux_ch), port_name(port));
3071 int intel_bios_max_tmds_clock(struct intel_encoder *encoder)
3073 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3074 const struct intel_bios_encoder_data *devdata = i915->vbt.ports[encoder->port];
3076 return _intel_bios_max_tmds_clock(devdata);
3079 /* This is an index in the HDMI/DVI DDI buffer translation table, or -1 */
3080 int intel_bios_hdmi_level_shift(struct intel_encoder *encoder)
3082 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3083 const struct intel_bios_encoder_data *devdata = i915->vbt.ports[encoder->port];
3085 return _intel_bios_hdmi_level_shift(devdata);
3088 int intel_bios_encoder_dp_boost_level(const struct intel_bios_encoder_data *devdata)
3090 if (!devdata || devdata->i915->vbt.version < 196 || !devdata->child.iboost)
3093 return translate_iboost(devdata->child.dp_iboost_level);
3096 int intel_bios_encoder_hdmi_boost_level(const struct intel_bios_encoder_data *devdata)
3098 if (!devdata || devdata->i915->vbt.version < 196 || !devdata->child.iboost)
3101 return translate_iboost(devdata->child.hdmi_iboost_level);
3104 int intel_bios_dp_max_link_rate(struct intel_encoder *encoder)
3106 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3107 const struct intel_bios_encoder_data *devdata = i915->vbt.ports[encoder->port];
3109 return _intel_bios_dp_max_link_rate(devdata);
3112 int intel_bios_alternate_ddc_pin(struct intel_encoder *encoder)
3114 struct drm_i915_private *i915 = to_i915(encoder->base.dev);
3115 const struct intel_bios_encoder_data *devdata = i915->vbt.ports[encoder->port];
3117 if (!devdata || !devdata->child.ddc_pin)
3120 return map_ddc_pin(i915, devdata->child.ddc_pin);
3123 bool intel_bios_encoder_supports_typec_usb(const struct intel_bios_encoder_data *devdata)
3125 return devdata->i915->vbt.version >= 195 && devdata->child.dp_usb_type_c;
3128 bool intel_bios_encoder_supports_tbt(const struct intel_bios_encoder_data *devdata)
3130 return devdata->i915->vbt.version >= 209 && devdata->child.tbt;
3133 const struct intel_bios_encoder_data *
3134 intel_bios_encoder_data_lookup(struct drm_i915_private *i915, enum port port)
3136 return i915->vbt.ports[port];