Line data Source code
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 : #ifdef __linux__
28 : #include <linux/dmi.h>
29 : #include <drm/drm_dp_helper.h>
30 : #include <drm/drmP.h>
31 : #include <drm/i915_drm.h>
32 : #else
33 : #include <dev/pci/drm/drm_dp_helper.h>
34 : #include <dev/pci/drm/drmP.h>
35 : #include <dev/pci/drm/i915_drm.h>
36 : #endif
37 : #include "i915_drv.h"
38 : #include "intel_bios.h"
39 :
40 : #define SLAVE_ADDR1 0x70
41 : #define SLAVE_ADDR2 0x72
42 :
43 : static int panel_type;
44 :
45 : static const void *
46 0 : find_section(const void *_bdb, int section_id)
47 : {
48 0 : const struct bdb_header *bdb = _bdb;
49 : const u8 *base = _bdb;
50 : int index = 0;
51 : u32 total, current_size;
52 : u8 current_id;
53 :
54 : /* skip to first section */
55 0 : index += bdb->header_size;
56 0 : total = bdb->bdb_size;
57 :
58 : /* walk the sections looking for section_id */
59 0 : while (index + 3 < total) {
60 0 : current_id = *(base + index);
61 0 : index++;
62 :
63 0 : current_size = *((const u16 *)(base + index));
64 0 : index += 2;
65 :
66 : /* The MIPI Sequence Block v3+ has a separate size field. */
67 0 : if (current_id == BDB_MIPI_SEQUENCE && *(base + index) >= 3)
68 0 : current_size = *((const u32 *)(base + index + 1));
69 :
70 0 : if (index + current_size > total)
71 0 : return NULL;
72 :
73 0 : if (current_id == section_id)
74 0 : return base + index;
75 :
76 : index += current_size;
77 : }
78 :
79 0 : return NULL;
80 0 : }
81 :
82 : static u16
83 0 : get_blocksize(const void *p)
84 : {
85 : u16 *block_ptr, block_size;
86 :
87 0 : block_ptr = (u16 *)((char *)p - 2);
88 0 : block_size = *block_ptr;
89 0 : return block_size;
90 : }
91 :
92 : static void
93 0 : fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
94 : const struct lvds_dvo_timing *dvo_timing)
95 : {
96 0 : panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
97 0 : dvo_timing->hactive_lo;
98 0 : panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
99 0 : ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
100 0 : panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
101 0 : dvo_timing->hsync_pulse_width;
102 0 : panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
103 0 : ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
104 :
105 0 : panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
106 0 : dvo_timing->vactive_lo;
107 0 : panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
108 0 : dvo_timing->vsync_off;
109 0 : panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
110 0 : dvo_timing->vsync_pulse_width;
111 0 : panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
112 0 : ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
113 0 : panel_fixed_mode->clock = dvo_timing->clock * 10;
114 0 : panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
115 :
116 0 : if (dvo_timing->hsync_positive)
117 0 : panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
118 : else
119 0 : panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
120 :
121 0 : if (dvo_timing->vsync_positive)
122 0 : panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
123 : else
124 0 : panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
125 :
126 : /* Some VBTs have bogus h/vtotal values */
127 0 : if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
128 0 : panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
129 0 : if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
130 0 : panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
131 :
132 0 : drm_mode_set_name(panel_fixed_mode);
133 0 : }
134 :
135 : static const struct lvds_dvo_timing *
136 0 : get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
137 : const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
138 : int index)
139 : {
140 : /*
141 : * the size of fp_timing varies on the different platform.
142 : * So calculate the DVO timing relative offset in LVDS data
143 : * entry to get the DVO timing entry
144 : */
145 :
146 : int lfp_data_size =
147 0 : lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
148 0 : lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
149 : int dvo_timing_offset =
150 0 : lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
151 0 : lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
152 0 : char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
153 :
154 0 : return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
155 : }
156 :
157 : /* get lvds_fp_timing entry
158 : * this function may return NULL if the corresponding entry is invalid
159 : */
160 : static const struct lvds_fp_timing *
161 0 : get_lvds_fp_timing(const struct bdb_header *bdb,
162 : const struct bdb_lvds_lfp_data *data,
163 : const struct bdb_lvds_lfp_data_ptrs *ptrs,
164 : int index)
165 : {
166 0 : size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
167 0 : u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
168 : size_t ofs;
169 :
170 0 : if (index >= ARRAY_SIZE(ptrs->ptr))
171 0 : return NULL;
172 0 : ofs = ptrs->ptr[index].fp_timing_offset;
173 0 : if (ofs < data_ofs ||
174 0 : ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
175 0 : return NULL;
176 0 : return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
177 0 : }
178 :
179 : /* Try to find integrated panel data */
180 : static void
181 0 : parse_lfp_panel_data(struct drm_i915_private *dev_priv,
182 : const struct bdb_header *bdb)
183 : {
184 : const struct bdb_lvds_options *lvds_options;
185 : const struct bdb_lvds_lfp_data *lvds_lfp_data;
186 : const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
187 : const struct lvds_dvo_timing *panel_dvo_timing;
188 : const struct lvds_fp_timing *fp_timing;
189 : struct drm_display_mode *panel_fixed_mode;
190 : int drrs_mode;
191 :
192 0 : lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
193 0 : if (!lvds_options)
194 0 : return;
195 :
196 0 : dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
197 0 : if (lvds_options->panel_type == 0xff)
198 0 : return;
199 :
200 0 : panel_type = lvds_options->panel_type;
201 :
202 0 : drrs_mode = (lvds_options->dps_panel_type_bits
203 0 : >> (panel_type * 2)) & MODE_MASK;
204 : /*
205 : * VBT has static DRRS = 0 and seamless DRRS = 2.
206 : * The below piece of code is required to adjust vbt.drrs_type
207 : * to match the enum drrs_support_type.
208 : */
209 0 : switch (drrs_mode) {
210 : case 0:
211 0 : dev_priv->vbt.drrs_type = STATIC_DRRS_SUPPORT;
212 : DRM_DEBUG_KMS("DRRS supported mode is static\n");
213 0 : break;
214 : case 2:
215 0 : dev_priv->vbt.drrs_type = SEAMLESS_DRRS_SUPPORT;
216 : DRM_DEBUG_KMS("DRRS supported mode is seamless\n");
217 0 : break;
218 : default:
219 0 : dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
220 : DRM_DEBUG_KMS("DRRS not supported (VBT input)\n");
221 0 : break;
222 : }
223 :
224 0 : lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
225 0 : if (!lvds_lfp_data)
226 0 : return;
227 :
228 0 : lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
229 0 : if (!lvds_lfp_data_ptrs)
230 0 : return;
231 :
232 0 : dev_priv->vbt.lvds_vbt = 1;
233 :
234 0 : panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
235 : lvds_lfp_data_ptrs,
236 0 : lvds_options->panel_type);
237 :
238 0 : panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
239 0 : if (!panel_fixed_mode)
240 0 : return;
241 :
242 0 : fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
243 :
244 0 : dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
245 :
246 : DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
247 0 : drm_mode_debug_printmodeline(panel_fixed_mode);
248 :
249 0 : fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
250 : lvds_lfp_data_ptrs,
251 0 : lvds_options->panel_type);
252 0 : if (fp_timing) {
253 : /* check the resolution, just to be sure */
254 0 : if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
255 0 : fp_timing->y_res == panel_fixed_mode->vdisplay) {
256 0 : dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
257 : DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
258 : dev_priv->vbt.bios_lvds_val);
259 0 : }
260 : }
261 0 : }
262 :
263 : static void
264 0 : parse_lfp_backlight(struct drm_i915_private *dev_priv,
265 : const struct bdb_header *bdb)
266 : {
267 : const struct bdb_lfp_backlight_data *backlight_data;
268 : const struct bdb_lfp_backlight_data_entry *entry;
269 :
270 0 : backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
271 0 : if (!backlight_data)
272 0 : return;
273 :
274 0 : if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
275 : DRM_DEBUG_KMS("Unsupported backlight data entry size %u\n",
276 : backlight_data->entry_size);
277 0 : return;
278 : }
279 :
280 0 : entry = &backlight_data->data[panel_type];
281 :
282 0 : dev_priv->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
283 0 : if (!dev_priv->vbt.backlight.present) {
284 : DRM_DEBUG_KMS("PWM backlight not present in VBT (type %u)\n",
285 : entry->type);
286 0 : return;
287 : }
288 :
289 0 : dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
290 0 : dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
291 0 : dev_priv->vbt.backlight.min_brightness = entry->min_brightness;
292 : DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
293 : "active %s, min brightness %u, level %u\n",
294 : dev_priv->vbt.backlight.pwm_freq_hz,
295 : dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
296 : dev_priv->vbt.backlight.min_brightness,
297 : backlight_data->level[panel_type]);
298 0 : }
299 :
300 : /* Try to find sdvo panel data */
301 : static void
302 0 : parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
303 : const struct bdb_header *bdb)
304 : {
305 : const struct lvds_dvo_timing *dvo_timing;
306 : struct drm_display_mode *panel_fixed_mode;
307 : int index;
308 :
309 0 : index = i915.vbt_sdvo_panel_type;
310 0 : if (index == -2) {
311 : DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
312 0 : return;
313 : }
314 :
315 0 : if (index == -1) {
316 : const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
317 :
318 0 : sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
319 0 : if (!sdvo_lvds_options)
320 0 : return;
321 :
322 0 : index = sdvo_lvds_options->panel_type;
323 0 : }
324 :
325 0 : dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
326 0 : if (!dvo_timing)
327 0 : return;
328 :
329 0 : panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
330 0 : if (!panel_fixed_mode)
331 0 : return;
332 :
333 0 : fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
334 :
335 0 : dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
336 :
337 : DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
338 0 : drm_mode_debug_printmodeline(panel_fixed_mode);
339 0 : }
340 :
341 0 : static int intel_bios_ssc_frequency(struct drm_device *dev,
342 : bool alternate)
343 : {
344 0 : switch (INTEL_INFO(dev)->gen) {
345 : case 2:
346 0 : return alternate ? 66667 : 48000;
347 : case 3:
348 : case 4:
349 0 : return alternate ? 100000 : 96000;
350 : default:
351 0 : return alternate ? 100000 : 120000;
352 : }
353 0 : }
354 :
355 : static void
356 0 : parse_general_features(struct drm_i915_private *dev_priv,
357 : const struct bdb_header *bdb)
358 : {
359 0 : struct drm_device *dev = dev_priv->dev;
360 : const struct bdb_general_features *general;
361 :
362 0 : general = find_section(bdb, BDB_GENERAL_FEATURES);
363 0 : if (general) {
364 0 : dev_priv->vbt.int_tv_support = general->int_tv_support;
365 0 : dev_priv->vbt.int_crt_support = general->int_crt_support;
366 0 : dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
367 0 : dev_priv->vbt.lvds_ssc_freq =
368 0 : intel_bios_ssc_frequency(dev, general->ssc_freq);
369 0 : dev_priv->vbt.display_clock_mode = general->display_clock_mode;
370 0 : dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
371 : 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",
372 : dev_priv->vbt.int_tv_support,
373 : dev_priv->vbt.int_crt_support,
374 : dev_priv->vbt.lvds_use_ssc,
375 : dev_priv->vbt.lvds_ssc_freq,
376 : dev_priv->vbt.display_clock_mode,
377 : dev_priv->vbt.fdi_rx_polarity_inverted);
378 0 : }
379 0 : }
380 :
381 : static void
382 0 : parse_general_definitions(struct drm_i915_private *dev_priv,
383 : const struct bdb_header *bdb)
384 : {
385 : const struct bdb_general_definitions *general;
386 :
387 0 : general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
388 0 : if (general) {
389 0 : u16 block_size = get_blocksize(general);
390 0 : if (block_size >= sizeof(*general)) {
391 0 : int bus_pin = general->crt_ddc_gmbus_pin;
392 : DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
393 0 : if (intel_gmbus_is_valid_pin(dev_priv, bus_pin))
394 0 : dev_priv->vbt.crt_ddc_pin = bus_pin;
395 0 : } else {
396 : DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
397 : block_size);
398 : }
399 0 : }
400 0 : }
401 :
402 : static const union child_device_config *
403 0 : child_device_ptr(const struct bdb_general_definitions *p_defs, int i)
404 : {
405 0 : return (const void *) &p_defs->devices[i * p_defs->child_dev_size];
406 : }
407 :
408 : static void
409 0 : parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
410 : const struct bdb_header *bdb)
411 : {
412 : struct sdvo_device_mapping *p_mapping;
413 : const struct bdb_general_definitions *p_defs;
414 : const struct old_child_dev_config *child; /* legacy */
415 : int i, child_device_num, count;
416 : u16 block_size;
417 :
418 0 : p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
419 0 : if (!p_defs) {
420 : DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
421 0 : return;
422 : }
423 :
424 : /*
425 : * Only parse SDVO mappings when the general definitions block child
426 : * device size matches that of the *legacy* child device config
427 : * struct. Thus, SDVO mapping will be skipped for newer VBT.
428 : */
429 0 : if (p_defs->child_dev_size != sizeof(*child)) {
430 : DRM_DEBUG_KMS("Unsupported child device size for SDVO mapping.\n");
431 0 : return;
432 : }
433 : /* get the block size of general definitions */
434 0 : block_size = get_blocksize(p_defs);
435 : /* get the number of child device */
436 0 : child_device_num = (block_size - sizeof(*p_defs)) /
437 0 : p_defs->child_dev_size;
438 : count = 0;
439 0 : for (i = 0; i < child_device_num; i++) {
440 0 : child = &child_device_ptr(p_defs, i)->old;
441 0 : if (!child->device_type) {
442 : /* skip the device block if device type is invalid */
443 : continue;
444 : }
445 0 : if (child->slave_addr != SLAVE_ADDR1 &&
446 0 : child->slave_addr != SLAVE_ADDR2) {
447 : /*
448 : * If the slave address is neither 0x70 nor 0x72,
449 : * it is not a SDVO device. Skip it.
450 : */
451 : continue;
452 : }
453 0 : if (child->dvo_port != DEVICE_PORT_DVOB &&
454 0 : child->dvo_port != DEVICE_PORT_DVOC) {
455 : /* skip the incorrect SDVO port */
456 : DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
457 : continue;
458 : }
459 : DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
460 : " %s port\n",
461 : child->slave_addr,
462 : (child->dvo_port == DEVICE_PORT_DVOB) ?
463 : "SDVOB" : "SDVOC");
464 0 : p_mapping = &(dev_priv->sdvo_mappings[child->dvo_port - 1]);
465 0 : if (!p_mapping->initialized) {
466 0 : p_mapping->dvo_port = child->dvo_port;
467 0 : p_mapping->slave_addr = child->slave_addr;
468 0 : p_mapping->dvo_wiring = child->dvo_wiring;
469 0 : p_mapping->ddc_pin = child->ddc_pin;
470 0 : p_mapping->i2c_pin = child->i2c_pin;
471 0 : p_mapping->initialized = 1;
472 : DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
473 : p_mapping->dvo_port,
474 : p_mapping->slave_addr,
475 : p_mapping->dvo_wiring,
476 : p_mapping->ddc_pin,
477 : p_mapping->i2c_pin);
478 0 : } else {
479 : DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
480 : "two SDVO device.\n");
481 : }
482 0 : if (child->slave2_addr) {
483 : /* Maybe this is a SDVO device with multiple inputs */
484 : /* And the mapping info is not added */
485 : DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
486 : " is a SDVO device with multiple inputs.\n");
487 : }
488 0 : count++;
489 0 : }
490 :
491 : if (!count) {
492 : /* No SDVO device info is found */
493 : DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
494 : }
495 0 : return;
496 0 : }
497 :
498 : static void
499 0 : parse_driver_features(struct drm_i915_private *dev_priv,
500 : const struct bdb_header *bdb)
501 : {
502 : const struct bdb_driver_features *driver;
503 :
504 0 : driver = find_section(bdb, BDB_DRIVER_FEATURES);
505 0 : if (!driver)
506 0 : return;
507 :
508 0 : if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
509 0 : dev_priv->vbt.edp_support = 1;
510 :
511 0 : if (driver->dual_frequency)
512 0 : dev_priv->render_reclock_avail = true;
513 :
514 : DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
515 : /*
516 : * If DRRS is not supported, drrs_type has to be set to 0.
517 : * This is because, VBT is configured in such a way that
518 : * static DRRS is 0 and DRRS not supported is represented by
519 : * driver->drrs_enabled=false
520 : */
521 0 : if (!driver->drrs_enabled)
522 0 : dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
523 0 : }
524 :
525 : static void
526 0 : parse_edp(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
527 : {
528 : const struct bdb_edp *edp;
529 : const struct edp_power_seq *edp_pps;
530 : const struct edp_link_params *edp_link_params;
531 :
532 0 : edp = find_section(bdb, BDB_EDP);
533 0 : if (!edp) {
534 0 : if (dev_priv->vbt.edp_support)
535 : DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
536 0 : return;
537 : }
538 :
539 0 : switch ((edp->color_depth >> (panel_type * 2)) & 3) {
540 : case EDP_18BPP:
541 0 : dev_priv->vbt.edp_bpp = 18;
542 0 : break;
543 : case EDP_24BPP:
544 0 : dev_priv->vbt.edp_bpp = 24;
545 0 : break;
546 : case EDP_30BPP:
547 0 : dev_priv->vbt.edp_bpp = 30;
548 0 : break;
549 : }
550 :
551 : /* Get the eDP sequencing and link info */
552 0 : edp_pps = &edp->power_seqs[panel_type];
553 0 : edp_link_params = &edp->link_params[panel_type];
554 :
555 0 : dev_priv->vbt.edp_pps = *edp_pps;
556 :
557 0 : switch (edp_link_params->rate) {
558 : case EDP_RATE_1_62:
559 0 : dev_priv->vbt.edp_rate = DP_LINK_BW_1_62;
560 0 : break;
561 : case EDP_RATE_2_7:
562 0 : dev_priv->vbt.edp_rate = DP_LINK_BW_2_7;
563 0 : break;
564 : default:
565 : DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
566 : edp_link_params->rate);
567 : break;
568 : }
569 :
570 0 : switch (edp_link_params->lanes) {
571 : case EDP_LANE_1:
572 0 : dev_priv->vbt.edp_lanes = 1;
573 0 : break;
574 : case EDP_LANE_2:
575 0 : dev_priv->vbt.edp_lanes = 2;
576 0 : break;
577 : case EDP_LANE_4:
578 0 : dev_priv->vbt.edp_lanes = 4;
579 0 : break;
580 : default:
581 : DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
582 : edp_link_params->lanes);
583 : break;
584 : }
585 :
586 0 : switch (edp_link_params->preemphasis) {
587 : case EDP_PREEMPHASIS_NONE:
588 0 : dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
589 0 : break;
590 : case EDP_PREEMPHASIS_3_5dB:
591 0 : dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
592 0 : break;
593 : case EDP_PREEMPHASIS_6dB:
594 0 : dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
595 0 : break;
596 : case EDP_PREEMPHASIS_9_5dB:
597 0 : dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
598 0 : break;
599 : default:
600 : DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
601 : edp_link_params->preemphasis);
602 : break;
603 : }
604 :
605 0 : switch (edp_link_params->vswing) {
606 : case EDP_VSWING_0_4V:
607 0 : dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
608 0 : break;
609 : case EDP_VSWING_0_6V:
610 0 : dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
611 0 : break;
612 : case EDP_VSWING_0_8V:
613 0 : dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
614 0 : break;
615 : case EDP_VSWING_1_2V:
616 0 : dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
617 0 : break;
618 : default:
619 : DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
620 : edp_link_params->vswing);
621 : break;
622 : }
623 :
624 0 : if (bdb->version >= 173) {
625 : uint8_t vswing;
626 :
627 : /* Don't read from VBT if module parameter has valid value*/
628 0 : if (i915.edp_vswing) {
629 0 : dev_priv->edp_low_vswing = i915.edp_vswing == 1;
630 0 : } else {
631 0 : vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
632 0 : dev_priv->edp_low_vswing = vswing == 0;
633 : }
634 0 : }
635 0 : }
636 :
637 : static void
638 0 : parse_psr(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
639 : {
640 : const struct bdb_psr *psr;
641 : const struct psr_table *psr_table;
642 :
643 0 : psr = find_section(bdb, BDB_PSR);
644 0 : if (!psr) {
645 : DRM_DEBUG_KMS("No PSR BDB found.\n");
646 0 : return;
647 : }
648 :
649 0 : psr_table = &psr->psr_table[panel_type];
650 :
651 0 : dev_priv->vbt.psr.full_link = psr_table->full_link;
652 0 : dev_priv->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
653 :
654 : /* Allowed VBT values goes from 0 to 15 */
655 0 : dev_priv->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
656 0 : psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
657 :
658 0 : switch (psr_table->lines_to_wait) {
659 : case 0:
660 0 : dev_priv->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
661 0 : break;
662 : case 1:
663 0 : dev_priv->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
664 0 : break;
665 : case 2:
666 0 : dev_priv->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
667 0 : break;
668 : case 3:
669 0 : dev_priv->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
670 0 : break;
671 : default:
672 : DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
673 : psr_table->lines_to_wait);
674 : break;
675 : }
676 :
677 0 : dev_priv->vbt.psr.tp1_wakeup_time = psr_table->tp1_wakeup_time;
678 0 : dev_priv->vbt.psr.tp2_tp3_wakeup_time = psr_table->tp2_tp3_wakeup_time;
679 0 : }
680 :
681 0 : static u8 *goto_next_sequence(u8 *data, int *size)
682 : {
683 : u16 len;
684 0 : int tmp = *size;
685 :
686 0 : if (--tmp < 0)
687 0 : return NULL;
688 :
689 : /* goto first element */
690 0 : data++;
691 0 : while (1) {
692 0 : switch (*data) {
693 : case MIPI_SEQ_ELEM_SEND_PKT:
694 : /*
695 : * skip by this element payload size
696 : * skip elem id, command flag and data type
697 : */
698 0 : tmp -= 5;
699 0 : if (tmp < 0)
700 0 : return NULL;
701 :
702 0 : data += 3;
703 0 : len = *((u16 *)data);
704 :
705 0 : tmp -= len;
706 0 : if (tmp < 0)
707 0 : return NULL;
708 :
709 : /* skip by len */
710 0 : data = data + 2 + len;
711 0 : break;
712 : case MIPI_SEQ_ELEM_DELAY:
713 : /* skip by elem id, and delay is 4 bytes */
714 0 : tmp -= 5;
715 0 : if (tmp < 0)
716 0 : return NULL;
717 :
718 0 : data += 5;
719 0 : break;
720 : case MIPI_SEQ_ELEM_GPIO:
721 0 : tmp -= 3;
722 0 : if (tmp < 0)
723 0 : return NULL;
724 :
725 0 : data += 3;
726 0 : break;
727 : default:
728 0 : DRM_ERROR("Unknown element\n");
729 0 : return NULL;
730 : }
731 :
732 : /* end of sequence ? */
733 0 : if (*data == 0)
734 : break;
735 : }
736 :
737 : /* goto next sequence or end of block byte */
738 0 : if (--tmp < 0)
739 0 : return NULL;
740 :
741 0 : data++;
742 :
743 : /* update amount of data left for the sequence block to be parsed */
744 0 : *size = tmp;
745 0 : return data;
746 0 : }
747 :
748 : static void
749 0 : parse_mipi(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
750 : {
751 : const struct bdb_mipi_config *start;
752 : const struct bdb_mipi_sequence *sequence;
753 : const struct mipi_config *config;
754 : const struct mipi_pps_data *pps;
755 : u8 *data;
756 : const u8 *seq_data;
757 0 : int i, panel_id, seq_size;
758 : u16 block_size;
759 :
760 : /* parse MIPI blocks only if LFP type is MIPI */
761 0 : if (!dev_priv->vbt.has_mipi)
762 0 : return;
763 :
764 : /* Initialize this to undefined indicating no generic MIPI support */
765 0 : dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
766 :
767 : /* Block #40 is already parsed and panel_fixed_mode is
768 : * stored in dev_priv->lfp_lvds_vbt_mode
769 : * resuse this when needed
770 : */
771 :
772 : /* Parse #52 for panel index used from panel_type already
773 : * parsed
774 : */
775 0 : start = find_section(bdb, BDB_MIPI_CONFIG);
776 0 : if (!start) {
777 : DRM_DEBUG_KMS("No MIPI config BDB found");
778 0 : return;
779 : }
780 :
781 : DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
782 : panel_type);
783 :
784 : /*
785 : * get hold of the correct configuration block and pps data as per
786 : * the panel_type as index
787 : */
788 0 : config = &start->config[panel_type];
789 0 : pps = &start->pps[panel_type];
790 :
791 : /* store as of now full data. Trim when we realise all is not needed */
792 0 : dev_priv->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
793 0 : if (!dev_priv->vbt.dsi.config)
794 0 : return;
795 :
796 0 : dev_priv->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
797 0 : if (!dev_priv->vbt.dsi.pps) {
798 0 : kfree(dev_priv->vbt.dsi.config);
799 0 : return;
800 : }
801 :
802 : /* We have mandatory mipi config blocks. Initialize as generic panel */
803 0 : dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
804 :
805 : /* Check if we have sequence block as well */
806 0 : sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
807 0 : if (!sequence) {
808 : DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
809 0 : return;
810 : }
811 :
812 : /* Fail gracefully for forward incompatible sequence block. */
813 0 : if (sequence->version >= 3) {
814 0 : DRM_ERROR("Unable to parse MIPI Sequence Block v3+\n");
815 0 : return;
816 : }
817 :
818 : DRM_DEBUG_DRIVER("Found MIPI sequence block\n");
819 :
820 0 : block_size = get_blocksize(sequence);
821 :
822 : /*
823 : * parse the sequence block for individual sequences
824 : */
825 0 : dev_priv->vbt.dsi.seq_version = sequence->version;
826 :
827 0 : seq_data = &sequence->data[0];
828 :
829 : /*
830 : * sequence block is variable length and hence we need to parse and
831 : * get the sequence data for specific panel id
832 : */
833 0 : for (i = 0; i < MAX_MIPI_CONFIGURATIONS; i++) {
834 0 : panel_id = *seq_data;
835 0 : seq_size = *((u16 *) (seq_data + 1));
836 0 : if (panel_id == panel_type)
837 : break;
838 :
839 : /* skip the sequence including seq header of 3 bytes */
840 0 : seq_data = seq_data + 3 + seq_size;
841 0 : if ((seq_data - &sequence->data[0]) > block_size) {
842 0 : DRM_ERROR("Sequence start is beyond sequence block size, corrupted sequence block\n");
843 0 : return;
844 : }
845 : }
846 :
847 0 : if (i == MAX_MIPI_CONFIGURATIONS) {
848 0 : DRM_ERROR("Sequence block detected but no valid configuration\n");
849 0 : return;
850 : }
851 :
852 : /* check if found sequence is completely within the sequence block
853 : * just being paranoid */
854 0 : if (seq_size > block_size) {
855 0 : DRM_ERROR("Corrupted sequence/size, bailing out\n");
856 0 : return;
857 : }
858 :
859 : /* skip the panel id(1 byte) and seq size(2 bytes) */
860 0 : dev_priv->vbt.dsi.data = kmemdup(seq_data + 3, seq_size, GFP_KERNEL);
861 0 : if (!dev_priv->vbt.dsi.data)
862 0 : return;
863 :
864 : /*
865 : * loop into the sequence data and split into multiple sequneces
866 : * There are only 5 types of sequences as of now
867 : */
868 : data = dev_priv->vbt.dsi.data;
869 0 : dev_priv->vbt.dsi.size = seq_size;
870 :
871 : /* two consecutive 0x00 indicate end of all sequences */
872 0 : while (1) {
873 0 : int seq_id = *data;
874 0 : if (MIPI_SEQ_MAX > seq_id && seq_id > MIPI_SEQ_UNDEFINED) {
875 0 : dev_priv->vbt.dsi.sequence[seq_id] = data;
876 : DRM_DEBUG_DRIVER("Found mipi sequence - %d\n", seq_id);
877 : } else {
878 0 : DRM_ERROR("undefined sequence\n");
879 0 : goto err;
880 : }
881 :
882 : /* partial parsing to skip elements */
883 0 : data = goto_next_sequence(data, &seq_size);
884 :
885 0 : if (data == NULL) {
886 0 : DRM_ERROR("Sequence elements going beyond block itself. Sequence block parsing failed\n");
887 0 : goto err;
888 : }
889 :
890 0 : if (*data == 0)
891 0 : break; /* end of sequence reached */
892 0 : }
893 :
894 : DRM_DEBUG_DRIVER("MIPI related vbt parsing complete\n");
895 0 : return;
896 : err:
897 0 : kfree(dev_priv->vbt.dsi.data);
898 0 : dev_priv->vbt.dsi.data = NULL;
899 :
900 : /* error during parsing so set all pointers to null
901 : * because of partial parsing */
902 0 : memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
903 0 : }
904 :
905 0 : static u8 translate_iboost(u8 val)
906 : {
907 : static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
908 :
909 0 : if (val >= ARRAY_SIZE(mapping)) {
910 : DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
911 0 : return 0;
912 : }
913 0 : return mapping[val];
914 0 : }
915 :
916 0 : static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
917 : const struct bdb_header *bdb)
918 : {
919 : union child_device_config *it, *child = NULL;
920 0 : struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
921 : uint8_t hdmi_level_shift;
922 : int i, j;
923 : bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
924 : uint8_t aux_channel, ddc_pin;
925 : /* Each DDI port can have more than one value on the "DVO Port" field,
926 : * so look for all the possible values for each port and abort if more
927 : * than one is found. */
928 0 : int dvo_ports[][3] = {
929 : {DVO_PORT_HDMIA, DVO_PORT_DPA, -1},
930 : {DVO_PORT_HDMIB, DVO_PORT_DPB, -1},
931 : {DVO_PORT_HDMIC, DVO_PORT_DPC, -1},
932 : {DVO_PORT_HDMID, DVO_PORT_DPD, -1},
933 : {DVO_PORT_CRT, DVO_PORT_HDMIE, DVO_PORT_DPE},
934 : };
935 :
936 : /* Find the child device to use, abort if more than one found. */
937 0 : for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
938 0 : it = dev_priv->vbt.child_dev + i;
939 :
940 0 : for (j = 0; j < 3; j++) {
941 0 : if (dvo_ports[port][j] == -1)
942 : break;
943 :
944 0 : if (it->common.dvo_port == dvo_ports[port][j]) {
945 0 : if (child) {
946 : DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
947 : port_name(port));
948 0 : return;
949 : }
950 : child = it;
951 0 : }
952 : }
953 : }
954 0 : if (!child)
955 0 : return;
956 :
957 0 : aux_channel = child->raw[25];
958 0 : ddc_pin = child->common.ddc_pin;
959 :
960 0 : is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
961 0 : is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
962 0 : is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
963 0 : is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
964 0 : is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
965 :
966 0 : if (port == PORT_A && is_dvi) {
967 : DRM_DEBUG_KMS("VBT claims port A supports DVI%s, ignoring\n",
968 : is_hdmi ? "/HDMI" : "");
969 : is_dvi = false;
970 : is_hdmi = false;
971 0 : }
972 :
973 0 : info->supports_dvi = is_dvi;
974 0 : info->supports_hdmi = is_hdmi;
975 0 : info->supports_dp = is_dp;
976 :
977 : DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
978 : port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
979 :
980 : if (is_edp && is_dvi)
981 : DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
982 : port_name(port));
983 0 : if (is_crt && port != PORT_E)
984 : DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
985 : if (is_crt && (is_dvi || is_dp))
986 : DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
987 : port_name(port));
988 : if (is_dvi && (port == PORT_A || port == PORT_E))
989 : DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port));
990 : if (!is_dvi && !is_dp && !is_crt)
991 : DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
992 : port_name(port));
993 : if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
994 : DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
995 :
996 0 : if (is_dvi) {
997 0 : if (port == PORT_E) {
998 0 : info->alternate_ddc_pin = ddc_pin;
999 : /* if DDIE share ddc pin with other port, then
1000 : * dvi/hdmi couldn't exist on the shared port.
1001 : * Otherwise they share the same ddc bin and system
1002 : * couldn't communicate with them seperately. */
1003 0 : if (ddc_pin == DDC_PIN_B) {
1004 0 : dev_priv->vbt.ddi_port_info[PORT_B].supports_dvi = 0;
1005 0 : dev_priv->vbt.ddi_port_info[PORT_B].supports_hdmi = 0;
1006 0 : } else if (ddc_pin == DDC_PIN_C) {
1007 0 : dev_priv->vbt.ddi_port_info[PORT_C].supports_dvi = 0;
1008 0 : dev_priv->vbt.ddi_port_info[PORT_C].supports_hdmi = 0;
1009 0 : } else if (ddc_pin == DDC_PIN_D) {
1010 0 : dev_priv->vbt.ddi_port_info[PORT_D].supports_dvi = 0;
1011 0 : dev_priv->vbt.ddi_port_info[PORT_D].supports_hdmi = 0;
1012 0 : }
1013 0 : } else if (ddc_pin == DDC_PIN_B && port != PORT_B)
1014 : DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
1015 0 : else if (ddc_pin == DDC_PIN_C && port != PORT_C)
1016 : DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
1017 0 : else if (ddc_pin == DDC_PIN_D && port != PORT_D)
1018 : DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
1019 : }
1020 :
1021 0 : if (is_dp) {
1022 0 : if (port == PORT_E) {
1023 0 : info->alternate_aux_channel = aux_channel;
1024 : /* if DDIE share aux channel with other port, then
1025 : * DP couldn't exist on the shared port. Otherwise
1026 : * they share the same aux channel and system
1027 : * couldn't communicate with them seperately. */
1028 0 : if (aux_channel == DP_AUX_A)
1029 0 : dev_priv->vbt.ddi_port_info[PORT_A].supports_dp = 0;
1030 0 : else if (aux_channel == DP_AUX_B)
1031 0 : dev_priv->vbt.ddi_port_info[PORT_B].supports_dp = 0;
1032 0 : else if (aux_channel == DP_AUX_C)
1033 0 : dev_priv->vbt.ddi_port_info[PORT_C].supports_dp = 0;
1034 0 : else if (aux_channel == DP_AUX_D)
1035 0 : dev_priv->vbt.ddi_port_info[PORT_D].supports_dp = 0;
1036 : }
1037 0 : else if (aux_channel == DP_AUX_A && port != PORT_A)
1038 : DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
1039 0 : else if (aux_channel == DP_AUX_B && port != PORT_B)
1040 : DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
1041 0 : else if (aux_channel == DP_AUX_C && port != PORT_C)
1042 : DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
1043 0 : else if (aux_channel == DP_AUX_D && port != PORT_D)
1044 : DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
1045 : }
1046 :
1047 0 : if (bdb->version >= 158) {
1048 : /* The VBT HDMI level shift values match the table we have. */
1049 0 : hdmi_level_shift = child->raw[7] & 0xF;
1050 : DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
1051 : port_name(port),
1052 : hdmi_level_shift);
1053 0 : info->hdmi_level_shift = hdmi_level_shift;
1054 0 : }
1055 :
1056 : /* Parse the I_boost config for SKL and above */
1057 0 : if (bdb->version >= 196 && (child->common.flags_1 & IBOOST_ENABLE)) {
1058 0 : info->dp_boost_level = translate_iboost(child->common.iboost_level & 0xF);
1059 : DRM_DEBUG_KMS("VBT (e)DP boost level for port %c: %d\n",
1060 : port_name(port), info->dp_boost_level);
1061 0 : info->hdmi_boost_level = translate_iboost(child->common.iboost_level >> 4);
1062 : DRM_DEBUG_KMS("VBT HDMI boost level for port %c: %d\n",
1063 : port_name(port), info->hdmi_boost_level);
1064 0 : }
1065 0 : }
1066 :
1067 0 : static void parse_ddi_ports(struct drm_i915_private *dev_priv,
1068 : const struct bdb_header *bdb)
1069 : {
1070 0 : struct drm_device *dev = dev_priv->dev;
1071 : enum port port;
1072 :
1073 0 : if (!HAS_DDI(dev))
1074 0 : return;
1075 :
1076 0 : if (!dev_priv->vbt.child_dev_num)
1077 0 : return;
1078 :
1079 0 : if (bdb->version < 155)
1080 0 : return;
1081 :
1082 0 : for (port = PORT_A; port < I915_MAX_PORTS; port++)
1083 0 : parse_ddi_port(dev_priv, port, bdb);
1084 0 : }
1085 :
1086 : static void
1087 0 : parse_device_mapping(struct drm_i915_private *dev_priv,
1088 : const struct bdb_header *bdb)
1089 : {
1090 : const struct bdb_general_definitions *p_defs;
1091 : const union child_device_config *p_child;
1092 : union child_device_config *child_dev_ptr;
1093 : int i, child_device_num, count;
1094 : u8 expected_size;
1095 : u16 block_size;
1096 :
1097 0 : p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
1098 0 : if (!p_defs) {
1099 : DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
1100 0 : return;
1101 : }
1102 0 : if (bdb->version < 195) {
1103 : expected_size = sizeof(struct old_child_dev_config);
1104 0 : } else if (bdb->version == 195) {
1105 : expected_size = 37;
1106 0 : } else if (bdb->version <= 197) {
1107 : expected_size = 38;
1108 : } else {
1109 : expected_size = 38;
1110 : BUILD_BUG_ON(sizeof(*p_child) < 38);
1111 : DRM_DEBUG_DRIVER("Expected child device config size for VBT version %u not known; assuming %u\n",
1112 : bdb->version, expected_size);
1113 : }
1114 :
1115 : /* The legacy sized child device config is the minimum we need. */
1116 0 : if (p_defs->child_dev_size < sizeof(struct old_child_dev_config)) {
1117 0 : DRM_ERROR("Child device config size %u is too small.\n",
1118 : p_defs->child_dev_size);
1119 0 : return;
1120 : }
1121 :
1122 : /* Flag an error for unexpected size, but continue anyway. */
1123 0 : if (p_defs->child_dev_size != expected_size)
1124 0 : DRM_ERROR("Unexpected child device config size %u (expected %u for VBT version %u)\n",
1125 : p_defs->child_dev_size, expected_size, bdb->version);
1126 :
1127 : /* get the block size of general definitions */
1128 0 : block_size = get_blocksize(p_defs);
1129 : /* get the number of child device */
1130 0 : child_device_num = (block_size - sizeof(*p_defs)) /
1131 0 : p_defs->child_dev_size;
1132 : count = 0;
1133 : /* get the number of child device that is present */
1134 0 : for (i = 0; i < child_device_num; i++) {
1135 0 : p_child = child_device_ptr(p_defs, i);
1136 0 : if (!p_child->common.device_type) {
1137 : /* skip the device block if device type is invalid */
1138 : continue;
1139 : }
1140 0 : count++;
1141 0 : }
1142 0 : if (!count) {
1143 : DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
1144 0 : return;
1145 : }
1146 0 : dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
1147 0 : if (!dev_priv->vbt.child_dev) {
1148 : DRM_DEBUG_KMS("No memory space for child device\n");
1149 0 : return;
1150 : }
1151 :
1152 0 : dev_priv->vbt.child_dev_num = count;
1153 : count = 0;
1154 0 : for (i = 0; i < child_device_num; i++) {
1155 0 : p_child = child_device_ptr(p_defs, i);
1156 0 : if (!p_child->common.device_type) {
1157 : /* skip the device block if device type is invalid */
1158 : continue;
1159 : }
1160 :
1161 0 : if (p_child->common.dvo_port >= DVO_PORT_MIPIA
1162 0 : && p_child->common.dvo_port <= DVO_PORT_MIPID
1163 0 : &&p_child->common.device_type & DEVICE_TYPE_MIPI_OUTPUT) {
1164 : DRM_DEBUG_KMS("Found MIPI as LFP\n");
1165 0 : dev_priv->vbt.has_mipi = 1;
1166 0 : dev_priv->vbt.dsi.port = p_child->common.dvo_port;
1167 0 : }
1168 :
1169 0 : child_dev_ptr = dev_priv->vbt.child_dev + count;
1170 0 : count++;
1171 :
1172 : /*
1173 : * Copy as much as we know (sizeof) and is available
1174 : * (child_dev_size) of the child device. Accessing the data must
1175 : * depend on VBT version.
1176 : */
1177 0 : memcpy(child_dev_ptr, p_child,
1178 : min_t(size_t, p_defs->child_dev_size, sizeof(*p_child)));
1179 0 : }
1180 0 : return;
1181 0 : }
1182 :
1183 : static void
1184 0 : init_vbt_defaults(struct drm_i915_private *dev_priv)
1185 : {
1186 0 : struct drm_device *dev = dev_priv->dev;
1187 : enum port port;
1188 :
1189 0 : dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
1190 :
1191 : /* Default to having backlight */
1192 0 : dev_priv->vbt.backlight.present = true;
1193 :
1194 : /* LFP panel data */
1195 0 : dev_priv->vbt.lvds_dither = 1;
1196 0 : dev_priv->vbt.lvds_vbt = 0;
1197 :
1198 : /* SDVO panel data */
1199 0 : dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
1200 :
1201 : /* general features */
1202 0 : dev_priv->vbt.int_tv_support = 1;
1203 0 : dev_priv->vbt.int_crt_support = 1;
1204 :
1205 : /* Default to using SSC */
1206 0 : dev_priv->vbt.lvds_use_ssc = 1;
1207 : /*
1208 : * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
1209 : * clock for LVDS.
1210 : */
1211 0 : dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev,
1212 0 : !HAS_PCH_SPLIT(dev));
1213 : DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
1214 :
1215 0 : for (port = PORT_A; port < I915_MAX_PORTS; port++) {
1216 : struct ddi_vbt_port_info *info =
1217 0 : &dev_priv->vbt.ddi_port_info[port];
1218 :
1219 0 : info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
1220 :
1221 0 : info->supports_dvi = (port != PORT_A && port != PORT_E);
1222 0 : info->supports_hdmi = info->supports_dvi;
1223 0 : info->supports_dp = (port != PORT_E);
1224 : }
1225 0 : }
1226 :
1227 0 : static int intel_no_opregion_vbt_callback(const struct dmi_system_id *id)
1228 : {
1229 : DRM_DEBUG_KMS("Falling back to manually reading VBT from "
1230 : "VBIOS ROM for %s\n",
1231 : id->ident);
1232 0 : return 1;
1233 : }
1234 :
1235 : static const struct dmi_system_id intel_no_opregion_vbt[] = {
1236 : {
1237 : .callback = intel_no_opregion_vbt_callback,
1238 : .ident = "ThinkCentre A57",
1239 : .matches = {
1240 : DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
1241 : DMI_MATCH(DMI_PRODUCT_NAME, "97027RG"),
1242 : },
1243 : },
1244 : { }
1245 : };
1246 :
1247 0 : static const struct bdb_header *validate_vbt(const void *base,
1248 : size_t size,
1249 : const void *_vbt,
1250 : const char *source)
1251 : {
1252 0 : size_t offset = _vbt - base;
1253 0 : const struct vbt_header *vbt = _vbt;
1254 : const struct bdb_header *bdb;
1255 :
1256 0 : if (offset + sizeof(struct vbt_header) > size) {
1257 : DRM_DEBUG_DRIVER("VBT header incomplete\n");
1258 0 : return NULL;
1259 : }
1260 :
1261 0 : if (memcmp(vbt->signature, "$VBT", 4)) {
1262 : DRM_DEBUG_DRIVER("VBT invalid signature\n");
1263 0 : return NULL;
1264 : }
1265 :
1266 0 : offset += vbt->bdb_offset;
1267 0 : if (offset + sizeof(struct bdb_header) > size) {
1268 : DRM_DEBUG_DRIVER("BDB header incomplete\n");
1269 0 : return NULL;
1270 : }
1271 :
1272 0 : bdb = base + offset;
1273 0 : if (offset + bdb->bdb_size > size) {
1274 : DRM_DEBUG_DRIVER("BDB incomplete\n");
1275 0 : return NULL;
1276 : }
1277 :
1278 : DRM_DEBUG_KMS("Using VBT from %s: %20s\n",
1279 : source, vbt->signature);
1280 0 : return bdb;
1281 0 : }
1282 :
1283 0 : static const struct bdb_header *find_vbt(void __iomem *bios, size_t size)
1284 : {
1285 : const struct bdb_header *bdb = NULL;
1286 : size_t i;
1287 :
1288 : /* Scour memory looking for the VBT signature. */
1289 0 : for (i = 0; i + 4 < size; i++) {
1290 0 : if (ioread32(bios + i) == *((const u32 *) "$VBT")) {
1291 : /*
1292 : * This is the one place where we explicitly discard the
1293 : * address space (__iomem) of the BIOS/VBT. From now on
1294 : * everything is based on 'base', and treated as regular
1295 : * memory.
1296 : */
1297 : void *_bios = (void __force *) bios;
1298 :
1299 0 : bdb = validate_vbt(_bios, size, _bios + i, "PCI ROM");
1300 : break;
1301 : }
1302 : }
1303 :
1304 0 : return bdb;
1305 : }
1306 :
1307 : #include <dev/isa/isareg.h>
1308 : #include <dev/isa/isavar.h>
1309 :
1310 : #define VGA_BIOS_ADDR 0xc0000
1311 : #define VGA_BIOS_LEN 0x10000
1312 :
1313 : /**
1314 : * intel_parse_bios - find VBT and initialize settings from the BIOS
1315 : * @dev: DRM device
1316 : *
1317 : * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
1318 : * to appropriate values.
1319 : *
1320 : * Returns 0 on success, nonzero on failure.
1321 : */
1322 : int
1323 0 : intel_parse_bios(struct drm_device *dev)
1324 : {
1325 0 : struct drm_i915_private *dev_priv = dev->dev_private;
1326 : #ifdef __linux__
1327 : struct pci_dev *pdev = dev->pdev;
1328 : #endif
1329 : const struct bdb_header *bdb = NULL;
1330 : u8 __iomem *bios = NULL;
1331 :
1332 0 : if (HAS_PCH_NOP(dev))
1333 0 : return -ENODEV;
1334 :
1335 0 : init_vbt_defaults(dev_priv);
1336 :
1337 : /* XXX Should this validation be moved to intel_opregion.c? */
1338 0 : if (!dmi_check_system(intel_no_opregion_vbt) && dev_priv->opregion.vbt)
1339 0 : bdb = validate_vbt(dev_priv->opregion.header, OPREGION_SIZE,
1340 : dev_priv->opregion.vbt, "OpRegion");
1341 :
1342 0 : if (bdb == NULL) {
1343 : size_t size;
1344 :
1345 : #ifdef __linux__
1346 : bios = pci_map_rom(pdev, &size);
1347 : if (!bios)
1348 : return -1;
1349 : #else
1350 0 : bios = (u8 *)ISA_HOLE_VADDR(VGA_BIOS_ADDR);
1351 : size = VGA_BIOS_LEN;
1352 : #endif
1353 :
1354 0 : bdb = find_vbt(bios, size);
1355 0 : if (!bdb) {
1356 : #ifdef __linux__
1357 : pci_unmap_rom(pdev, bios);
1358 : #endif
1359 0 : return -1;
1360 : }
1361 0 : }
1362 :
1363 : /* Grab useful general definitions */
1364 0 : parse_general_features(dev_priv, bdb);
1365 0 : parse_general_definitions(dev_priv, bdb);
1366 0 : parse_lfp_panel_data(dev_priv, bdb);
1367 0 : parse_lfp_backlight(dev_priv, bdb);
1368 0 : parse_sdvo_panel_data(dev_priv, bdb);
1369 0 : parse_sdvo_device_mapping(dev_priv, bdb);
1370 0 : parse_device_mapping(dev_priv, bdb);
1371 0 : parse_driver_features(dev_priv, bdb);
1372 0 : parse_edp(dev_priv, bdb);
1373 0 : parse_psr(dev_priv, bdb);
1374 0 : parse_mipi(dev_priv, bdb);
1375 0 : parse_ddi_ports(dev_priv, bdb);
1376 :
1377 : #ifdef __linux__
1378 : if (bios)
1379 : pci_unmap_rom(pdev, bios);
1380 : #endif
1381 :
1382 0 : return 0;
1383 0 : }
1384 :
1385 : /**
1386 : * intel_bios_is_port_present - is the specified digital port present
1387 : * @dev_priv: i915 device instance
1388 : * @port: port to check
1389 : *
1390 : * Return true if the device in %port is present.
1391 : */
1392 0 : bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port)
1393 : {
1394 : static const struct {
1395 : u16 dp, hdmi;
1396 : } port_mapping[] = {
1397 : [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
1398 : [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
1399 : [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
1400 : [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
1401 : };
1402 : int i;
1403 :
1404 : /* FIXME maybe deal with port A as well? */
1405 0 : if (WARN_ON(port == PORT_A) || port >= ARRAY_SIZE(port_mapping))
1406 0 : return false;
1407 :
1408 0 : if (!dev_priv->vbt.child_dev_num)
1409 0 : return false;
1410 :
1411 0 : for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1412 : const union child_device_config *p_child =
1413 0 : &dev_priv->vbt.child_dev[i];
1414 0 : if ((p_child->common.dvo_port == port_mapping[port].dp ||
1415 0 : p_child->common.dvo_port == port_mapping[port].hdmi) &&
1416 0 : (p_child->common.device_type & (DEVICE_TYPE_TMDS_DVI_SIGNALING |
1417 : DEVICE_TYPE_DISPLAYPORT_OUTPUT)))
1418 0 : return true;
1419 0 : }
1420 :
1421 0 : return false;
1422 0 : }
|