xref: /linux/drivers/gpu/drm/i915/display/intel_bios.c (revision fab183d632628381b466a41479489541ac0e29a0)
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 <linux/debugfs.h>
29 #include <linux/firmware.h>
30 
31 #include <drm/display/drm_dp_helper.h>
32 #include <drm/display/drm_dsc_helper.h>
33 #include <drm/drm_edid.h>
34 #include <drm/drm_fixed.h>
35 #include <drm/drm_print.h>
36 
37 #include "intel_display.h"
38 #include "intel_display_core.h"
39 #include "intel_display_rpm.h"
40 #include "intel_display_types.h"
41 #include "intel_display_utils.h"
42 #include "intel_gmbus.h"
43 #include "intel_rom.h"
44 #include "intel_vdsc.h"
45 
46 #define _INTEL_BIOS_PRIVATE
47 #include "intel_vbt_defs.h"
48 
49 /**
50  * DOC: Video BIOS Table (VBT)
51  *
52  * The Video BIOS Table, or VBT, provides platform and board specific
53  * configuration information to the driver that is not discoverable or available
54  * through other means. The configuration is mostly related to display
55  * hardware. The VBT is available via the ACPI OpRegion or, on older systems, in
56  * the PCI ROM.
57  *
58  * The VBT consists of a VBT Header (defined as &struct vbt_header), a BDB
59  * Header (&struct bdb_header), and a number of BIOS Data Blocks (BDB) that
60  * contain the actual configuration information. The VBT Header, and thus the
61  * VBT, begins with "$VBT" signature. The VBT Header contains the offset of the
62  * BDB Header. The data blocks are concatenated after the BDB Header. The data
63  * blocks have a 1-byte Block ID, 2-byte Block Size, and Block Size bytes of
64  * data. (Block 53, the MIPI Sequence Block is an exception.)
65  *
66  * The driver parses the VBT during load. The relevant information is stored in
67  * driver private data for ease of use, and the actual VBT is not read after
68  * that.
69  */
70 
71 /* Wrapper for VBT child device config */
72 struct intel_bios_encoder_data {
73 	struct intel_display *display;
74 
75 	struct child_device_config child;
76 	struct dsc_compression_parameters_entry *dsc;
77 	struct list_head node;
78 };
79 
80 #define	TARGET_ADDR1	0x70
81 #define	TARGET_ADDR2	0x72
82 
83 /* Get BDB block size given a pointer to Block ID. */
_get_blocksize(const u8 * block_base)84 static u32 _get_blocksize(const u8 *block_base)
85 {
86 	/* The MIPI Sequence Block v3+ has a separate size field. */
87 	if (*block_base == BDB_MIPI_SEQUENCE && *(block_base + 3) >= 3)
88 		return *((const u32 *)(block_base + 4));
89 	else
90 		return *((const u16 *)(block_base + 1));
91 }
92 
93 /* Get BDB block size give a pointer to data after Block ID and Block Size. */
get_blocksize(const void * block_data)94 static u32 get_blocksize(const void *block_data)
95 {
96 	return _get_blocksize(block_data - 3);
97 }
98 
99 static const void *
find_raw_section(const void * _bdb,enum bdb_block_id section_id)100 find_raw_section(const void *_bdb, enum bdb_block_id section_id)
101 {
102 	const struct bdb_header *bdb = _bdb;
103 	const u8 *base = _bdb;
104 	int index = 0;
105 	u32 total, current_size;
106 	enum bdb_block_id current_id;
107 
108 	/* skip to first section */
109 	index += bdb->header_size;
110 	total = bdb->bdb_size;
111 
112 	/* walk the sections looking for section_id */
113 	while (index + 3 < total) {
114 		current_id = *(base + index);
115 		current_size = _get_blocksize(base + index);
116 		index += 3;
117 
118 		if (index + current_size > total)
119 			return NULL;
120 
121 		if (current_id == section_id)
122 			return base + index;
123 
124 		index += current_size;
125 	}
126 
127 	return NULL;
128 }
129 
130 /*
131  * Offset from the start of BDB to the start of the
132  * block data (just past the block header).
133  */
raw_block_offset(const void * bdb,enum bdb_block_id section_id)134 static u32 raw_block_offset(const void *bdb, enum bdb_block_id section_id)
135 {
136 	const void *block;
137 
138 	block = find_raw_section(bdb, section_id);
139 	if (!block)
140 		return 0;
141 
142 	return block - bdb;
143 }
144 
145 struct bdb_block_entry {
146 	struct list_head node;
147 	enum bdb_block_id section_id;
148 	u8 data[];
149 };
150 
151 static const void *
bdb_find_section(struct intel_display * display,enum bdb_block_id section_id)152 bdb_find_section(struct intel_display *display,
153 		 enum bdb_block_id section_id)
154 {
155 	struct bdb_block_entry *entry;
156 
157 	list_for_each_entry(entry, &display->vbt.bdb_blocks, node) {
158 		if (entry->section_id == section_id)
159 			return entry->data + 3;
160 	}
161 
162 	return NULL;
163 }
164 
165 static const struct {
166 	enum bdb_block_id section_id;
167 	size_t min_size;
168 } bdb_blocks[] = {
169 	{ .section_id = BDB_GENERAL_FEATURES,
170 	  .min_size = sizeof(struct bdb_general_features), },
171 	{ .section_id = BDB_GENERAL_DEFINITIONS,
172 	  .min_size = sizeof(struct bdb_general_definitions), },
173 	{ .section_id = BDB_PSR,
174 	  .min_size = sizeof(struct bdb_psr), },
175 	{ .section_id = BDB_DRIVER_FEATURES,
176 	  .min_size = sizeof(struct bdb_driver_features), },
177 	{ .section_id = BDB_SDVO_LVDS_OPTIONS,
178 	  .min_size = sizeof(struct bdb_sdvo_lvds_options), },
179 	{ .section_id = BDB_SDVO_LVDS_DTD,
180 	  .min_size = sizeof(struct bdb_sdvo_lvds_dtd), },
181 	{ .section_id = BDB_EDP,
182 	  .min_size = sizeof(struct bdb_edp), },
183 	{ .section_id = BDB_LFP_OPTIONS,
184 	  .min_size = sizeof(struct bdb_lfp_options), },
185 	/*
186 	 * BDB_LFP_DATA depends on BDB_LFP_DATA_PTRS,
187 	 * so keep the two ordered.
188 	 */
189 	{ .section_id = BDB_LFP_DATA_PTRS,
190 	  .min_size = sizeof(struct bdb_lfp_data_ptrs), },
191 	{ .section_id = BDB_LFP_DATA,
192 	  .min_size = 0, /* special case */ },
193 	{ .section_id = BDB_LFP_BACKLIGHT,
194 	  .min_size = sizeof(struct bdb_lfp_backlight), },
195 	{ .section_id = BDB_LFP_POWER,
196 	  .min_size = sizeof(struct bdb_lfp_power), },
197 	{ .section_id = BDB_MIPI_CONFIG,
198 	  .min_size = sizeof(struct bdb_mipi_config), },
199 	{ .section_id = BDB_MIPI_SEQUENCE,
200 	  .min_size = sizeof(struct bdb_mipi_sequence) },
201 	{ .section_id = BDB_COMPRESSION_PARAMETERS,
202 	  .min_size = sizeof(struct bdb_compression_parameters), },
203 	{ .section_id = BDB_GENERIC_DTD,
204 	  .min_size = sizeof(struct bdb_generic_dtd), },
205 };
206 
lfp_data_min_size(struct intel_display * display)207 static size_t lfp_data_min_size(struct intel_display *display)
208 {
209 	const struct bdb_lfp_data_ptrs *ptrs;
210 	size_t size;
211 
212 	ptrs = bdb_find_section(display, BDB_LFP_DATA_PTRS);
213 	if (!ptrs)
214 		return 0;
215 
216 	size = sizeof(struct bdb_lfp_data);
217 	if (ptrs->panel_name.table_size)
218 		size = max(size, ptrs->panel_name.offset +
219 			   sizeof(struct bdb_lfp_data_tail));
220 
221 	return size;
222 }
223 
validate_lfp_data_ptrs(const void * bdb,const struct bdb_lfp_data_ptrs * ptrs)224 static bool validate_lfp_data_ptrs(const void *bdb,
225 				   const struct bdb_lfp_data_ptrs *ptrs)
226 {
227 	int fp_timing_size, dvo_timing_size, panel_pnp_id_size, panel_name_size;
228 	int data_block_size, lfp_data_size;
229 	const void *data_block;
230 	int i;
231 
232 	data_block = find_raw_section(bdb, BDB_LFP_DATA);
233 	if (!data_block)
234 		return false;
235 
236 	data_block_size = get_blocksize(data_block);
237 	if (data_block_size == 0)
238 		return false;
239 
240 	/* always 3 indicating the presence of fp_timing+dvo_timing+panel_pnp_id */
241 	if (ptrs->num_entries != 3)
242 		return false;
243 
244 	fp_timing_size = ptrs->ptr[0].fp_timing.table_size;
245 	dvo_timing_size = ptrs->ptr[0].dvo_timing.table_size;
246 	panel_pnp_id_size = ptrs->ptr[0].panel_pnp_id.table_size;
247 	panel_name_size = ptrs->panel_name.table_size;
248 
249 	/* fp_timing has variable size */
250 	if (fp_timing_size < 32 ||
251 	    dvo_timing_size != sizeof(struct bdb_edid_dtd) ||
252 	    panel_pnp_id_size != sizeof(struct bdb_edid_pnp_id))
253 		return false;
254 
255 	/* panel_name is not present in old VBTs */
256 	if (panel_name_size != 0 &&
257 	    panel_name_size != sizeof(struct bdb_edid_product_name))
258 		return false;
259 
260 	lfp_data_size = ptrs->ptr[1].fp_timing.offset - ptrs->ptr[0].fp_timing.offset;
261 	if (16 * lfp_data_size > data_block_size)
262 		return false;
263 
264 	/* make sure the table entries have uniform size */
265 	for (i = 1; i < 16; i++) {
266 		if (ptrs->ptr[i].fp_timing.table_size != fp_timing_size ||
267 		    ptrs->ptr[i].dvo_timing.table_size != dvo_timing_size ||
268 		    ptrs->ptr[i].panel_pnp_id.table_size != panel_pnp_id_size)
269 			return false;
270 
271 		if (ptrs->ptr[i].fp_timing.offset - ptrs->ptr[i-1].fp_timing.offset != lfp_data_size ||
272 		    ptrs->ptr[i].dvo_timing.offset - ptrs->ptr[i-1].dvo_timing.offset != lfp_data_size ||
273 		    ptrs->ptr[i].panel_pnp_id.offset - ptrs->ptr[i-1].panel_pnp_id.offset != lfp_data_size)
274 			return false;
275 	}
276 
277 	/*
278 	 * Except for vlv/chv machines all real VBTs seem to have 6
279 	 * unaccounted bytes in the fp_timing table. And it doesn't
280 	 * appear to be a really intentional hole as the fp_timing
281 	 * 0xffff terminator is always within those 6 missing bytes.
282 	 */
283 	if (fp_timing_size + 6 + dvo_timing_size + panel_pnp_id_size == lfp_data_size)
284 		fp_timing_size += 6;
285 
286 	if (fp_timing_size + dvo_timing_size + panel_pnp_id_size != lfp_data_size)
287 		return false;
288 
289 	if (ptrs->ptr[0].fp_timing.offset + fp_timing_size != ptrs->ptr[0].dvo_timing.offset ||
290 	    ptrs->ptr[0].dvo_timing.offset + dvo_timing_size != ptrs->ptr[0].panel_pnp_id.offset ||
291 	    ptrs->ptr[0].panel_pnp_id.offset + panel_pnp_id_size != lfp_data_size)
292 		return false;
293 
294 	/* make sure the tables fit inside the data block */
295 	for (i = 0; i < 16; i++) {
296 		if (ptrs->ptr[i].fp_timing.offset + fp_timing_size > data_block_size ||
297 		    ptrs->ptr[i].dvo_timing.offset + dvo_timing_size > data_block_size ||
298 		    ptrs->ptr[i].panel_pnp_id.offset + panel_pnp_id_size > data_block_size)
299 			return false;
300 	}
301 
302 	if (ptrs->panel_name.offset + 16 * panel_name_size > data_block_size)
303 		return false;
304 
305 	/* make sure fp_timing terminators are present at expected locations */
306 	for (i = 0; i < 16; i++) {
307 		const u16 *t = data_block + ptrs->ptr[i].fp_timing.offset +
308 			fp_timing_size - 2;
309 
310 		if (*t != 0xffff)
311 			return false;
312 	}
313 
314 	return true;
315 }
316 
317 /* make the data table offsets relative to the data block */
fixup_lfp_data_ptrs(const void * bdb,void * ptrs_block)318 static bool fixup_lfp_data_ptrs(const void *bdb, void *ptrs_block)
319 {
320 	struct bdb_lfp_data_ptrs *ptrs = ptrs_block;
321 	u32 offset;
322 	int i;
323 
324 	offset = raw_block_offset(bdb, BDB_LFP_DATA);
325 
326 	for (i = 0; i < 16; i++) {
327 		if (ptrs->ptr[i].fp_timing.offset < offset ||
328 		    ptrs->ptr[i].dvo_timing.offset < offset ||
329 		    ptrs->ptr[i].panel_pnp_id.offset < offset)
330 			return false;
331 
332 		ptrs->ptr[i].fp_timing.offset -= offset;
333 		ptrs->ptr[i].dvo_timing.offset -= offset;
334 		ptrs->ptr[i].panel_pnp_id.offset -= offset;
335 	}
336 
337 	if (ptrs->panel_name.table_size) {
338 		if (ptrs->panel_name.offset < offset)
339 			return false;
340 
341 		ptrs->panel_name.offset -= offset;
342 	}
343 
344 	return validate_lfp_data_ptrs(bdb, ptrs);
345 }
346 
make_lfp_data_ptr(struct lfp_data_ptr_table * table,int table_size,int total_size)347 static int make_lfp_data_ptr(struct lfp_data_ptr_table *table,
348 			     int table_size, int total_size)
349 {
350 	if (total_size < table_size)
351 		return total_size;
352 
353 	table->table_size = table_size;
354 	table->offset = total_size - table_size;
355 
356 	return total_size - table_size;
357 }
358 
next_lfp_data_ptr(struct lfp_data_ptr_table * next,const struct lfp_data_ptr_table * prev,int size)359 static void next_lfp_data_ptr(struct lfp_data_ptr_table *next,
360 			      const struct lfp_data_ptr_table *prev,
361 			      int size)
362 {
363 	next->table_size = prev->table_size;
364 	next->offset = prev->offset + size;
365 }
366 
generate_lfp_data_ptrs(struct intel_display * display,const void * bdb)367 static void *generate_lfp_data_ptrs(struct intel_display *display,
368 				    const void *bdb)
369 {
370 	int i, size, table_size, block_size, offset, fp_timing_size;
371 	struct bdb_lfp_data_ptrs *ptrs;
372 	const void *block;
373 	void *ptrs_block;
374 
375 	/*
376 	 * The hardcoded fp_timing_size is only valid for
377 	 * modernish VBTs. All older VBTs definitely should
378 	 * include block 41 and thus we don't need to
379 	 * generate one.
380 	 */
381 	if (display->vbt.version < 155)
382 		return NULL;
383 
384 	fp_timing_size = 38;
385 
386 	block = find_raw_section(bdb, BDB_LFP_DATA);
387 	if (!block)
388 		return NULL;
389 
390 	drm_dbg_kms(display->drm, "Generating LFP data table pointers\n");
391 
392 	block_size = get_blocksize(block);
393 
394 	size = fp_timing_size + sizeof(struct bdb_edid_dtd) +
395 		sizeof(struct bdb_edid_pnp_id);
396 	if (size * 16 > block_size)
397 		return NULL;
398 
399 	ptrs_block = kzalloc(sizeof(*ptrs) + 3, GFP_KERNEL);
400 	if (!ptrs_block)
401 		return NULL;
402 
403 	*(u8 *)(ptrs_block + 0) = BDB_LFP_DATA_PTRS;
404 	*(u16 *)(ptrs_block + 1) = sizeof(*ptrs);
405 	ptrs = ptrs_block + 3;
406 
407 	table_size = sizeof(struct bdb_edid_pnp_id);
408 	size = make_lfp_data_ptr(&ptrs->ptr[0].panel_pnp_id, table_size, size);
409 
410 	table_size = sizeof(struct bdb_edid_dtd);
411 	size = make_lfp_data_ptr(&ptrs->ptr[0].dvo_timing, table_size, size);
412 
413 	table_size = fp_timing_size;
414 	size = make_lfp_data_ptr(&ptrs->ptr[0].fp_timing, table_size, size);
415 
416 	if (ptrs->ptr[0].fp_timing.table_size)
417 		ptrs->num_entries++;
418 	if (ptrs->ptr[0].dvo_timing.table_size)
419 		ptrs->num_entries++;
420 	if (ptrs->ptr[0].panel_pnp_id.table_size)
421 		ptrs->num_entries++;
422 
423 	if (size != 0 || ptrs->num_entries != 3) {
424 		kfree(ptrs_block);
425 		return NULL;
426 	}
427 
428 	size = fp_timing_size + sizeof(struct bdb_edid_dtd) +
429 		sizeof(struct bdb_edid_pnp_id);
430 	for (i = 1; i < 16; i++) {
431 		next_lfp_data_ptr(&ptrs->ptr[i].fp_timing, &ptrs->ptr[i-1].fp_timing, size);
432 		next_lfp_data_ptr(&ptrs->ptr[i].dvo_timing, &ptrs->ptr[i-1].dvo_timing, size);
433 		next_lfp_data_ptr(&ptrs->ptr[i].panel_pnp_id, &ptrs->ptr[i-1].panel_pnp_id, size);
434 	}
435 
436 	table_size = sizeof(struct bdb_edid_product_name);
437 
438 	if (16 * (size + table_size) <= block_size) {
439 		ptrs->panel_name.table_size = table_size;
440 		ptrs->panel_name.offset = size * 16;
441 	}
442 
443 	offset = block - bdb;
444 
445 	for (i = 0; i < 16; i++) {
446 		ptrs->ptr[i].fp_timing.offset += offset;
447 		ptrs->ptr[i].dvo_timing.offset += offset;
448 		ptrs->ptr[i].panel_pnp_id.offset += offset;
449 	}
450 
451 	if (ptrs->panel_name.table_size)
452 		ptrs->panel_name.offset += offset;
453 
454 	return ptrs_block;
455 }
456 
457 static void
init_bdb_block(struct intel_display * display,const void * bdb,enum bdb_block_id section_id,size_t min_size)458 init_bdb_block(struct intel_display *display,
459 	       const void *bdb, enum bdb_block_id section_id,
460 	       size_t min_size)
461 {
462 	struct bdb_block_entry *entry;
463 	void *temp_block = NULL;
464 	const void *block;
465 	size_t block_size;
466 
467 	block = find_raw_section(bdb, section_id);
468 
469 	/* Modern VBTs lack the LFP data table pointers block, make one up */
470 	if (!block && section_id == BDB_LFP_DATA_PTRS) {
471 		temp_block = generate_lfp_data_ptrs(display, bdb);
472 		if (temp_block)
473 			block = temp_block + 3;
474 	}
475 	if (!block)
476 		return;
477 
478 	drm_WARN(display->drm, min_size == 0,
479 		 "Block %d min_size is zero\n", section_id);
480 
481 	block_size = get_blocksize(block);
482 
483 	/*
484 	 * Version number and new block size are considered
485 	 * part of the header for MIPI sequenece block v3+.
486 	 */
487 	if (section_id == BDB_MIPI_SEQUENCE && *(const u8 *)block >= 3)
488 		block_size += 5;
489 
490 	entry = kzalloc_flex(*entry, data, max(min_size, block_size) + 3);
491 	if (!entry) {
492 		kfree(temp_block);
493 		return;
494 	}
495 
496 	entry->section_id = section_id;
497 	memcpy(entry->data, block - 3, block_size + 3);
498 
499 	kfree(temp_block);
500 
501 	drm_dbg_kms(display->drm,
502 		    "Found BDB block %d (size %zu, min size %zu)\n",
503 		    section_id, block_size, min_size);
504 
505 	if (section_id == BDB_LFP_DATA_PTRS &&
506 	    !fixup_lfp_data_ptrs(bdb, entry->data + 3)) {
507 		drm_err(display->drm,
508 			"VBT has malformed LFP data table pointers\n");
509 		kfree(entry);
510 		return;
511 	}
512 
513 	list_add_tail(&entry->node, &display->vbt.bdb_blocks);
514 }
515 
init_bdb_blocks(struct intel_display * display,const void * bdb)516 static void init_bdb_blocks(struct intel_display *display,
517 			    const void *bdb)
518 {
519 	int i;
520 
521 	for (i = 0; i < ARRAY_SIZE(bdb_blocks); i++) {
522 		enum bdb_block_id section_id = bdb_blocks[i].section_id;
523 		size_t min_size = bdb_blocks[i].min_size;
524 
525 		if (section_id == BDB_LFP_DATA)
526 			min_size = lfp_data_min_size(display);
527 
528 		init_bdb_block(display, bdb, section_id, min_size);
529 	}
530 }
531 
532 static void
fill_detail_timing_data(struct intel_display * display,struct drm_display_mode * panel_fixed_mode,const struct bdb_edid_dtd * dvo_timing)533 fill_detail_timing_data(struct intel_display *display,
534 			struct drm_display_mode *panel_fixed_mode,
535 			const struct bdb_edid_dtd *dvo_timing)
536 {
537 	panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
538 		dvo_timing->hactive_lo;
539 	panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
540 		((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
541 	panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
542 		((dvo_timing->hsync_pulse_width_hi << 8) |
543 			dvo_timing->hsync_pulse_width_lo);
544 	panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
545 		((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
546 
547 	panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
548 		dvo_timing->vactive_lo;
549 	panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
550 		((dvo_timing->vsync_off_hi << 4) | dvo_timing->vsync_off_lo);
551 	panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
552 		((dvo_timing->vsync_pulse_width_hi << 4) |
553 			dvo_timing->vsync_pulse_width_lo);
554 	panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
555 		((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
556 	panel_fixed_mode->clock = dvo_timing->clock * 10;
557 	panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
558 
559 	if (dvo_timing->hsync_positive)
560 		panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
561 	else
562 		panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
563 
564 	if (dvo_timing->vsync_positive)
565 		panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
566 	else
567 		panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
568 
569 	panel_fixed_mode->width_mm = (dvo_timing->himage_hi << 8) |
570 		dvo_timing->himage_lo;
571 	panel_fixed_mode->height_mm = (dvo_timing->vimage_hi << 8) |
572 		dvo_timing->vimage_lo;
573 
574 	/* Some VBTs have bogus h/vsync_end values */
575 	if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal) {
576 		drm_dbg_kms(display->drm, "reducing hsync_end %d->%d\n",
577 			    panel_fixed_mode->hsync_end, panel_fixed_mode->htotal);
578 		panel_fixed_mode->hsync_end = panel_fixed_mode->htotal;
579 	}
580 	if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal) {
581 		drm_dbg_kms(display->drm, "reducing vsync_end %d->%d\n",
582 			    panel_fixed_mode->vsync_end, panel_fixed_mode->vtotal);
583 		panel_fixed_mode->vsync_end = panel_fixed_mode->vtotal;
584 	}
585 
586 	drm_mode_set_name(panel_fixed_mode);
587 }
588 
589 static const struct bdb_edid_dtd *
get_lfp_dvo_timing(const struct bdb_lfp_data * data,const struct bdb_lfp_data_ptrs * ptrs,int index)590 get_lfp_dvo_timing(const struct bdb_lfp_data *data,
591 		   const struct bdb_lfp_data_ptrs *ptrs,
592 		   int index)
593 {
594 	return (const void *)data + ptrs->ptr[index].dvo_timing.offset;
595 }
596 
597 static const struct fp_timing *
get_lfp_fp_timing(const struct bdb_lfp_data * data,const struct bdb_lfp_data_ptrs * ptrs,int index)598 get_lfp_fp_timing(const struct bdb_lfp_data *data,
599 		  const struct bdb_lfp_data_ptrs *ptrs,
600 		  int index)
601 {
602 	return (const void *)data + ptrs->ptr[index].fp_timing.offset;
603 }
604 
605 static const struct drm_edid_product_id *
get_lfp_pnp_id(const struct bdb_lfp_data * data,const struct bdb_lfp_data_ptrs * ptrs,int index)606 get_lfp_pnp_id(const struct bdb_lfp_data *data,
607 	       const struct bdb_lfp_data_ptrs *ptrs,
608 	       int index)
609 {
610 	/* These two are supposed to have the same layout in memory. */
611 	BUILD_BUG_ON(sizeof(struct bdb_edid_pnp_id) != sizeof(struct drm_edid_product_id));
612 
613 	return (const void *)data + ptrs->ptr[index].panel_pnp_id.offset;
614 }
615 
616 static const struct bdb_lfp_data_tail *
get_lfp_data_tail(const struct bdb_lfp_data * data,const struct bdb_lfp_data_ptrs * ptrs)617 get_lfp_data_tail(const struct bdb_lfp_data *data,
618 		  const struct bdb_lfp_data_ptrs *ptrs)
619 {
620 	if (ptrs->panel_name.table_size)
621 		return (const void *)data + ptrs->panel_name.offset;
622 	else
623 		return NULL;
624 }
625 
is_panel_type_valid(int panel_type)626 static bool is_panel_type_valid(int panel_type)
627 {
628 	return panel_type >= 0 && panel_type < 16;
629 }
630 
is_panel_type_pnp(int panel_type)631 static bool is_panel_type_pnp(int panel_type)
632 {
633 	return panel_type == 0xff;
634 }
635 
is_panel_type_valid_or_pnp(int panel_type)636 static bool is_panel_type_valid_or_pnp(int panel_type)
637 {
638 	return is_panel_type_valid(panel_type) || is_panel_type_pnp(panel_type);
639 }
640 
opregion_get_panel_type(struct intel_display * display,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)641 static int opregion_get_panel_type(struct intel_display *display,
642 				   const struct intel_bios_encoder_data *devdata,
643 				   const struct drm_edid *drm_edid, bool use_fallback)
644 {
645 	return intel_opregion_get_panel_type(display);
646 }
647 
vbt_get_panel_type(struct intel_display * display,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)648 static int vbt_get_panel_type(struct intel_display *display,
649 			      const struct intel_bios_encoder_data *devdata,
650 			      const struct drm_edid *drm_edid, bool use_fallback)
651 {
652 	const struct bdb_lfp_options *lfp_options;
653 
654 	lfp_options = bdb_find_section(display, BDB_LFP_OPTIONS);
655 	if (!lfp_options)
656 		return -1;
657 
658 	if (!is_panel_type_valid_or_pnp(lfp_options->panel_type)) {
659 		drm_dbg_kms(display->drm, "Invalid VBT panel type 0x%x\n",
660 			    lfp_options->panel_type);
661 		return -1;
662 	}
663 
664 	if (devdata && devdata->child.handle == DEVICE_HANDLE_LFP2) {
665 		if (!is_panel_type_valid_or_pnp(lfp_options->panel_type2)) {
666 			drm_dbg_kms(display->drm, "Invalid VBT panel type 2 0x%x\n",
667 				    lfp_options->panel_type2);
668 			return -1;
669 		}
670 
671 		return lfp_options->panel_type2;
672 	}
673 
674 	drm_WARN_ON(display->drm,
675 		    devdata && devdata->child.handle != DEVICE_HANDLE_LFP1);
676 
677 	return lfp_options->panel_type;
678 }
679 
pnpid_get_panel_type(struct intel_display * display,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)680 static int pnpid_get_panel_type(struct intel_display *display,
681 				const struct intel_bios_encoder_data *devdata,
682 				const struct drm_edid *drm_edid, bool use_fallback)
683 {
684 	const struct bdb_lfp_data *data;
685 	const struct bdb_lfp_data_ptrs *ptrs;
686 	struct drm_edid_product_id product_id, product_id_nodate;
687 	struct drm_printer p;
688 	int i, best = -1;
689 
690 	if (!drm_edid)
691 		return -1;
692 
693 	drm_edid_get_product_id(drm_edid, &product_id);
694 
695 	product_id_nodate = product_id;
696 	product_id_nodate.week_of_manufacture = 0;
697 	product_id_nodate.year_of_manufacture = 0;
698 
699 	p = drm_dbg_printer(display->drm, DRM_UT_KMS, "EDID");
700 	drm_edid_print_product_id(&p, &product_id, true);
701 
702 	ptrs = bdb_find_section(display, BDB_LFP_DATA_PTRS);
703 	if (!ptrs)
704 		return -1;
705 
706 	data = bdb_find_section(display, BDB_LFP_DATA);
707 	if (!data)
708 		return -1;
709 
710 	for (i = 0; i < 16; i++) {
711 		const struct drm_edid_product_id *vbt_id =
712 			get_lfp_pnp_id(data, ptrs, i);
713 
714 		/* full match? */
715 		if (!memcmp(vbt_id, &product_id, sizeof(*vbt_id)))
716 			return i;
717 
718 		/*
719 		 * Accept a match w/o date if no full match is found,
720 		 * and the VBT entry does not specify a date.
721 		 */
722 		if (best < 0 &&
723 		    !memcmp(vbt_id, &product_id_nodate, sizeof(*vbt_id)))
724 			best = i;
725 	}
726 
727 	return best;
728 }
729 
fallback_get_panel_type(struct intel_display * display,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)730 static int fallback_get_panel_type(struct intel_display *display,
731 				   const struct intel_bios_encoder_data *devdata,
732 				   const struct drm_edid *drm_edid, bool use_fallback)
733 {
734 	return use_fallback ? 0 : -1;
735 }
736 
737 enum panel_type {
738 	PANEL_TYPE_OPREGION,
739 	PANEL_TYPE_VBT,
740 	PANEL_TYPE_PNPID,
741 	PANEL_TYPE_FALLBACK,
742 };
743 
get_panel_type(struct intel_display * display,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)744 static int get_panel_type(struct intel_display *display,
745 			  const struct intel_bios_encoder_data *devdata,
746 			  const struct drm_edid *drm_edid, bool use_fallback)
747 {
748 	struct {
749 		const char *name;
750 		int (*get_panel_type)(struct intel_display *display,
751 				      const struct intel_bios_encoder_data *devdata,
752 				      const struct drm_edid *drm_edid, bool use_fallback);
753 		int panel_type;
754 	} panel_types[] = {
755 		[PANEL_TYPE_OPREGION] = {
756 			.name = "OpRegion",
757 			.get_panel_type = opregion_get_panel_type,
758 		},
759 		[PANEL_TYPE_VBT] = {
760 			.name = "VBT",
761 			.get_panel_type = vbt_get_panel_type,
762 		},
763 		[PANEL_TYPE_PNPID] = {
764 			.name = "PNPID",
765 			.get_panel_type = pnpid_get_panel_type,
766 		},
767 		[PANEL_TYPE_FALLBACK] = {
768 			.name = "fallback",
769 			.get_panel_type = fallback_get_panel_type,
770 		},
771 	};
772 	int i;
773 
774 	for (i = 0; i < ARRAY_SIZE(panel_types); i++) {
775 		panel_types[i].panel_type = panel_types[i].get_panel_type(display, devdata,
776 									  drm_edid, use_fallback);
777 
778 		drm_WARN_ON(display->drm, panel_types[i].panel_type > 0xf &&
779 			    panel_types[i].panel_type != 0xff);
780 
781 		if (panel_types[i].panel_type >= 0)
782 			drm_dbg_kms(display->drm, "Panel type (%s): %d\n",
783 				    panel_types[i].name, panel_types[i].panel_type);
784 	}
785 
786 	if (is_panel_type_valid(panel_types[PANEL_TYPE_OPREGION].panel_type))
787 		i = PANEL_TYPE_OPREGION;
788 	else if (is_panel_type_pnp(panel_types[PANEL_TYPE_VBT].panel_type) &&
789 		 is_panel_type_valid(panel_types[PANEL_TYPE_PNPID].panel_type))
790 		i = PANEL_TYPE_PNPID;
791 	else if (is_panel_type_valid(panel_types[PANEL_TYPE_VBT].panel_type))
792 		i = PANEL_TYPE_VBT;
793 	else
794 		i = PANEL_TYPE_FALLBACK;
795 
796 	drm_dbg_kms(display->drm, "Selected panel type (%s): %d\n",
797 		    panel_types[i].name, panel_types[i].panel_type);
798 
799 	return panel_types[i].panel_type;
800 }
801 
panel_bits(unsigned int value,int panel_type,int num_bits)802 static unsigned int panel_bits(unsigned int value, int panel_type, int num_bits)
803 {
804 	return (value >> (panel_type * num_bits)) & (BIT(num_bits) - 1);
805 }
806 
panel_bool(unsigned int value,int panel_type)807 static bool panel_bool(unsigned int value, int panel_type)
808 {
809 	return panel_bits(value, panel_type, 1);
810 }
811 
812 /* Parse general panel options */
813 static void
parse_panel_options(struct intel_display * display,struct intel_panel * panel)814 parse_panel_options(struct intel_display *display,
815 		    struct intel_panel *panel)
816 {
817 	const struct bdb_lfp_options *lfp_options;
818 	int panel_type = panel->vbt.panel_type;
819 	int drrs_mode;
820 
821 	lfp_options = bdb_find_section(display, BDB_LFP_OPTIONS);
822 	if (!lfp_options)
823 		return;
824 
825 	panel->vbt.lvds_dither = lfp_options->pixel_dither;
826 
827 	/*
828 	 * Empirical evidence indicates the block size can be
829 	 * either 4,14,16,24+ bytes. For older VBTs no clear
830 	 * relationship between the block size vs. BDB version.
831 	 */
832 	if (get_blocksize(lfp_options) < 16)
833 		return;
834 
835 	drrs_mode = panel_bits(lfp_options->dps_panel_type_bits,
836 			       panel_type, 2);
837 	/*
838 	 * VBT has static DRRS = 0 and seamless DRRS = 2.
839 	 * The below piece of code is required to adjust vbt.drrs_type
840 	 * to match the enum drrs_support_type.
841 	 */
842 	switch (drrs_mode) {
843 	case 0:
844 		panel->vbt.drrs_type = DRRS_TYPE_STATIC;
845 		drm_dbg_kms(display->drm, "DRRS supported mode is static\n");
846 		break;
847 	case 2:
848 		panel->vbt.drrs_type = DRRS_TYPE_SEAMLESS;
849 		drm_dbg_kms(display->drm,
850 			    "DRRS supported mode is seamless\n");
851 		break;
852 	default:
853 		panel->vbt.drrs_type = DRRS_TYPE_NONE;
854 		drm_dbg_kms(display->drm,
855 			    "DRRS not supported (VBT input)\n");
856 		break;
857 	}
858 }
859 
860 static void
parse_lfp_panel_dtd(struct intel_display * display,struct intel_panel * panel,const struct bdb_lfp_data * lfp_data,const struct bdb_lfp_data_ptrs * lfp_data_ptrs)861 parse_lfp_panel_dtd(struct intel_display *display,
862 		    struct intel_panel *panel,
863 		    const struct bdb_lfp_data *lfp_data,
864 		    const struct bdb_lfp_data_ptrs *lfp_data_ptrs)
865 {
866 	const struct bdb_edid_dtd *panel_dvo_timing;
867 	const struct fp_timing *fp_timing;
868 	struct drm_display_mode *panel_fixed_mode;
869 	int panel_type = panel->vbt.panel_type;
870 
871 	panel_dvo_timing = get_lfp_dvo_timing(lfp_data,
872 					      lfp_data_ptrs,
873 					      panel_type);
874 
875 	panel_fixed_mode = kzalloc_obj(*panel_fixed_mode);
876 	if (!panel_fixed_mode)
877 		return;
878 
879 	fill_detail_timing_data(display, panel_fixed_mode, panel_dvo_timing);
880 
881 	panel->vbt.lfp_vbt_mode = panel_fixed_mode;
882 
883 	drm_dbg_kms(display->drm,
884 		    "Found panel mode in BIOS VBT legacy lfp table: " DRM_MODE_FMT "\n",
885 		    DRM_MODE_ARG(panel_fixed_mode));
886 
887 	fp_timing = get_lfp_fp_timing(lfp_data,
888 				      lfp_data_ptrs,
889 				      panel_type);
890 
891 	/* check the resolution, just to be sure */
892 	if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
893 	    fp_timing->y_res == panel_fixed_mode->vdisplay) {
894 		panel->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
895 		drm_dbg_kms(display->drm,
896 			    "VBT initial LVDS value %x\n",
897 			    panel->vbt.bios_lvds_val);
898 	}
899 }
900 
901 static void
parse_lfp_data(struct intel_display * display,struct intel_panel * panel)902 parse_lfp_data(struct intel_display *display,
903 	       struct intel_panel *panel)
904 {
905 	const struct bdb_lfp_data *data;
906 	const struct bdb_lfp_data_tail *tail;
907 	const struct bdb_lfp_data_ptrs *ptrs;
908 	const struct drm_edid_product_id *pnp_id;
909 	struct drm_printer p;
910 	int panel_type = panel->vbt.panel_type;
911 
912 	ptrs = bdb_find_section(display, BDB_LFP_DATA_PTRS);
913 	if (!ptrs)
914 		return;
915 
916 	data = bdb_find_section(display, BDB_LFP_DATA);
917 	if (!data)
918 		return;
919 
920 	if (!panel->vbt.lfp_vbt_mode)
921 		parse_lfp_panel_dtd(display, panel, data, ptrs);
922 
923 	pnp_id = get_lfp_pnp_id(data, ptrs, panel_type);
924 
925 	p = drm_dbg_printer(display->drm, DRM_UT_KMS, "Panel");
926 	drm_edid_print_product_id(&p, pnp_id, false);
927 
928 	tail = get_lfp_data_tail(data, ptrs);
929 	if (!tail)
930 		return;
931 
932 	drm_dbg_kms(display->drm, "Panel name: %.*s\n",
933 		    (int)sizeof(tail->panel_name[0].name),
934 		    tail->panel_name[panel_type].name);
935 
936 	if (display->vbt.version >= 188) {
937 		panel->vbt.seamless_drrs_min_refresh_rate =
938 			tail->seamless_drrs_min_refresh_rate[panel_type];
939 		drm_dbg_kms(display->drm,
940 			    "Seamless DRRS min refresh rate: %d Hz\n",
941 			    panel->vbt.seamless_drrs_min_refresh_rate);
942 	}
943 }
944 
945 static void
parse_generic_dtd(struct intel_display * display,struct intel_panel * panel)946 parse_generic_dtd(struct intel_display *display,
947 		  struct intel_panel *panel)
948 {
949 	const struct bdb_generic_dtd *generic_dtd;
950 	const struct generic_dtd_entry *dtd;
951 	struct drm_display_mode *panel_fixed_mode;
952 	int num_dtd;
953 
954 	/*
955 	 * Older VBTs provided DTD information for internal displays through
956 	 * the "LFP panel tables" block (42).  As of VBT revision 229 the
957 	 * DTD information should be provided via a newer "generic DTD"
958 	 * block (58).  Just to be safe, we'll try the new generic DTD block
959 	 * first on VBT >= 229, but still fall back to trying the old LFP
960 	 * block if that fails.
961 	 */
962 	if (display->vbt.version < 229)
963 		return;
964 
965 	generic_dtd = bdb_find_section(display, BDB_GENERIC_DTD);
966 	if (!generic_dtd)
967 		return;
968 
969 	if (generic_dtd->gdtd_size < sizeof(struct generic_dtd_entry)) {
970 		drm_err(display->drm, "GDTD size %u is too small.\n",
971 			generic_dtd->gdtd_size);
972 		return;
973 	} else if (generic_dtd->gdtd_size !=
974 		   sizeof(struct generic_dtd_entry)) {
975 		drm_err(display->drm, "Unexpected GDTD size %u\n",
976 			generic_dtd->gdtd_size);
977 		/* DTD has unknown fields, but keep going */
978 	}
979 
980 	num_dtd = (get_blocksize(generic_dtd) -
981 		   sizeof(struct bdb_generic_dtd)) / generic_dtd->gdtd_size;
982 	if (panel->vbt.panel_type >= num_dtd) {
983 		drm_err(display->drm,
984 			"Panel type %d not found in table of %d DTD's\n",
985 			panel->vbt.panel_type, num_dtd);
986 		return;
987 	}
988 
989 	dtd = &generic_dtd->dtd[panel->vbt.panel_type];
990 
991 	panel_fixed_mode = kzalloc_obj(*panel_fixed_mode);
992 	if (!panel_fixed_mode)
993 		return;
994 
995 	panel_fixed_mode->hdisplay = dtd->hactive;
996 	panel_fixed_mode->hsync_start =
997 		panel_fixed_mode->hdisplay + dtd->hfront_porch;
998 	panel_fixed_mode->hsync_end =
999 		panel_fixed_mode->hsync_start + dtd->hsync;
1000 	panel_fixed_mode->htotal =
1001 		panel_fixed_mode->hdisplay + dtd->hblank;
1002 
1003 	panel_fixed_mode->vdisplay = dtd->vactive;
1004 	panel_fixed_mode->vsync_start =
1005 		panel_fixed_mode->vdisplay + dtd->vfront_porch;
1006 	panel_fixed_mode->vsync_end =
1007 		panel_fixed_mode->vsync_start + dtd->vsync;
1008 	panel_fixed_mode->vtotal =
1009 		panel_fixed_mode->vdisplay + dtd->vblank;
1010 
1011 	panel_fixed_mode->clock = dtd->pixel_clock;
1012 	panel_fixed_mode->width_mm = dtd->width_mm;
1013 	panel_fixed_mode->height_mm = dtd->height_mm;
1014 
1015 	panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
1016 	drm_mode_set_name(panel_fixed_mode);
1017 
1018 	if (dtd->hsync_positive_polarity)
1019 		panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
1020 	else
1021 		panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
1022 
1023 	if (dtd->vsync_positive_polarity)
1024 		panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
1025 	else
1026 		panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
1027 
1028 	drm_dbg_kms(display->drm,
1029 		    "Found panel mode in BIOS VBT generic dtd table: " DRM_MODE_FMT "\n",
1030 		    DRM_MODE_ARG(panel_fixed_mode));
1031 
1032 	panel->vbt.lfp_vbt_mode = panel_fixed_mode;
1033 }
1034 
1035 static void
parse_lfp_backlight(struct intel_display * display,struct intel_panel * panel)1036 parse_lfp_backlight(struct intel_display *display,
1037 		    struct intel_panel *panel)
1038 {
1039 	const struct bdb_lfp_backlight *backlight_data;
1040 	const struct lfp_backlight_data_entry *entry;
1041 	int panel_type = panel->vbt.panel_type;
1042 	u16 level;
1043 
1044 	backlight_data = bdb_find_section(display, BDB_LFP_BACKLIGHT);
1045 	if (!backlight_data)
1046 		return;
1047 
1048 	if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
1049 		drm_dbg_kms(display->drm,
1050 			    "Unsupported backlight data entry size %u\n",
1051 			    backlight_data->entry_size);
1052 		return;
1053 	}
1054 
1055 	entry = &backlight_data->data[panel_type];
1056 
1057 	panel->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
1058 	if (!panel->vbt.backlight.present) {
1059 		drm_dbg_kms(display->drm,
1060 			    "PWM backlight not present in VBT (type %u)\n",
1061 			    entry->type);
1062 		return;
1063 	}
1064 
1065 	panel->vbt.backlight.type = INTEL_BACKLIGHT_DISPLAY_DDI;
1066 	panel->vbt.backlight.controller = 0;
1067 	if (display->vbt.version >= 191) {
1068 		const struct lfp_backlight_control_method *method;
1069 
1070 		method = &backlight_data->backlight_control[panel_type];
1071 		panel->vbt.backlight.type = method->type;
1072 		panel->vbt.backlight.controller = method->controller;
1073 	}
1074 
1075 	panel->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
1076 	panel->vbt.backlight.active_low_pwm = entry->active_low_pwm;
1077 
1078 	if (display->vbt.version >= 234) {
1079 		u16 min_level;
1080 		bool scale;
1081 
1082 		level = backlight_data->brightness_level[panel_type].level;
1083 		min_level = backlight_data->brightness_min_level[panel_type].level;
1084 
1085 		if (display->vbt.version >= 236)
1086 			scale = backlight_data->brightness_precision_bits[panel_type] == 16;
1087 		else
1088 			scale = level > 255;
1089 
1090 		if (scale)
1091 			min_level = min_level / 255;
1092 
1093 		if (min_level > 255) {
1094 			drm_warn(display->drm, "Brightness min level > 255\n");
1095 			level = 255;
1096 		}
1097 		panel->vbt.backlight.min_brightness = min_level;
1098 
1099 		panel->vbt.backlight.brightness_precision_bits =
1100 			backlight_data->brightness_precision_bits[panel_type];
1101 	} else {
1102 		level = backlight_data->level[panel_type];
1103 		panel->vbt.backlight.min_brightness = entry->min_brightness;
1104 	}
1105 
1106 	if (display->vbt.version >= 239)
1107 		panel->vbt.backlight.hdr_dpcd_refresh_timeout =
1108 			DIV_ROUND_UP(backlight_data->hdr_dpcd_refresh_timeout[panel_type], 100);
1109 	else
1110 		panel->vbt.backlight.hdr_dpcd_refresh_timeout = 30;
1111 
1112 	drm_dbg_kms(display->drm,
1113 		    "VBT backlight PWM modulation frequency %u Hz, "
1114 		    "active %s, min brightness %u, level %u, controller %u\n",
1115 		    panel->vbt.backlight.pwm_freq_hz,
1116 		    panel->vbt.backlight.active_low_pwm ? "low" : "high",
1117 		    panel->vbt.backlight.min_brightness,
1118 		    level,
1119 		    panel->vbt.backlight.controller);
1120 }
1121 
1122 static void
parse_sdvo_lvds_data(struct intel_display * display,struct intel_panel * panel)1123 parse_sdvo_lvds_data(struct intel_display *display,
1124 		     struct intel_panel *panel)
1125 {
1126 	const struct bdb_sdvo_lvds_dtd *dtd;
1127 	struct drm_display_mode *panel_fixed_mode;
1128 	int index;
1129 
1130 	index = display->params.vbt_sdvo_panel_type;
1131 	if (index == -2) {
1132 		drm_dbg_kms(display->drm,
1133 			    "Ignore SDVO LVDS mode from BIOS VBT tables.\n");
1134 		return;
1135 	}
1136 
1137 	if (index == -1) {
1138 		const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
1139 
1140 		sdvo_lvds_options = bdb_find_section(display, BDB_SDVO_LVDS_OPTIONS);
1141 		if (!sdvo_lvds_options)
1142 			return;
1143 
1144 		index = sdvo_lvds_options->panel_type;
1145 	}
1146 
1147 	dtd = bdb_find_section(display, BDB_SDVO_LVDS_DTD);
1148 	if (!dtd)
1149 		return;
1150 
1151 	/*
1152 	 * This should not happen, as long as the panel_type
1153 	 * enumeration doesn't grow over 4 items.  But if it does, it
1154 	 * could lead to hard-to-detect bugs, so better double-check
1155 	 * it here to be sure.
1156 	 */
1157 	if (index >= ARRAY_SIZE(dtd->dtd)) {
1158 		drm_err(display->drm,
1159 			"index %d is larger than dtd->dtd[4] array\n",
1160 			index);
1161 		return;
1162 	}
1163 
1164 	panel_fixed_mode = kzalloc_obj(*panel_fixed_mode);
1165 	if (!panel_fixed_mode)
1166 		return;
1167 
1168 	fill_detail_timing_data(display, panel_fixed_mode, &dtd->dtd[index]);
1169 
1170 	panel->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
1171 
1172 	drm_dbg_kms(display->drm,
1173 		    "Found SDVO LVDS mode in BIOS VBT tables: " DRM_MODE_FMT "\n",
1174 		    DRM_MODE_ARG(panel_fixed_mode));
1175 }
1176 
intel_bios_ssc_frequency(struct intel_display * display,bool alternate)1177 static int intel_bios_ssc_frequency(struct intel_display *display,
1178 				    bool alternate)
1179 {
1180 	switch (DISPLAY_VER(display)) {
1181 	case 2:
1182 		return alternate ? 66667 : 48000;
1183 	case 3:
1184 	case 4:
1185 		return alternate ? 100000 : 96000;
1186 	default:
1187 		return alternate ? 100000 : 120000;
1188 	}
1189 }
1190 
1191 static void
parse_general_features(struct intel_display * display)1192 parse_general_features(struct intel_display *display)
1193 {
1194 	const struct bdb_general_features *general;
1195 
1196 	general = bdb_find_section(display, BDB_GENERAL_FEATURES);
1197 	if (!general)
1198 		return;
1199 
1200 	display->vbt.int_tv_support = general->int_tv_support;
1201 	/* int_crt_support can't be trusted on earlier platforms */
1202 	if (display->vbt.version >= 155 &&
1203 	    (HAS_DDI(display) || display->platform.valleyview))
1204 		display->vbt.int_crt_support = general->int_crt_support;
1205 	display->vbt.lvds_use_ssc = general->enable_ssc;
1206 	display->vbt.lvds_ssc_freq =
1207 		intel_bios_ssc_frequency(display, general->ssc_freq);
1208 	display->vbt.display_clock_mode = general->display_clock_mode;
1209 	display->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
1210 	if (display->vbt.version >= 181) {
1211 		display->vbt.orientation = general->rotate_180 ?
1212 			DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP :
1213 			DRM_MODE_PANEL_ORIENTATION_NORMAL;
1214 	} else {
1215 		display->vbt.orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
1216 	}
1217 
1218 	if (display->vbt.version >= 249 && general->afc_startup_config) {
1219 		display->vbt.override_afc_startup = true;
1220 		display->vbt.override_afc_startup_val = general->afc_startup_config == 1 ? 0 : 7;
1221 	}
1222 
1223 	drm_dbg_kms(display->drm,
1224 		    "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",
1225 		    display->vbt.int_tv_support,
1226 		    display->vbt.int_crt_support,
1227 		    display->vbt.lvds_use_ssc,
1228 		    display->vbt.lvds_ssc_freq,
1229 		    display->vbt.display_clock_mode,
1230 		    display->vbt.fdi_rx_polarity_inverted);
1231 }
1232 
1233 static const struct child_device_config *
child_device_ptr(const struct bdb_general_definitions * defs,int i)1234 child_device_ptr(const struct bdb_general_definitions *defs, int i)
1235 {
1236 	return (const void *) &defs->devices[i * defs->child_dev_size];
1237 }
1238 
1239 static void
parse_sdvo_device_mapping(struct intel_display * display)1240 parse_sdvo_device_mapping(struct intel_display *display)
1241 {
1242 	const struct intel_bios_encoder_data *devdata;
1243 	int count = 0;
1244 
1245 	/*
1246 	 * Only parse SDVO mappings on gens that could have SDVO. This isn't
1247 	 * accurate and doesn't have to be, as long as it's not too strict.
1248 	 */
1249 	if (!IS_DISPLAY_VER(display, 3, 7)) {
1250 		drm_dbg_kms(display->drm, "Skipping SDVO device mapping\n");
1251 		return;
1252 	}
1253 
1254 	list_for_each_entry(devdata, &display->vbt.display_devices, node) {
1255 		const struct child_device_config *child = &devdata->child;
1256 		struct sdvo_device_mapping *mapping;
1257 
1258 		if (child->target_addr != TARGET_ADDR1 &&
1259 		    child->target_addr != TARGET_ADDR2) {
1260 			/*
1261 			 * If the target address is neither 0x70 nor 0x72,
1262 			 * it is not a SDVO device. Skip it.
1263 			 */
1264 			continue;
1265 		}
1266 		if (child->dvo_port != DEVICE_PORT_DVOB &&
1267 		    child->dvo_port != DEVICE_PORT_DVOC) {
1268 			/* skip the incorrect SDVO port */
1269 			drm_dbg_kms(display->drm,
1270 				    "Incorrect SDVO port. Skip it\n");
1271 			continue;
1272 		}
1273 		drm_dbg_kms(display->drm,
1274 			    "the SDVO device with target addr %2x is found on"
1275 			    " %s port\n",
1276 			    child->target_addr,
1277 			    (child->dvo_port == DEVICE_PORT_DVOB) ?
1278 			    "SDVOB" : "SDVOC");
1279 		mapping = &display->vbt.sdvo_mappings[child->dvo_port - 1];
1280 		if (!mapping->initialized) {
1281 			mapping->dvo_port = child->dvo_port;
1282 			mapping->target_addr = child->target_addr;
1283 			mapping->dvo_wiring = child->dvo_wiring;
1284 			mapping->ddc_pin = child->ddc_pin;
1285 			mapping->i2c_pin = child->i2c_pin;
1286 			mapping->initialized = 1;
1287 			drm_dbg_kms(display->drm,
1288 				    "SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
1289 				    mapping->dvo_port, mapping->target_addr,
1290 				    mapping->dvo_wiring, mapping->ddc_pin,
1291 				    mapping->i2c_pin);
1292 		} else {
1293 			drm_dbg_kms(display->drm,
1294 				    "Maybe one SDVO port is shared by "
1295 				    "two SDVO device.\n");
1296 		}
1297 		if (child->target2_addr) {
1298 			/* Maybe this is a SDVO device with multiple inputs */
1299 			/* And the mapping info is not added */
1300 			drm_dbg_kms(display->drm,
1301 				    "there exists the target2_addr. Maybe this"
1302 				    " is a SDVO device with multiple inputs.\n");
1303 		}
1304 		count++;
1305 	}
1306 
1307 	if (!count) {
1308 		/* No SDVO device info is found */
1309 		drm_dbg_kms(display->drm,
1310 			    "No SDVO device info is found in VBT\n");
1311 	}
1312 }
1313 
1314 static void
parse_driver_features(struct intel_display * display)1315 parse_driver_features(struct intel_display *display)
1316 {
1317 	const struct bdb_driver_features *driver;
1318 
1319 	driver = bdb_find_section(display, BDB_DRIVER_FEATURES);
1320 	if (!driver)
1321 		return;
1322 
1323 	if (DISPLAY_VER(display) >= 5) {
1324 		/*
1325 		 * Note that we consider BDB_DRIVER_FEATURE_INT_SDVO_LVDS
1326 		 * to mean "eDP". The VBT spec doesn't agree with that
1327 		 * interpretation, but real world VBTs seem to.
1328 		 */
1329 		if (driver->lvds_config != BDB_DRIVER_FEATURE_INT_LVDS)
1330 			display->vbt.int_lvds_support = 0;
1331 	} else {
1332 		/*
1333 		 * FIXME it's not clear which BDB version has the LVDS config
1334 		 * bits defined. Revision history in the VBT spec says:
1335 		 * "0.92 | Add two definitions for VBT value of LVDS Active
1336 		 *  Config (00b and 11b values defined) | 06/13/2005"
1337 		 * but does not the specify the BDB version.
1338 		 *
1339 		 * So far version 134 (on i945gm) is the oldest VBT observed
1340 		 * in the wild with the bits correctly populated. Version
1341 		 * 108 (on i85x) does not have the bits correctly populated.
1342 		 */
1343 		if (display->vbt.version >= 134 &&
1344 		    driver->lvds_config != BDB_DRIVER_FEATURE_INT_LVDS &&
1345 		    driver->lvds_config != BDB_DRIVER_FEATURE_INT_SDVO_LVDS)
1346 			display->vbt.int_lvds_support = 0;
1347 	}
1348 }
1349 
1350 static void
parse_panel_driver_features(struct intel_display * display,struct intel_panel * panel)1351 parse_panel_driver_features(struct intel_display *display,
1352 			    struct intel_panel *panel)
1353 {
1354 	const struct bdb_driver_features *driver;
1355 
1356 	driver = bdb_find_section(display, BDB_DRIVER_FEATURES);
1357 	if (!driver)
1358 		return;
1359 
1360 	if (display->vbt.version < 228) {
1361 		drm_dbg_kms(display->drm, "DRRS State Enabled:%d\n",
1362 			    driver->drrs_enabled);
1363 		/*
1364 		 * If DRRS is not supported, drrs_type has to be set to 0.
1365 		 * This is because, VBT is configured in such a way that
1366 		 * static DRRS is 0 and DRRS not supported is represented by
1367 		 * driver->drrs_enabled=false
1368 		 */
1369 		if (!driver->drrs_enabled && panel->vbt.drrs_type != DRRS_TYPE_NONE) {
1370 			/*
1371 			 * FIXME Should DMRRS perhaps be treated as seamless
1372 			 * but without the automatic downclocking?
1373 			 */
1374 			if (driver->dmrrs_enabled)
1375 				panel->vbt.drrs_type = DRRS_TYPE_STATIC;
1376 			else
1377 				panel->vbt.drrs_type = DRRS_TYPE_NONE;
1378 		}
1379 
1380 		panel->vbt.psr.enable = driver->psr_enabled;
1381 	}
1382 }
1383 
1384 static void
parse_power_conservation_features(struct intel_display * display,struct intel_panel * panel)1385 parse_power_conservation_features(struct intel_display *display,
1386 				  struct intel_panel *panel)
1387 {
1388 	const struct bdb_lfp_power *power;
1389 	u8 panel_type = panel->vbt.panel_type;
1390 
1391 	panel->vbt.vrr = true; /* matches Windows behaviour */
1392 
1393 	if (display->vbt.version < 228)
1394 		return;
1395 
1396 	power = bdb_find_section(display, BDB_LFP_POWER);
1397 	if (!power)
1398 		return;
1399 
1400 	panel->vbt.psr.enable = panel_bool(power->psr, panel_type);
1401 
1402 	/*
1403 	 * If DRRS is not supported, drrs_type has to be set to 0.
1404 	 * This is because, VBT is configured in such a way that
1405 	 * static DRRS is 0 and DRRS not supported is represented by
1406 	 * power->drrs & BIT(panel_type)=false
1407 	 */
1408 	if (!panel_bool(power->drrs, panel_type) && panel->vbt.drrs_type != DRRS_TYPE_NONE) {
1409 		/*
1410 		 * FIXME Should DMRRS perhaps be treated as seamless
1411 		 * but without the automatic downclocking?
1412 		 */
1413 		if (panel_bool(power->dmrrs, panel_type))
1414 			panel->vbt.drrs_type = DRRS_TYPE_STATIC;
1415 		else
1416 			panel->vbt.drrs_type = DRRS_TYPE_NONE;
1417 	}
1418 
1419 	if (display->vbt.version >= 232)
1420 		panel->vbt.edp.hobl = panel_bool(power->hobl, panel_type);
1421 
1422 	if (display->vbt.version >= 233)
1423 		panel->vbt.vrr = panel_bool(power->vrr_feature_enabled,
1424 					    panel_type);
1425 }
1426 
vbt_edp_to_pps_delays(struct intel_pps_delays * pps,const struct edp_power_seq * edp_pps)1427 static void vbt_edp_to_pps_delays(struct intel_pps_delays *pps,
1428 				  const struct edp_power_seq *edp_pps)
1429 {
1430 	pps->power_up = edp_pps->t1_t3;
1431 	pps->backlight_on = edp_pps->t8;
1432 	pps->backlight_off = edp_pps->t9;
1433 	pps->power_down = edp_pps->t10;
1434 	pps->power_cycle = edp_pps->t11_t12;
1435 }
1436 
1437 static void
parse_edp(struct intel_display * display,struct intel_panel * panel)1438 parse_edp(struct intel_display *display,
1439 	  struct intel_panel *panel)
1440 {
1441 	const struct bdb_edp *edp;
1442 	const struct edp_fast_link_params *edp_link_params;
1443 	int panel_type = panel->vbt.panel_type;
1444 
1445 	edp = bdb_find_section(display, BDB_EDP);
1446 	if (!edp)
1447 		return;
1448 
1449 	switch (panel_bits(edp->color_depth, panel_type, 2)) {
1450 	case EDP_18BPP:
1451 		panel->vbt.edp.bpp = 18;
1452 		break;
1453 	case EDP_24BPP:
1454 		panel->vbt.edp.bpp = 24;
1455 		break;
1456 	case EDP_30BPP:
1457 		panel->vbt.edp.bpp = 30;
1458 		break;
1459 	}
1460 
1461 	/* Get the eDP sequencing and link info */
1462 	edp_link_params = &edp->fast_link_params[panel_type];
1463 
1464 	vbt_edp_to_pps_delays(&panel->vbt.edp.pps,
1465 			      &edp->power_seqs[panel_type]);
1466 
1467 	if (display->vbt.version >= 224) {
1468 		panel->vbt.edp.rate =
1469 			edp->edp_fast_link_training_rate[panel_type] * 20;
1470 	} else {
1471 		switch (edp_link_params->rate) {
1472 		case EDP_RATE_1_62:
1473 			panel->vbt.edp.rate = 162000;
1474 			break;
1475 		case EDP_RATE_2_7:
1476 			panel->vbt.edp.rate = 270000;
1477 			break;
1478 		case EDP_RATE_5_4:
1479 			panel->vbt.edp.rate = 540000;
1480 			break;
1481 		default:
1482 			drm_dbg_kms(display->drm,
1483 				    "VBT has unknown eDP link rate value %u\n",
1484 				    edp_link_params->rate);
1485 			break;
1486 		}
1487 	}
1488 
1489 	switch (edp_link_params->lanes) {
1490 	case EDP_LANE_1:
1491 		panel->vbt.edp.lanes = 1;
1492 		break;
1493 	case EDP_LANE_2:
1494 		panel->vbt.edp.lanes = 2;
1495 		break;
1496 	case EDP_LANE_4:
1497 		panel->vbt.edp.lanes = 4;
1498 		break;
1499 	default:
1500 		drm_dbg_kms(display->drm,
1501 			    "VBT has unknown eDP lane count value %u\n",
1502 			    edp_link_params->lanes);
1503 		break;
1504 	}
1505 
1506 	switch (edp_link_params->preemphasis) {
1507 	case EDP_PREEMPHASIS_NONE:
1508 		panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
1509 		break;
1510 	case EDP_PREEMPHASIS_3_5dB:
1511 		panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
1512 		break;
1513 	case EDP_PREEMPHASIS_6dB:
1514 		panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
1515 		break;
1516 	case EDP_PREEMPHASIS_9_5dB:
1517 		panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
1518 		break;
1519 	default:
1520 		drm_dbg_kms(display->drm,
1521 			    "VBT has unknown eDP pre-emphasis value %u\n",
1522 			    edp_link_params->preemphasis);
1523 		break;
1524 	}
1525 
1526 	switch (edp_link_params->vswing) {
1527 	case EDP_VSWING_0_4V:
1528 		panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
1529 		break;
1530 	case EDP_VSWING_0_6V:
1531 		panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
1532 		break;
1533 	case EDP_VSWING_0_8V:
1534 		panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
1535 		break;
1536 	case EDP_VSWING_1_2V:
1537 		panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
1538 		break;
1539 	default:
1540 		drm_dbg_kms(display->drm,
1541 			    "VBT has unknown eDP voltage swing value %u\n",
1542 			    edp_link_params->vswing);
1543 		break;
1544 	}
1545 
1546 	if (display->vbt.version >= 173) {
1547 		u8 vswing;
1548 
1549 		/* Don't read from VBT if module parameter has valid value*/
1550 		if (display->params.edp_vswing) {
1551 			panel->vbt.edp.low_vswing =
1552 				display->params.edp_vswing == 1;
1553 		} else {
1554 			vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
1555 			panel->vbt.edp.low_vswing = vswing == 0;
1556 		}
1557 	}
1558 
1559 	panel->vbt.edp.drrs_msa_timing_delay =
1560 		panel_bits(edp->sdrrs_msa_timing_delay, panel_type, 2);
1561 
1562 	if (display->vbt.version >= 244)
1563 		panel->vbt.edp.max_link_rate =
1564 			edp->edp_max_port_link_rate[panel_type] * 20;
1565 
1566 	if (display->vbt.version >= 251)
1567 		panel->vbt.edp.dsc_disable =
1568 			panel_bool(edp->edp_dsc_disable, panel_type);
1569 
1570 	if (display->vbt.version >= 261)
1571 		panel->vbt.edp.pipe_joiner_enable =
1572 			panel_bool(edp->pipe_joiner_enable, panel_type);
1573 }
1574 
1575 static void
parse_psr(struct intel_display * display,struct intel_panel * panel)1576 parse_psr(struct intel_display *display,
1577 	  struct intel_panel *panel)
1578 {
1579 	const struct bdb_psr *psr;
1580 	const struct psr_table *psr_table;
1581 	int panel_type = panel->vbt.panel_type;
1582 
1583 	psr = bdb_find_section(display, BDB_PSR);
1584 	if (!psr) {
1585 		drm_dbg_kms(display->drm, "No PSR BDB found.\n");
1586 		return;
1587 	}
1588 
1589 	psr_table = &psr->psr_table[panel_type];
1590 
1591 	panel->vbt.psr.full_link = psr_table->full_link;
1592 	panel->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
1593 	panel->vbt.psr.idle_frames = psr_table->idle_frames;
1594 
1595 	/*
1596 	 * New psr options 0=500us, 1=100us, 2=2500us, 3=0us
1597 	 * Old decimal value is wake up time in multiples of 100 us.
1598 	 */
1599 	if (display->vbt.version >= 205 &&
1600 	    (DISPLAY_VER(display) >= 9 && !display->platform.broxton)) {
1601 		switch (psr_table->tp1_wakeup_time) {
1602 		case 0:
1603 			panel->vbt.psr.tp1_wakeup_time_us = 500;
1604 			break;
1605 		case 1:
1606 			panel->vbt.psr.tp1_wakeup_time_us = 100;
1607 			break;
1608 		case 3:
1609 			panel->vbt.psr.tp1_wakeup_time_us = 0;
1610 			break;
1611 		default:
1612 			drm_dbg_kms(display->drm,
1613 				    "VBT tp1 wakeup time value %d is outside range[0-3], defaulting to max value 2500us\n",
1614 				    psr_table->tp1_wakeup_time);
1615 			fallthrough;
1616 		case 2:
1617 			panel->vbt.psr.tp1_wakeup_time_us = 2500;
1618 			break;
1619 		}
1620 
1621 		switch (psr_table->tp2_tp3_wakeup_time) {
1622 		case 0:
1623 			panel->vbt.psr.tp2_tp3_wakeup_time_us = 500;
1624 			break;
1625 		case 1:
1626 			panel->vbt.psr.tp2_tp3_wakeup_time_us = 100;
1627 			break;
1628 		case 3:
1629 			panel->vbt.psr.tp2_tp3_wakeup_time_us = 0;
1630 			break;
1631 		default:
1632 			drm_dbg_kms(display->drm,
1633 				    "VBT tp2_tp3 wakeup time value %d is outside range[0-3], defaulting to max value 2500us\n",
1634 				    psr_table->tp2_tp3_wakeup_time);
1635 			fallthrough;
1636 		case 2:
1637 			panel->vbt.psr.tp2_tp3_wakeup_time_us = 2500;
1638 		break;
1639 		}
1640 	} else {
1641 		panel->vbt.psr.tp1_wakeup_time_us = psr_table->tp1_wakeup_time * 100;
1642 		panel->vbt.psr.tp2_tp3_wakeup_time_us = psr_table->tp2_tp3_wakeup_time * 100;
1643 	}
1644 
1645 	if (display->vbt.version >= 226) {
1646 		u32 wakeup_time = psr->psr2_tp2_tp3_wakeup_time;
1647 
1648 		wakeup_time = panel_bits(wakeup_time, panel_type, 2);
1649 		switch (wakeup_time) {
1650 		case 0:
1651 			wakeup_time = 500;
1652 			break;
1653 		case 1:
1654 			wakeup_time = 100;
1655 			break;
1656 		case 3:
1657 			wakeup_time = 50;
1658 			break;
1659 		default:
1660 		case 2:
1661 			wakeup_time = 2500;
1662 			break;
1663 		}
1664 		panel->vbt.psr.psr2_tp2_tp3_wakeup_time_us = wakeup_time;
1665 	} else {
1666 		/* Reusing PSR1 wakeup time for PSR2 in older VBTs */
1667 		panel->vbt.psr.psr2_tp2_tp3_wakeup_time_us = panel->vbt.psr.tp2_tp3_wakeup_time_us;
1668 	}
1669 }
1670 
parse_dsi_backlight_ports(struct intel_display * display,struct intel_panel * panel,enum port port)1671 static void parse_dsi_backlight_ports(struct intel_display *display,
1672 				      struct intel_panel *panel,
1673 				      enum port port)
1674 {
1675 	enum port port_bc = DISPLAY_VER(display) >= 11 ? PORT_B : PORT_C;
1676 
1677 	if (!panel->vbt.dsi.config->dual_link || display->vbt.version < 197) {
1678 		panel->vbt.dsi.bl_ports = BIT(port);
1679 		if (panel->vbt.dsi.config->cabc_supported)
1680 			panel->vbt.dsi.cabc_ports = BIT(port);
1681 
1682 		return;
1683 	}
1684 
1685 	switch (panel->vbt.dsi.config->dl_dcs_backlight_ports) {
1686 	case DL_DCS_PORT_A:
1687 		panel->vbt.dsi.bl_ports = BIT(PORT_A);
1688 		break;
1689 	case DL_DCS_PORT_C:
1690 		panel->vbt.dsi.bl_ports = BIT(port_bc);
1691 		break;
1692 	default:
1693 	case DL_DCS_PORT_A_AND_C:
1694 		panel->vbt.dsi.bl_ports = BIT(PORT_A) | BIT(port_bc);
1695 		break;
1696 	}
1697 
1698 	if (!panel->vbt.dsi.config->cabc_supported)
1699 		return;
1700 
1701 	switch (panel->vbt.dsi.config->dl_dcs_cabc_ports) {
1702 	case DL_DCS_PORT_A:
1703 		panel->vbt.dsi.cabc_ports = BIT(PORT_A);
1704 		break;
1705 	case DL_DCS_PORT_C:
1706 		panel->vbt.dsi.cabc_ports = BIT(port_bc);
1707 		break;
1708 	default:
1709 	case DL_DCS_PORT_A_AND_C:
1710 		panel->vbt.dsi.cabc_ports =
1711 					BIT(PORT_A) | BIT(port_bc);
1712 		break;
1713 	}
1714 }
1715 
1716 static void
parse_mipi_config(struct intel_display * display,struct intel_panel * panel)1717 parse_mipi_config(struct intel_display *display,
1718 		  struct intel_panel *panel)
1719 {
1720 	const struct bdb_mipi_config *start;
1721 	const struct mipi_config *config;
1722 	const struct mipi_pps_data *pps;
1723 	int panel_type = panel->vbt.panel_type;
1724 	enum port port;
1725 
1726 	/* parse MIPI blocks only if LFP type is MIPI */
1727 	if (!intel_bios_is_dsi_present(display, &port))
1728 		return;
1729 
1730 	/* Initialize this to undefined indicating no generic MIPI support */
1731 	panel->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
1732 
1733 	start = bdb_find_section(display, BDB_MIPI_CONFIG);
1734 	if (!start) {
1735 		drm_dbg_kms(display->drm, "No MIPI config BDB found");
1736 		return;
1737 	}
1738 
1739 	drm_dbg_kms(display->drm, "Found MIPI Config block, panel index = %d\n",
1740 		    panel_type);
1741 
1742 	/*
1743 	 * get hold of the correct configuration block and pps data as per
1744 	 * the panel_type as index
1745 	 */
1746 	config = &start->config[panel_type];
1747 	pps = &start->pps[panel_type];
1748 
1749 	/* store as of now full data. Trim when we realise all is not needed */
1750 	panel->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
1751 	if (!panel->vbt.dsi.config)
1752 		return;
1753 
1754 	panel->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
1755 	if (!panel->vbt.dsi.pps) {
1756 		kfree(panel->vbt.dsi.config);
1757 		return;
1758 	}
1759 
1760 	parse_dsi_backlight_ports(display, panel, port);
1761 
1762 	/* FIXME is the 90 vs. 270 correct? */
1763 	switch (config->rotation) {
1764 	case ENABLE_ROTATION_0:
1765 		/*
1766 		 * Most (all?) VBTs claim 0 degrees despite having
1767 		 * an upside down panel, thus we do not trust this.
1768 		 */
1769 		panel->vbt.dsi.orientation =
1770 			DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
1771 		break;
1772 	case ENABLE_ROTATION_90:
1773 		panel->vbt.dsi.orientation =
1774 			DRM_MODE_PANEL_ORIENTATION_RIGHT_UP;
1775 		break;
1776 	case ENABLE_ROTATION_180:
1777 		panel->vbt.dsi.orientation =
1778 			DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP;
1779 		break;
1780 	case ENABLE_ROTATION_270:
1781 		panel->vbt.dsi.orientation =
1782 			DRM_MODE_PANEL_ORIENTATION_LEFT_UP;
1783 		break;
1784 	}
1785 
1786 	/* We have mandatory mipi config blocks. Initialize as generic panel */
1787 	panel->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
1788 }
1789 
1790 /* Find the sequence block and size for the given panel. */
1791 static const u8 *
find_panel_sequence_block(struct intel_display * display,const struct bdb_mipi_sequence * sequence,u16 panel_id,u32 * seq_size)1792 find_panel_sequence_block(struct intel_display *display,
1793 			  const struct bdb_mipi_sequence *sequence,
1794 			  u16 panel_id, u32 *seq_size)
1795 {
1796 	u32 total = get_blocksize(sequence);
1797 	const u8 *data = &sequence->data[0];
1798 	u8 current_id;
1799 	u32 current_size;
1800 	int header_size = sequence->version >= 3 ? 5 : 3;
1801 	int index = 0;
1802 	int i;
1803 
1804 	/* skip new block size */
1805 	if (sequence->version >= 3)
1806 		data += 4;
1807 
1808 	for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index < total; i++) {
1809 		if (index + header_size > total) {
1810 			drm_err(display->drm,
1811 				"Invalid sequence block (header)\n");
1812 			return NULL;
1813 		}
1814 
1815 		current_id = *(data + index);
1816 		if (sequence->version >= 3)
1817 			current_size = *((const u32 *)(data + index + 1));
1818 		else
1819 			current_size = *((const u16 *)(data + index + 1));
1820 
1821 		index += header_size;
1822 
1823 		if (index + current_size > total) {
1824 			drm_err(display->drm, "Invalid sequence block\n");
1825 			return NULL;
1826 		}
1827 
1828 		if (current_id == panel_id) {
1829 			*seq_size = current_size;
1830 			return data + index;
1831 		}
1832 
1833 		index += current_size;
1834 	}
1835 
1836 	drm_err(display->drm,
1837 		"Sequence block detected but no valid configuration\n");
1838 
1839 	return NULL;
1840 }
1841 
goto_next_sequence(struct intel_display * display,const u8 * data,int index,int total)1842 static int goto_next_sequence(struct intel_display *display,
1843 			      const u8 *data, int index, int total)
1844 {
1845 	u16 len;
1846 
1847 	/* Skip Sequence Byte. */
1848 	for (index = index + 1; index < total; index += len) {
1849 		u8 operation_byte = *(data + index);
1850 		index++;
1851 
1852 		switch (operation_byte) {
1853 		case MIPI_SEQ_ELEM_END:
1854 			return index;
1855 		case MIPI_SEQ_ELEM_SEND_PKT:
1856 			if (index + 4 > total)
1857 				return 0;
1858 
1859 			len = *((const u16 *)(data + index + 2)) + 4;
1860 			break;
1861 		case MIPI_SEQ_ELEM_DELAY:
1862 			len = 4;
1863 			break;
1864 		case MIPI_SEQ_ELEM_GPIO:
1865 			len = 2;
1866 			break;
1867 		case MIPI_SEQ_ELEM_I2C:
1868 			if (index + 7 > total)
1869 				return 0;
1870 			len = *(data + index + 6) + 7;
1871 			break;
1872 		default:
1873 			drm_err(display->drm, "Unknown operation byte\n");
1874 			return 0;
1875 		}
1876 	}
1877 
1878 	return 0;
1879 }
1880 
goto_next_sequence_v3(struct intel_display * display,const u8 * data,int index,int total)1881 static int goto_next_sequence_v3(struct intel_display *display,
1882 				 const u8 *data, int index, int total)
1883 {
1884 	int seq_end;
1885 	u16 len;
1886 	u32 size_of_sequence;
1887 
1888 	/*
1889 	 * Could skip sequence based on Size of Sequence alone, but also do some
1890 	 * checking on the structure.
1891 	 */
1892 	if (total < 5) {
1893 		drm_err(display->drm, "Too small sequence size\n");
1894 		return 0;
1895 	}
1896 
1897 	/* Skip Sequence Byte. */
1898 	index++;
1899 
1900 	/*
1901 	 * Size of Sequence. Excludes the Sequence Byte and the size itself,
1902 	 * includes MIPI_SEQ_ELEM_END byte, excludes the final MIPI_SEQ_END
1903 	 * byte.
1904 	 */
1905 	size_of_sequence = *((const u32 *)(data + index));
1906 	index += 4;
1907 
1908 	seq_end = index + size_of_sequence;
1909 	if (seq_end > total) {
1910 		drm_err(display->drm, "Invalid sequence size\n");
1911 		return 0;
1912 	}
1913 
1914 	for (; index < total; index += len) {
1915 		u8 operation_byte = *(data + index);
1916 		index++;
1917 
1918 		if (operation_byte == MIPI_SEQ_ELEM_END) {
1919 			if (index != seq_end) {
1920 				drm_err(display->drm,
1921 					"Invalid element structure\n");
1922 				return 0;
1923 			}
1924 			return index;
1925 		}
1926 
1927 		len = *(data + index);
1928 		index++;
1929 
1930 		/*
1931 		 * FIXME: Would be nice to check elements like for v1/v2 in
1932 		 * goto_next_sequence() above.
1933 		 */
1934 		switch (operation_byte) {
1935 		case MIPI_SEQ_ELEM_SEND_PKT:
1936 		case MIPI_SEQ_ELEM_DELAY:
1937 		case MIPI_SEQ_ELEM_GPIO:
1938 		case MIPI_SEQ_ELEM_I2C:
1939 		case MIPI_SEQ_ELEM_SPI:
1940 		case MIPI_SEQ_ELEM_PMIC:
1941 			break;
1942 		default:
1943 			drm_err(display->drm, "Unknown operation byte %u\n",
1944 				operation_byte);
1945 			break;
1946 		}
1947 	}
1948 
1949 	return 0;
1950 }
1951 
1952 /*
1953  * Get len of pre-fixed deassert fragment from a v1 init OTP sequence,
1954  * skip all delay + gpio operands and stop at the first DSI packet op.
1955  */
get_init_otp_deassert_fragment_len(struct intel_display * display,struct intel_panel * panel)1956 static int get_init_otp_deassert_fragment_len(struct intel_display *display,
1957 					      struct intel_panel *panel)
1958 {
1959 	const u8 *data = panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP];
1960 	int index, len;
1961 
1962 	if (drm_WARN_ON(display->drm,
1963 			!data || panel->vbt.dsi.seq_version >= 3))
1964 		return 0;
1965 
1966 	/* index = 1 to skip sequence byte */
1967 	for (index = 1; data[index] != MIPI_SEQ_ELEM_END; index += len) {
1968 		switch (data[index]) {
1969 		case MIPI_SEQ_ELEM_SEND_PKT:
1970 			return index == 1 ? 0 : index;
1971 		case MIPI_SEQ_ELEM_DELAY:
1972 			len = 5; /* 1 byte for operand + uint32 */
1973 			break;
1974 		case MIPI_SEQ_ELEM_GPIO:
1975 			len = 3; /* 1 byte for op, 1 for gpio_nr, 1 for value */
1976 			break;
1977 		default:
1978 			return 0;
1979 		}
1980 	}
1981 
1982 	return 0;
1983 }
1984 
1985 /*
1986  * Some v1/v2 VBT MIPI sequences do the deassert in the init OTP sequence.
1987  * The deassert must be done before calling intel_dsi_device_ready, so for
1988  * these devices we split the init OTP sequence into a deassert sequence and
1989  * the actual init OTP part.
1990  */
vlv_fixup_mipi_sequences(struct intel_display * display,struct intel_panel * panel)1991 static void vlv_fixup_mipi_sequences(struct intel_display *display,
1992 				     struct intel_panel *panel)
1993 {
1994 	u8 *init_otp;
1995 	int len;
1996 
1997 	/* Limit this to v1/v2 vid-mode sequences */
1998 	if (panel->vbt.dsi.config->is_cmd_mode ||
1999 	    panel->vbt.dsi.seq_version >= 3)
2000 		return;
2001 
2002 	/* Only do this if there are otp and assert seqs and no deassert seq */
2003 	if (!panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] ||
2004 	    !panel->vbt.dsi.sequence[MIPI_SEQ_ASSERT_RESET] ||
2005 	    panel->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET])
2006 		return;
2007 
2008 	/* The deassert-sequence ends at the first DSI packet */
2009 	len = get_init_otp_deassert_fragment_len(display, panel);
2010 	if (!len)
2011 		return;
2012 
2013 	drm_dbg_kms(display->drm,
2014 		    "Using init OTP fragment to deassert reset\n");
2015 
2016 	/* Copy the fragment, update seq byte and terminate it */
2017 	init_otp = (u8 *)panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP];
2018 	panel->vbt.dsi.deassert_seq = kmemdup(init_otp, len + 1, GFP_KERNEL);
2019 	if (!panel->vbt.dsi.deassert_seq)
2020 		return;
2021 	panel->vbt.dsi.deassert_seq[0] = MIPI_SEQ_DEASSERT_RESET;
2022 	panel->vbt.dsi.deassert_seq[len] = MIPI_SEQ_ELEM_END;
2023 	/* Use the copy for deassert */
2024 	panel->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET] =
2025 		panel->vbt.dsi.deassert_seq;
2026 	/* Replace the last byte of the fragment with init OTP seq byte */
2027 	init_otp[len - 1] = MIPI_SEQ_INIT_OTP;
2028 	/* And make MIPI_MIPI_SEQ_INIT_OTP point to it */
2029 	panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] = init_otp + len - 1;
2030 }
2031 
2032 /*
2033  * Some machines (eg. Lenovo 82TQ) appear to have broken
2034  * VBT sequences:
2035  * - INIT_OTP is not present at all
2036  * - what should be in INIT_OTP is in DISPLAY_ON
2037  * - what should be in DISPLAY_ON is in BACKLIGHT_ON
2038  *   (along with the actual backlight stuff)
2039  *
2040  * To make those work we simply swap DISPLAY_ON and INIT_OTP.
2041  *
2042  * TODO: Do we need to limit this to specific machines,
2043  *       or examine the contents of the sequences to
2044  *       avoid false positives?
2045  */
icl_fixup_mipi_sequences(struct intel_display * display,struct intel_panel * panel)2046 static void icl_fixup_mipi_sequences(struct intel_display *display,
2047 				     struct intel_panel *panel)
2048 {
2049 	if (!panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] &&
2050 	    panel->vbt.dsi.sequence[MIPI_SEQ_DISPLAY_ON]) {
2051 		drm_dbg_kms(display->drm,
2052 			    "Broken VBT: Swapping INIT_OTP and DISPLAY_ON sequences\n");
2053 
2054 		swap(panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP],
2055 		     panel->vbt.dsi.sequence[MIPI_SEQ_DISPLAY_ON]);
2056 	}
2057 }
2058 
fixup_mipi_sequences(struct intel_display * display,struct intel_panel * panel)2059 static void fixup_mipi_sequences(struct intel_display *display,
2060 				 struct intel_panel *panel)
2061 {
2062 	if (DISPLAY_VER(display) >= 11)
2063 		icl_fixup_mipi_sequences(display, panel);
2064 	else if (display->platform.valleyview)
2065 		vlv_fixup_mipi_sequences(display, panel);
2066 }
2067 
2068 static void
parse_mipi_sequence(struct intel_display * display,struct intel_panel * panel)2069 parse_mipi_sequence(struct intel_display *display,
2070 		    struct intel_panel *panel)
2071 {
2072 	int panel_type = panel->vbt.panel_type;
2073 	const struct bdb_mipi_sequence *sequence;
2074 	const u8 *seq_data;
2075 	u32 seq_size;
2076 	u8 *data;
2077 	int index = 0;
2078 
2079 	/* Only our generic panel driver uses the sequence block. */
2080 	if (panel->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
2081 		return;
2082 
2083 	sequence = bdb_find_section(display, BDB_MIPI_SEQUENCE);
2084 	if (!sequence) {
2085 		drm_dbg_kms(display->drm,
2086 			    "No MIPI Sequence found, parsing complete\n");
2087 		return;
2088 	}
2089 
2090 	/* Fail gracefully for forward incompatible sequence block. */
2091 	if (sequence->version >= 4) {
2092 		drm_err(display->drm,
2093 			"Unable to parse MIPI Sequence Block v%u\n",
2094 			sequence->version);
2095 		return;
2096 	}
2097 
2098 	drm_dbg_kms(display->drm, "Found MIPI sequence block v%u\n",
2099 		    sequence->version);
2100 
2101 	seq_data = find_panel_sequence_block(display, sequence, panel_type, &seq_size);
2102 	if (!seq_data)
2103 		return;
2104 
2105 	data = kmemdup(seq_data, seq_size, GFP_KERNEL);
2106 	if (!data)
2107 		return;
2108 
2109 	/* Parse the sequences, store pointers to each sequence. */
2110 	for (;;) {
2111 		u8 seq_id = *(data + index);
2112 		if (seq_id == MIPI_SEQ_END)
2113 			break;
2114 
2115 		if (seq_id >= MIPI_SEQ_MAX) {
2116 			drm_err(display->drm, "Unknown sequence %u\n",
2117 				seq_id);
2118 			goto err;
2119 		}
2120 
2121 		/* Log about presence of sequences we won't run. */
2122 		if (seq_id == MIPI_SEQ_TEAR_ON || seq_id == MIPI_SEQ_TEAR_OFF)
2123 			drm_dbg_kms(display->drm,
2124 				    "Unsupported sequence %u\n", seq_id);
2125 
2126 		panel->vbt.dsi.sequence[seq_id] = data + index;
2127 
2128 		if (sequence->version >= 3)
2129 			index = goto_next_sequence_v3(display, data, index, seq_size);
2130 		else
2131 			index = goto_next_sequence(display, data, index, seq_size);
2132 		if (!index) {
2133 			drm_err(display->drm, "Invalid sequence %u\n",
2134 				seq_id);
2135 			goto err;
2136 		}
2137 	}
2138 
2139 	panel->vbt.dsi.data = data;
2140 	panel->vbt.dsi.size = seq_size;
2141 	panel->vbt.dsi.seq_version = sequence->version;
2142 
2143 	fixup_mipi_sequences(display, panel);
2144 
2145 	drm_dbg_kms(display->drm, "MIPI related VBT parsing complete\n");
2146 	return;
2147 
2148 err:
2149 	kfree(data);
2150 	memset(panel->vbt.dsi.sequence, 0, sizeof(panel->vbt.dsi.sequence));
2151 }
2152 
2153 static void
parse_compression_parameters(struct intel_display * display)2154 parse_compression_parameters(struct intel_display *display)
2155 {
2156 	const struct bdb_compression_parameters *params;
2157 	struct intel_bios_encoder_data *devdata;
2158 	u16 block_size;
2159 	int index;
2160 
2161 	if (display->vbt.version < 198)
2162 		return;
2163 
2164 	params = bdb_find_section(display, BDB_COMPRESSION_PARAMETERS);
2165 	if (params) {
2166 		/* Sanity checks */
2167 		if (params->entry_size != sizeof(params->data[0])) {
2168 			drm_dbg_kms(display->drm,
2169 				    "VBT: unsupported compression param entry size\n");
2170 			return;
2171 		}
2172 
2173 		block_size = get_blocksize(params);
2174 		if (block_size < sizeof(*params)) {
2175 			drm_dbg_kms(display->drm,
2176 				    "VBT: expected 16 compression param entries\n");
2177 			return;
2178 		}
2179 	}
2180 
2181 	list_for_each_entry(devdata, &display->vbt.display_devices, node) {
2182 		const struct child_device_config *child = &devdata->child;
2183 
2184 		if (!child->compression_enable)
2185 			continue;
2186 
2187 		if (!params) {
2188 			drm_dbg_kms(display->drm,
2189 				    "VBT: compression params not available\n");
2190 			continue;
2191 		}
2192 
2193 		if (child->compression_method_cps) {
2194 			drm_dbg_kms(display->drm,
2195 				    "VBT: CPS compression not supported\n");
2196 			continue;
2197 		}
2198 
2199 		index = child->compression_structure_index;
2200 
2201 		devdata->dsc = kmemdup(&params->data[index],
2202 				       sizeof(*devdata->dsc), GFP_KERNEL);
2203 	}
2204 }
2205 
translate_iboost(struct intel_display * display,u8 val)2206 static u8 translate_iboost(struct intel_display *display, u8 val)
2207 {
2208 	static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
2209 
2210 	if (val >= ARRAY_SIZE(mapping)) {
2211 		drm_dbg_kms(display->drm,
2212 			    "Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
2213 		return 0;
2214 	}
2215 	return mapping[val];
2216 }
2217 
2218 static const u8 cnp_ddc_pin_map[] = {
2219 	[0] = 0, /* N/A */
2220 	[GMBUS_PIN_1_BXT] = DDC_BUS_DDI_B,
2221 	[GMBUS_PIN_2_BXT] = DDC_BUS_DDI_C,
2222 	[GMBUS_PIN_4_CNP] = DDC_BUS_DDI_D, /* sic */
2223 	[GMBUS_PIN_3_BXT] = DDC_BUS_DDI_F, /* sic */
2224 };
2225 
2226 static const u8 icp_ddc_pin_map[] = {
2227 	[GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A,
2228 	[GMBUS_PIN_2_BXT] = ICL_DDC_BUS_DDI_B,
2229 	[GMBUS_PIN_3_BXT] = TGL_DDC_BUS_DDI_C,
2230 	[GMBUS_PIN_9_TC1_ICP] = ICL_DDC_BUS_PORT_1,
2231 	[GMBUS_PIN_10_TC2_ICP] = ICL_DDC_BUS_PORT_2,
2232 	[GMBUS_PIN_11_TC3_ICP] = ICL_DDC_BUS_PORT_3,
2233 	[GMBUS_PIN_12_TC4_ICP] = ICL_DDC_BUS_PORT_4,
2234 	[GMBUS_PIN_13_TC5_TGP] = TGL_DDC_BUS_PORT_5,
2235 	[GMBUS_PIN_14_TC6_TGP] = TGL_DDC_BUS_PORT_6,
2236 };
2237 
2238 static const u8 rkl_pch_tgp_ddc_pin_map[] = {
2239 	[GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A,
2240 	[GMBUS_PIN_2_BXT] = ICL_DDC_BUS_DDI_B,
2241 	[GMBUS_PIN_9_TC1_ICP] = RKL_DDC_BUS_DDI_D,
2242 	[GMBUS_PIN_10_TC2_ICP] = RKL_DDC_BUS_DDI_E,
2243 };
2244 
2245 static const u8 adls_ddc_pin_map[] = {
2246 	[GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A,
2247 	[GMBUS_PIN_9_TC1_ICP] = ADLS_DDC_BUS_PORT_TC1,
2248 	[GMBUS_PIN_10_TC2_ICP] = ADLS_DDC_BUS_PORT_TC2,
2249 	[GMBUS_PIN_11_TC3_ICP] = ADLS_DDC_BUS_PORT_TC3,
2250 	[GMBUS_PIN_12_TC4_ICP] = ADLS_DDC_BUS_PORT_TC4,
2251 };
2252 
2253 static const u8 gen9bc_tgp_ddc_pin_map[] = {
2254 	[GMBUS_PIN_2_BXT] = DDC_BUS_DDI_B,
2255 	[GMBUS_PIN_9_TC1_ICP] = DDC_BUS_DDI_C,
2256 	[GMBUS_PIN_10_TC2_ICP] = DDC_BUS_DDI_D,
2257 };
2258 
2259 static const u8 adlp_ddc_pin_map[] = {
2260 	[GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A,
2261 	[GMBUS_PIN_2_BXT] = ICL_DDC_BUS_DDI_B,
2262 	[GMBUS_PIN_9_TC1_ICP] = ADLP_DDC_BUS_PORT_TC1,
2263 	[GMBUS_PIN_10_TC2_ICP] = ADLP_DDC_BUS_PORT_TC2,
2264 	[GMBUS_PIN_11_TC3_ICP] = ADLP_DDC_BUS_PORT_TC3,
2265 	[GMBUS_PIN_12_TC4_ICP] = ADLP_DDC_BUS_PORT_TC4,
2266 };
2267 
map_ddc_pin(struct intel_display * display,u8 vbt_pin)2268 static u8 map_ddc_pin(struct intel_display *display, u8 vbt_pin)
2269 {
2270 	const u8 *ddc_pin_map;
2271 	int i, n_entries;
2272 
2273 	if (INTEL_PCH_TYPE(display) >= PCH_MTL || display->platform.alderlake_p) {
2274 		ddc_pin_map = adlp_ddc_pin_map;
2275 		n_entries = ARRAY_SIZE(adlp_ddc_pin_map);
2276 	} else if (display->platform.alderlake_s) {
2277 		ddc_pin_map = adls_ddc_pin_map;
2278 		n_entries = ARRAY_SIZE(adls_ddc_pin_map);
2279 	} else if (INTEL_PCH_TYPE(display) >= PCH_DG1) {
2280 		return vbt_pin;
2281 	} else if (display->platform.rocketlake && INTEL_PCH_TYPE(display) == PCH_TGP) {
2282 		ddc_pin_map = rkl_pch_tgp_ddc_pin_map;
2283 		n_entries = ARRAY_SIZE(rkl_pch_tgp_ddc_pin_map);
2284 	} else if (HAS_PCH_TGP(display) && DISPLAY_VER(display) == 9) {
2285 		ddc_pin_map = gen9bc_tgp_ddc_pin_map;
2286 		n_entries = ARRAY_SIZE(gen9bc_tgp_ddc_pin_map);
2287 	} else if (INTEL_PCH_TYPE(display) >= PCH_ICP) {
2288 		ddc_pin_map = icp_ddc_pin_map;
2289 		n_entries = ARRAY_SIZE(icp_ddc_pin_map);
2290 	} else if (HAS_PCH_CNP(display)) {
2291 		ddc_pin_map = cnp_ddc_pin_map;
2292 		n_entries = ARRAY_SIZE(cnp_ddc_pin_map);
2293 	} else {
2294 		/* Assuming direct map */
2295 		return vbt_pin;
2296 	}
2297 
2298 	for (i = 0; i < n_entries; i++) {
2299 		if (ddc_pin_map[i] == vbt_pin)
2300 			return i;
2301 	}
2302 
2303 	drm_dbg_kms(display->drm,
2304 		    "Ignoring alternate pin: VBT claims DDC pin %d, which is not valid for this platform\n",
2305 		    vbt_pin);
2306 	return 0;
2307 }
2308 
dvo_port_type(u8 dvo_port)2309 static u8 dvo_port_type(u8 dvo_port)
2310 {
2311 	switch (dvo_port) {
2312 	case DVO_PORT_HDMIA:
2313 	case DVO_PORT_HDMIB:
2314 	case DVO_PORT_HDMIC:
2315 	case DVO_PORT_HDMID:
2316 	case DVO_PORT_HDMIE:
2317 	case DVO_PORT_HDMIF:
2318 	case DVO_PORT_HDMIG:
2319 	case DVO_PORT_HDMIH:
2320 	case DVO_PORT_HDMII:
2321 		return DVO_PORT_HDMIA;
2322 	case DVO_PORT_DPA:
2323 	case DVO_PORT_DPB:
2324 	case DVO_PORT_DPC:
2325 	case DVO_PORT_DPD:
2326 	case DVO_PORT_DPE:
2327 	case DVO_PORT_DPF:
2328 	case DVO_PORT_DPG:
2329 	case DVO_PORT_DPH:
2330 	case DVO_PORT_DPI:
2331 		return DVO_PORT_DPA;
2332 	case DVO_PORT_MIPIA:
2333 	case DVO_PORT_MIPIB:
2334 	case DVO_PORT_MIPIC:
2335 	case DVO_PORT_MIPID:
2336 		return DVO_PORT_MIPIA;
2337 	default:
2338 		return dvo_port;
2339 	}
2340 }
2341 
__dvo_port_to_port(int n_ports,int n_dvo,const int port_mapping[][3],u8 dvo_port)2342 static enum port __dvo_port_to_port(int n_ports, int n_dvo,
2343 				    const int port_mapping[][3], u8 dvo_port)
2344 {
2345 	enum port port;
2346 	int i;
2347 
2348 	for (port = PORT_A; port < n_ports; port++) {
2349 		for (i = 0; i < n_dvo; i++) {
2350 			if (port_mapping[port][i] == -1)
2351 				break;
2352 
2353 			if (dvo_port == port_mapping[port][i])
2354 				return port;
2355 		}
2356 	}
2357 
2358 	return PORT_NONE;
2359 }
2360 
dvo_port_to_port(struct intel_display * display,u8 dvo_port)2361 static enum port dvo_port_to_port(struct intel_display *display,
2362 				  u8 dvo_port)
2363 {
2364 	/*
2365 	 * Each DDI port can have more than one value on the "DVO Port" field,
2366 	 * so look for all the possible values for each port.
2367 	 */
2368 	static const int port_mapping[][3] = {
2369 		[PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
2370 		[PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
2371 		[PORT_C] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
2372 		[PORT_D] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
2373 		[PORT_E] = { DVO_PORT_HDMIE, DVO_PORT_DPE, DVO_PORT_CRT },
2374 		[PORT_F] = { DVO_PORT_HDMIF, DVO_PORT_DPF, -1 },
2375 		[PORT_G] = { DVO_PORT_HDMIG, DVO_PORT_DPG, -1 },
2376 		[PORT_H] = { DVO_PORT_HDMIH, DVO_PORT_DPH, -1 },
2377 		[PORT_I] = { DVO_PORT_HDMII, DVO_PORT_DPI, -1 },
2378 	};
2379 	/*
2380 	 * RKL VBT uses PHY based mapping. Combo PHYs A,B,C,D
2381 	 * map to DDI A,B,TC1,TC2 respectively.
2382 	 */
2383 	static const int rkl_port_mapping[][3] = {
2384 		[PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
2385 		[PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
2386 		[PORT_C] = { -1 },
2387 		[PORT_TC1] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
2388 		[PORT_TC2] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
2389 	};
2390 	/*
2391 	 * Alderlake S ports used in the driver are PORT_A, PORT_D, PORT_E,
2392 	 * PORT_F and PORT_G, we need to map that to correct VBT sections.
2393 	 */
2394 	static const int adls_port_mapping[][3] = {
2395 		[PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
2396 		[PORT_B] = { -1 },
2397 		[PORT_C] = { -1 },
2398 		[PORT_TC1] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
2399 		[PORT_TC2] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
2400 		[PORT_TC3] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
2401 		[PORT_TC4] = { DVO_PORT_HDMIE, DVO_PORT_DPE, -1 },
2402 	};
2403 	static const int xelpd_port_mapping[][3] = {
2404 		[PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
2405 		[PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
2406 		[PORT_C] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
2407 		[PORT_D_XELPD] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
2408 		[PORT_E_XELPD] = { DVO_PORT_HDMIE, DVO_PORT_DPE, -1 },
2409 		[PORT_TC1] = { DVO_PORT_HDMIF, DVO_PORT_DPF, -1 },
2410 		[PORT_TC2] = { DVO_PORT_HDMIG, DVO_PORT_DPG, -1 },
2411 		[PORT_TC3] = { DVO_PORT_HDMIH, DVO_PORT_DPH, -1 },
2412 		[PORT_TC4] = { DVO_PORT_HDMII, DVO_PORT_DPI, -1 },
2413 	};
2414 
2415 	if (DISPLAY_VER(display) >= 13)
2416 		return __dvo_port_to_port(ARRAY_SIZE(xelpd_port_mapping),
2417 					  ARRAY_SIZE(xelpd_port_mapping[0]),
2418 					  xelpd_port_mapping,
2419 					  dvo_port);
2420 	else if (display->platform.alderlake_s)
2421 		return __dvo_port_to_port(ARRAY_SIZE(adls_port_mapping),
2422 					  ARRAY_SIZE(adls_port_mapping[0]),
2423 					  adls_port_mapping,
2424 					  dvo_port);
2425 	else if (display->platform.dg1 || display->platform.rocketlake)
2426 		return __dvo_port_to_port(ARRAY_SIZE(rkl_port_mapping),
2427 					  ARRAY_SIZE(rkl_port_mapping[0]),
2428 					  rkl_port_mapping,
2429 					  dvo_port);
2430 	else
2431 		return __dvo_port_to_port(ARRAY_SIZE(port_mapping),
2432 					  ARRAY_SIZE(port_mapping[0]),
2433 					  port_mapping,
2434 					  dvo_port);
2435 }
2436 
2437 static enum port
dsi_dvo_port_to_port(struct intel_display * display,u8 dvo_port)2438 dsi_dvo_port_to_port(struct intel_display *display, u8 dvo_port)
2439 {
2440 	switch (dvo_port) {
2441 	case DVO_PORT_MIPIA:
2442 		return PORT_A;
2443 	case DVO_PORT_MIPIC:
2444 		if (DISPLAY_VER(display) >= 11)
2445 			return PORT_B;
2446 		else
2447 			return PORT_C;
2448 	default:
2449 		return PORT_NONE;
2450 	}
2451 }
2452 
intel_bios_encoder_port(const struct intel_bios_encoder_data * devdata)2453 enum port intel_bios_encoder_port(const struct intel_bios_encoder_data *devdata)
2454 {
2455 	struct intel_display *display = devdata->display;
2456 	const struct child_device_config *child = &devdata->child;
2457 	enum port port;
2458 
2459 	port = dvo_port_to_port(display, child->dvo_port);
2460 	if (port == PORT_NONE && DISPLAY_VER(display) >= 11)
2461 		port = dsi_dvo_port_to_port(display, child->dvo_port);
2462 
2463 	return port;
2464 }
2465 
parse_bdb_230_dp_max_link_rate(const int vbt_max_link_rate)2466 static int parse_bdb_230_dp_max_link_rate(const int vbt_max_link_rate)
2467 {
2468 	switch (vbt_max_link_rate) {
2469 	default:
2470 	case BDB_230_VBT_DP_MAX_LINK_RATE_DEF:
2471 		return 0;
2472 	case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR20:
2473 		return 2000000;
2474 	case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR13P5:
2475 		return 1350000;
2476 	case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR10:
2477 		return 1000000;
2478 	case BDB_230_VBT_DP_MAX_LINK_RATE_HBR3:
2479 		return 810000;
2480 	case BDB_230_VBT_DP_MAX_LINK_RATE_HBR2:
2481 		return 540000;
2482 	case BDB_230_VBT_DP_MAX_LINK_RATE_HBR:
2483 		return 270000;
2484 	case BDB_230_VBT_DP_MAX_LINK_RATE_LBR:
2485 		return 162000;
2486 	}
2487 }
2488 
parse_bdb_216_dp_max_link_rate(const int vbt_max_link_rate)2489 static int parse_bdb_216_dp_max_link_rate(const int vbt_max_link_rate)
2490 {
2491 	switch (vbt_max_link_rate) {
2492 	default:
2493 	case BDB_216_VBT_DP_MAX_LINK_RATE_HBR3:
2494 		return 810000;
2495 	case BDB_216_VBT_DP_MAX_LINK_RATE_HBR2:
2496 		return 540000;
2497 	case BDB_216_VBT_DP_MAX_LINK_RATE_HBR:
2498 		return 270000;
2499 	case BDB_216_VBT_DP_MAX_LINK_RATE_LBR:
2500 		return 162000;
2501 	}
2502 }
2503 
edp_rate_override_mask(int rate)2504 static u32 edp_rate_override_mask(int rate)
2505 {
2506 	switch (rate) {
2507 	case 2000000: return BDB_263_VBT_EDP_LINK_RATE_20;
2508 	case 1350000: return BDB_263_VBT_EDP_LINK_RATE_13_5;
2509 	case 1000000: return BDB_263_VBT_EDP_LINK_RATE_10;
2510 	case 810000: return BDB_263_VBT_EDP_LINK_RATE_8_1;
2511 	case 675000: return BDB_263_VBT_EDP_LINK_RATE_6_75;
2512 	case 540000: return BDB_263_VBT_EDP_LINK_RATE_5_4;
2513 	case 432000: return BDB_263_VBT_EDP_LINK_RATE_4_32;
2514 	case 324000: return BDB_263_VBT_EDP_LINK_RATE_3_24;
2515 	case 270000: return BDB_263_VBT_EDP_LINK_RATE_2_7;
2516 	case 243000: return BDB_263_VBT_EDP_LINK_RATE_2_43;
2517 	case 216000: return BDB_263_VBT_EDP_LINK_RATE_2_16;
2518 	case 162000: return BDB_263_VBT_EDP_LINK_RATE_1_62;
2519 	default: return 0;
2520 	}
2521 }
2522 
intel_bios_dp_max_link_rate(const struct intel_bios_encoder_data * devdata)2523 int intel_bios_dp_max_link_rate(const struct intel_bios_encoder_data *devdata)
2524 {
2525 	if (!devdata || devdata->display->vbt.version < 216)
2526 		return 0;
2527 
2528 	if (devdata->display->vbt.version >= 230)
2529 		return parse_bdb_230_dp_max_link_rate(devdata->child.dp_max_link_rate);
2530 	else
2531 		return parse_bdb_216_dp_max_link_rate(devdata->child.dp_max_link_rate);
2532 }
2533 
intel_bios_dp_max_lane_count(const struct intel_bios_encoder_data * devdata)2534 int intel_bios_dp_max_lane_count(const struct intel_bios_encoder_data *devdata)
2535 {
2536 	if (!devdata || devdata->display->vbt.version < 244)
2537 		return 0;
2538 
2539 	return devdata->child.dp_max_lane_count + 1;
2540 }
2541 
2542 bool
intel_bios_encoder_reject_edp_rate(const struct intel_bios_encoder_data * devdata,int rate)2543 intel_bios_encoder_reject_edp_rate(const struct intel_bios_encoder_data *devdata,
2544 				   int rate)
2545 {
2546 	if (!devdata || devdata->display->vbt.version < 263)
2547 		return false;
2548 
2549 	if (devdata->child.edp_data_rate_override == BDB_263_VBT_EDP_RATES_MASK)
2550 		return false;
2551 
2552 	return devdata->child.edp_data_rate_override & edp_rate_override_mask(rate);
2553 }
2554 
sanitize_dedicated_external(struct intel_bios_encoder_data * devdata,enum port port)2555 static void sanitize_dedicated_external(struct intel_bios_encoder_data *devdata,
2556 					enum port port)
2557 {
2558 	struct intel_display *display = devdata->display;
2559 
2560 	if (!intel_bios_encoder_is_dedicated_external(devdata))
2561 		return;
2562 
2563 	/*
2564 	 * Since dedicated_external is for ports connected to PHYs outside of
2565 	 * the Type-C subsystem, clear bits that would only make sense for ports
2566 	 * with PHYs in the Type-C subsystem.
2567 	 */
2568 
2569 	/*
2570 	 * Bit dp_usb_type_c is marked as "don't care" in Bspec when
2571 	 * dedicated_external is set.
2572 	 */
2573 	if (devdata->child.dp_usb_type_c) {
2574 		drm_dbg_kms(display->drm,
2575 			    "VBT claims Port %c supports USB Type-C, but the port is dedicated external, ignoring\n",
2576 			    port_name(port));
2577 		devdata->child.dp_usb_type_c = 0;
2578 	}
2579 
2580 	/*
2581 	 * Bit tbt is marked as "don't care" in Bspec when dedicated_external is
2582 	 * set.
2583 	 */
2584 	if (devdata->child.tbt) {
2585 		drm_dbg_kms(display->drm,
2586 			    "VBT claims Port %c supports TBT, but the port is dedicated external, ignoring\n",
2587 			    port_name(port));
2588 		devdata->child.tbt = 0;
2589 	}
2590 
2591 	/*
2592 	 * DDI allocation for TC capable ports only make sense for PHYs in the
2593 	 * Type-C subsystem.
2594 	 */
2595 	if (devdata->child.dyn_port_over_tc) {
2596 		drm_dbg_kms(display->drm,
2597 			    "VBT claims Port %c supports dynamic DDI allocation in TCSS, but the port is dedicated external, ignoring\n",
2598 			    port_name(port));
2599 		devdata->child.dyn_port_over_tc = 0;
2600 	}
2601 }
2602 
sanitize_device_type(struct intel_bios_encoder_data * devdata,enum port port)2603 static void sanitize_device_type(struct intel_bios_encoder_data *devdata,
2604 				 enum port port)
2605 {
2606 	struct intel_display *display = devdata->display;
2607 	bool is_hdmi;
2608 
2609 	if (port != PORT_A || DISPLAY_VER(display) >= 12)
2610 		return;
2611 
2612 	if (!intel_bios_encoder_supports_dvi(devdata))
2613 		return;
2614 
2615 	is_hdmi = intel_bios_encoder_supports_hdmi(devdata);
2616 
2617 	drm_dbg_kms(display->drm, "VBT claims port A supports DVI%s, ignoring\n",
2618 		    is_hdmi ? "/HDMI" : "");
2619 
2620 	devdata->child.device_type &= ~DEVICE_TYPE_TMDS_DVI_SIGNALING;
2621 	devdata->child.device_type |= DEVICE_TYPE_NOT_HDMI_OUTPUT;
2622 }
2623 
sanitize_hdmi_level_shift(struct intel_bios_encoder_data * devdata,enum port port)2624 static void sanitize_hdmi_level_shift(struct intel_bios_encoder_data *devdata,
2625 				      enum port port)
2626 {
2627 	struct intel_display *display = devdata->display;
2628 
2629 	if (!intel_bios_encoder_supports_dvi(devdata))
2630 		return;
2631 
2632 	/*
2633 	 * Some BDW machines (eg. HP Pavilion 15-ab) shipped
2634 	 * with a HSW VBT where the level shifter value goes
2635 	 * up to 11, whereas the BDW max is 9.
2636 	 */
2637 	if (display->platform.broadwell && devdata->child.hdmi_level_shifter_value > 9) {
2638 		drm_dbg_kms(display->drm,
2639 			    "Bogus port %c VBT HDMI level shift %d, adjusting to %d\n",
2640 			    port_name(port), devdata->child.hdmi_level_shifter_value, 9);
2641 
2642 		devdata->child.hdmi_level_shifter_value = 9;
2643 	}
2644 }
2645 
2646 static bool
intel_bios_encoder_supports_crt(const struct intel_bios_encoder_data * devdata)2647 intel_bios_encoder_supports_crt(const struct intel_bios_encoder_data *devdata)
2648 {
2649 	return devdata->child.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
2650 }
2651 
2652 bool
intel_bios_encoder_supports_dvi(const struct intel_bios_encoder_data * devdata)2653 intel_bios_encoder_supports_dvi(const struct intel_bios_encoder_data *devdata)
2654 {
2655 	return devdata->child.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
2656 }
2657 
2658 bool
intel_bios_encoder_supports_hdmi(const struct intel_bios_encoder_data * devdata)2659 intel_bios_encoder_supports_hdmi(const struct intel_bios_encoder_data *devdata)
2660 {
2661 	return intel_bios_encoder_supports_dvi(devdata) &&
2662 		(devdata->child.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
2663 }
2664 
2665 bool
intel_bios_encoder_supports_dp(const struct intel_bios_encoder_data * devdata)2666 intel_bios_encoder_supports_dp(const struct intel_bios_encoder_data *devdata)
2667 {
2668 	return devdata->child.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
2669 }
2670 
2671 bool
intel_bios_encoder_supports_edp(const struct intel_bios_encoder_data * devdata)2672 intel_bios_encoder_supports_edp(const struct intel_bios_encoder_data *devdata)
2673 {
2674 	return intel_bios_encoder_supports_dp(devdata) &&
2675 		devdata->child.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR;
2676 }
2677 
2678 bool
intel_bios_encoder_supports_dsi(const struct intel_bios_encoder_data * devdata)2679 intel_bios_encoder_supports_dsi(const struct intel_bios_encoder_data *devdata)
2680 {
2681 	return devdata->child.device_type & DEVICE_TYPE_MIPI_OUTPUT;
2682 }
2683 
2684 bool
intel_bios_encoder_is_lspcon(const struct intel_bios_encoder_data * devdata)2685 intel_bios_encoder_is_lspcon(const struct intel_bios_encoder_data *devdata)
2686 {
2687 	return devdata && HAS_LSPCON(devdata->display) && devdata->child.lspcon;
2688 }
2689 
2690 /* This is an index in the HDMI/DVI DDI buffer translation table, or -1 */
intel_bios_hdmi_level_shift(const struct intel_bios_encoder_data * devdata)2691 int intel_bios_hdmi_level_shift(const struct intel_bios_encoder_data *devdata)
2692 {
2693 	if (!devdata || devdata->display->vbt.version < 158 ||
2694 	    DISPLAY_VER(devdata->display) >= 14)
2695 		return -1;
2696 
2697 	return devdata->child.hdmi_level_shifter_value;
2698 }
2699 
intel_bios_hdmi_max_tmds_clock(const struct intel_bios_encoder_data * devdata)2700 int intel_bios_hdmi_max_tmds_clock(const struct intel_bios_encoder_data *devdata)
2701 {
2702 	if (!devdata || devdata->display->vbt.version < 204)
2703 		return 0;
2704 
2705 	switch (devdata->child.hdmi_max_data_rate) {
2706 	default:
2707 		MISSING_CASE(devdata->child.hdmi_max_data_rate);
2708 		fallthrough;
2709 	case HDMI_MAX_DATA_RATE_PLATFORM:
2710 		return 0;
2711 	case HDMI_MAX_DATA_RATE_594:
2712 		return 594000;
2713 	case HDMI_MAX_DATA_RATE_340:
2714 		return 340000;
2715 	case HDMI_MAX_DATA_RATE_300:
2716 		return 300000;
2717 	case HDMI_MAX_DATA_RATE_297:
2718 		return 297000;
2719 	case HDMI_MAX_DATA_RATE_165:
2720 		return 165000;
2721 	}
2722 }
2723 
is_port_valid(struct intel_display * display,enum port port)2724 static bool is_port_valid(struct intel_display *display, enum port port)
2725 {
2726 	/*
2727 	 * On some ICL SKUs port F is not present, but broken VBTs mark
2728 	 * the port as present. Only try to initialize port F for the
2729 	 * SKUs that may actually have it.
2730 	 */
2731 	if (port == PORT_F && display->platform.icelake)
2732 		return display->platform.icelake_port_f;
2733 
2734 	return true;
2735 }
2736 
print_ddi_port(const struct intel_bios_encoder_data * devdata)2737 static void print_ddi_port(const struct intel_bios_encoder_data *devdata)
2738 {
2739 	struct intel_display *display = devdata->display;
2740 	const struct child_device_config *child = &devdata->child;
2741 	bool is_dvi, is_hdmi, is_dp, is_edp, is_dsi, is_crt, supports_typec_usb, supports_tbt;
2742 	int dp_boost_level, dp_max_link_rate, hdmi_boost_level, hdmi_level_shift, max_tmds_clock;
2743 	enum port port;
2744 
2745 	port = intel_bios_encoder_port(devdata);
2746 	if (port == PORT_NONE)
2747 		return;
2748 
2749 	is_dvi = intel_bios_encoder_supports_dvi(devdata);
2750 	is_dp = intel_bios_encoder_supports_dp(devdata);
2751 	is_crt = intel_bios_encoder_supports_crt(devdata);
2752 	is_hdmi = intel_bios_encoder_supports_hdmi(devdata);
2753 	is_edp = intel_bios_encoder_supports_edp(devdata);
2754 	is_dsi = intel_bios_encoder_supports_dsi(devdata);
2755 
2756 	supports_typec_usb = intel_bios_encoder_supports_typec_usb(devdata);
2757 	supports_tbt = intel_bios_encoder_supports_tbt(devdata);
2758 
2759 	drm_dbg_kms(display->drm,
2760 		    "Port %c VBT info: CRT:%d DVI:%d HDMI:%d DP:%d eDP:%d DSI:%d DP++:%d LSPCON:%d USB-Type-C:%d TBT:%d DSC:%d\n",
2761 		    port_name(port), is_crt, is_dvi, is_hdmi, is_dp, is_edp, is_dsi,
2762 		    intel_bios_encoder_supports_dp_dual_mode(devdata),
2763 		    intel_bios_encoder_is_lspcon(devdata),
2764 		    supports_typec_usb, supports_tbt,
2765 		    devdata->dsc != NULL);
2766 
2767 	if (intel_bios_encoder_is_dedicated_external(devdata))
2768 		drm_dbg_kms(display->drm,
2769 			    "Port %c is dedicated external\n",
2770 			    port_name(port));
2771 
2772 	if (intel_bios_encoder_supports_dyn_port_over_tc(devdata))
2773 		drm_dbg_kms(display->drm,
2774 			    "Port %c supports dynamic DDI allocation in TCSS\n",
2775 			    port_name(port));
2776 
2777 	hdmi_level_shift = intel_bios_hdmi_level_shift(devdata);
2778 	if (hdmi_level_shift >= 0) {
2779 		drm_dbg_kms(display->drm,
2780 			    "Port %c VBT HDMI level shift: %d\n",
2781 			    port_name(port), hdmi_level_shift);
2782 	}
2783 
2784 	max_tmds_clock = intel_bios_hdmi_max_tmds_clock(devdata);
2785 	if (max_tmds_clock)
2786 		drm_dbg_kms(display->drm,
2787 			    "Port %c VBT HDMI max TMDS clock: %d kHz\n",
2788 			    port_name(port), max_tmds_clock);
2789 
2790 	/* I_boost config for SKL and above */
2791 	dp_boost_level = intel_bios_dp_boost_level(devdata);
2792 	if (dp_boost_level)
2793 		drm_dbg_kms(display->drm,
2794 			    "Port %c VBT (e)DP boost level: %d\n",
2795 			    port_name(port), dp_boost_level);
2796 
2797 	hdmi_boost_level = intel_bios_hdmi_boost_level(devdata);
2798 	if (hdmi_boost_level)
2799 		drm_dbg_kms(display->drm,
2800 			    "Port %c VBT HDMI boost level: %d\n",
2801 			    port_name(port), hdmi_boost_level);
2802 
2803 	dp_max_link_rate = intel_bios_dp_max_link_rate(devdata);
2804 	if (dp_max_link_rate)
2805 		drm_dbg_kms(display->drm,
2806 			    "Port %c VBT DP max link rate: %d\n",
2807 			    port_name(port), dp_max_link_rate);
2808 
2809 	/*
2810 	 * FIXME need to implement support for VBT
2811 	 * vswing/preemph tables should this ever trigger.
2812 	 */
2813 	drm_WARN(display->drm, child->use_vbt_vswing,
2814 		 "Port %c asks to use VBT vswing/preemph tables\n",
2815 		 port_name(port));
2816 }
2817 
parse_ddi_port(struct intel_bios_encoder_data * devdata)2818 static void parse_ddi_port(struct intel_bios_encoder_data *devdata)
2819 {
2820 	struct intel_display *display = devdata->display;
2821 	enum port port;
2822 
2823 	port = intel_bios_encoder_port(devdata);
2824 	if (port == PORT_NONE)
2825 		return;
2826 
2827 	if (!is_port_valid(display, port)) {
2828 		drm_dbg_kms(display->drm,
2829 			    "VBT reports port %c as supported, but that can't be true: skipping\n",
2830 			    port_name(port));
2831 		return;
2832 	}
2833 
2834 	sanitize_dedicated_external(devdata, port);
2835 	sanitize_device_type(devdata, port);
2836 	sanitize_hdmi_level_shift(devdata, port);
2837 }
2838 
has_ddi_port_info(struct intel_display * display)2839 static bool has_ddi_port_info(struct intel_display *display)
2840 {
2841 	return DISPLAY_VER(display) >= 5 || display->platform.g4x;
2842 }
2843 
parse_ddi_ports(struct intel_display * display)2844 static void parse_ddi_ports(struct intel_display *display)
2845 {
2846 	struct intel_bios_encoder_data *devdata;
2847 
2848 	if (!has_ddi_port_info(display))
2849 		return;
2850 
2851 	list_for_each_entry(devdata, &display->vbt.display_devices, node)
2852 		parse_ddi_port(devdata);
2853 
2854 	list_for_each_entry(devdata, &display->vbt.display_devices, node)
2855 		print_ddi_port(devdata);
2856 }
2857 
child_device_expected_size(u16 version)2858 static int child_device_expected_size(u16 version)
2859 {
2860 	BUILD_BUG_ON(sizeof(struct child_device_config) < 40);
2861 
2862 	if (version > 264)
2863 		return -ENOENT;
2864 	else if (version >= 263)
2865 		return 44;
2866 	else if (version >= 256)
2867 		return 40;
2868 	else if (version >= 216)
2869 		return 39;
2870 	else if (version >= 196)
2871 		return 38;
2872 	else if (version >= 195)
2873 		return 37;
2874 	else if (version >= 111)
2875 		return LEGACY_CHILD_DEVICE_CONFIG_SIZE;
2876 	else if (version >= 106)
2877 		return 27;
2878 	else
2879 		return 22;
2880 }
2881 
child_device_size_valid(struct intel_display * display,int size)2882 static bool child_device_size_valid(struct intel_display *display, int size)
2883 {
2884 	int expected_size;
2885 
2886 	expected_size = child_device_expected_size(display->vbt.version);
2887 	if (expected_size < 0) {
2888 		expected_size = sizeof(struct child_device_config);
2889 		drm_dbg_kms(display->drm,
2890 			    "Expected child device config size for VBT version %u not known; assuming %d\n",
2891 			    display->vbt.version, expected_size);
2892 	}
2893 
2894 	/* Flag an error for unexpected size, but continue anyway. */
2895 	if (size != expected_size)
2896 		drm_err(display->drm,
2897 			"Unexpected child device config size %d (expected %d for VBT version %u)\n",
2898 			size, expected_size, display->vbt.version);
2899 
2900 	/* The legacy sized child device config is the minimum we need. */
2901 	if (size < LEGACY_CHILD_DEVICE_CONFIG_SIZE) {
2902 		drm_dbg_kms(display->drm,
2903 			    "Child device config size %d is too small.\n",
2904 			    size);
2905 		return false;
2906 	}
2907 
2908 	return true;
2909 }
2910 
2911 static void
parse_general_definitions(struct intel_display * display)2912 parse_general_definitions(struct intel_display *display)
2913 {
2914 	const struct bdb_general_definitions *defs;
2915 	struct intel_bios_encoder_data *devdata;
2916 	const struct child_device_config *child;
2917 	int i, child_device_num;
2918 	u16 block_size;
2919 	int bus_pin;
2920 
2921 	defs = bdb_find_section(display, BDB_GENERAL_DEFINITIONS);
2922 	if (!defs) {
2923 		drm_dbg_kms(display->drm,
2924 			    "No general definition block is found, no devices defined.\n");
2925 		return;
2926 	}
2927 
2928 	block_size = get_blocksize(defs);
2929 	if (block_size < sizeof(*defs)) {
2930 		drm_dbg_kms(display->drm,
2931 			    "General definitions block too small (%u)\n",
2932 			    block_size);
2933 		return;
2934 	}
2935 
2936 	bus_pin = defs->crt_ddc_gmbus_pin;
2937 	drm_dbg_kms(display->drm, "crt_ddc_bus_pin: %d\n", bus_pin);
2938 	if (intel_gmbus_is_valid_pin(display, bus_pin))
2939 		display->vbt.crt_ddc_pin = bus_pin;
2940 
2941 	if (!child_device_size_valid(display, defs->child_dev_size))
2942 		return;
2943 
2944 	/* get the number of child device */
2945 	child_device_num = (block_size - sizeof(*defs)) / defs->child_dev_size;
2946 
2947 	for (i = 0; i < child_device_num; i++) {
2948 		child = child_device_ptr(defs, i);
2949 		if (!child->device_type)
2950 			continue;
2951 
2952 		drm_dbg_kms(display->drm,
2953 			    "Found VBT child device with type 0x%x\n",
2954 			    child->device_type);
2955 
2956 		devdata = kzalloc_obj(*devdata);
2957 		if (!devdata)
2958 			break;
2959 
2960 		devdata->display = display;
2961 
2962 		/*
2963 		 * Copy as much as we know (sizeof) and is available
2964 		 * (child_dev_size) of the child device config. Accessing the
2965 		 * data must depend on VBT version.
2966 		 */
2967 		memcpy(&devdata->child, child,
2968 		       min_t(size_t, defs->child_dev_size, sizeof(*child)));
2969 
2970 		list_add_tail(&devdata->node, &display->vbt.display_devices);
2971 	}
2972 
2973 	if (list_empty(&display->vbt.display_devices))
2974 		drm_dbg_kms(display->drm,
2975 			    "no child dev is parsed from VBT\n");
2976 }
2977 
2978 /* Common defaults which may be overridden by VBT. */
2979 static void
init_vbt_defaults(struct intel_display * display)2980 init_vbt_defaults(struct intel_display *display)
2981 {
2982 	display->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
2983 
2984 	/* general features */
2985 	display->vbt.int_tv_support = 1;
2986 	display->vbt.int_crt_support = 1;
2987 
2988 	/* driver features */
2989 	display->vbt.int_lvds_support = 1;
2990 
2991 	/* Default to using SSC */
2992 	display->vbt.lvds_use_ssc = 1;
2993 	/*
2994 	 * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
2995 	 * clock for LVDS.
2996 	 */
2997 	display->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(display,
2998 							      !HAS_PCH_SPLIT(display));
2999 	drm_dbg_kms(display->drm, "Set default to SSC at %d kHz\n",
3000 		    display->vbt.lvds_ssc_freq);
3001 }
3002 
3003 /* Common defaults which may be overridden by VBT. */
3004 static void
init_vbt_panel_defaults(struct intel_panel * panel)3005 init_vbt_panel_defaults(struct intel_panel *panel)
3006 {
3007 	/* Default to having backlight */
3008 	panel->vbt.backlight.present = true;
3009 
3010 	/* LFP panel data */
3011 	panel->vbt.lvds_dither = true;
3012 }
3013 
3014 /* Defaults to initialize only if there is no VBT. */
3015 static void
init_vbt_missing_defaults(struct intel_display * display)3016 init_vbt_missing_defaults(struct intel_display *display)
3017 {
3018 	unsigned int ports = DISPLAY_RUNTIME_INFO(display)->port_mask;
3019 	enum port port;
3020 
3021 	if (!HAS_DDI(display) && !display->platform.cherryview)
3022 		return;
3023 
3024 	for_each_port_masked(port, ports) {
3025 		struct intel_bios_encoder_data *devdata;
3026 		struct child_device_config *child;
3027 		enum phy phy = intel_port_to_phy(display, port);
3028 
3029 		/*
3030 		 * VBT has the TypeC mode (native,TBT/USB) and we don't want
3031 		 * to detect it.
3032 		 */
3033 		if (intel_phy_is_tc(display, phy))
3034 			continue;
3035 
3036 		/* Create fake child device config */
3037 		devdata = kzalloc_obj(*devdata);
3038 		if (!devdata)
3039 			break;
3040 
3041 		devdata->display = display;
3042 		child = &devdata->child;
3043 
3044 		if (port == PORT_F)
3045 			child->dvo_port = DVO_PORT_HDMIF;
3046 		else if (port == PORT_E)
3047 			child->dvo_port = DVO_PORT_HDMIE;
3048 		else
3049 			child->dvo_port = DVO_PORT_HDMIA + port;
3050 
3051 		if (port != PORT_A && port != PORT_E)
3052 			child->device_type |= DEVICE_TYPE_TMDS_DVI_SIGNALING;
3053 
3054 		if (port != PORT_E)
3055 			child->device_type |= DEVICE_TYPE_DISPLAYPORT_OUTPUT;
3056 
3057 		if (port == PORT_A)
3058 			child->device_type |= DEVICE_TYPE_INTERNAL_CONNECTOR;
3059 
3060 		list_add_tail(&devdata->node, &display->vbt.display_devices);
3061 
3062 		drm_dbg_kms(display->drm,
3063 			    "Generating default VBT child device with type 0x%04x on port %c\n",
3064 			    child->device_type, port_name(port));
3065 	}
3066 
3067 	/* Bypass some minimum baseline VBT version checks */
3068 	display->vbt.version = 155;
3069 }
3070 
get_bdb_header(const struct vbt_header * vbt)3071 static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
3072 {
3073 	const void *_vbt = vbt;
3074 
3075 	return _vbt + vbt->bdb_offset;
3076 }
3077 
3078 static const char vbt_signature[] = "$VBT";
3079 static const int vbt_signature_len = 4;
3080 
3081 /**
3082  * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
3083  * @display:	display device
3084  * @buf:	pointer to a buffer to validate
3085  * @size:	size of the buffer
3086  *
3087  * Returns true on valid VBT.
3088  */
intel_bios_is_valid_vbt(struct intel_display * display,const void * buf,size_t size)3089 bool intel_bios_is_valid_vbt(struct intel_display *display,
3090 			     const void *buf, size_t size)
3091 {
3092 	const struct vbt_header *vbt = buf;
3093 	const struct bdb_header *bdb;
3094 
3095 	if (!vbt)
3096 		return false;
3097 
3098 	if (sizeof(struct vbt_header) > size) {
3099 		drm_dbg_kms(display->drm, "VBT header incomplete\n");
3100 		return false;
3101 	}
3102 
3103 	if (memcmp(vbt->signature, vbt_signature, vbt_signature_len)) {
3104 		drm_dbg_kms(display->drm, "VBT invalid signature\n");
3105 		return false;
3106 	}
3107 
3108 	if (vbt->vbt_size > size) {
3109 		drm_dbg_kms(display->drm,
3110 			    "VBT incomplete (vbt_size overflows)\n");
3111 		return false;
3112 	}
3113 
3114 	size = vbt->vbt_size;
3115 
3116 	if (range_overflows_t(size_t,
3117 			      vbt->bdb_offset,
3118 			      sizeof(struct bdb_header),
3119 			      size)) {
3120 		drm_dbg_kms(display->drm, "BDB header incomplete\n");
3121 		return false;
3122 	}
3123 
3124 	bdb = get_bdb_header(vbt);
3125 	if (range_overflows_t(size_t, vbt->bdb_offset, bdb->bdb_size, size)) {
3126 		drm_dbg_kms(display->drm, "BDB incomplete\n");
3127 		return false;
3128 	}
3129 
3130 	return vbt;
3131 }
3132 
firmware_get_vbt(struct intel_display * display,size_t * size)3133 static struct vbt_header *firmware_get_vbt(struct intel_display *display,
3134 					   size_t *size)
3135 {
3136 	struct vbt_header *vbt = NULL;
3137 	const struct firmware *fw = NULL;
3138 	const char *name = display->params.vbt_firmware;
3139 	int ret;
3140 
3141 	if (!name || !*name)
3142 		return NULL;
3143 
3144 	ret = request_firmware(&fw, name, display->drm->dev);
3145 	if (ret) {
3146 		drm_err(display->drm,
3147 			"Requesting VBT firmware \"%s\" failed (%d)\n",
3148 			name, ret);
3149 		return NULL;
3150 	}
3151 
3152 	if (intel_bios_is_valid_vbt(display, fw->data, fw->size)) {
3153 		vbt = kmemdup(fw->data, fw->size, GFP_KERNEL);
3154 		if (vbt) {
3155 			drm_dbg_kms(display->drm,
3156 				    "Found valid VBT firmware \"%s\"\n", name);
3157 			if (size)
3158 				*size = fw->size;
3159 		}
3160 	} else {
3161 		drm_dbg_kms(display->drm, "Invalid VBT firmware \"%s\"\n",
3162 			    name);
3163 	}
3164 
3165 	release_firmware(fw);
3166 
3167 	return vbt;
3168 }
3169 
oprom_get_vbt(struct intel_display * display,struct intel_rom * rom,size_t * size,const char * type)3170 static struct vbt_header *oprom_get_vbt(struct intel_display *display,
3171 					struct intel_rom *rom,
3172 					size_t *size, const char *type)
3173 {
3174 	struct vbt_header *vbt;
3175 	size_t vbt_size;
3176 	loff_t offset;
3177 
3178 	if (!rom)
3179 		return NULL;
3180 
3181 	BUILD_BUG_ON(vbt_signature_len != sizeof(vbt_signature) - 1);
3182 	BUILD_BUG_ON(vbt_signature_len != sizeof(u32));
3183 
3184 	offset = intel_rom_find(rom, *(const u32 *)vbt_signature);
3185 	if (offset < 0)
3186 		goto err_free_rom;
3187 
3188 	if (sizeof(struct vbt_header) > intel_rom_size(rom) - offset) {
3189 		drm_dbg_kms(display->drm, "VBT header incomplete\n");
3190 		goto err_free_rom;
3191 	}
3192 
3193 	BUILD_BUG_ON(sizeof(vbt->vbt_size) != sizeof(u16));
3194 
3195 	vbt_size = intel_rom_read16(rom, offset + offsetof(struct vbt_header, vbt_size));
3196 	if (vbt_size > intel_rom_size(rom) - offset) {
3197 		drm_dbg_kms(display->drm, "VBT incomplete (vbt_size overflows)\n");
3198 		goto err_free_rom;
3199 	}
3200 
3201 	vbt = kzalloc(round_up(vbt_size, 4), GFP_KERNEL);
3202 	if (!vbt)
3203 		goto err_free_rom;
3204 
3205 	intel_rom_read_block(rom, vbt, offset, vbt_size);
3206 
3207 	if (!intel_bios_is_valid_vbt(display, vbt, vbt_size))
3208 		goto err_free_vbt;
3209 
3210 	drm_dbg_kms(display->drm, "Found valid VBT in %s\n", type);
3211 
3212 	if (size)
3213 		*size = vbt_size;
3214 
3215 	intel_rom_free(rom);
3216 
3217 	return vbt;
3218 
3219 err_free_vbt:
3220 	kfree(vbt);
3221 err_free_rom:
3222 	intel_rom_free(rom);
3223 	return NULL;
3224 }
3225 
intel_bios_get_vbt(struct intel_display * display,size_t * sizep)3226 static const struct vbt_header *intel_bios_get_vbt(struct intel_display *display,
3227 						   size_t *sizep)
3228 {
3229 	const struct vbt_header *vbt = NULL;
3230 
3231 	vbt = firmware_get_vbt(display, sizep);
3232 
3233 	if (!vbt)
3234 		vbt = intel_opregion_get_vbt(display, sizep);
3235 
3236 	/*
3237 	 * If the OpRegion does not have VBT, look in SPI flash
3238 	 * through MMIO or PCI mapping
3239 	 */
3240 	if (!vbt && display->platform.dgfx)
3241 		with_intel_display_rpm(display)
3242 			vbt = oprom_get_vbt(display, intel_rom_spi(display->drm), sizep, "SPI flash");
3243 
3244 	if (!vbt)
3245 		with_intel_display_rpm(display)
3246 			vbt = oprom_get_vbt(display, intel_rom_pci(display->drm), sizep, "PCI ROM");
3247 
3248 	return vbt;
3249 }
3250 
3251 /**
3252  * intel_bios_init - find VBT and initialize settings from the BIOS
3253  * @display: display device instance
3254  *
3255  * Parse and initialize settings from the Video BIOS Tables (VBT). If the VBT
3256  * was not found in ACPI OpRegion, try to find it in PCI ROM first. Also
3257  * initialize some defaults if the VBT is not present at all.
3258  */
intel_bios_init(struct intel_display * display)3259 void intel_bios_init(struct intel_display *display)
3260 {
3261 	const struct vbt_header *vbt;
3262 	const struct bdb_header *bdb;
3263 
3264 	INIT_LIST_HEAD(&display->vbt.display_devices);
3265 	INIT_LIST_HEAD(&display->vbt.bdb_blocks);
3266 
3267 	if (!HAS_DISPLAY(display)) {
3268 		drm_dbg_kms(display->drm,
3269 			    "Skipping VBT init due to disabled display.\n");
3270 		return;
3271 	}
3272 
3273 	init_vbt_defaults(display);
3274 
3275 	vbt = intel_bios_get_vbt(display, NULL);
3276 
3277 	if (!vbt)
3278 		goto out;
3279 
3280 	bdb = get_bdb_header(vbt);
3281 	display->vbt.version = bdb->version;
3282 
3283 	drm_dbg_kms(display->drm,
3284 		    "VBT signature \"%.*s\", BDB version %d\n",
3285 		    (int)sizeof(vbt->signature), vbt->signature,
3286 		    display->vbt.version);
3287 
3288 	init_bdb_blocks(display, bdb);
3289 
3290 	/* Grab useful general definitions */
3291 	parse_general_features(display);
3292 	parse_general_definitions(display);
3293 	parse_driver_features(display);
3294 
3295 	/* Depends on child device list */
3296 	parse_compression_parameters(display);
3297 
3298 out:
3299 	if (!vbt) {
3300 		drm_info(display->drm,
3301 			 "Failed to find VBIOS tables (VBT)\n");
3302 		init_vbt_missing_defaults(display);
3303 	}
3304 
3305 	/* Further processing on pre-parsed or generated child device data */
3306 	parse_sdvo_device_mapping(display);
3307 	parse_ddi_ports(display);
3308 
3309 	kfree(vbt);
3310 }
3311 
intel_bios_init_panel(struct intel_display * display,struct intel_panel * panel,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)3312 static void intel_bios_init_panel(struct intel_display *display,
3313 				  struct intel_panel *panel,
3314 				  const struct intel_bios_encoder_data *devdata,
3315 				  const struct drm_edid *drm_edid,
3316 				  bool use_fallback)
3317 {
3318 	/* already have it? */
3319 	if (panel->vbt.panel_type >= 0) {
3320 		drm_WARN_ON(display->drm, !use_fallback);
3321 		return;
3322 	}
3323 
3324 	panel->vbt.panel_type = get_panel_type(display, devdata,
3325 					       drm_edid, use_fallback);
3326 	if (panel->vbt.panel_type < 0) {
3327 		drm_WARN_ON(display->drm, use_fallback);
3328 		return;
3329 	}
3330 
3331 	init_vbt_panel_defaults(panel);
3332 
3333 	parse_panel_options(display, panel);
3334 	parse_generic_dtd(display, panel);
3335 	parse_lfp_data(display, panel);
3336 	parse_lfp_backlight(display, panel);
3337 	parse_sdvo_lvds_data(display, panel);
3338 	parse_panel_driver_features(display, panel);
3339 	parse_power_conservation_features(display, panel);
3340 	parse_edp(display, panel);
3341 	parse_psr(display, panel);
3342 	parse_mipi_config(display, panel);
3343 	parse_mipi_sequence(display, panel);
3344 }
3345 
intel_bios_init_panel_early(struct intel_display * display,struct intel_panel * panel,const struct intel_bios_encoder_data * devdata)3346 void intel_bios_init_panel_early(struct intel_display *display,
3347 				 struct intel_panel *panel,
3348 				 const struct intel_bios_encoder_data *devdata)
3349 {
3350 	intel_bios_init_panel(display, panel, devdata, NULL, false);
3351 }
3352 
intel_bios_init_panel_late(struct intel_display * display,struct intel_panel * panel,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid)3353 void intel_bios_init_panel_late(struct intel_display *display,
3354 				struct intel_panel *panel,
3355 				const struct intel_bios_encoder_data *devdata,
3356 				const struct drm_edid *drm_edid)
3357 {
3358 	intel_bios_init_panel(display, panel, devdata, drm_edid, true);
3359 }
3360 
3361 /**
3362  * intel_bios_driver_remove - Free any resources allocated by intel_bios_init()
3363  * @display: display device instance
3364  */
intel_bios_driver_remove(struct intel_display * display)3365 void intel_bios_driver_remove(struct intel_display *display)
3366 {
3367 	struct intel_bios_encoder_data *devdata, *nd;
3368 	struct bdb_block_entry *entry, *ne;
3369 
3370 	list_for_each_entry_safe(devdata, nd, &display->vbt.display_devices,
3371 				 node) {
3372 		list_del(&devdata->node);
3373 		kfree(devdata->dsc);
3374 		kfree(devdata);
3375 	}
3376 
3377 	list_for_each_entry_safe(entry, ne, &display->vbt.bdb_blocks, node) {
3378 		list_del(&entry->node);
3379 		kfree(entry);
3380 	}
3381 }
3382 
intel_bios_fini_panel(struct intel_panel * panel)3383 void intel_bios_fini_panel(struct intel_panel *panel)
3384 {
3385 	kfree(panel->vbt.sdvo_lvds_vbt_mode);
3386 	panel->vbt.sdvo_lvds_vbt_mode = NULL;
3387 	kfree(panel->vbt.lfp_vbt_mode);
3388 	panel->vbt.lfp_vbt_mode = NULL;
3389 	kfree(panel->vbt.dsi.data);
3390 	panel->vbt.dsi.data = NULL;
3391 	kfree(panel->vbt.dsi.pps);
3392 	panel->vbt.dsi.pps = NULL;
3393 	kfree(panel->vbt.dsi.config);
3394 	panel->vbt.dsi.config = NULL;
3395 	kfree(panel->vbt.dsi.deassert_seq);
3396 	panel->vbt.dsi.deassert_seq = NULL;
3397 }
3398 
3399 /**
3400  * intel_bios_is_tv_present - is integrated TV present in VBT
3401  * @display: display device instance
3402  *
3403  * Return true if TV is present. If no child devices were parsed from VBT,
3404  * assume TV is present.
3405  */
intel_bios_is_tv_present(struct intel_display * display)3406 bool intel_bios_is_tv_present(struct intel_display *display)
3407 {
3408 	const struct intel_bios_encoder_data *devdata;
3409 
3410 	if (!display->vbt.int_tv_support)
3411 		return false;
3412 
3413 	if (list_empty(&display->vbt.display_devices))
3414 		return true;
3415 
3416 	list_for_each_entry(devdata, &display->vbt.display_devices, node) {
3417 		const struct child_device_config *child = &devdata->child;
3418 
3419 		/*
3420 		 * If the device type is not TV, continue.
3421 		 */
3422 		switch (child->device_type) {
3423 		case DEVICE_TYPE_INT_TV:
3424 		case DEVICE_TYPE_TV:
3425 		case DEVICE_TYPE_TV_SVIDEO_COMPOSITE:
3426 			break;
3427 		default:
3428 			continue;
3429 		}
3430 		/* Only when the addin_offset is non-zero, it is regarded
3431 		 * as present.
3432 		 */
3433 		if (child->addin_offset)
3434 			return true;
3435 	}
3436 
3437 	return false;
3438 }
3439 
3440 /**
3441  * intel_bios_is_lvds_present - is LVDS present in VBT
3442  * @display: display device instance
3443  * @i2c_pin:	i2c pin for LVDS if present
3444  *
3445  * Return true if LVDS is present. If no child devices were parsed from VBT,
3446  * assume LVDS is present.
3447  */
intel_bios_is_lvds_present(struct intel_display * display,u8 * i2c_pin)3448 bool intel_bios_is_lvds_present(struct intel_display *display, u8 *i2c_pin)
3449 {
3450 	const struct intel_bios_encoder_data *devdata;
3451 
3452 	if (list_empty(&display->vbt.display_devices))
3453 		return true;
3454 
3455 	list_for_each_entry(devdata, &display->vbt.display_devices, node) {
3456 		const struct child_device_config *child = &devdata->child;
3457 
3458 		/* If the device type is not LFP, continue.
3459 		 * We have to check both the new identifiers as well as the
3460 		 * old for compatibility with some BIOSes.
3461 		 */
3462 		if (child->device_type != DEVICE_TYPE_INT_LFP &&
3463 		    child->device_type != DEVICE_TYPE_LFP)
3464 			continue;
3465 
3466 		if (intel_gmbus_is_valid_pin(display, child->i2c_pin))
3467 			*i2c_pin = child->i2c_pin;
3468 
3469 		/* However, we cannot trust the BIOS writers to populate
3470 		 * the VBT correctly.  Since LVDS requires additional
3471 		 * information from AIM blocks, a non-zero addin offset is
3472 		 * a good indicator that the LVDS is actually present.
3473 		 */
3474 		if (child->addin_offset)
3475 			return true;
3476 
3477 		/* But even then some BIOS writers perform some black magic
3478 		 * and instantiate the device without reference to any
3479 		 * additional data.  Trust that if the VBT was written into
3480 		 * the OpRegion then they have validated the LVDS's existence.
3481 		 */
3482 		return intel_opregion_vbt_present(display);
3483 	}
3484 
3485 	return false;
3486 }
3487 
3488 /**
3489  * intel_bios_is_port_present - is the specified digital port present
3490  * @display: display device instance
3491  * @port:	port to check
3492  *
3493  * Return true if the device in %port is present.
3494  */
intel_bios_is_port_present(struct intel_display * display,enum port port)3495 bool intel_bios_is_port_present(struct intel_display *display, enum port port)
3496 {
3497 	const struct intel_bios_encoder_data *devdata;
3498 
3499 	if (WARN_ON(!has_ddi_port_info(display)))
3500 		return true;
3501 
3502 	if (!is_port_valid(display, port))
3503 		return false;
3504 
3505 	list_for_each_entry(devdata, &display->vbt.display_devices, node) {
3506 		const struct child_device_config *child = &devdata->child;
3507 
3508 		if (dvo_port_to_port(display, child->dvo_port) == port)
3509 			return true;
3510 	}
3511 
3512 	return false;
3513 }
3514 
intel_bios_encoder_supports_dp_dual_mode(const struct intel_bios_encoder_data * devdata)3515 bool intel_bios_encoder_supports_dp_dual_mode(const struct intel_bios_encoder_data *devdata)
3516 {
3517 	const struct child_device_config *child = &devdata->child;
3518 
3519 	if (!devdata)
3520 		return false;
3521 
3522 	if (!intel_bios_encoder_supports_dp(devdata) ||
3523 	    !intel_bios_encoder_supports_hdmi(devdata))
3524 		return false;
3525 
3526 	if (dvo_port_type(child->dvo_port) == DVO_PORT_DPA)
3527 		return true;
3528 
3529 	/* Only accept a HDMI dvo_port as DP++ if it has an AUX channel */
3530 	if (dvo_port_type(child->dvo_port) == DVO_PORT_HDMIA &&
3531 	    child->aux_channel != 0)
3532 		return true;
3533 
3534 	return false;
3535 }
3536 
3537 /**
3538  * intel_bios_is_dsi_present - is DSI present in VBT
3539  * @display: display device instance
3540  * @port:	port for DSI if present
3541  *
3542  * Return true if DSI is present, and return the port in %port.
3543  */
intel_bios_is_dsi_present(struct intel_display * display,enum port * port)3544 bool intel_bios_is_dsi_present(struct intel_display *display,
3545 			       enum port *port)
3546 {
3547 	const struct intel_bios_encoder_data *devdata;
3548 
3549 	list_for_each_entry(devdata, &display->vbt.display_devices, node) {
3550 		const struct child_device_config *child = &devdata->child;
3551 		u8 dvo_port = child->dvo_port;
3552 
3553 		if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT))
3554 			continue;
3555 
3556 		if (dsi_dvo_port_to_port(display, dvo_port) == PORT_NONE) {
3557 			drm_dbg_kms(display->drm,
3558 				    "VBT has unsupported DSI port %c\n",
3559 				    port_name(dvo_port - DVO_PORT_MIPIA));
3560 			continue;
3561 		}
3562 
3563 		if (port)
3564 			*port = dsi_dvo_port_to_port(display, dvo_port);
3565 		return true;
3566 	}
3567 
3568 	return false;
3569 }
3570 
fill_dsc(struct intel_crtc_state * crtc_state,struct dsc_compression_parameters_entry * dsc,int dsc_max_bpc)3571 static bool fill_dsc(struct intel_crtc_state *crtc_state,
3572 		     struct dsc_compression_parameters_entry *dsc,
3573 		     int dsc_max_bpc)
3574 {
3575 	struct intel_display *display = to_intel_display(crtc_state);
3576 	struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config;
3577 	int slices_per_line;
3578 	int bpc = 8;
3579 
3580 	vdsc_cfg->dsc_version_major = dsc->version_major;
3581 	vdsc_cfg->dsc_version_minor = dsc->version_minor;
3582 
3583 	if (dsc->support_12bpc && dsc_max_bpc >= 12)
3584 		bpc = 12;
3585 	else if (dsc->support_10bpc && dsc_max_bpc >= 10)
3586 		bpc = 10;
3587 	else if (dsc->support_8bpc && dsc_max_bpc >= 8)
3588 		bpc = 8;
3589 	else
3590 		drm_dbg_kms(display->drm, "VBT: Unsupported BPC %d for DCS\n",
3591 			    dsc_max_bpc);
3592 
3593 	crtc_state->pipe_bpp = bpc * 3;
3594 
3595 	crtc_state->dsc.compressed_bpp_x16 = fxp_q4_from_int(min(crtc_state->pipe_bpp,
3596 								 VBT_DSC_MAX_BPP(dsc->max_bpp)));
3597 
3598 	/*
3599 	 * FIXME: This is ugly, and slice count should take DSC engine
3600 	 * throughput etc. into account.
3601 	 *
3602 	 * Also, per spec DSI supports 1, 2, 3 or 4 horizontal slices.
3603 	 *
3604 	 * FIXME: split only when necessary
3605 	 */
3606 	if (dsc->slices_per_line & BIT(2)) {
3607 		slices_per_line = 4;
3608 	} else if (dsc->slices_per_line & BIT(1)) {
3609 		slices_per_line = 2;
3610 	} else {
3611 		/* FIXME */
3612 		if (!(dsc->slices_per_line & BIT(0)))
3613 			drm_dbg_kms(display->drm,
3614 				    "VBT: Unsupported DSC slice count for DSI\n");
3615 
3616 		slices_per_line = 1;
3617 	}
3618 
3619 	if (drm_WARN_ON(display->drm,
3620 			!intel_dsc_get_slice_config(display, 1, slices_per_line,
3621 						    &crtc_state->dsc.slice_config)))
3622 		return false;
3623 
3624 	if (crtc_state->hw.adjusted_mode.crtc_hdisplay %
3625 	    intel_dsc_line_slice_count(&crtc_state->dsc.slice_config) != 0)
3626 		drm_dbg_kms(display->drm,
3627 			    "VBT: DSC hdisplay %d not divisible by slice count %d\n",
3628 			    crtc_state->hw.adjusted_mode.crtc_hdisplay,
3629 			    intel_dsc_line_slice_count(&crtc_state->dsc.slice_config));
3630 
3631 	/*
3632 	 * The VBT rc_buffer_block_size and rc_buffer_size definitions
3633 	 * correspond to DP 1.4 DPCD offsets 0x62 and 0x63.
3634 	 */
3635 	vdsc_cfg->rc_model_size = drm_dsc_dp_rc_buffer_size(dsc->rc_buffer_block_size,
3636 							    dsc->rc_buffer_size);
3637 
3638 	/* FIXME: DSI spec says bpc + 1 for this one */
3639 	vdsc_cfg->line_buf_depth = VBT_DSC_LINE_BUFFER_DEPTH(dsc->line_buffer_depth);
3640 
3641 	vdsc_cfg->block_pred_enable = dsc->block_prediction_enable;
3642 
3643 	vdsc_cfg->slice_height = dsc->slice_height;
3644 
3645 	return true;
3646 }
3647 
3648 /* FIXME: initially DSI specific */
intel_bios_get_dsc_params(struct intel_encoder * encoder,struct intel_crtc_state * crtc_state,int dsc_max_bpc)3649 bool intel_bios_get_dsc_params(struct intel_encoder *encoder,
3650 			       struct intel_crtc_state *crtc_state,
3651 			       int dsc_max_bpc)
3652 {
3653 	struct intel_display *display = to_intel_display(encoder);
3654 	const struct intel_bios_encoder_data *devdata;
3655 
3656 	list_for_each_entry(devdata, &display->vbt.display_devices, node) {
3657 		const struct child_device_config *child = &devdata->child;
3658 
3659 		if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT))
3660 			continue;
3661 
3662 		if (dsi_dvo_port_to_port(display, child->dvo_port) == encoder->port) {
3663 			if (!devdata->dsc)
3664 				return false;
3665 
3666 			return fill_dsc(crtc_state, devdata->dsc, dsc_max_bpc);
3667 		}
3668 	}
3669 
3670 	return false;
3671 }
3672 
3673 static const u8 adlp_aux_ch_map[] = {
3674 	[AUX_CH_A] = DP_AUX_A,
3675 	[AUX_CH_B] = DP_AUX_B,
3676 	[AUX_CH_C] = DP_AUX_C,
3677 	[AUX_CH_D_XELPD] = DP_AUX_D,
3678 	[AUX_CH_E_XELPD] = DP_AUX_E,
3679 	[AUX_CH_USBC1] = DP_AUX_F,
3680 	[AUX_CH_USBC2] = DP_AUX_G,
3681 	[AUX_CH_USBC3] = DP_AUX_H,
3682 	[AUX_CH_USBC4] = DP_AUX_I,
3683 };
3684 
3685 /*
3686  * ADL-S VBT uses PHY based mapping. Combo PHYs A,B,C,D,E
3687  * map to DDI A,TC1,TC2,TC3,TC4 respectively.
3688  */
3689 static const u8 adls_aux_ch_map[] = {
3690 	[AUX_CH_A] = DP_AUX_A,
3691 	[AUX_CH_USBC1] = DP_AUX_B,
3692 	[AUX_CH_USBC2] = DP_AUX_C,
3693 	[AUX_CH_USBC3] = DP_AUX_D,
3694 	[AUX_CH_USBC4] = DP_AUX_E,
3695 };
3696 
3697 /*
3698  * RKL/DG1 VBT uses PHY based mapping. Combo PHYs A,B,C,D
3699  * map to DDI A,B,TC1,TC2 respectively.
3700  */
3701 static const u8 rkl_aux_ch_map[] = {
3702 	[AUX_CH_A] = DP_AUX_A,
3703 	[AUX_CH_B] = DP_AUX_B,
3704 	[AUX_CH_USBC1] = DP_AUX_C,
3705 	[AUX_CH_USBC2] = DP_AUX_D,
3706 };
3707 
3708 static const u8 direct_aux_ch_map[] = {
3709 	[AUX_CH_A] = DP_AUX_A,
3710 	[AUX_CH_B] = DP_AUX_B,
3711 	[AUX_CH_C] = DP_AUX_C,
3712 	[AUX_CH_D] = DP_AUX_D, /* aka AUX_CH_USBC1 */
3713 	[AUX_CH_E] = DP_AUX_E, /* aka AUX_CH_USBC2 */
3714 	[AUX_CH_F] = DP_AUX_F, /* aka AUX_CH_USBC3 */
3715 	[AUX_CH_G] = DP_AUX_G, /* aka AUX_CH_USBC4 */
3716 	[AUX_CH_H] = DP_AUX_H, /* aka AUX_CH_USBC5 */
3717 	[AUX_CH_I] = DP_AUX_I, /* aka AUX_CH_USBC6 */
3718 };
3719 
map_aux_ch(struct intel_display * display,u8 aux_channel)3720 static enum aux_ch map_aux_ch(struct intel_display *display, u8 aux_channel)
3721 {
3722 	const u8 *aux_ch_map;
3723 	int i, n_entries;
3724 
3725 	if (DISPLAY_VER(display) >= 13) {
3726 		aux_ch_map = adlp_aux_ch_map;
3727 		n_entries = ARRAY_SIZE(adlp_aux_ch_map);
3728 	} else if (display->platform.alderlake_s) {
3729 		aux_ch_map = adls_aux_ch_map;
3730 		n_entries = ARRAY_SIZE(adls_aux_ch_map);
3731 	} else if (display->platform.dg1 || display->platform.rocketlake) {
3732 		aux_ch_map = rkl_aux_ch_map;
3733 		n_entries = ARRAY_SIZE(rkl_aux_ch_map);
3734 	} else {
3735 		aux_ch_map = direct_aux_ch_map;
3736 		n_entries = ARRAY_SIZE(direct_aux_ch_map);
3737 	}
3738 
3739 	for (i = 0; i < n_entries; i++) {
3740 		if (aux_ch_map[i] == aux_channel)
3741 			return i;
3742 	}
3743 
3744 	drm_dbg_kms(display->drm,
3745 		    "Ignoring alternate AUX CH: VBT claims AUX 0x%x, which is not valid for this platform\n",
3746 		    aux_channel);
3747 
3748 	return AUX_CH_NONE;
3749 }
3750 
intel_bios_dp_aux_ch(const struct intel_bios_encoder_data * devdata)3751 enum aux_ch intel_bios_dp_aux_ch(const struct intel_bios_encoder_data *devdata)
3752 {
3753 	if (!devdata || !devdata->child.aux_channel)
3754 		return AUX_CH_NONE;
3755 
3756 	return map_aux_ch(devdata->display, devdata->child.aux_channel);
3757 }
3758 
intel_bios_dp_has_shared_aux_ch(const struct intel_bios_encoder_data * devdata)3759 bool intel_bios_dp_has_shared_aux_ch(const struct intel_bios_encoder_data *devdata)
3760 {
3761 	struct intel_display *display;
3762 	u8 aux_channel;
3763 	int count = 0;
3764 
3765 	if (!devdata || !devdata->child.aux_channel)
3766 		return false;
3767 
3768 	display = devdata->display;
3769 	aux_channel = devdata->child.aux_channel;
3770 
3771 	list_for_each_entry(devdata, &display->vbt.display_devices, node) {
3772 		if (intel_bios_encoder_supports_dp(devdata) &&
3773 		    aux_channel == devdata->child.aux_channel)
3774 			count++;
3775 	}
3776 
3777 	return count > 1;
3778 }
3779 
intel_bios_dp_boost_level(const struct intel_bios_encoder_data * devdata)3780 int intel_bios_dp_boost_level(const struct intel_bios_encoder_data *devdata)
3781 {
3782 	if (!devdata || devdata->display->vbt.version < 196 || !devdata->child.iboost)
3783 		return 0;
3784 
3785 	return translate_iboost(devdata->display, devdata->child.dp_iboost_level);
3786 }
3787 
intel_bios_hdmi_boost_level(const struct intel_bios_encoder_data * devdata)3788 int intel_bios_hdmi_boost_level(const struct intel_bios_encoder_data *devdata)
3789 {
3790 	if (!devdata || devdata->display->vbt.version < 196 || !devdata->child.iboost)
3791 		return 0;
3792 
3793 	return translate_iboost(devdata->display, devdata->child.hdmi_iboost_level);
3794 }
3795 
intel_bios_hdmi_ddc_pin(const struct intel_bios_encoder_data * devdata)3796 int intel_bios_hdmi_ddc_pin(const struct intel_bios_encoder_data *devdata)
3797 {
3798 	if (!devdata || !devdata->child.ddc_pin)
3799 		return 0;
3800 
3801 	return map_ddc_pin(devdata->display, devdata->child.ddc_pin);
3802 }
3803 
intel_bios_encoder_supports_typec_usb(const struct intel_bios_encoder_data * devdata)3804 bool intel_bios_encoder_supports_typec_usb(const struct intel_bios_encoder_data *devdata)
3805 {
3806 	return devdata->display->vbt.version >= 195 && devdata->child.dp_usb_type_c;
3807 }
3808 
intel_bios_encoder_supports_tbt(const struct intel_bios_encoder_data * devdata)3809 bool intel_bios_encoder_supports_tbt(const struct intel_bios_encoder_data *devdata)
3810 {
3811 	return devdata->display->vbt.version >= 209 && devdata->child.tbt;
3812 }
3813 
intel_bios_encoder_is_dedicated_external(const struct intel_bios_encoder_data * devdata)3814 bool intel_bios_encoder_is_dedicated_external(const struct intel_bios_encoder_data *devdata)
3815 {
3816 	return devdata->display->vbt.version >= 264 &&
3817 		devdata->child.dedicated_external;
3818 }
3819 
intel_bios_encoder_supports_dyn_port_over_tc(const struct intel_bios_encoder_data * devdata)3820 bool intel_bios_encoder_supports_dyn_port_over_tc(const struct intel_bios_encoder_data *devdata)
3821 {
3822 	return devdata->display->vbt.version >= 264 &&
3823 		devdata->child.dyn_port_over_tc;
3824 }
3825 
intel_bios_encoder_lane_reversal(const struct intel_bios_encoder_data * devdata)3826 bool intel_bios_encoder_lane_reversal(const struct intel_bios_encoder_data *devdata)
3827 {
3828 	return devdata && devdata->child.lane_reversal;
3829 }
3830 
intel_bios_encoder_hpd_invert(const struct intel_bios_encoder_data * devdata)3831 bool intel_bios_encoder_hpd_invert(const struct intel_bios_encoder_data *devdata)
3832 {
3833 	return devdata && devdata->child.hpd_invert;
3834 }
3835 
3836 const struct intel_bios_encoder_data *
intel_bios_encoder_data_lookup(struct intel_display * display,enum port port)3837 intel_bios_encoder_data_lookup(struct intel_display *display, enum port port)
3838 {
3839 	struct intel_bios_encoder_data *devdata;
3840 
3841 	list_for_each_entry(devdata, &display->vbt.display_devices, node) {
3842 		if (intel_bios_encoder_port(devdata) == port)
3843 			return devdata;
3844 	}
3845 
3846 	return NULL;
3847 }
3848 
intel_bios_for_each_encoder(struct intel_display * display,void (* func)(struct intel_display * display,const struct intel_bios_encoder_data * devdata))3849 void intel_bios_for_each_encoder(struct intel_display *display,
3850 				 void (*func)(struct intel_display *display,
3851 					      const struct intel_bios_encoder_data *devdata))
3852 {
3853 	struct intel_bios_encoder_data *devdata;
3854 
3855 	list_for_each_entry(devdata, &display->vbt.display_devices, node)
3856 		func(display, devdata);
3857 }
3858 
intel_bios_vbt_show(struct seq_file * m,void * unused)3859 static int intel_bios_vbt_show(struct seq_file *m, void *unused)
3860 {
3861 	struct intel_display *display = m->private;
3862 	const void *vbt;
3863 	size_t vbt_size;
3864 
3865 	vbt = intel_bios_get_vbt(display, &vbt_size);
3866 
3867 	if (vbt) {
3868 		seq_write(m, vbt, vbt_size);
3869 		kfree(vbt);
3870 	}
3871 
3872 	return 0;
3873 }
3874 
3875 DEFINE_SHOW_ATTRIBUTE(intel_bios_vbt);
3876 
intel_bios_debugfs_register(struct intel_display * display)3877 void intel_bios_debugfs_register(struct intel_display *display)
3878 {
3879 	debugfs_create_file("i915_vbt", 0444, display->drm->debugfs_root,
3880 			    display, &intel_bios_vbt_fops);
3881 }
3882