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 28da68386dSThomas Zimmermann #include <drm/display/drm_dp_helper.h> 292a64b147SThomas Zimmermann #include <drm/display/drm_dsc_helper.h> 30cfc10489SJani Nikula #include <drm/drm_edid.h> 31df0566a6SJani Nikula 32df0566a6SJani Nikula #include "i915_drv.h" 33ce2fce25SMatt Roper #include "i915_reg.h" 34cfc10489SJani Nikula #include "intel_display.h" 35cfc10489SJani Nikula #include "intel_display_types.h" 36cfc10489SJani Nikula #include "intel_gmbus.h" 37df0566a6SJani Nikula 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 630d9ef19bSJani Nikula /* Wrapper for VBT child device config */ 643162d057SJani Nikula struct intel_bios_encoder_data { 657371fa34SJani Nikula struct drm_i915_private *i915; 667371fa34SJani Nikula 670d9ef19bSJani Nikula struct child_device_config child; 686e0d46e9SJani Nikula struct dsc_compression_parameters_entry *dsc; 690d9ef19bSJani Nikula struct list_head node; 700d9ef19bSJani Nikula }; 710d9ef19bSJani Nikula 72df0566a6SJani 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. */ 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. */ 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 * 92e163cfb4SVille Syrjälä find_raw_section(const void *_bdb, enum bdb_block_id section_id) 93df0566a6SJani Nikula { 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 122e163cfb4SVille Syrjälä /* 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ä */ 12639b1bc4bSVille Syrjälä static u32 raw_block_offset(const void *bdb, enum bdb_block_id section_id) 127e163cfb4SVille 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 * 1440a93eeb5SMaarten Lankhorst 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ä 149a434689cSJani Nikula list_for_each_entry(entry, &i915->display.vbt.bdb_blocks, node) { 150e163cfb4SVille Syrjälä 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), }, 177901a0cadSVille 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ä */ 181e163cfb4SVille 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, 184901a0cadSVille Syrjälä .min_size = 0, /* special case */ }, 185e163cfb4SVille 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ä 199901a0cadSVille 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ä 2040a93eeb5SMaarten Lankhorst 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ä 216514003e1SVille 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ä { 2195ab58d69SVille Syrjälä int fp_timing_size, dvo_timing_size, panel_pnp_id_size, panel_name_size; 220514003e1SVille Syrjälä int data_block_size, lfp_data_size; 2214e78d602SVille Syrjälä const void *data_block; 222514003e1SVille Syrjälä int i; 223514003e1SVille Syrjälä 2244e78d602SVille 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); 229514003e1SVille 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; 2395ab58d69SVille Syrjälä panel_name_size = ptrs->panel_name.table_size; 240514003e1SVille 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ä 2475ab58d69SVille 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ä 252514003e1SVille 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ä 2694e78d602SVille 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ä 286514003e1SVille 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ä 2945ab58d69SVille Syrjälä if (ptrs->panel_name.offset + 16 * panel_name_size > data_block_size) 2955ab58d69SVille Syrjälä return false; 2965ab58d69SVille Syrjälä 2974e78d602SVille 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ä 306514003e1SVille Syrjälä return true; 307514003e1SVille Syrjälä } 308514003e1SVille Syrjälä 309918f3025SVille Syrjälä /* make the data table offsets relative to the data 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ä 31639b1bc4bSVille Syrjälä offset = raw_block_offset(bdb, BDB_LVDS_LFP_DATA); 317918f3025SVille 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ä 3295ab58d69SVille 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ä 336514003e1SVille Syrjälä return validate_lfp_data_ptrs(bdb, ptrs); 337918f3025SVille Syrjälä } 338918f3025SVille Syrjälä 339a87d0a84SVille 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ä 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ä 359a87d0a84SVille Syrjälä static void *generate_lfp_data_ptrs(struct drm_i915_private *i915, 360a87d0a84SVille Syrjälä const void *bdb) 361a87d0a84SVille Syrjälä { 362d3a70518SVille Syrjälä int i, size, table_size, block_size, offset, fp_timing_size; 363a87d0a84SVille Syrjälä struct bdb_lvds_lfp_data_ptrs *ptrs; 364d3a70518SVille Syrjälä const void *block; 365a87d0a84SVille Syrjälä void *ptrs_block; 366a87d0a84SVille Syrjälä 367d3a70518SVille 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ä 378a87d0a84SVille 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ä 386d3a70518SVille Syrjälä size = fp_timing_size + sizeof(struct lvds_dvo_timing) + 387d3a70518SVille Syrjälä sizeof(struct lvds_pnp_id); 388a87d0a84SVille 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ä 405d3a70518SVille Syrjälä table_size = fp_timing_size; 406a87d0a84SVille 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) { 4167674cd0bSXia Fukun kfree(ptrs_block); 417a87d0a84SVille Syrjälä return NULL; 418a87d0a84SVille Syrjälä } 419a87d0a84SVille Syrjälä 420d3a70518SVille Syrjälä size = fp_timing_size + sizeof(struct lvds_dvo_timing) + 421d3a70518SVille Syrjälä sizeof(struct lvds_pnp_id); 422a87d0a84SVille 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ä 449e163cfb4SVille Syrjälä static void 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; 455a87d0a84SVille Syrjälä void *temp_block = NULL; 456e163cfb4SVille 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); 460a87d0a84SVille 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ä } 467e163cfb4SVille 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ä 475a06289f3SVille 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ä 482e163cfb4SVille Syrjälä entry = kzalloc(struct_size(entry, data, max(min_size, block_size) + 3), 483e163cfb4SVille Syrjälä GFP_KERNEL); 484a87d0a84SVille Syrjälä if (!entry) { 485a87d0a84SVille Syrjälä kfree(temp_block); 486e163cfb4SVille Syrjälä return; 487a87d0a84SVille Syrjälä } 488e163cfb4SVille Syrjälä 489e163cfb4SVille Syrjälä entry->section_id = section_id; 490e163cfb4SVille Syrjälä memcpy(entry->data, block - 3, block_size + 3); 491e163cfb4SVille Syrjälä 492a87d0a84SVille Syrjälä kfree(temp_block); 493a87d0a84SVille Syrjälä 494e163cfb4SVille 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ä 497918f3025SVille 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ä 504a434689cSJani Nikula list_add_tail(&entry->node, &i915->display.vbt.bdb_blocks); 505e163cfb4SVille Syrjälä } 506e163cfb4SVille Syrjälä 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ä 516901a0cadSVille Syrjälä if (section_id == BDB_LVDS_LFP_DATA) 517901a0cadSVille Syrjälä min_size = lfp_data_min_size(i915); 518901a0cadSVille Syrjälä 519e163cfb4SVille Syrjälä init_bdb_block(i915, bdb, section_id, min_size); 520e163cfb4SVille Syrjälä } 521e163cfb4SVille Syrjälä } 522e163cfb4SVille Syrjälä 523df0566a6SJani Nikula static void 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 * 57458b2e382SVille Syrjälä get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *data, 57558b2e382SVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs, 576df0566a6SJani Nikula int index) 577df0566a6SJani Nikula { 57858b2e382SVille Syrjälä return (const void *)data + ptrs->ptr[index].dvo_timing.offset; 579df0566a6SJani Nikula } 580df0566a6SJani Nikula 581df0566a6SJani Nikula static const struct lvds_fp_timing * 582918f3025SVille Syrjälä get_lvds_fp_timing(const struct bdb_lvds_lfp_data *data, 583df0566a6SJani Nikula const struct bdb_lvds_lfp_data_ptrs *ptrs, 584df0566a6SJani Nikula int index) 585df0566a6SJani Nikula { 58658b2e382SVille Syrjälä return (const void *)data + ptrs->ptr[index].fp_timing.offset; 587df0566a6SJani Nikula } 588df0566a6SJani Nikula 589c518a775SVille Syrjälä static const struct lvds_pnp_id * 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ä 597901a0cadSVille Syrjälä static const struct bdb_lvds_lfp_data_tail * 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ä 60706bfa86eSVille 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ä 620c518a775SVille Syrjälä static int opregion_get_panel_type(struct drm_i915_private *i915, 6216434cf63SAnimesh Manna const struct intel_bios_encoder_data *devdata, 622c36225a1SJani Nikula const struct drm_edid *drm_edid, bool use_fallback) 623cc589f2dSVille Syrjälä { 624cc589f2dSVille Syrjälä return intel_opregion_get_panel_type(i915); 625cc589f2dSVille Syrjälä } 626cc589f2dSVille Syrjälä 627c518a775SVille Syrjälä static int vbt_get_panel_type(struct drm_i915_private *i915, 6286434cf63SAnimesh Manna const struct intel_bios_encoder_data *devdata, 629c36225a1SJani Nikula const struct drm_edid *drm_edid, bool use_fallback) 630719f4c51SVille Syrjälä { 631719f4c51SVille Syrjälä const struct bdb_lvds_options *lvds_options; 632719f4c51SVille Syrjälä 6330a93eeb5SMaarten Lankhorst lvds_options = bdb_find_section(i915, BDB_LVDS_OPTIONS); 634719f4c51SVille Syrjälä if (!lvds_options) 635719f4c51SVille Syrjälä return -1; 636719f4c51SVille Syrjälä 637c518a775SVille Syrjälä if (lvds_options->panel_type > 0xf && 638c518a775SVille Syrjälä lvds_options->panel_type != 0xff) { 639719f4c51SVille 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ä 6446434cf63SAnimesh Manna 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 649719f4c51SVille Syrjälä return lvds_options->panel_type; 650719f4c51SVille Syrjälä } 651719f4c51SVille Syrjälä 652c518a775SVille Syrjälä static int pnpid_get_panel_type(struct drm_i915_private *i915, 6536434cf63SAnimesh Manna const struct intel_bios_encoder_data *devdata, 654c36225a1SJani Nikula 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; 660c36225a1SJani Nikula 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ä 6740a93eeb5SMaarten Lankhorst ptrs = bdb_find_section(i915, BDB_LVDS_LFP_DATA_PTRS); 675c518a775SVille Syrjälä if (!ptrs) 676c518a775SVille Syrjälä return -1; 677c518a775SVille Syrjälä 6780a93eeb5SMaarten Lankhorst 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ä 702c518a775SVille Syrjälä static int fallback_get_panel_type(struct drm_i915_private *i915, 7036434cf63SAnimesh Manna const struct intel_bios_encoder_data *devdata, 704c36225a1SJani Nikula const struct drm_edid *drm_edid, bool use_fallback) 705cc589f2dSVille Syrjälä { 7063f9ffce5SVille 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ä 716c518a775SVille Syrjälä static int get_panel_type(struct drm_i915_private *i915, 7176434cf63SAnimesh Manna const struct intel_bios_encoder_data *devdata, 718c36225a1SJani Nikula 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, 724c36225a1SJani Nikula 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++) { 7473f9ffce5SVille Syrjälä panel_types[i].panel_type = panel_types[i].get_panel_type(i915, devdata, 748c36225a1SJani Nikula drm_edid, use_fallback); 749cc589f2dSVille Syrjälä 750c518a775SVille Syrjälä drm_WARN_ON(&i915->drm, panel_types[i].panel_type > 0xf && 751c518a775SVille 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", 755cc589f2dSVille Syrjälä panel_types[i].name, panel_types[i].panel_type); 756719f4c51SVille Syrjälä } 757719f4c51SVille Syrjälä 758cc589f2dSVille Syrjälä if (panel_types[PANEL_TYPE_OPREGION].panel_type >= 0) 759cc589f2dSVille 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 && 764c518a775SVille Syrjälä panel_types[PANEL_TYPE_VBT].panel_type >= 0) 765cc589f2dSVille Syrjälä i = PANEL_TYPE_VBT; 766cc589f2dSVille Syrjälä else 767cc589f2dSVille Syrjälä i = PANEL_TYPE_FALLBACK; 768719f4c51SVille 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ä 772cc589f2dSVille Syrjälä return panel_types[i].panel_type; 773719f4c51SVille Syrjälä } 774719f4c51SVille Syrjälä 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ä 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ä } 784a50cc495SVille Syrjälä 7859e7ecedfSMatt Roper /* Parse general panel options */ 786df0566a6SJani Nikula static void 7873cf05076SVille Syrjälä parse_panel_options(struct drm_i915_private *i915, 7880256ea13SVille Syrjälä struct intel_panel *panel) 789df0566a6SJani Nikula { 790df0566a6SJani Nikula const struct bdb_lvds_options *lvds_options; 7910256ea13SVille Syrjälä int panel_type = panel->vbt.panel_type; 792df0566a6SJani Nikula int drrs_mode; 793df0566a6SJani Nikula 7940a93eeb5SMaarten Lankhorst lvds_options = bdb_find_section(i915, BDB_LVDS_OPTIONS); 795df0566a6SJani Nikula if (!lvds_options) 796df0566a6SJani Nikula return; 797df0566a6SJani Nikula 7983cf05076SVille Syrjälä panel->vbt.lvds_dither = lvds_options->pixel_dither; 799df0566a6SJani Nikula 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) 8065c9016b2SVille Syrjälä return; 807df0566a6SJani Nikula 808a50cc495SVille Syrjälä drrs_mode = panel_bits(lvds_options->dps_panel_type_bits, 809a50cc495SVille Syrjälä 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) { 816df0566a6SJani Nikula case 0: 8173cf05076SVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_STATIC; 818dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, "DRRS supported mode is static\n"); 819df0566a6SJani Nikula break; 820df0566a6SJani Nikula case 2: 8213cf05076SVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_SEAMLESS; 822dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 823e92cbf38SWambui Karuga "DRRS supported mode is seamless\n"); 824df0566a6SJani Nikula break; 825df0566a6SJani Nikula default: 8263cf05076SVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_NONE; 827dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 828e92cbf38SWambui Karuga "DRRS not supported (VBT input)\n"); 829df0566a6SJani Nikula break; 830df0566a6SJani Nikula } 8319e7ecedfSMatt Roper } 8329e7ecedfSMatt Roper 8339e7ecedfSMatt Roper static void 83413367132SVille Syrjälä parse_lfp_panel_dtd(struct drm_i915_private *i915, 8353cf05076SVille Syrjälä struct intel_panel *panel, 83613367132SVille Syrjälä const struct bdb_lvds_lfp_data *lvds_lfp_data, 83713367132SVille Syrjälä 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; 8419e7ecedfSMatt Roper struct drm_display_mode *panel_fixed_mode; 8423cf05076SVille Syrjälä 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); 853df0566a6SJani Nikula 8543cf05076SVille Syrjälä panel->vbt.lfp_lvds_vbt_mode = panel_fixed_mode; 855df0566a6SJani Nikula 856dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 857f01bae2dSVille Syrjälä "Found panel mode in BIOS VBT legacy lfp table: " DRM_MODE_FMT "\n", 858f01bae2dSVille Syrjälä DRM_MODE_ARG(panel_fixed_mode)); 859df0566a6SJani Nikula 860918f3025SVille Syrjälä fp_timing = get_lvds_fp_timing(lvds_lfp_data, 861df0566a6SJani Nikula lvds_lfp_data_ptrs, 862df0566a6SJani Nikula panel_type); 86358b2e382SVille Syrjälä 864df0566a6SJani Nikula /* check the resolution, just to be sure */ 865df0566a6SJani Nikula if (fp_timing->x_res == panel_fixed_mode->hdisplay && 866df0566a6SJani Nikula fp_timing->y_res == panel_fixed_mode->vdisplay) { 8673cf05076SVille Syrjälä panel->vbt.bios_lvds_val = fp_timing->lvds_reg_val; 868dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 869e92cbf38SWambui Karuga "VBT initial LVDS value %x\n", 8703cf05076SVille Syrjälä panel->vbt.bios_lvds_val); 871df0566a6SJani Nikula } 872df0566a6SJani Nikula } 873df0566a6SJani Nikula 874df0566a6SJani Nikula static void 8753cf05076SVille Syrjälä parse_lfp_data(struct drm_i915_private *i915, 8763cf05076SVille Syrjälä struct intel_panel *panel) 87713367132SVille Syrjälä { 87813367132SVille Syrjälä const struct bdb_lvds_lfp_data *data; 879901a0cadSVille Syrjälä const struct bdb_lvds_lfp_data_tail *tail; 88013367132SVille Syrjälä const struct bdb_lvds_lfp_data_ptrs *ptrs; 88106bfa86eSVille Syrjälä const struct lvds_pnp_id *pnp_id; 8823cf05076SVille Syrjälä int panel_type = panel->vbt.panel_type; 88313367132SVille Syrjälä 8840a93eeb5SMaarten Lankhorst ptrs = bdb_find_section(i915, BDB_LVDS_LFP_DATA_PTRS); 88513367132SVille Syrjälä if (!ptrs) 88613367132SVille Syrjälä return; 88713367132SVille Syrjälä 8880a93eeb5SMaarten Lankhorst data = bdb_find_section(i915, BDB_LVDS_LFP_DATA); 88913367132SVille Syrjälä if (!data) 89013367132SVille Syrjälä return; 89113367132SVille Syrjälä 8923cf05076SVille Syrjälä if (!panel->vbt.lfp_lvds_vbt_mode) 8933cf05076SVille Syrjälä parse_lfp_panel_dtd(i915, panel, data, ptrs); 894901a0cadSVille 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"); 89706bfa86eSVille Syrjälä 898901a0cadSVille Syrjälä tail = get_lfp_data_tail(data, ptrs); 899901a0cadSVille Syrjälä if (!tail) 900901a0cadSVille Syrjälä return; 901901a0cadSVille 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); 90506bfa86eSVille Syrjälä 906a434689cSJani Nikula if (i915->display.vbt.version >= 188) { 9073cf05076SVille 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, 910790b45f1SVille Syrjälä "Seamless DRRS min refresh rate: %d Hz\n", 9113cf05076SVille Syrjälä panel->vbt.seamless_drrs_min_refresh_rate); 912790b45f1SVille Syrjälä } 91313367132SVille Syrjälä } 91413367132SVille Syrjälä 91513367132SVille Syrjälä static void 9163cf05076SVille Syrjälä parse_generic_dtd(struct drm_i915_private *i915, 9173cf05076SVille Syrjälä 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; 92333ef6d4fSMatt Roper 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. 93113367132SVille Syrjälä */ 932a434689cSJani Nikula if (i915->display.vbt.version < 229) 93313367132SVille Syrjälä return; 93413367132SVille Syrjälä 9350a93eeb5SMaarten Lankhorst generic_dtd = bdb_find_section(i915, BDB_GENERIC_DTD); 93633ef6d4fSMatt Roper if (!generic_dtd) 93733ef6d4fSMatt Roper return; 93833ef6d4fSMatt Roper 93933ef6d4fSMatt Roper if (generic_dtd->gdtd_size < sizeof(struct generic_dtd_entry)) { 940dbd440d8SJani Nikula 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 != 94433ef6d4fSMatt Roper sizeof(struct generic_dtd_entry)) { 945dbd440d8SJani Nikula drm_err(&i915->drm, "Unexpected GDTD size %u\n", 946e92cbf38SWambui Karuga 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) - 95133ef6d4fSMatt Roper sizeof(struct bdb_generic_dtd)) / generic_dtd->gdtd_size; 9523cf05076SVille Syrjälä if (panel->vbt.panel_type >= num_dtd) { 953dbd440d8SJani Nikula drm_err(&i915->drm, 954e92cbf38SWambui Karuga "Panel type %d not found in table of %d DTD's\n", 9553cf05076SVille Syrjälä panel->vbt.panel_type, num_dtd); 95633ef6d4fSMatt Roper return; 95733ef6d4fSMatt Roper } 95833ef6d4fSMatt Roper 9593cf05076SVille Syrjälä 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 = 96933ef6d4fSMatt Roper panel_fixed_mode->hsync_start + dtd->hsync; 970ad278f35SVandita Kulkarni panel_fixed_mode->htotal = 971ad278f35SVandita Kulkarni 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 = 97733ef6d4fSMatt Roper panel_fixed_mode->vsync_start + dtd->vsync; 978ad278f35SVandita Kulkarni panel_fixed_mode->vtotal = 979ad278f35SVandita Kulkarni 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; 99733ef6d4fSMatt Roper 998dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 999f01bae2dSVille Syrjälä "Found panel mode in BIOS VBT generic dtd table: " DRM_MODE_FMT "\n", 1000f01bae2dSVille Syrjälä DRM_MODE_ARG(panel_fixed_mode)); 100133ef6d4fSMatt Roper 10023cf05076SVille Syrjälä panel->vbt.lfp_lvds_vbt_mode = panel_fixed_mode; 100333ef6d4fSMatt Roper } 100433ef6d4fSMatt Roper 100533ef6d4fSMatt Roper static void 10063cf05076SVille Syrjälä parse_lfp_backlight(struct drm_i915_private *i915, 10073cf05076SVille Syrjälä struct intel_panel *panel) 1008df0566a6SJani Nikula { 1009df0566a6SJani Nikula const struct bdb_lfp_backlight_data *backlight_data; 1010df0566a6SJani Nikula const struct lfp_backlight_data_entry *entry; 10113cf05076SVille Syrjälä int panel_type = panel->vbt.panel_type; 1012d381baadSJosé Roberto de Souza u16 level; 1013df0566a6SJani Nikula 10140a93eeb5SMaarten Lankhorst backlight_data = bdb_find_section(i915, BDB_LVDS_BACKLIGHT); 1015df0566a6SJani Nikula if (!backlight_data) 1016df0566a6SJani Nikula return; 1017df0566a6SJani Nikula 1018df0566a6SJani Nikula if (backlight_data->entry_size != sizeof(backlight_data->data[0])) { 1019dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1020e92cbf38SWambui Karuga "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]; 1026df0566a6SJani Nikula 10273cf05076SVille Syrjälä panel->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM; 10283cf05076SVille Syrjälä if (!panel->vbt.backlight.present) { 1029dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1030e92cbf38SWambui Karuga "PWM backlight not present in VBT (type %u)\n", 1031df0566a6SJani Nikula entry->type); 1032df0566a6SJani Nikula return; 1033df0566a6SJani Nikula } 1034df0566a6SJani Nikula 10353cf05076SVille Syrjälä panel->vbt.backlight.type = INTEL_BACKLIGHT_DISPLAY_DDI; 1036a0dcb06dSJani Nikula panel->vbt.backlight.controller = 0; 1037a434689cSJani Nikula if (i915->display.vbt.version >= 191) { 10384378daf5SLukasz Majczak size_t exp_size; 10394378daf5SLukasz Majczak 1040a434689cSJani Nikula if (i915->display.vbt.version >= 236) 10414378daf5SLukasz Majczak exp_size = sizeof(struct bdb_lfp_backlight_data); 1042a434689cSJani Nikula else if (i915->display.vbt.version >= 234) 10434378daf5SLukasz Majczak exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_234; 10444378daf5SLukasz Majczak else 10454378daf5SLukasz Majczak exp_size = EXP_BDB_LFP_BL_DATA_SIZE_REV_191; 10464378daf5SLukasz Majczak 10474378daf5SLukasz Majczak if (get_blocksize(backlight_data) >= exp_size) { 1048df0566a6SJani Nikula const struct lfp_backlight_control_method *method; 1049df0566a6SJani Nikula 1050df0566a6SJani Nikula method = &backlight_data->backlight_control[panel_type]; 10513cf05076SVille Syrjälä panel->vbt.backlight.type = method->type; 10523cf05076SVille Syrjälä panel->vbt.backlight.controller = method->controller; 1053df0566a6SJani Nikula } 10544378daf5SLukasz Majczak } 1055df0566a6SJani Nikula 10563cf05076SVille Syrjälä panel->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz; 10573cf05076SVille Syrjälä panel->vbt.backlight.active_low_pwm = entry->active_low_pwm; 1058d381baadSJosé Roberto de Souza 1059a434689cSJani Nikula if (i915->display.vbt.version >= 234) { 1060d381baadSJosé Roberto de Souza u16 min_level; 1061d381baadSJosé Roberto de Souza bool scale; 1062d381baadSJosé Roberto de Souza 1063d381baadSJosé Roberto de Souza level = backlight_data->brightness_level[panel_type].level; 1064d381baadSJosé Roberto de Souza min_level = backlight_data->brightness_min_level[panel_type].level; 1065d381baadSJosé Roberto de Souza 1066a434689cSJani Nikula if (i915->display.vbt.version >= 236) 1067d381baadSJosé Roberto de Souza scale = backlight_data->brightness_precision_bits[panel_type] == 16; 1068d381baadSJosé Roberto de Souza else 1069d381baadSJosé Roberto de Souza scale = level > 255; 1070d381baadSJosé Roberto de Souza 1071d381baadSJosé Roberto de Souza if (scale) 1072d381baadSJosé Roberto de Souza min_level = min_level / 255; 1073d381baadSJosé Roberto de Souza 1074d381baadSJosé Roberto de Souza if (min_level > 255) { 1075dbd440d8SJani Nikula drm_warn(&i915->drm, "Brightness min level > 255\n"); 1076d381baadSJosé Roberto de Souza level = 255; 1077d381baadSJosé Roberto de Souza } 10783cf05076SVille Syrjälä panel->vbt.backlight.min_brightness = min_level; 107984d3d71fSLee Shawn C 10803cf05076SVille Syrjälä panel->vbt.backlight.brightness_precision_bits = 108184d3d71fSLee Shawn C backlight_data->brightness_precision_bits[panel_type]; 1082d381baadSJosé Roberto de Souza } else { 1083d381baadSJosé Roberto de Souza level = backlight_data->level[panel_type]; 10843cf05076SVille Syrjälä panel->vbt.backlight.min_brightness = entry->min_brightness; 1085d381baadSJosé Roberto de Souza } 1086d381baadSJosé Roberto de Souza 1087fe82b93fSVille Syrjälä if (i915->display.vbt.version >= 239) 1088fe82b93fSVille Syrjälä panel->vbt.backlight.hdr_dpcd_refresh_timeout = 1089fe82b93fSVille Syrjälä DIV_ROUND_UP(backlight_data->hdr_dpcd_refresh_timeout[panel_type], 100); 1090fe82b93fSVille Syrjälä else 1091fe82b93fSVille Syrjälä panel->vbt.backlight.hdr_dpcd_refresh_timeout = 30; 1092fe82b93fSVille Syrjälä 1093dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1094e92cbf38SWambui Karuga "VBT backlight PWM modulation frequency %u Hz, " 1095df0566a6SJani Nikula "active %s, min brightness %u, level %u, controller %u\n", 10963cf05076SVille Syrjälä panel->vbt.backlight.pwm_freq_hz, 10973cf05076SVille Syrjälä panel->vbt.backlight.active_low_pwm ? "low" : "high", 10983cf05076SVille Syrjälä panel->vbt.backlight.min_brightness, 1099d381baadSJosé Roberto de Souza level, 11003cf05076SVille Syrjälä panel->vbt.backlight.controller); 1101df0566a6SJani Nikula } 1102df0566a6SJani Nikula 1103df0566a6SJani Nikula /* Try to find sdvo panel data */ 1104df0566a6SJani Nikula static void 11053cf05076SVille Syrjälä parse_sdvo_panel_data(struct drm_i915_private *i915, 11063cf05076SVille Syrjälä struct intel_panel *panel) 1107df0566a6SJani Nikula { 1108df0566a6SJani Nikula const struct bdb_sdvo_panel_dtds *dtds; 1109df0566a6SJani Nikula struct drm_display_mode *panel_fixed_mode; 1110df0566a6SJani Nikula int index; 1111df0566a6SJani Nikula 1112dbd440d8SJani Nikula index = i915->params.vbt_sdvo_panel_type; 1113df0566a6SJani Nikula if (index == -2) { 1114dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1115e92cbf38SWambui Karuga "Ignore SDVO panel mode from BIOS VBT tables.\n"); 1116df0566a6SJani Nikula return; 1117df0566a6SJani Nikula } 1118df0566a6SJani Nikula 1119df0566a6SJani Nikula if (index == -1) { 1120df0566a6SJani Nikula const struct bdb_sdvo_lvds_options *sdvo_lvds_options; 1121df0566a6SJani Nikula 11220a93eeb5SMaarten Lankhorst sdvo_lvds_options = bdb_find_section(i915, BDB_SDVO_LVDS_OPTIONS); 1123df0566a6SJani Nikula if (!sdvo_lvds_options) 1124df0566a6SJani Nikula return; 1125df0566a6SJani Nikula 1126df0566a6SJani Nikula index = sdvo_lvds_options->panel_type; 1127df0566a6SJani Nikula } 1128df0566a6SJani Nikula 11290a93eeb5SMaarten Lankhorst dtds = bdb_find_section(i915, BDB_SDVO_PANEL_DTDS); 1130df0566a6SJani Nikula if (!dtds) 1131df0566a6SJani Nikula return; 1132df0566a6SJani Nikula 1133df0566a6SJani Nikula panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL); 1134df0566a6SJani Nikula if (!panel_fixed_mode) 1135df0566a6SJani Nikula return; 1136df0566a6SJani Nikula 1137df0566a6SJani Nikula fill_detail_timing_data(panel_fixed_mode, &dtds->dtds[index]); 1138df0566a6SJani Nikula 11393cf05076SVille Syrjälä panel->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode; 1140df0566a6SJani Nikula 1141dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1142f01bae2dSVille Syrjälä "Found SDVO panel mode in BIOS VBT tables: " DRM_MODE_FMT "\n", 1143f01bae2dSVille Syrjälä DRM_MODE_ARG(panel_fixed_mode)); 1144df0566a6SJani Nikula } 1145df0566a6SJani Nikula 1146dbd440d8SJani Nikula static int intel_bios_ssc_frequency(struct drm_i915_private *i915, 1147df0566a6SJani Nikula bool alternate) 1148df0566a6SJani Nikula { 1149005e9537SMatt Roper switch (DISPLAY_VER(i915)) { 1150df0566a6SJani Nikula case 2: 1151df0566a6SJani Nikula return alternate ? 66667 : 48000; 1152df0566a6SJani Nikula case 3: 1153df0566a6SJani Nikula case 4: 1154df0566a6SJani Nikula return alternate ? 100000 : 96000; 1155df0566a6SJani Nikula default: 1156df0566a6SJani Nikula return alternate ? 100000 : 120000; 1157df0566a6SJani Nikula } 1158df0566a6SJani Nikula } 1159df0566a6SJani Nikula 1160df0566a6SJani Nikula static void 1161e163cfb4SVille Syrjälä parse_general_features(struct drm_i915_private *i915) 1162df0566a6SJani Nikula { 1163df0566a6SJani Nikula const struct bdb_general_features *general; 1164df0566a6SJani Nikula 11650a93eeb5SMaarten Lankhorst general = bdb_find_section(i915, BDB_GENERAL_FEATURES); 1166df0566a6SJani Nikula if (!general) 1167df0566a6SJani Nikula return; 1168df0566a6SJani Nikula 1169a434689cSJani Nikula i915->display.vbt.int_tv_support = general->int_tv_support; 1170df0566a6SJani Nikula /* int_crt_support can't be trusted on earlier platforms */ 1171a434689cSJani Nikula if (i915->display.vbt.version >= 155 && 1172dbd440d8SJani Nikula (HAS_DDI(i915) || IS_VALLEYVIEW(i915))) 1173a434689cSJani Nikula i915->display.vbt.int_crt_support = general->int_crt_support; 1174a434689cSJani Nikula i915->display.vbt.lvds_use_ssc = general->enable_ssc; 1175a434689cSJani Nikula i915->display.vbt.lvds_ssc_freq = 1176dbd440d8SJani Nikula intel_bios_ssc_frequency(i915, general->ssc_freq); 1177a434689cSJani Nikula i915->display.vbt.display_clock_mode = general->display_clock_mode; 1178a434689cSJani Nikula i915->display.vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted; 1179a434689cSJani Nikula if (i915->display.vbt.version >= 181) { 1180a434689cSJani Nikula i915->display.vbt.orientation = general->rotate_180 ? 1181df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP : 1182df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_NORMAL; 1183df0566a6SJani Nikula } else { 1184a434689cSJani Nikula i915->display.vbt.orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 1185df0566a6SJani Nikula } 1186b70ad01aSJosé Roberto de Souza 1187a434689cSJani Nikula if (i915->display.vbt.version >= 249 && general->afc_startup_config) { 1188a434689cSJani Nikula i915->display.vbt.override_afc_startup = true; 1189a434689cSJani Nikula i915->display.vbt.override_afc_startup_val = general->afc_startup_config == 0x1 ? 0x0 : 0x7; 1190b70ad01aSJosé Roberto de Souza } 1191b70ad01aSJosé Roberto de Souza 1192dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1193e92cbf38SWambui Karuga "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", 1194a434689cSJani Nikula i915->display.vbt.int_tv_support, 1195a434689cSJani Nikula i915->display.vbt.int_crt_support, 1196a434689cSJani Nikula i915->display.vbt.lvds_use_ssc, 1197a434689cSJani Nikula i915->display.vbt.lvds_ssc_freq, 1198a434689cSJani Nikula i915->display.vbt.display_clock_mode, 1199a434689cSJani Nikula i915->display.vbt.fdi_rx_polarity_inverted); 1200df0566a6SJani Nikula } 1201df0566a6SJani Nikula 1202df0566a6SJani Nikula static const struct child_device_config * 1203df0566a6SJani Nikula child_device_ptr(const struct bdb_general_definitions *defs, int i) 1204df0566a6SJani Nikula { 1205df0566a6SJani Nikula return (const void *) &defs->devices[i * defs->child_dev_size]; 1206df0566a6SJani Nikula } 1207df0566a6SJani Nikula 1208df0566a6SJani Nikula static void 1209ef0096e4SJani Nikula parse_sdvo_device_mapping(struct drm_i915_private *i915) 1210df0566a6SJani Nikula { 12113162d057SJani Nikula const struct intel_bios_encoder_data *devdata; 12120d9ef19bSJani Nikula int count = 0; 1213df0566a6SJani Nikula 1214df0566a6SJani Nikula /* 1215df0566a6SJani Nikula * Only parse SDVO mappings on gens that could have SDVO. This isn't 1216df0566a6SJani Nikula * accurate and doesn't have to be, as long as it's not too strict. 1217df0566a6SJani Nikula */ 121893e7e61eSLucas De Marchi if (!IS_DISPLAY_VER(i915, 3, 7)) { 1219dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, "Skipping SDVO device mapping\n"); 1220df0566a6SJani Nikula return; 1221df0566a6SJani Nikula } 1222df0566a6SJani Nikula 1223a434689cSJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) { 1224d24b3475SVille Syrjälä const struct child_device_config *child = &devdata->child; 1225d24b3475SVille Syrjälä struct sdvo_device_mapping *mapping; 1226df0566a6SJani Nikula 1227df0566a6SJani Nikula if (child->slave_addr != SLAVE_ADDR1 && 1228df0566a6SJani Nikula child->slave_addr != SLAVE_ADDR2) { 1229df0566a6SJani Nikula /* 1230df0566a6SJani Nikula * If the slave address is neither 0x70 nor 0x72, 1231df0566a6SJani Nikula * it is not a SDVO device. Skip it. 1232df0566a6SJani Nikula */ 1233df0566a6SJani Nikula continue; 1234df0566a6SJani Nikula } 1235df0566a6SJani Nikula if (child->dvo_port != DEVICE_PORT_DVOB && 1236df0566a6SJani Nikula child->dvo_port != DEVICE_PORT_DVOC) { 1237df0566a6SJani Nikula /* skip the incorrect SDVO port */ 1238dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1239e92cbf38SWambui Karuga "Incorrect SDVO port. Skip it\n"); 1240df0566a6SJani Nikula continue; 1241df0566a6SJani Nikula } 1242dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1243e92cbf38SWambui Karuga "the SDVO device with slave addr %2x is found on" 1244df0566a6SJani Nikula " %s port\n", 1245df0566a6SJani Nikula child->slave_addr, 1246df0566a6SJani Nikula (child->dvo_port == DEVICE_PORT_DVOB) ? 1247df0566a6SJani Nikula "SDVOB" : "SDVOC"); 1248a434689cSJani Nikula mapping = &i915->display.vbt.sdvo_mappings[child->dvo_port - 1]; 1249df0566a6SJani Nikula if (!mapping->initialized) { 1250df0566a6SJani Nikula mapping->dvo_port = child->dvo_port; 1251df0566a6SJani Nikula mapping->slave_addr = child->slave_addr; 1252df0566a6SJani Nikula mapping->dvo_wiring = child->dvo_wiring; 1253df0566a6SJani Nikula mapping->ddc_pin = child->ddc_pin; 1254df0566a6SJani Nikula mapping->i2c_pin = child->i2c_pin; 1255df0566a6SJani Nikula mapping->initialized = 1; 1256dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1257e92cbf38SWambui Karuga "SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n", 1258e92cbf38SWambui Karuga mapping->dvo_port, mapping->slave_addr, 1259e92cbf38SWambui Karuga mapping->dvo_wiring, mapping->ddc_pin, 1260df0566a6SJani Nikula mapping->i2c_pin); 1261df0566a6SJani Nikula } else { 1262dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1263e92cbf38SWambui Karuga "Maybe one SDVO port is shared by " 1264df0566a6SJani Nikula "two SDVO device.\n"); 1265df0566a6SJani Nikula } 1266df0566a6SJani Nikula if (child->slave2_addr) { 1267df0566a6SJani Nikula /* Maybe this is a SDVO device with multiple inputs */ 1268df0566a6SJani Nikula /* And the mapping info is not added */ 1269dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1270e92cbf38SWambui Karuga "there exists the slave2_addr. Maybe this" 1271df0566a6SJani Nikula " is a SDVO device with multiple inputs.\n"); 1272df0566a6SJani Nikula } 1273df0566a6SJani Nikula count++; 1274df0566a6SJani Nikula } 1275df0566a6SJani Nikula 1276df0566a6SJani Nikula if (!count) { 1277df0566a6SJani Nikula /* No SDVO device info is found */ 1278dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1279e92cbf38SWambui Karuga "No SDVO device info is found in VBT\n"); 1280df0566a6SJani Nikula } 1281df0566a6SJani Nikula } 1282df0566a6SJani Nikula 1283df0566a6SJani Nikula static void 1284e163cfb4SVille Syrjälä parse_driver_features(struct drm_i915_private *i915) 1285df0566a6SJani Nikula { 1286df0566a6SJani Nikula const struct bdb_driver_features *driver; 1287df0566a6SJani Nikula 12880a93eeb5SMaarten Lankhorst driver = bdb_find_section(i915, BDB_DRIVER_FEATURES); 1289df0566a6SJani Nikula if (!driver) 1290df0566a6SJani Nikula return; 1291df0566a6SJani Nikula 1292005e9537SMatt Roper if (DISPLAY_VER(i915) >= 5) { 1293df0566a6SJani Nikula /* 1294df0566a6SJani Nikula * Note that we consider BDB_DRIVER_FEATURE_INT_SDVO_LVDS 1295df0566a6SJani Nikula * to mean "eDP". The VBT spec doesn't agree with that 1296df0566a6SJani Nikula * interpretation, but real world VBTs seem to. 1297df0566a6SJani Nikula */ 1298df0566a6SJani Nikula if (driver->lvds_config != BDB_DRIVER_FEATURE_INT_LVDS) 1299a434689cSJani Nikula i915->display.vbt.int_lvds_support = 0; 1300df0566a6SJani Nikula } else { 1301df0566a6SJani Nikula /* 1302df0566a6SJani Nikula * FIXME it's not clear which BDB version has the LVDS config 1303df0566a6SJani Nikula * bits defined. Revision history in the VBT spec says: 1304df0566a6SJani Nikula * "0.92 | Add two definitions for VBT value of LVDS Active 1305df0566a6SJani Nikula * Config (00b and 11b values defined) | 06/13/2005" 1306df0566a6SJani Nikula * but does not the specify the BDB version. 1307df0566a6SJani Nikula * 1308df0566a6SJani Nikula * So far version 134 (on i945gm) is the oldest VBT observed 1309df0566a6SJani Nikula * in the wild with the bits correctly populated. Version 1310df0566a6SJani Nikula * 108 (on i85x) does not have the bits correctly populated. 1311df0566a6SJani Nikula */ 1312a434689cSJani Nikula if (i915->display.vbt.version >= 134 && 1313df0566a6SJani Nikula driver->lvds_config != BDB_DRIVER_FEATURE_INT_LVDS && 1314df0566a6SJani Nikula driver->lvds_config != BDB_DRIVER_FEATURE_INT_SDVO_LVDS) 1315a434689cSJani Nikula i915->display.vbt.int_lvds_support = 0; 1316df0566a6SJani Nikula } 1317c3fbcf60SVille Syrjälä } 1318c3fbcf60SVille Syrjälä 1319c3fbcf60SVille Syrjälä static void 13203cf05076SVille Syrjälä parse_panel_driver_features(struct drm_i915_private *i915, 13213cf05076SVille Syrjälä struct intel_panel *panel) 1322c3fbcf60SVille Syrjälä { 1323c3fbcf60SVille Syrjälä const struct bdb_driver_features *driver; 1324c3fbcf60SVille Syrjälä 13250a93eeb5SMaarten Lankhorst driver = bdb_find_section(i915, BDB_DRIVER_FEATURES); 1326c3fbcf60SVille Syrjälä if (!driver) 1327c3fbcf60SVille Syrjälä return; 1328df0566a6SJani Nikula 1329a434689cSJani Nikula if (i915->display.vbt.version < 228) { 1330dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, "DRRS State Enabled:%d\n", 1331e92cbf38SWambui Karuga driver->drrs_enabled); 1332df0566a6SJani Nikula /* 1333df0566a6SJani Nikula * If DRRS is not supported, drrs_type has to be set to 0. 1334df0566a6SJani Nikula * This is because, VBT is configured in such a way that 1335df0566a6SJani Nikula * static DRRS is 0 and DRRS not supported is represented by 1336df0566a6SJani Nikula * driver->drrs_enabled=false 1337df0566a6SJani Nikula */ 13385a18db2eSVille Syrjälä if (!driver->drrs_enabled && panel->vbt.drrs_type != DRRS_TYPE_NONE) { 13395a18db2eSVille Syrjälä /* 13405a18db2eSVille Syrjälä * FIXME Should DMRRS perhaps be treated as seamless 13415a18db2eSVille Syrjälä * but without the automatic downclocking? 13425a18db2eSVille Syrjälä */ 13435a18db2eSVille Syrjälä if (driver->dmrrs_enabled) 13445a18db2eSVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_STATIC; 13455a18db2eSVille Syrjälä else 13463cf05076SVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_NONE; 13475a18db2eSVille Syrjälä } 1348551fb93dSJosé Roberto de Souza 13493cf05076SVille Syrjälä panel->vbt.psr.enable = driver->psr_enabled; 1350df0566a6SJani Nikula } 1351551fb93dSJosé Roberto de Souza } 1352551fb93dSJosé Roberto de Souza 1353551fb93dSJosé Roberto de Souza static void 13543cf05076SVille Syrjälä parse_power_conservation_features(struct drm_i915_private *i915, 13553cf05076SVille Syrjälä struct intel_panel *panel) 1356551fb93dSJosé Roberto de Souza { 1357551fb93dSJosé Roberto de Souza const struct bdb_lfp_power *power; 13583cf05076SVille Syrjälä u8 panel_type = panel->vbt.panel_type; 1359551fb93dSJosé Roberto de Souza 1360fba99b1aSVille Syrjälä panel->vbt.vrr = true; /* matches Windows behaviour */ 1361551fb93dSJosé Roberto de Souza 1362a434689cSJani Nikula if (i915->display.vbt.version < 228) 1363551fb93dSJosé Roberto de Souza return; 1364551fb93dSJosé Roberto de Souza 13650a93eeb5SMaarten Lankhorst power = bdb_find_section(i915, BDB_LFP_POWER); 1366551fb93dSJosé Roberto de Souza if (!power) 1367551fb93dSJosé Roberto de Souza return; 1368551fb93dSJosé Roberto de Souza 1369a50cc495SVille Syrjälä panel->vbt.psr.enable = panel_bool(power->psr, panel_type); 1370551fb93dSJosé Roberto de Souza 1371551fb93dSJosé Roberto de Souza /* 1372551fb93dSJosé Roberto de Souza * If DRRS is not supported, drrs_type has to be set to 0. 1373551fb93dSJosé Roberto de Souza * This is because, VBT is configured in such a way that 1374551fb93dSJosé Roberto de Souza * static DRRS is 0 and DRRS not supported is represented by 1375551fb93dSJosé Roberto de Souza * power->drrs & BIT(panel_type)=false 1376551fb93dSJosé Roberto de Souza */ 1377a50cc495SVille Syrjälä if (!panel_bool(power->drrs, panel_type) && panel->vbt.drrs_type != DRRS_TYPE_NONE) { 13785a18db2eSVille Syrjälä /* 13795a18db2eSVille Syrjälä * FIXME Should DMRRS perhaps be treated as seamless 13805a18db2eSVille Syrjälä * but without the automatic downclocking? 13815a18db2eSVille Syrjälä */ 1382a50cc495SVille Syrjälä if (panel_bool(power->dmrrs, panel_type)) 13835a18db2eSVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_STATIC; 13845a18db2eSVille Syrjälä else 13853cf05076SVille Syrjälä panel->vbt.drrs_type = DRRS_TYPE_NONE; 13865a18db2eSVille Syrjälä } 1387f615cb6aSJosé Roberto de Souza 1388a434689cSJani Nikula if (i915->display.vbt.version >= 232) 1389a50cc495SVille Syrjälä panel->vbt.edp.hobl = panel_bool(power->hobl, panel_type); 1390fba99b1aSVille Syrjälä 1391a434689cSJani Nikula if (i915->display.vbt.version >= 233) 1392a50cc495SVille Syrjälä panel->vbt.vrr = panel_bool(power->vrr_feature_enabled, 1393a50cc495SVille Syrjälä panel_type); 1394551fb93dSJosé Roberto de Souza } 1395df0566a6SJani Nikula 1396df0566a6SJani Nikula static void 13973cf05076SVille Syrjälä parse_edp(struct drm_i915_private *i915, 13983cf05076SVille Syrjälä struct intel_panel *panel) 1399df0566a6SJani Nikula { 1400df0566a6SJani Nikula const struct bdb_edp *edp; 1401df0566a6SJani Nikula const struct edp_power_seq *edp_pps; 1402df0566a6SJani Nikula const struct edp_fast_link_params *edp_link_params; 14033cf05076SVille Syrjälä int panel_type = panel->vbt.panel_type; 1404df0566a6SJani Nikula 14050a93eeb5SMaarten Lankhorst edp = bdb_find_section(i915, BDB_EDP); 1406df0566a6SJani Nikula if (!edp) 1407df0566a6SJani Nikula return; 1408df0566a6SJani Nikula 1409a50cc495SVille Syrjälä switch (panel_bits(edp->color_depth, panel_type, 2)) { 1410df0566a6SJani Nikula case EDP_18BPP: 14113cf05076SVille Syrjälä panel->vbt.edp.bpp = 18; 1412df0566a6SJani Nikula break; 1413df0566a6SJani Nikula case EDP_24BPP: 14143cf05076SVille Syrjälä panel->vbt.edp.bpp = 24; 1415df0566a6SJani Nikula break; 1416df0566a6SJani Nikula case EDP_30BPP: 14173cf05076SVille Syrjälä panel->vbt.edp.bpp = 30; 1418df0566a6SJani Nikula break; 1419df0566a6SJani Nikula } 1420df0566a6SJani Nikula 1421df0566a6SJani Nikula /* Get the eDP sequencing and link info */ 1422df0566a6SJani Nikula edp_pps = &edp->power_seqs[panel_type]; 1423df0566a6SJani Nikula edp_link_params = &edp->fast_link_params[panel_type]; 1424df0566a6SJani Nikula 14253cf05076SVille Syrjälä panel->vbt.edp.pps = *edp_pps; 1426df0566a6SJani Nikula 1427a434689cSJani Nikula if (i915->display.vbt.version >= 224) { 1428f06d1d66SVille Syrjälä panel->vbt.edp.rate = 1429f06d1d66SVille Syrjälä edp->edp_fast_link_training_rate[panel_type] * 20; 1430f06d1d66SVille Syrjälä } else { 1431df0566a6SJani Nikula switch (edp_link_params->rate) { 1432df0566a6SJani Nikula case EDP_RATE_1_62: 1433f06d1d66SVille Syrjälä panel->vbt.edp.rate = 162000; 1434df0566a6SJani Nikula break; 1435df0566a6SJani Nikula case EDP_RATE_2_7: 1436f06d1d66SVille Syrjälä panel->vbt.edp.rate = 270000; 1437f06d1d66SVille Syrjälä break; 1438f06d1d66SVille Syrjälä case EDP_RATE_5_4: 1439f06d1d66SVille Syrjälä panel->vbt.edp.rate = 540000; 1440df0566a6SJani Nikula break; 1441df0566a6SJani Nikula default: 1442dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1443e92cbf38SWambui Karuga "VBT has unknown eDP link rate value %u\n", 1444df0566a6SJani Nikula edp_link_params->rate); 1445df0566a6SJani Nikula break; 1446df0566a6SJani Nikula } 1447f06d1d66SVille Syrjälä } 1448df0566a6SJani Nikula 1449df0566a6SJani Nikula switch (edp_link_params->lanes) { 1450df0566a6SJani Nikula case EDP_LANE_1: 14513cf05076SVille Syrjälä panel->vbt.edp.lanes = 1; 1452df0566a6SJani Nikula break; 1453df0566a6SJani Nikula case EDP_LANE_2: 14543cf05076SVille Syrjälä panel->vbt.edp.lanes = 2; 1455df0566a6SJani Nikula break; 1456df0566a6SJani Nikula case EDP_LANE_4: 14573cf05076SVille Syrjälä panel->vbt.edp.lanes = 4; 1458df0566a6SJani Nikula break; 1459df0566a6SJani Nikula default: 1460dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1461e92cbf38SWambui Karuga "VBT has unknown eDP lane count value %u\n", 1462df0566a6SJani Nikula edp_link_params->lanes); 1463df0566a6SJani Nikula break; 1464df0566a6SJani Nikula } 1465df0566a6SJani Nikula 1466df0566a6SJani Nikula switch (edp_link_params->preemphasis) { 1467df0566a6SJani Nikula case EDP_PREEMPHASIS_NONE: 14683cf05076SVille Syrjälä panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0; 1469df0566a6SJani Nikula break; 1470df0566a6SJani Nikula case EDP_PREEMPHASIS_3_5dB: 14713cf05076SVille Syrjälä panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1; 1472df0566a6SJani Nikula break; 1473df0566a6SJani Nikula case EDP_PREEMPHASIS_6dB: 14743cf05076SVille Syrjälä panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2; 1475df0566a6SJani Nikula break; 1476df0566a6SJani Nikula case EDP_PREEMPHASIS_9_5dB: 14773cf05076SVille Syrjälä panel->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3; 1478df0566a6SJani Nikula break; 1479df0566a6SJani Nikula default: 1480dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1481e92cbf38SWambui Karuga "VBT has unknown eDP pre-emphasis value %u\n", 1482df0566a6SJani Nikula edp_link_params->preemphasis); 1483df0566a6SJani Nikula break; 1484df0566a6SJani Nikula } 1485df0566a6SJani Nikula 1486df0566a6SJani Nikula switch (edp_link_params->vswing) { 1487df0566a6SJani Nikula case EDP_VSWING_0_4V: 14883cf05076SVille Syrjälä panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0; 1489df0566a6SJani Nikula break; 1490df0566a6SJani Nikula case EDP_VSWING_0_6V: 14913cf05076SVille Syrjälä panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1; 1492df0566a6SJani Nikula break; 1493df0566a6SJani Nikula case EDP_VSWING_0_8V: 14943cf05076SVille Syrjälä panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2; 1495df0566a6SJani Nikula break; 1496df0566a6SJani Nikula case EDP_VSWING_1_2V: 14973cf05076SVille Syrjälä panel->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3; 1498df0566a6SJani Nikula break; 1499df0566a6SJani Nikula default: 1500dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1501e92cbf38SWambui Karuga "VBT has unknown eDP voltage swing value %u\n", 1502df0566a6SJani Nikula edp_link_params->vswing); 1503df0566a6SJani Nikula break; 1504df0566a6SJani Nikula } 1505df0566a6SJani Nikula 1506a434689cSJani Nikula if (i915->display.vbt.version >= 173) { 1507df0566a6SJani Nikula u8 vswing; 1508df0566a6SJani Nikula 1509df0566a6SJani Nikula /* Don't read from VBT if module parameter has valid value*/ 1510dbd440d8SJani Nikula if (i915->params.edp_vswing) { 15113cf05076SVille Syrjälä panel->vbt.edp.low_vswing = 1512dbd440d8SJani Nikula i915->params.edp_vswing == 1; 1513df0566a6SJani Nikula } else { 1514df0566a6SJani Nikula vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF; 15153cf05076SVille Syrjälä panel->vbt.edp.low_vswing = vswing == 0; 1516df0566a6SJani Nikula } 1517df0566a6SJani Nikula } 1518b395c29aSVille Syrjälä 15193cf05076SVille Syrjälä panel->vbt.edp.drrs_msa_timing_delay = 1520a50cc495SVille Syrjälä panel_bits(edp->sdrrs_msa_timing_delay, panel_type, 2); 152124b8b74eSVille Syrjälä 1522a434689cSJani Nikula if (i915->display.vbt.version >= 244) 152324b8b74eSVille Syrjälä panel->vbt.edp.max_link_rate = 152424b8b74eSVille Syrjälä edp->edp_max_port_link_rate[panel_type] * 20; 1525df0566a6SJani Nikula } 1526df0566a6SJani Nikula 1527df0566a6SJani Nikula static void 15283cf05076SVille Syrjälä parse_psr(struct drm_i915_private *i915, 15293cf05076SVille Syrjälä struct intel_panel *panel) 1530df0566a6SJani Nikula { 1531df0566a6SJani Nikula const struct bdb_psr *psr; 1532df0566a6SJani Nikula const struct psr_table *psr_table; 15333cf05076SVille Syrjälä int panel_type = panel->vbt.panel_type; 1534df0566a6SJani Nikula 15350a93eeb5SMaarten Lankhorst psr = bdb_find_section(i915, BDB_PSR); 1536df0566a6SJani Nikula if (!psr) { 1537dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, "No PSR BDB found.\n"); 1538df0566a6SJani Nikula return; 1539df0566a6SJani Nikula } 1540df0566a6SJani Nikula 1541df0566a6SJani Nikula psr_table = &psr->psr_table[panel_type]; 1542df0566a6SJani Nikula 15433cf05076SVille Syrjälä panel->vbt.psr.full_link = psr_table->full_link; 15443cf05076SVille Syrjälä panel->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup; 1545df0566a6SJani Nikula 1546df0566a6SJani Nikula /* Allowed VBT values goes from 0 to 15 */ 15473cf05076SVille Syrjälä panel->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 : 1548df0566a6SJani Nikula psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames; 1549df0566a6SJani Nikula 1550df0566a6SJani Nikula /* 1551df0566a6SJani Nikula * New psr options 0=500us, 1=100us, 2=2500us, 3=0us 1552df0566a6SJani Nikula * Old decimal value is wake up time in multiples of 100 us. 1553df0566a6SJani Nikula */ 1554a434689cSJani Nikula if (i915->display.vbt.version >= 205 && 15552446e1d6SMatt Roper (DISPLAY_VER(i915) >= 9 && !IS_BROXTON(i915))) { 1556df0566a6SJani Nikula switch (psr_table->tp1_wakeup_time) { 1557df0566a6SJani Nikula case 0: 15583cf05076SVille Syrjälä panel->vbt.psr.tp1_wakeup_time_us = 500; 1559df0566a6SJani Nikula break; 1560df0566a6SJani Nikula case 1: 15613cf05076SVille Syrjälä panel->vbt.psr.tp1_wakeup_time_us = 100; 1562df0566a6SJani Nikula break; 1563df0566a6SJani Nikula case 3: 15643cf05076SVille Syrjälä panel->vbt.psr.tp1_wakeup_time_us = 0; 1565df0566a6SJani Nikula break; 1566df0566a6SJani Nikula default: 1567dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1568e92cbf38SWambui Karuga "VBT tp1 wakeup time value %d is outside range[0-3], defaulting to max value 2500us\n", 1569df0566a6SJani Nikula psr_table->tp1_wakeup_time); 1570df561f66SGustavo A. R. Silva fallthrough; 1571df0566a6SJani Nikula case 2: 15723cf05076SVille Syrjälä panel->vbt.psr.tp1_wakeup_time_us = 2500; 1573df0566a6SJani Nikula break; 1574df0566a6SJani Nikula } 1575df0566a6SJani Nikula 1576df0566a6SJani Nikula switch (psr_table->tp2_tp3_wakeup_time) { 1577df0566a6SJani Nikula case 0: 15783cf05076SVille Syrjälä panel->vbt.psr.tp2_tp3_wakeup_time_us = 500; 1579df0566a6SJani Nikula break; 1580df0566a6SJani Nikula case 1: 15813cf05076SVille Syrjälä panel->vbt.psr.tp2_tp3_wakeup_time_us = 100; 1582df0566a6SJani Nikula break; 1583df0566a6SJani Nikula case 3: 15843cf05076SVille Syrjälä panel->vbt.psr.tp2_tp3_wakeup_time_us = 0; 1585df0566a6SJani Nikula break; 1586df0566a6SJani Nikula default: 1587dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1588e92cbf38SWambui Karuga "VBT tp2_tp3 wakeup time value %d is outside range[0-3], defaulting to max value 2500us\n", 1589df0566a6SJani Nikula psr_table->tp2_tp3_wakeup_time); 1590df561f66SGustavo A. R. Silva fallthrough; 1591df0566a6SJani Nikula case 2: 15923cf05076SVille Syrjälä panel->vbt.psr.tp2_tp3_wakeup_time_us = 2500; 1593df0566a6SJani Nikula break; 1594df0566a6SJani Nikula } 1595df0566a6SJani Nikula } else { 15963cf05076SVille Syrjälä panel->vbt.psr.tp1_wakeup_time_us = psr_table->tp1_wakeup_time * 100; 15973cf05076SVille Syrjälä panel->vbt.psr.tp2_tp3_wakeup_time_us = psr_table->tp2_tp3_wakeup_time * 100; 1598df0566a6SJani Nikula } 1599df0566a6SJani Nikula 1600a434689cSJani Nikula if (i915->display.vbt.version >= 226) { 1601b5ea9c93SDhinakaran Pandiyan u32 wakeup_time = psr->psr2_tp2_tp3_wakeup_time; 1602df0566a6SJani Nikula 1603a50cc495SVille Syrjälä wakeup_time = panel_bits(wakeup_time, panel_type, 2); 1604df0566a6SJani Nikula switch (wakeup_time) { 1605df0566a6SJani Nikula case 0: 1606df0566a6SJani Nikula wakeup_time = 500; 1607df0566a6SJani Nikula break; 1608df0566a6SJani Nikula case 1: 1609df0566a6SJani Nikula wakeup_time = 100; 1610df0566a6SJani Nikula break; 1611df0566a6SJani Nikula case 3: 1612df0566a6SJani Nikula wakeup_time = 50; 1613df0566a6SJani Nikula break; 1614df0566a6SJani Nikula default: 1615df0566a6SJani Nikula case 2: 1616df0566a6SJani Nikula wakeup_time = 2500; 1617df0566a6SJani Nikula break; 1618df0566a6SJani Nikula } 16193cf05076SVille Syrjälä panel->vbt.psr.psr2_tp2_tp3_wakeup_time_us = wakeup_time; 1620df0566a6SJani Nikula } else { 1621df0566a6SJani Nikula /* Reusing PSR1 wakeup time for PSR2 in older VBTs */ 16223cf05076SVille Syrjälä panel->vbt.psr.psr2_tp2_tp3_wakeup_time_us = panel->vbt.psr.tp2_tp3_wakeup_time_us; 1623df0566a6SJani Nikula } 1624df0566a6SJani Nikula } 1625df0566a6SJani Nikula 1626dbd440d8SJani Nikula static void parse_dsi_backlight_ports(struct drm_i915_private *i915, 16273cf05076SVille Syrjälä struct intel_panel *panel, 16283cf05076SVille Syrjälä enum port port) 1629df0566a6SJani Nikula { 1630ab55165dSJani Nikula enum port port_bc = DISPLAY_VER(i915) >= 11 ? PORT_B : PORT_C; 1631ab55165dSJani Nikula 1632a434689cSJani Nikula if (!panel->vbt.dsi.config->dual_link || i915->display.vbt.version < 197) { 16333cf05076SVille Syrjälä panel->vbt.dsi.bl_ports = BIT(port); 16343cf05076SVille Syrjälä if (panel->vbt.dsi.config->cabc_supported) 16353cf05076SVille Syrjälä panel->vbt.dsi.cabc_ports = BIT(port); 1636df0566a6SJani Nikula 1637df0566a6SJani Nikula return; 1638df0566a6SJani Nikula } 1639df0566a6SJani Nikula 16403cf05076SVille Syrjälä switch (panel->vbt.dsi.config->dl_dcs_backlight_ports) { 1641df0566a6SJani Nikula case DL_DCS_PORT_A: 16423cf05076SVille Syrjälä panel->vbt.dsi.bl_ports = BIT(PORT_A); 1643df0566a6SJani Nikula break; 1644df0566a6SJani Nikula case DL_DCS_PORT_C: 1645ab55165dSJani Nikula panel->vbt.dsi.bl_ports = BIT(port_bc); 1646df0566a6SJani Nikula break; 1647df0566a6SJani Nikula default: 1648df0566a6SJani Nikula case DL_DCS_PORT_A_AND_C: 1649ab55165dSJani Nikula panel->vbt.dsi.bl_ports = BIT(PORT_A) | BIT(port_bc); 1650df0566a6SJani Nikula break; 1651df0566a6SJani Nikula } 1652df0566a6SJani Nikula 16533cf05076SVille Syrjälä if (!panel->vbt.dsi.config->cabc_supported) 1654df0566a6SJani Nikula return; 1655df0566a6SJani Nikula 16563cf05076SVille Syrjälä switch (panel->vbt.dsi.config->dl_dcs_cabc_ports) { 1657df0566a6SJani Nikula case DL_DCS_PORT_A: 16583cf05076SVille Syrjälä panel->vbt.dsi.cabc_ports = BIT(PORT_A); 1659df0566a6SJani Nikula break; 1660df0566a6SJani Nikula case DL_DCS_PORT_C: 1661ab55165dSJani Nikula panel->vbt.dsi.cabc_ports = BIT(port_bc); 1662df0566a6SJani Nikula break; 1663df0566a6SJani Nikula default: 1664df0566a6SJani Nikula case DL_DCS_PORT_A_AND_C: 16653cf05076SVille Syrjälä panel->vbt.dsi.cabc_ports = 1666ab55165dSJani Nikula BIT(PORT_A) | BIT(port_bc); 1667df0566a6SJani Nikula break; 1668df0566a6SJani Nikula } 1669df0566a6SJani Nikula } 1670df0566a6SJani Nikula 1671df0566a6SJani Nikula static void 16723cf05076SVille Syrjälä parse_mipi_config(struct drm_i915_private *i915, 16733cf05076SVille Syrjälä struct intel_panel *panel) 1674df0566a6SJani Nikula { 1675df0566a6SJani Nikula const struct bdb_mipi_config *start; 1676df0566a6SJani Nikula const struct mipi_config *config; 1677df0566a6SJani Nikula const struct mipi_pps_data *pps; 16783cf05076SVille Syrjälä int panel_type = panel->vbt.panel_type; 1679df0566a6SJani Nikula enum port port; 1680df0566a6SJani Nikula 1681df0566a6SJani Nikula /* parse MIPI blocks only if LFP type is MIPI */ 1682dbd440d8SJani Nikula if (!intel_bios_is_dsi_present(i915, &port)) 1683df0566a6SJani Nikula return; 1684df0566a6SJani Nikula 1685df0566a6SJani Nikula /* Initialize this to undefined indicating no generic MIPI support */ 16863cf05076SVille Syrjälä panel->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID; 1687df0566a6SJani Nikula 1688df0566a6SJani Nikula /* Block #40 is already parsed and panel_fixed_mode is 1689dbd440d8SJani Nikula * stored in i915->lfp_lvds_vbt_mode 1690df0566a6SJani Nikula * resuse this when needed 1691df0566a6SJani Nikula */ 1692df0566a6SJani Nikula 1693df0566a6SJani Nikula /* Parse #52 for panel index used from panel_type already 1694df0566a6SJani Nikula * parsed 1695df0566a6SJani Nikula */ 16960a93eeb5SMaarten Lankhorst start = bdb_find_section(i915, BDB_MIPI_CONFIG); 1697df0566a6SJani Nikula if (!start) { 1698dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, "No MIPI config BDB found"); 1699df0566a6SJani Nikula return; 1700df0566a6SJani Nikula } 1701df0566a6SJani Nikula 1702dbd440d8SJani Nikula drm_dbg(&i915->drm, "Found MIPI Config block, panel index = %d\n", 1703df0566a6SJani Nikula panel_type); 1704df0566a6SJani Nikula 1705df0566a6SJani Nikula /* 1706df0566a6SJani Nikula * get hold of the correct configuration block and pps data as per 1707df0566a6SJani Nikula * the panel_type as index 1708df0566a6SJani Nikula */ 1709df0566a6SJani Nikula config = &start->config[panel_type]; 1710df0566a6SJani Nikula pps = &start->pps[panel_type]; 1711df0566a6SJani Nikula 1712df0566a6SJani Nikula /* store as of now full data. Trim when we realise all is not needed */ 17133cf05076SVille Syrjälä panel->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL); 17143cf05076SVille Syrjälä if (!panel->vbt.dsi.config) 1715df0566a6SJani Nikula return; 1716df0566a6SJani Nikula 17173cf05076SVille Syrjälä panel->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL); 17183cf05076SVille Syrjälä if (!panel->vbt.dsi.pps) { 17193cf05076SVille Syrjälä kfree(panel->vbt.dsi.config); 1720df0566a6SJani Nikula return; 1721df0566a6SJani Nikula } 1722df0566a6SJani Nikula 17233cf05076SVille Syrjälä parse_dsi_backlight_ports(i915, panel, port); 1724df0566a6SJani Nikula 1725df0566a6SJani Nikula /* FIXME is the 90 vs. 270 correct? */ 1726df0566a6SJani Nikula switch (config->rotation) { 1727df0566a6SJani Nikula case ENABLE_ROTATION_0: 1728df0566a6SJani Nikula /* 1729df0566a6SJani Nikula * Most (all?) VBTs claim 0 degrees despite having 1730df0566a6SJani Nikula * an upside down panel, thus we do not trust this. 1731df0566a6SJani Nikula */ 17323cf05076SVille Syrjälä panel->vbt.dsi.orientation = 1733df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_UNKNOWN; 1734df0566a6SJani Nikula break; 1735df0566a6SJani Nikula case ENABLE_ROTATION_90: 17363cf05076SVille Syrjälä panel->vbt.dsi.orientation = 1737df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_RIGHT_UP; 1738df0566a6SJani Nikula break; 1739df0566a6SJani Nikula case ENABLE_ROTATION_180: 17403cf05076SVille Syrjälä panel->vbt.dsi.orientation = 1741df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP; 1742df0566a6SJani Nikula break; 1743df0566a6SJani Nikula case ENABLE_ROTATION_270: 17443cf05076SVille Syrjälä panel->vbt.dsi.orientation = 1745df0566a6SJani Nikula DRM_MODE_PANEL_ORIENTATION_LEFT_UP; 1746df0566a6SJani Nikula break; 1747df0566a6SJani Nikula } 1748df0566a6SJani Nikula 1749df0566a6SJani Nikula /* We have mandatory mipi config blocks. Initialize as generic panel */ 17503cf05076SVille Syrjälä panel->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID; 1751df0566a6SJani Nikula } 1752df0566a6SJani Nikula 1753df0566a6SJani Nikula /* Find the sequence block and size for the given panel. */ 1754df0566a6SJani Nikula static const u8 * 1755df0566a6SJani Nikula find_panel_sequence_block(const struct bdb_mipi_sequence *sequence, 1756df0566a6SJani Nikula u16 panel_id, u32 *seq_size) 1757df0566a6SJani Nikula { 1758df0566a6SJani Nikula u32 total = get_blocksize(sequence); 1759df0566a6SJani Nikula const u8 *data = &sequence->data[0]; 1760df0566a6SJani Nikula u8 current_id; 1761df0566a6SJani Nikula u32 current_size; 1762df0566a6SJani Nikula int header_size = sequence->version >= 3 ? 5 : 3; 1763df0566a6SJani Nikula int index = 0; 1764df0566a6SJani Nikula int i; 1765df0566a6SJani Nikula 1766df0566a6SJani Nikula /* skip new block size */ 1767df0566a6SJani Nikula if (sequence->version >= 3) 1768df0566a6SJani Nikula data += 4; 1769df0566a6SJani Nikula 1770df0566a6SJani Nikula for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index < total; i++) { 1771df0566a6SJani Nikula if (index + header_size > total) { 1772df0566a6SJani Nikula DRM_ERROR("Invalid sequence block (header)\n"); 1773df0566a6SJani Nikula return NULL; 1774df0566a6SJani Nikula } 1775df0566a6SJani Nikula 1776df0566a6SJani Nikula current_id = *(data + index); 1777df0566a6SJani Nikula if (sequence->version >= 3) 1778df0566a6SJani Nikula current_size = *((const u32 *)(data + index + 1)); 1779df0566a6SJani Nikula else 1780df0566a6SJani Nikula current_size = *((const u16 *)(data + index + 1)); 1781df0566a6SJani Nikula 1782df0566a6SJani Nikula index += header_size; 1783df0566a6SJani Nikula 1784df0566a6SJani Nikula if (index + current_size > total) { 1785df0566a6SJani Nikula DRM_ERROR("Invalid sequence block\n"); 1786df0566a6SJani Nikula return NULL; 1787df0566a6SJani Nikula } 1788df0566a6SJani Nikula 1789df0566a6SJani Nikula if (current_id == panel_id) { 1790df0566a6SJani Nikula *seq_size = current_size; 1791df0566a6SJani Nikula return data + index; 1792df0566a6SJani Nikula } 1793df0566a6SJani Nikula 1794df0566a6SJani Nikula index += current_size; 1795df0566a6SJani Nikula } 1796df0566a6SJani Nikula 1797df0566a6SJani Nikula DRM_ERROR("Sequence block detected but no valid configuration\n"); 1798df0566a6SJani Nikula 1799df0566a6SJani Nikula return NULL; 1800df0566a6SJani Nikula } 1801df0566a6SJani Nikula 1802df0566a6SJani Nikula static int goto_next_sequence(const u8 *data, int index, int total) 1803df0566a6SJani Nikula { 1804df0566a6SJani Nikula u16 len; 1805df0566a6SJani Nikula 1806df0566a6SJani Nikula /* Skip Sequence Byte. */ 1807df0566a6SJani Nikula for (index = index + 1; index < total; index += len) { 1808df0566a6SJani Nikula u8 operation_byte = *(data + index); 1809df0566a6SJani Nikula index++; 1810df0566a6SJani Nikula 1811df0566a6SJani Nikula switch (operation_byte) { 1812df0566a6SJani Nikula case MIPI_SEQ_ELEM_END: 1813df0566a6SJani Nikula return index; 1814df0566a6SJani Nikula case MIPI_SEQ_ELEM_SEND_PKT: 1815df0566a6SJani Nikula if (index + 4 > total) 1816df0566a6SJani Nikula return 0; 1817df0566a6SJani Nikula 1818df0566a6SJani Nikula len = *((const u16 *)(data + index + 2)) + 4; 1819df0566a6SJani Nikula break; 1820df0566a6SJani Nikula case MIPI_SEQ_ELEM_DELAY: 1821df0566a6SJani Nikula len = 4; 1822df0566a6SJani Nikula break; 1823df0566a6SJani Nikula case MIPI_SEQ_ELEM_GPIO: 1824df0566a6SJani Nikula len = 2; 1825df0566a6SJani Nikula break; 1826df0566a6SJani Nikula case MIPI_SEQ_ELEM_I2C: 1827df0566a6SJani Nikula if (index + 7 > total) 1828df0566a6SJani Nikula return 0; 1829df0566a6SJani Nikula len = *(data + index + 6) + 7; 1830df0566a6SJani Nikula break; 1831df0566a6SJani Nikula default: 1832df0566a6SJani Nikula DRM_ERROR("Unknown operation byte\n"); 1833df0566a6SJani Nikula return 0; 1834df0566a6SJani Nikula } 1835df0566a6SJani Nikula } 1836df0566a6SJani Nikula 1837df0566a6SJani Nikula return 0; 1838df0566a6SJani Nikula } 1839df0566a6SJani Nikula 1840df0566a6SJani Nikula static int goto_next_sequence_v3(const u8 *data, int index, int total) 1841df0566a6SJani Nikula { 1842df0566a6SJani Nikula int seq_end; 1843df0566a6SJani Nikula u16 len; 1844df0566a6SJani Nikula u32 size_of_sequence; 1845df0566a6SJani Nikula 1846df0566a6SJani Nikula /* 1847df0566a6SJani Nikula * Could skip sequence based on Size of Sequence alone, but also do some 1848df0566a6SJani Nikula * checking on the structure. 1849df0566a6SJani Nikula */ 1850df0566a6SJani Nikula if (total < 5) { 1851df0566a6SJani Nikula DRM_ERROR("Too small sequence size\n"); 1852df0566a6SJani Nikula return 0; 1853df0566a6SJani Nikula } 1854df0566a6SJani Nikula 1855df0566a6SJani Nikula /* Skip Sequence Byte. */ 1856df0566a6SJani Nikula index++; 1857df0566a6SJani Nikula 1858df0566a6SJani Nikula /* 1859df0566a6SJani Nikula * Size of Sequence. Excludes the Sequence Byte and the size itself, 1860df0566a6SJani Nikula * includes MIPI_SEQ_ELEM_END byte, excludes the final MIPI_SEQ_END 1861df0566a6SJani Nikula * byte. 1862df0566a6SJani Nikula */ 1863df0566a6SJani Nikula size_of_sequence = *((const u32 *)(data + index)); 1864df0566a6SJani Nikula index += 4; 1865df0566a6SJani Nikula 1866df0566a6SJani Nikula seq_end = index + size_of_sequence; 1867df0566a6SJani Nikula if (seq_end > total) { 1868df0566a6SJani Nikula DRM_ERROR("Invalid sequence size\n"); 1869df0566a6SJani Nikula return 0; 1870df0566a6SJani Nikula } 1871df0566a6SJani Nikula 1872df0566a6SJani Nikula for (; index < total; index += len) { 1873df0566a6SJani Nikula u8 operation_byte = *(data + index); 1874df0566a6SJani Nikula index++; 1875df0566a6SJani Nikula 1876df0566a6SJani Nikula if (operation_byte == MIPI_SEQ_ELEM_END) { 1877df0566a6SJani Nikula if (index != seq_end) { 1878df0566a6SJani Nikula DRM_ERROR("Invalid element structure\n"); 1879df0566a6SJani Nikula return 0; 1880df0566a6SJani Nikula } 1881df0566a6SJani Nikula return index; 1882df0566a6SJani Nikula } 1883df0566a6SJani Nikula 1884df0566a6SJani Nikula len = *(data + index); 1885df0566a6SJani Nikula index++; 1886df0566a6SJani Nikula 1887df0566a6SJani Nikula /* 1888df0566a6SJani Nikula * FIXME: Would be nice to check elements like for v1/v2 in 1889df0566a6SJani Nikula * goto_next_sequence() above. 1890df0566a6SJani Nikula */ 1891df0566a6SJani Nikula switch (operation_byte) { 1892df0566a6SJani Nikula case MIPI_SEQ_ELEM_SEND_PKT: 1893df0566a6SJani Nikula case MIPI_SEQ_ELEM_DELAY: 1894df0566a6SJani Nikula case MIPI_SEQ_ELEM_GPIO: 1895df0566a6SJani Nikula case MIPI_SEQ_ELEM_I2C: 1896df0566a6SJani Nikula case MIPI_SEQ_ELEM_SPI: 1897df0566a6SJani Nikula case MIPI_SEQ_ELEM_PMIC: 1898df0566a6SJani Nikula break; 1899df0566a6SJani Nikula default: 1900df0566a6SJani Nikula DRM_ERROR("Unknown operation byte %u\n", 1901df0566a6SJani Nikula operation_byte); 1902df0566a6SJani Nikula break; 1903df0566a6SJani Nikula } 1904df0566a6SJani Nikula } 1905df0566a6SJani Nikula 1906df0566a6SJani Nikula return 0; 1907df0566a6SJani Nikula } 1908df0566a6SJani Nikula 1909df0566a6SJani Nikula /* 1910df0566a6SJani Nikula * Get len of pre-fixed deassert fragment from a v1 init OTP sequence, 1911df0566a6SJani Nikula * skip all delay + gpio operands and stop at the first DSI packet op. 1912df0566a6SJani Nikula */ 19133cf05076SVille Syrjälä static int get_init_otp_deassert_fragment_len(struct drm_i915_private *i915, 19143cf05076SVille Syrjälä struct intel_panel *panel) 1915df0566a6SJani Nikula { 19163cf05076SVille Syrjälä const u8 *data = panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP]; 1917df0566a6SJani Nikula int index, len; 1918df0566a6SJani Nikula 1919dbd440d8SJani Nikula if (drm_WARN_ON(&i915->drm, 19203cf05076SVille Syrjälä !data || panel->vbt.dsi.seq_version != 1)) 1921df0566a6SJani Nikula return 0; 1922df0566a6SJani Nikula 1923df0566a6SJani Nikula /* index = 1 to skip sequence byte */ 1924df0566a6SJani Nikula for (index = 1; data[index] != MIPI_SEQ_ELEM_END; index += len) { 1925df0566a6SJani Nikula switch (data[index]) { 1926df0566a6SJani Nikula case MIPI_SEQ_ELEM_SEND_PKT: 1927df0566a6SJani Nikula return index == 1 ? 0 : index; 1928df0566a6SJani Nikula case MIPI_SEQ_ELEM_DELAY: 1929df0566a6SJani Nikula len = 5; /* 1 byte for operand + uint32 */ 1930df0566a6SJani Nikula break; 1931df0566a6SJani Nikula case MIPI_SEQ_ELEM_GPIO: 1932df0566a6SJani Nikula len = 3; /* 1 byte for op, 1 for gpio_nr, 1 for value */ 1933df0566a6SJani Nikula break; 1934df0566a6SJani Nikula default: 1935df0566a6SJani Nikula return 0; 1936df0566a6SJani Nikula } 1937df0566a6SJani Nikula } 1938df0566a6SJani Nikula 1939df0566a6SJani Nikula return 0; 1940df0566a6SJani Nikula } 1941df0566a6SJani Nikula 1942df0566a6SJani Nikula /* 1943df0566a6SJani Nikula * Some v1 VBT MIPI sequences do the deassert in the init OTP sequence. 1944df0566a6SJani Nikula * The deassert must be done before calling intel_dsi_device_ready, so for 1945df0566a6SJani Nikula * these devices we split the init OTP sequence into a deassert sequence and 1946df0566a6SJani Nikula * the actual init OTP part. 1947df0566a6SJani Nikula */ 19483cf05076SVille Syrjälä static void fixup_mipi_sequences(struct drm_i915_private *i915, 19493cf05076SVille Syrjälä struct intel_panel *panel) 1950df0566a6SJani Nikula { 1951df0566a6SJani Nikula u8 *init_otp; 1952df0566a6SJani Nikula int len; 1953df0566a6SJani Nikula 1954df0566a6SJani Nikula /* Limit this to VLV for now. */ 1955dbd440d8SJani Nikula if (!IS_VALLEYVIEW(i915)) 1956df0566a6SJani Nikula return; 1957df0566a6SJani Nikula 1958df0566a6SJani Nikula /* Limit this to v1 vid-mode sequences */ 19593cf05076SVille Syrjälä if (panel->vbt.dsi.config->is_cmd_mode || 19603cf05076SVille Syrjälä panel->vbt.dsi.seq_version != 1) 1961df0566a6SJani Nikula return; 1962df0566a6SJani Nikula 1963df0566a6SJani Nikula /* Only do this if there are otp and assert seqs and no deassert seq */ 19643cf05076SVille Syrjälä if (!panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] || 19653cf05076SVille Syrjälä !panel->vbt.dsi.sequence[MIPI_SEQ_ASSERT_RESET] || 19663cf05076SVille Syrjälä panel->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET]) 1967df0566a6SJani Nikula return; 1968df0566a6SJani Nikula 1969df0566a6SJani Nikula /* The deassert-sequence ends at the first DSI packet */ 19703cf05076SVille Syrjälä len = get_init_otp_deassert_fragment_len(i915, panel); 1971df0566a6SJani Nikula if (!len) 1972df0566a6SJani Nikula return; 1973df0566a6SJani Nikula 1974dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 1975e92cbf38SWambui Karuga "Using init OTP fragment to deassert reset\n"); 1976df0566a6SJani Nikula 1977df0566a6SJani Nikula /* Copy the fragment, update seq byte and terminate it */ 19783cf05076SVille Syrjälä init_otp = (u8 *)panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP]; 19793cf05076SVille Syrjälä panel->vbt.dsi.deassert_seq = kmemdup(init_otp, len + 1, GFP_KERNEL); 19803cf05076SVille Syrjälä if (!panel->vbt.dsi.deassert_seq) 1981df0566a6SJani Nikula return; 19823cf05076SVille Syrjälä panel->vbt.dsi.deassert_seq[0] = MIPI_SEQ_DEASSERT_RESET; 19833cf05076SVille Syrjälä panel->vbt.dsi.deassert_seq[len] = MIPI_SEQ_ELEM_END; 1984df0566a6SJani Nikula /* Use the copy for deassert */ 19853cf05076SVille Syrjälä panel->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET] = 19863cf05076SVille Syrjälä panel->vbt.dsi.deassert_seq; 1987df0566a6SJani Nikula /* Replace the last byte of the fragment with init OTP seq byte */ 1988df0566a6SJani Nikula init_otp[len - 1] = MIPI_SEQ_INIT_OTP; 1989df0566a6SJani Nikula /* And make MIPI_MIPI_SEQ_INIT_OTP point to it */ 19903cf05076SVille Syrjälä panel->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] = init_otp + len - 1; 1991df0566a6SJani Nikula } 1992df0566a6SJani Nikula 1993df0566a6SJani Nikula static void 19943cf05076SVille Syrjälä parse_mipi_sequence(struct drm_i915_private *i915, 19953cf05076SVille Syrjälä struct intel_panel *panel) 1996df0566a6SJani Nikula { 19973cf05076SVille Syrjälä int panel_type = panel->vbt.panel_type; 1998df0566a6SJani Nikula const struct bdb_mipi_sequence *sequence; 1999df0566a6SJani Nikula const u8 *seq_data; 2000df0566a6SJani Nikula u32 seq_size; 2001df0566a6SJani Nikula u8 *data; 2002df0566a6SJani Nikula int index = 0; 2003df0566a6SJani Nikula 2004df0566a6SJani Nikula /* Only our generic panel driver uses the sequence block. */ 20053cf05076SVille Syrjälä if (panel->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID) 2006df0566a6SJani Nikula return; 2007df0566a6SJani Nikula 20080a93eeb5SMaarten Lankhorst sequence = bdb_find_section(i915, BDB_MIPI_SEQUENCE); 2009df0566a6SJani Nikula if (!sequence) { 2010dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 2011e92cbf38SWambui Karuga "No MIPI Sequence found, parsing complete\n"); 2012df0566a6SJani Nikula return; 2013df0566a6SJani Nikula } 2014df0566a6SJani Nikula 2015df0566a6SJani Nikula /* Fail gracefully for forward incompatible sequence block. */ 2016df0566a6SJani Nikula if (sequence->version >= 4) { 2017dbd440d8SJani Nikula drm_err(&i915->drm, 2018e92cbf38SWambui Karuga "Unable to parse MIPI Sequence Block v%u\n", 2019df0566a6SJani Nikula sequence->version); 2020df0566a6SJani Nikula return; 2021df0566a6SJani Nikula } 2022df0566a6SJani Nikula 2023dbd440d8SJani Nikula drm_dbg(&i915->drm, "Found MIPI sequence block v%u\n", 2024e92cbf38SWambui Karuga sequence->version); 2025df0566a6SJani Nikula 2026df0566a6SJani Nikula seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size); 2027df0566a6SJani Nikula if (!seq_data) 2028df0566a6SJani Nikula return; 2029df0566a6SJani Nikula 2030df0566a6SJani Nikula data = kmemdup(seq_data, seq_size, GFP_KERNEL); 2031df0566a6SJani Nikula if (!data) 2032df0566a6SJani Nikula return; 2033df0566a6SJani Nikula 2034df0566a6SJani Nikula /* Parse the sequences, store pointers to each sequence. */ 2035df0566a6SJani Nikula for (;;) { 2036df0566a6SJani Nikula u8 seq_id = *(data + index); 2037df0566a6SJani Nikula if (seq_id == MIPI_SEQ_END) 2038df0566a6SJani Nikula break; 2039df0566a6SJani Nikula 2040df0566a6SJani Nikula if (seq_id >= MIPI_SEQ_MAX) { 2041dbd440d8SJani Nikula drm_err(&i915->drm, "Unknown sequence %u\n", 2042e92cbf38SWambui Karuga seq_id); 2043df0566a6SJani Nikula goto err; 2044df0566a6SJani Nikula } 2045df0566a6SJani Nikula 2046df0566a6SJani Nikula /* Log about presence of sequences we won't run. */ 2047df0566a6SJani Nikula if (seq_id == MIPI_SEQ_TEAR_ON || seq_id == MIPI_SEQ_TEAR_OFF) 2048dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 2049e92cbf38SWambui Karuga "Unsupported sequence %u\n", seq_id); 2050df0566a6SJani Nikula 20513cf05076SVille Syrjälä panel->vbt.dsi.sequence[seq_id] = data + index; 2052df0566a6SJani Nikula 2053df0566a6SJani Nikula if (sequence->version >= 3) 2054df0566a6SJani Nikula index = goto_next_sequence_v3(data, index, seq_size); 2055df0566a6SJani Nikula else 2056df0566a6SJani Nikula index = goto_next_sequence(data, index, seq_size); 2057df0566a6SJani Nikula if (!index) { 2058dbd440d8SJani Nikula drm_err(&i915->drm, "Invalid sequence %u\n", 2059e92cbf38SWambui Karuga seq_id); 2060df0566a6SJani Nikula goto err; 2061df0566a6SJani Nikula } 2062df0566a6SJani Nikula } 2063df0566a6SJani Nikula 20643cf05076SVille Syrjälä panel->vbt.dsi.data = data; 20653cf05076SVille Syrjälä panel->vbt.dsi.size = seq_size; 20663cf05076SVille Syrjälä panel->vbt.dsi.seq_version = sequence->version; 2067df0566a6SJani Nikula 20683cf05076SVille Syrjälä fixup_mipi_sequences(i915, panel); 2069df0566a6SJani Nikula 2070dbd440d8SJani Nikula drm_dbg(&i915->drm, "MIPI related VBT parsing complete\n"); 2071df0566a6SJani Nikula return; 2072df0566a6SJani Nikula 2073df0566a6SJani Nikula err: 2074df0566a6SJani Nikula kfree(data); 20753cf05076SVille Syrjälä memset(panel->vbt.dsi.sequence, 0, sizeof(panel->vbt.dsi.sequence)); 2076df0566a6SJani Nikula } 2077df0566a6SJani Nikula 20786e0d46e9SJani Nikula static void 2079e163cfb4SVille Syrjälä parse_compression_parameters(struct drm_i915_private *i915) 20806e0d46e9SJani Nikula { 20816e0d46e9SJani Nikula const struct bdb_compression_parameters *params; 20823162d057SJani Nikula struct intel_bios_encoder_data *devdata; 20836e0d46e9SJani Nikula u16 block_size; 20846e0d46e9SJani Nikula int index; 20856e0d46e9SJani Nikula 2086a434689cSJani Nikula if (i915->display.vbt.version < 198) 20876e0d46e9SJani Nikula return; 20886e0d46e9SJani Nikula 20890a93eeb5SMaarten Lankhorst params = bdb_find_section(i915, BDB_COMPRESSION_PARAMETERS); 20906e0d46e9SJani Nikula if (params) { 20916e0d46e9SJani Nikula /* Sanity checks */ 20926e0d46e9SJani Nikula if (params->entry_size != sizeof(params->data[0])) { 2093e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm, 2094e92cbf38SWambui Karuga "VBT: unsupported compression param entry size\n"); 20956e0d46e9SJani Nikula return; 20966e0d46e9SJani Nikula } 20976e0d46e9SJani Nikula 20986e0d46e9SJani Nikula block_size = get_blocksize(params); 20996e0d46e9SJani Nikula if (block_size < sizeof(*params)) { 2100e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm, 2101e92cbf38SWambui Karuga "VBT: expected 16 compression param entries\n"); 21026e0d46e9SJani Nikula return; 21036e0d46e9SJani Nikula } 21046e0d46e9SJani Nikula } 21056e0d46e9SJani Nikula 2106a434689cSJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) { 2107d24b3475SVille Syrjälä const struct child_device_config *child = &devdata->child; 21086e0d46e9SJani Nikula 21096e0d46e9SJani Nikula if (!child->compression_enable) 21106e0d46e9SJani Nikula continue; 21116e0d46e9SJani Nikula 21126e0d46e9SJani Nikula if (!params) { 2113e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm, 2114e92cbf38SWambui Karuga "VBT: compression params not available\n"); 21156e0d46e9SJani Nikula continue; 21166e0d46e9SJani Nikula } 21176e0d46e9SJani Nikula 21186e0d46e9SJani Nikula if (child->compression_method_cps) { 2119e92cbf38SWambui Karuga drm_dbg_kms(&i915->drm, 2120e92cbf38SWambui Karuga "VBT: CPS compression not supported\n"); 21216e0d46e9SJani Nikula continue; 21226e0d46e9SJani Nikula } 21236e0d46e9SJani Nikula 21246e0d46e9SJani Nikula index = child->compression_structure_index; 21256e0d46e9SJani Nikula 21266e0d46e9SJani Nikula devdata->dsc = kmemdup(¶ms->data[index], 21276e0d46e9SJani Nikula sizeof(*devdata->dsc), GFP_KERNEL); 21286e0d46e9SJani Nikula } 21296e0d46e9SJani Nikula } 21306e0d46e9SJani Nikula 2131df0566a6SJani Nikula static u8 translate_iboost(u8 val) 2132df0566a6SJani Nikula { 2133df0566a6SJani Nikula static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */ 2134df0566a6SJani Nikula 2135df0566a6SJani Nikula if (val >= ARRAY_SIZE(mapping)) { 2136df0566a6SJani Nikula DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val); 2137df0566a6SJani Nikula return 0; 2138df0566a6SJani Nikula } 2139df0566a6SJani Nikula return mapping[val]; 2140df0566a6SJani Nikula } 2141df0566a6SJani Nikula 21429e1dbc1aSJani Nikula static const u8 cnp_ddc_pin_map[] = { 21439e1dbc1aSJani Nikula [0] = 0, /* N/A */ 21443d7af6cfSVille Syrjälä [GMBUS_PIN_1_BXT] = DDC_BUS_DDI_B, 21453d7af6cfSVille Syrjälä [GMBUS_PIN_2_BXT] = DDC_BUS_DDI_C, 21463d7af6cfSVille Syrjälä [GMBUS_PIN_4_CNP] = DDC_BUS_DDI_D, /* sic */ 21473d7af6cfSVille Syrjälä [GMBUS_PIN_3_BXT] = DDC_BUS_DDI_F, /* sic */ 21489e1dbc1aSJani Nikula }; 21499e1dbc1aSJani Nikula 21509e1dbc1aSJani Nikula static const u8 icp_ddc_pin_map[] = { 21513d7af6cfSVille Syrjälä [GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A, 21523d7af6cfSVille Syrjälä [GMBUS_PIN_2_BXT] = ICL_DDC_BUS_DDI_B, 21533d7af6cfSVille Syrjälä [GMBUS_PIN_3_BXT] = TGL_DDC_BUS_DDI_C, 21543d7af6cfSVille Syrjälä [GMBUS_PIN_9_TC1_ICP] = ICL_DDC_BUS_PORT_1, 21553d7af6cfSVille Syrjälä [GMBUS_PIN_10_TC2_ICP] = ICL_DDC_BUS_PORT_2, 21563d7af6cfSVille Syrjälä [GMBUS_PIN_11_TC3_ICP] = ICL_DDC_BUS_PORT_3, 21573d7af6cfSVille Syrjälä [GMBUS_PIN_12_TC4_ICP] = ICL_DDC_BUS_PORT_4, 21583d7af6cfSVille Syrjälä [GMBUS_PIN_13_TC5_TGP] = TGL_DDC_BUS_PORT_5, 21593d7af6cfSVille Syrjälä [GMBUS_PIN_14_TC6_TGP] = TGL_DDC_BUS_PORT_6, 21609e1dbc1aSJani Nikula }; 21619e1dbc1aSJani Nikula 21629e1dbc1aSJani Nikula static const u8 rkl_pch_tgp_ddc_pin_map[] = { 21633d7af6cfSVille Syrjälä [GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A, 21643d7af6cfSVille Syrjälä [GMBUS_PIN_2_BXT] = ICL_DDC_BUS_DDI_B, 21653d7af6cfSVille Syrjälä [GMBUS_PIN_9_TC1_ICP] = RKL_DDC_BUS_DDI_D, 21663d7af6cfSVille Syrjälä [GMBUS_PIN_10_TC2_ICP] = RKL_DDC_BUS_DDI_E, 21679e1dbc1aSJani Nikula }; 21689e1dbc1aSJani Nikula 21699e1dbc1aSJani Nikula static const u8 adls_ddc_pin_map[] = { 21703d7af6cfSVille Syrjälä [GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A, 21713d7af6cfSVille Syrjälä [GMBUS_PIN_9_TC1_ICP] = ADLS_DDC_BUS_PORT_TC1, 21723d7af6cfSVille Syrjälä [GMBUS_PIN_10_TC2_ICP] = ADLS_DDC_BUS_PORT_TC2, 21733d7af6cfSVille Syrjälä [GMBUS_PIN_11_TC3_ICP] = ADLS_DDC_BUS_PORT_TC3, 21743d7af6cfSVille Syrjälä [GMBUS_PIN_12_TC4_ICP] = ADLS_DDC_BUS_PORT_TC4, 21759e1dbc1aSJani Nikula }; 21769e1dbc1aSJani Nikula 21779e1dbc1aSJani Nikula static const u8 gen9bc_tgp_ddc_pin_map[] = { 21783d7af6cfSVille Syrjälä [GMBUS_PIN_2_BXT] = DDC_BUS_DDI_B, 21793d7af6cfSVille Syrjälä [GMBUS_PIN_9_TC1_ICP] = DDC_BUS_DDI_C, 21803d7af6cfSVille Syrjälä [GMBUS_PIN_10_TC2_ICP] = DDC_BUS_DDI_D, 21819e1dbc1aSJani Nikula }; 21829e1dbc1aSJani Nikula 2183af10ec31STejas Upadhyay static const u8 adlp_ddc_pin_map[] = { 21843d7af6cfSVille Syrjälä [GMBUS_PIN_1_BXT] = ICL_DDC_BUS_DDI_A, 21853d7af6cfSVille Syrjälä [GMBUS_PIN_2_BXT] = ICL_DDC_BUS_DDI_B, 21863d7af6cfSVille Syrjälä [GMBUS_PIN_9_TC1_ICP] = ADLP_DDC_BUS_PORT_TC1, 21873d7af6cfSVille Syrjälä [GMBUS_PIN_10_TC2_ICP] = ADLP_DDC_BUS_PORT_TC2, 21883d7af6cfSVille Syrjälä [GMBUS_PIN_11_TC3_ICP] = ADLP_DDC_BUS_PORT_TC3, 21893d7af6cfSVille Syrjälä [GMBUS_PIN_12_TC4_ICP] = ADLP_DDC_BUS_PORT_TC4, 2190af10ec31STejas Upadhyay }; 2191af10ec31STejas Upadhyay 21929e1dbc1aSJani Nikula static u8 map_ddc_pin(struct drm_i915_private *i915, u8 vbt_pin) 21939e1dbc1aSJani Nikula { 21949e1dbc1aSJani Nikula const u8 *ddc_pin_map; 21953d7af6cfSVille Syrjälä int i, n_entries; 21969e1dbc1aSJani Nikula 2197cf867d6aSRadhakrishna Sripada if (HAS_PCH_MTP(i915) || IS_ALDERLAKE_P(i915)) { 2198af10ec31STejas Upadhyay ddc_pin_map = adlp_ddc_pin_map; 2199af10ec31STejas Upadhyay n_entries = ARRAY_SIZE(adlp_ddc_pin_map); 2200af10ec31STejas Upadhyay } else if (IS_ALDERLAKE_S(i915)) { 22019e1dbc1aSJani Nikula ddc_pin_map = adls_ddc_pin_map; 22029e1dbc1aSJani Nikula n_entries = ARRAY_SIZE(adls_ddc_pin_map); 22039e1dbc1aSJani Nikula } else if (INTEL_PCH_TYPE(i915) >= PCH_DG1) { 22049e1dbc1aSJani Nikula return vbt_pin; 22059e1dbc1aSJani Nikula } else if (IS_ROCKETLAKE(i915) && INTEL_PCH_TYPE(i915) == PCH_TGP) { 22069e1dbc1aSJani Nikula ddc_pin_map = rkl_pch_tgp_ddc_pin_map; 22079e1dbc1aSJani Nikula n_entries = ARRAY_SIZE(rkl_pch_tgp_ddc_pin_map); 22089e1dbc1aSJani Nikula } else if (HAS_PCH_TGP(i915) && DISPLAY_VER(i915) == 9) { 22099e1dbc1aSJani Nikula ddc_pin_map = gen9bc_tgp_ddc_pin_map; 22109e1dbc1aSJani Nikula n_entries = ARRAY_SIZE(gen9bc_tgp_ddc_pin_map); 22119e1dbc1aSJani Nikula } else if (INTEL_PCH_TYPE(i915) >= PCH_ICP) { 22129e1dbc1aSJani Nikula ddc_pin_map = icp_ddc_pin_map; 22139e1dbc1aSJani Nikula n_entries = ARRAY_SIZE(icp_ddc_pin_map); 22149e1dbc1aSJani Nikula } else if (HAS_PCH_CNP(i915)) { 22159e1dbc1aSJani Nikula ddc_pin_map = cnp_ddc_pin_map; 22169e1dbc1aSJani Nikula n_entries = ARRAY_SIZE(cnp_ddc_pin_map); 22179e1dbc1aSJani Nikula } else { 22189e1dbc1aSJani Nikula /* Assuming direct map */ 22199e1dbc1aSJani Nikula return vbt_pin; 22209e1dbc1aSJani Nikula } 22219e1dbc1aSJani Nikula 22223d7af6cfSVille Syrjälä for (i = 0; i < n_entries; i++) { 22233d7af6cfSVille Syrjälä if (ddc_pin_map[i] == vbt_pin) 22243d7af6cfSVille Syrjälä return i; 22253d7af6cfSVille Syrjälä } 22269e1dbc1aSJani Nikula 22279e1dbc1aSJani Nikula drm_dbg_kms(&i915->drm, 22289e1dbc1aSJani Nikula "Ignoring alternate pin: VBT claims DDC pin %d, which is not valid for this platform\n", 22299e1dbc1aSJani Nikula vbt_pin); 22309e1dbc1aSJani Nikula return 0; 22319e1dbc1aSJani Nikula } 22329e1dbc1aSJani Nikula 223332c2bc89SVille Syrjälä static u8 dvo_port_type(u8 dvo_port) 223432c2bc89SVille Syrjälä { 223532c2bc89SVille Syrjälä switch (dvo_port) { 223632c2bc89SVille Syrjälä case DVO_PORT_HDMIA: 223732c2bc89SVille Syrjälä case DVO_PORT_HDMIB: 223832c2bc89SVille Syrjälä case DVO_PORT_HDMIC: 223932c2bc89SVille Syrjälä case DVO_PORT_HDMID: 224032c2bc89SVille Syrjälä case DVO_PORT_HDMIE: 224132c2bc89SVille Syrjälä case DVO_PORT_HDMIF: 224232c2bc89SVille Syrjälä case DVO_PORT_HDMIG: 224332c2bc89SVille Syrjälä case DVO_PORT_HDMIH: 224432c2bc89SVille Syrjälä case DVO_PORT_HDMII: 224532c2bc89SVille Syrjälä return DVO_PORT_HDMIA; 224632c2bc89SVille Syrjälä case DVO_PORT_DPA: 224732c2bc89SVille Syrjälä case DVO_PORT_DPB: 224832c2bc89SVille Syrjälä case DVO_PORT_DPC: 224932c2bc89SVille Syrjälä case DVO_PORT_DPD: 225032c2bc89SVille Syrjälä case DVO_PORT_DPE: 225132c2bc89SVille Syrjälä case DVO_PORT_DPF: 225232c2bc89SVille Syrjälä case DVO_PORT_DPG: 225332c2bc89SVille Syrjälä case DVO_PORT_DPH: 225432c2bc89SVille Syrjälä case DVO_PORT_DPI: 225532c2bc89SVille Syrjälä return DVO_PORT_DPA; 225632c2bc89SVille Syrjälä case DVO_PORT_MIPIA: 225732c2bc89SVille Syrjälä case DVO_PORT_MIPIB: 225832c2bc89SVille Syrjälä case DVO_PORT_MIPIC: 225932c2bc89SVille Syrjälä case DVO_PORT_MIPID: 226032c2bc89SVille Syrjälä return DVO_PORT_MIPIA; 226132c2bc89SVille Syrjälä default: 226232c2bc89SVille Syrjälä return dvo_port; 226332c2bc89SVille Syrjälä } 226432c2bc89SVille Syrjälä } 226532c2bc89SVille Syrjälä 22664628142aSLucas De Marchi static enum port __dvo_port_to_port(int n_ports, int n_dvo, 22674628142aSLucas De Marchi const int port_mapping[][3], u8 dvo_port) 2268df0566a6SJani Nikula { 2269df0566a6SJani Nikula enum port port; 2270df0566a6SJani Nikula int i; 2271df0566a6SJani Nikula 22724628142aSLucas De Marchi for (port = PORT_A; port < n_ports; port++) { 22734628142aSLucas De Marchi for (i = 0; i < n_dvo; i++) { 22744628142aSLucas De Marchi if (port_mapping[port][i] == -1) 2275df0566a6SJani Nikula break; 2276df0566a6SJani Nikula 22774628142aSLucas De Marchi if (dvo_port == port_mapping[port][i]) 2278df0566a6SJani Nikula return port; 2279df0566a6SJani Nikula } 2280df0566a6SJani Nikula } 2281df0566a6SJani Nikula 2282df0566a6SJani Nikula return PORT_NONE; 2283df0566a6SJani Nikula } 2284df0566a6SJani Nikula 2285dbd440d8SJani Nikula static enum port dvo_port_to_port(struct drm_i915_private *i915, 22864628142aSLucas De Marchi u8 dvo_port) 22874628142aSLucas De Marchi { 22884628142aSLucas De Marchi /* 22894628142aSLucas De Marchi * Each DDI port can have more than one value on the "DVO Port" field, 22904628142aSLucas De Marchi * so look for all the possible values for each port. 22914628142aSLucas De Marchi */ 22924628142aSLucas De Marchi static const int port_mapping[][3] = { 22934628142aSLucas De Marchi [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 }, 22944628142aSLucas De Marchi [PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 }, 22954628142aSLucas De Marchi [PORT_C] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 }, 22964628142aSLucas De Marchi [PORT_D] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 }, 22978c1a8f12SMatt Roper [PORT_E] = { DVO_PORT_HDMIE, DVO_PORT_DPE, DVO_PORT_CRT }, 22984628142aSLucas De Marchi [PORT_F] = { DVO_PORT_HDMIF, DVO_PORT_DPF, -1 }, 22994628142aSLucas De Marchi [PORT_G] = { DVO_PORT_HDMIG, DVO_PORT_DPG, -1 }, 2300176430ccSVille Syrjälä [PORT_H] = { DVO_PORT_HDMIH, DVO_PORT_DPH, -1 }, 2301176430ccSVille Syrjälä [PORT_I] = { DVO_PORT_HDMII, DVO_PORT_DPI, -1 }, 23024628142aSLucas De Marchi }; 23034628142aSLucas De Marchi /* 23041d8ca002SVille Syrjälä * RKL VBT uses PHY based mapping. Combo PHYs A,B,C,D 23051d8ca002SVille Syrjälä * map to DDI A,B,TC1,TC2 respectively. 23064628142aSLucas De Marchi */ 23074628142aSLucas De Marchi static const int rkl_port_mapping[][3] = { 23084628142aSLucas De Marchi [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 }, 23094628142aSLucas De Marchi [PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 }, 23104628142aSLucas De Marchi [PORT_C] = { -1 }, 23111d8ca002SVille Syrjälä [PORT_TC1] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 }, 23121d8ca002SVille Syrjälä [PORT_TC2] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 }, 23134628142aSLucas De Marchi }; 231418c283dfSAditya Swarup /* 231518c283dfSAditya Swarup * Alderlake S ports used in the driver are PORT_A, PORT_D, PORT_E, 231618c283dfSAditya Swarup * PORT_F and PORT_G, we need to map that to correct VBT sections. 231718c283dfSAditya Swarup */ 231818c283dfSAditya Swarup static const int adls_port_mapping[][3] = { 231918c283dfSAditya Swarup [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 }, 232018c283dfSAditya Swarup [PORT_B] = { -1 }, 232118c283dfSAditya Swarup [PORT_C] = { -1 }, 232218c283dfSAditya Swarup [PORT_TC1] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 }, 232318c283dfSAditya Swarup [PORT_TC2] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 }, 232418c283dfSAditya Swarup [PORT_TC3] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 }, 232518c283dfSAditya Swarup [PORT_TC4] = { DVO_PORT_HDMIE, DVO_PORT_DPE, -1 }, 232618c283dfSAditya Swarup }; 2327eeb63c54SJosé Roberto de Souza static const int xelpd_port_mapping[][3] = { 2328eeb63c54SJosé Roberto de Souza [PORT_A] = { DVO_PORT_HDMIA, DVO_PORT_DPA, -1 }, 2329eeb63c54SJosé Roberto de Souza [PORT_B] = { DVO_PORT_HDMIB, DVO_PORT_DPB, -1 }, 2330eeb63c54SJosé Roberto de Souza [PORT_C] = { DVO_PORT_HDMIC, DVO_PORT_DPC, -1 }, 2331eeb63c54SJosé Roberto de Souza [PORT_D_XELPD] = { DVO_PORT_HDMID, DVO_PORT_DPD, -1 }, 2332eeb63c54SJosé Roberto de Souza [PORT_E_XELPD] = { DVO_PORT_HDMIE, DVO_PORT_DPE, -1 }, 2333eeb63c54SJosé Roberto de Souza [PORT_TC1] = { DVO_PORT_HDMIF, DVO_PORT_DPF, -1 }, 2334eeb63c54SJosé Roberto de Souza [PORT_TC2] = { DVO_PORT_HDMIG, DVO_PORT_DPG, -1 }, 2335eeb63c54SJosé Roberto de Souza [PORT_TC3] = { DVO_PORT_HDMIH, DVO_PORT_DPH, -1 }, 2336eeb63c54SJosé Roberto de Souza [PORT_TC4] = { DVO_PORT_HDMII, DVO_PORT_DPI, -1 }, 2337eeb63c54SJosé Roberto de Souza }; 23384628142aSLucas De Marchi 2339612dc414SImre Deak if (DISPLAY_VER(i915) >= 13) 2340eeb63c54SJosé Roberto de Souza return __dvo_port_to_port(ARRAY_SIZE(xelpd_port_mapping), 2341eeb63c54SJosé Roberto de Souza ARRAY_SIZE(xelpd_port_mapping[0]), 2342eeb63c54SJosé Roberto de Souza xelpd_port_mapping, 2343eeb63c54SJosé Roberto de Souza dvo_port); 2344eeb63c54SJosé Roberto de Souza else if (IS_ALDERLAKE_S(i915)) 234518c283dfSAditya Swarup return __dvo_port_to_port(ARRAY_SIZE(adls_port_mapping), 234618c283dfSAditya Swarup ARRAY_SIZE(adls_port_mapping[0]), 234718c283dfSAditya Swarup adls_port_mapping, 234818c283dfSAditya Swarup dvo_port); 2349dbd440d8SJani Nikula else if (IS_DG1(i915) || IS_ROCKETLAKE(i915)) 23504628142aSLucas De Marchi return __dvo_port_to_port(ARRAY_SIZE(rkl_port_mapping), 23514628142aSLucas De Marchi ARRAY_SIZE(rkl_port_mapping[0]), 23524628142aSLucas De Marchi rkl_port_mapping, 23534628142aSLucas De Marchi dvo_port); 23544628142aSLucas De Marchi else 23554628142aSLucas De Marchi return __dvo_port_to_port(ARRAY_SIZE(port_mapping), 23564628142aSLucas De Marchi ARRAY_SIZE(port_mapping[0]), 23574628142aSLucas De Marchi port_mapping, 23584628142aSLucas De Marchi dvo_port); 23594628142aSLucas De Marchi } 23604628142aSLucas De Marchi 2361118b5c13SVille Syrjälä static enum port 2362118b5c13SVille Syrjälä dsi_dvo_port_to_port(struct drm_i915_private *i915, u8 dvo_port) 2363118b5c13SVille Syrjälä { 2364118b5c13SVille Syrjälä switch (dvo_port) { 2365118b5c13SVille Syrjälä case DVO_PORT_MIPIA: 2366118b5c13SVille Syrjälä return PORT_A; 2367118b5c13SVille Syrjälä case DVO_PORT_MIPIC: 2368118b5c13SVille Syrjälä if (DISPLAY_VER(i915) >= 11) 2369118b5c13SVille Syrjälä return PORT_B; 2370118b5c13SVille Syrjälä else 2371118b5c13SVille Syrjälä return PORT_C; 2372118b5c13SVille Syrjälä default: 2373118b5c13SVille Syrjälä return PORT_NONE; 2374118b5c13SVille Syrjälä } 2375118b5c13SVille Syrjälä } 2376118b5c13SVille Syrjälä 2377021a62a5SVille Syrjälä enum port intel_bios_encoder_port(const struct intel_bios_encoder_data *devdata) 2378d84b1945SVille Syrjälä { 2379d84b1945SVille Syrjälä struct drm_i915_private *i915 = devdata->i915; 2380d84b1945SVille Syrjälä const struct child_device_config *child = &devdata->child; 2381d84b1945SVille Syrjälä enum port port; 2382d84b1945SVille Syrjälä 2383d84b1945SVille Syrjälä port = dvo_port_to_port(i915, child->dvo_port); 2384d84b1945SVille Syrjälä if (port == PORT_NONE && DISPLAY_VER(i915) >= 11) 2385d84b1945SVille Syrjälä port = dsi_dvo_port_to_port(i915, child->dvo_port); 2386d84b1945SVille Syrjälä 2387d84b1945SVille Syrjälä return port; 2388d84b1945SVille Syrjälä } 2389d84b1945SVille Syrjälä 2390b60e320bSLee Shawn C static int parse_bdb_230_dp_max_link_rate(const int vbt_max_link_rate) 2391b60e320bSLee Shawn C { 2392b60e320bSLee Shawn C switch (vbt_max_link_rate) { 2393b60e320bSLee Shawn C default: 2394b60e320bSLee Shawn C case BDB_230_VBT_DP_MAX_LINK_RATE_DEF: 2395b60e320bSLee Shawn C return 0; 2396b60e320bSLee Shawn C case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR20: 2397b60e320bSLee Shawn C return 2000000; 2398b60e320bSLee Shawn C case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR13P5: 2399b60e320bSLee Shawn C return 1350000; 2400b60e320bSLee Shawn C case BDB_230_VBT_DP_MAX_LINK_RATE_UHBR10: 2401b60e320bSLee Shawn C return 1000000; 2402b60e320bSLee Shawn C case BDB_230_VBT_DP_MAX_LINK_RATE_HBR3: 2403b60e320bSLee Shawn C return 810000; 2404b60e320bSLee Shawn C case BDB_230_VBT_DP_MAX_LINK_RATE_HBR2: 2405b60e320bSLee Shawn C return 540000; 2406b60e320bSLee Shawn C case BDB_230_VBT_DP_MAX_LINK_RATE_HBR: 2407b60e320bSLee Shawn C return 270000; 2408b60e320bSLee Shawn C case BDB_230_VBT_DP_MAX_LINK_RATE_LBR: 2409b60e320bSLee Shawn C return 162000; 2410b60e320bSLee Shawn C } 2411b60e320bSLee Shawn C } 2412b60e320bSLee Shawn C 2413b60e320bSLee Shawn C static int parse_bdb_216_dp_max_link_rate(const int vbt_max_link_rate) 2414b60e320bSLee Shawn C { 2415b60e320bSLee Shawn C switch (vbt_max_link_rate) { 2416b60e320bSLee Shawn C default: 2417b60e320bSLee Shawn C case BDB_216_VBT_DP_MAX_LINK_RATE_HBR3: 2418b60e320bSLee Shawn C return 810000; 2419b60e320bSLee Shawn C case BDB_216_VBT_DP_MAX_LINK_RATE_HBR2: 2420b60e320bSLee Shawn C return 540000; 2421b60e320bSLee Shawn C case BDB_216_VBT_DP_MAX_LINK_RATE_HBR: 2422b60e320bSLee Shawn C return 270000; 2423b60e320bSLee Shawn C case BDB_216_VBT_DP_MAX_LINK_RATE_LBR: 2424b60e320bSLee Shawn C return 162000; 2425b60e320bSLee Shawn C } 2426b60e320bSLee Shawn C } 2427b60e320bSLee Shawn C 242802107ef1SVille Syrjälä int intel_bios_dp_max_link_rate(const struct intel_bios_encoder_data *devdata) 242972337aacSJani Nikula { 2430a434689cSJani Nikula if (!devdata || devdata->i915->display.vbt.version < 216) 243172337aacSJani Nikula return 0; 243272337aacSJani Nikula 2433a434689cSJani Nikula if (devdata->i915->display.vbt.version >= 230) 243472337aacSJani Nikula return parse_bdb_230_dp_max_link_rate(devdata->child.dp_max_link_rate); 243572337aacSJani Nikula else 243672337aacSJani Nikula return parse_bdb_216_dp_max_link_rate(devdata->child.dp_max_link_rate); 243772337aacSJani Nikula } 243872337aacSJani Nikula 243902107ef1SVille Syrjälä int intel_bios_dp_max_lane_count(const struct intel_bios_encoder_data *devdata) 24404182a311SVille Syrjälä { 24414182a311SVille Syrjälä if (!devdata || devdata->i915->display.vbt.version < 244) 24424182a311SVille Syrjälä return 0; 24434182a311SVille Syrjälä 24444182a311SVille Syrjälä return devdata->child.dp_max_lane_count + 1; 24454182a311SVille Syrjälä } 24464182a311SVille Syrjälä 2447d0ab409dSJani Nikula static void sanitize_device_type(struct intel_bios_encoder_data *devdata, 2448d0ab409dSJani Nikula enum port port) 2449d0ab409dSJani Nikula { 2450d0ab409dSJani Nikula struct drm_i915_private *i915 = devdata->i915; 2451d0ab409dSJani Nikula bool is_hdmi; 2452d0ab409dSJani Nikula 2453005e9537SMatt Roper if (port != PORT_A || DISPLAY_VER(i915) >= 12) 2454d0ab409dSJani Nikula return; 2455d0ab409dSJani Nikula 245686996822SJani Nikula if (!intel_bios_encoder_supports_dvi(devdata)) 2457d0ab409dSJani Nikula return; 2458d0ab409dSJani Nikula 245986996822SJani Nikula is_hdmi = intel_bios_encoder_supports_hdmi(devdata); 2460d0ab409dSJani Nikula 2461d0ab409dSJani Nikula drm_dbg_kms(&i915->drm, "VBT claims port A supports DVI%s, ignoring\n", 2462d0ab409dSJani Nikula is_hdmi ? "/HDMI" : ""); 2463d0ab409dSJani Nikula 2464d0ab409dSJani Nikula devdata->child.device_type &= ~DEVICE_TYPE_TMDS_DVI_SIGNALING; 2465d0ab409dSJani Nikula devdata->child.device_type |= DEVICE_TYPE_NOT_HDMI_OUTPUT; 2466d0ab409dSJani Nikula } 2467d0ab409dSJani Nikula 2468d0ab409dSJani Nikula static bool 2469d0ab409dSJani Nikula intel_bios_encoder_supports_crt(const struct intel_bios_encoder_data *devdata) 2470d0ab409dSJani Nikula { 2471d0ab409dSJani Nikula return devdata->child.device_type & DEVICE_TYPE_ANALOG_OUTPUT; 2472d0ab409dSJani Nikula } 2473d0ab409dSJani Nikula 247445c0673aSJani Nikula bool 2475d0ab409dSJani Nikula intel_bios_encoder_supports_dvi(const struct intel_bios_encoder_data *devdata) 2476d0ab409dSJani Nikula { 2477d0ab409dSJani Nikula return devdata->child.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING; 2478d0ab409dSJani Nikula } 2479d0ab409dSJani Nikula 248045c0673aSJani Nikula bool 2481d0ab409dSJani Nikula intel_bios_encoder_supports_hdmi(const struct intel_bios_encoder_data *devdata) 2482d0ab409dSJani Nikula { 2483d0ab409dSJani Nikula return intel_bios_encoder_supports_dvi(devdata) && 2484d0ab409dSJani Nikula (devdata->child.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0; 2485d0ab409dSJani Nikula } 2486d0ab409dSJani Nikula 248745c0673aSJani Nikula bool 2488d0ab409dSJani Nikula intel_bios_encoder_supports_dp(const struct intel_bios_encoder_data *devdata) 2489d0ab409dSJani Nikula { 2490d0ab409dSJani Nikula return devdata->child.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT; 2491d0ab409dSJani Nikula } 2492d0ab409dSJani Nikula 24939d4b7af5SVille Syrjälä bool 2494d0ab409dSJani Nikula intel_bios_encoder_supports_edp(const struct intel_bios_encoder_data *devdata) 2495d0ab409dSJani Nikula { 2496d0ab409dSJani Nikula return intel_bios_encoder_supports_dp(devdata) && 2497d0ab409dSJani Nikula devdata->child.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR; 2498d0ab409dSJani Nikula } 2499d0ab409dSJani Nikula 2500021a62a5SVille Syrjälä bool 2501ba00eb6aSVille Syrjälä intel_bios_encoder_supports_dsi(const struct intel_bios_encoder_data *devdata) 2502ba00eb6aSVille Syrjälä { 2503ba00eb6aSVille Syrjälä return devdata->child.device_type & DEVICE_TYPE_MIPI_OUTPUT; 2504ba00eb6aSVille Syrjälä } 2505ba00eb6aSVille Syrjälä 2506db5d650fSVille Syrjälä bool 2507db5d650fSVille Syrjälä intel_bios_encoder_is_lspcon(const struct intel_bios_encoder_data *devdata) 2508db5d650fSVille Syrjälä { 2509db5d650fSVille Syrjälä return devdata && HAS_LSPCON(devdata->i915) && devdata->child.lspcon; 2510db5d650fSVille Syrjälä } 2511db5d650fSVille Syrjälä 251202107ef1SVille Syrjälä /* This is an index in the HDMI/DVI DDI buffer translation table, or -1 */ 251302107ef1SVille Syrjälä int intel_bios_hdmi_level_shift(const struct intel_bios_encoder_data *devdata) 2514a9a56e76SJani Nikula { 2515d9c078d3SRadhakrishna Sripada if (!devdata || devdata->i915->display.vbt.version < 158 || 2516d9c078d3SRadhakrishna Sripada DISPLAY_VER(devdata->i915) >= 14) 2517a9a56e76SJani Nikula return -1; 2518a9a56e76SJani Nikula 2519a9a56e76SJani Nikula return devdata->child.hdmi_level_shifter_value; 2520a9a56e76SJani Nikula } 2521a9a56e76SJani Nikula 252202107ef1SVille Syrjälä int intel_bios_hdmi_max_tmds_clock(const struct intel_bios_encoder_data *devdata) 25236ba69981SJani Nikula { 2524a434689cSJani Nikula if (!devdata || devdata->i915->display.vbt.version < 204) 25256ba69981SJani Nikula return 0; 25266ba69981SJani Nikula 25276ba69981SJani Nikula switch (devdata->child.hdmi_max_data_rate) { 25286ba69981SJani Nikula default: 25296ba69981SJani Nikula MISSING_CASE(devdata->child.hdmi_max_data_rate); 25306ba69981SJani Nikula fallthrough; 25316ba69981SJani Nikula case HDMI_MAX_DATA_RATE_PLATFORM: 25326ba69981SJani Nikula return 0; 25335708fe0dSLee Shawn C case HDMI_MAX_DATA_RATE_594: 25345708fe0dSLee Shawn C return 594000; 25355708fe0dSLee Shawn C case HDMI_MAX_DATA_RATE_340: 25365708fe0dSLee Shawn C return 340000; 25375708fe0dSLee Shawn C case HDMI_MAX_DATA_RATE_300: 25385708fe0dSLee Shawn C return 300000; 25396ba69981SJani Nikula case HDMI_MAX_DATA_RATE_297: 25406ba69981SJani Nikula return 297000; 25416ba69981SJani Nikula case HDMI_MAX_DATA_RATE_165: 25426ba69981SJani Nikula return 165000; 25436ba69981SJani Nikula } 25446ba69981SJani Nikula } 25456ba69981SJani Nikula 25465a9d38b2SLucas De Marchi static bool is_port_valid(struct drm_i915_private *i915, enum port port) 25475a9d38b2SLucas De Marchi { 25485a9d38b2SLucas De Marchi /* 2549cad83b40SLucas De Marchi * On some ICL SKUs port F is not present, but broken VBTs mark 25505a9d38b2SLucas De Marchi * the port as present. Only try to initialize port F for the 25515a9d38b2SLucas De Marchi * SKUs that may actually have it. 25525a9d38b2SLucas De Marchi */ 2553cad83b40SLucas De Marchi if (port == PORT_F && IS_ICELAKE(i915)) 2554cad83b40SLucas De Marchi return IS_ICL_WITH_PORT_F(i915); 25555a9d38b2SLucas De Marchi 25565a9d38b2SLucas De Marchi return true; 25575a9d38b2SLucas De Marchi } 25585a9d38b2SLucas De Marchi 2559021a62a5SVille Syrjälä static void print_ddi_port(const struct intel_bios_encoder_data *devdata) 2560df0566a6SJani Nikula { 2561c78783f3SJani Nikula struct drm_i915_private *i915 = devdata->i915; 2562d1dad6f4SJani Nikula const struct child_device_config *child = &devdata->child; 2563ba00eb6aSVille Syrjälä bool is_dvi, is_hdmi, is_dp, is_edp, is_dsi, is_crt, supports_typec_usb, supports_tbt; 256472337aacSJani Nikula int dp_boost_level, dp_max_link_rate, hdmi_boost_level, hdmi_level_shift, max_tmds_clock; 2565021a62a5SVille Syrjälä enum port port; 2566021a62a5SVille Syrjälä 2567021a62a5SVille Syrjälä port = intel_bios_encoder_port(devdata); 2568021a62a5SVille Syrjälä if (port == PORT_NONE) 2569021a62a5SVille Syrjälä return; 2570df0566a6SJani Nikula 2571d0ab409dSJani Nikula is_dvi = intel_bios_encoder_supports_dvi(devdata); 2572d0ab409dSJani Nikula is_dp = intel_bios_encoder_supports_dp(devdata); 2573d0ab409dSJani Nikula is_crt = intel_bios_encoder_supports_crt(devdata); 2574d0ab409dSJani Nikula is_hdmi = intel_bios_encoder_supports_hdmi(devdata); 2575d0ab409dSJani Nikula is_edp = intel_bios_encoder_supports_edp(devdata); 2576ba00eb6aSVille Syrjälä is_dsi = intel_bios_encoder_supports_dsi(devdata); 2577df0566a6SJani Nikula 2578f08fbe6aSJani Nikula supports_typec_usb = intel_bios_encoder_supports_typec_usb(devdata); 2579f08fbe6aSJani Nikula supports_tbt = intel_bios_encoder_supports_tbt(devdata); 2580df0566a6SJani Nikula 2581dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 25822bea1d7cSVille Syrjälä "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", 2583ba00eb6aSVille Syrjälä port_name(port), is_crt, is_dvi, is_hdmi, is_dp, is_edp, is_dsi, 25842bea1d7cSVille Syrjälä intel_bios_encoder_supports_dp_dual_mode(devdata), 2585db5d650fSVille Syrjälä intel_bios_encoder_is_lspcon(devdata), 2586f08fbe6aSJani Nikula supports_typec_usb, supports_tbt, 25876e0d46e9SJani Nikula devdata->dsc != NULL); 2588df0566a6SJani Nikula 258902107ef1SVille Syrjälä hdmi_level_shift = intel_bios_hdmi_level_shift(devdata); 2590a9a56e76SJani Nikula if (hdmi_level_shift >= 0) { 2591dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 25926ee8d381SJani Nikula "Port %c VBT HDMI level shift: %d\n", 2593a9a56e76SJani Nikula port_name(port), hdmi_level_shift); 2594df0566a6SJani Nikula } 2595df0566a6SJani Nikula 259602107ef1SVille Syrjälä max_tmds_clock = intel_bios_hdmi_max_tmds_clock(devdata); 2597df0566a6SJani Nikula if (max_tmds_clock) 2598dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 25996ee8d381SJani Nikula "Port %c VBT HDMI max TMDS clock: %d kHz\n", 2600df0566a6SJani Nikula port_name(port), max_tmds_clock); 2601df0566a6SJani Nikula 2602c0a950d1SJani Nikula /* I_boost config for SKL and above */ 260302107ef1SVille Syrjälä dp_boost_level = intel_bios_dp_boost_level(devdata); 2604c0a950d1SJani Nikula if (dp_boost_level) 2605dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 26066ee8d381SJani Nikula "Port %c VBT (e)DP boost level: %d\n", 2607c0a950d1SJani Nikula port_name(port), dp_boost_level); 2608c0a950d1SJani Nikula 260902107ef1SVille Syrjälä hdmi_boost_level = intel_bios_hdmi_boost_level(devdata); 2610c0a950d1SJani Nikula if (hdmi_boost_level) 2611dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 26126ee8d381SJani Nikula "Port %c VBT HDMI boost level: %d\n", 2613c0a950d1SJani Nikula port_name(port), hdmi_boost_level); 2614df0566a6SJani Nikula 261502107ef1SVille Syrjälä dp_max_link_rate = intel_bios_dp_max_link_rate(devdata); 261672337aacSJani Nikula if (dp_max_link_rate) 2617dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 26186ee8d381SJani Nikula "Port %c VBT DP max link rate: %d\n", 261972337aacSJani Nikula port_name(port), dp_max_link_rate); 2620429a0955SVille Syrjälä 2621429a0955SVille Syrjälä /* 2622429a0955SVille Syrjälä * FIXME need to implement support for VBT 2623429a0955SVille Syrjälä * vswing/preemph tables should this ever trigger. 2624429a0955SVille Syrjälä */ 2625429a0955SVille Syrjälä drm_WARN(&i915->drm, child->use_vbt_vswing, 2626429a0955SVille Syrjälä "Port %c asks to use VBT vswing/preemph tables\n", 2627429a0955SVille Syrjälä port_name(port)); 26288d2ba05bSJani Nikula } 26298d2ba05bSJani Nikula 26308d2ba05bSJani Nikula static void parse_ddi_port(struct intel_bios_encoder_data *devdata) 26318d2ba05bSJani Nikula { 26328d2ba05bSJani Nikula struct drm_i915_private *i915 = devdata->i915; 26338d2ba05bSJani Nikula enum port port; 26348d2ba05bSJani Nikula 2635d84b1945SVille Syrjälä port = intel_bios_encoder_port(devdata); 26368d2ba05bSJani Nikula if (port == PORT_NONE) 26378d2ba05bSJani Nikula return; 26388d2ba05bSJani Nikula 26398d2ba05bSJani Nikula if (!is_port_valid(i915, port)) { 26408d2ba05bSJani Nikula drm_dbg_kms(&i915->drm, 26418d2ba05bSJani Nikula "VBT reports port %c as supported, but that can't be true: skipping\n", 26428d2ba05bSJani Nikula port_name(port)); 26438d2ba05bSJani Nikula return; 26448d2ba05bSJani Nikula } 26458d2ba05bSJani Nikula 26468d2ba05bSJani Nikula sanitize_device_type(devdata, port); 2647df0566a6SJani Nikula } 2648df0566a6SJani Nikula 2649b90b6e41SVille Syrjälä static bool has_ddi_port_info(struct drm_i915_private *i915) 2650b90b6e41SVille Syrjälä { 2651594c504dSVille Syrjälä return DISPLAY_VER(i915) >= 5 || IS_G4X(i915); 2652b90b6e41SVille Syrjälä } 2653b90b6e41SVille Syrjälä 2654ef0096e4SJani Nikula static void parse_ddi_ports(struct drm_i915_private *i915) 2655df0566a6SJani Nikula { 26563162d057SJani Nikula struct intel_bios_encoder_data *devdata; 2657df0566a6SJani Nikula 2658eb9fcf63SVille Syrjälä if (!has_ddi_port_info(i915)) 2659df0566a6SJani Nikula return; 2660df0566a6SJani Nikula 2661a434689cSJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) 2662c78783f3SJani Nikula parse_ddi_port(devdata); 2663e61f294cSJani Nikula 2664021a62a5SVille Syrjälä list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) 2665021a62a5SVille Syrjälä print_ddi_port(devdata); 2666df0566a6SJani Nikula } 2667df0566a6SJani Nikula 2668df0566a6SJani Nikula static void 2669e163cfb4SVille Syrjälä parse_general_definitions(struct drm_i915_private *i915) 2670df0566a6SJani Nikula { 2671df0566a6SJani Nikula const struct bdb_general_definitions *defs; 26723162d057SJani Nikula struct intel_bios_encoder_data *devdata; 2673df0566a6SJani Nikula const struct child_device_config *child; 26740d9ef19bSJani Nikula int i, child_device_num; 2675df0566a6SJani Nikula u8 expected_size; 2676df0566a6SJani Nikula u16 block_size; 2677df0566a6SJani Nikula int bus_pin; 2678df0566a6SJani Nikula 26790a93eeb5SMaarten Lankhorst defs = bdb_find_section(i915, BDB_GENERAL_DEFINITIONS); 2680df0566a6SJani Nikula if (!defs) { 2681dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 2682e92cbf38SWambui Karuga "No general definition block is found, no devices defined.\n"); 2683df0566a6SJani Nikula return; 2684df0566a6SJani Nikula } 2685df0566a6SJani Nikula 2686df0566a6SJani Nikula block_size = get_blocksize(defs); 2687df0566a6SJani Nikula if (block_size < sizeof(*defs)) { 2688dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 2689e92cbf38SWambui Karuga "General definitions block too small (%u)\n", 2690df0566a6SJani Nikula block_size); 2691df0566a6SJani Nikula return; 2692df0566a6SJani Nikula } 2693df0566a6SJani Nikula 2694df0566a6SJani Nikula bus_pin = defs->crt_ddc_gmbus_pin; 2695dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, "crt_ddc_bus_pin: %d\n", bus_pin); 2696dbd440d8SJani Nikula if (intel_gmbus_is_valid_pin(i915, bus_pin)) 2697a434689cSJani Nikula i915->display.vbt.crt_ddc_pin = bus_pin; 2698df0566a6SJani Nikula 2699a434689cSJani Nikula if (i915->display.vbt.version < 106) { 2700df0566a6SJani Nikula expected_size = 22; 2701a434689cSJani Nikula } else if (i915->display.vbt.version < 111) { 2702df0566a6SJani Nikula expected_size = 27; 2703a434689cSJani Nikula } else if (i915->display.vbt.version < 195) { 2704df0566a6SJani Nikula expected_size = LEGACY_CHILD_DEVICE_CONFIG_SIZE; 2705a434689cSJani Nikula } else if (i915->display.vbt.version == 195) { 2706df0566a6SJani Nikula expected_size = 37; 2707a434689cSJani Nikula } else if (i915->display.vbt.version <= 215) { 2708df0566a6SJani Nikula expected_size = 38; 27090eaca1edSVille Syrjälä } else if (i915->display.vbt.version <= 250) { 2710df0566a6SJani Nikula expected_size = 39; 2711df0566a6SJani Nikula } else { 2712df0566a6SJani Nikula expected_size = sizeof(*child); 2713df0566a6SJani Nikula BUILD_BUG_ON(sizeof(*child) < 39); 2714dbd440d8SJani Nikula drm_dbg(&i915->drm, 2715e92cbf38SWambui Karuga "Expected child device config size for VBT version %u not known; assuming %u\n", 2716a434689cSJani Nikula i915->display.vbt.version, expected_size); 2717df0566a6SJani Nikula } 2718df0566a6SJani Nikula 2719df0566a6SJani Nikula /* Flag an error for unexpected size, but continue anyway. */ 2720df0566a6SJani Nikula if (defs->child_dev_size != expected_size) 2721dbd440d8SJani Nikula drm_err(&i915->drm, 2722e92cbf38SWambui Karuga "Unexpected child device config size %u (expected %u for VBT version %u)\n", 2723a434689cSJani Nikula defs->child_dev_size, expected_size, i915->display.vbt.version); 2724df0566a6SJani Nikula 2725df0566a6SJani Nikula /* The legacy sized child device config is the minimum we need. */ 2726df0566a6SJani Nikula if (defs->child_dev_size < LEGACY_CHILD_DEVICE_CONFIG_SIZE) { 2727dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 2728e92cbf38SWambui Karuga "Child device config size %u is too small.\n", 2729df0566a6SJani Nikula defs->child_dev_size); 2730df0566a6SJani Nikula return; 2731df0566a6SJani Nikula } 2732df0566a6SJani Nikula 2733df0566a6SJani Nikula /* get the number of child device */ 2734df0566a6SJani Nikula child_device_num = (block_size - sizeof(*defs)) / defs->child_dev_size; 2735df0566a6SJani Nikula 2736df0566a6SJani Nikula for (i = 0; i < child_device_num; i++) { 2737df0566a6SJani Nikula child = child_device_ptr(defs, i); 2738df0566a6SJani Nikula if (!child->device_type) 2739df0566a6SJani Nikula continue; 2740df0566a6SJani Nikula 2741dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 2742e92cbf38SWambui Karuga "Found VBT child device with type 0x%x\n", 2743bdeb18dbSMatt Roper child->device_type); 2744bdeb18dbSMatt Roper 27450d9ef19bSJani Nikula devdata = kzalloc(sizeof(*devdata), GFP_KERNEL); 27460d9ef19bSJani Nikula if (!devdata) 27470d9ef19bSJani Nikula break; 27480d9ef19bSJani Nikula 27497371fa34SJani Nikula devdata->i915 = i915; 27507371fa34SJani Nikula 2751df0566a6SJani Nikula /* 2752df0566a6SJani Nikula * Copy as much as we know (sizeof) and is available 27530d9ef19bSJani Nikula * (child_dev_size) of the child device config. Accessing the 27540d9ef19bSJani Nikula * data must depend on VBT version. 2755df0566a6SJani Nikula */ 27560d9ef19bSJani Nikula memcpy(&devdata->child, child, 2757df0566a6SJani Nikula min_t(size_t, defs->child_dev_size, sizeof(*child))); 27580d9ef19bSJani Nikula 2759a434689cSJani Nikula list_add_tail(&devdata->node, &i915->display.vbt.display_devices); 2760df0566a6SJani Nikula } 27610d9ef19bSJani Nikula 2762a434689cSJani Nikula if (list_empty(&i915->display.vbt.display_devices)) 2763dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 2764e92cbf38SWambui Karuga "no child dev is parsed from VBT\n"); 2765df0566a6SJani Nikula } 2766df0566a6SJani Nikula 2767df0566a6SJani Nikula /* Common defaults which may be overridden by VBT. */ 2768df0566a6SJani Nikula static void 2769dbd440d8SJani Nikula init_vbt_defaults(struct drm_i915_private *i915) 2770df0566a6SJani Nikula { 2771a434689cSJani Nikula i915->display.vbt.crt_ddc_pin = GMBUS_PIN_VGADDC; 2772df0566a6SJani Nikula 2773df0566a6SJani Nikula /* general features */ 2774a434689cSJani Nikula i915->display.vbt.int_tv_support = 1; 2775a434689cSJani Nikula i915->display.vbt.int_crt_support = 1; 2776df0566a6SJani Nikula 2777df0566a6SJani Nikula /* driver features */ 2778a434689cSJani Nikula i915->display.vbt.int_lvds_support = 1; 2779df0566a6SJani Nikula 2780df0566a6SJani Nikula /* Default to using SSC */ 2781a434689cSJani Nikula i915->display.vbt.lvds_use_ssc = 1; 2782df0566a6SJani Nikula /* 2783df0566a6SJani Nikula * Core/SandyBridge/IvyBridge use alternative (120MHz) reference 2784df0566a6SJani Nikula * clock for LVDS. 2785df0566a6SJani Nikula */ 2786a434689cSJani Nikula i915->display.vbt.lvds_ssc_freq = intel_bios_ssc_frequency(i915, 2787dbd440d8SJani Nikula !HAS_PCH_SPLIT(i915)); 2788dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, "Set default to SSC at %d kHz\n", 2789a434689cSJani Nikula i915->display.vbt.lvds_ssc_freq); 2790df0566a6SJani Nikula } 2791df0566a6SJani Nikula 27923cf05076SVille Syrjälä /* Common defaults which may be overridden by VBT. */ 27933cf05076SVille Syrjälä static void 27943cf05076SVille Syrjälä init_vbt_panel_defaults(struct intel_panel *panel) 27953cf05076SVille Syrjälä { 27963cf05076SVille Syrjälä /* Default to having backlight */ 27973cf05076SVille Syrjälä panel->vbt.backlight.present = true; 27983cf05076SVille Syrjälä 27993cf05076SVille Syrjälä /* LFP panel data */ 28003cf05076SVille Syrjälä panel->vbt.lvds_dither = true; 28013cf05076SVille Syrjälä } 28023cf05076SVille Syrjälä 2803df0566a6SJani Nikula /* Defaults to initialize only if there is no VBT. */ 2804df0566a6SJani Nikula static void 2805dbd440d8SJani Nikula init_vbt_missing_defaults(struct drm_i915_private *i915) 2806df0566a6SJani Nikula { 2807df0566a6SJani Nikula enum port port; 28089b52aa72SRodrigo Vivi int ports = BIT(PORT_A) | BIT(PORT_B) | BIT(PORT_C) | 28099b52aa72SRodrigo Vivi BIT(PORT_D) | BIT(PORT_E) | BIT(PORT_F); 2810df0566a6SJani Nikula 2811e20e4037SJani Nikula if (!HAS_DDI(i915) && !IS_CHERRYVIEW(i915)) 2812e20e4037SJani Nikula return; 2813e20e4037SJani Nikula 28143ae04c0cSJani Nikula for_each_port_masked(port, ports) { 28153162d057SJani Nikula struct intel_bios_encoder_data *devdata; 281651f57481SJani Nikula struct child_device_config *child; 2817dbd440d8SJani Nikula enum phy phy = intel_port_to_phy(i915, port); 2818df0566a6SJani Nikula 2819df0566a6SJani Nikula /* 2820df0566a6SJani Nikula * VBT has the TypeC mode (native,TBT/USB) and we don't want 2821df0566a6SJani Nikula * to detect it. 2822df0566a6SJani Nikula */ 2823dbd440d8SJani Nikula if (intel_phy_is_tc(i915, phy)) 2824df0566a6SJani Nikula continue; 2825df0566a6SJani Nikula 282651f57481SJani Nikula /* Create fake child device config */ 282751f57481SJani Nikula devdata = kzalloc(sizeof(*devdata), GFP_KERNEL); 282851f57481SJani Nikula if (!devdata) 282951f57481SJani Nikula break; 283051f57481SJani Nikula 28317371fa34SJani Nikula devdata->i915 = i915; 283251f57481SJani Nikula child = &devdata->child; 283351f57481SJani Nikula 283451f57481SJani Nikula if (port == PORT_F) 283551f57481SJani Nikula child->dvo_port = DVO_PORT_HDMIF; 283651f57481SJani Nikula else if (port == PORT_E) 283751f57481SJani Nikula child->dvo_port = DVO_PORT_HDMIE; 283851f57481SJani Nikula else 283951f57481SJani Nikula child->dvo_port = DVO_PORT_HDMIA + port; 284051f57481SJani Nikula 284151f57481SJani Nikula if (port != PORT_A && port != PORT_E) 284251f57481SJani Nikula child->device_type |= DEVICE_TYPE_TMDS_DVI_SIGNALING; 284351f57481SJani Nikula 284451f57481SJani Nikula if (port != PORT_E) 284551f57481SJani Nikula child->device_type |= DEVICE_TYPE_DISPLAYPORT_OUTPUT; 284651f57481SJani Nikula 284751f57481SJani Nikula if (port == PORT_A) 284851f57481SJani Nikula child->device_type |= DEVICE_TYPE_INTERNAL_CONNECTOR; 284951f57481SJani Nikula 2850a434689cSJani Nikula list_add_tail(&devdata->node, &i915->display.vbt.display_devices); 285151f57481SJani Nikula 285251f57481SJani Nikula drm_dbg_kms(&i915->drm, 285351f57481SJani Nikula "Generating default VBT child device with type 0x04%x on port %c\n", 285451f57481SJani Nikula child->device_type, port_name(port)); 2855df0566a6SJani Nikula } 285651f57481SJani Nikula 285751f57481SJani Nikula /* Bypass some minimum baseline VBT version checks */ 2858a434689cSJani Nikula i915->display.vbt.version = 155; 2859df0566a6SJani Nikula } 2860df0566a6SJani Nikula 2861df0566a6SJani Nikula static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt) 2862df0566a6SJani Nikula { 2863df0566a6SJani Nikula const void *_vbt = vbt; 2864df0566a6SJani Nikula 2865df0566a6SJani Nikula return _vbt + vbt->bdb_offset; 2866df0566a6SJani Nikula } 2867df0566a6SJani Nikula 2868df0566a6SJani Nikula /** 2869df0566a6SJani Nikula * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT 2870df0566a6SJani Nikula * @buf: pointer to a buffer to validate 2871df0566a6SJani Nikula * @size: size of the buffer 2872df0566a6SJani Nikula * 2873df0566a6SJani Nikula * Returns true on valid VBT. 2874df0566a6SJani Nikula */ 2875df0566a6SJani Nikula bool intel_bios_is_valid_vbt(const void *buf, size_t size) 2876df0566a6SJani Nikula { 2877df0566a6SJani Nikula const struct vbt_header *vbt = buf; 2878df0566a6SJani Nikula const struct bdb_header *bdb; 2879df0566a6SJani Nikula 2880df0566a6SJani Nikula if (!vbt) 2881df0566a6SJani Nikula return false; 2882df0566a6SJani Nikula 2883df0566a6SJani Nikula if (sizeof(struct vbt_header) > size) { 2884df0566a6SJani Nikula DRM_DEBUG_DRIVER("VBT header incomplete\n"); 2885df0566a6SJani Nikula return false; 2886df0566a6SJani Nikula } 2887df0566a6SJani Nikula 2888df0566a6SJani Nikula if (memcmp(vbt->signature, "$VBT", 4)) { 2889df0566a6SJani Nikula DRM_DEBUG_DRIVER("VBT invalid signature\n"); 2890df0566a6SJani Nikula return false; 2891df0566a6SJani Nikula } 2892df0566a6SJani Nikula 2893ff00ff96SLucas De Marchi if (vbt->vbt_size > size) { 2894ff00ff96SLucas De Marchi DRM_DEBUG_DRIVER("VBT incomplete (vbt_size overflows)\n"); 2895ff00ff96SLucas De Marchi return false; 2896ff00ff96SLucas De Marchi } 2897ff00ff96SLucas De Marchi 2898ff00ff96SLucas De Marchi size = vbt->vbt_size; 2899ff00ff96SLucas De Marchi 2900df0566a6SJani Nikula if (range_overflows_t(size_t, 2901df0566a6SJani Nikula vbt->bdb_offset, 2902df0566a6SJani Nikula sizeof(struct bdb_header), 2903df0566a6SJani Nikula size)) { 2904df0566a6SJani Nikula DRM_DEBUG_DRIVER("BDB header incomplete\n"); 2905df0566a6SJani Nikula return false; 2906df0566a6SJani Nikula } 2907df0566a6SJani Nikula 2908df0566a6SJani Nikula bdb = get_bdb_header(vbt); 2909df0566a6SJani Nikula if (range_overflows_t(size_t, vbt->bdb_offset, bdb->bdb_size, size)) { 2910df0566a6SJani Nikula DRM_DEBUG_DRIVER("BDB incomplete\n"); 2911df0566a6SJani Nikula return false; 2912df0566a6SJani Nikula } 2913df0566a6SJani Nikula 2914df0566a6SJani Nikula return vbt; 2915df0566a6SJani Nikula } 2916df0566a6SJani Nikula 29173631c363SJani Nikula static u32 intel_spi_read(struct intel_uncore *uncore, u32 offset) 29183631c363SJani Nikula { 29193631c363SJani Nikula intel_uncore_write(uncore, PRIMARY_SPI_ADDRESS, offset); 29203631c363SJani Nikula 29213631c363SJani Nikula return intel_uncore_read(uncore, PRIMARY_SPI_TRIGGER); 29223631c363SJani Nikula } 29233631c363SJani Nikula 2924a36e7dc0SClint Taylor static struct vbt_header *spi_oprom_get_vbt(struct drm_i915_private *i915) 2925a36e7dc0SClint Taylor { 2926a36e7dc0SClint Taylor u32 count, data, found, store = 0; 2927a36e7dc0SClint Taylor u32 static_region, oprom_offset; 2928a36e7dc0SClint Taylor u32 oprom_size = 0x200000; 2929a36e7dc0SClint Taylor u16 vbt_size; 2930a36e7dc0SClint Taylor u32 *vbt; 2931a36e7dc0SClint Taylor 2932a36e7dc0SClint Taylor static_region = intel_uncore_read(&i915->uncore, SPI_STATIC_REGIONS); 2933a36e7dc0SClint Taylor static_region &= OPTIONROM_SPI_REGIONID_MASK; 2934a36e7dc0SClint Taylor intel_uncore_write(&i915->uncore, PRIMARY_SPI_REGIONID, static_region); 2935a36e7dc0SClint Taylor 2936a36e7dc0SClint Taylor oprom_offset = intel_uncore_read(&i915->uncore, OROM_OFFSET); 2937a36e7dc0SClint Taylor oprom_offset &= OROM_OFFSET_MASK; 2938a36e7dc0SClint Taylor 2939a36e7dc0SClint Taylor for (count = 0; count < oprom_size; count += 4) { 29403631c363SJani Nikula data = intel_spi_read(&i915->uncore, oprom_offset + count); 2941a36e7dc0SClint Taylor if (data == *((const u32 *)"$VBT")) { 2942a36e7dc0SClint Taylor found = oprom_offset + count; 2943a36e7dc0SClint Taylor break; 2944a36e7dc0SClint Taylor } 2945a36e7dc0SClint Taylor } 2946a36e7dc0SClint Taylor 2947a36e7dc0SClint Taylor if (count >= oprom_size) 2948a36e7dc0SClint Taylor goto err_not_found; 2949a36e7dc0SClint Taylor 2950a36e7dc0SClint Taylor /* Get VBT size and allocate space for the VBT */ 29513631c363SJani Nikula vbt_size = intel_spi_read(&i915->uncore, 29523631c363SJani Nikula found + offsetof(struct vbt_header, vbt_size)); 2953a36e7dc0SClint Taylor vbt_size &= 0xffff; 2954a36e7dc0SClint Taylor 2955980f42e7SJani Nikula vbt = kzalloc(round_up(vbt_size, 4), GFP_KERNEL); 2956a36e7dc0SClint Taylor if (!vbt) 2957a36e7dc0SClint Taylor goto err_not_found; 2958a36e7dc0SClint Taylor 29593631c363SJani Nikula for (count = 0; count < vbt_size; count += 4) 29603631c363SJani Nikula *(vbt + store++) = intel_spi_read(&i915->uncore, found + count); 2961a36e7dc0SClint Taylor 2962a36e7dc0SClint Taylor if (!intel_bios_is_valid_vbt(vbt, vbt_size)) 2963a36e7dc0SClint Taylor goto err_free_vbt; 2964a36e7dc0SClint Taylor 2965a36e7dc0SClint Taylor drm_dbg_kms(&i915->drm, "Found valid VBT in SPI flash\n"); 2966a36e7dc0SClint Taylor 2967a36e7dc0SClint Taylor return (struct vbt_header *)vbt; 2968a36e7dc0SClint Taylor 2969a36e7dc0SClint Taylor err_free_vbt: 2970a36e7dc0SClint Taylor kfree(vbt); 2971a36e7dc0SClint Taylor err_not_found: 2972a36e7dc0SClint Taylor return NULL; 2973a36e7dc0SClint Taylor } 2974a36e7dc0SClint Taylor 2975dbd440d8SJani Nikula static struct vbt_header *oprom_get_vbt(struct drm_i915_private *i915) 2976df0566a6SJani Nikula { 2977dbd440d8SJani Nikula struct pci_dev *pdev = to_pci_dev(i915->drm.dev); 29782cded152SLucas De Marchi void __iomem *p = NULL, *oprom; 2979fd0186ceSLucas De Marchi struct vbt_header *vbt; 2980fd0186ceSLucas De Marchi u16 vbt_size; 29812cded152SLucas De Marchi size_t i, size; 29822cded152SLucas De Marchi 29832cded152SLucas De Marchi oprom = pci_map_rom(pdev, &size); 29842cded152SLucas De Marchi if (!oprom) 29852cded152SLucas De Marchi return NULL; 2986df0566a6SJani Nikula 2987df0566a6SJani Nikula /* Scour memory looking for the VBT signature. */ 298898cf5c9aSLucas De Marchi for (i = 0; i + 4 < size; i += 4) { 2989496f50a6SLucas De Marchi if (ioread32(oprom + i) != *((const u32 *)"$VBT")) 2990df0566a6SJani Nikula continue; 2991df0566a6SJani Nikula 2992fd0186ceSLucas De Marchi p = oprom + i; 2993fd0186ceSLucas De Marchi size -= i; 2994df0566a6SJani Nikula break; 2995df0566a6SJani Nikula } 2996df0566a6SJani Nikula 2997fd0186ceSLucas De Marchi if (!p) 29982cded152SLucas De Marchi goto err_unmap_oprom; 2999fd0186ceSLucas De Marchi 3000fd0186ceSLucas De Marchi if (sizeof(struct vbt_header) > size) { 3001dbd440d8SJani Nikula drm_dbg(&i915->drm, "VBT header incomplete\n"); 30022cded152SLucas De Marchi goto err_unmap_oprom; 3003fd0186ceSLucas De Marchi } 3004fd0186ceSLucas De Marchi 3005fd0186ceSLucas De Marchi vbt_size = ioread16(p + offsetof(struct vbt_header, vbt_size)); 3006fd0186ceSLucas De Marchi if (vbt_size > size) { 3007dbd440d8SJani Nikula drm_dbg(&i915->drm, 3008e92cbf38SWambui Karuga "VBT incomplete (vbt_size overflows)\n"); 30092cded152SLucas De Marchi goto err_unmap_oprom; 3010fd0186ceSLucas De Marchi } 3011fd0186ceSLucas De Marchi 3012fd0186ceSLucas De Marchi /* The rest will be validated by intel_bios_is_valid_vbt() */ 3013fd0186ceSLucas De Marchi vbt = kmalloc(vbt_size, GFP_KERNEL); 3014fd0186ceSLucas De Marchi if (!vbt) 30152cded152SLucas De Marchi goto err_unmap_oprom; 3016fd0186ceSLucas De Marchi 3017fd0186ceSLucas De Marchi memcpy_fromio(vbt, p, vbt_size); 3018fd0186ceSLucas De Marchi 3019fd0186ceSLucas De Marchi if (!intel_bios_is_valid_vbt(vbt, vbt_size)) 3020fd0186ceSLucas De Marchi goto err_free_vbt; 3021fd0186ceSLucas De Marchi 30222cded152SLucas De Marchi pci_unmap_rom(pdev, oprom); 30232cded152SLucas De Marchi 3024a36e7dc0SClint Taylor drm_dbg_kms(&i915->drm, "Found valid VBT in PCI ROM\n"); 3025a36e7dc0SClint Taylor 3026fd0186ceSLucas De Marchi return vbt; 3027fd0186ceSLucas De Marchi 3028fd0186ceSLucas De Marchi err_free_vbt: 3029fd0186ceSLucas De Marchi kfree(vbt); 30302cded152SLucas De Marchi err_unmap_oprom: 30312cded152SLucas De Marchi pci_unmap_rom(pdev, oprom); 3032fd0186ceSLucas De Marchi 3033df0566a6SJani Nikula return NULL; 3034df0566a6SJani Nikula } 3035df0566a6SJani Nikula 3036df0566a6SJani Nikula /** 3037df0566a6SJani Nikula * intel_bios_init - find VBT and initialize settings from the BIOS 3038dbd440d8SJani Nikula * @i915: i915 device instance 3039df0566a6SJani Nikula * 3040df0566a6SJani Nikula * Parse and initialize settings from the Video BIOS Tables (VBT). If the VBT 3041df0566a6SJani Nikula * was not found in ACPI OpRegion, try to find it in PCI ROM first. Also 3042df0566a6SJani Nikula * initialize some defaults if the VBT is not present at all. 3043df0566a6SJani Nikula */ 3044dbd440d8SJani Nikula void intel_bios_init(struct drm_i915_private *i915) 3045df0566a6SJani Nikula { 30467249dfcbSJani Nikula const struct vbt_header *vbt = i915->display.opregion.vbt; 30472cded152SLucas De Marchi struct vbt_header *oprom_vbt = NULL; 3048df0566a6SJani Nikula const struct bdb_header *bdb; 3049df0566a6SJani Nikula 3050a434689cSJani Nikula INIT_LIST_HEAD(&i915->display.vbt.display_devices); 3051a434689cSJani Nikula INIT_LIST_HEAD(&i915->display.vbt.bdb_blocks); 30520d9ef19bSJani Nikula 3053dbd440d8SJani Nikula if (!HAS_DISPLAY(i915)) { 3054dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 3055e92cbf38SWambui Karuga "Skipping VBT init due to disabled display.\n"); 3056df0566a6SJani Nikula return; 3057df0566a6SJani Nikula } 3058df0566a6SJani Nikula 3059dbd440d8SJani Nikula init_vbt_defaults(i915); 3060df0566a6SJani Nikula 3061a36e7dc0SClint Taylor /* 3062a36e7dc0SClint Taylor * If the OpRegion does not have VBT, look in SPI flash through MMIO or 3063a36e7dc0SClint Taylor * PCI mapping 3064a36e7dc0SClint Taylor */ 3065a36e7dc0SClint Taylor if (!vbt && IS_DGFX(i915)) { 3066a36e7dc0SClint Taylor oprom_vbt = spi_oprom_get_vbt(i915); 3067a36e7dc0SClint Taylor vbt = oprom_vbt; 3068a36e7dc0SClint Taylor } 3069a36e7dc0SClint Taylor 3070df0566a6SJani Nikula if (!vbt) { 3071dbd440d8SJani Nikula oprom_vbt = oprom_get_vbt(i915); 30722cded152SLucas De Marchi vbt = oprom_vbt; 3073df0566a6SJani Nikula } 3074df0566a6SJani Nikula 3075a36e7dc0SClint Taylor if (!vbt) 3076a36e7dc0SClint Taylor goto out; 3077a36e7dc0SClint Taylor 3078df0566a6SJani Nikula bdb = get_bdb_header(vbt); 3079a434689cSJani Nikula i915->display.vbt.version = bdb->version; 3080df0566a6SJani Nikula 3081dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 3082e92cbf38SWambui Karuga "VBT signature \"%.*s\", BDB version %d\n", 3083a434689cSJani Nikula (int)sizeof(vbt->signature), vbt->signature, i915->display.vbt.version); 3084df0566a6SJani Nikula 3085e163cfb4SVille Syrjälä init_bdb_blocks(i915, bdb); 3086e163cfb4SVille Syrjälä 3087df0566a6SJani Nikula /* Grab useful general definitions */ 3088e163cfb4SVille Syrjälä parse_general_features(i915); 3089e163cfb4SVille Syrjälä parse_general_definitions(i915); 3090e163cfb4SVille Syrjälä parse_driver_features(i915); 3091df0566a6SJani Nikula 30926e0d46e9SJani Nikula /* Depends on child device list */ 3093e163cfb4SVille Syrjälä parse_compression_parameters(i915); 30946e0d46e9SJani Nikula 3095df0566a6SJani Nikula out: 3096df0566a6SJani Nikula if (!vbt) { 3097dbd440d8SJani Nikula drm_info(&i915->drm, 3098e92cbf38SWambui Karuga "Failed to find VBIOS tables (VBT)\n"); 3099dbd440d8SJani Nikula init_vbt_missing_defaults(i915); 3100df0566a6SJani Nikula } 3101df0566a6SJani Nikula 310251f57481SJani Nikula /* Further processing on pre-parsed or generated child device data */ 310351f57481SJani Nikula parse_sdvo_device_mapping(i915); 310451f57481SJani Nikula parse_ddi_ports(i915); 310551f57481SJani Nikula 31062cded152SLucas De Marchi kfree(oprom_vbt); 3107df0566a6SJani Nikula } 3108df0566a6SJani Nikula 31093f9ffce5SVille Syrjälä static void intel_bios_init_panel(struct drm_i915_private *i915, 3110c518a775SVille Syrjälä struct intel_panel *panel, 31116434cf63SAnimesh Manna const struct intel_bios_encoder_data *devdata, 3112c36225a1SJani Nikula const struct drm_edid *drm_edid, 31133f9ffce5SVille Syrjälä bool use_fallback) 3114c2fdb424SVille Syrjälä { 31153f9ffce5SVille Syrjälä /* already have it? */ 31163f9ffce5SVille Syrjälä if (panel->vbt.panel_type >= 0) { 31173f9ffce5SVille Syrjälä drm_WARN_ON(&i915->drm, !use_fallback); 31183f9ffce5SVille Syrjälä return; 31193f9ffce5SVille Syrjälä } 31203cf05076SVille Syrjälä 31213f9ffce5SVille Syrjälä panel->vbt.panel_type = get_panel_type(i915, devdata, 3122c36225a1SJani Nikula drm_edid, use_fallback); 31233f9ffce5SVille Syrjälä if (panel->vbt.panel_type < 0) { 31243f9ffce5SVille Syrjälä drm_WARN_ON(&i915->drm, use_fallback); 31253f9ffce5SVille Syrjälä return; 31263f9ffce5SVille Syrjälä } 31273f9ffce5SVille Syrjälä 31283f9ffce5SVille Syrjälä init_vbt_panel_defaults(panel); 31290256ea13SVille Syrjälä 31300256ea13SVille Syrjälä parse_panel_options(i915, panel); 31313cf05076SVille Syrjälä parse_generic_dtd(i915, panel); 31323cf05076SVille Syrjälä parse_lfp_data(i915, panel); 31333cf05076SVille Syrjälä parse_lfp_backlight(i915, panel); 31343cf05076SVille Syrjälä parse_sdvo_panel_data(i915, panel); 31353cf05076SVille Syrjälä parse_panel_driver_features(i915, panel); 31363cf05076SVille Syrjälä parse_power_conservation_features(i915, panel); 31373cf05076SVille Syrjälä parse_edp(i915, panel); 31383cf05076SVille Syrjälä parse_psr(i915, panel); 31393cf05076SVille Syrjälä parse_mipi_config(i915, panel); 31403cf05076SVille Syrjälä parse_mipi_sequence(i915, panel); 3141c2fdb424SVille Syrjälä } 3142c2fdb424SVille Syrjälä 31433f9ffce5SVille Syrjälä void intel_bios_init_panel_early(struct drm_i915_private *i915, 31443f9ffce5SVille Syrjälä struct intel_panel *panel, 31453f9ffce5SVille Syrjälä const struct intel_bios_encoder_data *devdata) 31463f9ffce5SVille Syrjälä { 31473f9ffce5SVille Syrjälä intel_bios_init_panel(i915, panel, devdata, NULL, false); 31483f9ffce5SVille Syrjälä } 31493f9ffce5SVille Syrjälä 31503f9ffce5SVille Syrjälä void intel_bios_init_panel_late(struct drm_i915_private *i915, 31513f9ffce5SVille Syrjälä struct intel_panel *panel, 31523f9ffce5SVille Syrjälä const struct intel_bios_encoder_data *devdata, 3153c36225a1SJani Nikula const struct drm_edid *drm_edid) 31543f9ffce5SVille Syrjälä { 3155c36225a1SJani Nikula intel_bios_init_panel(i915, panel, devdata, drm_edid, true); 31563f9ffce5SVille Syrjälä } 31573f9ffce5SVille Syrjälä 3158df0566a6SJani Nikula /** 315978dae1acSJanusz Krzysztofik * intel_bios_driver_remove - Free any resources allocated by intel_bios_init() 3160dbd440d8SJani Nikula * @i915: i915 device instance 3161df0566a6SJani Nikula */ 3162dbd440d8SJani Nikula void intel_bios_driver_remove(struct drm_i915_private *i915) 3163df0566a6SJani Nikula { 3164e163cfb4SVille Syrjälä struct intel_bios_encoder_data *devdata, *nd; 3165e163cfb4SVille Syrjälä struct bdb_block_entry *entry, *ne; 31660d9ef19bSJani Nikula 3167a434689cSJani Nikula list_for_each_entry_safe(devdata, nd, &i915->display.vbt.display_devices, node) { 31680d9ef19bSJani Nikula list_del(&devdata->node); 31696e0d46e9SJani Nikula kfree(devdata->dsc); 31700d9ef19bSJani Nikula kfree(devdata); 31710d9ef19bSJani Nikula } 31720d9ef19bSJani Nikula 3173a434689cSJani Nikula list_for_each_entry_safe(entry, ne, &i915->display.vbt.bdb_blocks, node) { 3174e163cfb4SVille Syrjälä list_del(&entry->node); 3175e163cfb4SVille Syrjälä kfree(entry); 3176e163cfb4SVille Syrjälä } 31773cf05076SVille Syrjälä } 3178e163cfb4SVille Syrjälä 31793cf05076SVille Syrjälä void intel_bios_fini_panel(struct intel_panel *panel) 31803cf05076SVille Syrjälä { 31813cf05076SVille Syrjälä kfree(panel->vbt.sdvo_lvds_vbt_mode); 31823cf05076SVille Syrjälä panel->vbt.sdvo_lvds_vbt_mode = NULL; 31833cf05076SVille Syrjälä kfree(panel->vbt.lfp_lvds_vbt_mode); 31843cf05076SVille Syrjälä panel->vbt.lfp_lvds_vbt_mode = NULL; 31853cf05076SVille Syrjälä kfree(panel->vbt.dsi.data); 31863cf05076SVille Syrjälä panel->vbt.dsi.data = NULL; 31873cf05076SVille Syrjälä kfree(panel->vbt.dsi.pps); 31883cf05076SVille Syrjälä panel->vbt.dsi.pps = NULL; 31893cf05076SVille Syrjälä kfree(panel->vbt.dsi.config); 31903cf05076SVille Syrjälä panel->vbt.dsi.config = NULL; 31913cf05076SVille Syrjälä kfree(panel->vbt.dsi.deassert_seq); 31923cf05076SVille Syrjälä panel->vbt.dsi.deassert_seq = NULL; 3193df0566a6SJani Nikula } 3194df0566a6SJani Nikula 3195df0566a6SJani Nikula /** 3196df0566a6SJani Nikula * intel_bios_is_tv_present - is integrated TV present in VBT 3197dbd440d8SJani Nikula * @i915: i915 device instance 3198df0566a6SJani Nikula * 3199df0566a6SJani Nikula * Return true if TV is present. If no child devices were parsed from VBT, 3200df0566a6SJani Nikula * assume TV is present. 3201df0566a6SJani Nikula */ 3202dbd440d8SJani Nikula bool intel_bios_is_tv_present(struct drm_i915_private *i915) 3203df0566a6SJani Nikula { 32043162d057SJani Nikula const struct intel_bios_encoder_data *devdata; 3205df0566a6SJani Nikula 3206a434689cSJani Nikula if (!i915->display.vbt.int_tv_support) 3207df0566a6SJani Nikula return false; 3208df0566a6SJani Nikula 3209a434689cSJani Nikula if (list_empty(&i915->display.vbt.display_devices)) 3210df0566a6SJani Nikula return true; 3211df0566a6SJani Nikula 3212a434689cSJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) { 3213d24b3475SVille Syrjälä const struct child_device_config *child = &devdata->child; 32140d9ef19bSJani Nikula 3215df0566a6SJani Nikula /* 3216df0566a6SJani Nikula * If the device type is not TV, continue. 3217df0566a6SJani Nikula */ 3218df0566a6SJani Nikula switch (child->device_type) { 3219df0566a6SJani Nikula case DEVICE_TYPE_INT_TV: 3220df0566a6SJani Nikula case DEVICE_TYPE_TV: 3221df0566a6SJani Nikula case DEVICE_TYPE_TV_SVIDEO_COMPOSITE: 3222df0566a6SJani Nikula break; 3223df0566a6SJani Nikula default: 3224df0566a6SJani Nikula continue; 3225df0566a6SJani Nikula } 3226df0566a6SJani Nikula /* Only when the addin_offset is non-zero, it is regarded 3227df0566a6SJani Nikula * as present. 3228df0566a6SJani Nikula */ 3229df0566a6SJani Nikula if (child->addin_offset) 3230df0566a6SJani Nikula return true; 3231df0566a6SJani Nikula } 3232df0566a6SJani Nikula 3233df0566a6SJani Nikula return false; 3234df0566a6SJani Nikula } 3235df0566a6SJani Nikula 3236df0566a6SJani Nikula /** 3237df0566a6SJani Nikula * intel_bios_is_lvds_present - is LVDS present in VBT 3238dbd440d8SJani Nikula * @i915: i915 device instance 3239df0566a6SJani Nikula * @i2c_pin: i2c pin for LVDS if present 3240df0566a6SJani Nikula * 3241df0566a6SJani Nikula * Return true if LVDS is present. If no child devices were parsed from VBT, 3242df0566a6SJani Nikula * assume LVDS is present. 3243df0566a6SJani Nikula */ 3244dbd440d8SJani Nikula bool intel_bios_is_lvds_present(struct drm_i915_private *i915, u8 *i2c_pin) 3245df0566a6SJani Nikula { 32463162d057SJani Nikula const struct intel_bios_encoder_data *devdata; 3247df0566a6SJani Nikula 3248a434689cSJani Nikula if (list_empty(&i915->display.vbt.display_devices)) 3249df0566a6SJani Nikula return true; 3250df0566a6SJani Nikula 3251a434689cSJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) { 3252d24b3475SVille Syrjälä const struct child_device_config *child = &devdata->child; 3253df0566a6SJani Nikula 3254df0566a6SJani Nikula /* If the device type is not LFP, continue. 3255df0566a6SJani Nikula * We have to check both the new identifiers as well as the 3256df0566a6SJani Nikula * old for compatibility with some BIOSes. 3257df0566a6SJani Nikula */ 3258df0566a6SJani Nikula if (child->device_type != DEVICE_TYPE_INT_LFP && 3259df0566a6SJani Nikula child->device_type != DEVICE_TYPE_LFP) 3260df0566a6SJani Nikula continue; 3261df0566a6SJani Nikula 3262dbd440d8SJani Nikula if (intel_gmbus_is_valid_pin(i915, child->i2c_pin)) 3263df0566a6SJani Nikula *i2c_pin = child->i2c_pin; 3264df0566a6SJani Nikula 3265df0566a6SJani Nikula /* However, we cannot trust the BIOS writers to populate 3266df0566a6SJani Nikula * the VBT correctly. Since LVDS requires additional 3267df0566a6SJani Nikula * information from AIM blocks, a non-zero addin offset is 3268df0566a6SJani Nikula * a good indicator that the LVDS is actually present. 3269df0566a6SJani Nikula */ 3270df0566a6SJani Nikula if (child->addin_offset) 3271df0566a6SJani Nikula return true; 3272df0566a6SJani Nikula 3273df0566a6SJani Nikula /* But even then some BIOS writers perform some black magic 3274df0566a6SJani Nikula * and instantiate the device without reference to any 3275df0566a6SJani Nikula * additional data. Trust that if the VBT was written into 3276df0566a6SJani Nikula * the OpRegion then they have validated the LVDS's existence. 3277df0566a6SJani Nikula */ 32787249dfcbSJani Nikula if (i915->display.opregion.vbt) 3279df0566a6SJani Nikula return true; 3280df0566a6SJani Nikula } 3281df0566a6SJani Nikula 3282df0566a6SJani Nikula return false; 3283df0566a6SJani Nikula } 3284df0566a6SJani Nikula 3285df0566a6SJani Nikula /** 3286df0566a6SJani Nikula * intel_bios_is_port_present - is the specified digital port present 3287dbd440d8SJani Nikula * @i915: i915 device instance 3288df0566a6SJani Nikula * @port: port to check 3289df0566a6SJani Nikula * 3290df0566a6SJani Nikula * Return true if the device in %port is present. 3291df0566a6SJani Nikula */ 3292dbd440d8SJani Nikula bool intel_bios_is_port_present(struct drm_i915_private *i915, enum port port) 3293df0566a6SJani Nikula { 3294b17a15d6SVille Syrjälä const struct intel_bios_encoder_data *devdata; 3295b17a15d6SVille Syrjälä 3296a868a1e5SVille Syrjälä if (WARN_ON(!has_ddi_port_info(i915))) 3297df0566a6SJani Nikula return true; 3298df0566a6SJani Nikula 3299b17a15d6SVille Syrjälä if (!is_port_valid(i915, port)) 3300b17a15d6SVille Syrjälä return false; 3301b17a15d6SVille Syrjälä 3302b17a15d6SVille Syrjälä list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) { 3303b17a15d6SVille Syrjälä const struct child_device_config *child = &devdata->child; 3304b17a15d6SVille Syrjälä 3305b17a15d6SVille Syrjälä if (dvo_port_to_port(i915, child->dvo_port) == port) 3306b17a15d6SVille Syrjälä return true; 3307b17a15d6SVille Syrjälä } 3308b17a15d6SVille Syrjälä 3309b17a15d6SVille Syrjälä return false; 3310df0566a6SJani Nikula } 3311df0566a6SJani Nikula 33122bea1d7cSVille Syrjälä bool intel_bios_encoder_supports_dp_dual_mode(const struct intel_bios_encoder_data *devdata) 331332c2bc89SVille Syrjälä { 3314044cbc7aSVille Syrjälä const struct child_device_config *child = &devdata->child; 3315044cbc7aSVille Syrjälä 3316044cbc7aSVille Syrjälä if (!intel_bios_encoder_supports_dp(devdata) || 3317044cbc7aSVille Syrjälä !intel_bios_encoder_supports_hdmi(devdata)) 331832c2bc89SVille Syrjälä return false; 331932c2bc89SVille Syrjälä 332032c2bc89SVille Syrjälä if (dvo_port_type(child->dvo_port) == DVO_PORT_DPA) 332132c2bc89SVille Syrjälä return true; 332232c2bc89SVille Syrjälä 332332c2bc89SVille Syrjälä /* Only accept a HDMI dvo_port as DP++ if it has an AUX channel */ 332432c2bc89SVille Syrjälä if (dvo_port_type(child->dvo_port) == DVO_PORT_HDMIA && 332532c2bc89SVille Syrjälä child->aux_channel != 0) 332632c2bc89SVille Syrjälä return true; 332732c2bc89SVille Syrjälä 332832c2bc89SVille Syrjälä return false; 332932c2bc89SVille Syrjälä } 333032c2bc89SVille Syrjälä 3331df0566a6SJani Nikula /** 3332df0566a6SJani Nikula * intel_bios_is_dsi_present - is DSI present in VBT 3333dbd440d8SJani Nikula * @i915: i915 device instance 3334df0566a6SJani Nikula * @port: port for DSI if present 3335df0566a6SJani Nikula * 3336df0566a6SJani Nikula * Return true if DSI is present, and return the port in %port. 3337df0566a6SJani Nikula */ 3338dbd440d8SJani Nikula bool intel_bios_is_dsi_present(struct drm_i915_private *i915, 3339df0566a6SJani Nikula enum port *port) 3340df0566a6SJani Nikula { 33413162d057SJani Nikula const struct intel_bios_encoder_data *devdata; 3342df0566a6SJani Nikula 3343a434689cSJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) { 3344d24b3475SVille Syrjälä const struct child_device_config *child = &devdata->child; 3345d24b3475SVille Syrjälä u8 dvo_port = child->dvo_port; 3346df0566a6SJani Nikula 3347df0566a6SJani Nikula if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT)) 3348df0566a6SJani Nikula continue; 3349df0566a6SJani Nikula 3350118b5c13SVille Syrjälä if (dsi_dvo_port_to_port(i915, dvo_port) == PORT_NONE) { 3351dbd440d8SJani Nikula drm_dbg_kms(&i915->drm, 3352e92cbf38SWambui Karuga "VBT has unsupported DSI port %c\n", 3353df0566a6SJani Nikula port_name(dvo_port - DVO_PORT_MIPIA)); 3354118b5c13SVille Syrjälä continue; 3355df0566a6SJani Nikula } 3356118b5c13SVille Syrjälä 3357118b5c13SVille Syrjälä if (port) 3358118b5c13SVille Syrjälä *port = dsi_dvo_port_to_port(i915, dvo_port); 3359118b5c13SVille Syrjälä return true; 3360df0566a6SJani Nikula } 3361df0566a6SJani Nikula 3362df0566a6SJani Nikula return false; 3363df0566a6SJani Nikula } 3364df0566a6SJani Nikula 33651bf2f3bfSJani Nikula static void fill_dsc(struct intel_crtc_state *crtc_state, 33661bf2f3bfSJani Nikula struct dsc_compression_parameters_entry *dsc, 33671bf2f3bfSJani Nikula int dsc_max_bpc) 33681bf2f3bfSJani Nikula { 33691bf2f3bfSJani Nikula struct drm_dsc_config *vdsc_cfg = &crtc_state->dsc.config; 33701bf2f3bfSJani Nikula int bpc = 8; 33711bf2f3bfSJani Nikula 33721bf2f3bfSJani Nikula vdsc_cfg->dsc_version_major = dsc->version_major; 33731bf2f3bfSJani Nikula vdsc_cfg->dsc_version_minor = dsc->version_minor; 33741bf2f3bfSJani Nikula 33751bf2f3bfSJani Nikula if (dsc->support_12bpc && dsc_max_bpc >= 12) 33761bf2f3bfSJani Nikula bpc = 12; 33771bf2f3bfSJani Nikula else if (dsc->support_10bpc && dsc_max_bpc >= 10) 33781bf2f3bfSJani Nikula bpc = 10; 33791bf2f3bfSJani Nikula else if (dsc->support_8bpc && dsc_max_bpc >= 8) 33801bf2f3bfSJani Nikula bpc = 8; 33811bf2f3bfSJani Nikula else 33821bf2f3bfSJani Nikula DRM_DEBUG_KMS("VBT: Unsupported BPC %d for DCS\n", 33831bf2f3bfSJani Nikula dsc_max_bpc); 33841bf2f3bfSJani Nikula 33851bf2f3bfSJani Nikula crtc_state->pipe_bpp = bpc * 3; 33861bf2f3bfSJani Nikula 33871bf2f3bfSJani Nikula crtc_state->dsc.compressed_bpp = min(crtc_state->pipe_bpp, 33881bf2f3bfSJani Nikula VBT_DSC_MAX_BPP(dsc->max_bpp)); 33891bf2f3bfSJani Nikula 33901bf2f3bfSJani Nikula /* 33911bf2f3bfSJani Nikula * FIXME: This is ugly, and slice count should take DSC engine 33921bf2f3bfSJani Nikula * throughput etc. into account. 33931bf2f3bfSJani Nikula * 33941bf2f3bfSJani Nikula * Also, per spec DSI supports 1, 2, 3 or 4 horizontal slices. 33951bf2f3bfSJani Nikula */ 33961bf2f3bfSJani Nikula if (dsc->slices_per_line & BIT(2)) { 33971bf2f3bfSJani Nikula crtc_state->dsc.slice_count = 4; 33981bf2f3bfSJani Nikula } else if (dsc->slices_per_line & BIT(1)) { 33991bf2f3bfSJani Nikula crtc_state->dsc.slice_count = 2; 34001bf2f3bfSJani Nikula } else { 34011bf2f3bfSJani Nikula /* FIXME */ 34021bf2f3bfSJani Nikula if (!(dsc->slices_per_line & BIT(0))) 34031bf2f3bfSJani Nikula DRM_DEBUG_KMS("VBT: Unsupported DSC slice count for DSI\n"); 34041bf2f3bfSJani Nikula 34051bf2f3bfSJani Nikula crtc_state->dsc.slice_count = 1; 34061bf2f3bfSJani Nikula } 34071bf2f3bfSJani Nikula 34081bf2f3bfSJani Nikula if (crtc_state->hw.adjusted_mode.crtc_hdisplay % 34091bf2f3bfSJani Nikula crtc_state->dsc.slice_count != 0) 34101bf2f3bfSJani Nikula DRM_DEBUG_KMS("VBT: DSC hdisplay %d not divisible by slice count %d\n", 34111bf2f3bfSJani Nikula crtc_state->hw.adjusted_mode.crtc_hdisplay, 34121bf2f3bfSJani Nikula crtc_state->dsc.slice_count); 34131bf2f3bfSJani Nikula 34141bf2f3bfSJani Nikula /* 34151bf2f3bfSJani Nikula * The VBT rc_buffer_block_size and rc_buffer_size definitions 3416fd8a5b27SJani Nikula * correspond to DP 1.4 DPCD offsets 0x62 and 0x63. 34171bf2f3bfSJani Nikula */ 3418fd8a5b27SJani Nikula vdsc_cfg->rc_model_size = drm_dsc_dp_rc_buffer_size(dsc->rc_buffer_block_size, 3419fd8a5b27SJani Nikula dsc->rc_buffer_size); 34201bf2f3bfSJani Nikula 34211bf2f3bfSJani Nikula /* FIXME: DSI spec says bpc + 1 for this one */ 34221bf2f3bfSJani Nikula vdsc_cfg->line_buf_depth = VBT_DSC_LINE_BUFFER_DEPTH(dsc->line_buffer_depth); 34231bf2f3bfSJani Nikula 34241bf2f3bfSJani Nikula vdsc_cfg->block_pred_enable = dsc->block_prediction_enable; 34251bf2f3bfSJani Nikula 34261bf2f3bfSJani Nikula vdsc_cfg->slice_height = dsc->slice_height; 34271bf2f3bfSJani Nikula } 34281bf2f3bfSJani Nikula 34291bf2f3bfSJani Nikula /* FIXME: initially DSI specific */ 34301bf2f3bfSJani Nikula bool intel_bios_get_dsc_params(struct intel_encoder *encoder, 34311bf2f3bfSJani Nikula struct intel_crtc_state *crtc_state, 34321bf2f3bfSJani Nikula int dsc_max_bpc) 34331bf2f3bfSJani Nikula { 34341bf2f3bfSJani Nikula struct drm_i915_private *i915 = to_i915(encoder->base.dev); 34353162d057SJani Nikula const struct intel_bios_encoder_data *devdata; 34361bf2f3bfSJani Nikula 3437a434689cSJani Nikula list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) { 3438d24b3475SVille Syrjälä const struct child_device_config *child = &devdata->child; 34391bf2f3bfSJani Nikula 34401bf2f3bfSJani Nikula if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT)) 34411bf2f3bfSJani Nikula continue; 34421bf2f3bfSJani Nikula 3443118b5c13SVille Syrjälä if (dsi_dvo_port_to_port(i915, child->dvo_port) == encoder->port) { 34441bf2f3bfSJani Nikula if (!devdata->dsc) 34451bf2f3bfSJani Nikula return false; 34461bf2f3bfSJani Nikula 34471bf2f3bfSJani Nikula if (crtc_state) 34481bf2f3bfSJani Nikula fill_dsc(crtc_state, devdata->dsc, dsc_max_bpc); 34491bf2f3bfSJani Nikula 34501bf2f3bfSJani Nikula return true; 34511bf2f3bfSJani Nikula } 34521bf2f3bfSJani Nikula } 34531bf2f3bfSJani Nikula 34541bf2f3bfSJani Nikula return false; 34551bf2f3bfSJani Nikula } 34561bf2f3bfSJani Nikula 34575a0fc7a0SVille Syrjälä static const u8 adlp_aux_ch_map[] = { 34585a0fc7a0SVille Syrjälä [AUX_CH_A] = DP_AUX_A, 34595a0fc7a0SVille Syrjälä [AUX_CH_B] = DP_AUX_B, 34605a0fc7a0SVille Syrjälä [AUX_CH_C] = DP_AUX_C, 34615a0fc7a0SVille Syrjälä [AUX_CH_D_XELPD] = DP_AUX_D, 34625a0fc7a0SVille Syrjälä [AUX_CH_E_XELPD] = DP_AUX_E, 34635a0fc7a0SVille Syrjälä [AUX_CH_USBC1] = DP_AUX_F, 34645a0fc7a0SVille Syrjälä [AUX_CH_USBC2] = DP_AUX_G, 34655a0fc7a0SVille Syrjälä [AUX_CH_USBC3] = DP_AUX_H, 34665a0fc7a0SVille Syrjälä [AUX_CH_USBC4] = DP_AUX_I, 34675a0fc7a0SVille Syrjälä }; 34685a0fc7a0SVille Syrjälä 34695a0fc7a0SVille Syrjälä /* 34705a0fc7a0SVille Syrjälä * ADL-S VBT uses PHY based mapping. Combo PHYs A,B,C,D,E 34715a0fc7a0SVille Syrjälä * map to DDI A,TC1,TC2,TC3,TC4 respectively. 34725a0fc7a0SVille Syrjälä */ 34735a0fc7a0SVille Syrjälä static const u8 adls_aux_ch_map[] = { 34745a0fc7a0SVille Syrjälä [AUX_CH_A] = DP_AUX_A, 34755a0fc7a0SVille Syrjälä [AUX_CH_USBC1] = DP_AUX_B, 34765a0fc7a0SVille Syrjälä [AUX_CH_USBC2] = DP_AUX_C, 34775a0fc7a0SVille Syrjälä [AUX_CH_USBC3] = DP_AUX_D, 34785a0fc7a0SVille Syrjälä [AUX_CH_USBC4] = DP_AUX_E, 34795a0fc7a0SVille Syrjälä }; 3480df0566a6SJani Nikula 348118c283dfSAditya Swarup /* 348218c283dfSAditya Swarup * RKL/DG1 VBT uses PHY based mapping. Combo PHYs A,B,C,D 348318c283dfSAditya Swarup * map to DDI A,B,TC1,TC2 respectively. 348418c283dfSAditya Swarup */ 34855a0fc7a0SVille Syrjälä static const u8 rkl_aux_ch_map[] = { 34865a0fc7a0SVille Syrjälä [AUX_CH_A] = DP_AUX_A, 34875a0fc7a0SVille Syrjälä [AUX_CH_B] = DP_AUX_B, 34885a0fc7a0SVille Syrjälä [AUX_CH_USBC1] = DP_AUX_C, 34895a0fc7a0SVille Syrjälä [AUX_CH_USBC2] = DP_AUX_D, 34905a0fc7a0SVille Syrjälä }; 34915a0fc7a0SVille Syrjälä 34925a0fc7a0SVille Syrjälä static const u8 direct_aux_ch_map[] = { 34935a0fc7a0SVille Syrjälä [AUX_CH_A] = DP_AUX_A, 34945a0fc7a0SVille Syrjälä [AUX_CH_B] = DP_AUX_B, 34955a0fc7a0SVille Syrjälä [AUX_CH_C] = DP_AUX_C, 34965a0fc7a0SVille Syrjälä [AUX_CH_D] = DP_AUX_D, /* aka AUX_CH_USBC1 */ 34975a0fc7a0SVille Syrjälä [AUX_CH_E] = DP_AUX_E, /* aka AUX_CH_USBC2 */ 34985a0fc7a0SVille Syrjälä [AUX_CH_F] = DP_AUX_F, /* aka AUX_CH_USBC3 */ 34995a0fc7a0SVille Syrjälä [AUX_CH_G] = DP_AUX_G, /* aka AUX_CH_USBC4 */ 35005a0fc7a0SVille Syrjälä [AUX_CH_H] = DP_AUX_H, /* aka AUX_CH_USBC5 */ 35015a0fc7a0SVille Syrjälä [AUX_CH_I] = DP_AUX_I, /* aka AUX_CH_USBC6 */ 35025a0fc7a0SVille Syrjälä }; 35035a0fc7a0SVille Syrjälä 35045a0fc7a0SVille Syrjälä static enum aux_ch map_aux_ch(struct drm_i915_private *i915, u8 aux_channel) 35055a0fc7a0SVille Syrjälä { 35065a0fc7a0SVille Syrjälä const u8 *aux_ch_map; 35075a0fc7a0SVille Syrjälä int i, n_entries; 35085a0fc7a0SVille Syrjälä 35095a0fc7a0SVille Syrjälä if (DISPLAY_VER(i915) >= 13) { 35105a0fc7a0SVille Syrjälä aux_ch_map = adlp_aux_ch_map; 35115a0fc7a0SVille Syrjälä n_entries = ARRAY_SIZE(adlp_aux_ch_map); 35125a0fc7a0SVille Syrjälä } else if (IS_ALDERLAKE_S(i915)) { 35135a0fc7a0SVille Syrjälä aux_ch_map = adls_aux_ch_map; 35145a0fc7a0SVille Syrjälä n_entries = ARRAY_SIZE(adls_aux_ch_map); 35155a0fc7a0SVille Syrjälä } else if (IS_DG1(i915) || IS_ROCKETLAKE(i915)) { 35165a0fc7a0SVille Syrjälä aux_ch_map = rkl_aux_ch_map; 35175a0fc7a0SVille Syrjälä n_entries = ARRAY_SIZE(rkl_aux_ch_map); 35185a0fc7a0SVille Syrjälä } else { 35195a0fc7a0SVille Syrjälä aux_ch_map = direct_aux_ch_map; 35205a0fc7a0SVille Syrjälä n_entries = ARRAY_SIZE(direct_aux_ch_map); 3521df0566a6SJani Nikula } 3522df0566a6SJani Nikula 35235a0fc7a0SVille Syrjälä for (i = 0; i < n_entries; i++) { 35245a0fc7a0SVille Syrjälä if (aux_ch_map[i] == aux_channel) 35255a0fc7a0SVille Syrjälä return i; 35265a0fc7a0SVille Syrjälä } 35275a0fc7a0SVille Syrjälä 35285a0fc7a0SVille Syrjälä drm_dbg_kms(&i915->drm, 35295a0fc7a0SVille Syrjälä "Ignoring alternate AUX CH: VBT claims AUX 0x%x, which is not valid for this platform\n", 35305a0fc7a0SVille Syrjälä aux_channel); 35315a0fc7a0SVille Syrjälä 35325a0fc7a0SVille Syrjälä return AUX_CH_NONE; 3533df0566a6SJani Nikula } 3534d9ee2111SJani Nikula 3535bb45217fSVille Syrjälä enum aux_ch intel_bios_dp_aux_ch(const struct intel_bios_encoder_data *devdata) 3536bb45217fSVille Syrjälä { 3537bb45217fSVille Syrjälä if (!devdata || !devdata->child.aux_channel) 3538bb45217fSVille Syrjälä return AUX_CH_NONE; 3539bb45217fSVille Syrjälä 3540bb45217fSVille Syrjälä return map_aux_ch(devdata->i915, devdata->child.aux_channel); 3541bb45217fSVille Syrjälä } 3542d9ee2111SJani Nikula 3543*70052100SVille Syrjälä bool intel_bios_dp_has_shared_aux_ch(const struct intel_bios_encoder_data *devdata) 3544*70052100SVille Syrjälä { 3545*70052100SVille Syrjälä struct drm_i915_private *i915; 3546*70052100SVille Syrjälä u8 aux_channel; 3547*70052100SVille Syrjälä int count = 0; 3548*70052100SVille Syrjälä 3549*70052100SVille Syrjälä if (!devdata || !devdata->child.aux_channel) 3550*70052100SVille Syrjälä return false; 3551*70052100SVille Syrjälä 3552*70052100SVille Syrjälä i915 = devdata->i915; 3553*70052100SVille Syrjälä aux_channel = devdata->child.aux_channel; 3554*70052100SVille Syrjälä 3555*70052100SVille Syrjälä list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) { 3556*70052100SVille Syrjälä if (intel_bios_encoder_supports_dp(devdata) && 3557*70052100SVille Syrjälä aux_channel == devdata->child.aux_channel) 3558*70052100SVille Syrjälä count++; 3559*70052100SVille Syrjälä } 3560*70052100SVille Syrjälä 3561*70052100SVille Syrjälä return count > 1; 3562*70052100SVille Syrjälä } 3563*70052100SVille Syrjälä 356402107ef1SVille Syrjälä int intel_bios_dp_boost_level(const struct intel_bios_encoder_data *devdata) 3565605a1872SJani Nikula { 3566a434689cSJani Nikula if (!devdata || devdata->i915->display.vbt.version < 196 || !devdata->child.iboost) 3567c0a950d1SJani Nikula return 0; 3568605a1872SJani Nikula 3569c0a950d1SJani Nikula return translate_iboost(devdata->child.dp_iboost_level); 3570605a1872SJani Nikula } 357101a60883SJani Nikula 357202107ef1SVille Syrjälä int intel_bios_hdmi_boost_level(const struct intel_bios_encoder_data *devdata) 357301a60883SJani Nikula { 3574a434689cSJani Nikula if (!devdata || devdata->i915->display.vbt.version < 196 || !devdata->child.iboost) 3575c0a950d1SJani Nikula return 0; 357601a60883SJani Nikula 3577c0a950d1SJani Nikula return translate_iboost(devdata->child.hdmi_iboost_level); 357801a60883SJani Nikula } 3579f83acdabSJani Nikula 358002107ef1SVille Syrjälä int intel_bios_hdmi_ddc_pin(const struct intel_bios_encoder_data *devdata) 3581f83acdabSJani Nikula { 3582dab8477bSJani Nikula if (!devdata || !devdata->child.ddc_pin) 3583dab8477bSJani Nikula return 0; 3584dab8477bSJani Nikula 358502107ef1SVille Syrjälä return map_ddc_pin(devdata->i915, devdata->child.ddc_pin); 358617004bfbSJani Nikula } 3587c5faae5aSJani Nikula 3588f08fbe6aSJani Nikula bool intel_bios_encoder_supports_typec_usb(const struct intel_bios_encoder_data *devdata) 3589c5faae5aSJani Nikula { 3590a434689cSJani Nikula return devdata->i915->display.vbt.version >= 195 && devdata->child.dp_usb_type_c; 3591c5faae5aSJani Nikula } 3592c5faae5aSJani Nikula 3593f08fbe6aSJani Nikula bool intel_bios_encoder_supports_tbt(const struct intel_bios_encoder_data *devdata) 3594c5faae5aSJani Nikula { 3595a434689cSJani Nikula return devdata->i915->display.vbt.version >= 209 && devdata->child.tbt; 3596c5faae5aSJani Nikula } 359745c0673aSJani Nikula 35985f42196dSVille Syrjälä bool intel_bios_encoder_lane_reversal(const struct intel_bios_encoder_data *devdata) 35995f42196dSVille Syrjälä { 36005f42196dSVille Syrjälä return devdata && devdata->child.lane_reversal; 36015f42196dSVille Syrjälä } 36025f42196dSVille Syrjälä 36039151c85cSVille Syrjälä bool intel_bios_encoder_hpd_invert(const struct intel_bios_encoder_data *devdata) 36049151c85cSVille Syrjälä { 36059151c85cSVille Syrjälä return devdata && devdata->child.hpd_invert; 36069151c85cSVille Syrjälä } 36079151c85cSVille Syrjälä 360845c0673aSJani Nikula const struct intel_bios_encoder_data * 360945c0673aSJani Nikula intel_bios_encoder_data_lookup(struct drm_i915_private *i915, enum port port) 361045c0673aSJani Nikula { 3611021a62a5SVille Syrjälä struct intel_bios_encoder_data *devdata; 3612021a62a5SVille Syrjälä 3613021a62a5SVille Syrjälä list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) { 3614021a62a5SVille Syrjälä if (intel_bios_encoder_port(devdata) == port) 3615021a62a5SVille Syrjälä return devdata; 3616021a62a5SVille Syrjälä } 3617021a62a5SVille Syrjälä 3618021a62a5SVille Syrjälä return NULL; 3619021a62a5SVille Syrjälä } 3620021a62a5SVille Syrjälä 3621021a62a5SVille Syrjälä void intel_bios_for_each_encoder(struct drm_i915_private *i915, 3622021a62a5SVille Syrjälä void (*func)(struct drm_i915_private *i915, 3623021a62a5SVille Syrjälä const struct intel_bios_encoder_data *devdata)) 3624021a62a5SVille Syrjälä { 3625021a62a5SVille Syrjälä struct intel_bios_encoder_data *devdata; 3626021a62a5SVille Syrjälä 3627021a62a5SVille Syrjälä list_for_each_entry(devdata, &i915->display.vbt.display_devices, node) 3628021a62a5SVille Syrjälä func(i915, devdata); 362945c0673aSJani Nikula } 3630