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