1df0566a6SJani Nikula /*
2df0566a6SJani Nikula * Copyright © 2006 Intel Corporation
3df0566a6SJani Nikula *
4df0566a6SJani Nikula * Permission is hereby granted, free of charge, to any person obtaining a
5df0566a6SJani Nikula * copy of this software and associated documentation files (the "Software"),
6df0566a6SJani Nikula * to deal in the Software without restriction, including without limitation
7df0566a6SJani Nikula * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8df0566a6SJani Nikula * and/or sell copies of the Software, and to permit persons to whom the
9df0566a6SJani Nikula * Software is furnished to do so, subject to the following conditions:
10df0566a6SJani Nikula *
11df0566a6SJani Nikula * The above copyright notice and this permission notice (including the next
12df0566a6SJani Nikula * paragraph) shall be included in all copies or substantial portions of the
13df0566a6SJani Nikula * Software.
14df0566a6SJani Nikula *
15df0566a6SJani Nikula * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16df0566a6SJani Nikula * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17df0566a6SJani Nikula * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18df0566a6SJani Nikula * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19df0566a6SJani Nikula * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20df0566a6SJani Nikula * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21df0566a6SJani Nikula * SOFTWARE.
22df0566a6SJani Nikula *
23df0566a6SJani Nikula * Authors:
24df0566a6SJani Nikula * Eric Anholt <eric@anholt.net>
25df0566a6SJani Nikula *
26df0566a6SJani Nikula */
27df0566a6SJani Nikula
28255490f9SVille Syrjälä #include <drm/display/drm_dp_helper.h>
29da68386dSThomas Zimmermann #include <drm/display/drm_dsc_helper.h>
302a64b147SThomas Zimmermann #include <drm/drm_edid.h>
31df0566a6SJani Nikula
32d8fe2ab6SMatt Roper #include "i915_drv.h"
331bf2f3bfSJani Nikula #include "i915_reg.h"
34df0566a6SJani Nikula #include "intel_display.h"
35df0566a6SJani Nikula #include "intel_display_types.h"
36df0566a6SJani Nikula #include "intel_gmbus.h"
37ce2fce25SMatt Roper
38df0566a6SJani Nikula #define _INTEL_BIOS_PRIVATE
39df0566a6SJani Nikula #include "intel_vbt_defs.h"
40df0566a6SJani Nikula
41df0566a6SJani Nikula /**
42df0566a6SJani Nikula * DOC: Video BIOS Table (VBT)
43df0566a6SJani Nikula *
44df0566a6SJani Nikula * The Video BIOS Table, or VBT, provides platform and board specific
45df0566a6SJani Nikula * configuration information to the driver that is not discoverable or available
46df0566a6SJani Nikula * through other means. The configuration is mostly related to display
47df0566a6SJani Nikula * hardware. The VBT is available via the ACPI OpRegion or, on older systems, in
48df0566a6SJani Nikula * the PCI ROM.
49df0566a6SJani Nikula *
50df0566a6SJani Nikula * The VBT consists of a VBT Header (defined as &struct vbt_header), a BDB
51df0566a6SJani Nikula * Header (&struct bdb_header), and a number of BIOS Data Blocks (BDB) that
52df0566a6SJani Nikula * contain the actual configuration information. The VBT Header, and thus the
53df0566a6SJani Nikula * VBT, begins with "$VBT" signature. The VBT Header contains the offset of the
54df0566a6SJani Nikula * BDB Header. The data blocks are concatenated after the BDB Header. The data
55df0566a6SJani Nikula * blocks have a 1-byte Block ID, 2-byte Block Size, and Block Size bytes of
56df0566a6SJani Nikula * data. (Block 53, the MIPI Sequence Block is an exception.)
57df0566a6SJani Nikula *
58df0566a6SJani Nikula * The driver parses the VBT during load. The relevant information is stored in
59df0566a6SJani Nikula * driver private data for ease of use, and the actual VBT is not read after
60df0566a6SJani Nikula * that.
61df0566a6SJani Nikula */
62df0566a6SJani Nikula
63df0566a6SJani Nikula /* Wrapper for VBT child device config */
640d9ef19bSJani Nikula struct intel_bios_encoder_data {
653162d057SJani Nikula struct drm_i915_private *i915;
667371fa34SJani Nikula
677371fa34SJani Nikula struct child_device_config child;
680d9ef19bSJani Nikula struct dsc_compression_parameters_entry *dsc;
696e0d46e9SJani Nikula struct list_head node;
700d9ef19bSJani Nikula };
710d9ef19bSJani Nikula
720d9ef19bSJani Nikula #define SLAVE_ADDR1 0x70
73df0566a6SJani Nikula #define SLAVE_ADDR2 0x72
74df0566a6SJani Nikula
75df0566a6SJani Nikula /* Get BDB block size given a pointer to Block ID. */
_get_blocksize(const u8 * block_base)76df0566a6SJani Nikula static u32 _get_blocksize(const u8 *block_base)
77df0566a6SJani Nikula {
78df0566a6SJani Nikula /* The MIPI Sequence Block v3+ has a separate size field. */
79df0566a6SJani Nikula if (*block_base == BDB_MIPI_SEQUENCE && *(block_base + 3) >= 3)
80df0566a6SJani Nikula return *((const u32 *)(block_base + 4));
81df0566a6SJani Nikula else
82df0566a6SJani Nikula return *((const u16 *)(block_base + 1));
83df0566a6SJani Nikula }
84df0566a6SJani Nikula
85df0566a6SJani Nikula /* Get BDB block size give a pointer to data after Block ID and Block Size. */
get_blocksize(const void * block_data)86df0566a6SJani Nikula static u32 get_blocksize(const void *block_data)
87df0566a6SJani Nikula {
88df0566a6SJani Nikula return _get_blocksize(block_data - 3);
89df0566a6SJani Nikula }
90df0566a6SJani Nikula
91df0566a6SJani Nikula static const void *
find_raw_section(const void * _bdb,enum bdb_block_id section_id)92df0566a6SJani Nikula find_raw_section(const void *_bdb, enum bdb_block_id section_id)
93e163cfb4SVille Syrjälä {
94df0566a6SJani Nikula const struct bdb_header *bdb = _bdb;
95df0566a6SJani Nikula const u8 *base = _bdb;
96df0566a6SJani Nikula int index = 0;
97df0566a6SJani Nikula u32 total, current_size;
98df0566a6SJani Nikula enum bdb_block_id current_id;
99df0566a6SJani Nikula
100df0566a6SJani Nikula /* skip to first section */
101df0566a6SJani Nikula index += bdb->header_size;
102df0566a6SJani Nikula total = bdb->bdb_size;
103df0566a6SJani Nikula
104df0566a6SJani Nikula /* walk the sections looking for section_id */
105df0566a6SJani Nikula while (index + 3 < total) {
106df0566a6SJani Nikula current_id = *(base + index);
107df0566a6SJani Nikula current_size = _get_blocksize(base + index);
108df0566a6SJani Nikula index += 3;
109df0566a6SJani Nikula
110df0566a6SJani Nikula if (index + current_size > total)
111df0566a6SJani Nikula return NULL;
112df0566a6SJani Nikula
113df0566a6SJani Nikula if (current_id == section_id)
114df0566a6SJani Nikula return base + index;
115df0566a6SJani Nikula
116df0566a6SJani Nikula index += current_size;
117df0566a6SJani Nikula }
118df0566a6SJani Nikula
119df0566a6SJani Nikula return NULL;
120df0566a6SJani Nikula }
121df0566a6SJani Nikula
122df0566a6SJani Nikula /*
123e163cfb4SVille Syrjälä * Offset from the start of BDB to the start of the
124e163cfb4SVille Syrjälä * block data (just past the block header).
125e163cfb4SVille Syrjälä */
raw_block_offset(const void * bdb,enum bdb_block_id section_id)126e163cfb4SVille Syrjälä static u32 raw_block_offset(const void *bdb, enum bdb_block_id section_id)
12739b1bc4bSVille Syrjälä {
128e163cfb4SVille Syrjälä const void *block;
129e163cfb4SVille Syrjälä
130e163cfb4SVille Syrjälä block = find_raw_section(bdb, section_id);
131e163cfb4SVille Syrjälä if (!block)
132e163cfb4SVille Syrjälä return 0;
133e163cfb4SVille Syrjälä
134e163cfb4SVille Syrjälä return block - bdb;
135e163cfb4SVille Syrjälä }
136e163cfb4SVille Syrjälä
137e163cfb4SVille Syrjälä struct bdb_block_entry {
138e163cfb4SVille Syrjälä struct list_head node;
139e163cfb4SVille Syrjälä enum bdb_block_id section_id;
140e163cfb4SVille Syrjälä u8 data[];
141e163cfb4SVille Syrjälä };
142e163cfb4SVille Syrjälä
143e163cfb4SVille Syrjälä static const void *
bdb_find_section(struct drm_i915_private * i915,enum bdb_block_id section_id)144e163cfb4SVille Syrjälä bdb_find_section(struct drm_i915_private *i915,
145e163cfb4SVille Syrjälä enum bdb_block_id section_id)
146e163cfb4SVille Syrjälä {
147e163cfb4SVille Syrjälä struct bdb_block_entry *entry;
148e163cfb4SVille Syrjälä
149e163cfb4SVille Syrjälä list_for_each_entry(entry, &i915->display.vbt.bdb_blocks, node) {
150a434689cSJani Nikula if (entry->section_id == section_id)
151e163cfb4SVille Syrjälä return entry->data + 3;
152e163cfb4SVille Syrjälä }
153e163cfb4SVille Syrjälä
154e163cfb4SVille Syrjälä return NULL;
155e163cfb4SVille Syrjälä }
156e163cfb4SVille Syrjälä
157e163cfb4SVille Syrjälä static const struct {
158e163cfb4SVille Syrjälä enum bdb_block_id section_id;
159e163cfb4SVille Syrjälä size_t min_size;
160e163cfb4SVille Syrjälä } bdb_blocks[] = {
161e163cfb4SVille Syrjälä { .section_id = BDB_GENERAL_FEATURES,
162e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_general_features), },
163e163cfb4SVille Syrjälä { .section_id = BDB_GENERAL_DEFINITIONS,
164e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_general_definitions), },
165e163cfb4SVille Syrjälä { .section_id = BDB_PSR,
166e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_psr), },
167e163cfb4SVille Syrjälä { .section_id = BDB_DRIVER_FEATURES,
168e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_driver_features), },
169e163cfb4SVille Syrjälä { .section_id = BDB_SDVO_LVDS_OPTIONS,
170e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_sdvo_lvds_options), },
171e163cfb4SVille Syrjälä { .section_id = BDB_SDVO_PANEL_DTDS,
172e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_sdvo_panel_dtds), },
173e163cfb4SVille Syrjälä { .section_id = BDB_EDP,
174e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_edp), },
175e163cfb4SVille Syrjälä { .section_id = BDB_LVDS_OPTIONS,
176e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_lvds_options), },
177e163cfb4SVille Syrjälä /*
178901a0cadSVille Syrjälä * BDB_LVDS_LFP_DATA depends on BDB_LVDS_LFP_DATA_PTRS,
179901a0cadSVille Syrjälä * so keep the two ordered.
180901a0cadSVille Syrjälä */
181901a0cadSVille Syrjälä { .section_id = BDB_LVDS_LFP_DATA_PTRS,
182e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_lvds_lfp_data_ptrs), },
183e163cfb4SVille Syrjälä { .section_id = BDB_LVDS_LFP_DATA,
184e163cfb4SVille Syrjälä .min_size = 0, /* special case */ },
185901a0cadSVille Syrjälä { .section_id = BDB_LVDS_BACKLIGHT,
186e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_lfp_backlight_data), },
187e163cfb4SVille Syrjälä { .section_id = BDB_LFP_POWER,
188e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_lfp_power), },
189e163cfb4SVille Syrjälä { .section_id = BDB_MIPI_CONFIG,
190e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_mipi_config), },
191e163cfb4SVille Syrjälä { .section_id = BDB_MIPI_SEQUENCE,
192e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_mipi_sequence) },
193e163cfb4SVille Syrjälä { .section_id = BDB_COMPRESSION_PARAMETERS,
194e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_compression_parameters), },
195e163cfb4SVille Syrjälä { .section_id = BDB_GENERIC_DTD,
196e163cfb4SVille Syrjälä .min_size = sizeof(struct bdb_generic_dtd), },
197e163cfb4SVille Syrjälä };
198e163cfb4SVille Syrjälä
lfp_data_min_size(struct drm_i915_private * i915)199e163cfb4SVille Syrjälä static size_t lfp_data_min_size(struct drm_i915_private *i915)
200901a0cadSVille Syrjälä {
201901a0cadSVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs;
202901a0cadSVille Syrjälä size_t size;
203901a0cadSVille Syrjälä
204901a0cadSVille Syrjälä ptrs = bdb_find_section(i915, BDB_LVDS_LFP_DATA_PTRS);
205901a0cadSVille Syrjälä if (!ptrs)
206901a0cadSVille Syrjälä return 0;
207901a0cadSVille Syrjälä
208901a0cadSVille Syrjälä size = sizeof(struct bdb_lvds_lfp_data);
209901a0cadSVille Syrjälä if (ptrs->panel_name.table_size)
210901a0cadSVille Syrjälä size = max(size, ptrs->panel_name.offset +
211901a0cadSVille Syrjälä sizeof(struct bdb_lvds_lfp_data_tail));
212901a0cadSVille Syrjälä
213901a0cadSVille Syrjälä return size;
214901a0cadSVille Syrjälä }
215901a0cadSVille Syrjälä
validate_lfp_data_ptrs(const void * bdb,const struct bdb_lvds_lfp_data_ptrs * ptrs)216901a0cadSVille Syrjälä static bool validate_lfp_data_ptrs(const void *bdb,
217514003e1SVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs)
218514003e1SVille Syrjälä {
219514003e1SVille Syrjälä int fp_timing_size, dvo_timing_size, panel_pnp_id_size, panel_name_size;
2205ab58d69SVille Syrjälä int data_block_size, lfp_data_size;
221514003e1SVille Syrjälä const void *data_block;
2224e78d602SVille Syrjälä int i;
223514003e1SVille Syrjälä
224514003e1SVille Syrjälä data_block = find_raw_section(bdb, BDB_LVDS_LFP_DATA);
2254e78d602SVille Syrjälä if (!data_block)
2264e78d602SVille Syrjälä return false;
2274e78d602SVille Syrjälä
2284e78d602SVille Syrjälä data_block_size = get_blocksize(data_block);
2294e78d602SVille Syrjälä if (data_block_size == 0)
230514003e1SVille Syrjälä return false;
231514003e1SVille Syrjälä
232514003e1SVille Syrjälä /* always 3 indicating the presence of fp_timing+dvo_timing+panel_pnp_id */
233514003e1SVille Syrjälä if (ptrs->lvds_entries != 3)
234514003e1SVille Syrjälä return false;
235514003e1SVille Syrjälä
236514003e1SVille Syrjälä fp_timing_size = ptrs->ptr[0].fp_timing.table_size;
237514003e1SVille Syrjälä dvo_timing_size = ptrs->ptr[0].dvo_timing.table_size;
238514003e1SVille Syrjälä panel_pnp_id_size = ptrs->ptr[0].panel_pnp_id.table_size;
239514003e1SVille Syrjälä panel_name_size = ptrs->panel_name.table_size;
2405ab58d69SVille Syrjälä
241514003e1SVille Syrjälä /* fp_timing has variable size */
242514003e1SVille Syrjälä if (fp_timing_size < 32 ||
243514003e1SVille Syrjälä dvo_timing_size != sizeof(struct lvds_dvo_timing) ||
244514003e1SVille Syrjälä panel_pnp_id_size != sizeof(struct lvds_pnp_id))
245514003e1SVille Syrjälä return false;
246514003e1SVille Syrjälä
247514003e1SVille Syrjälä /* panel_name is not present in old VBTs */
2485ab58d69SVille Syrjälä if (panel_name_size != 0 &&
2495ab58d69SVille Syrjälä panel_name_size != sizeof(struct lvds_lfp_panel_name))
2505ab58d69SVille Syrjälä return false;
2515ab58d69SVille Syrjälä
2525ab58d69SVille Syrjälä lfp_data_size = ptrs->ptr[1].fp_timing.offset - ptrs->ptr[0].fp_timing.offset;
253514003e1SVille Syrjälä if (16 * lfp_data_size > data_block_size)
254514003e1SVille Syrjälä return false;
255514003e1SVille Syrjälä
256514003e1SVille Syrjälä /* make sure the table entries have uniform size */
257514003e1SVille Syrjälä for (i = 1; i < 16; i++) {
258514003e1SVille Syrjälä if (ptrs->ptr[i].fp_timing.table_size != fp_timing_size ||
259514003e1SVille Syrjälä ptrs->ptr[i].dvo_timing.table_size != dvo_timing_size ||
260514003e1SVille Syrjälä ptrs->ptr[i].panel_pnp_id.table_size != panel_pnp_id_size)
261514003e1SVille Syrjälä return false;
262514003e1SVille Syrjälä
263514003e1SVille Syrjälä if (ptrs->ptr[i].fp_timing.offset - ptrs->ptr[i-1].fp_timing.offset != lfp_data_size ||
264514003e1SVille Syrjälä ptrs->ptr[i].dvo_timing.offset - ptrs->ptr[i-1].dvo_timing.offset != lfp_data_size ||
265514003e1SVille Syrjälä ptrs->ptr[i].panel_pnp_id.offset - ptrs->ptr[i-1].panel_pnp_id.offset != lfp_data_size)
266514003e1SVille Syrjälä return false;
267514003e1SVille Syrjälä }
268514003e1SVille Syrjälä
269514003e1SVille Syrjälä /*
2704e78d602SVille Syrjälä * Except for vlv/chv machines all real VBTs seem to have 6
2714e78d602SVille Syrjälä * unaccounted bytes in the fp_timing table. And it doesn't
2724e78d602SVille Syrjälä * appear to be a really intentional hole as the fp_timing
2734e78d602SVille Syrjälä * 0xffff terminator is always within those 6 missing bytes.
2744e78d602SVille Syrjälä */
2754e78d602SVille Syrjälä if (fp_timing_size + 6 + dvo_timing_size + panel_pnp_id_size == lfp_data_size)
2764e78d602SVille Syrjälä fp_timing_size += 6;
2774e78d602SVille Syrjälä
2784e78d602SVille Syrjälä if (fp_timing_size + dvo_timing_size + panel_pnp_id_size != lfp_data_size)
2794e78d602SVille Syrjälä return false;
2804e78d602SVille Syrjälä
2814e78d602SVille Syrjälä if (ptrs->ptr[0].fp_timing.offset + fp_timing_size != ptrs->ptr[0].dvo_timing.offset ||
2824e78d602SVille Syrjälä ptrs->ptr[0].dvo_timing.offset + dvo_timing_size != ptrs->ptr[0].panel_pnp_id.offset ||
2834e78d602SVille Syrjälä ptrs->ptr[0].panel_pnp_id.offset + panel_pnp_id_size != lfp_data_size)
2844e78d602SVille Syrjälä return false;
2854e78d602SVille Syrjälä
2864e78d602SVille Syrjälä /* make sure the tables fit inside the data block */
287514003e1SVille Syrjälä for (i = 0; i < 16; i++) {
288514003e1SVille Syrjälä if (ptrs->ptr[i].fp_timing.offset + fp_timing_size > data_block_size ||
289514003e1SVille Syrjälä ptrs->ptr[i].dvo_timing.offset + dvo_timing_size > data_block_size ||
290514003e1SVille Syrjälä ptrs->ptr[i].panel_pnp_id.offset + panel_pnp_id_size > data_block_size)
291514003e1SVille Syrjälä return false;
292514003e1SVille Syrjälä }
293514003e1SVille Syrjälä
294514003e1SVille Syrjälä if (ptrs->panel_name.offset + 16 * panel_name_size > data_block_size)
2955ab58d69SVille Syrjälä return false;
2965ab58d69SVille Syrjälä
2975ab58d69SVille Syrjälä /* make sure fp_timing terminators are present at expected locations */
2984e78d602SVille Syrjälä for (i = 0; i < 16; i++) {
2994e78d602SVille Syrjälä const u16 *t = data_block + ptrs->ptr[i].fp_timing.offset +
3004e78d602SVille Syrjälä fp_timing_size - 2;
3014e78d602SVille Syrjälä
3024e78d602SVille Syrjälä if (*t != 0xffff)
3034e78d602SVille Syrjälä return false;
3044e78d602SVille Syrjälä }
3054e78d602SVille Syrjälä
3064e78d602SVille Syrjälä return true;
307514003e1SVille Syrjälä }
308514003e1SVille Syrjälä
309514003e1SVille Syrjälä /* make the data table offsets relative to the data block */
fixup_lfp_data_ptrs(const void * bdb,void * ptrs_block)310918f3025SVille Syrjälä static bool fixup_lfp_data_ptrs(const void *bdb, void *ptrs_block)
311918f3025SVille Syrjälä {
312918f3025SVille Syrjälä struct bdb_lvds_lfp_data_ptrs *ptrs = ptrs_block;
313918f3025SVille Syrjälä u32 offset;
314918f3025SVille Syrjälä int i;
315918f3025SVille Syrjälä
316918f3025SVille Syrjälä offset = raw_block_offset(bdb, BDB_LVDS_LFP_DATA);
31739b1bc4bSVille Syrjälä
318918f3025SVille Syrjälä for (i = 0; i < 16; i++) {
319918f3025SVille Syrjälä if (ptrs->ptr[i].fp_timing.offset < offset ||
320918f3025SVille Syrjälä ptrs->ptr[i].dvo_timing.offset < offset ||
321918f3025SVille Syrjälä ptrs->ptr[i].panel_pnp_id.offset < offset)
322918f3025SVille Syrjälä return false;
323918f3025SVille Syrjälä
324918f3025SVille Syrjälä ptrs->ptr[i].fp_timing.offset -= offset;
325918f3025SVille Syrjälä ptrs->ptr[i].dvo_timing.offset -= offset;
326918f3025SVille Syrjälä ptrs->ptr[i].panel_pnp_id.offset -= offset;
327918f3025SVille Syrjälä }
328918f3025SVille Syrjälä
329918f3025SVille Syrjälä if (ptrs->panel_name.table_size) {
3305ab58d69SVille Syrjälä if (ptrs->panel_name.offset < offset)
3315ab58d69SVille Syrjälä return false;
3325ab58d69SVille Syrjälä
3335ab58d69SVille Syrjälä ptrs->panel_name.offset -= offset;
3345ab58d69SVille Syrjälä }
3355ab58d69SVille Syrjälä
3365ab58d69SVille Syrjälä return validate_lfp_data_ptrs(bdb, ptrs);
337514003e1SVille Syrjälä }
338918f3025SVille Syrjälä
make_lfp_data_ptr(struct lvds_lfp_data_ptr_table * table,int table_size,int total_size)339918f3025SVille Syrjälä static int make_lfp_data_ptr(struct lvds_lfp_data_ptr_table *table,
340a87d0a84SVille Syrjälä int table_size, int total_size)
341a87d0a84SVille Syrjälä {
342a87d0a84SVille Syrjälä if (total_size < table_size)
343a87d0a84SVille Syrjälä return total_size;
344a87d0a84SVille Syrjälä
345a87d0a84SVille Syrjälä table->table_size = table_size;
346a87d0a84SVille Syrjälä table->offset = total_size - table_size;
347a87d0a84SVille Syrjälä
348a87d0a84SVille Syrjälä return total_size - table_size;
349a87d0a84SVille Syrjälä }
350a87d0a84SVille Syrjälä
next_lfp_data_ptr(struct lvds_lfp_data_ptr_table * next,const struct lvds_lfp_data_ptr_table * prev,int size)351a87d0a84SVille Syrjälä static void next_lfp_data_ptr(struct lvds_lfp_data_ptr_table *next,
352a87d0a84SVille Syrjälä const struct lvds_lfp_data_ptr_table *prev,
353a87d0a84SVille Syrjälä int size)
354a87d0a84SVille Syrjälä {
355a87d0a84SVille Syrjälä next->table_size = prev->table_size;
356a87d0a84SVille Syrjälä next->offset = prev->offset + size;
357a87d0a84SVille Syrjälä }
358a87d0a84SVille Syrjälä
generate_lfp_data_ptrs(struct drm_i915_private * i915,const void * bdb)359a87d0a84SVille Syrjälä static void *generate_lfp_data_ptrs(struct drm_i915_private *i915,
360a87d0a84SVille Syrjälä const void *bdb)
361a87d0a84SVille Syrjälä {
362a87d0a84SVille Syrjälä int i, size, table_size, block_size, offset, fp_timing_size;
363d3a70518SVille Syrjälä struct bdb_lvds_lfp_data_ptrs *ptrs;
364a87d0a84SVille Syrjälä const void *block;
365d3a70518SVille Syrjälä void *ptrs_block;
366a87d0a84SVille Syrjälä
367a87d0a84SVille Syrjälä /*
368d3a70518SVille Syrjälä * The hardcoded fp_timing_size is only valid for
369d3a70518SVille Syrjälä * modernish VBTs. All older VBTs definitely should
370d3a70518SVille Syrjälä * include block 41 and thus we don't need to
371d3a70518SVille Syrjälä * generate one.
372d3a70518SVille Syrjälä */
373d3a70518SVille Syrjälä if (i915->display.vbt.version < 155)
374d3a70518SVille Syrjälä return NULL;
375d3a70518SVille Syrjälä
376d3a70518SVille Syrjälä fp_timing_size = 38;
377d3a70518SVille Syrjälä
378d3a70518SVille Syrjälä block = find_raw_section(bdb, BDB_LVDS_LFP_DATA);
379a87d0a84SVille Syrjälä if (!block)
380a87d0a84SVille Syrjälä return NULL;
381a87d0a84SVille Syrjälä
382a87d0a84SVille Syrjälä drm_dbg_kms(&i915->drm, "Generating LFP data table pointers\n");
383a87d0a84SVille Syrjälä
384a87d0a84SVille Syrjälä block_size = get_blocksize(block);
385a87d0a84SVille Syrjälä
386a87d0a84SVille Syrjälä size = fp_timing_size + sizeof(struct lvds_dvo_timing) +
387d3a70518SVille Syrjälä sizeof(struct lvds_pnp_id);
388d3a70518SVille Syrjälä if (size * 16 > block_size)
389a87d0a84SVille Syrjälä return NULL;
390a87d0a84SVille Syrjälä
391a87d0a84SVille Syrjälä ptrs_block = kzalloc(sizeof(*ptrs) + 3, GFP_KERNEL);
392a87d0a84SVille Syrjälä if (!ptrs_block)
393a87d0a84SVille Syrjälä return NULL;
394a87d0a84SVille Syrjälä
395a87d0a84SVille Syrjälä *(u8 *)(ptrs_block + 0) = BDB_LVDS_LFP_DATA_PTRS;
396a87d0a84SVille Syrjälä *(u16 *)(ptrs_block + 1) = sizeof(*ptrs);
397a87d0a84SVille Syrjälä ptrs = ptrs_block + 3;
398a87d0a84SVille Syrjälä
399a87d0a84SVille Syrjälä table_size = sizeof(struct lvds_pnp_id);
400a87d0a84SVille Syrjälä size = make_lfp_data_ptr(&ptrs->ptr[0].panel_pnp_id, table_size, size);
401a87d0a84SVille Syrjälä
402a87d0a84SVille Syrjälä table_size = sizeof(struct lvds_dvo_timing);
403a87d0a84SVille Syrjälä size = make_lfp_data_ptr(&ptrs->ptr[0].dvo_timing, table_size, size);
404a87d0a84SVille Syrjälä
405a87d0a84SVille Syrjälä table_size = fp_timing_size;
406d3a70518SVille Syrjälä size = make_lfp_data_ptr(&ptrs->ptr[0].fp_timing, table_size, size);
407a87d0a84SVille Syrjälä
408a87d0a84SVille Syrjälä if (ptrs->ptr[0].fp_timing.table_size)
409a87d0a84SVille Syrjälä ptrs->lvds_entries++;
410a87d0a84SVille Syrjälä if (ptrs->ptr[0].dvo_timing.table_size)
411a87d0a84SVille Syrjälä ptrs->lvds_entries++;
412a87d0a84SVille Syrjälä if (ptrs->ptr[0].panel_pnp_id.table_size)
413a87d0a84SVille Syrjälä ptrs->lvds_entries++;
414a87d0a84SVille Syrjälä
415a87d0a84SVille Syrjälä if (size != 0 || ptrs->lvds_entries != 3) {
416a87d0a84SVille Syrjälä kfree(ptrs_block);
417*1382901fSXia Fukun return NULL;
418a87d0a84SVille Syrjälä }
419a87d0a84SVille Syrjälä
420a87d0a84SVille Syrjälä size = fp_timing_size + sizeof(struct lvds_dvo_timing) +
421d3a70518SVille Syrjälä sizeof(struct lvds_pnp_id);
422d3a70518SVille Syrjälä for (i = 1; i < 16; i++) {
423a87d0a84SVille Syrjälä next_lfp_data_ptr(&ptrs->ptr[i].fp_timing, &ptrs->ptr[i-1].fp_timing, size);
424a87d0a84SVille Syrjälä next_lfp_data_ptr(&ptrs->ptr[i].dvo_timing, &ptrs->ptr[i-1].dvo_timing, size);
425a87d0a84SVille Syrjälä next_lfp_data_ptr(&ptrs->ptr[i].panel_pnp_id, &ptrs->ptr[i-1].panel_pnp_id, size);
426a87d0a84SVille Syrjälä }
427a87d0a84SVille Syrjälä
428a87d0a84SVille Syrjälä table_size = sizeof(struct lvds_lfp_panel_name);
429a87d0a84SVille Syrjälä
430a87d0a84SVille Syrjälä if (16 * (size + table_size) <= block_size) {
431a87d0a84SVille Syrjälä ptrs->panel_name.table_size = table_size;
432a87d0a84SVille Syrjälä ptrs->panel_name.offset = size * 16;
433a87d0a84SVille Syrjälä }
434a87d0a84SVille Syrjälä
435a87d0a84SVille Syrjälä offset = block - bdb;
436a87d0a84SVille Syrjälä
437a87d0a84SVille Syrjälä for (i = 0; i < 16; i++) {
438a87d0a84SVille Syrjälä ptrs->ptr[i].fp_timing.offset += offset;
439a87d0a84SVille Syrjälä ptrs->ptr[i].dvo_timing.offset += offset;
440a87d0a84SVille Syrjälä ptrs->ptr[i].panel_pnp_id.offset += offset;
441a87d0a84SVille Syrjälä }
442a87d0a84SVille Syrjälä
443a87d0a84SVille Syrjälä if (ptrs->panel_name.table_size)
444a87d0a84SVille Syrjälä ptrs->panel_name.offset += offset;
445a87d0a84SVille Syrjälä
446a87d0a84SVille Syrjälä return ptrs_block;
447a87d0a84SVille Syrjälä }
448a87d0a84SVille Syrjälä
449a87d0a84SVille Syrjälä static void
init_bdb_block(struct drm_i915_private * i915,const void * bdb,enum bdb_block_id section_id,size_t min_size)450e163cfb4SVille Syrjälä init_bdb_block(struct drm_i915_private *i915,
451e163cfb4SVille Syrjälä const void *bdb, enum bdb_block_id section_id,
452e163cfb4SVille Syrjälä size_t min_size)
453e163cfb4SVille Syrjälä {
454e163cfb4SVille Syrjälä struct bdb_block_entry *entry;
455e163cfb4SVille Syrjälä void *temp_block = NULL;
456a87d0a84SVille Syrjälä const void *block;
457e163cfb4SVille Syrjälä size_t block_size;
458e163cfb4SVille Syrjälä
459e163cfb4SVille Syrjälä block = find_raw_section(bdb, section_id);
460e163cfb4SVille Syrjälä
461a87d0a84SVille Syrjälä /* Modern VBTs lack the LFP data table pointers block, make one up */
462a87d0a84SVille Syrjälä if (!block && section_id == BDB_LVDS_LFP_DATA_PTRS) {
463a87d0a84SVille Syrjälä temp_block = generate_lfp_data_ptrs(i915, bdb);
464a87d0a84SVille Syrjälä if (temp_block)
465a87d0a84SVille Syrjälä block = temp_block + 3;
466a87d0a84SVille Syrjälä }
467a87d0a84SVille Syrjälä if (!block)
468e163cfb4SVille Syrjälä return;
469e163cfb4SVille Syrjälä
470e163cfb4SVille Syrjälä drm_WARN(&i915->drm, min_size == 0,
471e163cfb4SVille Syrjälä "Block %d min_size is zero\n", section_id);
472e163cfb4SVille Syrjälä
473e163cfb4SVille Syrjälä block_size = get_blocksize(block);
474e163cfb4SVille Syrjälä
475e163cfb4SVille Syrjälä /*
476a06289f3SVille Syrjälä * Version number and new block size are considered
477a06289f3SVille Syrjälä * part of the header for MIPI sequenece block v3+.
478a06289f3SVille Syrjälä */
479a06289f3SVille Syrjälä if (section_id == BDB_MIPI_SEQUENCE && *(const u8 *)block >= 3)
480a06289f3SVille Syrjälä block_size += 5;
481a06289f3SVille Syrjälä
482a06289f3SVille Syrjälä entry = kzalloc(struct_size(entry, data, max(min_size, block_size) + 3),
483e163cfb4SVille Syrjälä GFP_KERNEL);
484e163cfb4SVille Syrjälä if (!entry) {
485a87d0a84SVille Syrjälä kfree(temp_block);
486a87d0a84SVille Syrjälä return;
487e163cfb4SVille Syrjälä }
488a87d0a84SVille Syrjälä
489e163cfb4SVille Syrjälä entry->section_id = section_id;
490e163cfb4SVille Syrjälä memcpy(entry->data, block - 3, block_size + 3);
491e163cfb4SVille Syrjälä
492e163cfb4SVille Syrjälä kfree(temp_block);
493a87d0a84SVille Syrjälä
494a87d0a84SVille Syrjälä drm_dbg_kms(&i915->drm, "Found BDB block %d (size %zu, min size %zu)\n",
495e163cfb4SVille Syrjälä section_id, block_size, min_size);
496e163cfb4SVille Syrjälä
497e163cfb4SVille Syrjälä if (section_id == BDB_LVDS_LFP_DATA_PTRS &&
498918f3025SVille Syrjälä !fixup_lfp_data_ptrs(bdb, entry->data + 3)) {
499918f3025SVille Syrjälä drm_err(&i915->drm, "VBT has malformed LFP data table pointers\n");
500918f3025SVille Syrjälä kfree(entry);
501918f3025SVille Syrjälä return;
502918f3025SVille Syrjälä }
503918f3025SVille Syrjälä
504918f3025SVille Syrjälä list_add_tail(&entry->node, &i915->display.vbt.bdb_blocks);
505a434689cSJani Nikula }
506e163cfb4SVille Syrjälä
init_bdb_blocks(struct drm_i915_private * i915,const void * bdb)507e163cfb4SVille Syrjälä static void init_bdb_blocks(struct drm_i915_private *i915,
508e163cfb4SVille Syrjälä const void *bdb)
509e163cfb4SVille Syrjälä {
510e163cfb4SVille Syrjälä int i;
511e163cfb4SVille Syrjälä
512e163cfb4SVille Syrjälä for (i = 0; i < ARRAY_SIZE(bdb_blocks); i++) {
513e163cfb4SVille Syrjälä enum bdb_block_id section_id = bdb_blocks[i].section_id;
514e163cfb4SVille Syrjälä size_t min_size = bdb_blocks[i].min_size;
515e163cfb4SVille Syrjälä
516e163cfb4SVille Syrjälä if (section_id == BDB_LVDS_LFP_DATA)
517901a0cadSVille Syrjälä min_size = lfp_data_min_size(i915);
518901a0cadSVille Syrjälä
519901a0cadSVille Syrjälä init_bdb_block(i915, bdb, section_id, min_size);
520e163cfb4SVille Syrjälä }
521e163cfb4SVille Syrjälä }
522e163cfb4SVille Syrjälä
523e163cfb4SVille Syrjälä static void
fill_detail_timing_data(struct drm_display_mode * panel_fixed_mode,const struct lvds_dvo_timing * dvo_timing)524df0566a6SJani Nikula fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
525df0566a6SJani Nikula const struct lvds_dvo_timing *dvo_timing)
526df0566a6SJani Nikula {
527df0566a6SJani Nikula panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
528df0566a6SJani Nikula dvo_timing->hactive_lo;
529df0566a6SJani Nikula panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
530df0566a6SJani Nikula ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
531df0566a6SJani Nikula panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
532df0566a6SJani Nikula ((dvo_timing->hsync_pulse_width_hi << 8) |
533df0566a6SJani Nikula dvo_timing->hsync_pulse_width_lo);
534df0566a6SJani Nikula panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
535df0566a6SJani Nikula ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
536df0566a6SJani Nikula
537df0566a6SJani Nikula panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
538df0566a6SJani Nikula dvo_timing->vactive_lo;
539df0566a6SJani Nikula panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
540df0566a6SJani Nikula ((dvo_timing->vsync_off_hi << 4) | dvo_timing->vsync_off_lo);
541df0566a6SJani Nikula panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
542df0566a6SJani Nikula ((dvo_timing->vsync_pulse_width_hi << 4) |
543df0566a6SJani Nikula dvo_timing->vsync_pulse_width_lo);
544df0566a6SJani Nikula panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
545df0566a6SJani Nikula ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
546df0566a6SJani Nikula panel_fixed_mode->clock = dvo_timing->clock * 10;
547df0566a6SJani Nikula panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
548df0566a6SJani Nikula
549df0566a6SJani Nikula if (dvo_timing->hsync_positive)
550df0566a6SJani Nikula panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
551df0566a6SJani Nikula else
552df0566a6SJani Nikula panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
553df0566a6SJani Nikula
554df0566a6SJani Nikula if (dvo_timing->vsync_positive)
555df0566a6SJani Nikula panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
556df0566a6SJani Nikula else
557df0566a6SJani Nikula panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
558df0566a6SJani Nikula
559df0566a6SJani Nikula panel_fixed_mode->width_mm = (dvo_timing->himage_hi << 8) |
560df0566a6SJani Nikula dvo_timing->himage_lo;
561df0566a6SJani Nikula panel_fixed_mode->height_mm = (dvo_timing->vimage_hi << 8) |
562df0566a6SJani Nikula dvo_timing->vimage_lo;
563df0566a6SJani Nikula
564df0566a6SJani Nikula /* Some VBTs have bogus h/vtotal values */
565df0566a6SJani Nikula if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
566df0566a6SJani Nikula panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
567df0566a6SJani Nikula if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
568df0566a6SJani Nikula panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
569df0566a6SJani Nikula
570df0566a6SJani Nikula drm_mode_set_name(panel_fixed_mode);
571df0566a6SJani Nikula }
572df0566a6SJani Nikula
573df0566a6SJani Nikula static const struct lvds_dvo_timing *
get_lvds_dvo_timing(const struct bdb_lvds_lfp_data * data,const struct bdb_lvds_lfp_data_ptrs * ptrs,int index)574df0566a6SJani Nikula get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *data,
57558b2e382SVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs,
57658b2e382SVille Syrjälä int index)
577df0566a6SJani Nikula {
578df0566a6SJani Nikula return (const void *)data + ptrs->ptr[index].dvo_timing.offset;
57958b2e382SVille Syrjälä }
580df0566a6SJani Nikula
581df0566a6SJani Nikula static const struct lvds_fp_timing *
get_lvds_fp_timing(const struct bdb_lvds_lfp_data * data,const struct bdb_lvds_lfp_data_ptrs * ptrs,int index)582df0566a6SJani Nikula get_lvds_fp_timing(const struct bdb_lvds_lfp_data *data,
583918f3025SVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs,
584df0566a6SJani Nikula int index)
585df0566a6SJani Nikula {
586df0566a6SJani Nikula return (const void *)data + ptrs->ptr[index].fp_timing.offset;
58758b2e382SVille Syrjälä }
588df0566a6SJani Nikula
589df0566a6SJani Nikula static const struct lvds_pnp_id *
get_lvds_pnp_id(const struct bdb_lvds_lfp_data * data,const struct bdb_lvds_lfp_data_ptrs * ptrs,int index)590c518a775SVille Syrjälä get_lvds_pnp_id(const struct bdb_lvds_lfp_data *data,
591c518a775SVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs,
592c518a775SVille Syrjälä int index)
593c518a775SVille Syrjälä {
594c518a775SVille Syrjälä return (const void *)data + ptrs->ptr[index].panel_pnp_id.offset;
595c518a775SVille Syrjälä }
596c518a775SVille Syrjälä
597c518a775SVille Syrjälä static const struct bdb_lvds_lfp_data_tail *
get_lfp_data_tail(const struct bdb_lvds_lfp_data * data,const struct bdb_lvds_lfp_data_ptrs * ptrs)598901a0cadSVille Syrjälä get_lfp_data_tail(const struct bdb_lvds_lfp_data *data,
599901a0cadSVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs)
600901a0cadSVille Syrjälä {
601901a0cadSVille Syrjälä if (ptrs->panel_name.table_size)
602901a0cadSVille Syrjälä return (const void *)data + ptrs->panel_name.offset;
603901a0cadSVille Syrjälä else
604901a0cadSVille Syrjälä return NULL;
605901a0cadSVille Syrjälä }
606901a0cadSVille Syrjälä
dump_pnp_id(struct drm_i915_private * i915,const struct lvds_pnp_id * pnp_id,const char * name)607901a0cadSVille Syrjälä static void dump_pnp_id(struct drm_i915_private *i915,
60806bfa86eSVille Syrjälä const struct lvds_pnp_id *pnp_id,
60906bfa86eSVille Syrjälä const char *name)
61006bfa86eSVille Syrjälä {
61106bfa86eSVille Syrjälä u16 mfg_name = be16_to_cpu((__force __be16)pnp_id->mfg_name);
61206bfa86eSVille Syrjälä char vend[4];
61306bfa86eSVille Syrjälä
61406bfa86eSVille Syrjälä drm_dbg_kms(&i915->drm, "%s PNPID mfg: %s (0x%x), prod: %u, serial: %u, week: %d, year: %d\n",
61506bfa86eSVille Syrjälä name, drm_edid_decode_mfg_id(mfg_name, vend),
61606bfa86eSVille Syrjälä pnp_id->mfg_name, pnp_id->product_code, pnp_id->serial,
61706bfa86eSVille Syrjälä pnp_id->mfg_week, pnp_id->mfg_year + 1990);
61806bfa86eSVille Syrjälä }
61906bfa86eSVille Syrjälä
opregion_get_panel_type(struct drm_i915_private * i915,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)62006bfa86eSVille Syrjälä static int opregion_get_panel_type(struct drm_i915_private *i915,
621c518a775SVille Syrjälä const struct intel_bios_encoder_data *devdata,
6226434cf63SAnimesh Manna const struct drm_edid *drm_edid, bool use_fallback)
623c518a775SVille Syrjälä {
624cc589f2dSVille Syrjälä return intel_opregion_get_panel_type(i915);
625cc589f2dSVille Syrjälä }
626cc589f2dSVille Syrjälä
vbt_get_panel_type(struct drm_i915_private * i915,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)627cc589f2dSVille Syrjälä static int vbt_get_panel_type(struct drm_i915_private *i915,
628c518a775SVille Syrjälä const struct intel_bios_encoder_data *devdata,
6296434cf63SAnimesh Manna const struct drm_edid *drm_edid, bool use_fallback)
630c518a775SVille Syrjälä {
631719f4c51SVille Syrjälä const struct bdb_lvds_options *lvds_options;
632719f4c51SVille Syrjälä
633719f4c51SVille Syrjälä lvds_options = bdb_find_section(i915, BDB_LVDS_OPTIONS);
634719f4c51SVille Syrjälä if (!lvds_options)
635719f4c51SVille Syrjälä return -1;
636719f4c51SVille Syrjälä
637719f4c51SVille Syrjälä if (lvds_options->panel_type > 0xf &&
638c518a775SVille Syrjälä lvds_options->panel_type != 0xff) {
639c518a775SVille Syrjälä drm_dbg_kms(&i915->drm, "Invalid VBT panel type 0x%x\n",
640719f4c51SVille Syrjälä lvds_options->panel_type);
641719f4c51SVille Syrjälä return -1;
642719f4c51SVille Syrjälä }
643719f4c51SVille Syrjälä
644719f4c51SVille Syrjälä if (devdata && devdata->child.handle == DEVICE_HANDLE_LFP2)
6456434cf63SAnimesh Manna return lvds_options->panel_type2;
6466434cf63SAnimesh Manna
6476434cf63SAnimesh Manna drm_WARN_ON(&i915->drm, devdata && devdata->child.handle != DEVICE_HANDLE_LFP1);
6486434cf63SAnimesh Manna
6496434cf63SAnimesh Manna return lvds_options->panel_type;
650719f4c51SVille Syrjälä }
651719f4c51SVille Syrjälä
pnpid_get_panel_type(struct drm_i915_private * i915,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)652719f4c51SVille Syrjälä static int pnpid_get_panel_type(struct drm_i915_private *i915,
653c518a775SVille Syrjälä const struct intel_bios_encoder_data *devdata,
6546434cf63SAnimesh Manna const struct drm_edid *drm_edid, bool use_fallback)
655c518a775SVille Syrjälä {
656c518a775SVille Syrjälä const struct bdb_lvds_lfp_data *data;
657c518a775SVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs;
658c518a775SVille Syrjälä const struct lvds_pnp_id *edid_id;
659c518a775SVille Syrjälä struct lvds_pnp_id edid_id_nodate;
660c518a775SVille Syrjälä const struct edid *edid = drm_edid_raw(drm_edid); /* FIXME */
661c518a775SVille Syrjälä int i, best = -1;
662c518a775SVille Syrjälä
663c518a775SVille Syrjälä if (!edid)
664c518a775SVille Syrjälä return -1;
665c518a775SVille Syrjälä
666c518a775SVille Syrjälä edid_id = (const void *)&edid->mfg_id[0];
667c518a775SVille Syrjälä
668c518a775SVille Syrjälä edid_id_nodate = *edid_id;
669c518a775SVille Syrjälä edid_id_nodate.mfg_week = 0;
670c518a775SVille Syrjälä edid_id_nodate.mfg_year = 0;
671c518a775SVille Syrjälä
67206bfa86eSVille Syrjälä dump_pnp_id(i915, edid_id, "EDID");
67306bfa86eSVille Syrjälä
674c518a775SVille Syrjälä ptrs = bdb_find_section(i915, BDB_LVDS_LFP_DATA_PTRS);
675c518a775SVille Syrjälä if (!ptrs)
676c518a775SVille Syrjälä return -1;
677c518a775SVille Syrjälä
678c518a775SVille Syrjälä data = bdb_find_section(i915, BDB_LVDS_LFP_DATA);
679c518a775SVille Syrjälä if (!data)
680c518a775SVille Syrjälä return -1;
681c518a775SVille Syrjälä
682c518a775SVille Syrjälä for (i = 0; i < 16; i++) {
683c518a775SVille Syrjälä const struct lvds_pnp_id *vbt_id =
684c518a775SVille Syrjälä get_lvds_pnp_id(data, ptrs, i);
685c518a775SVille Syrjälä
686c518a775SVille Syrjälä /* full match? */
687c518a775SVille Syrjälä if (!memcmp(vbt_id, edid_id, sizeof(*vbt_id)))
688c518a775SVille Syrjälä return i;
689c518a775SVille Syrjälä
690c518a775SVille Syrjälä /*
691c518a775SVille Syrjälä * Accept a match w/o date if no full match is found,
692c518a775SVille Syrjälä * and the VBT entry does not specify a date.
693c518a775SVille Syrjälä */
694c518a775SVille Syrjälä if (best < 0 &&
695c518a775SVille Syrjälä !memcmp(vbt_id, &edid_id_nodate, sizeof(*vbt_id)))
696c518a775SVille Syrjälä best = i;
697c518a775SVille Syrjälä }
698c518a775SVille Syrjälä
699c518a775SVille Syrjälä return best;
700c518a775SVille Syrjälä }
701c518a775SVille Syrjälä
fallback_get_panel_type(struct drm_i915_private * i915,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)702c518a775SVille Syrjälä static int fallback_get_panel_type(struct drm_i915_private *i915,
7036434cf63SAnimesh Manna const struct intel_bios_encoder_data *devdata,
704c518a775SVille Syrjälä const struct drm_edid *drm_edid, bool use_fallback)
705cc589f2dSVille Syrjälä {
706cc589f2dSVille Syrjälä return use_fallback ? 0 : -1;
707cc589f2dSVille Syrjälä }
708cc589f2dSVille Syrjälä
709cc589f2dSVille Syrjälä enum panel_type {
710cc589f2dSVille Syrjälä PANEL_TYPE_OPREGION,
711cc589f2dSVille Syrjälä PANEL_TYPE_VBT,
712c518a775SVille Syrjälä PANEL_TYPE_PNPID,
713cc589f2dSVille Syrjälä PANEL_TYPE_FALLBACK,
714cc589f2dSVille Syrjälä };
715cc589f2dSVille Syrjälä
get_panel_type(struct drm_i915_private * i915,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)716c518a775SVille Syrjälä static int get_panel_type(struct drm_i915_private *i915,
7176434cf63SAnimesh Manna const struct intel_bios_encoder_data *devdata,
718c518a775SVille Syrjälä const struct drm_edid *drm_edid, bool use_fallback)
719719f4c51SVille Syrjälä {
720cc589f2dSVille Syrjälä struct {
721cc589f2dSVille Syrjälä const char *name;
722c518a775SVille Syrjälä int (*get_panel_type)(struct drm_i915_private *i915,
7236434cf63SAnimesh Manna const struct intel_bios_encoder_data *devdata,
724c518a775SVille Syrjälä const struct drm_edid *drm_edid, bool use_fallback);
725cc589f2dSVille Syrjälä int panel_type;
726cc589f2dSVille Syrjälä } panel_types[] = {
727cc589f2dSVille Syrjälä [PANEL_TYPE_OPREGION] = {
728cc589f2dSVille Syrjälä .name = "OpRegion",
729cc589f2dSVille Syrjälä .get_panel_type = opregion_get_panel_type,
730cc589f2dSVille Syrjälä },
731cc589f2dSVille Syrjälä [PANEL_TYPE_VBT] = {
732cc589f2dSVille Syrjälä .name = "VBT",
733cc589f2dSVille Syrjälä .get_panel_type = vbt_get_panel_type,
734cc589f2dSVille Syrjälä },
735c518a775SVille Syrjälä [PANEL_TYPE_PNPID] = {
736c518a775SVille Syrjälä .name = "PNPID",
737c518a775SVille Syrjälä .get_panel_type = pnpid_get_panel_type,
738c518a775SVille Syrjälä },
739cc589f2dSVille Syrjälä [PANEL_TYPE_FALLBACK] = {
740cc589f2dSVille Syrjälä .name = "fallback",
741cc589f2dSVille Syrjälä .get_panel_type = fallback_get_panel_type,
742cc589f2dSVille Syrjälä },
743cc589f2dSVille Syrjälä };
744cc589f2dSVille Syrjälä int i;
745719f4c51SVille Syrjälä
746cc589f2dSVille Syrjälä for (i = 0; i < ARRAY_SIZE(panel_types); i++) {
7476434cf63SAnimesh Manna panel_types[i].panel_type = panel_types[i].get_panel_type(i915, devdata,
748cc589f2dSVille Syrjälä drm_edid, use_fallback);
749c518a775SVille Syrjälä
750c518a775SVille Syrjälä drm_WARN_ON(&i915->drm, panel_types[i].panel_type > 0xf &&
751cc589f2dSVille Syrjälä panel_types[i].panel_type != 0xff);
752cc589f2dSVille Syrjälä
753cc589f2dSVille Syrjälä if (panel_types[i].panel_type >= 0)
754cc589f2dSVille Syrjälä drm_dbg_kms(&i915->drm, "Panel type (%s): %d\n",
755719f4c51SVille Syrjälä panel_types[i].name, panel_types[i].panel_type);
756719f4c51SVille Syrjälä }
757cc589f2dSVille Syrjälä
758cc589f2dSVille Syrjälä if (panel_types[PANEL_TYPE_OPREGION].panel_type >= 0)
759c518a775SVille Syrjälä i = PANEL_TYPE_OPREGION;
760c518a775SVille Syrjälä else if (panel_types[PANEL_TYPE_VBT].panel_type == 0xff &&
761c518a775SVille Syrjälä panel_types[PANEL_TYPE_PNPID].panel_type >= 0)
762c518a775SVille Syrjälä i = PANEL_TYPE_PNPID;
763c518a775SVille Syrjälä else if (panel_types[PANEL_TYPE_VBT].panel_type != 0xff &&
764cc589f2dSVille Syrjälä panel_types[PANEL_TYPE_VBT].panel_type >= 0)
765cc589f2dSVille Syrjälä i = PANEL_TYPE_VBT;
766cc589f2dSVille Syrjälä else
767719f4c51SVille Syrjälä i = PANEL_TYPE_FALLBACK;
768cc589f2dSVille Syrjälä
769cc589f2dSVille Syrjälä drm_dbg_kms(&i915->drm, "Selected panel type (%s): %d\n",
770cc589f2dSVille Syrjälä panel_types[i].name, panel_types[i].panel_type);
771cc589f2dSVille Syrjälä
772719f4c51SVille Syrjälä return panel_types[i].panel_type;
773719f4c51SVille Syrjälä }
774a50cc495SVille Syrjälä
panel_bits(unsigned int value,int panel_type,int num_bits)775a50cc495SVille Syrjälä static unsigned int panel_bits(unsigned int value, int panel_type, int num_bits)
776a50cc495SVille Syrjälä {
777a50cc495SVille Syrjälä return (value >> (panel_type * num_bits)) & (BIT(num_bits) - 1);
778a50cc495SVille Syrjälä }
779a50cc495SVille Syrjälä
panel_bool(unsigned int value,int panel_type)780a50cc495SVille Syrjälä static bool panel_bool(unsigned int value, int panel_type)
781a50cc495SVille Syrjälä {
782a50cc495SVille Syrjälä return panel_bits(value, panel_type, 1);
783a50cc495SVille Syrjälä }
7849e7ecedfSMatt Roper
785df0566a6SJani Nikula /* Parse general panel options */
7863cf05076SVille Syrjälä static void
parse_panel_options(struct drm_i915_private * i915,struct intel_panel * panel)7870256ea13SVille Syrjälä parse_panel_options(struct drm_i915_private *i915,
788df0566a6SJani Nikula struct intel_panel *panel)
789df0566a6SJani Nikula {
7900256ea13SVille Syrjälä const struct bdb_lvds_options *lvds_options;
791df0566a6SJani Nikula int panel_type = panel->vbt.panel_type;
792df0566a6SJani Nikula int drrs_mode;
793e163cfb4SVille Syrjälä
794df0566a6SJani Nikula lvds_options = bdb_find_section(i915, BDB_LVDS_OPTIONS);
795df0566a6SJani Nikula if (!lvds_options)
796df0566a6SJani Nikula return;
7973cf05076SVille Syrjälä
798df0566a6SJani Nikula panel->vbt.lvds_dither = lvds_options->pixel_dither;
7995c9016b2SVille Syrjälä
8005c9016b2SVille Syrjälä /*
8015c9016b2SVille Syrjälä * Empirical evidence indicates the block size can be
8025c9016b2SVille Syrjälä * either 4,14,16,24+ bytes. For older VBTs no clear
8035c9016b2SVille Syrjälä * relationship between the block size vs. BDB version.
8045c9016b2SVille Syrjälä */
8055c9016b2SVille Syrjälä if (get_blocksize(lvds_options) < 16)
806df0566a6SJani Nikula return;
807a50cc495SVille Syrjälä
808a50cc495SVille Syrjälä drrs_mode = panel_bits(lvds_options->dps_panel_type_bits,
809df0566a6SJani Nikula panel_type, 2);
810df0566a6SJani Nikula /*
811df0566a6SJani Nikula * VBT has static DRRS = 0 and seamless DRRS = 2.
812df0566a6SJani Nikula * The below piece of code is required to adjust vbt.drrs_type
813df0566a6SJani Nikula * to match the enum drrs_support_type.
814df0566a6SJani Nikula */
815df0566a6SJani Nikula switch (drrs_mode) {
8163cf05076SVille Syrjälä case 0:
817dbd440d8SJani Nikula panel->vbt.drrs_type = DRRS_TYPE_STATIC;
818df0566a6SJani Nikula drm_dbg_kms(&i915->drm, "DRRS supported mode is static\n");
819df0566a6SJani Nikula break;
8203cf05076SVille Syrjälä case 2:
821dbd440d8SJani Nikula panel->vbt.drrs_type = DRRS_TYPE_SEAMLESS;
822e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm,
823df0566a6SJani Nikula "DRRS supported mode is seamless\n");
824df0566a6SJani Nikula break;
8253cf05076SVille Syrjälä default:
826dbd440d8SJani Nikula panel->vbt.drrs_type = DRRS_TYPE_NONE;
827e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm,
828df0566a6SJani Nikula "DRRS not supported (VBT input)\n");
829df0566a6SJani Nikula break;
8309e7ecedfSMatt Roper }
8319e7ecedfSMatt Roper }
8329e7ecedfSMatt Roper
83313367132SVille Syrjälä static void
parse_lfp_panel_dtd(struct drm_i915_private * i915,struct intel_panel * panel,const struct bdb_lvds_lfp_data * lvds_lfp_data,const struct bdb_lvds_lfp_data_ptrs * lvds_lfp_data_ptrs)8343cf05076SVille Syrjälä parse_lfp_panel_dtd(struct drm_i915_private *i915,
83513367132SVille Syrjälä struct intel_panel *panel,
83613367132SVille Syrjälä const struct bdb_lvds_lfp_data *lvds_lfp_data,
8379e7ecedfSMatt Roper const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs)
8389e7ecedfSMatt Roper {
8399e7ecedfSMatt Roper const struct lvds_dvo_timing *panel_dvo_timing;
8409e7ecedfSMatt Roper const struct lvds_fp_timing *fp_timing;
8413cf05076SVille Syrjälä struct drm_display_mode *panel_fixed_mode;
842df0566a6SJani Nikula int panel_type = panel->vbt.panel_type;
843df0566a6SJani Nikula
844df0566a6SJani Nikula panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
845df0566a6SJani Nikula lvds_lfp_data_ptrs,
846df0566a6SJani Nikula panel_type);
847df0566a6SJani Nikula
848df0566a6SJani Nikula panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
849df0566a6SJani Nikula if (!panel_fixed_mode)
850df0566a6SJani Nikula return;
851df0566a6SJani Nikula
852df0566a6SJani Nikula fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
8533cf05076SVille Syrjälä
854df0566a6SJani Nikula panel->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
855dbd440d8SJani Nikula
856f01bae2dSVille Syrjälä drm_dbg_kms(&i915->drm,
857f01bae2dSVille Syrjälä "Found panel mode in BIOS VBT legacy lfp table: " DRM_MODE_FMT "\n",
858df0566a6SJani Nikula DRM_MODE_ARG(panel_fixed_mode));
859918f3025SVille Syrjälä
860df0566a6SJani Nikula fp_timing = get_lvds_fp_timing(lvds_lfp_data,
861df0566a6SJani Nikula lvds_lfp_data_ptrs,
86258b2e382SVille Syrjälä panel_type);
863df0566a6SJani Nikula
864df0566a6SJani Nikula /* check the resolution, just to be sure */
865df0566a6SJani Nikula if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
8663cf05076SVille Syrjälä fp_timing->y_res == panel_fixed_mode->vdisplay) {
867dbd440d8SJani Nikula panel->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
868e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm,
8693cf05076SVille Syrjälä "VBT initial LVDS value %x\n",
870df0566a6SJani Nikula panel->vbt.bios_lvds_val);
871df0566a6SJani Nikula }
872df0566a6SJani Nikula }
873df0566a6SJani Nikula
8743cf05076SVille Syrjälä static void
parse_lfp_data(struct drm_i915_private * i915,struct intel_panel * panel)8753cf05076SVille Syrjälä parse_lfp_data(struct drm_i915_private *i915,
87613367132SVille Syrjälä struct intel_panel *panel)
87713367132SVille Syrjälä {
878901a0cadSVille Syrjälä const struct bdb_lvds_lfp_data *data;
87913367132SVille Syrjälä const struct bdb_lvds_lfp_data_tail *tail;
88006bfa86eSVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs;
8813cf05076SVille Syrjälä const struct lvds_pnp_id *pnp_id;
88213367132SVille Syrjälä int panel_type = panel->vbt.panel_type;
88313367132SVille Syrjälä
88413367132SVille Syrjälä ptrs = bdb_find_section(i915, BDB_LVDS_LFP_DATA_PTRS);
88513367132SVille Syrjälä if (!ptrs)
88613367132SVille Syrjälä return;
88713367132SVille Syrjälä
88813367132SVille Syrjälä data = bdb_find_section(i915, BDB_LVDS_LFP_DATA);
88913367132SVille Syrjälä if (!data)
89013367132SVille Syrjälä return;
8913cf05076SVille Syrjälä
8923cf05076SVille Syrjälä if (!panel->vbt.lfp_lvds_vbt_mode)
893901a0cadSVille Syrjälä parse_lfp_panel_dtd(i915, panel, data, ptrs);
89406bfa86eSVille Syrjälä
89506bfa86eSVille Syrjälä pnp_id = get_lvds_pnp_id(data, ptrs, panel_type);
89606bfa86eSVille Syrjälä dump_pnp_id(i915, pnp_id, "Panel");
897901a0cadSVille Syrjälä
898901a0cadSVille Syrjälä tail = get_lfp_data_tail(data, ptrs);
899901a0cadSVille Syrjälä if (!tail)
900901a0cadSVille Syrjälä return;
90106bfa86eSVille Syrjälä
90206bfa86eSVille Syrjälä drm_dbg_kms(&i915->drm, "Panel name: %.*s\n",
90306bfa86eSVille Syrjälä (int)sizeof(tail->panel_name[0].name),
90406bfa86eSVille Syrjälä tail->panel_name[panel_type].name);
905a434689cSJani Nikula
9063cf05076SVille Syrjälä if (i915->display.vbt.version >= 188) {
907790b45f1SVille Syrjälä panel->vbt.seamless_drrs_min_refresh_rate =
908790b45f1SVille Syrjälä tail->seamless_drrs_min_refresh_rate[panel_type];
909790b45f1SVille Syrjälä drm_dbg_kms(&i915->drm,
9103cf05076SVille Syrjälä "Seamless DRRS min refresh rate: %d Hz\n",
911790b45f1SVille Syrjälä panel->vbt.seamless_drrs_min_refresh_rate);
91213367132SVille Syrjälä }
91313367132SVille Syrjälä }
91413367132SVille Syrjälä
9153cf05076SVille Syrjälä static void
parse_generic_dtd(struct drm_i915_private * i915,struct intel_panel * panel)9163cf05076SVille Syrjälä parse_generic_dtd(struct drm_i915_private *i915,
91733ef6d4fSMatt Roper struct intel_panel *panel)
91833ef6d4fSMatt Roper {
91933ef6d4fSMatt Roper const struct bdb_generic_dtd *generic_dtd;
92033ef6d4fSMatt Roper const struct generic_dtd_entry *dtd;
92133ef6d4fSMatt Roper struct drm_display_mode *panel_fixed_mode;
92233ef6d4fSMatt Roper int num_dtd;
92313367132SVille Syrjälä
92413367132SVille Syrjälä /*
92513367132SVille Syrjälä * Older VBTs provided DTD information for internal displays through
92613367132SVille Syrjälä * the "LFP panel tables" block (42). As of VBT revision 229 the
92713367132SVille Syrjälä * DTD information should be provided via a newer "generic DTD"
92813367132SVille Syrjälä * block (58). Just to be safe, we'll try the new generic DTD block
92913367132SVille Syrjälä * first on VBT >= 229, but still fall back to trying the old LFP
93013367132SVille Syrjälä * block if that fails.
931a434689cSJani Nikula */
93213367132SVille Syrjälä if (i915->display.vbt.version < 229)
93313367132SVille Syrjälä return;
934e163cfb4SVille Syrjälä
93533ef6d4fSMatt Roper generic_dtd = bdb_find_section(i915, BDB_GENERIC_DTD);
93633ef6d4fSMatt Roper if (!generic_dtd)
93733ef6d4fSMatt Roper return;
93833ef6d4fSMatt Roper
939dbd440d8SJani Nikula if (generic_dtd->gdtd_size < sizeof(struct generic_dtd_entry)) {
94033ef6d4fSMatt Roper drm_err(&i915->drm, "GDTD size %u is too small.\n",
94133ef6d4fSMatt Roper generic_dtd->gdtd_size);
94233ef6d4fSMatt Roper return;
94333ef6d4fSMatt Roper } else if (generic_dtd->gdtd_size !=
944dbd440d8SJani Nikula sizeof(struct generic_dtd_entry)) {
945e92cbf38SWambui Karuga drm_err(&i915->drm, "Unexpected GDTD size %u\n",
94633ef6d4fSMatt Roper generic_dtd->gdtd_size);
94733ef6d4fSMatt Roper /* DTD has unknown fields, but keep going */
94833ef6d4fSMatt Roper }
94933ef6d4fSMatt Roper
95033ef6d4fSMatt Roper num_dtd = (get_blocksize(generic_dtd) -
9513cf05076SVille Syrjälä sizeof(struct bdb_generic_dtd)) / generic_dtd->gdtd_size;
952dbd440d8SJani Nikula if (panel->vbt.panel_type >= num_dtd) {
953e92cbf38SWambui Karuga drm_err(&i915->drm,
9543cf05076SVille Syrjälä "Panel type %d not found in table of %d DTD's\n",
95533ef6d4fSMatt Roper panel->vbt.panel_type, num_dtd);
95633ef6d4fSMatt Roper return;
95733ef6d4fSMatt Roper }
9583cf05076SVille Syrjälä
95933ef6d4fSMatt Roper dtd = &generic_dtd->dtd[panel->vbt.panel_type];
96033ef6d4fSMatt Roper
96133ef6d4fSMatt Roper panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
96233ef6d4fSMatt Roper if (!panel_fixed_mode)
96333ef6d4fSMatt Roper return;
96433ef6d4fSMatt Roper
96533ef6d4fSMatt Roper panel_fixed_mode->hdisplay = dtd->hactive;
96633ef6d4fSMatt Roper panel_fixed_mode->hsync_start =
96733ef6d4fSMatt Roper panel_fixed_mode->hdisplay + dtd->hfront_porch;
96833ef6d4fSMatt Roper panel_fixed_mode->hsync_end =
969ad278f35SVandita Kulkarni panel_fixed_mode->hsync_start + dtd->hsync;
970ad278f35SVandita Kulkarni panel_fixed_mode->htotal =
97133ef6d4fSMatt Roper panel_fixed_mode->hdisplay + dtd->hblank;
97233ef6d4fSMatt Roper
97333ef6d4fSMatt Roper panel_fixed_mode->vdisplay = dtd->vactive;
97433ef6d4fSMatt Roper panel_fixed_mode->vsync_start =
97533ef6d4fSMatt Roper panel_fixed_mode->vdisplay + dtd->vfront_porch;
97633ef6d4fSMatt Roper panel_fixed_mode->vsync_end =
977ad278f35SVandita Kulkarni panel_fixed_mode->vsync_start + dtd->vsync;
978ad278f35SVandita Kulkarni panel_fixed_mode->vtotal =
97933ef6d4fSMatt Roper panel_fixed_mode->vdisplay + dtd->vblank;
98033ef6d4fSMatt Roper
98133ef6d4fSMatt Roper panel_fixed_mode->clock = dtd->pixel_clock;
98233ef6d4fSMatt Roper panel_fixed_mode->width_mm = dtd->width_mm;
98333ef6d4fSMatt Roper panel_fixed_mode->height_mm = dtd->height_mm;
98433ef6d4fSMatt Roper
98533ef6d4fSMatt Roper panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
98633ef6d4fSMatt Roper drm_mode_set_name(panel_fixed_mode);
98733ef6d4fSMatt Roper
98833ef6d4fSMatt Roper if (dtd->hsync_positive_polarity)
98933ef6d4fSMatt Roper panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
99033ef6d4fSMatt Roper else
99133ef6d4fSMatt Roper panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
99233ef6d4fSMatt Roper
99333ef6d4fSMatt Roper if (dtd->vsync_positive_polarity)
99433ef6d4fSMatt Roper panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
99533ef6d4fSMatt Roper else
99633ef6d4fSMatt Roper panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
997dbd440d8SJani Nikula
998f01bae2dSVille Syrjälä drm_dbg_kms(&i915->drm,
999f01bae2dSVille Syrjälä "Found panel mode in BIOS VBT generic dtd table: " DRM_MODE_FMT "\n",
100033ef6d4fSMatt Roper DRM_MODE_ARG(panel_fixed_mode));
10013cf05076SVille Syrjälä
100233ef6d4fSMatt Roper panel->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
100333ef6d4fSMatt Roper }
100433ef6d4fSMatt Roper
10053cf05076SVille Syrjälä static void
parse_lfp_backlight(struct drm_i915_private * i915,struct intel_panel * panel)10063cf05076SVille Syrjälä parse_lfp_backlight(struct drm_i915_private *i915,
1007df0566a6SJani Nikula struct intel_panel *panel)
1008df0566a6SJani Nikula {
1009df0566a6SJani Nikula const struct bdb_lfp_backlight_data *backlight_data;
10103cf05076SVille Syrjälä const struct lfp_backlight_data_entry *entry;
1011d381baadSJosé Roberto de Souza int panel_type = panel->vbt.panel_type;
1012df0566a6SJani Nikula u16 level;
1013e163cfb4SVille Syrjälä
1014df0566a6SJani Nikula backlight_data = bdb_find_section(i915, BDB_LVDS_BACKLIGHT);
1015df0566a6SJani Nikula if (!backlight_data)
1016df0566a6SJani Nikula return;
1017df0566a6SJani Nikula
1018dbd440d8SJani Nikula if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
1019e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm,
1020df0566a6SJani Nikula "Unsupported backlight data entry size %u\n",
1021df0566a6SJani Nikula backlight_data->entry_size);
1022df0566a6SJani Nikula return;
1023df0566a6SJani Nikula }
1024df0566a6SJani Nikula
1025df0566a6SJani Nikula entry = &backlight_data->data[panel_type];
10263cf05076SVille Syrjälä
10273cf05076SVille Syrjälä panel->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
1028dbd440d8SJani Nikula if (!panel->vbt.backlight.present) {
1029e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm,
1030df0566a6SJani Nikula "PWM backlight not present in VBT (type %u)\n",
1031df0566a6SJani Nikula entry->type);
1032df0566a6SJani Nikula return;
1033df0566a6SJani Nikula }
10343cf05076SVille Syrjälä
1035a434689cSJani Nikula panel->vbt.backlight.type = INTEL_BACKLIGHT_DISPLAY_DDI;
10364378daf5SLukasz Majczak panel->vbt.backlight.controller = 0;
10374378daf5SLukasz Majczak if (i915->display.vbt.version >= 191) {
1038a434689cSJani Nikula const struct lfp_backlight_control_method *method;
10394378daf5SLukasz Majczak
1040a434689cSJani Nikula method = &backlight_data->backlight_control[panel_type];
10414378daf5SLukasz Majczak panel->vbt.backlight.type = method->type;
10424378daf5SLukasz Majczak panel->vbt.backlight.controller = method->controller;
10434378daf5SLukasz Majczak }
10444378daf5SLukasz Majczak
10454378daf5SLukasz Majczak panel->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
1046df0566a6SJani Nikula panel->vbt.backlight.active_low_pwm = entry->active_low_pwm;
1047df0566a6SJani Nikula
1048df0566a6SJani Nikula if (i915->display.vbt.version >= 234) {
10493cf05076SVille Syrjälä u16 min_level;
10503cf05076SVille Syrjälä bool scale;
1051df0566a6SJani Nikula
10524378daf5SLukasz Majczak level = backlight_data->brightness_level[panel_type].level;
1053df0566a6SJani Nikula min_level = backlight_data->brightness_min_level[panel_type].level;
10543cf05076SVille Syrjälä
10553cf05076SVille Syrjälä if (i915->display.vbt.version >= 236)
1056d381baadSJosé Roberto de Souza scale = backlight_data->brightness_precision_bits[panel_type] == 16;
1057a434689cSJani Nikula else
1058d381baadSJosé Roberto de Souza scale = level > 255;
1059d381baadSJosé Roberto de Souza
1060d381baadSJosé Roberto de Souza if (scale)
1061d381baadSJosé Roberto de Souza min_level = min_level / 255;
1062d381baadSJosé Roberto de Souza
1063d381baadSJosé Roberto de Souza if (min_level > 255) {
1064a434689cSJani Nikula drm_warn(&i915->drm, "Brightness min level > 255\n");
1065d381baadSJosé Roberto de Souza level = 255;
1066d381baadSJosé Roberto de Souza }
1067d381baadSJosé Roberto de Souza panel->vbt.backlight.min_brightness = min_level;
1068d381baadSJosé Roberto de Souza
1069d381baadSJosé Roberto de Souza panel->vbt.backlight.brightness_precision_bits =
1070d381baadSJosé Roberto de Souza backlight_data->brightness_precision_bits[panel_type];
1071d381baadSJosé Roberto de Souza } else {
1072d381baadSJosé Roberto de Souza level = backlight_data->level[panel_type];
1073dbd440d8SJani Nikula panel->vbt.backlight.min_brightness = entry->min_brightness;
1074d381baadSJosé Roberto de Souza }
1075d381baadSJosé Roberto de Souza
10763cf05076SVille Syrjälä if (i915->display.vbt.version >= 239)
107784d3d71fSLee Shawn C panel->vbt.backlight.hdr_dpcd_refresh_timeout =
10783cf05076SVille Syrjälä DIV_ROUND_UP(backlight_data->hdr_dpcd_refresh_timeout[panel_type], 100);
107984d3d71fSLee Shawn C else
1080d381baadSJosé Roberto de Souza panel->vbt.backlight.hdr_dpcd_refresh_timeout = 30;
1081d381baadSJosé Roberto de Souza
10823cf05076SVille Syrjälä drm_dbg_kms(&i915->drm,
1083d381baadSJosé Roberto de Souza "VBT backlight PWM modulation frequency %u Hz, "
1084d381baadSJosé Roberto de Souza "active %s, min brightness %u, level %u, controller %u\n",
1085dbd440d8SJani Nikula panel->vbt.backlight.pwm_freq_hz,
1086e92cbf38SWambui Karuga panel->vbt.backlight.active_low_pwm ? "low" : "high",
1087df0566a6SJani Nikula panel->vbt.backlight.min_brightness,
10883cf05076SVille Syrjälä level,
10893cf05076SVille Syrjälä panel->vbt.backlight.controller);
10903cf05076SVille Syrjälä }
1091d381baadSJosé Roberto de Souza
10923cf05076SVille Syrjälä /* Try to find sdvo panel data */
1093df0566a6SJani Nikula static void
parse_sdvo_panel_data(struct drm_i915_private * i915,struct intel_panel * panel)1094df0566a6SJani Nikula parse_sdvo_panel_data(struct drm_i915_private *i915,
1095df0566a6SJani Nikula struct intel_panel *panel)
1096df0566a6SJani Nikula {
10973cf05076SVille Syrjälä const struct bdb_sdvo_panel_dtds *dtds;
10983cf05076SVille Syrjälä struct drm_display_mode *panel_fixed_mode;
1099df0566a6SJani Nikula int index;
1100df0566a6SJani Nikula
1101df0566a6SJani Nikula index = i915->params.vbt_sdvo_panel_type;
1102df0566a6SJani Nikula if (index == -2) {
1103df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
1104dbd440d8SJani Nikula "Ignore SDVO panel mode from BIOS VBT tables.\n");
1105df0566a6SJani Nikula return;
1106dbd440d8SJani Nikula }
1107e92cbf38SWambui Karuga
1108df0566a6SJani Nikula if (index == -1) {
1109df0566a6SJani Nikula const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
1110df0566a6SJani Nikula
1111df0566a6SJani Nikula sdvo_lvds_options = bdb_find_section(i915, BDB_SDVO_LVDS_OPTIONS);
1112df0566a6SJani Nikula if (!sdvo_lvds_options)
1113df0566a6SJani Nikula return;
1114e163cfb4SVille Syrjälä
1115df0566a6SJani Nikula index = sdvo_lvds_options->panel_type;
1116df0566a6SJani Nikula }
1117df0566a6SJani Nikula
1118df0566a6SJani Nikula dtds = bdb_find_section(i915, BDB_SDVO_PANEL_DTDS);
1119df0566a6SJani Nikula if (!dtds)
1120df0566a6SJani Nikula return;
1121e163cfb4SVille Syrjälä
1122df0566a6SJani Nikula panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
1123df0566a6SJani Nikula if (!panel_fixed_mode)
1124df0566a6SJani Nikula return;
1125df0566a6SJani Nikula
1126df0566a6SJani Nikula fill_detail_timing_data(panel_fixed_mode, &dtds->dtds[index]);
1127df0566a6SJani Nikula
1128df0566a6SJani Nikula panel->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
1129df0566a6SJani Nikula
1130df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
11313cf05076SVille Syrjälä "Found SDVO panel mode in BIOS VBT tables: " DRM_MODE_FMT "\n",
1132df0566a6SJani Nikula DRM_MODE_ARG(panel_fixed_mode));
1133dbd440d8SJani Nikula }
1134f01bae2dSVille Syrjälä
intel_bios_ssc_frequency(struct drm_i915_private * i915,bool alternate)1135f01bae2dSVille Syrjälä static int intel_bios_ssc_frequency(struct drm_i915_private *i915,
1136df0566a6SJani Nikula bool alternate)
1137df0566a6SJani Nikula {
1138dbd440d8SJani Nikula switch (DISPLAY_VER(i915)) {
1139df0566a6SJani Nikula case 2:
1140df0566a6SJani Nikula return alternate ? 66667 : 48000;
1141005e9537SMatt Roper case 3:
1142df0566a6SJani Nikula case 4:
1143df0566a6SJani Nikula return alternate ? 100000 : 96000;
1144df0566a6SJani Nikula default:
1145df0566a6SJani Nikula return alternate ? 100000 : 120000;
1146df0566a6SJani Nikula }
1147df0566a6SJani Nikula }
1148df0566a6SJani Nikula
1149df0566a6SJani Nikula static void
parse_general_features(struct drm_i915_private * i915)1150df0566a6SJani Nikula parse_general_features(struct drm_i915_private *i915)
1151df0566a6SJani Nikula {
1152df0566a6SJani Nikula const struct bdb_general_features *general;
1153e163cfb4SVille Syrjälä
1154df0566a6SJani Nikula general = bdb_find_section(i915, BDB_GENERAL_FEATURES);
1155df0566a6SJani Nikula if (!general)
1156df0566a6SJani Nikula return;
1157e163cfb4SVille Syrjälä
1158df0566a6SJani Nikula i915->display.vbt.int_tv_support = general->int_tv_support;
1159df0566a6SJani Nikula /* int_crt_support can't be trusted on earlier platforms */
1160df0566a6SJani Nikula if (i915->display.vbt.version >= 155 &&
1161a434689cSJani Nikula (HAS_DDI(i915) || IS_VALLEYVIEW(i915)))
1162df0566a6SJani Nikula i915->display.vbt.int_crt_support = general->int_crt_support;
1163a434689cSJani Nikula i915->display.vbt.lvds_use_ssc = general->enable_ssc;
1164dbd440d8SJani Nikula i915->display.vbt.lvds_ssc_freq =
1165a434689cSJani Nikula intel_bios_ssc_frequency(i915, general->ssc_freq);
1166a434689cSJani Nikula i915->display.vbt.display_clock_mode = general->display_clock_mode;
1167a434689cSJani Nikula i915->display.vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
1168dbd440d8SJani Nikula if (i915->display.vbt.version >= 181) {
1169a434689cSJani Nikula i915->display.vbt.orientation = general->rotate_180 ?
1170a434689cSJani Nikula DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP :
1171a434689cSJani Nikula DRM_MODE_PANEL_ORIENTATION_NORMAL;
1172a434689cSJani Nikula } else {
1173df0566a6SJani Nikula i915->display.vbt.orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
1174df0566a6SJani Nikula }
1175df0566a6SJani Nikula
1176a434689cSJani Nikula if (i915->display.vbt.version >= 249 && general->afc_startup_config) {
1177df0566a6SJani Nikula i915->display.vbt.override_afc_startup = true;
1178b70ad01aSJosé Roberto de Souza i915->display.vbt.override_afc_startup_val = general->afc_startup_config == 0x1 ? 0x0 : 0x7;
1179a434689cSJani Nikula }
1180a434689cSJani Nikula
1181a434689cSJani Nikula drm_dbg_kms(&i915->drm,
1182b70ad01aSJosé Roberto de Souza "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",
1183b70ad01aSJosé Roberto de Souza i915->display.vbt.int_tv_support,
1184dbd440d8SJani Nikula i915->display.vbt.int_crt_support,
1185e92cbf38SWambui Karuga i915->display.vbt.lvds_use_ssc,
1186a434689cSJani Nikula i915->display.vbt.lvds_ssc_freq,
1187a434689cSJani Nikula i915->display.vbt.display_clock_mode,
1188a434689cSJani Nikula i915->display.vbt.fdi_rx_polarity_inverted);
1189a434689cSJani Nikula }
1190a434689cSJani Nikula
1191a434689cSJani Nikula static const struct child_device_config *
child_device_ptr(const struct bdb_general_definitions * defs,int i)1192df0566a6SJani Nikula child_device_ptr(const struct bdb_general_definitions *defs, int i)
1193df0566a6SJani Nikula {
1194df0566a6SJani Nikula return (const void *) &defs->devices[i * defs->child_dev_size];
1195df0566a6SJani Nikula }
1196df0566a6SJani Nikula
1197df0566a6SJani Nikula static void
parse_sdvo_device_mapping(struct drm_i915_private * i915)1198df0566a6SJani Nikula parse_sdvo_device_mapping(struct drm_i915_private *i915)
1199df0566a6SJani Nikula {
1200df0566a6SJani Nikula const struct intel_bios_encoder_data *devdata;
1201ef0096e4SJani Nikula int count = 0;
1202df0566a6SJani Nikula
1203df0566a6SJani Nikula /*
12043162d057SJani Nikula * Only parse SDVO mappings on gens that could have SDVO. This isn't
1205df0566a6SJani Nikula * accurate and doesn't have to be, as long as it's not too strict.
12060d9ef19bSJani Nikula */
1207df0566a6SJani Nikula if (!IS_DISPLAY_VER(i915, 3, 7)) {
1208df0566a6SJani Nikula drm_dbg_kms(&i915->drm, "Skipping SDVO device mapping\n");
1209df0566a6SJani Nikula return;
1210df0566a6SJani Nikula }
1211df0566a6SJani Nikula
121293e7e61eSLucas De Marchi list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) {
1213dbd440d8SJani Nikula const struct child_device_config *child = &devdata->child;
1214df0566a6SJani Nikula struct sdvo_device_mapping *mapping;
1215df0566a6SJani Nikula
1216df0566a6SJani Nikula if (child->slave_addr != SLAVE_ADDR1 &&
1217a434689cSJani Nikula child->slave_addr != SLAVE_ADDR2) {
12180d9ef19bSJani Nikula /*
1219df0566a6SJani Nikula * If the slave address is neither 0x70 nor 0x72,
1220df0566a6SJani Nikula * it is not a SDVO device. Skip it.
1221df0566a6SJani Nikula */
1222df0566a6SJani Nikula continue;
1223df0566a6SJani Nikula }
1224df0566a6SJani Nikula if (child->dvo_port != DEVICE_PORT_DVOB &&
1225df0566a6SJani Nikula child->dvo_port != DEVICE_PORT_DVOC) {
1226df0566a6SJani Nikula /* skip the incorrect SDVO port */
1227df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
1228df0566a6SJani Nikula "Incorrect SDVO port. Skip it\n");
1229df0566a6SJani Nikula continue;
1230df0566a6SJani Nikula }
1231dbd440d8SJani Nikula drm_dbg_kms(&i915->drm,
1232e92cbf38SWambui Karuga "the SDVO device with slave addr %2x is found on"
1233df0566a6SJani Nikula " %s port\n",
1234df0566a6SJani Nikula child->slave_addr,
1235dbd440d8SJani Nikula (child->dvo_port == DEVICE_PORT_DVOB) ?
1236e92cbf38SWambui Karuga "SDVOB" : "SDVOC");
1237df0566a6SJani Nikula mapping = &i915->display.vbt.sdvo_mappings[child->dvo_port - 1];
1238df0566a6SJani Nikula if (!mapping->initialized) {
1239df0566a6SJani Nikula mapping->dvo_port = child->dvo_port;
1240df0566a6SJani Nikula mapping->slave_addr = child->slave_addr;
1241a434689cSJani Nikula mapping->dvo_wiring = child->dvo_wiring;
1242df0566a6SJani Nikula mapping->ddc_pin = child->ddc_pin;
1243df0566a6SJani Nikula mapping->i2c_pin = child->i2c_pin;
1244df0566a6SJani Nikula mapping->initialized = 1;
1245df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
1246df0566a6SJani Nikula "SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
1247df0566a6SJani Nikula mapping->dvo_port, mapping->slave_addr,
1248df0566a6SJani Nikula mapping->dvo_wiring, mapping->ddc_pin,
1249dbd440d8SJani Nikula mapping->i2c_pin);
1250e92cbf38SWambui Karuga } else {
1251e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm,
1252e92cbf38SWambui Karuga "Maybe one SDVO port is shared by "
1253df0566a6SJani Nikula "two SDVO device.\n");
1254df0566a6SJani Nikula }
1255dbd440d8SJani Nikula if (child->slave2_addr) {
1256e92cbf38SWambui Karuga /* Maybe this is a SDVO device with multiple inputs */
1257df0566a6SJani Nikula /* And the mapping info is not added */
1258df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
1259df0566a6SJani Nikula "there exists the slave2_addr. Maybe this"
1260df0566a6SJani Nikula " is a SDVO device with multiple inputs.\n");
1261df0566a6SJani Nikula }
1262dbd440d8SJani Nikula count++;
1263e92cbf38SWambui Karuga }
1264df0566a6SJani Nikula
1265df0566a6SJani Nikula if (!count) {
1266df0566a6SJani Nikula /* No SDVO device info is found */
1267df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
1268df0566a6SJani Nikula "No SDVO device info is found in VBT\n");
1269df0566a6SJani Nikula }
1270df0566a6SJani Nikula }
1271dbd440d8SJani Nikula
1272e92cbf38SWambui Karuga static void
parse_driver_features(struct drm_i915_private * i915)1273df0566a6SJani Nikula parse_driver_features(struct drm_i915_private *i915)
1274df0566a6SJani Nikula {
1275df0566a6SJani Nikula const struct bdb_driver_features *driver;
1276df0566a6SJani Nikula
1277e163cfb4SVille Syrjälä driver = bdb_find_section(i915, BDB_DRIVER_FEATURES);
1278df0566a6SJani Nikula if (!driver)
1279df0566a6SJani Nikula return;
1280df0566a6SJani Nikula
1281e163cfb4SVille Syrjälä if (DISPLAY_VER(i915) >= 5) {
1282df0566a6SJani Nikula /*
1283df0566a6SJani Nikula * Note that we consider BDB_DRIVER_FEATURE_INT_SDVO_LVDS
1284df0566a6SJani Nikula * to mean "eDP". The VBT spec doesn't agree with that
1285005e9537SMatt Roper * interpretation, but real world VBTs seem to.
1286df0566a6SJani Nikula */
1287df0566a6SJani Nikula if (driver->lvds_config != BDB_DRIVER_FEATURE_INT_LVDS)
1288df0566a6SJani Nikula i915->display.vbt.int_lvds_support = 0;
1289df0566a6SJani Nikula } else {
1290df0566a6SJani Nikula /*
1291df0566a6SJani Nikula * FIXME it's not clear which BDB version has the LVDS config
1292a434689cSJani Nikula * bits defined. Revision history in the VBT spec says:
1293df0566a6SJani Nikula * "0.92 | Add two definitions for VBT value of LVDS Active
1294df0566a6SJani Nikula * Config (00b and 11b values defined) | 06/13/2005"
1295df0566a6SJani Nikula * but does not the specify the BDB version.
1296df0566a6SJani Nikula *
1297df0566a6SJani Nikula * So far version 134 (on i945gm) is the oldest VBT observed
1298df0566a6SJani Nikula * in the wild with the bits correctly populated. Version
1299df0566a6SJani Nikula * 108 (on i85x) does not have the bits correctly populated.
1300df0566a6SJani Nikula */
1301df0566a6SJani Nikula if (i915->display.vbt.version >= 134 &&
1302df0566a6SJani Nikula driver->lvds_config != BDB_DRIVER_FEATURE_INT_LVDS &&
1303df0566a6SJani Nikula driver->lvds_config != BDB_DRIVER_FEATURE_INT_SDVO_LVDS)
1304df0566a6SJani Nikula i915->display.vbt.int_lvds_support = 0;
1305a434689cSJani Nikula }
1306df0566a6SJani Nikula }
1307df0566a6SJani Nikula
1308a434689cSJani Nikula static void
parse_panel_driver_features(struct drm_i915_private * i915,struct intel_panel * panel)1309df0566a6SJani Nikula parse_panel_driver_features(struct drm_i915_private *i915,
1310c3fbcf60SVille Syrjälä struct intel_panel *panel)
1311c3fbcf60SVille Syrjälä {
1312c3fbcf60SVille Syrjälä const struct bdb_driver_features *driver;
13133cf05076SVille Syrjälä
13143cf05076SVille Syrjälä driver = bdb_find_section(i915, BDB_DRIVER_FEATURES);
1315c3fbcf60SVille Syrjälä if (!driver)
1316c3fbcf60SVille Syrjälä return;
1317c3fbcf60SVille Syrjälä
1318c3fbcf60SVille Syrjälä if (i915->display.vbt.version < 228) {
1319c3fbcf60SVille Syrjälä drm_dbg_kms(&i915->drm, "DRRS State Enabled:%d\n",
1320c3fbcf60SVille Syrjälä driver->drrs_enabled);
1321df0566a6SJani Nikula /*
1322a434689cSJani Nikula * If DRRS is not supported, drrs_type has to be set to 0.
1323dbd440d8SJani Nikula * This is because, VBT is configured in such a way that
1324e92cbf38SWambui Karuga * static DRRS is 0 and DRRS not supported is represented by
1325df0566a6SJani Nikula * driver->drrs_enabled=false
1326df0566a6SJani Nikula */
1327df0566a6SJani Nikula if (!driver->drrs_enabled && panel->vbt.drrs_type != DRRS_TYPE_NONE) {
1328df0566a6SJani Nikula /*
1329df0566a6SJani Nikula * FIXME Should DMRRS perhaps be treated as seamless
1330df0566a6SJani Nikula * but without the automatic downclocking?
13315a18db2eSVille Syrjälä */
13325a18db2eSVille Syrjälä if (driver->dmrrs_enabled)
13335a18db2eSVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_STATIC;
13345a18db2eSVille Syrjälä else
13355a18db2eSVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_NONE;
13365a18db2eSVille Syrjälä }
13375a18db2eSVille Syrjälä
13385a18db2eSVille Syrjälä panel->vbt.psr.enable = driver->psr_enabled;
13393cf05076SVille Syrjälä }
13405a18db2eSVille Syrjälä }
1341551fb93dSJosé Roberto de Souza
13423cf05076SVille Syrjälä static void
parse_power_conservation_features(struct drm_i915_private * i915,struct intel_panel * panel)1343df0566a6SJani Nikula parse_power_conservation_features(struct drm_i915_private *i915,
1344551fb93dSJosé Roberto de Souza struct intel_panel *panel)
1345551fb93dSJosé Roberto de Souza {
1346551fb93dSJosé Roberto de Souza const struct bdb_lfp_power *power;
13473cf05076SVille Syrjälä u8 panel_type = panel->vbt.panel_type;
13483cf05076SVille Syrjälä
1349551fb93dSJosé Roberto de Souza panel->vbt.vrr = true; /* matches Windows behaviour */
1350551fb93dSJosé Roberto de Souza
13513cf05076SVille Syrjälä if (i915->display.vbt.version < 228)
1352551fb93dSJosé Roberto de Souza return;
1353fba99b1aSVille Syrjälä
1354551fb93dSJosé Roberto de Souza power = bdb_find_section(i915, BDB_LFP_POWER);
1355a434689cSJani Nikula if (!power)
1356551fb93dSJosé Roberto de Souza return;
1357551fb93dSJosé Roberto de Souza
1358e163cfb4SVille Syrjälä panel->vbt.psr.enable = panel_bool(power->psr, panel_type);
1359551fb93dSJosé Roberto de Souza
1360551fb93dSJosé Roberto de Souza /*
1361551fb93dSJosé Roberto de Souza * If DRRS is not supported, drrs_type has to be set to 0.
1362a50cc495SVille Syrjälä * This is because, VBT is configured in such a way that
1363551fb93dSJosé Roberto de Souza * static DRRS is 0 and DRRS not supported is represented by
1364551fb93dSJosé Roberto de Souza * power->drrs & BIT(panel_type)=false
1365551fb93dSJosé Roberto de Souza */
1366551fb93dSJosé Roberto de Souza if (!panel_bool(power->drrs, panel_type) && panel->vbt.drrs_type != DRRS_TYPE_NONE) {
1367551fb93dSJosé Roberto de Souza /*
1368551fb93dSJosé Roberto de Souza * FIXME Should DMRRS perhaps be treated as seamless
1369551fb93dSJosé Roberto de Souza * but without the automatic downclocking?
1370a50cc495SVille Syrjälä */
13715a18db2eSVille Syrjälä if (panel_bool(power->dmrrs, panel_type))
13725a18db2eSVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_STATIC;
13735a18db2eSVille Syrjälä else
13745a18db2eSVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_NONE;
1375a50cc495SVille Syrjälä }
13765a18db2eSVille Syrjälä
13775a18db2eSVille Syrjälä if (i915->display.vbt.version >= 232)
13783cf05076SVille Syrjälä panel->vbt.edp.hobl = panel_bool(power->hobl, panel_type);
13795a18db2eSVille Syrjälä
1380f615cb6aSJosé Roberto de Souza if (i915->display.vbt.version >= 233)
1381a434689cSJani Nikula panel->vbt.vrr = panel_bool(power->vrr_feature_enabled,
1382a50cc495SVille Syrjälä panel_type);
1383fba99b1aSVille Syrjälä }
1384a434689cSJani Nikula
1385a50cc495SVille Syrjälä static void
parse_edp(struct drm_i915_private * i915,struct intel_panel * panel)1386a50cc495SVille Syrjälä parse_edp(struct drm_i915_private *i915,
1387551fb93dSJosé Roberto de Souza struct intel_panel *panel)
1388df0566a6SJani Nikula {
1389df0566a6SJani Nikula const struct bdb_edp *edp;
13903cf05076SVille Syrjälä const struct edp_power_seq *edp_pps;
13913cf05076SVille Syrjälä const struct edp_fast_link_params *edp_link_params;
1392df0566a6SJani Nikula int panel_type = panel->vbt.panel_type;
1393df0566a6SJani Nikula
1394df0566a6SJani Nikula edp = bdb_find_section(i915, BDB_EDP);
1395df0566a6SJani Nikula if (!edp)
13963cf05076SVille Syrjälä return;
1397df0566a6SJani Nikula
1398e163cfb4SVille Syrjälä switch (panel_bits(edp->color_depth, panel_type, 2)) {
1399df0566a6SJani Nikula case EDP_18BPP:
1400df0566a6SJani Nikula panel->vbt.edp.bpp = 18;
1401df0566a6SJani Nikula break;
1402a50cc495SVille Syrjälä case EDP_24BPP:
1403df0566a6SJani Nikula panel->vbt.edp.bpp = 24;
14043cf05076SVille Syrjälä break;
1405df0566a6SJani Nikula case EDP_30BPP:
1406df0566a6SJani Nikula panel->vbt.edp.bpp = 30;
14073cf05076SVille Syrjälä break;
1408df0566a6SJani Nikula }
1409df0566a6SJani Nikula
14103cf05076SVille Syrjälä /* Get the eDP sequencing and link info */
1411df0566a6SJani Nikula edp_pps = &edp->power_seqs[panel_type];
1412df0566a6SJani Nikula edp_link_params = &edp->fast_link_params[panel_type];
1413df0566a6SJani Nikula
1414df0566a6SJani Nikula panel->vbt.edp.pps = *edp_pps;
1415df0566a6SJani Nikula
1416df0566a6SJani Nikula if (i915->display.vbt.version >= 224) {
1417df0566a6SJani Nikula panel->vbt.edp.rate =
14183cf05076SVille Syrjälä edp->edp_fast_link_training_rate[panel_type] * 20;
1419df0566a6SJani Nikula } else {
1420a434689cSJani Nikula switch (edp_link_params->rate) {
1421f06d1d66SVille Syrjälä case EDP_RATE_1_62:
1422f06d1d66SVille Syrjälä panel->vbt.edp.rate = 162000;
1423f06d1d66SVille Syrjälä break;
1424df0566a6SJani Nikula case EDP_RATE_2_7:
1425df0566a6SJani Nikula panel->vbt.edp.rate = 270000;
1426f06d1d66SVille Syrjälä break;
1427df0566a6SJani Nikula case EDP_RATE_5_4:
1428df0566a6SJani Nikula panel->vbt.edp.rate = 540000;
1429f06d1d66SVille Syrjälä break;
1430f06d1d66SVille Syrjälä default:
1431f06d1d66SVille Syrjälä drm_dbg_kms(&i915->drm,
1432f06d1d66SVille Syrjälä "VBT has unknown eDP link rate value %u\n",
1433df0566a6SJani Nikula edp_link_params->rate);
1434df0566a6SJani Nikula break;
1435dbd440d8SJani Nikula }
1436e92cbf38SWambui Karuga }
1437df0566a6SJani Nikula
1438df0566a6SJani Nikula switch (edp_link_params->lanes) {
1439df0566a6SJani Nikula case EDP_LANE_1:
1440f06d1d66SVille Syrjälä panel->vbt.edp.lanes = 1;
1441df0566a6SJani Nikula break;
1442df0566a6SJani Nikula case EDP_LANE_2:
1443df0566a6SJani Nikula panel->vbt.edp.lanes = 2;
14443cf05076SVille Syrjälä break;
1445df0566a6SJani Nikula case EDP_LANE_4:
1446df0566a6SJani Nikula panel->vbt.edp.lanes = 4;
14473cf05076SVille Syrjälä break;
1448df0566a6SJani Nikula default:
1449df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
14503cf05076SVille Syrjälä "VBT has unknown eDP lane count value %u\n",
1451df0566a6SJani Nikula edp_link_params->lanes);
1452df0566a6SJani Nikula break;
1453dbd440d8SJani Nikula }
1454e92cbf38SWambui Karuga
1455df0566a6SJani Nikula switch (edp_link_params->preemphasis) {
1456df0566a6SJani Nikula case EDP_PREEMPHASIS_NONE:
1457df0566a6SJani Nikula panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
1458df0566a6SJani Nikula break;
1459df0566a6SJani Nikula case EDP_PREEMPHASIS_3_5dB:
1460df0566a6SJani Nikula panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
14613cf05076SVille Syrjälä break;
1462df0566a6SJani Nikula case EDP_PREEMPHASIS_6dB:
1463df0566a6SJani Nikula panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
14643cf05076SVille Syrjälä break;
1465df0566a6SJani Nikula case EDP_PREEMPHASIS_9_5dB:
1466df0566a6SJani Nikula panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
14673cf05076SVille Syrjälä break;
1468df0566a6SJani Nikula default:
1469df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
14703cf05076SVille Syrjälä "VBT has unknown eDP pre-emphasis value %u\n",
1471df0566a6SJani Nikula edp_link_params->preemphasis);
1472df0566a6SJani Nikula break;
1473dbd440d8SJani Nikula }
1474e92cbf38SWambui Karuga
1475df0566a6SJani Nikula switch (edp_link_params->vswing) {
1476df0566a6SJani Nikula case EDP_VSWING_0_4V:
1477df0566a6SJani Nikula panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
1478df0566a6SJani Nikula break;
1479df0566a6SJani Nikula case EDP_VSWING_0_6V:
1480df0566a6SJani Nikula panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
14813cf05076SVille Syrjälä break;
1482df0566a6SJani Nikula case EDP_VSWING_0_8V:
1483df0566a6SJani Nikula panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
14843cf05076SVille Syrjälä break;
1485df0566a6SJani Nikula case EDP_VSWING_1_2V:
1486df0566a6SJani Nikula panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
14873cf05076SVille Syrjälä break;
1488df0566a6SJani Nikula default:
1489df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
14903cf05076SVille Syrjälä "VBT has unknown eDP voltage swing value %u\n",
1491df0566a6SJani Nikula edp_link_params->vswing);
1492df0566a6SJani Nikula break;
1493dbd440d8SJani Nikula }
1494e92cbf38SWambui Karuga
1495df0566a6SJani Nikula if (i915->display.vbt.version >= 173) {
1496df0566a6SJani Nikula u8 vswing;
1497df0566a6SJani Nikula
1498df0566a6SJani Nikula /* Don't read from VBT if module parameter has valid value*/
1499a434689cSJani Nikula if (i915->params.edp_vswing) {
1500df0566a6SJani Nikula panel->vbt.edp.low_vswing =
1501df0566a6SJani Nikula i915->params.edp_vswing == 1;
1502df0566a6SJani Nikula } else {
1503dbd440d8SJani Nikula vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
15043cf05076SVille Syrjälä panel->vbt.edp.low_vswing = vswing == 0;
1505dbd440d8SJani Nikula }
1506df0566a6SJani Nikula }
1507df0566a6SJani Nikula
15083cf05076SVille Syrjälä panel->vbt.edp.drrs_msa_timing_delay =
1509df0566a6SJani Nikula panel_bits(edp->sdrrs_msa_timing_delay, panel_type, 2);
1510df0566a6SJani Nikula
1511b395c29aSVille Syrjälä if (i915->display.vbt.version >= 244)
15123cf05076SVille Syrjälä panel->vbt.edp.max_link_rate =
1513a50cc495SVille Syrjälä edp->edp_max_port_link_rate[panel_type] * 20;
151424b8b74eSVille Syrjälä }
1515a434689cSJani Nikula
151624b8b74eSVille Syrjälä static void
parse_psr(struct drm_i915_private * i915,struct intel_panel * panel)151724b8b74eSVille Syrjälä parse_psr(struct drm_i915_private *i915,
1518df0566a6SJani Nikula struct intel_panel *panel)
1519df0566a6SJani Nikula {
1520df0566a6SJani Nikula const struct bdb_psr *psr;
15213cf05076SVille Syrjälä const struct psr_table *psr_table;
15223cf05076SVille Syrjälä int panel_type = panel->vbt.panel_type;
1523df0566a6SJani Nikula
1524df0566a6SJani Nikula psr = bdb_find_section(i915, BDB_PSR);
1525df0566a6SJani Nikula if (!psr) {
15263cf05076SVille Syrjälä drm_dbg_kms(&i915->drm, "No PSR BDB found.\n");
1527df0566a6SJani Nikula return;
1528e163cfb4SVille Syrjälä }
1529df0566a6SJani Nikula
1530dbd440d8SJani Nikula psr_table = &psr->psr_table[panel_type];
1531df0566a6SJani Nikula
1532df0566a6SJani Nikula panel->vbt.psr.full_link = psr_table->full_link;
1533df0566a6SJani Nikula panel->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
1534df0566a6SJani Nikula
1535df0566a6SJani Nikula /* Allowed VBT values goes from 0 to 15 */
15363cf05076SVille Syrjälä panel->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
15373cf05076SVille Syrjälä psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
1538df0566a6SJani Nikula
1539df0566a6SJani Nikula /*
15403cf05076SVille Syrjälä * New psr options 0=500us, 1=100us, 2=2500us, 3=0us
1541df0566a6SJani Nikula * Old decimal value is wake up time in multiples of 100 us.
1542df0566a6SJani Nikula */
1543df0566a6SJani Nikula if (i915->display.vbt.version >= 205 &&
1544df0566a6SJani Nikula (DISPLAY_VER(i915) >= 9 && !IS_BROXTON(i915))) {
1545df0566a6SJani Nikula switch (psr_table->tp1_wakeup_time) {
1546df0566a6SJani Nikula case 0:
1547a434689cSJani Nikula panel->vbt.psr.tp1_wakeup_time_us = 500;
15482446e1d6SMatt Roper break;
1549df0566a6SJani Nikula case 1:
1550df0566a6SJani Nikula panel->vbt.psr.tp1_wakeup_time_us = 100;
15513cf05076SVille Syrjälä break;
1552df0566a6SJani Nikula case 3:
1553df0566a6SJani Nikula panel->vbt.psr.tp1_wakeup_time_us = 0;
15543cf05076SVille Syrjälä break;
1555df0566a6SJani Nikula default:
1556df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
15573cf05076SVille Syrjälä "VBT tp1 wakeup time value %d is outside range[0-3], defaulting to max value 2500us\n",
1558df0566a6SJani Nikula psr_table->tp1_wakeup_time);
1559df0566a6SJani Nikula fallthrough;
1560dbd440d8SJani Nikula case 2:
1561e92cbf38SWambui Karuga panel->vbt.psr.tp1_wakeup_time_us = 2500;
1562df0566a6SJani Nikula break;
1563df561f66SGustavo A. R. Silva }
1564df0566a6SJani Nikula
15653cf05076SVille Syrjälä switch (psr_table->tp2_tp3_wakeup_time) {
1566df0566a6SJani Nikula case 0:
1567df0566a6SJani Nikula panel->vbt.psr.tp2_tp3_wakeup_time_us = 500;
1568df0566a6SJani Nikula break;
1569df0566a6SJani Nikula case 1:
1570df0566a6SJani Nikula panel->vbt.psr.tp2_tp3_wakeup_time_us = 100;
15713cf05076SVille Syrjälä break;
1572df0566a6SJani Nikula case 3:
1573df0566a6SJani Nikula panel->vbt.psr.tp2_tp3_wakeup_time_us = 0;
15743cf05076SVille Syrjälä break;
1575df0566a6SJani Nikula default:
1576df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
15773cf05076SVille Syrjälä "VBT tp2_tp3 wakeup time value %d is outside range[0-3], defaulting to max value 2500us\n",
1578df0566a6SJani Nikula psr_table->tp2_tp3_wakeup_time);
1579df0566a6SJani Nikula fallthrough;
1580dbd440d8SJani Nikula case 2:
1581e92cbf38SWambui Karuga panel->vbt.psr.tp2_tp3_wakeup_time_us = 2500;
1582df0566a6SJani Nikula break;
1583df561f66SGustavo A. R. Silva }
1584df0566a6SJani Nikula } else {
15853cf05076SVille Syrjälä panel->vbt.psr.tp1_wakeup_time_us = psr_table->tp1_wakeup_time * 100;
1586df0566a6SJani Nikula panel->vbt.psr.tp2_tp3_wakeup_time_us = psr_table->tp2_tp3_wakeup_time * 100;
1587df0566a6SJani Nikula }
1588df0566a6SJani Nikula
15893cf05076SVille Syrjälä if (i915->display.vbt.version >= 226) {
15903cf05076SVille Syrjälä u32 wakeup_time = psr->psr2_tp2_tp3_wakeup_time;
1591df0566a6SJani Nikula
1592df0566a6SJani Nikula wakeup_time = panel_bits(wakeup_time, panel_type, 2);
1593a434689cSJani Nikula switch (wakeup_time) {
1594b5ea9c93SDhinakaran Pandiyan case 0:
1595df0566a6SJani Nikula wakeup_time = 500;
1596a50cc495SVille Syrjälä break;
1597df0566a6SJani Nikula case 1:
1598df0566a6SJani Nikula wakeup_time = 100;
1599df0566a6SJani Nikula break;
1600df0566a6SJani Nikula case 3:
1601df0566a6SJani Nikula wakeup_time = 50;
1602df0566a6SJani Nikula break;
1603df0566a6SJani Nikula default:
1604df0566a6SJani Nikula case 2:
1605df0566a6SJani Nikula wakeup_time = 2500;
1606df0566a6SJani Nikula break;
1607df0566a6SJani Nikula }
1608df0566a6SJani Nikula panel->vbt.psr.psr2_tp2_tp3_wakeup_time_us = wakeup_time;
1609df0566a6SJani Nikula } else {
1610df0566a6SJani Nikula /* Reusing PSR1 wakeup time for PSR2 in older VBTs */
1611df0566a6SJani Nikula panel->vbt.psr.psr2_tp2_tp3_wakeup_time_us = panel->vbt.psr.tp2_tp3_wakeup_time_us;
16123cf05076SVille Syrjälä }
1613df0566a6SJani Nikula }
1614df0566a6SJani Nikula
parse_dsi_backlight_ports(struct drm_i915_private * i915,struct intel_panel * panel,enum port port)16153cf05076SVille Syrjälä static void parse_dsi_backlight_ports(struct drm_i915_private *i915,
1616df0566a6SJani Nikula struct intel_panel *panel,
1617df0566a6SJani Nikula enum port port)
1618df0566a6SJani Nikula {
1619dbd440d8SJani Nikula enum port port_bc = DISPLAY_VER(i915) >= 11 ? PORT_B : PORT_C;
16203cf05076SVille Syrjälä
16213cf05076SVille Syrjälä if (!panel->vbt.dsi.config->dual_link || i915->display.vbt.version < 197) {
1622df0566a6SJani Nikula panel->vbt.dsi.bl_ports = BIT(port);
1623ab55165dSJani Nikula if (panel->vbt.dsi.config->cabc_supported)
1624ab55165dSJani Nikula panel->vbt.dsi.cabc_ports = BIT(port);
1625a434689cSJani Nikula
16263cf05076SVille Syrjälä return;
16273cf05076SVille Syrjälä }
16283cf05076SVille Syrjälä
1629df0566a6SJani Nikula switch (panel->vbt.dsi.config->dl_dcs_backlight_ports) {
1630df0566a6SJani Nikula case DL_DCS_PORT_A:
1631df0566a6SJani Nikula panel->vbt.dsi.bl_ports = BIT(PORT_A);
1632df0566a6SJani Nikula break;
16333cf05076SVille Syrjälä case DL_DCS_PORT_C:
1634df0566a6SJani Nikula panel->vbt.dsi.bl_ports = BIT(port_bc);
16353cf05076SVille Syrjälä break;
1636df0566a6SJani Nikula default:
1637df0566a6SJani Nikula case DL_DCS_PORT_A_AND_C:
1638ab55165dSJani Nikula panel->vbt.dsi.bl_ports = BIT(PORT_A) | BIT(port_bc);
1639df0566a6SJani Nikula break;
1640df0566a6SJani Nikula }
1641df0566a6SJani Nikula
1642ab55165dSJani Nikula if (!panel->vbt.dsi.config->cabc_supported)
1643df0566a6SJani Nikula return;
1644df0566a6SJani Nikula
1645df0566a6SJani Nikula switch (panel->vbt.dsi.config->dl_dcs_cabc_ports) {
16463cf05076SVille Syrjälä case DL_DCS_PORT_A:
1647df0566a6SJani Nikula panel->vbt.dsi.cabc_ports = BIT(PORT_A);
1648df0566a6SJani Nikula break;
16493cf05076SVille Syrjälä case DL_DCS_PORT_C:
1650df0566a6SJani Nikula panel->vbt.dsi.cabc_ports = BIT(port_bc);
16513cf05076SVille Syrjälä break;
1652df0566a6SJani Nikula default:
1653df0566a6SJani Nikula case DL_DCS_PORT_A_AND_C:
1654ab55165dSJani Nikula panel->vbt.dsi.cabc_ports =
1655df0566a6SJani Nikula BIT(PORT_A) | BIT(port_bc);
1656df0566a6SJani Nikula break;
1657df0566a6SJani Nikula }
16583cf05076SVille Syrjälä }
1659ab55165dSJani Nikula
1660df0566a6SJani Nikula static void
parse_mipi_config(struct drm_i915_private * i915,struct intel_panel * panel)1661df0566a6SJani Nikula parse_mipi_config(struct drm_i915_private *i915,
1662df0566a6SJani Nikula struct intel_panel *panel)
1663df0566a6SJani Nikula {
1664df0566a6SJani Nikula const struct bdb_mipi_config *start;
16653cf05076SVille Syrjälä const struct mipi_config *config;
16663cf05076SVille Syrjälä const struct mipi_pps_data *pps;
1667df0566a6SJani Nikula int panel_type = panel->vbt.panel_type;
1668df0566a6SJani Nikula enum port port;
1669df0566a6SJani Nikula
1670df0566a6SJani Nikula /* parse MIPI blocks only if LFP type is MIPI */
16713cf05076SVille Syrjälä if (!intel_bios_is_dsi_present(i915, &port))
1672df0566a6SJani Nikula return;
1673df0566a6SJani Nikula
1674df0566a6SJani Nikula /* Initialize this to undefined indicating no generic MIPI support */
1675dbd440d8SJani Nikula panel->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
1676df0566a6SJani Nikula
1677df0566a6SJani Nikula /* Block #40 is already parsed and panel_fixed_mode is
1678df0566a6SJani Nikula * stored in i915->lfp_lvds_vbt_mode
16793cf05076SVille Syrjälä * resuse this when needed
1680df0566a6SJani Nikula */
1681df0566a6SJani Nikula
1682dbd440d8SJani Nikula /* Parse #52 for panel index used from panel_type already
1683df0566a6SJani Nikula * parsed
1684df0566a6SJani Nikula */
1685df0566a6SJani Nikula start = bdb_find_section(i915, BDB_MIPI_CONFIG);
1686df0566a6SJani Nikula if (!start) {
1687df0566a6SJani Nikula drm_dbg_kms(&i915->drm, "No MIPI config BDB found");
1688df0566a6SJani Nikula return;
1689e163cfb4SVille Syrjälä }
1690df0566a6SJani Nikula
1691dbd440d8SJani Nikula drm_dbg(&i915->drm, "Found MIPI Config block, panel index = %d\n",
1692df0566a6SJani Nikula panel_type);
1693df0566a6SJani Nikula
1694df0566a6SJani Nikula /*
1695dbd440d8SJani Nikula * get hold of the correct configuration block and pps data as per
1696df0566a6SJani Nikula * the panel_type as index
1697df0566a6SJani Nikula */
1698df0566a6SJani Nikula config = &start->config[panel_type];
1699df0566a6SJani Nikula pps = &start->pps[panel_type];
1700df0566a6SJani Nikula
1701df0566a6SJani Nikula /* store as of now full data. Trim when we realise all is not needed */
1702df0566a6SJani Nikula panel->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
1703df0566a6SJani Nikula if (!panel->vbt.dsi.config)
1704df0566a6SJani Nikula return;
1705df0566a6SJani Nikula
17063cf05076SVille Syrjälä panel->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
17073cf05076SVille Syrjälä if (!panel->vbt.dsi.pps) {
1708df0566a6SJani Nikula kfree(panel->vbt.dsi.config);
1709df0566a6SJani Nikula return;
17103cf05076SVille Syrjälä }
17113cf05076SVille Syrjälä
17123cf05076SVille Syrjälä parse_dsi_backlight_ports(i915, panel, port);
1713df0566a6SJani Nikula
1714df0566a6SJani Nikula /* FIXME is the 90 vs. 270 correct? */
1715df0566a6SJani Nikula switch (config->rotation) {
17163cf05076SVille Syrjälä case ENABLE_ROTATION_0:
1717df0566a6SJani Nikula /*
1718df0566a6SJani Nikula * Most (all?) VBTs claim 0 degrees despite having
1719df0566a6SJani Nikula * an upside down panel, thus we do not trust this.
1720df0566a6SJani Nikula */
1721df0566a6SJani Nikula panel->vbt.dsi.orientation =
1722df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_UNKNOWN;
1723df0566a6SJani Nikula break;
1724df0566a6SJani Nikula case ENABLE_ROTATION_90:
17253cf05076SVille Syrjälä panel->vbt.dsi.orientation =
1726df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_RIGHT_UP;
1727df0566a6SJani Nikula break;
1728df0566a6SJani Nikula case ENABLE_ROTATION_180:
17293cf05076SVille Syrjälä panel->vbt.dsi.orientation =
1730df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP;
1731df0566a6SJani Nikula break;
1732df0566a6SJani Nikula case ENABLE_ROTATION_270:
17333cf05076SVille Syrjälä panel->vbt.dsi.orientation =
1734df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_LEFT_UP;
1735df0566a6SJani Nikula break;
1736df0566a6SJani Nikula }
17373cf05076SVille Syrjälä
1738df0566a6SJani Nikula /* We have mandatory mipi config blocks. Initialize as generic panel */
1739df0566a6SJani Nikula panel->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
1740df0566a6SJani Nikula }
1741df0566a6SJani Nikula
1742df0566a6SJani Nikula /* Find the sequence block and size for the given panel. */
17433cf05076SVille Syrjälä static const u8 *
find_panel_sequence_block(const struct bdb_mipi_sequence * sequence,u16 panel_id,u32 * seq_size)1744df0566a6SJani Nikula find_panel_sequence_block(const struct bdb_mipi_sequence *sequence,
1745df0566a6SJani Nikula u16 panel_id, u32 *seq_size)
1746df0566a6SJani Nikula {
1747df0566a6SJani Nikula u32 total = get_blocksize(sequence);
1748df0566a6SJani Nikula const u8 *data = &sequence->data[0];
1749df0566a6SJani Nikula u8 current_id;
1750df0566a6SJani Nikula u32 current_size;
1751df0566a6SJani Nikula int header_size = sequence->version >= 3 ? 5 : 3;
1752df0566a6SJani Nikula int index = 0;
1753df0566a6SJani Nikula int i;
1754df0566a6SJani Nikula
1755df0566a6SJani Nikula /* skip new block size */
1756df0566a6SJani Nikula if (sequence->version >= 3)
1757df0566a6SJani Nikula data += 4;
1758df0566a6SJani Nikula
1759df0566a6SJani Nikula for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index < total; i++) {
1760df0566a6SJani Nikula if (index + header_size > total) {
1761df0566a6SJani Nikula DRM_ERROR("Invalid sequence block (header)\n");
1762df0566a6SJani Nikula return NULL;
1763df0566a6SJani Nikula }
1764df0566a6SJani Nikula
1765df0566a6SJani Nikula current_id = *(data + index);
1766df0566a6SJani Nikula if (sequence->version >= 3)
1767df0566a6SJani Nikula current_size = *((const u32 *)(data + index + 1));
1768df0566a6SJani Nikula else
1769df0566a6SJani Nikula current_size = *((const u16 *)(data + index + 1));
1770df0566a6SJani Nikula
1771df0566a6SJani Nikula index += header_size;
1772df0566a6SJani Nikula
1773df0566a6SJani Nikula if (index + current_size > total) {
1774df0566a6SJani Nikula DRM_ERROR("Invalid sequence block\n");
1775df0566a6SJani Nikula return NULL;
1776df0566a6SJani Nikula }
1777df0566a6SJani Nikula
1778df0566a6SJani Nikula if (current_id == panel_id) {
1779df0566a6SJani Nikula *seq_size = current_size;
1780df0566a6SJani Nikula return data + index;
1781df0566a6SJani Nikula }
1782df0566a6SJani Nikula
1783df0566a6SJani Nikula index += current_size;
1784df0566a6SJani Nikula }
1785df0566a6SJani Nikula
1786df0566a6SJani Nikula DRM_ERROR("Sequence block detected but no valid configuration\n");
1787df0566a6SJani Nikula
1788df0566a6SJani Nikula return NULL;
1789df0566a6SJani Nikula }
1790df0566a6SJani Nikula
goto_next_sequence(const u8 * data,int index,int total)1791df0566a6SJani Nikula static int goto_next_sequence(const u8 *data, int index, int total)
1792df0566a6SJani Nikula {
1793df0566a6SJani Nikula u16 len;
1794df0566a6SJani Nikula
1795df0566a6SJani Nikula /* Skip Sequence Byte. */
1796df0566a6SJani Nikula for (index = index + 1; index < total; index += len) {
1797df0566a6SJani Nikula u8 operation_byte = *(data + index);
1798df0566a6SJani Nikula index++;
1799df0566a6SJani Nikula
1800df0566a6SJani Nikula switch (operation_byte) {
1801df0566a6SJani Nikula case MIPI_SEQ_ELEM_END:
1802df0566a6SJani Nikula return index;
1803df0566a6SJani Nikula case MIPI_SEQ_ELEM_SEND_PKT:
1804df0566a6SJani Nikula if (index + 4 > total)
1805df0566a6SJani Nikula return 0;
1806df0566a6SJani Nikula
1807df0566a6SJani Nikula len = *((const u16 *)(data + index + 2)) + 4;
1808df0566a6SJani Nikula break;
1809df0566a6SJani Nikula case MIPI_SEQ_ELEM_DELAY:
1810df0566a6SJani Nikula len = 4;
1811df0566a6SJani Nikula break;
1812df0566a6SJani Nikula case MIPI_SEQ_ELEM_GPIO:
1813df0566a6SJani Nikula len = 2;
1814df0566a6SJani Nikula break;
1815df0566a6SJani Nikula case MIPI_SEQ_ELEM_I2C:
1816df0566a6SJani Nikula if (index + 7 > total)
1817df0566a6SJani Nikula return 0;
1818df0566a6SJani Nikula len = *(data + index + 6) + 7;
1819df0566a6SJani Nikula break;
1820df0566a6SJani Nikula default:
1821df0566a6SJani Nikula DRM_ERROR("Unknown operation byte\n");
1822df0566a6SJani Nikula return 0;
1823df0566a6SJani Nikula }
1824df0566a6SJani Nikula }
1825df0566a6SJani Nikula
1826df0566a6SJani Nikula return 0;
1827df0566a6SJani Nikula }
1828df0566a6SJani Nikula
goto_next_sequence_v3(const u8 * data,int index,int total)1829df0566a6SJani Nikula static int goto_next_sequence_v3(const u8 *data, int index, int total)
1830df0566a6SJani Nikula {
1831df0566a6SJani Nikula int seq_end;
1832df0566a6SJani Nikula u16 len;
1833df0566a6SJani Nikula u32 size_of_sequence;
1834df0566a6SJani Nikula
1835df0566a6SJani Nikula /*
1836df0566a6SJani Nikula * Could skip sequence based on Size of Sequence alone, but also do some
1837df0566a6SJani Nikula * checking on the structure.
1838df0566a6SJani Nikula */
1839df0566a6SJani Nikula if (total < 5) {
1840df0566a6SJani Nikula DRM_ERROR("Too small sequence size\n");
1841df0566a6SJani Nikula return 0;
1842df0566a6SJani Nikula }
1843df0566a6SJani Nikula
1844df0566a6SJani Nikula /* Skip Sequence Byte. */
1845df0566a6SJani Nikula index++;
1846df0566a6SJani Nikula
1847df0566a6SJani Nikula /*
1848df0566a6SJani Nikula * Size of Sequence. Excludes the Sequence Byte and the size itself,
1849df0566a6SJani Nikula * includes MIPI_SEQ_ELEM_END byte, excludes the final MIPI_SEQ_END
1850df0566a6SJani Nikula * byte.
1851df0566a6SJani Nikula */
1852df0566a6SJani Nikula size_of_sequence = *((const u32 *)(data + index));
1853df0566a6SJani Nikula index += 4;
1854df0566a6SJani Nikula
1855df0566a6SJani Nikula seq_end = index + size_of_sequence;
1856df0566a6SJani Nikula if (seq_end > total) {
1857df0566a6SJani Nikula DRM_ERROR("Invalid sequence size\n");
1858df0566a6SJani Nikula return 0;
1859df0566a6SJani Nikula }
1860df0566a6SJani Nikula
1861df0566a6SJani Nikula for (; index < total; index += len) {
1862df0566a6SJani Nikula u8 operation_byte = *(data + index);
1863df0566a6SJani Nikula index++;
1864df0566a6SJani Nikula
1865df0566a6SJani Nikula if (operation_byte == MIPI_SEQ_ELEM_END) {
1866df0566a6SJani Nikula if (index != seq_end) {
1867df0566a6SJani Nikula DRM_ERROR("Invalid element structure\n");
1868df0566a6SJani Nikula return 0;
1869df0566a6SJani Nikula }
1870df0566a6SJani Nikula return index;
1871df0566a6SJani Nikula }
1872df0566a6SJani Nikula
1873df0566a6SJani Nikula len = *(data + index);
1874df0566a6SJani Nikula index++;
1875df0566a6SJani Nikula
1876df0566a6SJani Nikula /*
1877df0566a6SJani Nikula * FIXME: Would be nice to check elements like for v1/v2 in
1878df0566a6SJani Nikula * goto_next_sequence() above.
1879df0566a6SJani Nikula */
1880df0566a6SJani Nikula switch (operation_byte) {
1881df0566a6SJani Nikula case MIPI_SEQ_ELEM_SEND_PKT:
1882df0566a6SJani Nikula case MIPI_SEQ_ELEM_DELAY:
1883df0566a6SJani Nikula case MIPI_SEQ_ELEM_GPIO:
1884df0566a6SJani Nikula case MIPI_SEQ_ELEM_I2C:
1885df0566a6SJani Nikula case MIPI_SEQ_ELEM_SPI:
1886df0566a6SJani Nikula case MIPI_SEQ_ELEM_PMIC:
1887df0566a6SJani Nikula break;
1888df0566a6SJani Nikula default:
1889df0566a6SJani Nikula DRM_ERROR("Unknown operation byte %u\n",
1890df0566a6SJani Nikula operation_byte);
1891df0566a6SJani Nikula break;
1892df0566a6SJani Nikula }
1893df0566a6SJani Nikula }
1894df0566a6SJani Nikula
1895df0566a6SJani Nikula return 0;
1896df0566a6SJani Nikula }
1897df0566a6SJani Nikula
1898df0566a6SJani Nikula /*
1899df0566a6SJani Nikula * Get len of pre-fixed deassert fragment from a v1 init OTP sequence,
1900df0566a6SJani Nikula * skip all delay + gpio operands and stop at the first DSI packet op.
1901df0566a6SJani Nikula */
get_init_otp_deassert_fragment_len(struct drm_i915_private * i915,struct intel_panel * panel)1902df0566a6SJani Nikula static int get_init_otp_deassert_fragment_len(struct drm_i915_private *i915,
1903df0566a6SJani Nikula struct intel_panel *panel)
1904df0566a6SJani Nikula {
1905df0566a6SJani Nikula const u8 *data = panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP];
19063cf05076SVille Syrjälä int index, len;
19073cf05076SVille Syrjälä
1908df0566a6SJani Nikula if (drm_WARN_ON(&i915->drm,
19093cf05076SVille Syrjälä !data || panel->vbt.dsi.seq_version != 1))
1910df0566a6SJani Nikula return 0;
1911df0566a6SJani Nikula
1912dbd440d8SJani Nikula /* index = 1 to skip sequence byte */
19133cf05076SVille Syrjälä for (index = 1; data[index] != MIPI_SEQ_ELEM_END; index += len) {
1914df0566a6SJani Nikula switch (data[index]) {
1915df0566a6SJani Nikula case MIPI_SEQ_ELEM_SEND_PKT:
1916df0566a6SJani Nikula return index == 1 ? 0 : index;
1917df0566a6SJani Nikula case MIPI_SEQ_ELEM_DELAY:
1918df0566a6SJani Nikula len = 5; /* 1 byte for operand + uint32 */
1919df0566a6SJani Nikula break;
1920df0566a6SJani Nikula case MIPI_SEQ_ELEM_GPIO:
1921df0566a6SJani Nikula len = 3; /* 1 byte for op, 1 for gpio_nr, 1 for value */
1922df0566a6SJani Nikula break;
1923df0566a6SJani Nikula default:
1924df0566a6SJani Nikula return 0;
1925df0566a6SJani Nikula }
1926df0566a6SJani Nikula }
1927df0566a6SJani Nikula
1928df0566a6SJani Nikula return 0;
1929df0566a6SJani Nikula }
1930df0566a6SJani Nikula
1931df0566a6SJani Nikula /*
1932df0566a6SJani Nikula * Some v1 VBT MIPI sequences do the deassert in the init OTP sequence.
1933df0566a6SJani Nikula * The deassert must be done before calling intel_dsi_device_ready, so for
1934df0566a6SJani Nikula * these devices we split the init OTP sequence into a deassert sequence and
1935df0566a6SJani Nikula * the actual init OTP part.
1936df0566a6SJani Nikula */
vlv_fixup_mipi_sequences(struct drm_i915_private * i915,struct intel_panel * panel)1937df0566a6SJani Nikula static void vlv_fixup_mipi_sequences(struct drm_i915_private *i915,
1938df0566a6SJani Nikula struct intel_panel *panel)
1939df0566a6SJani Nikula {
1940df0566a6SJani Nikula u8 *init_otp;
19413cf05076SVille Syrjälä int len;
19423cf05076SVille Syrjälä
1943df0566a6SJani Nikula /* Limit this to v1 vid-mode sequences */
1944df0566a6SJani Nikula if (panel->vbt.dsi.config->is_cmd_mode ||
1945df0566a6SJani Nikula panel->vbt.dsi.seq_version != 1)
1946df0566a6SJani Nikula return;
1947df0566a6SJani Nikula
1948dbd440d8SJani Nikula /* Only do this if there are otp and assert seqs and no deassert seq */
1949df0566a6SJani Nikula if (!panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] ||
1950df0566a6SJani Nikula !panel->vbt.dsi.sequence[MIPI_SEQ_ASSERT_RESET] ||
1951df0566a6SJani Nikula panel->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET])
19523cf05076SVille Syrjälä return;
19533cf05076SVille Syrjälä
1954df0566a6SJani Nikula /* The deassert-sequence ends at the first DSI packet */
1955df0566a6SJani Nikula len = get_init_otp_deassert_fragment_len(i915, panel);
1956df0566a6SJani Nikula if (!len)
19573cf05076SVille Syrjälä return;
19583cf05076SVille Syrjälä
19593cf05076SVille Syrjälä drm_dbg_kms(&i915->drm,
1960df0566a6SJani Nikula "Using init OTP fragment to deassert reset\n");
1961df0566a6SJani Nikula
1962df0566a6SJani Nikula /* Copy the fragment, update seq byte and terminate it */
19633cf05076SVille Syrjälä init_otp = (u8 *)panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP];
1964df0566a6SJani Nikula panel->vbt.dsi.deassert_seq = kmemdup(init_otp, len + 1, GFP_KERNEL);
1965df0566a6SJani Nikula if (!panel->vbt.dsi.deassert_seq)
1966df0566a6SJani Nikula return;
1967dbd440d8SJani Nikula panel->vbt.dsi.deassert_seq[0] = MIPI_SEQ_DEASSERT_RESET;
1968e92cbf38SWambui Karuga panel->vbt.dsi.deassert_seq[len] = MIPI_SEQ_ELEM_END;
1969df0566a6SJani Nikula /* Use the copy for deassert */
1970df0566a6SJani Nikula panel->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET] =
19713cf05076SVille Syrjälä panel->vbt.dsi.deassert_seq;
19723cf05076SVille Syrjälä /* Replace the last byte of the fragment with init OTP seq byte */
19733cf05076SVille Syrjälä init_otp[len - 1] = MIPI_SEQ_INIT_OTP;
1974df0566a6SJani Nikula /* And make MIPI_MIPI_SEQ_INIT_OTP point to it */
19753cf05076SVille Syrjälä panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] = init_otp + len - 1;
19763cf05076SVille Syrjälä }
1977df0566a6SJani Nikula
19783cf05076SVille Syrjälä /*
19793cf05076SVille Syrjälä * Some machines (eg. Lenovo 82TQ) appear to have broken
1980df0566a6SJani Nikula * VBT sequences:
1981df0566a6SJani Nikula * - INIT_OTP is not present at all
1982df0566a6SJani Nikula * - what should be in INIT_OTP is in DISPLAY_ON
19833cf05076SVille Syrjälä * - what should be in DISPLAY_ON is in BACKLIGHT_ON
1984df0566a6SJani Nikula * (along with the actual backlight stuff)
1985df0566a6SJani Nikula *
1986df0566a6SJani Nikula * To make those work we simply swap DISPLAY_ON and INIT_OTP.
19873cf05076SVille Syrjälä *
19883cf05076SVille Syrjälä * TODO: Do we need to limit this to specific machines,
1989df0566a6SJani Nikula * or examine the contents of the sequences to
19903cf05076SVille Syrjälä * avoid false positives?
1991df0566a6SJani Nikula */
icl_fixup_mipi_sequences(struct drm_i915_private * i915,struct intel_panel * panel)1992df0566a6SJani Nikula static void icl_fixup_mipi_sequences(struct drm_i915_private *i915,
1993df0566a6SJani Nikula struct intel_panel *panel)
1994df0566a6SJani Nikula {
1995df0566a6SJani Nikula if (!panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] &&
1996df0566a6SJani Nikula panel->vbt.dsi.sequence[MIPI_SEQ_DISPLAY_ON]) {
1997df0566a6SJani Nikula drm_dbg_kms(&i915->drm, "Broken VBT: Swapping INIT_OTP and DISPLAY_ON sequences\n");
19983cf05076SVille Syrjälä
1999df0566a6SJani Nikula swap(panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP],
2000df0566a6SJani Nikula panel->vbt.dsi.sequence[MIPI_SEQ_DISPLAY_ON]);
2001e163cfb4SVille Syrjälä }
2002df0566a6SJani Nikula }
2003dbd440d8SJani Nikula
fixup_mipi_sequences(struct drm_i915_private * i915,struct intel_panel * panel)2004e92cbf38SWambui Karuga static void fixup_mipi_sequences(struct drm_i915_private *i915,
2005df0566a6SJani Nikula struct intel_panel *panel)
2006df0566a6SJani Nikula {
2007df0566a6SJani Nikula if (DISPLAY_VER(i915) >= 11)
2008df0566a6SJani Nikula icl_fixup_mipi_sequences(i915, panel);
2009df0566a6SJani Nikula else if (IS_VALLEYVIEW(i915))
2010dbd440d8SJani Nikula vlv_fixup_mipi_sequences(i915, panel);
2011e92cbf38SWambui Karuga }
2012df0566a6SJani Nikula
2013df0566a6SJani Nikula static void
parse_mipi_sequence(struct drm_i915_private * i915,struct intel_panel * panel)2014df0566a6SJani Nikula parse_mipi_sequence(struct drm_i915_private *i915,
2015df0566a6SJani Nikula struct intel_panel *panel)
2016dbd440d8SJani Nikula {
2017e92cbf38SWambui Karuga int panel_type = panel->vbt.panel_type;
2018df0566a6SJani Nikula const struct bdb_mipi_sequence *sequence;
2019df0566a6SJani Nikula const u8 *seq_data;
2020df0566a6SJani Nikula u32 seq_size;
2021df0566a6SJani Nikula u8 *data;
2022df0566a6SJani Nikula int index = 0;
2023df0566a6SJani Nikula
2024df0566a6SJani Nikula /* Only our generic panel driver uses the sequence block. */
2025df0566a6SJani Nikula if (panel->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
2026df0566a6SJani Nikula return;
2027df0566a6SJani Nikula
2028df0566a6SJani Nikula sequence = bdb_find_section(i915, BDB_MIPI_SEQUENCE);
2029df0566a6SJani Nikula if (!sequence) {
2030df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
2031df0566a6SJani Nikula "No MIPI Sequence found, parsing complete\n");
2032df0566a6SJani Nikula return;
2033df0566a6SJani Nikula }
2034dbd440d8SJani Nikula
2035e92cbf38SWambui Karuga /* Fail gracefully for forward incompatible sequence block. */
2036df0566a6SJani Nikula if (sequence->version >= 4) {
2037df0566a6SJani Nikula drm_err(&i915->drm,
2038df0566a6SJani Nikula "Unable to parse MIPI Sequence Block v%u\n",
2039df0566a6SJani Nikula sequence->version);
2040df0566a6SJani Nikula return;
2041dbd440d8SJani Nikula }
2042e92cbf38SWambui Karuga
2043df0566a6SJani Nikula drm_dbg(&i915->drm, "Found MIPI sequence block v%u\n",
20443cf05076SVille Syrjälä sequence->version);
2045df0566a6SJani Nikula
2046df0566a6SJani Nikula seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size);
2047df0566a6SJani Nikula if (!seq_data)
2048df0566a6SJani Nikula return;
2049df0566a6SJani Nikula
2050df0566a6SJani Nikula data = kmemdup(seq_data, seq_size, GFP_KERNEL);
2051dbd440d8SJani Nikula if (!data)
2052e92cbf38SWambui Karuga return;
2053df0566a6SJani Nikula
2054df0566a6SJani Nikula /* Parse the sequences, store pointers to each sequence. */
2055df0566a6SJani Nikula for (;;) {
2056df0566a6SJani Nikula u8 seq_id = *(data + index);
20573cf05076SVille Syrjälä if (seq_id == MIPI_SEQ_END)
20583cf05076SVille Syrjälä break;
20593cf05076SVille Syrjälä
2060df0566a6SJani Nikula if (seq_id >= MIPI_SEQ_MAX) {
20613cf05076SVille Syrjälä drm_err(&i915->drm, "Unknown sequence %u\n",
2062df0566a6SJani Nikula seq_id);
2063dbd440d8SJani Nikula goto err;
2064df0566a6SJani Nikula }
2065df0566a6SJani Nikula
2066df0566a6SJani Nikula /* Log about presence of sequences we won't run. */
2067df0566a6SJani Nikula if (seq_id == MIPI_SEQ_TEAR_ON || seq_id == MIPI_SEQ_TEAR_OFF)
20683cf05076SVille Syrjälä drm_dbg_kms(&i915->drm,
2069df0566a6SJani Nikula "Unsupported sequence %u\n", seq_id);
2070df0566a6SJani Nikula
20716e0d46e9SJani Nikula panel->vbt.dsi.sequence[seq_id] = data + index;
2072e163cfb4SVille Syrjälä
20736e0d46e9SJani Nikula if (sequence->version >= 3)
20746e0d46e9SJani Nikula index = goto_next_sequence_v3(data, index, seq_size);
20753162d057SJani Nikula else
20766e0d46e9SJani Nikula index = goto_next_sequence(data, index, seq_size);
20776e0d46e9SJani Nikula if (!index) {
20786e0d46e9SJani Nikula drm_err(&i915->drm, "Invalid sequence %u\n",
20796e0d46e9SJani Nikula seq_id);
2080a434689cSJani Nikula goto err;
20816e0d46e9SJani Nikula }
20826e0d46e9SJani Nikula }
2083e163cfb4SVille Syrjälä
20846e0d46e9SJani Nikula panel->vbt.dsi.data = data;
20856e0d46e9SJani Nikula panel->vbt.dsi.size = seq_size;
20866e0d46e9SJani Nikula panel->vbt.dsi.seq_version = sequence->version;
2087e92cbf38SWambui Karuga
2088e92cbf38SWambui Karuga fixup_mipi_sequences(i915, panel);
20896e0d46e9SJani Nikula
20906e0d46e9SJani Nikula drm_dbg(&i915->drm, "MIPI related VBT parsing complete\n");
20916e0d46e9SJani Nikula return;
20926e0d46e9SJani Nikula
20936e0d46e9SJani Nikula err:
2094e92cbf38SWambui Karuga kfree(data);
2095e92cbf38SWambui Karuga memset(panel->vbt.dsi.sequence, 0, sizeof(panel->vbt.dsi.sequence));
20966e0d46e9SJani Nikula }
20976e0d46e9SJani Nikula
20986e0d46e9SJani Nikula static void
parse_compression_parameters(struct drm_i915_private * i915)20996e0d46e9SJani Nikula parse_compression_parameters(struct drm_i915_private *i915)
2100a434689cSJani Nikula {
21016e0d46e9SJani Nikula const struct bdb_compression_parameters *params;
21026e0d46e9SJani Nikula struct intel_bios_encoder_data *devdata;
21036e0d46e9SJani Nikula u16 block_size;
21046e0d46e9SJani Nikula int index;
21056e0d46e9SJani Nikula
21066e0d46e9SJani Nikula if (i915->display.vbt.version < 198)
2107e92cbf38SWambui Karuga return;
2108e92cbf38SWambui Karuga
21096e0d46e9SJani Nikula params = bdb_find_section(i915, BDB_COMPRESSION_PARAMETERS);
21106e0d46e9SJani Nikula if (params) {
21116e0d46e9SJani Nikula /* Sanity checks */
21126e0d46e9SJani Nikula if (params->entry_size != sizeof(params->data[0])) {
2113e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm,
2114e92cbf38SWambui Karuga "VBT: unsupported compression param entry size\n");
21156e0d46e9SJani Nikula return;
21166e0d46e9SJani Nikula }
21176e0d46e9SJani Nikula
21186e0d46e9SJani Nikula block_size = get_blocksize(params);
21196e0d46e9SJani Nikula if (block_size < sizeof(*params)) {
21206e0d46e9SJani Nikula drm_dbg_kms(&i915->drm,
21216e0d46e9SJani Nikula "VBT: expected 16 compression param entries\n");
21226e0d46e9SJani Nikula return;
21236e0d46e9SJani Nikula }
21246e0d46e9SJani Nikula }
2125df0566a6SJani Nikula
2126df0566a6SJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) {
2127df0566a6SJani Nikula const struct child_device_config *child = &devdata->child;
2128df0566a6SJani Nikula
2129df0566a6SJani Nikula if (!child->compression_enable)
2130df0566a6SJani Nikula continue;
2131df0566a6SJani Nikula
2132df0566a6SJani Nikula if (!params) {
2133df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
2134df0566a6SJani Nikula "VBT: compression params not available\n");
2135df0566a6SJani Nikula continue;
21369e1dbc1aSJani Nikula }
21379e1dbc1aSJani Nikula
21389e1dbc1aSJani Nikula if (child->compression_method_cps) {
21399e1dbc1aSJani Nikula drm_dbg_kms(&i915->drm,
21409e1dbc1aSJani Nikula "VBT: CPS compression not supported\n");
21419e1dbc1aSJani Nikula continue;
21429e1dbc1aSJani Nikula }
21439e1dbc1aSJani Nikula
21449e1dbc1aSJani Nikula index = child->compression_structure_index;
21459e1dbc1aSJani Nikula
21469e1dbc1aSJani Nikula devdata->dsc = kmemdup(¶ms->data[index],
21479e1dbc1aSJani Nikula sizeof(*devdata->dsc), GFP_KERNEL);
21489e1dbc1aSJani Nikula }
21499e1dbc1aSJani Nikula }
21509e1dbc1aSJani Nikula
translate_iboost(u8 val)21519e1dbc1aSJani Nikula static u8 translate_iboost(u8 val)
21529e1dbc1aSJani Nikula {
21539e1dbc1aSJani Nikula static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
21549e1dbc1aSJani Nikula
21559e1dbc1aSJani Nikula if (val >= ARRAY_SIZE(mapping)) {
21569e1dbc1aSJani Nikula DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
21579e1dbc1aSJani Nikula return 0;
21589e1dbc1aSJani Nikula }
21599e1dbc1aSJani Nikula return mapping[val];
21609e1dbc1aSJani Nikula }
21619e1dbc1aSJani Nikula
21629e1dbc1aSJani Nikula static const u8 cnp_ddc_pin_map[] = {
21639e1dbc1aSJani Nikula [0] = 0, /* N/A */
21649e1dbc1aSJani Nikula [GMBUS_PIN_1_BXT] = DDC_BUS_DDI_B,
21659e1dbc1aSJani Nikula [GMBUS_PIN_2_BXT] = DDC_BUS_DDI_C,
21669e1dbc1aSJani Nikula [GMBUS_PIN_4_CNP] = DDC_BUS_DDI_D, /* sic */
21679e1dbc1aSJani Nikula [GMBUS_PIN_3_BXT] = DDC_BUS_DDI_F, /* sic */
21689e1dbc1aSJani Nikula };
21699e1dbc1aSJani Nikula
21709e1dbc1aSJani Nikula static const u8 icp_ddc_pin_map[] = {
21719e1dbc1aSJani Nikula [GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A,
21729e1dbc1aSJani Nikula [GMBUS_PIN_2_BXT] = ICL_DDC_BUS_DDI_B,
21739e1dbc1aSJani Nikula [GMBUS_PIN_3_BXT] = TGL_DDC_BUS_DDI_C,
21749e1dbc1aSJani Nikula [GMBUS_PIN_9_TC1_ICP] = ICL_DDC_BUS_PORT_1,
21759e1dbc1aSJani Nikula [GMBUS_PIN_10_TC2_ICP] = ICL_DDC_BUS_PORT_2,
21769e1dbc1aSJani Nikula [GMBUS_PIN_11_TC3_ICP] = ICL_DDC_BUS_PORT_3,
2177af10ec31STejas Upadhyay [GMBUS_PIN_12_TC4_ICP] = ICL_DDC_BUS_PORT_4,
2178af10ec31STejas Upadhyay [GMBUS_PIN_13_TC5_TGP] = TGL_DDC_BUS_PORT_5,
2179af10ec31STejas Upadhyay [GMBUS_PIN_14_TC6_TGP] = TGL_DDC_BUS_PORT_6,
2180af10ec31STejas Upadhyay };
2181af10ec31STejas Upadhyay
2182af10ec31STejas Upadhyay static const u8 rkl_pch_tgp_ddc_pin_map[] = {
2183af10ec31STejas Upadhyay [GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A,
2184af10ec31STejas Upadhyay [GMBUS_PIN_2_BXT] = ICL_DDC_BUS_DDI_B,
2185af10ec31STejas Upadhyay [GMBUS_PIN_9_TC1_ICP] = RKL_DDC_BUS_DDI_D,
21869e1dbc1aSJani Nikula [GMBUS_PIN_10_TC2_ICP] = RKL_DDC_BUS_DDI_E,
21879e1dbc1aSJani Nikula };
21889e1dbc1aSJani Nikula
21899e1dbc1aSJani Nikula static const u8 adls_ddc_pin_map[] = {
21909e1dbc1aSJani Nikula [GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A,
2191cf867d6aSRadhakrishna Sripada [GMBUS_PIN_9_TC1_ICP] = ADLS_DDC_BUS_PORT_TC1,
2192af10ec31STejas Upadhyay [GMBUS_PIN_10_TC2_ICP] = ADLS_DDC_BUS_PORT_TC2,
2193af10ec31STejas Upadhyay [GMBUS_PIN_11_TC3_ICP] = ADLS_DDC_BUS_PORT_TC3,
2194af10ec31STejas Upadhyay [GMBUS_PIN_12_TC4_ICP] = ADLS_DDC_BUS_PORT_TC4,
21959e1dbc1aSJani Nikula };
21969e1dbc1aSJani Nikula
21979e1dbc1aSJani Nikula static const u8 gen9bc_tgp_ddc_pin_map[] = {
21989e1dbc1aSJani Nikula [GMBUS_PIN_2_BXT] = DDC_BUS_DDI_B,
21999e1dbc1aSJani Nikula [GMBUS_PIN_9_TC1_ICP] = DDC_BUS_DDI_C,
22009e1dbc1aSJani Nikula [GMBUS_PIN_10_TC2_ICP] = DDC_BUS_DDI_D,
22019e1dbc1aSJani Nikula };
22029e1dbc1aSJani Nikula
22039e1dbc1aSJani Nikula static const u8 adlp_ddc_pin_map[] = {
22049e1dbc1aSJani Nikula [GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A,
22059e1dbc1aSJani Nikula [GMBUS_PIN_2_BXT] = ICL_DDC_BUS_DDI_B,
22069e1dbc1aSJani Nikula [GMBUS_PIN_9_TC1_ICP] = ADLP_DDC_BUS_PORT_TC1,
22079e1dbc1aSJani Nikula [GMBUS_PIN_10_TC2_ICP] = ADLP_DDC_BUS_PORT_TC2,
22089e1dbc1aSJani Nikula [GMBUS_PIN_11_TC3_ICP] = ADLP_DDC_BUS_PORT_TC3,
22099e1dbc1aSJani Nikula [GMBUS_PIN_12_TC4_ICP] = ADLP_DDC_BUS_PORT_TC4,
22109e1dbc1aSJani Nikula };
22119e1dbc1aSJani Nikula
map_ddc_pin(struct drm_i915_private * i915,u8 vbt_pin)22129e1dbc1aSJani Nikula static u8 map_ddc_pin(struct drm_i915_private *i915, u8 vbt_pin)
22139e1dbc1aSJani Nikula {
22149e1dbc1aSJani Nikula const u8 *ddc_pin_map;
22159e1dbc1aSJani Nikula int i, n_entries;
22169e1dbc1aSJani Nikula
22179e1dbc1aSJani Nikula if (HAS_PCH_MTP(i915) || IS_ALDERLAKE_P(i915)) {
22189e1dbc1aSJani Nikula ddc_pin_map = adlp_ddc_pin_map;
22199e1dbc1aSJani Nikula n_entries = ARRAY_SIZE(adlp_ddc_pin_map);
22209e1dbc1aSJani Nikula } else if (IS_ALDERLAKE_S(i915)) {
22219e1dbc1aSJani Nikula ddc_pin_map = adls_ddc_pin_map;
22229e1dbc1aSJani Nikula n_entries = ARRAY_SIZE(adls_ddc_pin_map);
22239e1dbc1aSJani Nikula } else if (INTEL_PCH_TYPE(i915) >= PCH_DG1) {
22249e1dbc1aSJani Nikula return vbt_pin;
2225df0566a6SJani Nikula } else if (IS_ROCKETLAKE(i915) && INTEL_PCH_TYPE(i915) == PCH_TGP) {
2226df0566a6SJani Nikula ddc_pin_map = rkl_pch_tgp_ddc_pin_map;
22275a449e58SJani Nikula n_entries = ARRAY_SIZE(rkl_pch_tgp_ddc_pin_map);
2228df0566a6SJani Nikula } else if (HAS_PCH_TGP(i915) && DISPLAY_VER(i915) == 9) {
2229df0566a6SJani Nikula ddc_pin_map = gen9bc_tgp_ddc_pin_map;
223095bbede5SJani Nikula n_entries = ARRAY_SIZE(gen9bc_tgp_ddc_pin_map);
223195bbede5SJani Nikula } else if (INTEL_PCH_TYPE(i915) >= PCH_ICP) {
223295bbede5SJani Nikula ddc_pin_map = icp_ddc_pin_map;
2233c4a774c4SJani Nikula n_entries = ARRAY_SIZE(icp_ddc_pin_map);
2234a434689cSJani Nikula } else if (HAS_PCH_CNP(i915)) {
2235df0566a6SJani Nikula ddc_pin_map = cnp_ddc_pin_map;
22365a449e58SJani Nikula n_entries = ARRAY_SIZE(cnp_ddc_pin_map);
2237df0566a6SJani Nikula } else {
2238df0566a6SJani Nikula /* Assuming direct map */
2239df0566a6SJani Nikula return vbt_pin;
2240df0566a6SJani Nikula }
2241df0566a6SJani Nikula
2242df0566a6SJani Nikula for (i = 0; i < n_entries; i++) {
2243dab8477bSJani Nikula if (ddc_pin_map[i] == vbt_pin)
2244df0566a6SJani Nikula return i;
2245df0566a6SJani Nikula }
2246dab8477bSJani Nikula
224745c0673aSJani Nikula drm_dbg_kms(&i915->drm,
2248dab8477bSJani Nikula "Ignoring alternate pin: VBT claims DDC pin %d, which is not valid for this platform\n",
2249df0566a6SJani Nikula vbt_pin);
2250df0566a6SJani Nikula return 0;
2251dab8477bSJani Nikula }
2252dab8477bSJani Nikula
dvo_port_type(u8 dvo_port)2253dab8477bSJani Nikula static u8 dvo_port_type(u8 dvo_port)
2254dab8477bSJani Nikula {
2255dab8477bSJani Nikula switch (dvo_port) {
2256dab8477bSJani Nikula case DVO_PORT_HDMIA:
2257dab8477bSJani Nikula case DVO_PORT_HDMIB:
2258dab8477bSJani Nikula case DVO_PORT_HDMIC:
2259dab8477bSJani Nikula case DVO_PORT_HDMID:
2260dab8477bSJani Nikula case DVO_PORT_HDMIE:
2261dab8477bSJani Nikula case DVO_PORT_HDMIF:
2262dab8477bSJani Nikula case DVO_PORT_HDMIG:
2263dab8477bSJani Nikula case DVO_PORT_HDMIH:
2264dab8477bSJani Nikula case DVO_PORT_HDMII:
2265894d1739SJani Nikula return DVO_PORT_HDMIA;
2266894d1739SJani Nikula case DVO_PORT_DPA:
2267894d1739SJani Nikula case DVO_PORT_DPB:
2268dbd440d8SJani Nikula case DVO_PORT_DPC:
2269e92cbf38SWambui Karuga case DVO_PORT_DPD:
2270df0566a6SJani Nikula case DVO_PORT_DPE:
2271dab8477bSJani Nikula case DVO_PORT_DPF:
227241e35ffbSVille Syrjälä case DVO_PORT_DPG:
2273df0566a6SJani Nikula case DVO_PORT_DPH:
2274df0566a6SJani Nikula case DVO_PORT_DPI:
2275894d1739SJani Nikula return DVO_PORT_DPA;
2276894d1739SJani Nikula case DVO_PORT_MIPIA:
2277894d1739SJani Nikula case DVO_PORT_MIPIB:
2278df0566a6SJani Nikula case DVO_PORT_MIPIC:
2279894d1739SJani Nikula case DVO_PORT_MIPID:
2280894d1739SJani Nikula return DVO_PORT_MIPIA;
2281894d1739SJani Nikula default:
2282df0566a6SJani Nikula return dvo_port;
2283a434689cSJani Nikula }
228441e35ffbSVille Syrjälä }
228545c0673aSJani Nikula
__dvo_port_to_port(int n_ports,int n_dvo,const int port_mapping[][3],u8 dvo_port)228645c0673aSJani Nikula static enum port __dvo_port_to_port(int n_ports, int n_dvo,
228745c0673aSJani Nikula const int port_mapping[][3], u8 dvo_port)
2288dab8477bSJani Nikula {
2289df0566a6SJani Nikula enum port port;
2290df0566a6SJani Nikula int i;
2291df0566a6SJani Nikula
2292df0566a6SJani Nikula for (port = PORT_A; port < n_ports; port++) {
22935a449e58SJani Nikula for (i = 0; i < n_dvo; i++) {
2294df0566a6SJani Nikula if (port_mapping[port][i] == -1)
2295df0566a6SJani Nikula break;
229695bbede5SJani Nikula
229795bbede5SJani Nikula if (dvo_port == port_mapping[port][i])
229895bbede5SJani Nikula return port;
2299c4a774c4SJani Nikula }
2300a434689cSJani Nikula }
2301df0566a6SJani Nikula
23025a449e58SJani Nikula return PORT_NONE;
2303df0566a6SJani Nikula }
2304df0566a6SJani Nikula
dvo_port_to_port(struct drm_i915_private * i915,u8 dvo_port)2305df0566a6SJani Nikula static enum port dvo_port_to_port(struct drm_i915_private *i915,
2306df0566a6SJani Nikula u8 dvo_port)
2307df0566a6SJani Nikula {
2308df0566a6SJani Nikula /*
230911182986SJani Nikula * Each DDI port can have more than one value on the "DVO Port" field,
2310df0566a6SJani Nikula * so look for all the possible values for each port.
2311df0566a6SJani Nikula */
231211182986SJani Nikula static const int port_mapping[][3] = {
231345c0673aSJani Nikula [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
2314df0566a6SJani Nikula [PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
2315df0566a6SJani Nikula [PORT_C] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
231611182986SJani Nikula [PORT_D] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
2317894d1739SJani Nikula [PORT_E] = { DVO_PORT_HDMIE, DVO_PORT_DPE, DVO_PORT_CRT },
2318894d1739SJani Nikula [PORT_F] = { DVO_PORT_HDMIF, DVO_PORT_DPF, -1 },
2319894d1739SJani Nikula [PORT_G] = { DVO_PORT_HDMIG, DVO_PORT_DPG, -1 },
2320dbd440d8SJani Nikula [PORT_H] = { DVO_PORT_HDMIH, DVO_PORT_DPH, -1 },
2321e92cbf38SWambui Karuga [PORT_I] = { DVO_PORT_HDMII, DVO_PORT_DPI, -1 },
2322df0566a6SJani Nikula };
232311182986SJani Nikula /*
232441e35ffbSVille Syrjälä * RKL VBT uses PHY based mapping. Combo PHYs A,B,C,D
2325df0566a6SJani Nikula * map to DDI A,B,TC1,TC2 respectively.
2326df0566a6SJani Nikula */
2327894d1739SJani Nikula static const int rkl_port_mapping[][3] = {
2328894d1739SJani Nikula [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
2329894d1739SJani Nikula [PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
2330df0566a6SJani Nikula [PORT_C] = { -1 },
2331894d1739SJani Nikula [PORT_TC1] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
2332894d1739SJani Nikula [PORT_TC2] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
2333894d1739SJani Nikula };
2334df0566a6SJani Nikula /*
2335a434689cSJani Nikula * Alderlake S ports used in the driver are PORT_A, PORT_D, PORT_E,
233641e35ffbSVille Syrjälä * PORT_F and PORT_G, we need to map that to correct VBT sections.
233745c0673aSJani Nikula */
233811182986SJani Nikula static const int adls_port_mapping[][3] = {
2339df0566a6SJani Nikula [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
2340df0566a6SJani Nikula [PORT_B] = { -1 },
234132c2bc89SVille Syrjälä [PORT_C] = { -1 },
234232c2bc89SVille Syrjälä [PORT_TC1] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
234332c2bc89SVille Syrjälä [PORT_TC2] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
234432c2bc89SVille Syrjälä [PORT_TC3] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
234532c2bc89SVille Syrjälä [PORT_TC4] = { DVO_PORT_HDMIE, DVO_PORT_DPE, -1 },
234632c2bc89SVille Syrjälä };
234732c2bc89SVille Syrjälä static const int xelpd_port_mapping[][3] = {
234832c2bc89SVille Syrjälä [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 },
234932c2bc89SVille Syrjälä [PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 },
235032c2bc89SVille Syrjälä [PORT_C] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 },
235132c2bc89SVille Syrjälä [PORT_D_XELPD] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 },
235232c2bc89SVille Syrjälä [PORT_E_XELPD] = { DVO_PORT_HDMIE, DVO_PORT_DPE, -1 },
235332c2bc89SVille Syrjälä [PORT_TC1] = { DVO_PORT_HDMIF, DVO_PORT_DPF, -1 },
235432c2bc89SVille Syrjälä [PORT_TC2] = { DVO_PORT_HDMIG, DVO_PORT_DPG, -1 },
235532c2bc89SVille Syrjälä [PORT_TC3] = { DVO_PORT_HDMIH, DVO_PORT_DPH, -1 },
235632c2bc89SVille Syrjälä [PORT_TC4] = { DVO_PORT_HDMII, DVO_PORT_DPI, -1 },
235732c2bc89SVille Syrjälä };
235832c2bc89SVille Syrjälä
235932c2bc89SVille Syrjälä if (DISPLAY_VER(i915) >= 13)
236032c2bc89SVille Syrjälä return __dvo_port_to_port(ARRAY_SIZE(xelpd_port_mapping),
236132c2bc89SVille Syrjälä ARRAY_SIZE(xelpd_port_mapping[0]),
236232c2bc89SVille Syrjälä xelpd_port_mapping,
236332c2bc89SVille Syrjälä dvo_port);
236432c2bc89SVille Syrjälä else if (IS_ALDERLAKE_S(i915))
236532c2bc89SVille Syrjälä return __dvo_port_to_port(ARRAY_SIZE(adls_port_mapping),
236632c2bc89SVille Syrjälä ARRAY_SIZE(adls_port_mapping[0]),
236732c2bc89SVille Syrjälä adls_port_mapping,
236832c2bc89SVille Syrjälä dvo_port);
236932c2bc89SVille Syrjälä else if (IS_DG1(i915) || IS_ROCKETLAKE(i915))
237032c2bc89SVille Syrjälä return __dvo_port_to_port(ARRAY_SIZE(rkl_port_mapping),
237132c2bc89SVille Syrjälä ARRAY_SIZE(rkl_port_mapping[0]),
237232c2bc89SVille Syrjälä rkl_port_mapping,
237332c2bc89SVille Syrjälä dvo_port);
23744628142aSLucas De Marchi else
23754628142aSLucas De Marchi return __dvo_port_to_port(ARRAY_SIZE(port_mapping),
2376df0566a6SJani Nikula ARRAY_SIZE(port_mapping[0]),
2377df0566a6SJani Nikula port_mapping,
2378df0566a6SJani Nikula dvo_port);
2379df0566a6SJani Nikula }
23804628142aSLucas De Marchi
23814628142aSLucas De Marchi static enum port
dsi_dvo_port_to_port(struct drm_i915_private * i915,u8 dvo_port)23824628142aSLucas De Marchi dsi_dvo_port_to_port(struct drm_i915_private *i915, u8 dvo_port)
2383df0566a6SJani Nikula {
2384df0566a6SJani Nikula switch (dvo_port) {
23854628142aSLucas De Marchi case DVO_PORT_MIPIA:
2386df0566a6SJani Nikula return PORT_A;
2387df0566a6SJani Nikula case DVO_PORT_MIPIC:
2388df0566a6SJani Nikula if (DISPLAY_VER(i915) >= 11)
2389df0566a6SJani Nikula return PORT_B;
2390df0566a6SJani Nikula else
2391df0566a6SJani Nikula return PORT_C;
2392df0566a6SJani Nikula default:
2393dbd440d8SJani Nikula return PORT_NONE;
23944628142aSLucas De Marchi }
23954628142aSLucas De Marchi }
23964628142aSLucas De Marchi
intel_bios_encoder_port(const struct intel_bios_encoder_data * devdata)23974628142aSLucas De Marchi enum port intel_bios_encoder_port(const struct intel_bios_encoder_data *devdata)
23984628142aSLucas De Marchi {
23994628142aSLucas De Marchi struct drm_i915_private *i915 = devdata->i915;
24004628142aSLucas De Marchi const struct child_device_config *child = &devdata->child;
24014628142aSLucas De Marchi enum port port;
24024628142aSLucas De Marchi
24034628142aSLucas De Marchi port = dvo_port_to_port(i915, child->dvo_port);
24044628142aSLucas De Marchi if (port == PORT_NONE && DISPLAY_VER(i915) >= 11)
24058c1a8f12SMatt Roper port = dsi_dvo_port_to_port(i915, child->dvo_port);
24064628142aSLucas De Marchi
24074628142aSLucas De Marchi return port;
2408176430ccSVille Syrjälä }
2409176430ccSVille Syrjälä
parse_bdb_230_dp_max_link_rate(const int vbt_max_link_rate)24104628142aSLucas De Marchi static int parse_bdb_230_dp_max_link_rate(const int vbt_max_link_rate)
24114628142aSLucas De Marchi {
24121d8ca002SVille Syrjälä switch (vbt_max_link_rate) {
24131d8ca002SVille Syrjälä default:
24144628142aSLucas De Marchi case BDB_230_VBT_DP_MAX_LINK_RATE_DEF:
24154628142aSLucas De Marchi return 0;
24164628142aSLucas De Marchi case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR20:
24174628142aSLucas De Marchi return 2000000;
24184628142aSLucas De Marchi case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR13P5:
24191d8ca002SVille Syrjälä return 1350000;
24201d8ca002SVille Syrjälä case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR10:
24214628142aSLucas De Marchi return 1000000;
242218c283dfSAditya Swarup case BDB_230_VBT_DP_MAX_LINK_RATE_HBR3:
242318c283dfSAditya Swarup return 810000;
242418c283dfSAditya Swarup case BDB_230_VBT_DP_MAX_LINK_RATE_HBR2:
242518c283dfSAditya Swarup return 540000;
242618c283dfSAditya Swarup case BDB_230_VBT_DP_MAX_LINK_RATE_HBR:
242718c283dfSAditya Swarup return 270000;
242818c283dfSAditya Swarup case BDB_230_VBT_DP_MAX_LINK_RATE_LBR:
242918c283dfSAditya Swarup return 162000;
243018c283dfSAditya Swarup }
243118c283dfSAditya Swarup }
243218c283dfSAditya Swarup
parse_bdb_216_dp_max_link_rate(const int vbt_max_link_rate)243318c283dfSAditya Swarup static int parse_bdb_216_dp_max_link_rate(const int vbt_max_link_rate)
243418c283dfSAditya Swarup {
2435eeb63c54SJosé Roberto de Souza switch (vbt_max_link_rate) {
2436eeb63c54SJosé Roberto de Souza default:
2437eeb63c54SJosé Roberto de Souza case BDB_216_VBT_DP_MAX_LINK_RATE_HBR3:
2438eeb63c54SJosé Roberto de Souza return 810000;
2439eeb63c54SJosé Roberto de Souza case BDB_216_VBT_DP_MAX_LINK_RATE_HBR2:
2440eeb63c54SJosé Roberto de Souza return 540000;
2441eeb63c54SJosé Roberto de Souza case BDB_216_VBT_DP_MAX_LINK_RATE_HBR:
2442eeb63c54SJosé Roberto de Souza return 270000;
2443eeb63c54SJosé Roberto de Souza case BDB_216_VBT_DP_MAX_LINK_RATE_LBR:
2444eeb63c54SJosé Roberto de Souza return 162000;
2445eeb63c54SJosé Roberto de Souza }
24464628142aSLucas De Marchi }
2447612dc414SImre Deak
intel_bios_dp_max_link_rate(const struct intel_bios_encoder_data * devdata)2448eeb63c54SJosé Roberto de Souza int intel_bios_dp_max_link_rate(const struct intel_bios_encoder_data *devdata)
2449eeb63c54SJosé Roberto de Souza {
2450eeb63c54SJosé Roberto de Souza if (!devdata || devdata->i915->display.vbt.version < 216)
2451eeb63c54SJosé Roberto de Souza return 0;
2452eeb63c54SJosé Roberto de Souza
245318c283dfSAditya Swarup if (devdata->i915->display.vbt.version >= 230)
245418c283dfSAditya Swarup return parse_bdb_230_dp_max_link_rate(devdata->child.dp_max_link_rate);
245518c283dfSAditya Swarup else
245618c283dfSAditya Swarup return parse_bdb_216_dp_max_link_rate(devdata->child.dp_max_link_rate);
2457dbd440d8SJani Nikula }
24584628142aSLucas De Marchi
intel_bios_dp_max_lane_count(const struct intel_bios_encoder_data * devdata)24594628142aSLucas De Marchi int intel_bios_dp_max_lane_count(const struct intel_bios_encoder_data *devdata)
24604628142aSLucas De Marchi {
24614628142aSLucas De Marchi if (!devdata || devdata->i915->display.vbt.version < 244)
24624628142aSLucas De Marchi return 0;
24634628142aSLucas De Marchi
24644628142aSLucas De Marchi return devdata->child.dp_max_lane_count + 1;
24654628142aSLucas De Marchi }
24664628142aSLucas De Marchi
sanitize_device_type(struct intel_bios_encoder_data * devdata,enum port port)24674628142aSLucas De Marchi static void sanitize_device_type(struct intel_bios_encoder_data *devdata,
24684628142aSLucas De Marchi enum port port)
2469b60e320bSLee Shawn C {
2470b60e320bSLee Shawn C struct drm_i915_private *i915 = devdata->i915;
2471b60e320bSLee Shawn C bool is_hdmi;
2472b60e320bSLee Shawn C
2473b60e320bSLee Shawn C if (port != PORT_A || DISPLAY_VER(i915) >= 12)
2474b60e320bSLee Shawn C return;
2475b60e320bSLee Shawn C
2476b60e320bSLee Shawn C if (!intel_bios_encoder_supports_dvi(devdata))
2477b60e320bSLee Shawn C return;
2478b60e320bSLee Shawn C
2479b60e320bSLee Shawn C is_hdmi = intel_bios_encoder_supports_hdmi(devdata);
2480b60e320bSLee Shawn C
2481b60e320bSLee Shawn C drm_dbg_kms(&i915->drm, "VBT claims port A supports DVI%s, ignoring\n",
2482b60e320bSLee Shawn C is_hdmi ? "/HDMI" : "");
2483b60e320bSLee Shawn C
2484b60e320bSLee Shawn C devdata->child.device_type &= ~DEVICE_TYPE_TMDS_DVI_SIGNALING;
2485b60e320bSLee Shawn C devdata->child.device_type |= DEVICE_TYPE_NOT_HDMI_OUTPUT;
2486b60e320bSLee Shawn C }
2487b60e320bSLee Shawn C
2488b60e320bSLee Shawn C static bool
intel_bios_encoder_supports_crt(const struct intel_bios_encoder_data * devdata)2489b60e320bSLee Shawn C intel_bios_encoder_supports_crt(const struct intel_bios_encoder_data *devdata)
2490b60e320bSLee Shawn C {
2491b60e320bSLee Shawn C return devdata->child.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
2492b60e320bSLee Shawn C }
2493b60e320bSLee Shawn C
2494b60e320bSLee Shawn C bool
intel_bios_encoder_supports_dvi(const struct intel_bios_encoder_data * devdata)2495b60e320bSLee Shawn C intel_bios_encoder_supports_dvi(const struct intel_bios_encoder_data *devdata)
2496b60e320bSLee Shawn C {
2497b60e320bSLee Shawn C return devdata->child.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
2498b60e320bSLee Shawn C }
2499b60e320bSLee Shawn C
2500b60e320bSLee Shawn C bool
intel_bios_encoder_supports_hdmi(const struct intel_bios_encoder_data * devdata)2501b60e320bSLee Shawn C intel_bios_encoder_supports_hdmi(const struct intel_bios_encoder_data *devdata)
2502b60e320bSLee Shawn C {
2503b60e320bSLee Shawn C return intel_bios_encoder_supports_dvi(devdata) &&
2504b60e320bSLee Shawn C (devdata->child.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
2505b60e320bSLee Shawn C }
2506b60e320bSLee Shawn C
250772337aacSJani Nikula bool
intel_bios_encoder_supports_dp(const struct intel_bios_encoder_data * devdata)250872337aacSJani Nikula intel_bios_encoder_supports_dp(const struct intel_bios_encoder_data *devdata)
2509a434689cSJani Nikula {
251072337aacSJani Nikula return devdata->child.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
251172337aacSJani Nikula }
2512a434689cSJani Nikula
251372337aacSJani Nikula bool
intel_bios_encoder_supports_edp(const struct intel_bios_encoder_data * devdata)251472337aacSJani Nikula intel_bios_encoder_supports_edp(const struct intel_bios_encoder_data *devdata)
251572337aacSJani Nikula {
251672337aacSJani Nikula return intel_bios_encoder_supports_dp(devdata) &&
251772337aacSJani Nikula devdata->child.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR;
25184182a311SVille Syrjälä }
25194182a311SVille Syrjälä
25204182a311SVille Syrjälä bool
intel_bios_encoder_supports_dsi(const struct intel_bios_encoder_data * devdata)25214182a311SVille Syrjälä intel_bios_encoder_supports_dsi(const struct intel_bios_encoder_data *devdata)
25224182a311SVille Syrjälä {
25234182a311SVille Syrjälä return devdata->child.device_type & DEVICE_TYPE_MIPI_OUTPUT;
25244182a311SVille Syrjälä }
25254182a311SVille Syrjälä
2526d0ab409dSJani Nikula bool
intel_bios_encoder_is_lspcon(const struct intel_bios_encoder_data * devdata)2527d0ab409dSJani Nikula intel_bios_encoder_is_lspcon(const struct intel_bios_encoder_data *devdata)
2528d0ab409dSJani Nikula {
2529d0ab409dSJani Nikula return devdata && HAS_LSPCON(devdata->i915) && devdata->child.lspcon;
2530d0ab409dSJani Nikula }
2531d0ab409dSJani Nikula
2532005e9537SMatt Roper /* This is an index in the HDMI/DVI DDI buffer translation table, or -1 */
intel_bios_hdmi_level_shift(const struct intel_bios_encoder_data * devdata)2533d0ab409dSJani Nikula int intel_bios_hdmi_level_shift(const struct intel_bios_encoder_data *devdata)
2534d0ab409dSJani Nikula {
253586996822SJani Nikula if (!devdata || devdata->i915->display.vbt.version < 158 ||
2536d0ab409dSJani Nikula DISPLAY_VER(devdata->i915) >= 14)
2537d0ab409dSJani Nikula return -1;
253886996822SJani Nikula
2539d0ab409dSJani Nikula return devdata->child.hdmi_level_shifter_value;
2540d0ab409dSJani Nikula }
2541d0ab409dSJani Nikula
intel_bios_hdmi_max_tmds_clock(const struct intel_bios_encoder_data * devdata)2542d0ab409dSJani Nikula int intel_bios_hdmi_max_tmds_clock(const struct intel_bios_encoder_data *devdata)
2543d0ab409dSJani Nikula {
2544d0ab409dSJani Nikula if (!devdata || devdata->i915->display.vbt.version < 204)
2545d0ab409dSJani Nikula return 0;
2546d0ab409dSJani Nikula
2547d0ab409dSJani Nikula switch (devdata->child.hdmi_max_data_rate) {
2548d0ab409dSJani Nikula default:
2549d0ab409dSJani Nikula MISSING_CASE(devdata->child.hdmi_max_data_rate);
2550d0ab409dSJani Nikula fallthrough;
2551d0ab409dSJani Nikula case HDMI_MAX_DATA_RATE_PLATFORM:
2552d0ab409dSJani Nikula return 0;
255345c0673aSJani Nikula case HDMI_MAX_DATA_RATE_594:
2554d0ab409dSJani Nikula return 594000;
2555d0ab409dSJani Nikula case HDMI_MAX_DATA_RATE_340:
2556d0ab409dSJani Nikula return 340000;
2557d0ab409dSJani Nikula case HDMI_MAX_DATA_RATE_300:
2558d0ab409dSJani Nikula return 300000;
255945c0673aSJani Nikula case HDMI_MAX_DATA_RATE_297:
2560d0ab409dSJani Nikula return 297000;
2561d0ab409dSJani Nikula case HDMI_MAX_DATA_RATE_165:
2562d0ab409dSJani Nikula return 165000;
2563d0ab409dSJani Nikula }
2564d0ab409dSJani Nikula }
2565d0ab409dSJani Nikula
is_port_valid(struct drm_i915_private * i915,enum port port)256645c0673aSJani Nikula static bool is_port_valid(struct drm_i915_private *i915, enum port port)
2567d0ab409dSJani Nikula {
2568d0ab409dSJani Nikula /*
2569d0ab409dSJani Nikula * On some ICL SKUs port F is not present, but broken VBTs mark
2570d0ab409dSJani Nikula * the port as present. Only try to initialize port F for the
2571d0ab409dSJani Nikula * SKUs that may actually have it.
2572d0ab409dSJani Nikula */
2573d0ab409dSJani Nikula if (port == PORT_F && IS_ICELAKE(i915))
2574d0ab409dSJani Nikula return IS_ICL_WITH_PORT_F(i915);
2575d0ab409dSJani Nikula
2576d0ab409dSJani Nikula return true;
2577d0ab409dSJani Nikula }
2578d0ab409dSJani Nikula
print_ddi_port(const struct intel_bios_encoder_data * devdata)2579a9a56e76SJani Nikula static void print_ddi_port(const struct intel_bios_encoder_data *devdata)
2580a9a56e76SJani Nikula {
2581a434689cSJani Nikula struct drm_i915_private *i915 = devdata->i915;
2582a9a56e76SJani Nikula const struct child_device_config *child = &devdata->child;
2583a9a56e76SJani Nikula bool is_dvi, is_hdmi, is_dp, is_edp, is_dsi, is_crt, supports_typec_usb, supports_tbt;
2584a9a56e76SJani Nikula int dp_boost_level, dp_max_link_rate, hdmi_boost_level, hdmi_level_shift, max_tmds_clock;
2585a9a56e76SJani Nikula enum port port;
2586a9a56e76SJani Nikula
25876ba69981SJani Nikula port = intel_bios_encoder_port(devdata);
25886ba69981SJani Nikula if (port == PORT_NONE)
2589a434689cSJani Nikula return;
25906ba69981SJani Nikula
25916ba69981SJani Nikula is_dvi = intel_bios_encoder_supports_dvi(devdata);
25926ba69981SJani Nikula is_dp = intel_bios_encoder_supports_dp(devdata);
25936ba69981SJani Nikula is_crt = intel_bios_encoder_supports_crt(devdata);
25946ba69981SJani Nikula is_hdmi = intel_bios_encoder_supports_hdmi(devdata);
25956ba69981SJani Nikula is_edp = intel_bios_encoder_supports_edp(devdata);
25966ba69981SJani Nikula is_dsi = intel_bios_encoder_supports_dsi(devdata);
25976ba69981SJani Nikula
25985708fe0dSLee Shawn C supports_typec_usb = intel_bios_encoder_supports_typec_usb(devdata);
25995708fe0dSLee Shawn C supports_tbt = intel_bios_encoder_supports_tbt(devdata);
26005708fe0dSLee Shawn C
26015708fe0dSLee Shawn C drm_dbg_kms(&i915->drm,
26025708fe0dSLee Shawn C "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",
26035708fe0dSLee Shawn C port_name(port), is_crt, is_dvi, is_hdmi, is_dp, is_edp, is_dsi,
26046ba69981SJani Nikula intel_bios_encoder_supports_dp_dual_mode(devdata),
26056ba69981SJani Nikula intel_bios_encoder_is_lspcon(devdata),
26066ba69981SJani Nikula supports_typec_usb, supports_tbt,
26076ba69981SJani Nikula devdata->dsc != NULL);
26086ba69981SJani Nikula
26096ba69981SJani Nikula hdmi_level_shift = intel_bios_hdmi_level_shift(devdata);
26106ba69981SJani Nikula if (hdmi_level_shift >= 0) {
26115a9d38b2SLucas De Marchi drm_dbg_kms(&i915->drm,
26125a9d38b2SLucas De Marchi "Port %c VBT HDMI level shift: %d\n",
26135a9d38b2SLucas De Marchi port_name(port), hdmi_level_shift);
2614cad83b40SLucas De Marchi }
26155a9d38b2SLucas De Marchi
26165a9d38b2SLucas De Marchi max_tmds_clock = intel_bios_hdmi_max_tmds_clock(devdata);
26175a9d38b2SLucas De Marchi if (max_tmds_clock)
2618cad83b40SLucas De Marchi drm_dbg_kms(&i915->drm,
2619cad83b40SLucas De Marchi "Port %c VBT HDMI max TMDS clock: %d kHz\n",
26205a9d38b2SLucas De Marchi port_name(port), max_tmds_clock);
26215a9d38b2SLucas De Marchi
26225a9d38b2SLucas De Marchi /* I_boost config for SKL and above */
26235a9d38b2SLucas De Marchi dp_boost_level = intel_bios_dp_boost_level(devdata);
26248d2ba05bSJani Nikula if (dp_boost_level)
26258d2ba05bSJani Nikula drm_dbg_kms(&i915->drm,
2626df0566a6SJani Nikula "Port %c VBT (e)DP boost level: %d\n",
2627c78783f3SJani Nikula port_name(port), dp_boost_level);
2628d1dad6f4SJani Nikula
2629f08fbe6aSJani Nikula hdmi_boost_level = intel_bios_hdmi_boost_level(devdata);
263072337aacSJani Nikula if (hdmi_boost_level)
2631df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
2632d0ab409dSJani Nikula "Port %c VBT HDMI boost level: %d\n",
2633d0ab409dSJani Nikula port_name(port), hdmi_boost_level);
2634d0ab409dSJani Nikula
2635d0ab409dSJani Nikula dp_max_link_rate = intel_bios_dp_max_link_rate(devdata);
2636d0ab409dSJani Nikula if (dp_max_link_rate)
2637df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
2638f08fbe6aSJani Nikula "Port %c VBT DP max link rate: %d\n",
2639f08fbe6aSJani Nikula port_name(port), dp_max_link_rate);
2640df0566a6SJani Nikula
2641dbd440d8SJani Nikula /*
2642e92cbf38SWambui Karuga * FIXME need to implement support for VBT
2643df0566a6SJani Nikula * vswing/preemph tables should this ever trigger.
2644dbd440d8SJani Nikula */
2645f08fbe6aSJani Nikula drm_WARN(&i915->drm, child->use_vbt_vswing,
26466e0d46e9SJani Nikula "Port %c asks to use VBT vswing/preemph tables\n",
2647df0566a6SJani Nikula port_name(port));
2648a9a56e76SJani Nikula }
2649a9a56e76SJani Nikula
parse_ddi_port(struct intel_bios_encoder_data * devdata)2650dbd440d8SJani Nikula static void parse_ddi_port(struct intel_bios_encoder_data *devdata)
26516ee8d381SJani Nikula {
2652a9a56e76SJani Nikula struct drm_i915_private *i915 = devdata->i915;
2653df0566a6SJani Nikula enum port port;
2654df0566a6SJani Nikula
26556ba69981SJani Nikula port = intel_bios_encoder_port(devdata);
2656df0566a6SJani Nikula if (port == PORT_NONE)
2657dbd440d8SJani Nikula return;
26586ee8d381SJani Nikula
2659df0566a6SJani Nikula if (!is_port_valid(i915, port)) {
2660df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
2661c0a950d1SJani Nikula "VBT reports port %c as supported, but that can't be true: skipping\n",
2662c0a950d1SJani Nikula port_name(port));
2663c0a950d1SJani Nikula return;
2664dbd440d8SJani Nikula }
26656ee8d381SJani Nikula
2666c0a950d1SJani Nikula sanitize_device_type(devdata, port);
2667c0a950d1SJani Nikula }
2668c0a950d1SJani Nikula
has_ddi_port_info(struct drm_i915_private * i915)2669c0a950d1SJani Nikula static bool has_ddi_port_info(struct drm_i915_private *i915)
2670dbd440d8SJani Nikula {
26716ee8d381SJani Nikula return DISPLAY_VER(i915) >= 5 || IS_G4X(i915);
2672c0a950d1SJani Nikula }
2673df0566a6SJani Nikula
parse_ddi_ports(struct drm_i915_private * i915)267472337aacSJani Nikula static void parse_ddi_ports(struct drm_i915_private *i915)
267572337aacSJani Nikula {
2676dbd440d8SJani Nikula struct intel_bios_encoder_data *devdata;
26776ee8d381SJani Nikula
267872337aacSJani Nikula if (!has_ddi_port_info(i915))
2679429a0955SVille Syrjälä return;
2680429a0955SVille Syrjälä
2681429a0955SVille Syrjälä list_for_each_entry(devdata, &i915->display.vbt.display_devices, node)
2682429a0955SVille Syrjälä parse_ddi_port(devdata);
2683429a0955SVille Syrjälä
2684429a0955SVille Syrjälä list_for_each_entry(devdata, &i915->display.vbt.display_devices, node)
2685429a0955SVille Syrjälä print_ddi_port(devdata);
2686429a0955SVille Syrjälä }
26878d2ba05bSJani Nikula
26888d2ba05bSJani Nikula static void
parse_general_definitions(struct drm_i915_private * i915)26898d2ba05bSJani Nikula parse_general_definitions(struct drm_i915_private *i915)
26908d2ba05bSJani Nikula {
26918d2ba05bSJani Nikula const struct bdb_general_definitions *defs;
26928d2ba05bSJani Nikula struct intel_bios_encoder_data *devdata;
26938d2ba05bSJani Nikula const struct child_device_config *child;
26948d2ba05bSJani Nikula int i, child_device_num;
26958d2ba05bSJani Nikula u8 expected_size;
26968d2ba05bSJani Nikula u16 block_size;
26978d2ba05bSJani Nikula int bus_pin;
26988d2ba05bSJani Nikula
26998d2ba05bSJani Nikula defs = bdb_find_section(i915, BDB_GENERAL_DEFINITIONS);
27008d2ba05bSJani Nikula if (!defs) {
27018d2ba05bSJani Nikula drm_dbg_kms(&i915->drm,
27028d2ba05bSJani Nikula "No general definition block is found, no devices defined.\n");
27038d2ba05bSJani Nikula return;
27048d2ba05bSJani Nikula }
27058d2ba05bSJani Nikula
2706a434689cSJani Nikula block_size = get_blocksize(defs);
27078d2ba05bSJani Nikula if (block_size < sizeof(*defs)) {
27088d2ba05bSJani Nikula drm_dbg_kms(&i915->drm,
27098d2ba05bSJani Nikula "General definitions block too small (%u)\n",
27108d2ba05bSJani Nikula block_size);
27118d2ba05bSJani Nikula return;
27128d2ba05bSJani Nikula }
27138d2ba05bSJani Nikula
27148d2ba05bSJani Nikula bus_pin = defs->crt_ddc_gmbus_pin;
27158d2ba05bSJani Nikula drm_dbg_kms(&i915->drm, "crt_ddc_bus_pin: %d\n", bus_pin);
27168d2ba05bSJani Nikula if (intel_gmbus_is_valid_pin(i915, bus_pin))
27178d2ba05bSJani Nikula i915->display.vbt.crt_ddc_pin = bus_pin;
27188d2ba05bSJani Nikula
27198d2ba05bSJani Nikula if (i915->display.vbt.version < 106) {
2720df0566a6SJani Nikula expected_size = 22;
2721a434689cSJani Nikula } else if (i915->display.vbt.version < 111) {
2722df0566a6SJani Nikula expected_size = 27;
2723df0566a6SJani Nikula } else if (i915->display.vbt.version < 195) {
2724b90b6e41SVille Syrjälä expected_size = LEGACY_CHILD_DEVICE_CONFIG_SIZE;
2725b90b6e41SVille Syrjälä } else if (i915->display.vbt.version == 195) {
2726594c504dSVille Syrjälä expected_size = 37;
2727b90b6e41SVille Syrjälä } else if (i915->display.vbt.version <= 215) {
2728b90b6e41SVille Syrjälä expected_size = 38;
2729ef0096e4SJani Nikula } else if (i915->display.vbt.version <= 250) {
2730df0566a6SJani Nikula expected_size = 39;
27313162d057SJani Nikula } else {
2732e61f294cSJani Nikula expected_size = sizeof(*child);
2733df0566a6SJani Nikula BUILD_BUG_ON(sizeof(*child) < 39);
2734eb9fcf63SVille Syrjälä drm_dbg(&i915->drm,
2735df0566a6SJani Nikula "Expected child device config size for VBT version %u not known; assuming %u\n",
2736df0566a6SJani Nikula i915->display.vbt.version, expected_size);
2737a434689cSJani Nikula }
2738c78783f3SJani Nikula
2739e61f294cSJani Nikula /* Flag an error for unexpected size, but continue anyway. */
2740e61f294cSJani Nikula if (defs->child_dev_size != expected_size)
2741a434689cSJani Nikula drm_err(&i915->drm,
2742a434689cSJani Nikula "Unexpected child device config size %u (expected %u for VBT version %u)\n",
2743e61f294cSJani Nikula defs->child_dev_size, expected_size, i915->display.vbt.version);
2744df0566a6SJani Nikula
2745df0566a6SJani Nikula /* The legacy sized child device config is the minimum we need. */
2746df0566a6SJani Nikula if (defs->child_dev_size < LEGACY_CHILD_DEVICE_CONFIG_SIZE) {
2747e163cfb4SVille Syrjälä drm_dbg_kms(&i915->drm,
2748df0566a6SJani Nikula "Child device config size %u is too small.\n",
2749df0566a6SJani Nikula defs->child_dev_size);
27503162d057SJani Nikula return;
2751df0566a6SJani Nikula }
27520d9ef19bSJani Nikula
2753df0566a6SJani Nikula /* get the number of child device */
2754df0566a6SJani Nikula child_device_num = (block_size - sizeof(*defs)) / defs->child_dev_size;
2755df0566a6SJani Nikula
2756df0566a6SJani Nikula for (i = 0; i < child_device_num; i++) {
2757e163cfb4SVille Syrjälä child = child_device_ptr(defs, i);
2758df0566a6SJani Nikula if (!child->device_type)
2759dbd440d8SJani Nikula continue;
2760e92cbf38SWambui Karuga
2761df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
2762df0566a6SJani Nikula "Found VBT child device with type 0x%x\n",
2763df0566a6SJani Nikula child->device_type);
2764df0566a6SJani Nikula
2765df0566a6SJani Nikula devdata = kzalloc(sizeof(*devdata), GFP_KERNEL);
2766dbd440d8SJani Nikula if (!devdata)
2767e92cbf38SWambui Karuga break;
2768df0566a6SJani Nikula
2769df0566a6SJani Nikula devdata->i915 = i915;
2770df0566a6SJani Nikula
2771df0566a6SJani Nikula /*
2772df0566a6SJani Nikula * Copy as much as we know (sizeof) and is available
2773dbd440d8SJani Nikula * (child_dev_size) of the child device config. Accessing the
2774dbd440d8SJani Nikula * data must depend on VBT version.
2775a434689cSJani Nikula */
2776df0566a6SJani Nikula memcpy(&devdata->child, child,
2777a434689cSJani Nikula min_t(size_t, defs->child_dev_size, sizeof(*child)));
2778df0566a6SJani Nikula
2779a434689cSJani Nikula list_add_tail(&devdata->node, &i915->display.vbt.display_devices);
2780df0566a6SJani Nikula }
2781a434689cSJani Nikula
2782df0566a6SJani Nikula if (list_empty(&i915->display.vbt.display_devices))
2783a434689cSJani Nikula drm_dbg_kms(&i915->drm,
2784df0566a6SJani Nikula "no child dev is parsed from VBT\n");
2785a434689cSJani Nikula }
2786df0566a6SJani Nikula
2787a434689cSJani Nikula /* Common defaults which may be overridden by VBT. */
2788df0566a6SJani Nikula static void
init_vbt_defaults(struct drm_i915_private * i915)2789df0566a6SJani Nikula init_vbt_defaults(struct drm_i915_private *i915)
2790df0566a6SJani Nikula {
2791df0566a6SJani Nikula i915->display.vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
2792dbd440d8SJani Nikula
2793e92cbf38SWambui Karuga /* general features */
2794a434689cSJani Nikula i915->display.vbt.int_tv_support = 1;
2795df0566a6SJani Nikula i915->display.vbt.int_crt_support = 1;
2796df0566a6SJani Nikula
2797df0566a6SJani Nikula /* driver features */
2798df0566a6SJani Nikula i915->display.vbt.int_lvds_support = 1;
2799dbd440d8SJani Nikula
2800e92cbf38SWambui Karuga /* Default to using SSC */
2801a434689cSJani Nikula i915->display.vbt.lvds_use_ssc = 1;
2802df0566a6SJani Nikula /*
2803df0566a6SJani Nikula * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
2804df0566a6SJani Nikula * clock for LVDS.
2805dbd440d8SJani Nikula */
2806e92cbf38SWambui Karuga i915->display.vbt.lvds_ssc_freq = intel_bios_ssc_frequency(i915,
2807df0566a6SJani Nikula !HAS_PCH_SPLIT(i915));
2808df0566a6SJani Nikula drm_dbg_kms(&i915->drm, "Set default to SSC at %d kHz\n",
2809df0566a6SJani Nikula i915->display.vbt.lvds_ssc_freq);
2810df0566a6SJani Nikula }
2811df0566a6SJani Nikula
2812df0566a6SJani Nikula /* Common defaults which may be overridden by VBT. */
2813df0566a6SJani Nikula static void
init_vbt_panel_defaults(struct intel_panel * panel)2814df0566a6SJani Nikula init_vbt_panel_defaults(struct intel_panel *panel)
2815df0566a6SJani Nikula {
2816df0566a6SJani Nikula /* Default to having backlight */
2817df0566a6SJani Nikula panel->vbt.backlight.present = true;
2818df0566a6SJani Nikula
2819dbd440d8SJani Nikula /* LFP panel data */
2820e92cbf38SWambui Karuga panel->vbt.lvds_dither = true;
2821bdeb18dbSMatt Roper }
2822bdeb18dbSMatt Roper
28230d9ef19bSJani Nikula /* Defaults to initialize only if there is no VBT. */
28240d9ef19bSJani Nikula static void
init_vbt_missing_defaults(struct drm_i915_private * i915)28250d9ef19bSJani Nikula init_vbt_missing_defaults(struct drm_i915_private *i915)
28260d9ef19bSJani Nikula {
28277371fa34SJani Nikula enum port port;
28287371fa34SJani Nikula int ports = BIT(PORT_A) | BIT(PORT_B) | BIT(PORT_C) |
2829df0566a6SJani Nikula BIT(PORT_D) | BIT(PORT_E) | BIT(PORT_F);
2830df0566a6SJani Nikula
28310d9ef19bSJani Nikula if (!HAS_DDI(i915) && !IS_CHERRYVIEW(i915))
28320d9ef19bSJani Nikula return;
2833df0566a6SJani Nikula
28340d9ef19bSJani Nikula for_each_port_masked(port, ports) {
2835df0566a6SJani Nikula struct intel_bios_encoder_data *devdata;
28360d9ef19bSJani Nikula struct child_device_config *child;
2837a434689cSJani Nikula enum phy phy = intel_port_to_phy(i915, port);
2838df0566a6SJani Nikula
28390d9ef19bSJani Nikula /*
2840a434689cSJani Nikula * VBT has the TypeC mode (native,TBT/USB) and we don't want
2841dbd440d8SJani Nikula * to detect it.
2842e92cbf38SWambui Karuga */
2843df0566a6SJani Nikula if (intel_phy_is_tc(i915, phy))
2844df0566a6SJani Nikula continue;
2845df0566a6SJani Nikula
2846df0566a6SJani Nikula /* Create fake child device config */
2847dbd440d8SJani Nikula devdata = kzalloc(sizeof(*devdata), GFP_KERNEL);
2848df0566a6SJani Nikula if (!devdata)
2849a434689cSJani Nikula break;
2850df0566a6SJani Nikula
2851df0566a6SJani Nikula devdata->i915 = i915;
2852a434689cSJani Nikula child = &devdata->child;
2853a434689cSJani Nikula
2854df0566a6SJani Nikula if (port == PORT_F)
2855df0566a6SJani Nikula child->dvo_port = DVO_PORT_HDMIF;
2856a434689cSJani Nikula else if (port == PORT_E)
2857df0566a6SJani Nikula child->dvo_port = DVO_PORT_HDMIE;
2858df0566a6SJani Nikula else
2859a434689cSJani Nikula child->dvo_port = DVO_PORT_HDMIA + port;
2860df0566a6SJani Nikula
2861df0566a6SJani Nikula if (port != PORT_A && port != PORT_E)
2862df0566a6SJani Nikula child->device_type |= DEVICE_TYPE_TMDS_DVI_SIGNALING;
2863df0566a6SJani Nikula
2864a434689cSJani Nikula if (port != PORT_E)
2865dbd440d8SJani Nikula child->device_type |= DEVICE_TYPE_DISPLAYPORT_OUTPUT;
2866dbd440d8SJani Nikula
2867a434689cSJani Nikula if (port == PORT_A)
2868df0566a6SJani Nikula child->device_type |= DEVICE_TYPE_INTERNAL_CONNECTOR;
2869df0566a6SJani Nikula
28703cf05076SVille Syrjälä list_add_tail(&devdata->node, &i915->display.vbt.display_devices);
28713cf05076SVille Syrjälä
28723cf05076SVille Syrjälä drm_dbg_kms(&i915->drm,
28733cf05076SVille Syrjälä "Generating default VBT child device with type 0x04%x on port %c\n",
28743cf05076SVille Syrjälä child->device_type, port_name(port));
28753cf05076SVille Syrjälä }
28763cf05076SVille Syrjälä
28773cf05076SVille Syrjälä /* Bypass some minimum baseline VBT version checks */
28783cf05076SVille Syrjälä i915->display.vbt.version = 155;
28793cf05076SVille Syrjälä }
28803cf05076SVille Syrjälä
get_bdb_header(const struct vbt_header * vbt)2881df0566a6SJani Nikula static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
2882df0566a6SJani Nikula {
2883dbd440d8SJani Nikula const void *_vbt = vbt;
2884df0566a6SJani Nikula
2885df0566a6SJani Nikula return _vbt + vbt->bdb_offset;
28869b52aa72SRodrigo Vivi }
28879b52aa72SRodrigo Vivi
2888df0566a6SJani Nikula /**
2889e20e4037SJani Nikula * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
2890e20e4037SJani Nikula * @buf: pointer to a buffer to validate
2891e20e4037SJani Nikula * @size: size of the buffer
28923ae04c0cSJani Nikula *
28933162d057SJani Nikula * Returns true on valid VBT.
289451f57481SJani Nikula */
intel_bios_is_valid_vbt(const void * buf,size_t size)2895dbd440d8SJani Nikula bool intel_bios_is_valid_vbt(const void *buf, size_t size)
2896df0566a6SJani Nikula {
2897df0566a6SJani Nikula const struct vbt_header *vbt = buf;
2898df0566a6SJani Nikula const struct bdb_header *bdb;
2899df0566a6SJani Nikula
2900df0566a6SJani Nikula if (!vbt)
2901dbd440d8SJani Nikula return false;
2902df0566a6SJani Nikula
2903df0566a6SJani Nikula if (sizeof(struct vbt_header) > size) {
290451f57481SJani Nikula DRM_DEBUG_DRIVER("VBT header incomplete\n");
290551f57481SJani Nikula return false;
290651f57481SJani Nikula }
290751f57481SJani Nikula
290851f57481SJani Nikula if (memcmp(vbt->signature, "$VBT", 4)) {
29097371fa34SJani Nikula DRM_DEBUG_DRIVER("VBT invalid signature\n");
291051f57481SJani Nikula return false;
291151f57481SJani Nikula }
291251f57481SJani Nikula
291351f57481SJani Nikula if (vbt->vbt_size > size) {
291451f57481SJani Nikula DRM_DEBUG_DRIVER("VBT incomplete (vbt_size overflows)\n");
291551f57481SJani Nikula return false;
291651f57481SJani Nikula }
291751f57481SJani Nikula
291851f57481SJani Nikula size = vbt->vbt_size;
291951f57481SJani Nikula
292051f57481SJani Nikula if (range_overflows_t(size_t,
292151f57481SJani Nikula vbt->bdb_offset,
292251f57481SJani Nikula sizeof(struct bdb_header),
292351f57481SJani Nikula size)) {
292451f57481SJani Nikula DRM_DEBUG_DRIVER("BDB header incomplete\n");
292551f57481SJani Nikula return false;
292651f57481SJani Nikula }
292751f57481SJani Nikula
2928a434689cSJani Nikula bdb = get_bdb_header(vbt);
292951f57481SJani Nikula if (range_overflows_t(size_t, vbt->bdb_offset, bdb->bdb_size, size)) {
293051f57481SJani Nikula DRM_DEBUG_DRIVER("BDB incomplete\n");
293151f57481SJani Nikula return false;
293251f57481SJani Nikula }
2933df0566a6SJani Nikula
293451f57481SJani Nikula return vbt;
293551f57481SJani Nikula }
2936a434689cSJani Nikula
intel_spi_read(struct intel_uncore * uncore,u32 offset)2937df0566a6SJani Nikula static u32 intel_spi_read(struct intel_uncore *uncore, u32 offset)
2938df0566a6SJani Nikula {
2939df0566a6SJani Nikula intel_uncore_write(uncore, PRIMARY_SPI_ADDRESS, offset);
2940df0566a6SJani Nikula
2941df0566a6SJani Nikula return intel_uncore_read(uncore, PRIMARY_SPI_TRIGGER);
2942df0566a6SJani Nikula }
2943df0566a6SJani Nikula
spi_oprom_get_vbt(struct drm_i915_private * i915)2944df0566a6SJani Nikula static struct vbt_header *spi_oprom_get_vbt(struct drm_i915_private *i915)
2945df0566a6SJani Nikula {
2946df0566a6SJani Nikula u32 count, data, found, store = 0;
2947df0566a6SJani Nikula u32 static_region, oprom_offset;
2948df0566a6SJani Nikula u32 oprom_size = 0x200000;
2949df0566a6SJani Nikula u16 vbt_size;
2950df0566a6SJani Nikula u32 *vbt;
2951df0566a6SJani Nikula
2952df0566a6SJani Nikula static_region = intel_uncore_read(&i915->uncore, SPI_STATIC_REGIONS);
2953df0566a6SJani Nikula static_region &= OPTIONROM_SPI_REGIONID_MASK;
2954df0566a6SJani Nikula intel_uncore_write(&i915->uncore, PRIMARY_SPI_REGIONID, static_region);
2955df0566a6SJani Nikula
2956df0566a6SJani Nikula oprom_offset = intel_uncore_read(&i915->uncore, OROM_OFFSET);
2957df0566a6SJani Nikula oprom_offset &= OROM_OFFSET_MASK;
2958df0566a6SJani Nikula
2959df0566a6SJani Nikula for (count = 0; count < oprom_size; count += 4) {
2960df0566a6SJani Nikula data = intel_spi_read(&i915->uncore, oprom_offset + count);
2961df0566a6SJani Nikula if (data == *((const u32 *)"$VBT")) {
2962df0566a6SJani Nikula found = oprom_offset + count;
2963df0566a6SJani Nikula break;
2964df0566a6SJani Nikula }
2965df0566a6SJani Nikula }
2966df0566a6SJani Nikula
2967df0566a6SJani Nikula if (count >= oprom_size)
2968df0566a6SJani Nikula goto err_not_found;
2969df0566a6SJani Nikula
2970df0566a6SJani Nikula /* Get VBT size and allocate space for the VBT */
2971ff00ff96SLucas De Marchi vbt_size = intel_spi_read(&i915->uncore,
2972ff00ff96SLucas De Marchi found + offsetof(struct vbt_header, vbt_size));
2973ff00ff96SLucas De Marchi vbt_size &= 0xffff;
2974ff00ff96SLucas De Marchi
2975ff00ff96SLucas De Marchi vbt = kzalloc(round_up(vbt_size, 4), GFP_KERNEL);
2976ff00ff96SLucas De Marchi if (!vbt)
2977ff00ff96SLucas De Marchi goto err_not_found;
2978df0566a6SJani Nikula
2979df0566a6SJani Nikula for (count = 0; count < vbt_size; count += 4)
2980df0566a6SJani Nikula *(vbt + store++) = intel_spi_read(&i915->uncore, found + count);
2981df0566a6SJani Nikula
2982df0566a6SJani Nikula if (!intel_bios_is_valid_vbt(vbt, vbt_size))
2983df0566a6SJani Nikula goto err_free_vbt;
2984df0566a6SJani Nikula
2985df0566a6SJani Nikula drm_dbg_kms(&i915->drm, "Found valid VBT in SPI flash\n");
2986df0566a6SJani Nikula
2987df0566a6SJani Nikula return (struct vbt_header *)vbt;
2988df0566a6SJani Nikula
2989df0566a6SJani Nikula err_free_vbt:
2990df0566a6SJani Nikula kfree(vbt);
2991df0566a6SJani Nikula err_not_found:
2992df0566a6SJani Nikula return NULL;
2993df0566a6SJani Nikula }
2994df0566a6SJani Nikula
oprom_get_vbt(struct drm_i915_private * i915)2995a36e7dc0SClint Taylor static struct vbt_header *oprom_get_vbt(struct drm_i915_private *i915)
2996a36e7dc0SClint Taylor {
2997a36e7dc0SClint Taylor struct pci_dev *pdev = to_pci_dev(i915->drm.dev);
2998a36e7dc0SClint Taylor void __iomem *p = NULL, *oprom;
2999a36e7dc0SClint Taylor struct vbt_header *vbt;
3000a36e7dc0SClint Taylor u16 vbt_size;
3001a36e7dc0SClint Taylor size_t i, size;
3002a36e7dc0SClint Taylor
3003a36e7dc0SClint Taylor oprom = pci_map_rom(pdev, &size);
3004a36e7dc0SClint Taylor if (!oprom)
3005a36e7dc0SClint Taylor return NULL;
3006a36e7dc0SClint Taylor
3007a36e7dc0SClint Taylor /* Scour memory looking for the VBT signature. */
3008a36e7dc0SClint Taylor for (i = 0; i + 4 < size; i += 4) {
3009a36e7dc0SClint Taylor if (ioread32(oprom + i) != *((const u32 *)"$VBT"))
3010a36e7dc0SClint Taylor continue;
3011a36e7dc0SClint Taylor
3012a36e7dc0SClint Taylor p = oprom + i;
3013a36e7dc0SClint Taylor size -= i;
3014a36e7dc0SClint Taylor break;
3015a36e7dc0SClint Taylor }
3016a36e7dc0SClint Taylor
3017a36e7dc0SClint Taylor if (!p)
3018a36e7dc0SClint Taylor goto err_unmap_oprom;
3019a36e7dc0SClint Taylor
3020a36e7dc0SClint Taylor if (sizeof(struct vbt_header) > size) {
3021a36e7dc0SClint Taylor drm_dbg(&i915->drm, "VBT header incomplete\n");
3022a36e7dc0SClint Taylor goto err_unmap_oprom;
3023a36e7dc0SClint Taylor }
3024a36e7dc0SClint Taylor
3025a36e7dc0SClint Taylor vbt_size = ioread16(p + offsetof(struct vbt_header, vbt_size));
3026a36e7dc0SClint Taylor if (vbt_size > size) {
3027a36e7dc0SClint Taylor drm_dbg(&i915->drm,
3028a36e7dc0SClint Taylor "VBT incomplete (vbt_size overflows)\n");
3029980f42e7SJani Nikula goto err_unmap_oprom;
3030a36e7dc0SClint Taylor }
3031a36e7dc0SClint Taylor
3032a36e7dc0SClint Taylor /* The rest will be validated by intel_bios_is_valid_vbt() */
3033a36e7dc0SClint Taylor vbt = kmalloc(vbt_size, GFP_KERNEL);
3034a36e7dc0SClint Taylor if (!vbt)
3035a36e7dc0SClint Taylor goto err_unmap_oprom;
3036a36e7dc0SClint Taylor
3037a36e7dc0SClint Taylor memcpy_fromio(vbt, p, vbt_size);
3038a36e7dc0SClint Taylor
3039a36e7dc0SClint Taylor if (!intel_bios_is_valid_vbt(vbt, vbt_size))
3040a36e7dc0SClint Taylor goto err_free_vbt;
3041a36e7dc0SClint Taylor
3042a36e7dc0SClint Taylor pci_unmap_rom(pdev, oprom);
3043a36e7dc0SClint Taylor
3044a36e7dc0SClint Taylor drm_dbg_kms(&i915->drm, "Found valid VBT in PCI ROM\n");
3045a36e7dc0SClint Taylor
3046a36e7dc0SClint Taylor return vbt;
3047a36e7dc0SClint Taylor
3048a36e7dc0SClint Taylor err_free_vbt:
3049a36e7dc0SClint Taylor kfree(vbt);
3050a36e7dc0SClint Taylor err_unmap_oprom:
3051a36e7dc0SClint Taylor pci_unmap_rom(pdev, oprom);
3052dbd440d8SJani Nikula
3053df0566a6SJani Nikula return NULL;
3054dbd440d8SJani Nikula }
30552cded152SLucas De Marchi
3056fd0186ceSLucas De Marchi /**
3057fd0186ceSLucas De Marchi * intel_bios_init - find VBT and initialize settings from the BIOS
30582cded152SLucas De Marchi * @i915: i915 device instance
30592cded152SLucas De Marchi *
30602cded152SLucas De Marchi * Parse and initialize settings from the Video BIOS Tables (VBT). If the VBT
30612cded152SLucas De Marchi * was not found in ACPI OpRegion, try to find it in PCI ROM first. Also
30622cded152SLucas De Marchi * initialize some defaults if the VBT is not present at all.
3063df0566a6SJani Nikula */
intel_bios_init(struct drm_i915_private * i915)3064df0566a6SJani Nikula void intel_bios_init(struct drm_i915_private *i915)
306598cf5c9aSLucas De Marchi {
3066496f50a6SLucas De Marchi const struct vbt_header *vbt = i915->display.opregion.vbt;
3067df0566a6SJani Nikula struct vbt_header *oprom_vbt = NULL;
3068df0566a6SJani Nikula const struct bdb_header *bdb;
3069fd0186ceSLucas De Marchi
3070fd0186ceSLucas De Marchi INIT_LIST_HEAD(&i915->display.vbt.display_devices);
3071df0566a6SJani Nikula INIT_LIST_HEAD(&i915->display.vbt.bdb_blocks);
3072df0566a6SJani Nikula
3073df0566a6SJani Nikula if (!HAS_DISPLAY(i915)) {
3074fd0186ceSLucas De Marchi drm_dbg_kms(&i915->drm,
30752cded152SLucas De Marchi "Skipping VBT init due to disabled display.\n");
3076fd0186ceSLucas De Marchi return;
3077fd0186ceSLucas De Marchi }
3078dbd440d8SJani Nikula
30792cded152SLucas De Marchi init_vbt_defaults(i915);
3080fd0186ceSLucas De Marchi
3081fd0186ceSLucas De Marchi /*
3082fd0186ceSLucas De Marchi * If the OpRegion does not have VBT, look in SPI flash through MMIO or
3083fd0186ceSLucas De Marchi * PCI mapping
3084dbd440d8SJani Nikula */
3085e92cbf38SWambui Karuga if (!vbt && IS_DGFX(i915)) {
30862cded152SLucas De Marchi oprom_vbt = spi_oprom_get_vbt(i915);
3087fd0186ceSLucas De Marchi vbt = oprom_vbt;
3088fd0186ceSLucas De Marchi }
3089fd0186ceSLucas De Marchi
3090fd0186ceSLucas De Marchi if (!vbt) {
3091fd0186ceSLucas De Marchi oprom_vbt = oprom_get_vbt(i915);
30922cded152SLucas De Marchi vbt = oprom_vbt;
3093fd0186ceSLucas De Marchi }
3094fd0186ceSLucas De Marchi
3095fd0186ceSLucas De Marchi if (!vbt)
3096fd0186ceSLucas De Marchi goto out;
3097fd0186ceSLucas De Marchi
3098fd0186ceSLucas De Marchi bdb = get_bdb_header(vbt);
30992cded152SLucas De Marchi i915->display.vbt.version = bdb->version;
31002cded152SLucas De Marchi
3101a36e7dc0SClint Taylor drm_dbg_kms(&i915->drm,
3102a36e7dc0SClint Taylor "VBT signature \"%.*s\", BDB version %d\n",
3103fd0186ceSLucas De Marchi (int)sizeof(vbt->signature), vbt->signature, i915->display.vbt.version);
3104fd0186ceSLucas De Marchi
3105fd0186ceSLucas De Marchi init_bdb_blocks(i915, bdb);
3106fd0186ceSLucas De Marchi
31072cded152SLucas De Marchi /* Grab useful general definitions */
31082cded152SLucas De Marchi parse_general_features(i915);
3109fd0186ceSLucas De Marchi parse_general_definitions(i915);
3110df0566a6SJani Nikula parse_driver_features(i915);
3111df0566a6SJani Nikula
3112df0566a6SJani Nikula /* Depends on child device list */
3113df0566a6SJani Nikula parse_compression_parameters(i915);
3114df0566a6SJani Nikula
3115dbd440d8SJani Nikula out:
3116df0566a6SJani Nikula if (!vbt) {
3117df0566a6SJani Nikula drm_info(&i915->drm,
3118df0566a6SJani Nikula "Failed to find VBIOS tables (VBT)\n");
3119df0566a6SJani Nikula init_vbt_missing_defaults(i915);
3120df0566a6SJani Nikula }
3121dbd440d8SJani Nikula
3122df0566a6SJani Nikula /* Further processing on pre-parsed or generated child device data */
31237249dfcbSJani Nikula parse_sdvo_device_mapping(i915);
31242cded152SLucas De Marchi parse_ddi_ports(i915);
3125df0566a6SJani Nikula
3126df0566a6SJani Nikula kfree(oprom_vbt);
3127a434689cSJani Nikula }
3128a434689cSJani Nikula
intel_bios_init_panel(struct drm_i915_private * i915,struct intel_panel * panel,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid,bool use_fallback)31290d9ef19bSJani Nikula static void intel_bios_init_panel(struct drm_i915_private *i915,
3130dbd440d8SJani Nikula struct intel_panel *panel,
3131dbd440d8SJani Nikula const struct intel_bios_encoder_data *devdata,
3132e92cbf38SWambui Karuga const struct drm_edid *drm_edid,
3133df0566a6SJani Nikula bool use_fallback)
3134df0566a6SJani Nikula {
3135df0566a6SJani Nikula /* already have it? */
3136dbd440d8SJani Nikula if (panel->vbt.panel_type >= 0) {
3137df0566a6SJani Nikula drm_WARN_ON(&i915->drm, !use_fallback);
3138a36e7dc0SClint Taylor return;
3139a36e7dc0SClint Taylor }
3140a36e7dc0SClint Taylor
3141a36e7dc0SClint Taylor panel->vbt.panel_type = get_panel_type(i915, devdata,
3142a36e7dc0SClint Taylor drm_edid, use_fallback);
3143a36e7dc0SClint Taylor if (panel->vbt.panel_type < 0) {
3144a36e7dc0SClint Taylor drm_WARN_ON(&i915->drm, use_fallback);
3145a36e7dc0SClint Taylor return;
3146a36e7dc0SClint Taylor }
3147df0566a6SJani Nikula
3148dbd440d8SJani Nikula init_vbt_panel_defaults(panel);
31492cded152SLucas De Marchi
3150df0566a6SJani Nikula parse_panel_options(i915, panel);
3151df0566a6SJani Nikula parse_generic_dtd(i915, panel);
3152a36e7dc0SClint Taylor parse_lfp_data(i915, panel);
3153a36e7dc0SClint Taylor parse_lfp_backlight(i915, panel);
3154a36e7dc0SClint Taylor parse_sdvo_panel_data(i915, panel);
3155df0566a6SJani Nikula parse_panel_driver_features(i915, panel);
3156a434689cSJani Nikula parse_power_conservation_features(i915, panel);
3157df0566a6SJani Nikula parse_edp(i915, panel);
3158dbd440d8SJani Nikula parse_psr(i915, panel);
3159e92cbf38SWambui Karuga parse_mipi_config(i915, panel);
3160a434689cSJani Nikula parse_mipi_sequence(i915, panel);
3161df0566a6SJani Nikula }
3162e163cfb4SVille Syrjälä
intel_bios_init_panel_early(struct drm_i915_private * i915,struct intel_panel * panel,const struct intel_bios_encoder_data * devdata)3163e163cfb4SVille Syrjälä void intel_bios_init_panel_early(struct drm_i915_private *i915,
3164df0566a6SJani Nikula struct intel_panel *panel,
3165e163cfb4SVille Syrjälä const struct intel_bios_encoder_data *devdata)
3166e163cfb4SVille Syrjälä {
3167e163cfb4SVille Syrjälä intel_bios_init_panel(i915, panel, devdata, NULL, false);
3168df0566a6SJani Nikula }
31696e0d46e9SJani Nikula
intel_bios_init_panel_late(struct drm_i915_private * i915,struct intel_panel * panel,const struct intel_bios_encoder_data * devdata,const struct drm_edid * drm_edid)3170e163cfb4SVille Syrjälä void intel_bios_init_panel_late(struct drm_i915_private *i915,
31716e0d46e9SJani Nikula struct intel_panel *panel,
3172df0566a6SJani Nikula const struct intel_bios_encoder_data *devdata,
3173df0566a6SJani Nikula const struct drm_edid *drm_edid)
3174dbd440d8SJani Nikula {
3175e92cbf38SWambui Karuga intel_bios_init_panel(i915, panel, devdata, drm_edid, true);
3176dbd440d8SJani Nikula }
3177df0566a6SJani Nikula
3178df0566a6SJani Nikula /**
317951f57481SJani Nikula * intel_bios_driver_remove - Free any resources allocated by intel_bios_init()
318051f57481SJani Nikula * @i915: i915 device instance
318151f57481SJani Nikula */
intel_bios_driver_remove(struct drm_i915_private * i915)318251f57481SJani Nikula void intel_bios_driver_remove(struct drm_i915_private *i915)
31832cded152SLucas De Marchi {
3184df0566a6SJani Nikula struct intel_bios_encoder_data *devdata, *nd;
3185df0566a6SJani Nikula struct bdb_block_entry *entry, *ne;
31863cf05076SVille Syrjälä
3187c518a775SVille Syrjälä list_for_each_entry_safe(devdata, nd, &i915->display.vbt.display_devices, node) {
31886434cf63SAnimesh Manna list_del(&devdata->node);
3189c518a775SVille Syrjälä kfree(devdata->dsc);
3190c2fdb424SVille Syrjälä kfree(devdata);
31913cf05076SVille Syrjälä }
31923cf05076SVille Syrjälä
31936434cf63SAnimesh Manna list_for_each_entry_safe(entry, ne, &i915->display.vbt.bdb_blocks, node) {
31940256ea13SVille Syrjälä list_del(&entry->node);
31950256ea13SVille Syrjälä kfree(entry);
31963cf05076SVille Syrjälä }
31973cf05076SVille Syrjälä }
31983cf05076SVille Syrjälä
intel_bios_fini_panel(struct intel_panel * panel)31993cf05076SVille Syrjälä void intel_bios_fini_panel(struct intel_panel *panel)
32003cf05076SVille Syrjälä {
32013cf05076SVille Syrjälä kfree(panel->vbt.sdvo_lvds_vbt_mode);
32023cf05076SVille Syrjälä panel->vbt.sdvo_lvds_vbt_mode = NULL;
32033cf05076SVille Syrjälä kfree(panel->vbt.lfp_lvds_vbt_mode);
32043cf05076SVille Syrjälä panel->vbt.lfp_lvds_vbt_mode = NULL;
32053cf05076SVille Syrjälä kfree(panel->vbt.dsi.data);
3206c2fdb424SVille Syrjälä panel->vbt.dsi.data = NULL;
3207c2fdb424SVille Syrjälä kfree(panel->vbt.dsi.pps);
3208df0566a6SJani Nikula panel->vbt.dsi.pps = NULL;
320978dae1acSJanusz Krzysztofik kfree(panel->vbt.dsi.config);
3210dbd440d8SJani Nikula panel->vbt.dsi.config = NULL;
3211df0566a6SJani Nikula kfree(panel->vbt.dsi.deassert_seq);
3212dbd440d8SJani Nikula panel->vbt.dsi.deassert_seq = NULL;
3213df0566a6SJani Nikula }
3214e163cfb4SVille Syrjälä
3215e163cfb4SVille Syrjälä /**
32160d9ef19bSJani Nikula * intel_bios_is_tv_present - is integrated TV present in VBT
3217a434689cSJani Nikula * @i915: i915 device instance
32180d9ef19bSJani Nikula *
32196e0d46e9SJani Nikula * Return true if TV is present. If no child devices were parsed from VBT,
32200d9ef19bSJani Nikula * assume TV is present.
32210d9ef19bSJani Nikula */
intel_bios_is_tv_present(struct drm_i915_private * i915)32220d9ef19bSJani Nikula bool intel_bios_is_tv_present(struct drm_i915_private *i915)
3223a434689cSJani Nikula {
3224e163cfb4SVille Syrjälä const struct intel_bios_encoder_data *devdata;
3225e163cfb4SVille Syrjälä
3226e163cfb4SVille Syrjälä if (!i915->display.vbt.int_tv_support)
32273cf05076SVille Syrjälä return false;
3228e163cfb4SVille Syrjälä
32293cf05076SVille Syrjälä if (list_empty(&i915->display.vbt.display_devices))
32303cf05076SVille Syrjälä return true;
32313cf05076SVille Syrjälä
32323cf05076SVille Syrjälä list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) {
32333cf05076SVille Syrjälä const struct child_device_config *child = &devdata->child;
32343cf05076SVille Syrjälä
32353cf05076SVille Syrjälä /*
32363cf05076SVille Syrjälä * If the device type is not TV, continue.
32373cf05076SVille Syrjälä */
32383cf05076SVille Syrjälä switch (child->device_type) {
32393cf05076SVille Syrjälä case DEVICE_TYPE_INT_TV:
32403cf05076SVille Syrjälä case DEVICE_TYPE_TV:
32413cf05076SVille Syrjälä case DEVICE_TYPE_TV_SVIDEO_COMPOSITE:
32423cf05076SVille Syrjälä break;
3243df0566a6SJani Nikula default:
3244df0566a6SJani Nikula continue;
3245df0566a6SJani Nikula }
3246df0566a6SJani Nikula /* Only when the addin_offset is non-zero, it is regarded
3247dbd440d8SJani Nikula * as present.
3248df0566a6SJani Nikula */
3249df0566a6SJani Nikula if (child->addin_offset)
3250df0566a6SJani Nikula return true;
3251df0566a6SJani Nikula }
3252dbd440d8SJani Nikula
3253df0566a6SJani Nikula return false;
32543162d057SJani Nikula }
3255df0566a6SJani Nikula
3256df0566a6SJani Nikula /**
3257a434689cSJani Nikula * intel_bios_is_lvds_present - is LVDS present in VBT
3258df0566a6SJani Nikula * @i915: i915 device instance
3259df0566a6SJani Nikula * @i2c_pin: i2c pin for LVDS if present
3260a434689cSJani Nikula *
3261df0566a6SJani Nikula * Return true if LVDS is present. If no child devices were parsed from VBT,
3262df0566a6SJani Nikula * assume LVDS is present.
3263a434689cSJani Nikula */
intel_bios_is_lvds_present(struct drm_i915_private * i915,u8 * i2c_pin)32640d9ef19bSJani Nikula bool intel_bios_is_lvds_present(struct drm_i915_private *i915, u8 *i2c_pin)
32650d9ef19bSJani Nikula {
3266df0566a6SJani Nikula const struct intel_bios_encoder_data *devdata;
3267df0566a6SJani Nikula
3268df0566a6SJani Nikula if (list_empty(&i915->display.vbt.display_devices))
3269df0566a6SJani Nikula return true;
3270df0566a6SJani Nikula
3271df0566a6SJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) {
3272df0566a6SJani Nikula const struct child_device_config *child = &devdata->child;
3273df0566a6SJani Nikula
3274df0566a6SJani Nikula /* If the device type is not LFP, continue.
3275df0566a6SJani Nikula * We have to check both the new identifiers as well as the
3276df0566a6SJani Nikula * old for compatibility with some BIOSes.
3277df0566a6SJani Nikula */
3278df0566a6SJani Nikula if (child->device_type != DEVICE_TYPE_INT_LFP &&
3279df0566a6SJani Nikula child->device_type != DEVICE_TYPE_LFP)
3280df0566a6SJani Nikula continue;
3281df0566a6SJani Nikula
3282df0566a6SJani Nikula if (intel_gmbus_is_valid_pin(i915, child->i2c_pin))
3283df0566a6SJani Nikula *i2c_pin = child->i2c_pin;
3284df0566a6SJani Nikula
3285df0566a6SJani Nikula /* However, we cannot trust the BIOS writers to populate
3286df0566a6SJani Nikula * the VBT correctly. Since LVDS requires additional
3287df0566a6SJani Nikula * information from AIM blocks, a non-zero addin offset is
3288df0566a6SJani Nikula * a good indicator that the LVDS is actually present.
3289dbd440d8SJani Nikula */
3290df0566a6SJani Nikula if (child->addin_offset)
3291df0566a6SJani Nikula return true;
3292df0566a6SJani Nikula
3293df0566a6SJani Nikula /* But even then some BIOS writers perform some black magic
3294df0566a6SJani Nikula * and instantiate the device without reference to any
3295dbd440d8SJani Nikula * additional data. Trust that if the VBT was written into
3296df0566a6SJani Nikula * the OpRegion then they have validated the LVDS's existence.
32973162d057SJani Nikula */
3298df0566a6SJani Nikula if (i915->display.opregion.vbt)
3299df0566a6SJani Nikula return true;
3300a434689cSJani Nikula }
3301df0566a6SJani Nikula
3302df0566a6SJani Nikula return false;
3303a434689cSJani Nikula }
33040d9ef19bSJani Nikula
3305df0566a6SJani Nikula /**
3306df0566a6SJani Nikula * intel_bios_is_port_present - is the specified digital port present
3307df0566a6SJani Nikula * @i915: i915 device instance
3308df0566a6SJani Nikula * @port: port to check
3309df0566a6SJani Nikula *
3310df0566a6SJani Nikula * Return true if the device in %port is present.
3311df0566a6SJani Nikula */
intel_bios_is_port_present(struct drm_i915_private * i915,enum port port)3312df0566a6SJani Nikula bool intel_bios_is_port_present(struct drm_i915_private *i915, enum port port)
3313df0566a6SJani Nikula {
3314dbd440d8SJani Nikula const struct intel_bios_encoder_data *devdata;
3315df0566a6SJani Nikula
3316df0566a6SJani Nikula if (WARN_ON(!has_ddi_port_info(i915)))
3317df0566a6SJani Nikula return true;
3318df0566a6SJani Nikula
3319df0566a6SJani Nikula if (!is_port_valid(i915, port))
3320df0566a6SJani Nikula return false;
3321df0566a6SJani Nikula
3322df0566a6SJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) {
3323df0566a6SJani Nikula const struct child_device_config *child = &devdata->child;
3324df0566a6SJani Nikula
3325df0566a6SJani Nikula if (dvo_port_to_port(i915, child->dvo_port) == port)
3326df0566a6SJani Nikula return true;
3327df0566a6SJani Nikula }
3328df0566a6SJani Nikula
3329df0566a6SJani Nikula return false;
33307249dfcbSJani Nikula }
3331df0566a6SJani Nikula
intel_bios_encoder_supports_dp_dual_mode(const struct intel_bios_encoder_data * devdata)3332df0566a6SJani Nikula bool intel_bios_encoder_supports_dp_dual_mode(const struct intel_bios_encoder_data *devdata)
3333df0566a6SJani Nikula {
3334df0566a6SJani Nikula const struct child_device_config *child = &devdata->child;
3335df0566a6SJani Nikula
3336df0566a6SJani Nikula if (!devdata)
3337df0566a6SJani Nikula return false;
3338df0566a6SJani Nikula
3339dbd440d8SJani Nikula if (!intel_bios_encoder_supports_dp(devdata) ||
3340df0566a6SJani Nikula !intel_bios_encoder_supports_hdmi(devdata))
3341df0566a6SJani Nikula return false;
3342df0566a6SJani Nikula
3343df0566a6SJani Nikula if (dvo_port_type(child->dvo_port) == DVO_PORT_DPA)
3344dbd440d8SJani Nikula return true;
3345df0566a6SJani Nikula
3346a868a1e5SVille Syrjälä /* Only accept a HDMI dvo_port as DP++ if it has an AUX channel */
3347df0566a6SJani Nikula if (dvo_port_type(child->dvo_port) == DVO_PORT_HDMIA &&
3348df0566a6SJani Nikula child->aux_channel != 0)
3349a434689cSJani Nikula return true;
3350df0566a6SJani Nikula
3351df0566a6SJani Nikula return false;
3352df0566a6SJani Nikula }
3353df0566a6SJani Nikula
3354dbd440d8SJani Nikula /**
3355df0566a6SJani Nikula * intel_bios_is_dsi_present - is DSI present in VBT
3356df0566a6SJani Nikula * @i915: i915 device instance
3357df0566a6SJani Nikula * @port: port for DSI if present
3358df0566a6SJani Nikula *
3359dbd440d8SJani Nikula * Return true if DSI is present, and return the port in %port.
3360df0566a6SJani Nikula */
intel_bios_is_dsi_present(struct drm_i915_private * i915,enum port * port)3361a868a1e5SVille Syrjälä bool intel_bios_is_dsi_present(struct drm_i915_private *i915,
3362a868a1e5SVille Syrjälä enum port *port)
336345c0673aSJani Nikula {
336445c0673aSJani Nikula const struct intel_bios_encoder_data *devdata;
336545c0673aSJani Nikula
3366df0566a6SJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) {
3367044cbc7aSVille Syrjälä const struct child_device_config *child = &devdata->child;
336832c2bc89SVille Syrjälä u8 dvo_port = child->dvo_port;
3369044cbc7aSVille Syrjälä
3370044cbc7aSVille Syrjälä if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT))
3371044cbc7aSVille Syrjälä continue;
3372044cbc7aSVille Syrjälä
337332c2bc89SVille Syrjälä if (dsi_dvo_port_to_port(i915, dvo_port) == PORT_NONE) {
337432c2bc89SVille Syrjälä drm_dbg_kms(&i915->drm,
337532c2bc89SVille Syrjälä "VBT has unsupported DSI port %c\n",
337632c2bc89SVille Syrjälä port_name(dvo_port - DVO_PORT_MIPIA));
337732c2bc89SVille Syrjälä continue;
337832c2bc89SVille Syrjälä }
337932c2bc89SVille Syrjälä
338032c2bc89SVille Syrjälä if (port)
338132c2bc89SVille Syrjälä *port = dsi_dvo_port_to_port(i915, dvo_port);
338232c2bc89SVille Syrjälä return true;
338332c2bc89SVille Syrjälä }
338432c2bc89SVille Syrjälä
338532c2bc89SVille Syrjälä return false;
338632c2bc89SVille Syrjälä }
3387df0566a6SJani Nikula
fill_dsc(struct intel_crtc_state * crtc_state,struct dsc_compression_parameters_entry * dsc,int dsc_max_bpc)3388df0566a6SJani Nikula static void fill_dsc(struct intel_crtc_state *crtc_state,
3389a868a1e5SVille Syrjälä struct dsc_compression_parameters_entry *dsc,
3390a868a1e5SVille Syrjälä int dsc_max_bpc)
339132c2bc89SVille Syrjälä {
3392044cbc7aSVille Syrjälä struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config;
339332c2bc89SVille Syrjälä int bpc = 8;
3394df0566a6SJani Nikula
3395df0566a6SJani Nikula vdsc_cfg->dsc_version_major = dsc->version_major;
3396df0566a6SJani Nikula vdsc_cfg->dsc_version_minor = dsc->version_minor;
3397dbd440d8SJani Nikula
3398df0566a6SJani Nikula if (dsc->support_12bpc && dsc_max_bpc >= 12)
3399df0566a6SJani Nikula bpc = 12;
3400df0566a6SJani Nikula else if (dsc->support_10bpc && dsc_max_bpc >= 10)
3401df0566a6SJani Nikula bpc = 10;
3402dbd440d8SJani Nikula else if (dsc->support_8bpc && dsc_max_bpc >= 8)
3403df0566a6SJani Nikula bpc = 8;
3404df0566a6SJani Nikula else
34053162d057SJani Nikula DRM_DEBUG_KMS("VBT: Unsupported BPC %d for DCS\n",
3406df0566a6SJani Nikula dsc_max_bpc);
3407df0566a6SJani Nikula
3408df0566a6SJani Nikula crtc_state->pipe_bpp = bpc * 3;
3409a434689cSJani Nikula
34100d9ef19bSJani Nikula crtc_state->dsc.compressed_bpp = min(crtc_state->pipe_bpp,
3411df0566a6SJani Nikula VBT_DSC_MAX_BPP(dsc->max_bpp));
3412df0566a6SJani Nikula
3413df0566a6SJani Nikula /*
3414df0566a6SJani Nikula * FIXME: This is ugly, and slice count should take DSC engine
3415df0566a6SJani Nikula * throughput etc. into account.
3416df0566a6SJani Nikula *
3417df0566a6SJani Nikula * Also, per spec DSI supports 1, 2, 3 or 4 horizontal slices.
3418005e9537SMatt Roper */
3419005e9537SMatt Roper if (dsc->slices_per_line & BIT(2)) {
3420df0566a6SJani Nikula crtc_state->dsc.slice_count = 4;
3421df0566a6SJani Nikula } else if (dsc->slices_per_line & BIT(1)) {
3422df0566a6SJani Nikula crtc_state->dsc.slice_count = 2;
3423df0566a6SJani Nikula } else {
3424df0566a6SJani Nikula /* FIXME */
3425df0566a6SJani Nikula if (!(dsc->slices_per_line & BIT(0)))
3426dbd440d8SJani Nikula DRM_DEBUG_KMS("VBT: Unsupported DSC slice count for DSI\n");
3427e92cbf38SWambui Karuga
3428df0566a6SJani Nikula crtc_state->dsc.slice_count = 1;
3429df0566a6SJani Nikula }
3430df0566a6SJani Nikula
3431df0566a6SJani Nikula if (crtc_state->hw.adjusted_mode.crtc_hdisplay %
3432df0566a6SJani Nikula crtc_state->dsc.slice_count != 0)
3433df0566a6SJani Nikula DRM_DEBUG_KMS("VBT: DSC hdisplay %d not divisible by slice count %d\n",
3434df0566a6SJani Nikula crtc_state->hw.adjusted_mode.crtc_hdisplay,
34351bf2f3bfSJani Nikula crtc_state->dsc.slice_count);
34361bf2f3bfSJani Nikula
34371bf2f3bfSJani Nikula /*
34381bf2f3bfSJani Nikula * The VBT rc_buffer_block_size and rc_buffer_size definitions
34391bf2f3bfSJani Nikula * correspond to DP 1.4 DPCD offsets 0x62 and 0x63.
34401bf2f3bfSJani Nikula */
34411bf2f3bfSJani Nikula vdsc_cfg->rc_model_size = drm_dsc_dp_rc_buffer_size(dsc->rc_buffer_block_size,
34421bf2f3bfSJani Nikula dsc->rc_buffer_size);
34431bf2f3bfSJani Nikula
34441bf2f3bfSJani Nikula /* FIXME: DSI spec says bpc + 1 for this one */
34451bf2f3bfSJani Nikula vdsc_cfg->line_buf_depth = VBT_DSC_LINE_BUFFER_DEPTH(dsc->line_buffer_depth);
34461bf2f3bfSJani Nikula
34471bf2f3bfSJani Nikula vdsc_cfg->block_pred_enable = dsc->block_prediction_enable;
34481bf2f3bfSJani Nikula
34491bf2f3bfSJani Nikula vdsc_cfg->slice_height = dsc->slice_height;
34501bf2f3bfSJani Nikula }
34511bf2f3bfSJani Nikula
34521bf2f3bfSJani Nikula /* FIXME: initially DSI specific */
intel_bios_get_dsc_params(struct intel_encoder * encoder,struct intel_crtc_state * crtc_state,int dsc_max_bpc)34531bf2f3bfSJani Nikula bool intel_bios_get_dsc_params(struct intel_encoder *encoder,
34541bf2f3bfSJani Nikula struct intel_crtc_state *crtc_state,
34551bf2f3bfSJani Nikula int dsc_max_bpc)
34561bf2f3bfSJani Nikula {
34571bf2f3bfSJani Nikula struct drm_i915_private *i915 = to_i915(encoder->base.dev);
34581bf2f3bfSJani Nikula const struct intel_bios_encoder_data *devdata;
34591bf2f3bfSJani Nikula
34601bf2f3bfSJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) {
34611bf2f3bfSJani Nikula const struct child_device_config *child = &devdata->child;
34621bf2f3bfSJani Nikula
34631bf2f3bfSJani Nikula if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT))
34641bf2f3bfSJani Nikula continue;
34651bf2f3bfSJani Nikula
34661bf2f3bfSJani Nikula if (dsi_dvo_port_to_port(i915, child->dvo_port) == encoder->port) {
34671bf2f3bfSJani Nikula if (!devdata->dsc)
34681bf2f3bfSJani Nikula return false;
34691bf2f3bfSJani Nikula
34701bf2f3bfSJani Nikula if (crtc_state)
34711bf2f3bfSJani Nikula fill_dsc(crtc_state, devdata->dsc, dsc_max_bpc);
34721bf2f3bfSJani Nikula
34731bf2f3bfSJani Nikula return true;
34741bf2f3bfSJani Nikula }
34751bf2f3bfSJani Nikula }
34761bf2f3bfSJani Nikula
34771bf2f3bfSJani Nikula return false;
34781bf2f3bfSJani Nikula }
34791bf2f3bfSJani Nikula
34801bf2f3bfSJani Nikula static const u8 adlp_aux_ch_map[] = {
34811bf2f3bfSJani Nikula [AUX_CH_A] = DP_AUX_A,
34821bf2f3bfSJani Nikula [AUX_CH_B] = DP_AUX_B,
34831bf2f3bfSJani Nikula [AUX_CH_C] = DP_AUX_C,
34841bf2f3bfSJani Nikula [AUX_CH_D_XELPD] = DP_AUX_D,
34851bf2f3bfSJani Nikula [AUX_CH_E_XELPD] = DP_AUX_E,
3486fd8a5b27SJani Nikula [AUX_CH_USBC1] = DP_AUX_F,
34871bf2f3bfSJani Nikula [AUX_CH_USBC2] = DP_AUX_G,
3488fd8a5b27SJani Nikula [AUX_CH_USBC3] = DP_AUX_H,
3489fd8a5b27SJani Nikula [AUX_CH_USBC4] = DP_AUX_I,
34901bf2f3bfSJani Nikula };
34911bf2f3bfSJani Nikula
34921bf2f3bfSJani Nikula /*
34931bf2f3bfSJani Nikula * ADL-S VBT uses PHY based mapping. Combo PHYs A,B,C,D,E
34941bf2f3bfSJani Nikula * map to DDI A,TC1,TC2,TC3,TC4 respectively.
34951bf2f3bfSJani Nikula */
34961bf2f3bfSJani Nikula static const u8 adls_aux_ch_map[] = {
34971bf2f3bfSJani Nikula [AUX_CH_A] = DP_AUX_A,
34981bf2f3bfSJani Nikula [AUX_CH_USBC1] = DP_AUX_B,
34991bf2f3bfSJani Nikula [AUX_CH_USBC2] = DP_AUX_C,
35001bf2f3bfSJani Nikula [AUX_CH_USBC3] = DP_AUX_D,
35011bf2f3bfSJani Nikula [AUX_CH_USBC4] = DP_AUX_E,
35021bf2f3bfSJani Nikula };
35031bf2f3bfSJani Nikula
35041bf2f3bfSJani Nikula /*
35053162d057SJani Nikula * RKL/DG1 VBT uses PHY based mapping. Combo PHYs A,B,C,D
35061bf2f3bfSJani Nikula * map to DDI A,B,TC1,TC2 respectively.
35071bf2f3bfSJani Nikula */
3508a434689cSJani Nikula static const u8 rkl_aux_ch_map[] = {
35091bf2f3bfSJani Nikula [AUX_CH_A] = DP_AUX_A,
35101bf2f3bfSJani Nikula [AUX_CH_B] = DP_AUX_B,
35111bf2f3bfSJani Nikula [AUX_CH_USBC1] = DP_AUX_C,
35121bf2f3bfSJani Nikula [AUX_CH_USBC2] = DP_AUX_D,
35131bf2f3bfSJani Nikula };
35141bf2f3bfSJani Nikula
35151bf2f3bfSJani Nikula static const u8 direct_aux_ch_map[] = {
35161bf2f3bfSJani Nikula [AUX_CH_A] = DP_AUX_A,
35171bf2f3bfSJani Nikula [AUX_CH_B] = DP_AUX_B,
35181bf2f3bfSJani Nikula [AUX_CH_C] = DP_AUX_C,
35191bf2f3bfSJani Nikula [AUX_CH_D] = DP_AUX_D, /* aka AUX_CH_USBC1 */
35201bf2f3bfSJani Nikula [AUX_CH_E] = DP_AUX_E, /* aka AUX_CH_USBC2 */
35211bf2f3bfSJani Nikula [AUX_CH_F] = DP_AUX_F, /* aka AUX_CH_USBC3 */
35221bf2f3bfSJani Nikula [AUX_CH_G] = DP_AUX_G, /* aka AUX_CH_USBC4 */
35231bf2f3bfSJani Nikula [AUX_CH_H] = DP_AUX_H, /* aka AUX_CH_USBC5 */
35241bf2f3bfSJani Nikula [AUX_CH_I] = DP_AUX_I, /* aka AUX_CH_USBC6 */
35251bf2f3bfSJani Nikula };
35261bf2f3bfSJani Nikula
map_aux_ch(struct drm_i915_private * i915,u8 aux_channel)35271bf2f3bfSJani Nikula static enum aux_ch map_aux_ch(struct drm_i915_private *i915, u8 aux_channel)
3528df0566a6SJani Nikula {
3529df0566a6SJani Nikula const u8 *aux_ch_map;
3530df0566a6SJani Nikula int i, n_entries;
3531df0566a6SJani Nikula
3532df0566a6SJani Nikula if (DISPLAY_VER(i915) >= 13) {
3533df0566a6SJani Nikula aux_ch_map = adlp_aux_ch_map;
3534df0566a6SJani Nikula n_entries = ARRAY_SIZE(adlp_aux_ch_map);
3535df0566a6SJani Nikula } else if (IS_ALDERLAKE_S(i915)) {
3536df0566a6SJani Nikula aux_ch_map = adls_aux_ch_map;
3537df0566a6SJani Nikula n_entries = ARRAY_SIZE(adls_aux_ch_map);
3538df0566a6SJani Nikula } else if (IS_DG1(i915) || IS_ROCKETLAKE(i915)) {
3539a434689cSJani Nikula aux_ch_map = rkl_aux_ch_map;
3540df0566a6SJani Nikula n_entries = ARRAY_SIZE(rkl_aux_ch_map);
35412446e1d6SMatt Roper } else {
35422446e1d6SMatt Roper aux_ch_map = direct_aux_ch_map;
3543df0566a6SJani Nikula n_entries = ARRAY_SIZE(direct_aux_ch_map);
3544df0566a6SJani Nikula }
3545dbc13742SJani Nikula
3546df0566a6SJani Nikula for (i = 0; i < n_entries; i++) {
3547df0566a6SJani Nikula if (aux_ch_map[i] == aux_channel)
3548df0566a6SJani Nikula return i;
3549df0566a6SJani Nikula }
3550df0566a6SJani Nikula
3551df0566a6SJani Nikula drm_dbg_kms(&i915->drm,
3552df0566a6SJani Nikula "Ignoring alternate AUX CH: VBT claims AUX 0x%x, which is not valid for this platform\n",
3553df0566a6SJani Nikula aux_channel);
3554df0566a6SJani Nikula
3555df0566a6SJani Nikula return AUX_CH_NONE;
3556df0566a6SJani Nikula }
3557df0566a6SJani Nikula
intel_bios_dp_aux_ch(const struct intel_bios_encoder_data * devdata)3558df0566a6SJani Nikula enum aux_ch intel_bios_dp_aux_ch(const struct intel_bios_encoder_data *devdata)
3559a434689cSJani Nikula {
3560df0566a6SJani Nikula if (!devdata || !devdata->child.aux_channel)
3561dbc13742SJani Nikula return AUX_CH_NONE;
3562df0566a6SJani Nikula
3563df0566a6SJani Nikula return map_aux_ch(devdata->i915, devdata->child.aux_channel);
3564aaab24bbSUma Shankar }
3565aaab24bbSUma Shankar
intel_bios_dp_has_shared_aux_ch(const struct intel_bios_encoder_data * devdata)3566aaab24bbSUma Shankar bool intel_bios_dp_has_shared_aux_ch(const struct intel_bios_encoder_data *devdata)
3567aaab24bbSUma Shankar {
3568aaab24bbSUma Shankar struct drm_i915_private *i915;
3569aaab24bbSUma Shankar u8 aux_channel;
3570aaab24bbSUma Shankar int count = 0;
3571aaab24bbSUma Shankar
3572aaab24bbSUma Shankar if (!devdata || !devdata->child.aux_channel)
3573aaab24bbSUma Shankar return false;
3574aaab24bbSUma Shankar
3575a434689cSJani Nikula i915 = devdata->i915;
3576aaab24bbSUma Shankar aux_channel = devdata->child.aux_channel;
3577dbc13742SJani Nikula
3578aaab24bbSUma Shankar list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) {
3579aaab24bbSUma Shankar if (intel_bios_encoder_supports_dp(devdata) &&
3580dbd440d8SJani Nikula aux_channel == devdata->child.aux_channel)
3581df0566a6SJani Nikula count++;
3582df0566a6SJani Nikula }
3583a434689cSJani Nikula
3584df0566a6SJani Nikula return count > 1;
3585df0566a6SJani Nikula }
35865a449e58SJani Nikula
intel_bios_dp_boost_level(const struct intel_bios_encoder_data * devdata)3587df0566a6SJani Nikula int intel_bios_dp_boost_level(const struct intel_bios_encoder_data *devdata)
3588df0566a6SJani Nikula {
3589dbd440d8SJani Nikula if (!devdata || devdata->i915->display.vbt.version < 196 || !devdata->child.iboost)
3590e92cbf38SWambui Karuga return 0;
3591df0566a6SJani Nikula
3592df0566a6SJani Nikula return translate_iboost(devdata->child.dp_iboost_level);
3593df0566a6SJani Nikula }
3594df0566a6SJani Nikula
intel_bios_hdmi_boost_level(const struct intel_bios_encoder_data * devdata)359518c283dfSAditya Swarup int intel_bios_hdmi_boost_level(const struct intel_bios_encoder_data *devdata)
359618c283dfSAditya Swarup {
359718c283dfSAditya Swarup if (!devdata || devdata->i915->display.vbt.version < 196 || !devdata->child.iboost)
359818c283dfSAditya Swarup return 0;
359918c283dfSAditya Swarup
360018c283dfSAditya Swarup return translate_iboost(devdata->child.hdmi_iboost_level);
360118c283dfSAditya Swarup }
36025a449e58SJani Nikula
intel_bios_hdmi_ddc_pin(const struct intel_bios_encoder_data * devdata)3603df0566a6SJani Nikula int intel_bios_hdmi_ddc_pin(const struct intel_bios_encoder_data *devdata)
3604df0566a6SJani Nikula {
3605df0566a6SJani Nikula if (!devdata || !devdata->child.ddc_pin)
3606df0566a6SJani Nikula return 0;
3607dbd440d8SJani Nikula
360818c283dfSAditya Swarup return map_ddc_pin(devdata->i915, devdata->child.ddc_pin);
360918c283dfSAditya Swarup }
3610df0566a6SJani Nikula
intel_bios_encoder_supports_typec_usb(const struct intel_bios_encoder_data * devdata)3611df0566a6SJani Nikula bool intel_bios_encoder_supports_typec_usb(const struct intel_bios_encoder_data *devdata)
3612df0566a6SJani Nikula {
3613dbd440d8SJani Nikula return devdata->i915->display.vbt.version >= 195 && devdata->child.dp_usb_type_c;
361418c283dfSAditya Swarup }
3615dbd440d8SJani Nikula
intel_bios_encoder_supports_tbt(const struct intel_bios_encoder_data * devdata)361618c283dfSAditya Swarup bool intel_bios_encoder_supports_tbt(const struct intel_bios_encoder_data *devdata)
361718c283dfSAditya Swarup {
361818c283dfSAditya Swarup return devdata->i915->display.vbt.version >= 209 && devdata->child.tbt;
3619df0566a6SJani Nikula }
3620df0566a6SJani Nikula
intel_bios_encoder_lane_reversal(const struct intel_bios_encoder_data * devdata)3621612dc414SImre Deak bool intel_bios_encoder_lane_reversal(const struct intel_bios_encoder_data *devdata)
3622ed2615a8SMatt Roper {
3623ed2615a8SMatt Roper return devdata && devdata->child.lane_reversal;
362418c283dfSAditya Swarup }
3625dbd440d8SJani Nikula
intel_bios_encoder_hpd_invert(const struct intel_bios_encoder_data * devdata)362618c283dfSAditya Swarup bool intel_bios_encoder_hpd_invert(const struct intel_bios_encoder_data *devdata)
362718c283dfSAditya Swarup {
362818c283dfSAditya Swarup return devdata && devdata->child.hpd_invert;
3629df0566a6SJani Nikula }
3630df0566a6SJani Nikula
3631612dc414SImre Deak const struct intel_bios_encoder_data *
intel_bios_encoder_data_lookup(struct drm_i915_private * i915,enum port port)3632ed2615a8SMatt Roper intel_bios_encoder_data_lookup(struct drm_i915_private *i915, enum port port)
3633ed2615a8SMatt Roper {
363418c283dfSAditya Swarup struct intel_bios_encoder_data *devdata;
363518c283dfSAditya Swarup
3636df0566a6SJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) {
3637df0566a6SJani Nikula if (intel_bios_encoder_port(devdata) == port)
3638df0566a6SJani Nikula return devdata;
3639612dc414SImre Deak }
3640ed2615a8SMatt Roper
3641ed2615a8SMatt Roper return NULL;
3642df0566a6SJani Nikula }
3643df0566a6SJani Nikula
intel_bios_for_each_encoder(struct drm_i915_private * i915,void (* func)(struct drm_i915_private * i915,const struct intel_bios_encoder_data * devdata))3644eb8de23cSKhaled Almahallawy void intel_bios_for_each_encoder(struct drm_i915_private *i915,
3645612dc414SImre Deak void (*func)(struct drm_i915_private *i915,
3646ed2615a8SMatt Roper const struct intel_bios_encoder_data *devdata))
3647ed2615a8SMatt Roper {
3648eb8de23cSKhaled Almahallawy struct intel_bios_encoder_data *devdata;
3649eb8de23cSKhaled Almahallawy
36505bf22ee4SVille Syrjälä list_for_each_entry(devdata, &i915->display.vbt.display_devices, node)
3651612dc414SImre Deak func(i915, devdata);
3652ed2615a8SMatt Roper }
3653ed2615a8SMatt Roper