]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/gpu/drm/i915/intel_bios.c
drm/i915/bios: filter out invalid DDC pins from VBT child devices
[mirror_ubuntu-artful-kernel.git] / drivers / gpu / drm / i915 / intel_bios.c
1 /*
2 * Copyright © 2006 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
27
28 #include <drm/drm_dp_helper.h>
29 #include <drm/drmP.h>
30 #include <drm/i915_drm.h>
31 #include "i915_drv.h"
32 #include <linux/dmi.h>
33
34 #define _INTEL_BIOS_PRIVATE
35 #include "intel_vbt_defs.h"
36
37 /**
38 * DOC: Video BIOS Table (VBT)
39 *
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
44 * the PCI ROM.
45 *
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.)
53 *
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
56 * that.
57 */
58
59 #define SLAVE_ADDR1 0x70
60 #define SLAVE_ADDR2 0x72
61
62 /* Get BDB block size given a pointer to Block ID. */
63 static u32 _get_blocksize(const u8 *block_base)
64 {
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));
68 else
69 return *((const u16 *)(block_base + 1));
70 }
71
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)
74 {
75 return _get_blocksize(block_data - 3);
76 }
77
78 static const void *
79 find_section(const void *_bdb, int section_id)
80 {
81 const struct bdb_header *bdb = _bdb;
82 const u8 *base = _bdb;
83 int index = 0;
84 u32 total, current_size;
85 u8 current_id;
86
87 /* skip to first section */
88 index += bdb->header_size;
89 total = bdb->bdb_size;
90
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);
95 index += 3;
96
97 if (index + current_size > total)
98 return NULL;
99
100 if (current_id == section_id)
101 return base + index;
102
103 index += current_size;
104 }
105
106 return NULL;
107 }
108
109 static void
110 fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
111 const struct lvds_dvo_timing *dvo_timing)
112 {
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);
122
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;
134
135 if (dvo_timing->hsync_positive)
136 panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
137 else
138 panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
139
140 if (dvo_timing->vsync_positive)
141 panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
142 else
143 panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
144
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;
149
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;
155
156 drm_mode_set_name(panel_fixed_mode);
157 }
158
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,
162 int index)
163 {
164 /*
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
168 */
169
170 int lfp_data_size =
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;
177
178 return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
179 }
180
181 /* get lvds_fp_timing entry
182 * this function may return NULL if the corresponding entry is invalid
183 */
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,
188 int index)
189 {
190 size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
191 u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
192 size_t ofs;
193
194 if (index >= ARRAY_SIZE(ptrs->ptr))
195 return NULL;
196 ofs = ptrs->ptr[index].fp_timing_offset;
197 if (ofs < data_ofs ||
198 ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
199 return NULL;
200 return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
201 }
202
203 /* Try to find integrated panel data */
204 static void
205 parse_lfp_panel_data(struct drm_i915_private *dev_priv,
206 const struct bdb_header *bdb)
207 {
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;
214 int panel_type;
215 int drrs_mode;
216 int ret;
217
218 lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
219 if (!lvds_options)
220 return;
221
222 dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
223
224 ret = intel_opregion_get_panel_type(dev_priv);
225 if (ret >= 0) {
226 WARN_ON(ret > 0xf);
227 panel_type = ret;
228 DRM_DEBUG_KMS("Panel type: %d (OpRegion)\n", panel_type);
229 } else {
230 if (lvds_options->panel_type > 0xf) {
231 DRM_DEBUG_KMS("Invalid VBT panel type 0x%x\n",
232 lvds_options->panel_type);
233 return;
234 }
235 panel_type = lvds_options->panel_type;
236 DRM_DEBUG_KMS("Panel type: %d (VBT)\n", panel_type);
237 }
238
239 dev_priv->vbt.panel_type = panel_type;
240
241 drrs_mode = (lvds_options->dps_panel_type_bits
242 >> (panel_type * 2)) & MODE_MASK;
243 /*
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.
247 */
248 switch (drrs_mode) {
249 case 0:
250 dev_priv->vbt.drrs_type = STATIC_DRRS_SUPPORT;
251 DRM_DEBUG_KMS("DRRS supported mode is static\n");
252 break;
253 case 2:
254 dev_priv->vbt.drrs_type = SEAMLESS_DRRS_SUPPORT;
255 DRM_DEBUG_KMS("DRRS supported mode is seamless\n");
256 break;
257 default:
258 dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
259 DRM_DEBUG_KMS("DRRS not supported (VBT input)\n");
260 break;
261 }
262
263 lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
264 if (!lvds_lfp_data)
265 return;
266
267 lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
268 if (!lvds_lfp_data_ptrs)
269 return;
270
271 dev_priv->vbt.lvds_vbt = 1;
272
273 panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
274 lvds_lfp_data_ptrs,
275 panel_type);
276
277 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
278 if (!panel_fixed_mode)
279 return;
280
281 fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
282
283 dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
284
285 DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
286 drm_mode_debug_printmodeline(panel_fixed_mode);
287
288 fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
289 lvds_lfp_data_ptrs,
290 panel_type);
291 if (fp_timing) {
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);
298 }
299 }
300 }
301
302 static void
303 parse_lfp_backlight(struct drm_i915_private *dev_priv,
304 const struct bdb_header *bdb)
305 {
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;
309
310 backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
311 if (!backlight_data)
312 return;
313
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);
317 return;
318 }
319
320 entry = &backlight_data->data[panel_type];
321
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",
325 entry->type);
326 return;
327 }
328
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;
333
334 method = &backlight_data->backlight_control[panel_type];
335 dev_priv->vbt.backlight.type = method->type;
336 dev_priv->vbt.backlight.controller = method->controller;
337 }
338
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);
349 }
350
351 /* Try to find sdvo panel data */
352 static void
353 parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
354 const struct bdb_header *bdb)
355 {
356 const struct lvds_dvo_timing *dvo_timing;
357 struct drm_display_mode *panel_fixed_mode;
358 int index;
359
360 index = i915.vbt_sdvo_panel_type;
361 if (index == -2) {
362 DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
363 return;
364 }
365
366 if (index == -1) {
367 const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
368
369 sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
370 if (!sdvo_lvds_options)
371 return;
372
373 index = sdvo_lvds_options->panel_type;
374 }
375
376 dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
377 if (!dvo_timing)
378 return;
379
380 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
381 if (!panel_fixed_mode)
382 return;
383
384 fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
385
386 dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
387
388 DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
389 drm_mode_debug_printmodeline(panel_fixed_mode);
390 }
391
392 static int intel_bios_ssc_frequency(struct drm_i915_private *dev_priv,
393 bool alternate)
394 {
395 switch (INTEL_INFO(dev_priv)->gen) {
396 case 2:
397 return alternate ? 66667 : 48000;
398 case 3:
399 case 4:
400 return alternate ? 100000 : 96000;
401 default:
402 return alternate ? 100000 : 120000;
403 }
404 }
405
406 static void
407 parse_general_features(struct drm_i915_private *dev_priv,
408 const struct bdb_header *bdb)
409 {
410 const struct bdb_general_features *general;
411
412 general = find_section(bdb, BDB_GENERAL_FEATURES);
413 if (!general)
414 return;
415
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);
433 }
434
435 static void
436 parse_general_definitions(struct drm_i915_private *dev_priv,
437 const struct bdb_header *bdb)
438 {
439 const struct bdb_general_definitions *general;
440
441 general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
442 if (general) {
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;
449 } else {
450 DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
451 block_size);
452 }
453 }
454 }
455
456 static const union child_device_config *
457 child_device_ptr(const struct bdb_general_definitions *p_defs, int i)
458 {
459 return (const void *) &p_defs->devices[i * p_defs->child_dev_size];
460 }
461
462 static void
463 parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
464 const struct bdb_header *bdb)
465 {
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;
470 u16 block_size;
471
472 p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
473 if (!p_defs) {
474 DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
475 return;
476 }
477
478 /*
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.
482 */
483 if (p_defs->child_dev_size != sizeof(*child)) {
484 DRM_DEBUG_KMS("Unsupported child device size for SDVO mapping.\n");
485 return;
486 }
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;
492 count = 0;
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 */
497 continue;
498 }
499 if (child->slave_addr != SLAVE_ADDR1 &&
500 child->slave_addr != SLAVE_ADDR2) {
501 /*
502 * If the slave address is neither 0x70 nor 0x72,
503 * it is not a SDVO device. Skip it.
504 */
505 continue;
506 }
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");
511 continue;
512 }
513 DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
514 " %s port\n",
515 child->slave_addr,
516 (child->dvo_port == DEVICE_PORT_DVOB) ?
517 "SDVOB" : "SDVOC");
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",
527 p_mapping->dvo_port,
528 p_mapping->slave_addr,
529 p_mapping->dvo_wiring,
530 p_mapping->ddc_pin,
531 p_mapping->i2c_pin);
532 } else {
533 DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
534 "two SDVO device.\n");
535 }
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");
541 }
542 count++;
543 }
544
545 if (!count) {
546 /* No SDVO device info is found */
547 DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
548 }
549 return;
550 }
551
552 static void
553 parse_driver_features(struct drm_i915_private *dev_priv,
554 const struct bdb_header *bdb)
555 {
556 const struct bdb_driver_features *driver;
557
558 driver = find_section(bdb, BDB_DRIVER_FEATURES);
559 if (!driver)
560 return;
561
562 if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
563 dev_priv->vbt.edp.support = 1;
564
565 DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
566 /*
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
571 */
572 if (!driver->drrs_enabled)
573 dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
574 }
575
576 static void
577 parse_edp(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
578 {
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;
583
584 edp = find_section(bdb, BDB_EDP);
585 if (!edp) {
586 if (dev_priv->vbt.edp.support)
587 DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
588 return;
589 }
590
591 switch ((edp->color_depth >> (panel_type * 2)) & 3) {
592 case EDP_18BPP:
593 dev_priv->vbt.edp.bpp = 18;
594 break;
595 case EDP_24BPP:
596 dev_priv->vbt.edp.bpp = 24;
597 break;
598 case EDP_30BPP:
599 dev_priv->vbt.edp.bpp = 30;
600 break;
601 }
602
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];
606
607 dev_priv->vbt.edp.pps = *edp_pps;
608
609 switch (edp_link_params->rate) {
610 case EDP_RATE_1_62:
611 dev_priv->vbt.edp.rate = DP_LINK_BW_1_62;
612 break;
613 case EDP_RATE_2_7:
614 dev_priv->vbt.edp.rate = DP_LINK_BW_2_7;
615 break;
616 default:
617 DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
618 edp_link_params->rate);
619 break;
620 }
621
622 switch (edp_link_params->lanes) {
623 case EDP_LANE_1:
624 dev_priv->vbt.edp.lanes = 1;
625 break;
626 case EDP_LANE_2:
627 dev_priv->vbt.edp.lanes = 2;
628 break;
629 case EDP_LANE_4:
630 dev_priv->vbt.edp.lanes = 4;
631 break;
632 default:
633 DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
634 edp_link_params->lanes);
635 break;
636 }
637
638 switch (edp_link_params->preemphasis) {
639 case EDP_PREEMPHASIS_NONE:
640 dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
641 break;
642 case EDP_PREEMPHASIS_3_5dB:
643 dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
644 break;
645 case EDP_PREEMPHASIS_6dB:
646 dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
647 break;
648 case EDP_PREEMPHASIS_9_5dB:
649 dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
650 break;
651 default:
652 DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
653 edp_link_params->preemphasis);
654 break;
655 }
656
657 switch (edp_link_params->vswing) {
658 case EDP_VSWING_0_4V:
659 dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
660 break;
661 case EDP_VSWING_0_6V:
662 dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
663 break;
664 case EDP_VSWING_0_8V:
665 dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
666 break;
667 case EDP_VSWING_1_2V:
668 dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
669 break;
670 default:
671 DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
672 edp_link_params->vswing);
673 break;
674 }
675
676 if (bdb->version >= 173) {
677 uint8_t vswing;
678
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;
682 } else {
683 vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
684 dev_priv->vbt.edp.low_vswing = vswing == 0;
685 }
686 }
687 }
688
689 static void
690 parse_psr(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
691 {
692 const struct bdb_psr *psr;
693 const struct psr_table *psr_table;
694 int panel_type = dev_priv->vbt.panel_type;
695
696 psr = find_section(bdb, BDB_PSR);
697 if (!psr) {
698 DRM_DEBUG_KMS("No PSR BDB found.\n");
699 return;
700 }
701
702 psr_table = &psr->psr_table[panel_type];
703
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;
706
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;
710
711 switch (psr_table->lines_to_wait) {
712 case 0:
713 dev_priv->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
714 break;
715 case 1:
716 dev_priv->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
717 break;
718 case 2:
719 dev_priv->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
720 break;
721 case 3:
722 dev_priv->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
723 break;
724 default:
725 DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
726 psr_table->lines_to_wait);
727 break;
728 }
729
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;
732 }
733
734 static void
735 parse_mipi_config(struct drm_i915_private *dev_priv,
736 const struct bdb_header *bdb)
737 {
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;
742
743 /* parse MIPI blocks only if LFP type is MIPI */
744 if (!intel_bios_is_dsi_present(dev_priv, NULL))
745 return;
746
747 /* Initialize this to undefined indicating no generic MIPI support */
748 dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
749
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
753 */
754
755 /* Parse #52 for panel index used from panel_type already
756 * parsed
757 */
758 start = find_section(bdb, BDB_MIPI_CONFIG);
759 if (!start) {
760 DRM_DEBUG_KMS("No MIPI config BDB found");
761 return;
762 }
763
764 DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
765 panel_type);
766
767 /*
768 * get hold of the correct configuration block and pps data as per
769 * the panel_type as index
770 */
771 config = &start->config[panel_type];
772 pps = &start->pps[panel_type];
773
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)
777 return;
778
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);
782 return;
783 }
784
785 /*
786 * These fields are introduced from the VBT version 197 onwards,
787 * so making sure that these bits are set zero in the previous
788 * versions.
789 */
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;
793 }
794
795 /* We have mandatory mipi config blocks. Initialize as generic panel */
796 dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
797 }
798
799 /* Find the sequence block and size for the given panel. */
800 static const u8 *
801 find_panel_sequence_block(const struct bdb_mipi_sequence *sequence,
802 u16 panel_id, u32 *seq_size)
803 {
804 u32 total = get_blocksize(sequence);
805 const u8 *data = &sequence->data[0];
806 u8 current_id;
807 u32 current_size;
808 int header_size = sequence->version >= 3 ? 5 : 3;
809 int index = 0;
810 int i;
811
812 /* skip new block size */
813 if (sequence->version >= 3)
814 data += 4;
815
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");
819 return NULL;
820 }
821
822 current_id = *(data + index);
823 if (sequence->version >= 3)
824 current_size = *((const u32 *)(data + index + 1));
825 else
826 current_size = *((const u16 *)(data + index + 1));
827
828 index += header_size;
829
830 if (index + current_size > total) {
831 DRM_ERROR("Invalid sequence block\n");
832 return NULL;
833 }
834
835 if (current_id == panel_id) {
836 *seq_size = current_size;
837 return data + index;
838 }
839
840 index += current_size;
841 }
842
843 DRM_ERROR("Sequence block detected but no valid configuration\n");
844
845 return NULL;
846 }
847
848 static int goto_next_sequence(const u8 *data, int index, int total)
849 {
850 u16 len;
851
852 /* Skip Sequence Byte. */
853 for (index = index + 1; index < total; index += len) {
854 u8 operation_byte = *(data + index);
855 index++;
856
857 switch (operation_byte) {
858 case MIPI_SEQ_ELEM_END:
859 return index;
860 case MIPI_SEQ_ELEM_SEND_PKT:
861 if (index + 4 > total)
862 return 0;
863
864 len = *((const u16 *)(data + index + 2)) + 4;
865 break;
866 case MIPI_SEQ_ELEM_DELAY:
867 len = 4;
868 break;
869 case MIPI_SEQ_ELEM_GPIO:
870 len = 2;
871 break;
872 case MIPI_SEQ_ELEM_I2C:
873 if (index + 7 > total)
874 return 0;
875 len = *(data + index + 6) + 7;
876 break;
877 default:
878 DRM_ERROR("Unknown operation byte\n");
879 return 0;
880 }
881 }
882
883 return 0;
884 }
885
886 static int goto_next_sequence_v3(const u8 *data, int index, int total)
887 {
888 int seq_end;
889 u16 len;
890 u32 size_of_sequence;
891
892 /*
893 * Could skip sequence based on Size of Sequence alone, but also do some
894 * checking on the structure.
895 */
896 if (total < 5) {
897 DRM_ERROR("Too small sequence size\n");
898 return 0;
899 }
900
901 /* Skip Sequence Byte. */
902 index++;
903
904 /*
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
907 * byte.
908 */
909 size_of_sequence = *((const uint32_t *)(data + index));
910 index += 4;
911
912 seq_end = index + size_of_sequence;
913 if (seq_end > total) {
914 DRM_ERROR("Invalid sequence size\n");
915 return 0;
916 }
917
918 for (; index < total; index += len) {
919 u8 operation_byte = *(data + index);
920 index++;
921
922 if (operation_byte == MIPI_SEQ_ELEM_END) {
923 if (index != seq_end) {
924 DRM_ERROR("Invalid element structure\n");
925 return 0;
926 }
927 return index;
928 }
929
930 len = *(data + index);
931 index++;
932
933 /*
934 * FIXME: Would be nice to check elements like for v1/v2 in
935 * goto_next_sequence() above.
936 */
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:
944 break;
945 default:
946 DRM_ERROR("Unknown operation byte %u\n",
947 operation_byte);
948 break;
949 }
950 }
951
952 return 0;
953 }
954
955 static void
956 parse_mipi_sequence(struct drm_i915_private *dev_priv,
957 const struct bdb_header *bdb)
958 {
959 int panel_type = dev_priv->vbt.panel_type;
960 const struct bdb_mipi_sequence *sequence;
961 const u8 *seq_data;
962 u32 seq_size;
963 u8 *data;
964 int index = 0;
965
966 /* Only our generic panel driver uses the sequence block. */
967 if (dev_priv->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
968 return;
969
970 sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
971 if (!sequence) {
972 DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
973 return;
974 }
975
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",
979 sequence->version);
980 return;
981 }
982
983 DRM_DEBUG_DRIVER("Found MIPI sequence block v%u\n", sequence->version);
984
985 seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size);
986 if (!seq_data)
987 return;
988
989 data = kmemdup(seq_data, seq_size, GFP_KERNEL);
990 if (!data)
991 return;
992
993 /* Parse the sequences, store pointers to each sequence. */
994 for (;;) {
995 u8 seq_id = *(data + index);
996 if (seq_id == MIPI_SEQ_END)
997 break;
998
999 if (seq_id >= MIPI_SEQ_MAX) {
1000 DRM_ERROR("Unknown sequence %u\n", seq_id);
1001 goto err;
1002 }
1003
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);
1007
1008 dev_priv->vbt.dsi.sequence[seq_id] = data + index;
1009
1010 if (sequence->version >= 3)
1011 index = goto_next_sequence_v3(data, index, seq_size);
1012 else
1013 index = goto_next_sequence(data, index, seq_size);
1014 if (!index) {
1015 DRM_ERROR("Invalid sequence %u\n", seq_id);
1016 goto err;
1017 }
1018 }
1019
1020 dev_priv->vbt.dsi.data = data;
1021 dev_priv->vbt.dsi.size = seq_size;
1022 dev_priv->vbt.dsi.seq_version = sequence->version;
1023
1024 DRM_DEBUG_DRIVER("MIPI related VBT parsing complete\n");
1025 return;
1026
1027 err:
1028 kfree(data);
1029 memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
1030 }
1031
1032 static u8 translate_iboost(u8 val)
1033 {
1034 static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
1035
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);
1038 return 0;
1039 }
1040 return mapping[val];
1041 }
1042
1043 static void sanitize_ddc_pin(struct drm_i915_private *dev_priv,
1044 enum port port)
1045 {
1046 const struct ddi_vbt_port_info *info =
1047 &dev_priv->vbt.ddi_port_info[port];
1048 enum port p;
1049
1050 if (!info->alternate_ddc_pin)
1051 return;
1052
1053 for_each_port_masked(p, (1 << port) - 1) {
1054 struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
1055
1056 if (info->alternate_ddc_pin != i->alternate_ddc_pin)
1057 continue;
1058
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));
1063
1064 /*
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.
1069 *
1070 * Due to parsing the ports in alphabetical order,
1071 * a higher port will always clobber a lower one.
1072 */
1073 i->supports_dvi = false;
1074 i->supports_hdmi = false;
1075 i->alternate_ddc_pin = 0;
1076 }
1077 }
1078
1079 static void sanitize_aux_ch(struct drm_i915_private *dev_priv,
1080 enum port port)
1081 {
1082 const struct ddi_vbt_port_info *info =
1083 &dev_priv->vbt.ddi_port_info[port];
1084 enum port p;
1085
1086 if (!info->alternate_aux_channel)
1087 return;
1088
1089 for_each_port_masked(p, (1 << port) - 1) {
1090 struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
1091
1092 if (info->alternate_aux_channel != i->alternate_aux_channel)
1093 continue;
1094
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));
1099
1100 /*
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.
1105 *
1106 * Due to parsing the ports in alphabetical order,
1107 * a higher port will always clobber a lower one.
1108 */
1109 i->supports_dp = false;
1110 i->alternate_aux_channel = 0;
1111 }
1112 }
1113
1114 static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
1115 const struct bdb_header *bdb)
1116 {
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;
1120 int i, j;
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.
1125 */
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},
1132 };
1133
1134 /*
1135 * Find the first child device to reference the port, report if more
1136 * than one found.
1137 */
1138 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1139 it = dev_priv->vbt.child_dev + i;
1140
1141 for (j = 0; j < 3; j++) {
1142 if (dvo_ports[port][j] == -1)
1143 break;
1144
1145 if (it->common.dvo_port == dvo_ports[port][j]) {
1146 if (child) {
1147 DRM_DEBUG_KMS("More than one child device for port %c in VBT, using the first.\n",
1148 port_name(port));
1149 } else {
1150 child = it;
1151 }
1152 }
1153 }
1154 }
1155 if (!child)
1156 return;
1157
1158 aux_channel = child->common.aux_channel;
1159
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);
1165
1166 if (port == PORT_A && is_dvi) {
1167 DRM_DEBUG_KMS("VBT claims port A supports DVI%s, ignoring\n",
1168 is_hdmi ? "/HDMI" : "");
1169 is_dvi = false;
1170 is_hdmi = false;
1171 }
1172
1173 info->supports_dvi = is_dvi;
1174 info->supports_hdmi = is_hdmi;
1175 info->supports_dp = is_dp;
1176 info->supports_edp = is_edp;
1177
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);
1180
1181 if (is_edp && is_dvi)
1182 DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
1183 port_name(port));
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",
1188 port_name(port));
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",
1193 port_name(port));
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));
1196
1197 if (is_dvi) {
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);
1202 } else {
1203 DRM_DEBUG_KMS("Port %c has invalid DDC pin %d, "
1204 "sticking to defaults\n",
1205 port_name(port), ddc_pin);
1206 }
1207 }
1208
1209 if (is_dp) {
1210 info->alternate_aux_channel = aux_channel;
1211
1212 sanitize_aux_ch(dev_priv, port);
1213 }
1214
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",
1219 port_name(port),
1220 hdmi_level_shift);
1221 info->hdmi_level_shift = hdmi_level_shift;
1222 }
1223
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);
1232 }
1233 }
1234
1235 static void parse_ddi_ports(struct drm_i915_private *dev_priv,
1236 const struct bdb_header *bdb)
1237 {
1238 enum port port;
1239
1240 if (!HAS_DDI(dev_priv) && !IS_CHERRYVIEW(dev_priv))
1241 return;
1242
1243 if (!dev_priv->vbt.child_dev_num)
1244 return;
1245
1246 if (bdb->version < 155)
1247 return;
1248
1249 for (port = PORT_A; port < I915_MAX_PORTS; port++)
1250 parse_ddi_port(dev_priv, port, bdb);
1251 }
1252
1253 static void
1254 parse_device_mapping(struct drm_i915_private *dev_priv,
1255 const struct bdb_header *bdb)
1256 {
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;
1261 u8 expected_size;
1262 u16 block_size;
1263
1264 p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
1265 if (!p_defs) {
1266 DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
1267 return;
1268 }
1269 if (bdb->version < 106) {
1270 expected_size = 22;
1271 } else if (bdb->version < 111) {
1272 expected_size = 27;
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) {
1277 expected_size = 37;
1278 } else if (bdb->version <= 197) {
1279 expected_size = 38;
1280 } else {
1281 expected_size = 38;
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);
1285 }
1286
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);
1291
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);
1296 return;
1297 }
1298
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;
1304 count = 0;
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 */
1310 continue;
1311 }
1312 count++;
1313 }
1314 if (!count) {
1315 DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
1316 return;
1317 }
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");
1321 return;
1322 }
1323
1324 dev_priv->vbt.child_dev_num = count;
1325 count = 0;
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 */
1330 continue;
1331 }
1332
1333 child_dev_ptr = dev_priv->vbt.child_dev + count;
1334 count++;
1335
1336 /*
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.
1340 */
1341 memcpy(child_dev_ptr, p_child,
1342 min_t(size_t, p_defs->child_dev_size, sizeof(*p_child)));
1343
1344 /*
1345 * copied full block, now init values when they are not
1346 * available in current version
1347 */
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;
1352 }
1353
1354 if (bdb->version < 192)
1355 child_dev_ptr->common.lspcon = 0;
1356 }
1357 return;
1358 }
1359
1360 /* Common defaults which may be overridden by VBT. */
1361 static void
1362 init_vbt_defaults(struct drm_i915_private *dev_priv)
1363 {
1364 enum port port;
1365
1366 dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
1367
1368 /* Default to having backlight */
1369 dev_priv->vbt.backlight.present = true;
1370
1371 /* LFP panel data */
1372 dev_priv->vbt.lvds_dither = 1;
1373 dev_priv->vbt.lvds_vbt = 0;
1374
1375 /* SDVO panel data */
1376 dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
1377
1378 /* general features */
1379 dev_priv->vbt.int_tv_support = 1;
1380 dev_priv->vbt.int_crt_support = 1;
1381
1382 /* Default to using SSC */
1383 dev_priv->vbt.lvds_use_ssc = 1;
1384 /*
1385 * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
1386 * clock for LVDS.
1387 */
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);
1391
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];
1395
1396 info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
1397 }
1398 }
1399
1400 /* Defaults to initialize only if there is no VBT. */
1401 static void
1402 init_vbt_missing_defaults(struct drm_i915_private *dev_priv)
1403 {
1404 enum port port;
1405
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];
1409
1410 info->supports_dvi = (port != PORT_A && port != PORT_E);
1411 info->supports_hdmi = info->supports_dvi;
1412 info->supports_dp = (port != PORT_E);
1413 }
1414 }
1415
1416 static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
1417 {
1418 const void *_vbt = vbt;
1419
1420 return _vbt + vbt->bdb_offset;
1421 }
1422
1423 /**
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
1427 *
1428 * Returns true on valid VBT.
1429 */
1430 bool intel_bios_is_valid_vbt(const void *buf, size_t size)
1431 {
1432 const struct vbt_header *vbt = buf;
1433 const struct bdb_header *bdb;
1434
1435 if (!vbt)
1436 return false;
1437
1438 if (sizeof(struct vbt_header) > size) {
1439 DRM_DEBUG_DRIVER("VBT header incomplete\n");
1440 return false;
1441 }
1442
1443 if (memcmp(vbt->signature, "$VBT", 4)) {
1444 DRM_DEBUG_DRIVER("VBT invalid signature\n");
1445 return false;
1446 }
1447
1448 if (range_overflows_t(size_t,
1449 vbt->bdb_offset,
1450 sizeof(struct bdb_header),
1451 size)) {
1452 DRM_DEBUG_DRIVER("BDB header incomplete\n");
1453 return false;
1454 }
1455
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");
1459 return false;
1460 }
1461
1462 return vbt;
1463 }
1464
1465 static const struct vbt_header *find_vbt(void __iomem *bios, size_t size)
1466 {
1467 size_t i;
1468
1469 /* Scour memory looking for the VBT signature. */
1470 for (i = 0; i + 4 < size; i++) {
1471 void *vbt;
1472
1473 if (ioread32(bios + i) != *((const u32 *) "$VBT"))
1474 continue;
1475
1476 /*
1477 * This is the one place where we explicitly discard the address
1478 * space (__iomem) of the BIOS/VBT.
1479 */
1480 vbt = (void __force *) bios + i;
1481 if (intel_bios_is_valid_vbt(vbt, size - i))
1482 return vbt;
1483
1484 break;
1485 }
1486
1487 return NULL;
1488 }
1489
1490 #define DRM_DMI_PRODUCT_VERSION 0x6
1491
1492 static void parse_product_info(struct drm_i915_private *dev_priv)
1493 {
1494 const char *product_ver = dmi_get_system_info(DRM_DMI_PRODUCT_VERSION);
1495 if (!product_ver)
1496 return;
1497
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;
1501 }
1502
1503 return;
1504 }
1505
1506 /**
1507 * intel_bios_init - find VBT and initialize settings from the BIOS
1508 * @dev_priv: i915 device instance
1509 *
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.
1513 */
1514 void intel_bios_init(struct drm_i915_private *dev_priv)
1515 {
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;
1520
1521 if (HAS_PCH_NOP(dev_priv)) {
1522 DRM_DEBUG_KMS("Skipping VBT init due to disabled display.\n");
1523 return;
1524 }
1525
1526 init_vbt_defaults(dev_priv);
1527
1528 /* If the OpRegion does not have VBT, look in PCI ROM. */
1529 if (!vbt) {
1530 size_t size;
1531
1532 bios = pci_map_rom(pdev, &size);
1533 if (!bios)
1534 goto out;
1535
1536 vbt = find_vbt(bios, size);
1537 if (!vbt)
1538 goto out;
1539
1540 DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
1541 }
1542
1543 bdb = get_bdb_header(vbt);
1544
1545 DRM_DEBUG_KMS("VBT signature \"%.*s\", BDB version %d\n",
1546 (int)sizeof(vbt->signature), vbt->signature, bdb->version);
1547
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);
1563
1564 out:
1565 if (!vbt) {
1566 DRM_INFO("Failed to find VBIOS tables (VBT)\n");
1567 init_vbt_missing_defaults(dev_priv);
1568 }
1569
1570 if (bios)
1571 pci_unmap_rom(pdev, bios);
1572 }
1573
1574 /**
1575 * intel_bios_is_tv_present - is integrated TV present in VBT
1576 * @dev_priv: i915 device instance
1577 *
1578 * Return true if TV is present. If no child devices were parsed from VBT,
1579 * assume TV is present.
1580 */
1581 bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv)
1582 {
1583 union child_device_config *p_child;
1584 int i;
1585
1586 if (!dev_priv->vbt.int_tv_support)
1587 return false;
1588
1589 if (!dev_priv->vbt.child_dev_num)
1590 return true;
1591
1592 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1593 p_child = dev_priv->vbt.child_dev + i;
1594 /*
1595 * If the device type is not TV, continue.
1596 */
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:
1601 break;
1602 default:
1603 continue;
1604 }
1605 /* Only when the addin_offset is non-zero, it is regarded
1606 * as present.
1607 */
1608 if (p_child->old.addin_offset)
1609 return true;
1610 }
1611
1612 return false;
1613 }
1614
1615 /**
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
1619 *
1620 * Return true if LVDS is present. If no child devices were parsed from VBT,
1621 * assume LVDS is present.
1622 */
1623 bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin)
1624 {
1625 int i;
1626
1627 if (!dev_priv->vbt.child_dev_num)
1628 return true;
1629
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;
1633
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.
1637 */
1638 if (child->device_type != DEVICE_TYPE_INT_LFP &&
1639 child->device_type != DEVICE_TYPE_LFP)
1640 continue;
1641
1642 if (intel_gmbus_is_valid_pin(dev_priv, child->i2c_pin))
1643 *i2c_pin = child->i2c_pin;
1644
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.
1649 */
1650 if (child->addin_offset)
1651 return true;
1652
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.
1657 */
1658 if (dev_priv->opregion.vbt)
1659 return true;
1660 }
1661
1662 return false;
1663 }
1664
1665 /**
1666 * intel_bios_is_port_present - is the specified digital port present
1667 * @dev_priv: i915 device instance
1668 * @port: port to check
1669 *
1670 * Return true if the device in %port is present.
1671 */
1672 bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port)
1673 {
1674 static const struct {
1675 u16 dp, hdmi;
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, },
1681 };
1682 int i;
1683
1684 /* FIXME maybe deal with port A as well? */
1685 if (WARN_ON(port == PORT_A) || port >= ARRAY_SIZE(port_mapping))
1686 return false;
1687
1688 if (!dev_priv->vbt.child_dev_num)
1689 return false;
1690
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)))
1698 return true;
1699 }
1700
1701 return false;
1702 }
1703
1704 /**
1705 * intel_bios_is_port_edp - is the device in given port eDP
1706 * @dev_priv: i915 device instance
1707 * @port: port to check
1708 *
1709 * Return true if the device in %port is eDP.
1710 */
1711 bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
1712 {
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,
1719 };
1720 int i;
1721
1722 if (HAS_DDI(dev_priv))
1723 return dev_priv->vbt.ddi_port_info[port].supports_edp;
1724
1725 if (!dev_priv->vbt.child_dev_num)
1726 return false;
1727
1728 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1729 p_child = dev_priv->vbt.child_dev + i;
1730
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))
1734 return true;
1735 }
1736
1737 return false;
1738 }
1739
1740 static bool child_dev_is_dp_dual_mode(const union child_device_config *p_child,
1741 enum port port)
1742 {
1743 static const struct {
1744 u16 dp, hdmi;
1745 } port_mapping[] = {
1746 /*
1747 * Buggy VBTs may declare DP ports as having
1748 * HDMI type dvo_port :( So let's check both.
1749 */
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, },
1754 };
1755
1756 if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
1757 return false;
1758
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))
1761 return false;
1762
1763 if (p_child->common.dvo_port == port_mapping[port].dp)
1764 return true;
1765
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)
1769 return true;
1770
1771 return false;
1772 }
1773
1774 bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv,
1775 enum port port)
1776 {
1777 int i;
1778
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];
1782
1783 if (child_dev_is_dp_dual_mode(p_child, port))
1784 return true;
1785 }
1786
1787 return false;
1788 }
1789
1790 /**
1791 * intel_bios_is_dsi_present - is DSI present in VBT
1792 * @dev_priv: i915 device instance
1793 * @port: port for DSI if present
1794 *
1795 * Return true if DSI is present, and return the port in %port.
1796 */
1797 bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv,
1798 enum port *port)
1799 {
1800 union child_device_config *p_child;
1801 u8 dvo_port;
1802 int i;
1803
1804 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1805 p_child = dev_priv->vbt.child_dev + i;
1806
1807 if (!(p_child->common.device_type & DEVICE_TYPE_MIPI_OUTPUT))
1808 continue;
1809
1810 dvo_port = p_child->common.dvo_port;
1811
1812 switch (dvo_port) {
1813 case DVO_PORT_MIPIA:
1814 case DVO_PORT_MIPIC:
1815 if (port)
1816 *port = dvo_port - DVO_PORT_MIPIA;
1817 return true;
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));
1822 break;
1823 }
1824 }
1825
1826 return false;
1827 }
1828
1829 /**
1830 * intel_bios_is_port_hpd_inverted - is HPD inverted for %port
1831 * @dev_priv: i915 device instance
1832 * @port: port to check
1833 *
1834 * Return true if HPD should be inverted for %port.
1835 */
1836 bool
1837 intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
1838 enum port port)
1839 {
1840 int i;
1841
1842 if (WARN_ON_ONCE(!IS_GEN9_LP(dev_priv)))
1843 return false;
1844
1845 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1846 if (!dev_priv->vbt.child_dev[i].common.hpd_invert)
1847 continue;
1848
1849 switch (dev_priv->vbt.child_dev[i].common.dvo_port) {
1850 case DVO_PORT_DPA:
1851 case DVO_PORT_HDMIA:
1852 if (port == PORT_A)
1853 return true;
1854 break;
1855 case DVO_PORT_DPB:
1856 case DVO_PORT_HDMIB:
1857 if (port == PORT_B)
1858 return true;
1859 break;
1860 case DVO_PORT_DPC:
1861 case DVO_PORT_HDMIC:
1862 if (port == PORT_C)
1863 return true;
1864 break;
1865 default:
1866 break;
1867 }
1868 }
1869
1870 return false;
1871 }
1872
1873 /**
1874 * intel_bios_is_lspcon_present - if LSPCON is attached on %port
1875 * @dev_priv: i915 device instance
1876 * @port: port to check
1877 *
1878 * Return true if LSPCON is present on this port
1879 */
1880 bool
1881 intel_bios_is_lspcon_present(struct drm_i915_private *dev_priv,
1882 enum port port)
1883 {
1884 int i;
1885
1886 if (!HAS_LSPCON(dev_priv))
1887 return false;
1888
1889 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1890 if (!dev_priv->vbt.child_dev[i].common.lspcon)
1891 continue;
1892
1893 switch (dev_priv->vbt.child_dev[i].common.dvo_port) {
1894 case DVO_PORT_DPA:
1895 case DVO_PORT_HDMIA:
1896 if (port == PORT_A)
1897 return true;
1898 break;
1899 case DVO_PORT_DPB:
1900 case DVO_PORT_HDMIB:
1901 if (port == PORT_B)
1902 return true;
1903 break;
1904 case DVO_PORT_DPC:
1905 case DVO_PORT_HDMIC:
1906 if (port == PORT_C)
1907 return true;
1908 break;
1909 case DVO_PORT_DPD:
1910 case DVO_PORT_HDMID:
1911 if (port == PORT_D)
1912 return true;
1913 break;
1914 default:
1915 break;
1916 }
1917 }
1918
1919 return false;
1920 }