1e3adcf8fSFrançois Tigeot /*
2e3adcf8fSFrançois Tigeot * Copyright © 2006 Intel Corporation
3e3adcf8fSFrançois Tigeot *
4e3adcf8fSFrançois Tigeot * Permission is hereby granted, free of charge, to any person obtaining a
5e3adcf8fSFrançois Tigeot * copy of this software and associated documentation files (the "Software"),
6e3adcf8fSFrançois Tigeot * to deal in the Software without restriction, including without limitation
7e3adcf8fSFrançois Tigeot * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8e3adcf8fSFrançois Tigeot * and/or sell copies of the Software, and to permit persons to whom the
9e3adcf8fSFrançois Tigeot * Software is furnished to do so, subject to the following conditions:
10e3adcf8fSFrançois Tigeot *
11e3adcf8fSFrançois Tigeot * The above copyright notice and this permission notice (including the next
12e3adcf8fSFrançois Tigeot * paragraph) shall be included in all copies or substantial portions of the
13e3adcf8fSFrançois Tigeot * Software.
14e3adcf8fSFrançois Tigeot *
15e3adcf8fSFrançois Tigeot * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16e3adcf8fSFrançois Tigeot * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17e3adcf8fSFrançois Tigeot * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18e3adcf8fSFrançois Tigeot * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19e3adcf8fSFrançois Tigeot * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20e3adcf8fSFrançois Tigeot * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21e3adcf8fSFrançois Tigeot * SOFTWARE.
22e3adcf8fSFrançois Tigeot *
23e3adcf8fSFrançois Tigeot * Authors:
24e3adcf8fSFrançois Tigeot * Eric Anholt <eric@anholt.net>
25e3adcf8fSFrançois Tigeot *
26e3adcf8fSFrançois Tigeot */
27aee94f86SFrançois Tigeot
2818e26a6dSFrançois Tigeot #include <drm/drm_dp_helper.h>
29352ff8bdSFrançois Tigeot #include <drm/drmP.h>
305c6c6f23SFrançois Tigeot #include <drm/i915_drm.h>
31e3adcf8fSFrançois Tigeot #include "i915_drv.h"
328621f407SFrançois Tigeot
338621f407SFrançois Tigeot #define _INTEL_BIOS_PRIVATE
348621f407SFrançois Tigeot #include "intel_vbt_defs.h"
35e3adcf8fSFrançois Tigeot
36c0e85e96SFrançois Tigeot /**
37c0e85e96SFrançois Tigeot * DOC: Video BIOS Table (VBT)
38c0e85e96SFrançois Tigeot *
39c0e85e96SFrançois Tigeot * The Video BIOS Table, or VBT, provides platform and board specific
40c0e85e96SFrançois Tigeot * configuration information to the driver that is not discoverable or available
41c0e85e96SFrançois Tigeot * through other means. The configuration is mostly related to display
42c0e85e96SFrançois Tigeot * hardware. The VBT is available via the ACPI OpRegion or, on older systems, in
43c0e85e96SFrançois Tigeot * the PCI ROM.
44c0e85e96SFrançois Tigeot *
45c0e85e96SFrançois Tigeot * The VBT consists of a VBT Header (defined as &struct vbt_header), a BDB
46c0e85e96SFrançois Tigeot * Header (&struct bdb_header), and a number of BIOS Data Blocks (BDB) that
47c0e85e96SFrançois Tigeot * contain the actual configuration information. The VBT Header, and thus the
48c0e85e96SFrançois Tigeot * VBT, begins with "$VBT" signature. The VBT Header contains the offset of the
49c0e85e96SFrançois Tigeot * BDB Header. The data blocks are concatenated after the BDB Header. The data
50c0e85e96SFrançois Tigeot * blocks have a 1-byte Block ID, 2-byte Block Size, and Block Size bytes of
51c0e85e96SFrançois Tigeot * data. (Block 53, the MIPI Sequence Block is an exception.)
52c0e85e96SFrançois Tigeot *
53c0e85e96SFrançois Tigeot * The driver parses the VBT during load. The relevant information is stored in
54c0e85e96SFrançois Tigeot * driver private data for ease of use, and the actual VBT is not read after
55c0e85e96SFrançois Tigeot * that.
56c0e85e96SFrançois Tigeot */
57c0e85e96SFrançois Tigeot
58e3adcf8fSFrançois Tigeot #define SLAVE_ADDR1 0x70
59e3adcf8fSFrançois Tigeot #define SLAVE_ADDR2 0x72
60e3adcf8fSFrançois Tigeot
61c0e85e96SFrançois Tigeot /* Get BDB block size given a pointer to Block ID. */
_get_blocksize(const u8 * block_base)62c0e85e96SFrançois Tigeot static u32 _get_blocksize(const u8 *block_base)
63c0e85e96SFrançois Tigeot {
64c0e85e96SFrançois Tigeot /* The MIPI Sequence Block v3+ has a separate size field. */
65c0e85e96SFrançois Tigeot if (*block_base == BDB_MIPI_SEQUENCE && *(block_base + 3) >= 3)
66c0e85e96SFrançois Tigeot return *((const u32 *)(block_base + 4));
67c0e85e96SFrançois Tigeot else
68c0e85e96SFrançois Tigeot return *((const u16 *)(block_base + 1));
69c0e85e96SFrançois Tigeot }
70c0e85e96SFrançois Tigeot
71c0e85e96SFrançois Tigeot /* Get BDB block size give a pointer to data after Block ID and Block Size. */
get_blocksize(const void * block_data)72c0e85e96SFrançois Tigeot static u32 get_blocksize(const void *block_data)
73c0e85e96SFrançois Tigeot {
741487f786SFrançois Tigeot return _get_blocksize(block_data - 3);
75c0e85e96SFrançois Tigeot }
76c0e85e96SFrançois Tigeot
7719c468b4SFrançois Tigeot static const void *
find_section(const void * _bdb,int section_id)7819c468b4SFrançois Tigeot find_section(const void *_bdb, int section_id)
79e3adcf8fSFrançois Tigeot {
8019c468b4SFrançois Tigeot const struct bdb_header *bdb = _bdb;
8119c468b4SFrançois Tigeot const u8 *base = _bdb;
82e3adcf8fSFrançois Tigeot int index = 0;
83a05eeebfSFrançois Tigeot u32 total, current_size;
84e3adcf8fSFrançois Tigeot u8 current_id;
85e3adcf8fSFrançois Tigeot
86e3adcf8fSFrançois Tigeot /* skip to first section */
87e3adcf8fSFrançois Tigeot index += bdb->header_size;
88e3adcf8fSFrançois Tigeot total = bdb->bdb_size;
89e3adcf8fSFrançois Tigeot
90e3adcf8fSFrançois Tigeot /* walk the sections looking for section_id */
91ba55f2f5SFrançois Tigeot while (index + 3 < total) {
92e3adcf8fSFrançois Tigeot current_id = *(base + index);
93c0e85e96SFrançois Tigeot current_size = _get_blocksize(base + index);
94c0e85e96SFrançois Tigeot index += 3;
95a05eeebfSFrançois Tigeot
96ba55f2f5SFrançois Tigeot if (index + current_size > total)
97ba55f2f5SFrançois Tigeot return NULL;
98ba55f2f5SFrançois Tigeot
99e3adcf8fSFrançois Tigeot if (current_id == section_id)
100e3adcf8fSFrançois Tigeot return base + index;
101ba55f2f5SFrançois Tigeot
102e3adcf8fSFrançois Tigeot index += current_size;
103e3adcf8fSFrançois Tigeot }
104e3adcf8fSFrançois Tigeot
105e3adcf8fSFrançois Tigeot return NULL;
106e3adcf8fSFrançois Tigeot }
107e3adcf8fSFrançois Tigeot
108e3adcf8fSFrançois Tigeot static void
fill_detail_timing_data(struct drm_display_mode * panel_fixed_mode,const struct lvds_dvo_timing * dvo_timing)109e3adcf8fSFrançois Tigeot fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
110e3adcf8fSFrançois Tigeot const struct lvds_dvo_timing *dvo_timing)
111e3adcf8fSFrançois Tigeot {
112e3adcf8fSFrançois Tigeot panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
113e3adcf8fSFrançois Tigeot dvo_timing->hactive_lo;
114e3adcf8fSFrançois Tigeot panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
115e3adcf8fSFrançois Tigeot ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
116e3adcf8fSFrançois Tigeot panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
117a85cb24fSFrançois Tigeot ((dvo_timing->hsync_pulse_width_hi << 8) |
118a85cb24fSFrançois Tigeot dvo_timing->hsync_pulse_width_lo);
119e3adcf8fSFrançois Tigeot panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
120e3adcf8fSFrançois Tigeot ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
121e3adcf8fSFrançois Tigeot
122e3adcf8fSFrançois Tigeot panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
123e3adcf8fSFrançois Tigeot dvo_timing->vactive_lo;
124e3adcf8fSFrançois Tigeot panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
125a85cb24fSFrançois Tigeot ((dvo_timing->vsync_off_hi << 4) | dvo_timing->vsync_off_lo);
126e3adcf8fSFrançois Tigeot panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
127a85cb24fSFrançois Tigeot ((dvo_timing->vsync_pulse_width_hi << 4) |
128a85cb24fSFrançois Tigeot dvo_timing->vsync_pulse_width_lo);
129e3adcf8fSFrançois Tigeot panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
130e3adcf8fSFrançois Tigeot ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
131e3adcf8fSFrançois Tigeot panel_fixed_mode->clock = dvo_timing->clock * 10;
132e3adcf8fSFrançois Tigeot panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
133e3adcf8fSFrançois Tigeot
134e3adcf8fSFrançois Tigeot if (dvo_timing->hsync_positive)
135e3adcf8fSFrançois Tigeot panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
136e3adcf8fSFrançois Tigeot else
137e3adcf8fSFrançois Tigeot panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
138e3adcf8fSFrançois Tigeot
139e3adcf8fSFrançois Tigeot if (dvo_timing->vsync_positive)
140e3adcf8fSFrançois Tigeot panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
141e3adcf8fSFrançois Tigeot else
142e3adcf8fSFrançois Tigeot panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
143e3adcf8fSFrançois Tigeot
1448621f407SFrançois Tigeot panel_fixed_mode->width_mm = (dvo_timing->himage_hi << 8) |
1458621f407SFrançois Tigeot dvo_timing->himage_lo;
1468621f407SFrançois Tigeot panel_fixed_mode->height_mm = (dvo_timing->vimage_hi << 8) |
1478621f407SFrançois Tigeot dvo_timing->vimage_lo;
1488621f407SFrançois Tigeot
149e3adcf8fSFrançois Tigeot /* Some VBTs have bogus h/vtotal values */
150e3adcf8fSFrançois Tigeot if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
151e3adcf8fSFrançois Tigeot panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
152e3adcf8fSFrançois Tigeot if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
153e3adcf8fSFrançois Tigeot panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
154e3adcf8fSFrançois Tigeot
155e3adcf8fSFrançois Tigeot drm_mode_set_name(panel_fixed_mode);
156e3adcf8fSFrançois Tigeot }
157e3adcf8fSFrançois Tigeot
158e3adcf8fSFrançois Tigeot static const struct lvds_dvo_timing *
get_lvds_dvo_timing(const struct bdb_lvds_lfp_data * lvds_lfp_data,const struct bdb_lvds_lfp_data_ptrs * lvds_lfp_data_ptrs,int index)159e3adcf8fSFrançois Tigeot get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
160e3adcf8fSFrançois Tigeot const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
161e3adcf8fSFrançois Tigeot int index)
162e3adcf8fSFrançois Tigeot {
163e3adcf8fSFrançois Tigeot /*
164e3adcf8fSFrançois Tigeot * the size of fp_timing varies on the different platform.
165e3adcf8fSFrançois Tigeot * So calculate the DVO timing relative offset in LVDS data
166e3adcf8fSFrançois Tigeot * entry to get the DVO timing entry
167e3adcf8fSFrançois Tigeot */
168e3adcf8fSFrançois Tigeot
169e3adcf8fSFrançois Tigeot int lfp_data_size =
170e3adcf8fSFrançois Tigeot lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
171e3adcf8fSFrançois Tigeot lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
172e3adcf8fSFrançois Tigeot int dvo_timing_offset =
173e3adcf8fSFrançois Tigeot lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
174e3adcf8fSFrançois Tigeot lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
1751487f786SFrançois Tigeot char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
176e3adcf8fSFrançois Tigeot
1771487f786SFrançois Tigeot return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
178e3adcf8fSFrançois Tigeot }
179e3adcf8fSFrançois Tigeot
180e3440f96SFrançois Tigeot /* get lvds_fp_timing entry
181e3440f96SFrançois Tigeot * this function may return NULL if the corresponding entry is invalid
182e3440f96SFrançois Tigeot */
183e3440f96SFrançois Tigeot static const struct lvds_fp_timing *
get_lvds_fp_timing(const struct bdb_header * bdb,const struct bdb_lvds_lfp_data * data,const struct bdb_lvds_lfp_data_ptrs * ptrs,int index)184e3440f96SFrançois Tigeot get_lvds_fp_timing(const struct bdb_header *bdb,
185e3440f96SFrançois Tigeot const struct bdb_lvds_lfp_data *data,
186e3440f96SFrançois Tigeot const struct bdb_lvds_lfp_data_ptrs *ptrs,
187e3440f96SFrançois Tigeot int index)
188e3440f96SFrançois Tigeot {
189e3440f96SFrançois Tigeot size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
190e3440f96SFrançois Tigeot u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
191e3440f96SFrançois Tigeot size_t ofs;
192e3440f96SFrançois Tigeot
193e3440f96SFrançois Tigeot if (index >= ARRAY_SIZE(ptrs->ptr))
194e3440f96SFrançois Tigeot return NULL;
195e3440f96SFrançois Tigeot ofs = ptrs->ptr[index].fp_timing_offset;
196e3440f96SFrançois Tigeot if (ofs < data_ofs ||
197e3440f96SFrançois Tigeot ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
198e3440f96SFrançois Tigeot return NULL;
199e3440f96SFrançois Tigeot return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
200e3440f96SFrançois Tigeot }
201e3440f96SFrançois Tigeot
202e3adcf8fSFrançois Tigeot /* Try to find integrated panel data */
203e3adcf8fSFrançois Tigeot static void
parse_lfp_panel_data(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)204e3adcf8fSFrançois Tigeot parse_lfp_panel_data(struct drm_i915_private *dev_priv,
20519c468b4SFrançois Tigeot const struct bdb_header *bdb)
206e3adcf8fSFrançois Tigeot {
207e3adcf8fSFrançois Tigeot const struct bdb_lvds_options *lvds_options;
208e3adcf8fSFrançois Tigeot const struct bdb_lvds_lfp_data *lvds_lfp_data;
209e3adcf8fSFrançois Tigeot const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
210e3adcf8fSFrançois Tigeot const struct lvds_dvo_timing *panel_dvo_timing;
211e3440f96SFrançois Tigeot const struct lvds_fp_timing *fp_timing;
212e3adcf8fSFrançois Tigeot struct drm_display_mode *panel_fixed_mode;
2138621f407SFrançois Tigeot int panel_type;
214a05eeebfSFrançois Tigeot int drrs_mode;
2158621f407SFrançois Tigeot int ret;
216e3adcf8fSFrançois Tigeot
217e3adcf8fSFrançois Tigeot lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
218e3adcf8fSFrançois Tigeot if (!lvds_options)
219e3adcf8fSFrançois Tigeot return;
220e3adcf8fSFrançois Tigeot
2215d0b1887SFrançois Tigeot dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
222e3adcf8fSFrançois Tigeot
2231487f786SFrançois Tigeot ret = intel_opregion_get_panel_type(dev_priv);
2248621f407SFrançois Tigeot if (ret >= 0) {
2258621f407SFrançois Tigeot WARN_ON(ret > 0xf);
2268621f407SFrançois Tigeot panel_type = ret;
2278621f407SFrançois Tigeot DRM_DEBUG_KMS("Panel type: %d (OpRegion)\n", panel_type);
2288621f407SFrançois Tigeot } else {
2298621f407SFrançois Tigeot if (lvds_options->panel_type > 0xf) {
2308621f407SFrançois Tigeot DRM_DEBUG_KMS("Invalid VBT panel type 0x%x\n",
2318621f407SFrançois Tigeot lvds_options->panel_type);
2328621f407SFrançois Tigeot return;
2338621f407SFrançois Tigeot }
234e3adcf8fSFrançois Tigeot panel_type = lvds_options->panel_type;
2358621f407SFrançois Tigeot DRM_DEBUG_KMS("Panel type: %d (VBT)\n", panel_type);
2368621f407SFrançois Tigeot }
2378621f407SFrançois Tigeot
2388621f407SFrançois Tigeot dev_priv->vbt.panel_type = panel_type;
239e3adcf8fSFrançois Tigeot
240ba55f2f5SFrançois Tigeot drrs_mode = (lvds_options->dps_panel_type_bits
241ba55f2f5SFrançois Tigeot >> (panel_type * 2)) & MODE_MASK;
242ba55f2f5SFrançois Tigeot /*
243ba55f2f5SFrançois Tigeot * VBT has static DRRS = 0 and seamless DRRS = 2.
244ba55f2f5SFrançois Tigeot * The below piece of code is required to adjust vbt.drrs_type
245ba55f2f5SFrançois Tigeot * to match the enum drrs_support_type.
246ba55f2f5SFrançois Tigeot */
247ba55f2f5SFrançois Tigeot switch (drrs_mode) {
248ba55f2f5SFrançois Tigeot case 0:
249ba55f2f5SFrançois Tigeot dev_priv->vbt.drrs_type = STATIC_DRRS_SUPPORT;
250ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("DRRS supported mode is static\n");
251ba55f2f5SFrançois Tigeot break;
252ba55f2f5SFrançois Tigeot case 2:
253ba55f2f5SFrançois Tigeot dev_priv->vbt.drrs_type = SEAMLESS_DRRS_SUPPORT;
254ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("DRRS supported mode is seamless\n");
255ba55f2f5SFrançois Tigeot break;
256ba55f2f5SFrançois Tigeot default:
257ba55f2f5SFrançois Tigeot dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
258ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("DRRS not supported (VBT input)\n");
259ba55f2f5SFrançois Tigeot break;
260ba55f2f5SFrançois Tigeot }
261ba55f2f5SFrançois Tigeot
262e3adcf8fSFrançois Tigeot lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
263e3adcf8fSFrançois Tigeot if (!lvds_lfp_data)
264e3adcf8fSFrançois Tigeot return;
265e3adcf8fSFrançois Tigeot
266e3adcf8fSFrançois Tigeot lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
267e3adcf8fSFrançois Tigeot if (!lvds_lfp_data_ptrs)
268e3adcf8fSFrançois Tigeot return;
269e3adcf8fSFrançois Tigeot
2705d0b1887SFrançois Tigeot dev_priv->vbt.lvds_vbt = 1;
271e3adcf8fSFrançois Tigeot
272e3adcf8fSFrançois Tigeot panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
273e3adcf8fSFrançois Tigeot lvds_lfp_data_ptrs,
2748621f407SFrançois Tigeot panel_type);
275e3adcf8fSFrançois Tigeot
276159fc1d7SFrançois Tigeot panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
277e3440f96SFrançois Tigeot if (!panel_fixed_mode)
278e3440f96SFrançois Tigeot return;
279e3adcf8fSFrançois Tigeot
280e3adcf8fSFrançois Tigeot fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
281e3adcf8fSFrançois Tigeot
2825d0b1887SFrançois Tigeot dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
283e3adcf8fSFrançois Tigeot
284e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
285e3adcf8fSFrançois Tigeot drm_mode_debug_printmodeline(panel_fixed_mode);
286e3adcf8fSFrançois Tigeot
287e3440f96SFrançois Tigeot fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
288e3440f96SFrançois Tigeot lvds_lfp_data_ptrs,
2898621f407SFrançois Tigeot panel_type);
290e3440f96SFrançois Tigeot if (fp_timing) {
291e3440f96SFrançois Tigeot /* check the resolution, just to be sure */
292e3440f96SFrançois Tigeot if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
293e3440f96SFrançois Tigeot fp_timing->y_res == panel_fixed_mode->vdisplay) {
2945d0b1887SFrançois Tigeot dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
295e3440f96SFrançois Tigeot DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
2965d0b1887SFrançois Tigeot dev_priv->vbt.bios_lvds_val);
297e3440f96SFrançois Tigeot }
298e3440f96SFrançois Tigeot }
299e3adcf8fSFrançois Tigeot }
300e3adcf8fSFrançois Tigeot
3019edbd4a0SFrançois Tigeot static void
parse_lfp_backlight(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)30219c468b4SFrançois Tigeot parse_lfp_backlight(struct drm_i915_private *dev_priv,
30319c468b4SFrançois Tigeot const struct bdb_header *bdb)
3049edbd4a0SFrançois Tigeot {
3059edbd4a0SFrançois Tigeot const struct bdb_lfp_backlight_data *backlight_data;
3069edbd4a0SFrançois Tigeot const struct bdb_lfp_backlight_data_entry *entry;
3078621f407SFrançois Tigeot int panel_type = dev_priv->vbt.panel_type;
3089edbd4a0SFrançois Tigeot
3099edbd4a0SFrançois Tigeot backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
3109edbd4a0SFrançois Tigeot if (!backlight_data)
3119edbd4a0SFrançois Tigeot return;
3129edbd4a0SFrançois Tigeot
3139edbd4a0SFrançois Tigeot if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
3149edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("Unsupported backlight data entry size %u\n",
3159edbd4a0SFrançois Tigeot backlight_data->entry_size);
3169edbd4a0SFrançois Tigeot return;
3179edbd4a0SFrançois Tigeot }
3189edbd4a0SFrançois Tigeot
3199edbd4a0SFrançois Tigeot entry = &backlight_data->data[panel_type];
3209edbd4a0SFrançois Tigeot
321ba55f2f5SFrançois Tigeot dev_priv->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
322ba55f2f5SFrançois Tigeot if (!dev_priv->vbt.backlight.present) {
323ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("PWM backlight not present in VBT (type %u)\n",
324ba55f2f5SFrançois Tigeot entry->type);
325ba55f2f5SFrançois Tigeot return;
326ba55f2f5SFrançois Tigeot }
327ba55f2f5SFrançois Tigeot
3281487f786SFrançois Tigeot dev_priv->vbt.backlight.type = INTEL_BACKLIGHT_DISPLAY_DDI;
3291487f786SFrançois Tigeot if (bdb->version >= 191 &&
3301487f786SFrançois Tigeot get_blocksize(backlight_data) >= sizeof(*backlight_data)) {
3311487f786SFrançois Tigeot const struct bdb_lfp_backlight_control_method *method;
3321487f786SFrançois Tigeot
3331487f786SFrançois Tigeot method = &backlight_data->backlight_control[panel_type];
3341487f786SFrançois Tigeot dev_priv->vbt.backlight.type = method->type;
335a85cb24fSFrançois Tigeot dev_priv->vbt.backlight.controller = method->controller;
3361487f786SFrançois Tigeot }
3371487f786SFrançois Tigeot
3389edbd4a0SFrançois Tigeot dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
3399edbd4a0SFrançois Tigeot dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
34024edb884SFrançois Tigeot dev_priv->vbt.backlight.min_brightness = entry->min_brightness;
3419edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
342a85cb24fSFrançois Tigeot "active %s, min brightness %u, level %u, controller %u\n",
3439edbd4a0SFrançois Tigeot dev_priv->vbt.backlight.pwm_freq_hz,
3449edbd4a0SFrançois Tigeot dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
34524edb884SFrançois Tigeot dev_priv->vbt.backlight.min_brightness,
346a85cb24fSFrançois Tigeot backlight_data->level[panel_type],
347a85cb24fSFrançois Tigeot dev_priv->vbt.backlight.controller);
3489edbd4a0SFrançois Tigeot }
3499edbd4a0SFrançois Tigeot
350e3adcf8fSFrançois Tigeot /* Try to find sdvo panel data */
351e3adcf8fSFrançois Tigeot static void
parse_sdvo_panel_data(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)352e3adcf8fSFrançois Tigeot parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
35319c468b4SFrançois Tigeot const struct bdb_header *bdb)
354e3adcf8fSFrançois Tigeot {
35519c468b4SFrançois Tigeot const struct lvds_dvo_timing *dvo_timing;
356e3adcf8fSFrançois Tigeot struct drm_display_mode *panel_fixed_mode;
357e3adcf8fSFrançois Tigeot int index;
358e3adcf8fSFrançois Tigeot
359*3f2dd94aSFrançois Tigeot index = i915_modparams.vbt_sdvo_panel_type;
360e3440f96SFrançois Tigeot if (index == -2) {
361e3440f96SFrançois Tigeot DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
362e3440f96SFrançois Tigeot return;
363e3440f96SFrançois Tigeot }
364e3440f96SFrançois Tigeot
365e3adcf8fSFrançois Tigeot if (index == -1) {
36619c468b4SFrançois Tigeot const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
367e3adcf8fSFrançois Tigeot
368e3adcf8fSFrançois Tigeot sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
369e3adcf8fSFrançois Tigeot if (!sdvo_lvds_options)
370e3adcf8fSFrançois Tigeot return;
371e3adcf8fSFrançois Tigeot
372e3adcf8fSFrançois Tigeot index = sdvo_lvds_options->panel_type;
373e3adcf8fSFrançois Tigeot }
374e3adcf8fSFrançois Tigeot
375e3adcf8fSFrançois Tigeot dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
376e3adcf8fSFrançois Tigeot if (!dvo_timing)
377e3adcf8fSFrançois Tigeot return;
378e3adcf8fSFrançois Tigeot
379159fc1d7SFrançois Tigeot panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
380e3440f96SFrançois Tigeot if (!panel_fixed_mode)
381e3440f96SFrançois Tigeot return;
382e3adcf8fSFrançois Tigeot
383e3adcf8fSFrançois Tigeot fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
384e3adcf8fSFrançois Tigeot
3855d0b1887SFrançois Tigeot dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
386e3adcf8fSFrançois Tigeot
387e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
388e3adcf8fSFrançois Tigeot drm_mode_debug_printmodeline(panel_fixed_mode);
389e3adcf8fSFrançois Tigeot }
390e3adcf8fSFrançois Tigeot
intel_bios_ssc_frequency(struct drm_i915_private * dev_priv,bool alternate)391aee94f86SFrançois Tigeot static int intel_bios_ssc_frequency(struct drm_i915_private *dev_priv,
392e3adcf8fSFrançois Tigeot bool alternate)
393e3adcf8fSFrançois Tigeot {
394aee94f86SFrançois Tigeot switch (INTEL_INFO(dev_priv)->gen) {
395e3adcf8fSFrançois Tigeot case 2:
3969edbd4a0SFrançois Tigeot return alternate ? 66667 : 48000;
397e3adcf8fSFrançois Tigeot case 3:
398e3adcf8fSFrançois Tigeot case 4:
3999edbd4a0SFrançois Tigeot return alternate ? 100000 : 96000;
400e3adcf8fSFrançois Tigeot default:
4019edbd4a0SFrançois Tigeot return alternate ? 100000 : 120000;
402e3adcf8fSFrançois Tigeot }
403e3adcf8fSFrançois Tigeot }
404e3adcf8fSFrançois Tigeot
405e3adcf8fSFrançois Tigeot static void
parse_general_features(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)406e3adcf8fSFrançois Tigeot parse_general_features(struct drm_i915_private *dev_priv,
40719c468b4SFrançois Tigeot const struct bdb_header *bdb)
408e3adcf8fSFrançois Tigeot {
40919c468b4SFrançois Tigeot const struct bdb_general_features *general;
410e3adcf8fSFrançois Tigeot
411e3adcf8fSFrançois Tigeot general = find_section(bdb, BDB_GENERAL_FEATURES);
412aee94f86SFrançois Tigeot if (!general)
413aee94f86SFrançois Tigeot return;
414aee94f86SFrançois Tigeot
4155d0b1887SFrançois Tigeot dev_priv->vbt.int_tv_support = general->int_tv_support;
416aee94f86SFrançois Tigeot /* int_crt_support can't be trusted on earlier platforms */
417aee94f86SFrançois Tigeot if (bdb->version >= 155 &&
418aee94f86SFrançois Tigeot (HAS_DDI(dev_priv) || IS_VALLEYVIEW(dev_priv)))
4195d0b1887SFrançois Tigeot dev_priv->vbt.int_crt_support = general->int_crt_support;
4205d0b1887SFrançois Tigeot dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
4215d0b1887SFrançois Tigeot dev_priv->vbt.lvds_ssc_freq =
422aee94f86SFrançois Tigeot intel_bios_ssc_frequency(dev_priv, general->ssc_freq);
4235d0b1887SFrançois Tigeot dev_priv->vbt.display_clock_mode = general->display_clock_mode;
4245d0b1887SFrançois Tigeot dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
425c0bdd5d9SFrançois Tigeot DRM_DEBUG_KMS("BDB_GENERAL_FEATURES int_tv_support %d int_crt_support %d lvds_use_ssc %d lvds_ssc_freq %d display_clock_mode %d fdi_rx_polarity_inverted %d\n",
4265d0b1887SFrançois Tigeot dev_priv->vbt.int_tv_support,
4275d0b1887SFrançois Tigeot dev_priv->vbt.int_crt_support,
4285d0b1887SFrançois Tigeot dev_priv->vbt.lvds_use_ssc,
4295d0b1887SFrançois Tigeot dev_priv->vbt.lvds_ssc_freq,
4305d0b1887SFrançois Tigeot dev_priv->vbt.display_clock_mode,
4315d0b1887SFrançois Tigeot dev_priv->vbt.fdi_rx_polarity_inverted);
432e3adcf8fSFrançois Tigeot }
433e3adcf8fSFrançois Tigeot
434*3f2dd94aSFrançois Tigeot static const struct child_device_config *
child_device_ptr(const struct bdb_general_definitions * defs,int i)435*3f2dd94aSFrançois Tigeot child_device_ptr(const struct bdb_general_definitions *defs, int i)
436e3adcf8fSFrançois Tigeot {
437*3f2dd94aSFrançois Tigeot return (const void *) &defs->devices[i * defs->child_dev_size];
43819c468b4SFrançois Tigeot }
43919c468b4SFrançois Tigeot
440e3adcf8fSFrançois Tigeot static void
parse_sdvo_device_mapping(struct drm_i915_private * dev_priv,u8 bdb_version)441*3f2dd94aSFrançois Tigeot parse_sdvo_device_mapping(struct drm_i915_private *dev_priv, u8 bdb_version)
442e3adcf8fSFrançois Tigeot {
443*3f2dd94aSFrançois Tigeot struct sdvo_device_mapping *mapping;
444*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
445*3f2dd94aSFrançois Tigeot int i, count = 0;
446a05eeebfSFrançois Tigeot
447a05eeebfSFrançois Tigeot /*
448*3f2dd94aSFrançois Tigeot * Only parse SDVO mappings on gens that could have SDVO. This isn't
449*3f2dd94aSFrançois Tigeot * accurate and doesn't have to be, as long as it's not too strict.
450e3adcf8fSFrançois Tigeot */
451*3f2dd94aSFrançois Tigeot if (!IS_GEN(dev_priv, 3, 7)) {
452*3f2dd94aSFrançois Tigeot DRM_DEBUG_KMS("Skipping SDVO device mapping\n");
453e3adcf8fSFrançois Tigeot return;
454e3adcf8fSFrançois Tigeot }
455*3f2dd94aSFrançois Tigeot
456*3f2dd94aSFrançois Tigeot for (i = 0, count = 0; i < dev_priv->vbt.child_dev_num; i++) {
457*3f2dd94aSFrançois Tigeot child = dev_priv->vbt.child_dev + i;
458*3f2dd94aSFrançois Tigeot
459a05eeebfSFrançois Tigeot if (child->slave_addr != SLAVE_ADDR1 &&
460a05eeebfSFrançois Tigeot child->slave_addr != SLAVE_ADDR2) {
461e3adcf8fSFrançois Tigeot /*
462e3adcf8fSFrançois Tigeot * If the slave address is neither 0x70 nor 0x72,
463e3adcf8fSFrançois Tigeot * it is not a SDVO device. Skip it.
464e3adcf8fSFrançois Tigeot */
465e3adcf8fSFrançois Tigeot continue;
466e3adcf8fSFrançois Tigeot }
467a05eeebfSFrançois Tigeot if (child->dvo_port != DEVICE_PORT_DVOB &&
468a05eeebfSFrançois Tigeot child->dvo_port != DEVICE_PORT_DVOC) {
469e3adcf8fSFrançois Tigeot /* skip the incorrect SDVO port */
470e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
471e3adcf8fSFrançois Tigeot continue;
472e3adcf8fSFrançois Tigeot }
473e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
474e3adcf8fSFrançois Tigeot " %s port\n",
475a05eeebfSFrançois Tigeot child->slave_addr,
476a05eeebfSFrançois Tigeot (child->dvo_port == DEVICE_PORT_DVOB) ?
477e3adcf8fSFrançois Tigeot "SDVOB" : "SDVOC");
478*3f2dd94aSFrançois Tigeot mapping = &dev_priv->vbt.sdvo_mappings[child->dvo_port - 1];
479*3f2dd94aSFrançois Tigeot if (!mapping->initialized) {
480*3f2dd94aSFrançois Tigeot mapping->dvo_port = child->dvo_port;
481*3f2dd94aSFrançois Tigeot mapping->slave_addr = child->slave_addr;
482*3f2dd94aSFrançois Tigeot mapping->dvo_wiring = child->dvo_wiring;
483*3f2dd94aSFrançois Tigeot mapping->ddc_pin = child->ddc_pin;
484*3f2dd94aSFrançois Tigeot mapping->i2c_pin = child->i2c_pin;
485*3f2dd94aSFrançois Tigeot mapping->initialized = 1;
486e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
487*3f2dd94aSFrançois Tigeot mapping->dvo_port,
488*3f2dd94aSFrançois Tigeot mapping->slave_addr,
489*3f2dd94aSFrançois Tigeot mapping->dvo_wiring,
490*3f2dd94aSFrançois Tigeot mapping->ddc_pin,
491*3f2dd94aSFrançois Tigeot mapping->i2c_pin);
492e3adcf8fSFrançois Tigeot } else {
493e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
494e3adcf8fSFrançois Tigeot "two SDVO device.\n");
495e3adcf8fSFrançois Tigeot }
496a05eeebfSFrançois Tigeot if (child->slave2_addr) {
497e3adcf8fSFrançois Tigeot /* Maybe this is a SDVO device with multiple inputs */
498e3adcf8fSFrançois Tigeot /* And the mapping info is not added */
499e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
500e3adcf8fSFrançois Tigeot " is a SDVO device with multiple inputs.\n");
501e3adcf8fSFrançois Tigeot }
502e3adcf8fSFrançois Tigeot count++;
503e3adcf8fSFrançois Tigeot }
504e3adcf8fSFrançois Tigeot
505e3adcf8fSFrançois Tigeot if (!count) {
506e3adcf8fSFrançois Tigeot /* No SDVO device info is found */
507e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
508e3adcf8fSFrançois Tigeot }
509e3adcf8fSFrançois Tigeot }
510e3adcf8fSFrançois Tigeot
511e3adcf8fSFrançois Tigeot static void
parse_driver_features(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)512e3adcf8fSFrançois Tigeot parse_driver_features(struct drm_i915_private *dev_priv,
51319c468b4SFrançois Tigeot const struct bdb_header *bdb)
514e3adcf8fSFrançois Tigeot {
51519c468b4SFrançois Tigeot const struct bdb_driver_features *driver;
516e3adcf8fSFrançois Tigeot
517e3adcf8fSFrançois Tigeot driver = find_section(bdb, BDB_DRIVER_FEATURES);
518e3adcf8fSFrançois Tigeot if (!driver)
519e3adcf8fSFrançois Tigeot return;
520e3adcf8fSFrançois Tigeot
5219edbd4a0SFrançois Tigeot if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
5228621f407SFrançois Tigeot dev_priv->vbt.edp.support = 1;
523ba55f2f5SFrançois Tigeot
524ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
525ba55f2f5SFrançois Tigeot /*
526ba55f2f5SFrançois Tigeot * If DRRS is not supported, drrs_type has to be set to 0.
527ba55f2f5SFrançois Tigeot * This is because, VBT is configured in such a way that
528ba55f2f5SFrançois Tigeot * static DRRS is 0 and DRRS not supported is represented by
529ba55f2f5SFrançois Tigeot * driver->drrs_enabled=false
530ba55f2f5SFrançois Tigeot */
531ba55f2f5SFrançois Tigeot if (!driver->drrs_enabled)
532ba55f2f5SFrançois Tigeot dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
533e3adcf8fSFrançois Tigeot }
534e3adcf8fSFrançois Tigeot
535e3adcf8fSFrançois Tigeot static void
parse_edp(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)53619c468b4SFrançois Tigeot parse_edp(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
537e3adcf8fSFrançois Tigeot {
53819c468b4SFrançois Tigeot const struct bdb_edp *edp;
53919c468b4SFrançois Tigeot const struct edp_power_seq *edp_pps;
540*3f2dd94aSFrançois Tigeot const struct edp_fast_link_params *edp_link_params;
5418621f407SFrançois Tigeot int panel_type = dev_priv->vbt.panel_type;
542e3adcf8fSFrançois Tigeot
543e3adcf8fSFrançois Tigeot edp = find_section(bdb, BDB_EDP);
544e3adcf8fSFrançois Tigeot if (!edp) {
5458621f407SFrançois Tigeot if (dev_priv->vbt.edp.support)
54619df918dSFrançois Tigeot DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
547e3adcf8fSFrançois Tigeot return;
548e3adcf8fSFrançois Tigeot }
549e3adcf8fSFrançois Tigeot
550e3adcf8fSFrançois Tigeot switch ((edp->color_depth >> (panel_type * 2)) & 3) {
551e3adcf8fSFrançois Tigeot case EDP_18BPP:
5528621f407SFrançois Tigeot dev_priv->vbt.edp.bpp = 18;
553e3adcf8fSFrançois Tigeot break;
554e3adcf8fSFrançois Tigeot case EDP_24BPP:
5558621f407SFrançois Tigeot dev_priv->vbt.edp.bpp = 24;
556e3adcf8fSFrançois Tigeot break;
557e3adcf8fSFrançois Tigeot case EDP_30BPP:
5588621f407SFrançois Tigeot dev_priv->vbt.edp.bpp = 30;
559e3adcf8fSFrançois Tigeot break;
560e3adcf8fSFrançois Tigeot }
561e3adcf8fSFrançois Tigeot
562e3adcf8fSFrançois Tigeot /* Get the eDP sequencing and link info */
563e3adcf8fSFrançois Tigeot edp_pps = &edp->power_seqs[panel_type];
564*3f2dd94aSFrançois Tigeot edp_link_params = &edp->fast_link_params[panel_type];
565e3adcf8fSFrançois Tigeot
5668621f407SFrançois Tigeot dev_priv->vbt.edp.pps = *edp_pps;
567e3adcf8fSFrançois Tigeot
568ba55f2f5SFrançois Tigeot switch (edp_link_params->rate) {
569ba55f2f5SFrançois Tigeot case EDP_RATE_1_62:
5708621f407SFrançois Tigeot dev_priv->vbt.edp.rate = DP_LINK_BW_1_62;
571ba55f2f5SFrançois Tigeot break;
572ba55f2f5SFrançois Tigeot case EDP_RATE_2_7:
5738621f407SFrançois Tigeot dev_priv->vbt.edp.rate = DP_LINK_BW_2_7;
574ba55f2f5SFrançois Tigeot break;
575ba55f2f5SFrançois Tigeot default:
576ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
577ba55f2f5SFrançois Tigeot edp_link_params->rate);
578ba55f2f5SFrançois Tigeot break;
579ba55f2f5SFrançois Tigeot }
580ba55f2f5SFrançois Tigeot
581e3adcf8fSFrançois Tigeot switch (edp_link_params->lanes) {
582ba55f2f5SFrançois Tigeot case EDP_LANE_1:
5838621f407SFrançois Tigeot dev_priv->vbt.edp.lanes = 1;
584e3adcf8fSFrançois Tigeot break;
585ba55f2f5SFrançois Tigeot case EDP_LANE_2:
5868621f407SFrançois Tigeot dev_priv->vbt.edp.lanes = 2;
587e3adcf8fSFrançois Tigeot break;
588ba55f2f5SFrançois Tigeot case EDP_LANE_4:
5898621f407SFrançois Tigeot dev_priv->vbt.edp.lanes = 4;
590e3adcf8fSFrançois Tigeot break;
591ba55f2f5SFrançois Tigeot default:
592ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
593ba55f2f5SFrançois Tigeot edp_link_params->lanes);
594ba55f2f5SFrançois Tigeot break;
595e3adcf8fSFrançois Tigeot }
596ba55f2f5SFrançois Tigeot
597e3adcf8fSFrançois Tigeot switch (edp_link_params->preemphasis) {
598ba55f2f5SFrançois Tigeot case EDP_PREEMPHASIS_NONE:
5998621f407SFrançois Tigeot dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
600e3adcf8fSFrançois Tigeot break;
601ba55f2f5SFrançois Tigeot case EDP_PREEMPHASIS_3_5dB:
6028621f407SFrançois Tigeot dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
603e3adcf8fSFrançois Tigeot break;
604ba55f2f5SFrançois Tigeot case EDP_PREEMPHASIS_6dB:
6058621f407SFrançois Tigeot dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
606e3adcf8fSFrançois Tigeot break;
607ba55f2f5SFrançois Tigeot case EDP_PREEMPHASIS_9_5dB:
6088621f407SFrançois Tigeot dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
609e3adcf8fSFrançois Tigeot break;
610ba55f2f5SFrançois Tigeot default:
611ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
612ba55f2f5SFrançois Tigeot edp_link_params->preemphasis);
613ba55f2f5SFrançois Tigeot break;
614e3adcf8fSFrançois Tigeot }
615ba55f2f5SFrançois Tigeot
616e3adcf8fSFrançois Tigeot switch (edp_link_params->vswing) {
617ba55f2f5SFrançois Tigeot case EDP_VSWING_0_4V:
6188621f407SFrançois Tigeot dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
619e3adcf8fSFrançois Tigeot break;
620ba55f2f5SFrançois Tigeot case EDP_VSWING_0_6V:
6218621f407SFrançois Tigeot dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
622e3adcf8fSFrançois Tigeot break;
623ba55f2f5SFrançois Tigeot case EDP_VSWING_0_8V:
6248621f407SFrançois Tigeot dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
625e3adcf8fSFrançois Tigeot break;
626ba55f2f5SFrançois Tigeot case EDP_VSWING_1_2V:
6278621f407SFrançois Tigeot dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
628e3adcf8fSFrançois Tigeot break;
629ba55f2f5SFrançois Tigeot default:
630ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
631ba55f2f5SFrançois Tigeot edp_link_params->vswing);
632ba55f2f5SFrançois Tigeot break;
633e3adcf8fSFrançois Tigeot }
634477eb7f9SFrançois Tigeot
635477eb7f9SFrançois Tigeot if (bdb->version >= 173) {
636477eb7f9SFrançois Tigeot uint8_t vswing;
637477eb7f9SFrançois Tigeot
63819c468b4SFrançois Tigeot /* Don't read from VBT if module parameter has valid value*/
639*3f2dd94aSFrançois Tigeot if (i915_modparams.edp_vswing) {
640*3f2dd94aSFrançois Tigeot dev_priv->vbt.edp.low_vswing =
641*3f2dd94aSFrançois Tigeot i915_modparams.edp_vswing == 1;
64219c468b4SFrançois Tigeot } else {
643477eb7f9SFrançois Tigeot vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
6448621f407SFrançois Tigeot dev_priv->vbt.edp.low_vswing = vswing == 0;
64519c468b4SFrançois Tigeot }
646477eb7f9SFrançois Tigeot }
647e3adcf8fSFrançois Tigeot }
648e3adcf8fSFrançois Tigeot
6492c9916cdSFrançois Tigeot static void
parse_psr(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)65019c468b4SFrançois Tigeot parse_psr(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
6512c9916cdSFrançois Tigeot {
65219c468b4SFrançois Tigeot const struct bdb_psr *psr;
65319c468b4SFrançois Tigeot const struct psr_table *psr_table;
6548621f407SFrançois Tigeot int panel_type = dev_priv->vbt.panel_type;
6552c9916cdSFrançois Tigeot
6562c9916cdSFrançois Tigeot psr = find_section(bdb, BDB_PSR);
6572c9916cdSFrançois Tigeot if (!psr) {
6582c9916cdSFrançois Tigeot DRM_DEBUG_KMS("No PSR BDB found.\n");
6592c9916cdSFrançois Tigeot return;
6602c9916cdSFrançois Tigeot }
6612c9916cdSFrançois Tigeot
6622c9916cdSFrançois Tigeot psr_table = &psr->psr_table[panel_type];
6632c9916cdSFrançois Tigeot
6642c9916cdSFrançois Tigeot dev_priv->vbt.psr.full_link = psr_table->full_link;
6652c9916cdSFrançois Tigeot dev_priv->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
6662c9916cdSFrançois Tigeot
6672c9916cdSFrançois Tigeot /* Allowed VBT values goes from 0 to 15 */
6682c9916cdSFrançois Tigeot dev_priv->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
6692c9916cdSFrançois Tigeot psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
6702c9916cdSFrançois Tigeot
6712c9916cdSFrançois Tigeot switch (psr_table->lines_to_wait) {
6722c9916cdSFrançois Tigeot case 0:
6732c9916cdSFrançois Tigeot dev_priv->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
6742c9916cdSFrançois Tigeot break;
6752c9916cdSFrançois Tigeot case 1:
6762c9916cdSFrançois Tigeot dev_priv->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
6772c9916cdSFrançois Tigeot break;
6782c9916cdSFrançois Tigeot case 2:
6792c9916cdSFrançois Tigeot dev_priv->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
6802c9916cdSFrançois Tigeot break;
6812c9916cdSFrançois Tigeot case 3:
6822c9916cdSFrançois Tigeot dev_priv->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
6832c9916cdSFrançois Tigeot break;
6842c9916cdSFrançois Tigeot default:
6852c9916cdSFrançois Tigeot DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
6862c9916cdSFrançois Tigeot psr_table->lines_to_wait);
6872c9916cdSFrançois Tigeot break;
6882c9916cdSFrançois Tigeot }
6892c9916cdSFrançois Tigeot
6902c9916cdSFrançois Tigeot dev_priv->vbt.psr.tp1_wakeup_time = psr_table->tp1_wakeup_time;
6912c9916cdSFrançois Tigeot dev_priv->vbt.psr.tp2_tp3_wakeup_time = psr_table->tp2_tp3_wakeup_time;
6922c9916cdSFrançois Tigeot }
6932c9916cdSFrançois Tigeot
parse_dsi_backlight_ports(struct drm_i915_private * dev_priv,u16 version,enum port port)694*3f2dd94aSFrançois Tigeot static void parse_dsi_backlight_ports(struct drm_i915_private *dev_priv,
695*3f2dd94aSFrançois Tigeot u16 version, enum port port)
696*3f2dd94aSFrançois Tigeot {
697*3f2dd94aSFrançois Tigeot if (!dev_priv->vbt.dsi.config->dual_link || version < 197) {
698*3f2dd94aSFrançois Tigeot dev_priv->vbt.dsi.bl_ports = BIT(port);
699*3f2dd94aSFrançois Tigeot if (dev_priv->vbt.dsi.config->cabc_supported)
700*3f2dd94aSFrançois Tigeot dev_priv->vbt.dsi.cabc_ports = BIT(port);
701*3f2dd94aSFrançois Tigeot
702*3f2dd94aSFrançois Tigeot return;
703*3f2dd94aSFrançois Tigeot }
704*3f2dd94aSFrançois Tigeot
705*3f2dd94aSFrançois Tigeot switch (dev_priv->vbt.dsi.config->dl_dcs_backlight_ports) {
706*3f2dd94aSFrançois Tigeot case DL_DCS_PORT_A:
707*3f2dd94aSFrançois Tigeot dev_priv->vbt.dsi.bl_ports = BIT(PORT_A);
708*3f2dd94aSFrançois Tigeot break;
709*3f2dd94aSFrançois Tigeot case DL_DCS_PORT_C:
710*3f2dd94aSFrançois Tigeot dev_priv->vbt.dsi.bl_ports = BIT(PORT_C);
711*3f2dd94aSFrançois Tigeot break;
712*3f2dd94aSFrançois Tigeot default:
713*3f2dd94aSFrançois Tigeot case DL_DCS_PORT_A_AND_C:
714*3f2dd94aSFrançois Tigeot dev_priv->vbt.dsi.bl_ports = BIT(PORT_A) | BIT(PORT_C);
715*3f2dd94aSFrançois Tigeot break;
716*3f2dd94aSFrançois Tigeot }
717*3f2dd94aSFrançois Tigeot
718*3f2dd94aSFrançois Tigeot if (!dev_priv->vbt.dsi.config->cabc_supported)
719*3f2dd94aSFrançois Tigeot return;
720*3f2dd94aSFrançois Tigeot
721*3f2dd94aSFrançois Tigeot switch (dev_priv->vbt.dsi.config->dl_dcs_cabc_ports) {
722*3f2dd94aSFrançois Tigeot case DL_DCS_PORT_A:
723*3f2dd94aSFrançois Tigeot dev_priv->vbt.dsi.cabc_ports = BIT(PORT_A);
724*3f2dd94aSFrançois Tigeot break;
725*3f2dd94aSFrançois Tigeot case DL_DCS_PORT_C:
726*3f2dd94aSFrançois Tigeot dev_priv->vbt.dsi.cabc_ports = BIT(PORT_C);
727*3f2dd94aSFrançois Tigeot break;
728*3f2dd94aSFrançois Tigeot default:
729*3f2dd94aSFrançois Tigeot case DL_DCS_PORT_A_AND_C:
730*3f2dd94aSFrançois Tigeot dev_priv->vbt.dsi.cabc_ports =
731*3f2dd94aSFrançois Tigeot BIT(PORT_A) | BIT(PORT_C);
732*3f2dd94aSFrançois Tigeot break;
733*3f2dd94aSFrançois Tigeot }
734*3f2dd94aSFrançois Tigeot }
735*3f2dd94aSFrançois Tigeot
736e3adcf8fSFrançois Tigeot static void
parse_mipi_config(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)737c0e85e96SFrançois Tigeot parse_mipi_config(struct drm_i915_private *dev_priv,
738c0e85e96SFrançois Tigeot const struct bdb_header *bdb)
7399edbd4a0SFrançois Tigeot {
74019c468b4SFrançois Tigeot const struct bdb_mipi_config *start;
74119c468b4SFrançois Tigeot const struct mipi_config *config;
74219c468b4SFrançois Tigeot const struct mipi_pps_data *pps;
7438621f407SFrançois Tigeot int panel_type = dev_priv->vbt.panel_type;
744*3f2dd94aSFrançois Tigeot enum port port;
7459edbd4a0SFrançois Tigeot
746ba55f2f5SFrançois Tigeot /* parse MIPI blocks only if LFP type is MIPI */
747*3f2dd94aSFrançois Tigeot if (!intel_bios_is_dsi_present(dev_priv, &port))
748ba55f2f5SFrançois Tigeot return;
749ba55f2f5SFrançois Tigeot
750ba55f2f5SFrançois Tigeot /* Initialize this to undefined indicating no generic MIPI support */
751ba55f2f5SFrançois Tigeot dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
752ba55f2f5SFrançois Tigeot
753ba55f2f5SFrançois Tigeot /* Block #40 is already parsed and panel_fixed_mode is
754ba55f2f5SFrançois Tigeot * stored in dev_priv->lfp_lvds_vbt_mode
755ba55f2f5SFrançois Tigeot * resuse this when needed
756ba55f2f5SFrançois Tigeot */
757ba55f2f5SFrançois Tigeot
758ba55f2f5SFrançois Tigeot /* Parse #52 for panel index used from panel_type already
759ba55f2f5SFrançois Tigeot * parsed
760ba55f2f5SFrançois Tigeot */
761ba55f2f5SFrançois Tigeot start = find_section(bdb, BDB_MIPI_CONFIG);
762ba55f2f5SFrançois Tigeot if (!start) {
763ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("No MIPI config BDB found");
7649edbd4a0SFrançois Tigeot return;
7659edbd4a0SFrançois Tigeot }
7669edbd4a0SFrançois Tigeot
767ba55f2f5SFrançois Tigeot DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
768ba55f2f5SFrançois Tigeot panel_type);
769ba55f2f5SFrançois Tigeot
770ba55f2f5SFrançois Tigeot /*
771ba55f2f5SFrançois Tigeot * get hold of the correct configuration block and pps data as per
772ba55f2f5SFrançois Tigeot * the panel_type as index
773ba55f2f5SFrançois Tigeot */
774ba55f2f5SFrançois Tigeot config = &start->config[panel_type];
775ba55f2f5SFrançois Tigeot pps = &start->pps[panel_type];
776ba55f2f5SFrançois Tigeot
777ba55f2f5SFrançois Tigeot /* store as of now full data. Trim when we realise all is not needed */
778ba55f2f5SFrançois Tigeot dev_priv->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
779ba55f2f5SFrançois Tigeot if (!dev_priv->vbt.dsi.config)
780ba55f2f5SFrançois Tigeot return;
781ba55f2f5SFrançois Tigeot
782ba55f2f5SFrançois Tigeot dev_priv->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
783ba55f2f5SFrançois Tigeot if (!dev_priv->vbt.dsi.pps) {
784ba55f2f5SFrançois Tigeot kfree(dev_priv->vbt.dsi.config);
785ba55f2f5SFrançois Tigeot return;
786ba55f2f5SFrançois Tigeot }
787ba55f2f5SFrançois Tigeot
788*3f2dd94aSFrançois Tigeot parse_dsi_backlight_ports(dev_priv, bdb->version, port);
7891487f786SFrançois Tigeot
790ba55f2f5SFrançois Tigeot /* We have mandatory mipi config blocks. Initialize as generic panel */
791ba55f2f5SFrançois Tigeot dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
792c0e85e96SFrançois Tigeot }
793ba55f2f5SFrançois Tigeot
794c0e85e96SFrançois Tigeot /* Find the sequence block and size for the given panel. */
795c0e85e96SFrançois Tigeot static const u8 *
find_panel_sequence_block(const struct bdb_mipi_sequence * sequence,u16 panel_id,u32 * seq_size)796c0e85e96SFrançois Tigeot find_panel_sequence_block(const struct bdb_mipi_sequence *sequence,
797c0e85e96SFrançois Tigeot u16 panel_id, u32 *seq_size)
798c0e85e96SFrançois Tigeot {
799c0e85e96SFrançois Tigeot u32 total = get_blocksize(sequence);
800c0e85e96SFrançois Tigeot const u8 *data = &sequence->data[0];
801c0e85e96SFrançois Tigeot u8 current_id;
802c0e85e96SFrançois Tigeot u32 current_size;
803c0e85e96SFrançois Tigeot int header_size = sequence->version >= 3 ? 5 : 3;
804c0e85e96SFrançois Tigeot int index = 0;
805c0e85e96SFrançois Tigeot int i;
806c0e85e96SFrançois Tigeot
807c0e85e96SFrançois Tigeot /* skip new block size */
808c0e85e96SFrançois Tigeot if (sequence->version >= 3)
809c0e85e96SFrançois Tigeot data += 4;
810c0e85e96SFrançois Tigeot
811c0e85e96SFrançois Tigeot for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index < total; i++) {
812c0e85e96SFrançois Tigeot if (index + header_size > total) {
813c0e85e96SFrançois Tigeot DRM_ERROR("Invalid sequence block (header)\n");
814c0e85e96SFrançois Tigeot return NULL;
815c0e85e96SFrançois Tigeot }
816c0e85e96SFrançois Tigeot
817c0e85e96SFrançois Tigeot current_id = *(data + index);
818c0e85e96SFrançois Tigeot if (sequence->version >= 3)
819c0e85e96SFrançois Tigeot current_size = *((const u32 *)(data + index + 1));
820c0e85e96SFrançois Tigeot else
821c0e85e96SFrançois Tigeot current_size = *((const u16 *)(data + index + 1));
822c0e85e96SFrançois Tigeot
823c0e85e96SFrançois Tigeot index += header_size;
824c0e85e96SFrançois Tigeot
825c0e85e96SFrançois Tigeot if (index + current_size > total) {
826c0e85e96SFrançois Tigeot DRM_ERROR("Invalid sequence block\n");
827c0e85e96SFrançois Tigeot return NULL;
828c0e85e96SFrançois Tigeot }
829c0e85e96SFrançois Tigeot
830c0e85e96SFrançois Tigeot if (current_id == panel_id) {
831c0e85e96SFrançois Tigeot *seq_size = current_size;
832c0e85e96SFrançois Tigeot return data + index;
833c0e85e96SFrançois Tigeot }
834c0e85e96SFrançois Tigeot
835c0e85e96SFrançois Tigeot index += current_size;
836c0e85e96SFrançois Tigeot }
837c0e85e96SFrançois Tigeot
838c0e85e96SFrançois Tigeot DRM_ERROR("Sequence block detected but no valid configuration\n");
839c0e85e96SFrançois Tigeot
840c0e85e96SFrançois Tigeot return NULL;
841c0e85e96SFrançois Tigeot }
842c0e85e96SFrançois Tigeot
goto_next_sequence(const u8 * data,int index,int total)843c0e85e96SFrançois Tigeot static int goto_next_sequence(const u8 *data, int index, int total)
844c0e85e96SFrançois Tigeot {
845c0e85e96SFrançois Tigeot u16 len;
846c0e85e96SFrançois Tigeot
847c0e85e96SFrançois Tigeot /* Skip Sequence Byte. */
848c0e85e96SFrançois Tigeot for (index = index + 1; index < total; index += len) {
849c0e85e96SFrançois Tigeot u8 operation_byte = *(data + index);
850c0e85e96SFrançois Tigeot index++;
851c0e85e96SFrançois Tigeot
852c0e85e96SFrançois Tigeot switch (operation_byte) {
853c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_END:
854c0e85e96SFrançois Tigeot return index;
855c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_SEND_PKT:
856c0e85e96SFrançois Tigeot if (index + 4 > total)
857c0e85e96SFrançois Tigeot return 0;
858c0e85e96SFrançois Tigeot
859c0e85e96SFrançois Tigeot len = *((const u16 *)(data + index + 2)) + 4;
860c0e85e96SFrançois Tigeot break;
861c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_DELAY:
862c0e85e96SFrançois Tigeot len = 4;
863c0e85e96SFrançois Tigeot break;
864c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_GPIO:
865c0e85e96SFrançois Tigeot len = 2;
866c0e85e96SFrançois Tigeot break;
867c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_I2C:
868c0e85e96SFrançois Tigeot if (index + 7 > total)
869c0e85e96SFrançois Tigeot return 0;
870c0e85e96SFrançois Tigeot len = *(data + index + 6) + 7;
871c0e85e96SFrançois Tigeot break;
872c0e85e96SFrançois Tigeot default:
873c0e85e96SFrançois Tigeot DRM_ERROR("Unknown operation byte\n");
874c0e85e96SFrançois Tigeot return 0;
875c0e85e96SFrançois Tigeot }
876c0e85e96SFrançois Tigeot }
877c0e85e96SFrançois Tigeot
878c0e85e96SFrançois Tigeot return 0;
879c0e85e96SFrançois Tigeot }
880c0e85e96SFrançois Tigeot
goto_next_sequence_v3(const u8 * data,int index,int total)881c0e85e96SFrançois Tigeot static int goto_next_sequence_v3(const u8 *data, int index, int total)
882c0e85e96SFrançois Tigeot {
883c0e85e96SFrançois Tigeot int seq_end;
884c0e85e96SFrançois Tigeot u16 len;
885c0e85e96SFrançois Tigeot u32 size_of_sequence;
886c0e85e96SFrançois Tigeot
887c0e85e96SFrançois Tigeot /*
888c0e85e96SFrançois Tigeot * Could skip sequence based on Size of Sequence alone, but also do some
889c0e85e96SFrançois Tigeot * checking on the structure.
890c0e85e96SFrançois Tigeot */
891c0e85e96SFrançois Tigeot if (total < 5) {
892c0e85e96SFrançois Tigeot DRM_ERROR("Too small sequence size\n");
893c0e85e96SFrançois Tigeot return 0;
894c0e85e96SFrançois Tigeot }
895c0e85e96SFrançois Tigeot
896c0e85e96SFrançois Tigeot /* Skip Sequence Byte. */
897c0e85e96SFrançois Tigeot index++;
898c0e85e96SFrançois Tigeot
899c0e85e96SFrançois Tigeot /*
900c0e85e96SFrançois Tigeot * Size of Sequence. Excludes the Sequence Byte and the size itself,
901c0e85e96SFrançois Tigeot * includes MIPI_SEQ_ELEM_END byte, excludes the final MIPI_SEQ_END
902c0e85e96SFrançois Tigeot * byte.
903c0e85e96SFrançois Tigeot */
904c0e85e96SFrançois Tigeot size_of_sequence = *((const uint32_t *)(data + index));
905c0e85e96SFrançois Tigeot index += 4;
906c0e85e96SFrançois Tigeot
907c0e85e96SFrançois Tigeot seq_end = index + size_of_sequence;
908c0e85e96SFrançois Tigeot if (seq_end > total) {
909c0e85e96SFrançois Tigeot DRM_ERROR("Invalid sequence size\n");
910c0e85e96SFrançois Tigeot return 0;
911c0e85e96SFrançois Tigeot }
912c0e85e96SFrançois Tigeot
913c0e85e96SFrançois Tigeot for (; index < total; index += len) {
914c0e85e96SFrançois Tigeot u8 operation_byte = *(data + index);
915c0e85e96SFrançois Tigeot index++;
916c0e85e96SFrançois Tigeot
917c0e85e96SFrançois Tigeot if (operation_byte == MIPI_SEQ_ELEM_END) {
918c0e85e96SFrançois Tigeot if (index != seq_end) {
919c0e85e96SFrançois Tigeot DRM_ERROR("Invalid element structure\n");
920c0e85e96SFrançois Tigeot return 0;
921c0e85e96SFrançois Tigeot }
922c0e85e96SFrançois Tigeot return index;
923c0e85e96SFrançois Tigeot }
924c0e85e96SFrançois Tigeot
925c0e85e96SFrançois Tigeot len = *(data + index);
926c0e85e96SFrançois Tigeot index++;
927c0e85e96SFrançois Tigeot
928c0e85e96SFrançois Tigeot /*
929c0e85e96SFrançois Tigeot * FIXME: Would be nice to check elements like for v1/v2 in
930c0e85e96SFrançois Tigeot * goto_next_sequence() above.
931c0e85e96SFrançois Tigeot */
932c0e85e96SFrançois Tigeot switch (operation_byte) {
933c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_SEND_PKT:
934c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_DELAY:
935c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_GPIO:
936c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_I2C:
937c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_SPI:
938c0e85e96SFrançois Tigeot case MIPI_SEQ_ELEM_PMIC:
939c0e85e96SFrançois Tigeot break;
940c0e85e96SFrançois Tigeot default:
941c0e85e96SFrançois Tigeot DRM_ERROR("Unknown operation byte %u\n",
942c0e85e96SFrançois Tigeot operation_byte);
943c0e85e96SFrançois Tigeot break;
944c0e85e96SFrançois Tigeot }
945c0e85e96SFrançois Tigeot }
946c0e85e96SFrançois Tigeot
947c0e85e96SFrançois Tigeot return 0;
948c0e85e96SFrançois Tigeot }
949c0e85e96SFrançois Tigeot
950c0e85e96SFrançois Tigeot static void
parse_mipi_sequence(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)951c0e85e96SFrançois Tigeot parse_mipi_sequence(struct drm_i915_private *dev_priv,
952c0e85e96SFrançois Tigeot const struct bdb_header *bdb)
953c0e85e96SFrançois Tigeot {
9548621f407SFrançois Tigeot int panel_type = dev_priv->vbt.panel_type;
955c0e85e96SFrançois Tigeot const struct bdb_mipi_sequence *sequence;
956c0e85e96SFrançois Tigeot const u8 *seq_data;
957c0e85e96SFrançois Tigeot u32 seq_size;
958c0e85e96SFrançois Tigeot u8 *data;
959c0e85e96SFrançois Tigeot int index = 0;
960c0e85e96SFrançois Tigeot
961c0e85e96SFrançois Tigeot /* Only our generic panel driver uses the sequence block. */
962c0e85e96SFrançois Tigeot if (dev_priv->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
963c0e85e96SFrançois Tigeot return;
964c0e85e96SFrançois Tigeot
965ba55f2f5SFrançois Tigeot sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
966ba55f2f5SFrançois Tigeot if (!sequence) {
967ba55f2f5SFrançois Tigeot DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
968ba55f2f5SFrançois Tigeot return;
969ba55f2f5SFrançois Tigeot }
970ba55f2f5SFrançois Tigeot
971a05eeebfSFrançois Tigeot /* Fail gracefully for forward incompatible sequence block. */
972c0e85e96SFrançois Tigeot if (sequence->version >= 4) {
973c0e85e96SFrançois Tigeot DRM_ERROR("Unable to parse MIPI Sequence Block v%u\n",
974c0e85e96SFrançois Tigeot sequence->version);
975a05eeebfSFrançois Tigeot return;
976a05eeebfSFrançois Tigeot }
977a05eeebfSFrançois Tigeot
978c0e85e96SFrançois Tigeot DRM_DEBUG_DRIVER("Found MIPI sequence block v%u\n", sequence->version);
979ba55f2f5SFrançois Tigeot
980c0e85e96SFrançois Tigeot seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size);
981c0e85e96SFrançois Tigeot if (!seq_data)
982c0e85e96SFrançois Tigeot return;
983ba55f2f5SFrançois Tigeot
984c0e85e96SFrançois Tigeot data = kmemdup(seq_data, seq_size, GFP_KERNEL);
985c0e85e96SFrançois Tigeot if (!data)
986c0e85e96SFrançois Tigeot return;
987ba55f2f5SFrançois Tigeot
988c0e85e96SFrançois Tigeot /* Parse the sequences, store pointers to each sequence. */
989c0e85e96SFrançois Tigeot for (;;) {
990c0e85e96SFrançois Tigeot u8 seq_id = *(data + index);
991c0e85e96SFrançois Tigeot if (seq_id == MIPI_SEQ_END)
992ba55f2f5SFrançois Tigeot break;
993ba55f2f5SFrançois Tigeot
994c0e85e96SFrançois Tigeot if (seq_id >= MIPI_SEQ_MAX) {
995c0e85e96SFrançois Tigeot DRM_ERROR("Unknown sequence %u\n", seq_id);
996c0e85e96SFrançois Tigeot goto err;
997c0e85e96SFrançois Tigeot }
998c0e85e96SFrançois Tigeot
9991e12ee3bSFrançois Tigeot /* Log about presence of sequences we won't run. */
10001e12ee3bSFrançois Tigeot if (seq_id == MIPI_SEQ_TEAR_ON || seq_id == MIPI_SEQ_TEAR_OFF)
10011e12ee3bSFrançois Tigeot DRM_DEBUG_KMS("Unsupported sequence %u\n", seq_id);
10021e12ee3bSFrançois Tigeot
1003c0e85e96SFrançois Tigeot dev_priv->vbt.dsi.sequence[seq_id] = data + index;
1004c0e85e96SFrançois Tigeot
1005c0e85e96SFrançois Tigeot if (sequence->version >= 3)
1006c0e85e96SFrançois Tigeot index = goto_next_sequence_v3(data, index, seq_size);
1007c0e85e96SFrançois Tigeot else
1008c0e85e96SFrançois Tigeot index = goto_next_sequence(data, index, seq_size);
1009c0e85e96SFrançois Tigeot if (!index) {
1010c0e85e96SFrançois Tigeot DRM_ERROR("Invalid sequence %u\n", seq_id);
1011c0e85e96SFrançois Tigeot goto err;
1012ba55f2f5SFrançois Tigeot }
1013ba55f2f5SFrançois Tigeot }
1014ba55f2f5SFrançois Tigeot
1015c0e85e96SFrançois Tigeot dev_priv->vbt.dsi.data = data;
1016ba55f2f5SFrançois Tigeot dev_priv->vbt.dsi.size = seq_size;
1017c0e85e96SFrançois Tigeot dev_priv->vbt.dsi.seq_version = sequence->version;
1018ba55f2f5SFrançois Tigeot
1019c0e85e96SFrançois Tigeot DRM_DEBUG_DRIVER("MIPI related VBT parsing complete\n");
1020ba55f2f5SFrançois Tigeot return;
1021ba55f2f5SFrançois Tigeot
1022c0e85e96SFrançois Tigeot err:
1023c0e85e96SFrançois Tigeot kfree(data);
102424edb884SFrançois Tigeot memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
10259edbd4a0SFrançois Tigeot }
10269edbd4a0SFrançois Tigeot
translate_iboost(u8 val)1027a05eeebfSFrançois Tigeot static u8 translate_iboost(u8 val)
1028a05eeebfSFrançois Tigeot {
1029a05eeebfSFrançois Tigeot static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
1030a05eeebfSFrançois Tigeot
1031a05eeebfSFrançois Tigeot if (val >= ARRAY_SIZE(mapping)) {
1032a05eeebfSFrançois Tigeot DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
1033a05eeebfSFrançois Tigeot return 0;
1034a05eeebfSFrançois Tigeot }
1035a05eeebfSFrançois Tigeot return mapping[val];
1036a05eeebfSFrançois Tigeot }
1037a05eeebfSFrançois Tigeot
sanitize_ddc_pin(struct drm_i915_private * dev_priv,enum port port)10384be47400SFrançois Tigeot static void sanitize_ddc_pin(struct drm_i915_private *dev_priv,
10394be47400SFrançois Tigeot enum port port)
10404be47400SFrançois Tigeot {
10414be47400SFrançois Tigeot const struct ddi_vbt_port_info *info =
10424be47400SFrançois Tigeot &dev_priv->vbt.ddi_port_info[port];
10434be47400SFrançois Tigeot enum port p;
10444be47400SFrançois Tigeot
10454be47400SFrançois Tigeot if (!info->alternate_ddc_pin)
10464be47400SFrançois Tigeot return;
10474be47400SFrançois Tigeot
10484be47400SFrançois Tigeot for_each_port_masked(p, (1 << port) - 1) {
10494be47400SFrançois Tigeot struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
10504be47400SFrançois Tigeot
10514be47400SFrançois Tigeot if (info->alternate_ddc_pin != i->alternate_ddc_pin)
10524be47400SFrançois Tigeot continue;
10534be47400SFrançois Tigeot
10544be47400SFrançois Tigeot DRM_DEBUG_KMS("port %c trying to use the same DDC pin (0x%x) as port %c, "
10554be47400SFrançois Tigeot "disabling port %c DVI/HDMI support\n",
10564be47400SFrançois Tigeot port_name(p), i->alternate_ddc_pin,
10574be47400SFrançois Tigeot port_name(port), port_name(p));
10584be47400SFrançois Tigeot
10594be47400SFrançois Tigeot /*
10604be47400SFrançois Tigeot * If we have multiple ports supposedly sharing the
10614be47400SFrançois Tigeot * pin, then dvi/hdmi couldn't exist on the shared
10624be47400SFrançois Tigeot * port. Otherwise they share the same ddc bin and
10634be47400SFrançois Tigeot * system couldn't communicate with them separately.
10644be47400SFrançois Tigeot *
10654be47400SFrançois Tigeot * Due to parsing the ports in alphabetical order,
10664be47400SFrançois Tigeot * a higher port will always clobber a lower one.
10674be47400SFrançois Tigeot */
10684be47400SFrançois Tigeot i->supports_dvi = false;
10694be47400SFrançois Tigeot i->supports_hdmi = false;
10704be47400SFrançois Tigeot i->alternate_ddc_pin = 0;
10714be47400SFrançois Tigeot }
10724be47400SFrançois Tigeot }
10734be47400SFrançois Tigeot
sanitize_aux_ch(struct drm_i915_private * dev_priv,enum port port)10744be47400SFrançois Tigeot static void sanitize_aux_ch(struct drm_i915_private *dev_priv,
10754be47400SFrançois Tigeot enum port port)
10764be47400SFrançois Tigeot {
10774be47400SFrançois Tigeot const struct ddi_vbt_port_info *info =
10784be47400SFrançois Tigeot &dev_priv->vbt.ddi_port_info[port];
10794be47400SFrançois Tigeot enum port p;
10804be47400SFrançois Tigeot
10814be47400SFrançois Tigeot if (!info->alternate_aux_channel)
10824be47400SFrançois Tigeot return;
10834be47400SFrançois Tigeot
10844be47400SFrançois Tigeot for_each_port_masked(p, (1 << port) - 1) {
10854be47400SFrançois Tigeot struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
10864be47400SFrançois Tigeot
10874be47400SFrançois Tigeot if (info->alternate_aux_channel != i->alternate_aux_channel)
10884be47400SFrançois Tigeot continue;
10894be47400SFrançois Tigeot
10904be47400SFrançois Tigeot DRM_DEBUG_KMS("port %c trying to use the same AUX CH (0x%x) as port %c, "
10914be47400SFrançois Tigeot "disabling port %c DP support\n",
10924be47400SFrançois Tigeot port_name(p), i->alternate_aux_channel,
10934be47400SFrançois Tigeot port_name(port), port_name(p));
10944be47400SFrançois Tigeot
10954be47400SFrançois Tigeot /*
10964be47400SFrançois Tigeot * If we have multiple ports supposedlt sharing the
10974be47400SFrançois Tigeot * aux channel, then DP couldn't exist on the shared
10984be47400SFrançois Tigeot * port. Otherwise they share the same aux channel
10994be47400SFrançois Tigeot * and system couldn't communicate with them separately.
11004be47400SFrançois Tigeot *
11014be47400SFrançois Tigeot * Due to parsing the ports in alphabetical order,
11024be47400SFrançois Tigeot * a higher port will always clobber a lower one.
11034be47400SFrançois Tigeot */
11044be47400SFrançois Tigeot i->supports_dp = false;
11054be47400SFrançois Tigeot i->alternate_aux_channel = 0;
11064be47400SFrançois Tigeot }
11074be47400SFrançois Tigeot }
11084be47400SFrançois Tigeot
1109*3f2dd94aSFrançois Tigeot static const u8 cnp_ddc_pin_map[] = {
1110*3f2dd94aSFrançois Tigeot [0] = 0, /* N/A */
1111*3f2dd94aSFrançois Tigeot [DDC_BUS_DDI_B] = GMBUS_PIN_1_BXT,
1112*3f2dd94aSFrançois Tigeot [DDC_BUS_DDI_C] = GMBUS_PIN_2_BXT,
1113*3f2dd94aSFrançois Tigeot [DDC_BUS_DDI_D] = GMBUS_PIN_4_CNP, /* sic */
1114*3f2dd94aSFrançois Tigeot [DDC_BUS_DDI_F] = GMBUS_PIN_3_BXT, /* sic */
1115*3f2dd94aSFrançois Tigeot };
1116*3f2dd94aSFrançois Tigeot
map_ddc_pin(struct drm_i915_private * dev_priv,u8 vbt_pin)1117*3f2dd94aSFrançois Tigeot static u8 map_ddc_pin(struct drm_i915_private *dev_priv, u8 vbt_pin)
11189edbd4a0SFrançois Tigeot {
1119*3f2dd94aSFrançois Tigeot if (HAS_PCH_CNP(dev_priv)) {
1120*3f2dd94aSFrançois Tigeot if (vbt_pin < ARRAY_SIZE(cnp_ddc_pin_map)) {
1121*3f2dd94aSFrançois Tigeot return cnp_ddc_pin_map[vbt_pin];
1122*3f2dd94aSFrançois Tigeot } else {
1123*3f2dd94aSFrançois Tigeot DRM_DEBUG_KMS("Ignoring alternate pin: VBT claims DDC pin %d, which is not valid for this platform\n", vbt_pin);
1124*3f2dd94aSFrançois Tigeot return 0;
1125*3f2dd94aSFrançois Tigeot }
1126*3f2dd94aSFrançois Tigeot }
1127*3f2dd94aSFrançois Tigeot
1128*3f2dd94aSFrançois Tigeot return vbt_pin;
1129*3f2dd94aSFrançois Tigeot }
1130*3f2dd94aSFrançois Tigeot
parse_ddi_port(struct drm_i915_private * dev_priv,enum port port,u8 bdb_version)1131*3f2dd94aSFrançois Tigeot static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
1132*3f2dd94aSFrançois Tigeot u8 bdb_version)
1133*3f2dd94aSFrançois Tigeot {
1134*3f2dd94aSFrançois Tigeot struct child_device_config *it, *child = NULL;
11359edbd4a0SFrançois Tigeot struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
11369edbd4a0SFrançois Tigeot uint8_t hdmi_level_shift;
11379edbd4a0SFrançois Tigeot int i, j;
11389edbd4a0SFrançois Tigeot bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
1139a05eeebfSFrançois Tigeot uint8_t aux_channel, ddc_pin;
11409edbd4a0SFrançois Tigeot /* Each DDI port can have more than one value on the "DVO Port" field,
1141a85cb24fSFrançois Tigeot * so look for all the possible values for each port.
1142a85cb24fSFrançois Tigeot */
1143a05eeebfSFrançois Tigeot int dvo_ports[][3] = {
1144a05eeebfSFrançois Tigeot {DVO_PORT_HDMIA, DVO_PORT_DPA, -1},
1145a05eeebfSFrançois Tigeot {DVO_PORT_HDMIB, DVO_PORT_DPB, -1},
1146a05eeebfSFrançois Tigeot {DVO_PORT_HDMIC, DVO_PORT_DPC, -1},
1147a05eeebfSFrançois Tigeot {DVO_PORT_HDMID, DVO_PORT_DPD, -1},
1148a05eeebfSFrançois Tigeot {DVO_PORT_CRT, DVO_PORT_HDMIE, DVO_PORT_DPE},
11499edbd4a0SFrançois Tigeot };
11509edbd4a0SFrançois Tigeot
1151a85cb24fSFrançois Tigeot /*
1152a85cb24fSFrançois Tigeot * Find the first child device to reference the port, report if more
1153a85cb24fSFrançois Tigeot * than one found.
1154a85cb24fSFrançois Tigeot */
11559edbd4a0SFrançois Tigeot for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
11569edbd4a0SFrançois Tigeot it = dev_priv->vbt.child_dev + i;
11579edbd4a0SFrançois Tigeot
1158a05eeebfSFrançois Tigeot for (j = 0; j < 3; j++) {
11599edbd4a0SFrançois Tigeot if (dvo_ports[port][j] == -1)
11609edbd4a0SFrançois Tigeot break;
11619edbd4a0SFrançois Tigeot
1162*3f2dd94aSFrançois Tigeot if (it->dvo_port == dvo_ports[port][j]) {
11639edbd4a0SFrançois Tigeot if (child) {
1164a85cb24fSFrançois Tigeot DRM_DEBUG_KMS("More than one child device for port %c in VBT, using the first.\n",
11659edbd4a0SFrançois Tigeot port_name(port));
1166a85cb24fSFrançois Tigeot } else {
11679edbd4a0SFrançois Tigeot child = it;
11689edbd4a0SFrançois Tigeot }
11699edbd4a0SFrançois Tigeot }
11709edbd4a0SFrançois Tigeot }
1171a85cb24fSFrançois Tigeot }
11729edbd4a0SFrançois Tigeot if (!child)
11739edbd4a0SFrançois Tigeot return;
11749edbd4a0SFrançois Tigeot
1175*3f2dd94aSFrançois Tigeot aux_channel = child->aux_channel;
1176*3f2dd94aSFrançois Tigeot ddc_pin = child->ddc_pin;
11779edbd4a0SFrançois Tigeot
1178*3f2dd94aSFrançois Tigeot is_dvi = child->device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
1179*3f2dd94aSFrançois Tigeot is_dp = child->device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
1180*3f2dd94aSFrançois Tigeot is_crt = child->device_type & DEVICE_TYPE_ANALOG_OUTPUT;
1181*3f2dd94aSFrançois Tigeot is_hdmi = is_dvi && (child->device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
1182*3f2dd94aSFrançois Tigeot is_edp = is_dp && (child->device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
1183*3f2dd94aSFrançois Tigeot
1184*3f2dd94aSFrançois Tigeot if (port == PORT_A && is_dvi) {
1185*3f2dd94aSFrançois Tigeot DRM_DEBUG_KMS("VBT claims port A supports DVI%s, ignoring\n",
1186*3f2dd94aSFrançois Tigeot is_hdmi ? "/HDMI" : "");
1187*3f2dd94aSFrançois Tigeot is_dvi = false;
1188*3f2dd94aSFrançois Tigeot is_hdmi = false;
1189*3f2dd94aSFrançois Tigeot }
1190*3f2dd94aSFrançois Tigeot
1191*3f2dd94aSFrançois Tigeot if (port == PORT_A && is_dvi) {
1192*3f2dd94aSFrançois Tigeot DRM_DEBUG_KMS("VBT claims port A supports DVI%s, ignoring\n",
1193*3f2dd94aSFrançois Tigeot is_hdmi ? "/HDMI" : "");
1194*3f2dd94aSFrançois Tigeot is_dvi = false;
1195*3f2dd94aSFrançois Tigeot is_hdmi = false;
1196*3f2dd94aSFrançois Tigeot }
11979edbd4a0SFrançois Tigeot
11989edbd4a0SFrançois Tigeot info->supports_dvi = is_dvi;
11999edbd4a0SFrançois Tigeot info->supports_hdmi = is_hdmi;
12009edbd4a0SFrançois Tigeot info->supports_dp = is_dp;
1201a85cb24fSFrançois Tigeot info->supports_edp = is_edp;
12029edbd4a0SFrançois Tigeot
12039edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
12049edbd4a0SFrançois Tigeot port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
12059edbd4a0SFrançois Tigeot
12069edbd4a0SFrançois Tigeot if (is_edp && is_dvi)
12079edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
12089edbd4a0SFrançois Tigeot port_name(port));
12099edbd4a0SFrançois Tigeot if (is_crt && port != PORT_E)
12109edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
12119edbd4a0SFrançois Tigeot if (is_crt && (is_dvi || is_dp))
12129edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
12139edbd4a0SFrançois Tigeot port_name(port));
12149edbd4a0SFrançois Tigeot if (is_dvi && (port == PORT_A || port == PORT_E))
12151b13d190SFrançois Tigeot DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port));
12169edbd4a0SFrançois Tigeot if (!is_dvi && !is_dp && !is_crt)
12179edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
12189edbd4a0SFrançois Tigeot port_name(port));
12199edbd4a0SFrançois Tigeot if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
12209edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
12219edbd4a0SFrançois Tigeot
12229edbd4a0SFrançois Tigeot if (is_dvi) {
1223*3f2dd94aSFrançois Tigeot info->alternate_ddc_pin = map_ddc_pin(dev_priv, ddc_pin);
12244be47400SFrançois Tigeot
12254be47400SFrançois Tigeot sanitize_ddc_pin(dev_priv, port);
12269edbd4a0SFrançois Tigeot }
12279edbd4a0SFrançois Tigeot
12289edbd4a0SFrançois Tigeot if (is_dp) {
1229a05eeebfSFrançois Tigeot info->alternate_aux_channel = aux_channel;
12304be47400SFrançois Tigeot
12314be47400SFrançois Tigeot sanitize_aux_ch(dev_priv, port);
12329edbd4a0SFrançois Tigeot }
12339edbd4a0SFrançois Tigeot
1234*3f2dd94aSFrançois Tigeot if (bdb_version >= 158) {
12359edbd4a0SFrançois Tigeot /* The VBT HDMI level shift values match the table we have. */
1236*3f2dd94aSFrançois Tigeot hdmi_level_shift = child->hdmi_level_shifter_value;
12379edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
12389edbd4a0SFrançois Tigeot port_name(port),
12399edbd4a0SFrançois Tigeot hdmi_level_shift);
12409edbd4a0SFrançois Tigeot info->hdmi_level_shift = hdmi_level_shift;
12419edbd4a0SFrançois Tigeot }
1242a05eeebfSFrançois Tigeot
1243a05eeebfSFrançois Tigeot /* Parse the I_boost config for SKL and above */
1244*3f2dd94aSFrançois Tigeot if (bdb_version >= 196 && child->iboost) {
1245*3f2dd94aSFrançois Tigeot info->dp_boost_level = translate_iboost(child->dp_iboost_level);
1246a05eeebfSFrançois Tigeot DRM_DEBUG_KMS("VBT (e)DP boost level for port %c: %d\n",
1247a05eeebfSFrançois Tigeot port_name(port), info->dp_boost_level);
1248*3f2dd94aSFrançois Tigeot info->hdmi_boost_level = translate_iboost(child->hdmi_iboost_level);
1249a05eeebfSFrançois Tigeot DRM_DEBUG_KMS("VBT HDMI boost level for port %c: %d\n",
1250a05eeebfSFrançois Tigeot port_name(port), info->hdmi_boost_level);
1251a05eeebfSFrançois Tigeot }
12529edbd4a0SFrançois Tigeot }
12539edbd4a0SFrançois Tigeot
parse_ddi_ports(struct drm_i915_private * dev_priv,u8 bdb_version)1254*3f2dd94aSFrançois Tigeot static void parse_ddi_ports(struct drm_i915_private *dev_priv, u8 bdb_version)
12559edbd4a0SFrançois Tigeot {
12569edbd4a0SFrançois Tigeot enum port port;
12579edbd4a0SFrançois Tigeot
1258*3f2dd94aSFrançois Tigeot if (!HAS_DDI(dev_priv) && !IS_CHERRYVIEW(dev_priv))
12599edbd4a0SFrançois Tigeot return;
12609edbd4a0SFrançois Tigeot
12619edbd4a0SFrançois Tigeot if (!dev_priv->vbt.child_dev_num)
12629edbd4a0SFrançois Tigeot return;
12639edbd4a0SFrançois Tigeot
1264*3f2dd94aSFrançois Tigeot if (bdb_version < 155)
12659edbd4a0SFrançois Tigeot return;
12669edbd4a0SFrançois Tigeot
12679edbd4a0SFrançois Tigeot for (port = PORT_A; port < I915_MAX_PORTS; port++)
1268*3f2dd94aSFrançois Tigeot parse_ddi_port(dev_priv, port, bdb_version);
12699edbd4a0SFrançois Tigeot }
12709edbd4a0SFrançois Tigeot
12719edbd4a0SFrançois Tigeot static void
parse_general_definitions(struct drm_i915_private * dev_priv,const struct bdb_header * bdb)1272*3f2dd94aSFrançois Tigeot parse_general_definitions(struct drm_i915_private *dev_priv,
127319c468b4SFrançois Tigeot const struct bdb_header *bdb)
1274e3adcf8fSFrançois Tigeot {
1275*3f2dd94aSFrançois Tigeot const struct bdb_general_definitions *defs;
1276*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
1277e3adcf8fSFrançois Tigeot int i, child_device_num, count;
1278a05eeebfSFrançois Tigeot u8 expected_size;
1279e3adcf8fSFrançois Tigeot u16 block_size;
1280*3f2dd94aSFrançois Tigeot int bus_pin;
1281e3adcf8fSFrançois Tigeot
1282*3f2dd94aSFrançois Tigeot defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
1283*3f2dd94aSFrançois Tigeot if (!defs) {
1284e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
1285e3adcf8fSFrançois Tigeot return;
1286e3adcf8fSFrançois Tigeot }
1287*3f2dd94aSFrançois Tigeot
1288*3f2dd94aSFrançois Tigeot block_size = get_blocksize(defs);
1289*3f2dd94aSFrançois Tigeot if (block_size < sizeof(*defs)) {
1290*3f2dd94aSFrançois Tigeot DRM_DEBUG_KMS("General definitions block too small (%u)\n",
1291*3f2dd94aSFrançois Tigeot block_size);
1292*3f2dd94aSFrançois Tigeot return;
1293*3f2dd94aSFrançois Tigeot }
1294*3f2dd94aSFrançois Tigeot
1295*3f2dd94aSFrançois Tigeot bus_pin = defs->crt_ddc_gmbus_pin;
1296*3f2dd94aSFrançois Tigeot DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
1297*3f2dd94aSFrançois Tigeot if (intel_gmbus_is_valid_pin(dev_priv, bus_pin))
1298*3f2dd94aSFrançois Tigeot dev_priv->vbt.crt_ddc_pin = bus_pin;
1299*3f2dd94aSFrançois Tigeot
1300c0e85e96SFrançois Tigeot if (bdb->version < 106) {
1301c0e85e96SFrançois Tigeot expected_size = 22;
13028621f407SFrançois Tigeot } else if (bdb->version < 111) {
1303c0e85e96SFrançois Tigeot expected_size = 27;
1304c0e85e96SFrançois Tigeot } else if (bdb->version < 195) {
1305*3f2dd94aSFrançois Tigeot expected_size = LEGACY_CHILD_DEVICE_CONFIG_SIZE;
1306a05eeebfSFrançois Tigeot } else if (bdb->version == 195) {
1307a05eeebfSFrançois Tigeot expected_size = 37;
1308a05eeebfSFrançois Tigeot } else if (bdb->version <= 197) {
1309a05eeebfSFrançois Tigeot expected_size = 38;
1310a05eeebfSFrançois Tigeot } else {
1311a05eeebfSFrançois Tigeot expected_size = 38;
1312*3f2dd94aSFrançois Tigeot BUILD_BUG_ON(sizeof(*child) < 38);
1313a05eeebfSFrançois Tigeot DRM_DEBUG_DRIVER("Expected child device config size for VBT version %u not known; assuming %u\n",
1314a05eeebfSFrançois Tigeot bdb->version, expected_size);
1315a05eeebfSFrançois Tigeot }
1316a05eeebfSFrançois Tigeot
1317a05eeebfSFrançois Tigeot /* Flag an error for unexpected size, but continue anyway. */
1318*3f2dd94aSFrançois Tigeot if (defs->child_dev_size != expected_size)
1319a05eeebfSFrançois Tigeot DRM_ERROR("Unexpected child device config size %u (expected %u for VBT version %u)\n",
1320*3f2dd94aSFrançois Tigeot defs->child_dev_size, expected_size, bdb->version);
1321a05eeebfSFrançois Tigeot
1322c0e85e96SFrançois Tigeot /* The legacy sized child device config is the minimum we need. */
1323*3f2dd94aSFrançois Tigeot if (defs->child_dev_size < LEGACY_CHILD_DEVICE_CONFIG_SIZE) {
1324c0e85e96SFrançois Tigeot DRM_DEBUG_KMS("Child device config size %u is too small.\n",
1325*3f2dd94aSFrançois Tigeot defs->child_dev_size);
1326c0e85e96SFrançois Tigeot return;
1327c0e85e96SFrançois Tigeot }
1328c0e85e96SFrançois Tigeot
1329e3adcf8fSFrançois Tigeot /* get the number of child device */
1330*3f2dd94aSFrançois Tigeot child_device_num = (block_size - sizeof(*defs)) / defs->child_dev_size;
1331e3adcf8fSFrançois Tigeot count = 0;
1332e3adcf8fSFrançois Tigeot /* get the number of child device that is present */
1333e3adcf8fSFrançois Tigeot for (i = 0; i < child_device_num; i++) {
1334*3f2dd94aSFrançois Tigeot child = child_device_ptr(defs, i);
1335*3f2dd94aSFrançois Tigeot if (!child->device_type)
1336e3adcf8fSFrançois Tigeot continue;
1337e3adcf8fSFrançois Tigeot count++;
1338e3adcf8fSFrançois Tigeot }
1339e3adcf8fSFrançois Tigeot if (!count) {
1340e3adcf8fSFrançois Tigeot DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
1341e3adcf8fSFrançois Tigeot return;
1342e3adcf8fSFrançois Tigeot }
1343*3f2dd94aSFrançois Tigeot dev_priv->vbt.child_dev = kcalloc(count, sizeof(*child), GFP_KERNEL);
13445d0b1887SFrançois Tigeot if (!dev_priv->vbt.child_dev) {
1345e3440f96SFrançois Tigeot DRM_DEBUG_KMS("No memory space for child device\n");
1346e3440f96SFrançois Tigeot return;
1347e3440f96SFrançois Tigeot }
1348e3adcf8fSFrançois Tigeot
13495d0b1887SFrançois Tigeot dev_priv->vbt.child_dev_num = count;
1350e3adcf8fSFrançois Tigeot count = 0;
1351e3adcf8fSFrançois Tigeot for (i = 0; i < child_device_num; i++) {
1352*3f2dd94aSFrançois Tigeot child = child_device_ptr(defs, i);
1353*3f2dd94aSFrançois Tigeot if (!child->device_type)
1354e3adcf8fSFrançois Tigeot continue;
1355a05eeebfSFrançois Tigeot
1356a05eeebfSFrançois Tigeot /*
1357a05eeebfSFrançois Tigeot * Copy as much as we know (sizeof) and is available
1358a05eeebfSFrançois Tigeot * (child_dev_size) of the child device. Accessing the data must
1359a05eeebfSFrançois Tigeot * depend on VBT version.
1360a05eeebfSFrançois Tigeot */
1361*3f2dd94aSFrançois Tigeot memcpy(dev_priv->vbt.child_dev + count, child,
1362*3f2dd94aSFrançois Tigeot min_t(size_t, defs->child_dev_size, sizeof(*child)));
1363*3f2dd94aSFrançois Tigeot count++;
13648621f407SFrançois Tigeot }
1365e3adcf8fSFrançois Tigeot }
1366e3adcf8fSFrançois Tigeot
1367a85cb24fSFrançois Tigeot /* Common defaults which may be overridden by VBT. */
1368e3adcf8fSFrançois Tigeot static void
init_vbt_defaults(struct drm_i915_private * dev_priv)1369e3adcf8fSFrançois Tigeot init_vbt_defaults(struct drm_i915_private *dev_priv)
1370e3adcf8fSFrançois Tigeot {
13719edbd4a0SFrançois Tigeot enum port port;
1372e3adcf8fSFrançois Tigeot
137319c468b4SFrançois Tigeot dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
1374e3adcf8fSFrançois Tigeot
1375ba55f2f5SFrançois Tigeot /* Default to having backlight */
1376ba55f2f5SFrançois Tigeot dev_priv->vbt.backlight.present = true;
1377ba55f2f5SFrançois Tigeot
1378e3adcf8fSFrançois Tigeot /* LFP panel data */
13795d0b1887SFrançois Tigeot dev_priv->vbt.lvds_dither = 1;
13805d0b1887SFrançois Tigeot dev_priv->vbt.lvds_vbt = 0;
1381e3adcf8fSFrançois Tigeot
1382e3adcf8fSFrançois Tigeot /* SDVO panel data */
13835d0b1887SFrançois Tigeot dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
1384e3adcf8fSFrançois Tigeot
1385e3adcf8fSFrançois Tigeot /* general features */
13865d0b1887SFrançois Tigeot dev_priv->vbt.int_tv_support = 1;
13875d0b1887SFrançois Tigeot dev_priv->vbt.int_crt_support = 1;
1388e3adcf8fSFrançois Tigeot
1389e3adcf8fSFrançois Tigeot /* Default to using SSC */
13905d0b1887SFrançois Tigeot dev_priv->vbt.lvds_use_ssc = 1;
13919edbd4a0SFrançois Tigeot /*
13929edbd4a0SFrançois Tigeot * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
13939edbd4a0SFrançois Tigeot * clock for LVDS.
13949edbd4a0SFrançois Tigeot */
1395aee94f86SFrançois Tigeot dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev_priv,
1396aee94f86SFrançois Tigeot !HAS_PCH_SPLIT(dev_priv));
13979edbd4a0SFrançois Tigeot DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
13989edbd4a0SFrançois Tigeot
13999edbd4a0SFrançois Tigeot for (port = PORT_A; port < I915_MAX_PORTS; port++) {
14009edbd4a0SFrançois Tigeot struct ddi_vbt_port_info *info =
14019edbd4a0SFrançois Tigeot &dev_priv->vbt.ddi_port_info[port];
14029edbd4a0SFrançois Tigeot
14031b13d190SFrançois Tigeot info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
1404a85cb24fSFrançois Tigeot }
1405a85cb24fSFrançois Tigeot }
1406a85cb24fSFrançois Tigeot
1407a85cb24fSFrançois Tigeot /* Defaults to initialize only if there is no VBT. */
1408a85cb24fSFrançois Tigeot static void
init_vbt_missing_defaults(struct drm_i915_private * dev_priv)1409a85cb24fSFrançois Tigeot init_vbt_missing_defaults(struct drm_i915_private *dev_priv)
1410a85cb24fSFrançois Tigeot {
1411a85cb24fSFrançois Tigeot enum port port;
1412a85cb24fSFrançois Tigeot
1413a85cb24fSFrançois Tigeot for (port = PORT_A; port < I915_MAX_PORTS; port++) {
1414a85cb24fSFrançois Tigeot struct ddi_vbt_port_info *info =
1415a85cb24fSFrançois Tigeot &dev_priv->vbt.ddi_port_info[port];
14169edbd4a0SFrançois Tigeot
14179edbd4a0SFrançois Tigeot info->supports_dvi = (port != PORT_A && port != PORT_E);
14189edbd4a0SFrançois Tigeot info->supports_hdmi = info->supports_dvi;
14199edbd4a0SFrançois Tigeot info->supports_dp = (port != PORT_E);
14209edbd4a0SFrançois Tigeot }
1421e3adcf8fSFrançois Tigeot }
1422e3adcf8fSFrançois Tigeot
get_bdb_header(const struct vbt_header * vbt)1423aee94f86SFrançois Tigeot static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
1424e3adcf8fSFrançois Tigeot {
14251487f786SFrançois Tigeot const void *_vbt = vbt;
1426aee94f86SFrançois Tigeot
14271487f786SFrançois Tigeot return _vbt + vbt->bdb_offset;
1428e3adcf8fSFrançois Tigeot }
1429e3adcf8fSFrançois Tigeot
1430aee94f86SFrançois Tigeot /**
1431aee94f86SFrançois Tigeot * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
1432aee94f86SFrançois Tigeot * @buf: pointer to a buffer to validate
1433aee94f86SFrançois Tigeot * @size: size of the buffer
1434aee94f86SFrançois Tigeot *
1435aee94f86SFrançois Tigeot * Returns true on valid VBT.
1436aee94f86SFrançois Tigeot */
intel_bios_is_valid_vbt(const void * buf,size_t size)1437aee94f86SFrançois Tigeot bool intel_bios_is_valid_vbt(const void *buf, size_t size)
1438e3adcf8fSFrançois Tigeot {
1439aee94f86SFrançois Tigeot const struct vbt_header *vbt = buf;
144019c468b4SFrançois Tigeot const struct bdb_header *bdb;
1441ba55f2f5SFrançois Tigeot
1442aee94f86SFrançois Tigeot if (!vbt)
1443aee94f86SFrançois Tigeot return false;
1444aee94f86SFrançois Tigeot
1445aee94f86SFrançois Tigeot if (sizeof(struct vbt_header) > size) {
1446ba55f2f5SFrançois Tigeot DRM_DEBUG_DRIVER("VBT header incomplete\n");
1447aee94f86SFrançois Tigeot return false;
1448ba55f2f5SFrançois Tigeot }
1449ba55f2f5SFrançois Tigeot
1450ba55f2f5SFrançois Tigeot if (memcmp(vbt->signature, "$VBT", 4)) {
1451ba55f2f5SFrançois Tigeot DRM_DEBUG_DRIVER("VBT invalid signature\n");
1452aee94f86SFrançois Tigeot return false;
1453ba55f2f5SFrançois Tigeot }
1454ba55f2f5SFrançois Tigeot
1455a85cb24fSFrançois Tigeot if (range_overflows_t(size_t,
1456a85cb24fSFrançois Tigeot vbt->bdb_offset,
1457a85cb24fSFrançois Tigeot sizeof(struct bdb_header),
1458a85cb24fSFrançois Tigeot size)) {
1459ba55f2f5SFrançois Tigeot DRM_DEBUG_DRIVER("BDB header incomplete\n");
1460aee94f86SFrançois Tigeot return false;
1461ba55f2f5SFrançois Tigeot }
1462ba55f2f5SFrançois Tigeot
1463aee94f86SFrançois Tigeot bdb = get_bdb_header(vbt);
1464a85cb24fSFrançois Tigeot if (range_overflows_t(size_t, vbt->bdb_offset, bdb->bdb_size, size)) {
1465ba55f2f5SFrançois Tigeot DRM_DEBUG_DRIVER("BDB incomplete\n");
1466aee94f86SFrançois Tigeot return false;
1467ba55f2f5SFrançois Tigeot }
1468ba55f2f5SFrançois Tigeot
1469aee94f86SFrançois Tigeot return vbt;
1470ba55f2f5SFrançois Tigeot }
1471ba55f2f5SFrançois Tigeot
find_vbt(void __iomem * bios,size_t size)1472aee94f86SFrançois Tigeot static const struct vbt_header *find_vbt(void __iomem *bios, size_t size)
147319c468b4SFrançois Tigeot {
147419c468b4SFrançois Tigeot size_t i;
147519c468b4SFrançois Tigeot
147619c468b4SFrançois Tigeot /* Scour memory looking for the VBT signature. */
147719c468b4SFrançois Tigeot for (i = 0; i + 4 < size; i++) {
1478aee94f86SFrançois Tigeot void *vbt;
1479352ff8bdSFrançois Tigeot
1480aee94f86SFrançois Tigeot if (ioread32(bios + i) != *((const u32 *) "$VBT"))
1481aee94f86SFrançois Tigeot continue;
1482aee94f86SFrançois Tigeot
1483aee94f86SFrançois Tigeot /*
1484aee94f86SFrançois Tigeot * This is the one place where we explicitly discard the address
1485aee94f86SFrançois Tigeot * space (__iomem) of the BIOS/VBT.
1486aee94f86SFrançois Tigeot */
14871487f786SFrançois Tigeot vbt = (void __force *) bios + i;
1488aee94f86SFrançois Tigeot if (intel_bios_is_valid_vbt(vbt, size - i))
1489aee94f86SFrançois Tigeot return vbt;
1490aee94f86SFrançois Tigeot
149119c468b4SFrançois Tigeot break;
149219c468b4SFrançois Tigeot }
149319c468b4SFrançois Tigeot
1494aee94f86SFrançois Tigeot return NULL;
149519c468b4SFrançois Tigeot }
149619c468b4SFrançois Tigeot
1497e3adcf8fSFrançois Tigeot /**
1498aee94f86SFrançois Tigeot * intel_bios_init - find VBT and initialize settings from the BIOS
1499c0e85e96SFrançois Tigeot * @dev_priv: i915 device instance
1500e3adcf8fSFrançois Tigeot *
1501a85cb24fSFrançois Tigeot * Parse and initialize settings from the Video BIOS Tables (VBT). If the VBT
1502a85cb24fSFrançois Tigeot * was not found in ACPI OpRegion, try to find it in PCI ROM first. Also
1503a85cb24fSFrançois Tigeot * initialize some defaults if the VBT is not present at all.
1504e3adcf8fSFrançois Tigeot */
intel_bios_init(struct drm_i915_private * dev_priv)1505a85cb24fSFrançois Tigeot void intel_bios_init(struct drm_i915_private *dev_priv)
1506e3adcf8fSFrançois Tigeot {
1507303bf270SFrançois Tigeot struct pci_dev *pdev = dev_priv->drm.pdev;
1508aee94f86SFrançois Tigeot const struct vbt_header *vbt = dev_priv->opregion.vbt;
1509aee94f86SFrançois Tigeot const struct bdb_header *bdb;
1510e3440f96SFrançois Tigeot u8 __iomem *bios = NULL;
1511e3adcf8fSFrançois Tigeot
1512a85cb24fSFrançois Tigeot if (HAS_PCH_NOP(dev_priv)) {
1513a85cb24fSFrançois Tigeot DRM_DEBUG_KMS("Skipping VBT init due to disabled display.\n");
1514a85cb24fSFrançois Tigeot return;
1515a85cb24fSFrançois Tigeot }
15168e26cdf6SFrançois Tigeot
1517e3adcf8fSFrançois Tigeot init_vbt_defaults(dev_priv);
1518e3adcf8fSFrançois Tigeot
1519a85cb24fSFrançois Tigeot /* If the OpRegion does not have VBT, look in PCI ROM. */
1520aee94f86SFrançois Tigeot if (!vbt) {
152119c468b4SFrançois Tigeot size_t size;
1522e3adcf8fSFrançois Tigeot
1523e3adcf8fSFrançois Tigeot bios = pci_map_rom(pdev, &size);
1524e3adcf8fSFrançois Tigeot if (!bios)
1525a85cb24fSFrançois Tigeot goto out;
1526e3adcf8fSFrançois Tigeot
1527aee94f86SFrançois Tigeot vbt = find_vbt(bios, size);
1528a85cb24fSFrançois Tigeot if (!vbt)
1529a85cb24fSFrançois Tigeot goto out;
1530aee94f86SFrançois Tigeot
1531aee94f86SFrançois Tigeot DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
1532e3adcf8fSFrançois Tigeot }
1533e3adcf8fSFrançois Tigeot
1534aee94f86SFrançois Tigeot bdb = get_bdb_header(vbt);
1535aee94f86SFrançois Tigeot
1536aee94f86SFrançois Tigeot DRM_DEBUG_KMS("VBT signature \"%.*s\", BDB version %d\n",
1537aee94f86SFrançois Tigeot (int)sizeof(vbt->signature), vbt->signature, bdb->version);
1538aee94f86SFrançois Tigeot
1539e3adcf8fSFrançois Tigeot /* Grab useful general definitions */
1540e3adcf8fSFrançois Tigeot parse_general_features(dev_priv, bdb);
1541e3adcf8fSFrançois Tigeot parse_general_definitions(dev_priv, bdb);
1542e3adcf8fSFrançois Tigeot parse_lfp_panel_data(dev_priv, bdb);
15439edbd4a0SFrançois Tigeot parse_lfp_backlight(dev_priv, bdb);
1544e3adcf8fSFrançois Tigeot parse_sdvo_panel_data(dev_priv, bdb);
1545e3adcf8fSFrançois Tigeot parse_driver_features(dev_priv, bdb);
1546e3adcf8fSFrançois Tigeot parse_edp(dev_priv, bdb);
15472c9916cdSFrançois Tigeot parse_psr(dev_priv, bdb);
1548c0e85e96SFrançois Tigeot parse_mipi_config(dev_priv, bdb);
1549c0e85e96SFrançois Tigeot parse_mipi_sequence(dev_priv, bdb);
1550*3f2dd94aSFrançois Tigeot
1551*3f2dd94aSFrançois Tigeot /* Further processing on pre-parsed data */
1552*3f2dd94aSFrançois Tigeot parse_sdvo_device_mapping(dev_priv, bdb->version);
1553*3f2dd94aSFrançois Tigeot parse_ddi_ports(dev_priv, bdb->version);
1554e3adcf8fSFrançois Tigeot
1555a85cb24fSFrançois Tigeot out:
1556a85cb24fSFrançois Tigeot if (!vbt) {
1557a85cb24fSFrançois Tigeot DRM_INFO("Failed to find VBIOS tables (VBT)\n");
1558a85cb24fSFrançois Tigeot init_vbt_missing_defaults(dev_priv);
1559a85cb24fSFrançois Tigeot }
1560a85cb24fSFrançois Tigeot
1561e3adcf8fSFrançois Tigeot if (bios)
1562e3adcf8fSFrançois Tigeot pci_unmap_rom(pdev, bios);
1563e3adcf8fSFrançois Tigeot }
15648621f407SFrançois Tigeot
15658621f407SFrançois Tigeot /**
15668621f407SFrançois Tigeot * intel_bios_is_tv_present - is integrated TV present in VBT
15678621f407SFrançois Tigeot * @dev_priv: i915 device instance
15688621f407SFrançois Tigeot *
15698621f407SFrançois Tigeot * Return true if TV is present. If no child devices were parsed from VBT,
15708621f407SFrançois Tigeot * assume TV is present.
15718621f407SFrançois Tigeot */
intel_bios_is_tv_present(struct drm_i915_private * dev_priv)15728621f407SFrançois Tigeot bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv)
15738621f407SFrançois Tigeot {
1574*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
15758621f407SFrançois Tigeot int i;
15768621f407SFrançois Tigeot
15778621f407SFrançois Tigeot if (!dev_priv->vbt.int_tv_support)
15788621f407SFrançois Tigeot return false;
15798621f407SFrançois Tigeot
15808621f407SFrançois Tigeot if (!dev_priv->vbt.child_dev_num)
15818621f407SFrançois Tigeot return true;
15828621f407SFrançois Tigeot
15838621f407SFrançois Tigeot for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1584*3f2dd94aSFrançois Tigeot child = dev_priv->vbt.child_dev + i;
15858621f407SFrançois Tigeot /*
15868621f407SFrançois Tigeot * If the device type is not TV, continue.
15878621f407SFrançois Tigeot */
1588*3f2dd94aSFrançois Tigeot switch (child->device_type) {
15898621f407SFrançois Tigeot case DEVICE_TYPE_INT_TV:
15908621f407SFrançois Tigeot case DEVICE_TYPE_TV:
15918621f407SFrançois Tigeot case DEVICE_TYPE_TV_SVIDEO_COMPOSITE:
15928621f407SFrançois Tigeot break;
15938621f407SFrançois Tigeot default:
15948621f407SFrançois Tigeot continue;
15958621f407SFrançois Tigeot }
15968621f407SFrançois Tigeot /* Only when the addin_offset is non-zero, it is regarded
15978621f407SFrançois Tigeot * as present.
15988621f407SFrançois Tigeot */
1599*3f2dd94aSFrançois Tigeot if (child->addin_offset)
16008621f407SFrançois Tigeot return true;
16018621f407SFrançois Tigeot }
16028621f407SFrançois Tigeot
16038621f407SFrançois Tigeot return false;
16048621f407SFrançois Tigeot }
16058621f407SFrançois Tigeot
16068621f407SFrançois Tigeot /**
16078621f407SFrançois Tigeot * intel_bios_is_lvds_present - is LVDS present in VBT
16088621f407SFrançois Tigeot * @dev_priv: i915 device instance
16098621f407SFrançois Tigeot * @i2c_pin: i2c pin for LVDS if present
16108621f407SFrançois Tigeot *
16118621f407SFrançois Tigeot * Return true if LVDS is present. If no child devices were parsed from VBT,
16128621f407SFrançois Tigeot * assume LVDS is present.
16138621f407SFrançois Tigeot */
intel_bios_is_lvds_present(struct drm_i915_private * dev_priv,u8 * i2c_pin)16148621f407SFrançois Tigeot bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin)
16158621f407SFrançois Tigeot {
1616*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
16178621f407SFrançois Tigeot int i;
16188621f407SFrançois Tigeot
16198621f407SFrançois Tigeot if (!dev_priv->vbt.child_dev_num)
16208621f407SFrançois Tigeot return true;
16218621f407SFrançois Tigeot
16228621f407SFrançois Tigeot for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1623*3f2dd94aSFrançois Tigeot child = dev_priv->vbt.child_dev + i;
16248621f407SFrançois Tigeot
16258621f407SFrançois Tigeot /* If the device type is not LFP, continue.
16268621f407SFrançois Tigeot * We have to check both the new identifiers as well as the
16278621f407SFrançois Tigeot * old for compatibility with some BIOSes.
16288621f407SFrançois Tigeot */
16298621f407SFrançois Tigeot if (child->device_type != DEVICE_TYPE_INT_LFP &&
16308621f407SFrançois Tigeot child->device_type != DEVICE_TYPE_LFP)
16318621f407SFrançois Tigeot continue;
16328621f407SFrançois Tigeot
16338621f407SFrançois Tigeot if (intel_gmbus_is_valid_pin(dev_priv, child->i2c_pin))
16348621f407SFrançois Tigeot *i2c_pin = child->i2c_pin;
16358621f407SFrançois Tigeot
16368621f407SFrançois Tigeot /* However, we cannot trust the BIOS writers to populate
16378621f407SFrançois Tigeot * the VBT correctly. Since LVDS requires additional
16388621f407SFrançois Tigeot * information from AIM blocks, a non-zero addin offset is
16398621f407SFrançois Tigeot * a good indicator that the LVDS is actually present.
16408621f407SFrançois Tigeot */
16418621f407SFrançois Tigeot if (child->addin_offset)
16428621f407SFrançois Tigeot return true;
16438621f407SFrançois Tigeot
16448621f407SFrançois Tigeot /* But even then some BIOS writers perform some black magic
16458621f407SFrançois Tigeot * and instantiate the device without reference to any
16468621f407SFrançois Tigeot * additional data. Trust that if the VBT was written into
16478621f407SFrançois Tigeot * the OpRegion then they have validated the LVDS's existence.
16488621f407SFrançois Tigeot */
16498621f407SFrançois Tigeot if (dev_priv->opregion.vbt)
16508621f407SFrançois Tigeot return true;
16518621f407SFrançois Tigeot }
16528621f407SFrançois Tigeot
16538621f407SFrançois Tigeot return false;
16548621f407SFrançois Tigeot }
16558621f407SFrançois Tigeot
16568621f407SFrançois Tigeot /**
16578621f407SFrançois Tigeot * intel_bios_is_port_present - is the specified digital port present
16588621f407SFrançois Tigeot * @dev_priv: i915 device instance
16598621f407SFrançois Tigeot * @port: port to check
16608621f407SFrançois Tigeot *
16618621f407SFrançois Tigeot * Return true if the device in %port is present.
16628621f407SFrançois Tigeot */
intel_bios_is_port_present(struct drm_i915_private * dev_priv,enum port port)16638621f407SFrançois Tigeot bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port)
16648621f407SFrançois Tigeot {
1665*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
16668621f407SFrançois Tigeot static const struct {
16678621f407SFrançois Tigeot u16 dp, hdmi;
16688621f407SFrançois Tigeot } port_mapping[] = {
16698621f407SFrançois Tigeot [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
16708621f407SFrançois Tigeot [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
16718621f407SFrançois Tigeot [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
16728621f407SFrançois Tigeot [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
16738621f407SFrançois Tigeot };
16748621f407SFrançois Tigeot int i;
16758621f407SFrançois Tigeot
16768621f407SFrançois Tigeot /* FIXME maybe deal with port A as well? */
16778621f407SFrançois Tigeot if (WARN_ON(port == PORT_A) || port >= ARRAY_SIZE(port_mapping))
16788621f407SFrançois Tigeot return false;
16798621f407SFrançois Tigeot
16808621f407SFrançois Tigeot if (!dev_priv->vbt.child_dev_num)
16818621f407SFrançois Tigeot return false;
16828621f407SFrançois Tigeot
16838621f407SFrançois Tigeot for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1684*3f2dd94aSFrançois Tigeot child = dev_priv->vbt.child_dev + i;
1685*3f2dd94aSFrançois Tigeot
1686*3f2dd94aSFrançois Tigeot if ((child->dvo_port == port_mapping[port].dp ||
1687*3f2dd94aSFrançois Tigeot child->dvo_port == port_mapping[port].hdmi) &&
1688*3f2dd94aSFrançois Tigeot (child->device_type & (DEVICE_TYPE_TMDS_DVI_SIGNALING |
16898621f407SFrançois Tigeot DEVICE_TYPE_DISPLAYPORT_OUTPUT)))
16908621f407SFrançois Tigeot return true;
16918621f407SFrançois Tigeot }
16928621f407SFrançois Tigeot
16938621f407SFrançois Tigeot return false;
16948621f407SFrançois Tigeot }
16958621f407SFrançois Tigeot
16968621f407SFrançois Tigeot /**
16978621f407SFrançois Tigeot * intel_bios_is_port_edp - is the device in given port eDP
16988621f407SFrançois Tigeot * @dev_priv: i915 device instance
16998621f407SFrançois Tigeot * @port: port to check
17008621f407SFrançois Tigeot *
17018621f407SFrançois Tigeot * Return true if the device in %port is eDP.
17028621f407SFrançois Tigeot */
intel_bios_is_port_edp(struct drm_i915_private * dev_priv,enum port port)17038621f407SFrançois Tigeot bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
17048621f407SFrançois Tigeot {
1705*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
17068621f407SFrançois Tigeot static const short port_mapping[] = {
17078621f407SFrançois Tigeot [PORT_B] = DVO_PORT_DPB,
17088621f407SFrançois Tigeot [PORT_C] = DVO_PORT_DPC,
17098621f407SFrançois Tigeot [PORT_D] = DVO_PORT_DPD,
17108621f407SFrançois Tigeot [PORT_E] = DVO_PORT_DPE,
17118621f407SFrançois Tigeot };
17128621f407SFrançois Tigeot int i;
17138621f407SFrançois Tigeot
1714a85cb24fSFrançois Tigeot if (HAS_DDI(dev_priv))
1715a85cb24fSFrançois Tigeot return dev_priv->vbt.ddi_port_info[port].supports_edp;
1716a85cb24fSFrançois Tigeot
17178621f407SFrançois Tigeot if (!dev_priv->vbt.child_dev_num)
17188621f407SFrançois Tigeot return false;
17198621f407SFrançois Tigeot
17208621f407SFrançois Tigeot for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1721*3f2dd94aSFrançois Tigeot child = dev_priv->vbt.child_dev + i;
17228621f407SFrançois Tigeot
1723*3f2dd94aSFrançois Tigeot if (child->dvo_port == port_mapping[port] &&
1724*3f2dd94aSFrançois Tigeot (child->device_type & DEVICE_TYPE_eDP_BITS) ==
17258621f407SFrançois Tigeot (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
17268621f407SFrançois Tigeot return true;
17278621f407SFrançois Tigeot }
17288621f407SFrançois Tigeot
17298621f407SFrançois Tigeot return false;
17308621f407SFrançois Tigeot }
17318621f407SFrançois Tigeot
child_dev_is_dp_dual_mode(const struct child_device_config * child,enum port port)1732*3f2dd94aSFrançois Tigeot static bool child_dev_is_dp_dual_mode(const struct child_device_config *child,
17334be47400SFrançois Tigeot enum port port)
17348621f407SFrançois Tigeot {
17358621f407SFrançois Tigeot static const struct {
17368621f407SFrançois Tigeot u16 dp, hdmi;
17378621f407SFrançois Tigeot } port_mapping[] = {
17388621f407SFrançois Tigeot /*
17398621f407SFrançois Tigeot * Buggy VBTs may declare DP ports as having
17408621f407SFrançois Tigeot * HDMI type dvo_port :( So let's check both.
17418621f407SFrançois Tigeot */
17428621f407SFrançois Tigeot [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
17438621f407SFrançois Tigeot [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
17448621f407SFrançois Tigeot [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
17458621f407SFrançois Tigeot [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
17468621f407SFrançois Tigeot };
17478621f407SFrançois Tigeot
17488621f407SFrançois Tigeot if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
17498621f407SFrançois Tigeot return false;
17508621f407SFrançois Tigeot
1751*3f2dd94aSFrançois Tigeot if ((child->device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) !=
17524be47400SFrançois Tigeot (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
17538621f407SFrançois Tigeot return false;
17548621f407SFrançois Tigeot
1755*3f2dd94aSFrançois Tigeot if (child->dvo_port == port_mapping[port].dp)
17564be47400SFrançois Tigeot return true;
17574be47400SFrançois Tigeot
17584be47400SFrançois Tigeot /* Only accept a HDMI dvo_port as DP++ if it has an AUX channel */
1759*3f2dd94aSFrançois Tigeot if (child->dvo_port == port_mapping[port].hdmi &&
1760*3f2dd94aSFrançois Tigeot child->aux_channel != 0)
17614be47400SFrançois Tigeot return true;
17624be47400SFrançois Tigeot
17634be47400SFrançois Tigeot return false;
17644be47400SFrançois Tigeot }
17654be47400SFrançois Tigeot
intel_bios_is_port_dp_dual_mode(struct drm_i915_private * dev_priv,enum port port)17664be47400SFrançois Tigeot bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv,
17674be47400SFrançois Tigeot enum port port)
17684be47400SFrançois Tigeot {
1769*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
17704be47400SFrançois Tigeot int i;
17714be47400SFrançois Tigeot
17728621f407SFrançois Tigeot for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1773*3f2dd94aSFrançois Tigeot child = dev_priv->vbt.child_dev + i;
17748621f407SFrançois Tigeot
1775*3f2dd94aSFrançois Tigeot if (child_dev_is_dp_dual_mode(child, port))
17768621f407SFrançois Tigeot return true;
17778621f407SFrançois Tigeot }
17788621f407SFrançois Tigeot
17798621f407SFrançois Tigeot return false;
17808621f407SFrançois Tigeot }
17818621f407SFrançois Tigeot
17828621f407SFrançois Tigeot /**
17838621f407SFrançois Tigeot * intel_bios_is_dsi_present - is DSI present in VBT
17848621f407SFrançois Tigeot * @dev_priv: i915 device instance
17858621f407SFrançois Tigeot * @port: port for DSI if present
17868621f407SFrançois Tigeot *
17878621f407SFrançois Tigeot * Return true if DSI is present, and return the port in %port.
17888621f407SFrançois Tigeot */
intel_bios_is_dsi_present(struct drm_i915_private * dev_priv,enum port * port)17898621f407SFrançois Tigeot bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv,
17908621f407SFrançois Tigeot enum port *port)
17918621f407SFrançois Tigeot {
1792*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
17938621f407SFrançois Tigeot u8 dvo_port;
17948621f407SFrançois Tigeot int i;
17958621f407SFrançois Tigeot
17968621f407SFrançois Tigeot for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1797*3f2dd94aSFrançois Tigeot child = dev_priv->vbt.child_dev + i;
17988621f407SFrançois Tigeot
1799*3f2dd94aSFrançois Tigeot if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT))
18008621f407SFrançois Tigeot continue;
18018621f407SFrançois Tigeot
1802*3f2dd94aSFrançois Tigeot dvo_port = child->dvo_port;
18038621f407SFrançois Tigeot
18048621f407SFrançois Tigeot switch (dvo_port) {
18058621f407SFrançois Tigeot case DVO_PORT_MIPIA:
18068621f407SFrançois Tigeot case DVO_PORT_MIPIC:
18078621f407SFrançois Tigeot if (port)
18088621f407SFrançois Tigeot *port = dvo_port - DVO_PORT_MIPIA;
18098621f407SFrançois Tigeot return true;
18108621f407SFrançois Tigeot case DVO_PORT_MIPIB:
18118621f407SFrançois Tigeot case DVO_PORT_MIPID:
18128621f407SFrançois Tigeot DRM_DEBUG_KMS("VBT has unsupported DSI port %c\n",
18138621f407SFrançois Tigeot port_name(dvo_port - DVO_PORT_MIPIA));
18148621f407SFrançois Tigeot break;
18158621f407SFrançois Tigeot }
18168621f407SFrançois Tigeot }
18178621f407SFrançois Tigeot
18188621f407SFrançois Tigeot return false;
18198621f407SFrançois Tigeot }
18208621f407SFrançois Tigeot
18218621f407SFrançois Tigeot /**
18228621f407SFrançois Tigeot * intel_bios_is_port_hpd_inverted - is HPD inverted for %port
18238621f407SFrançois Tigeot * @dev_priv: i915 device instance
18248621f407SFrançois Tigeot * @port: port to check
18258621f407SFrançois Tigeot *
18268621f407SFrançois Tigeot * Return true if HPD should be inverted for %port.
18278621f407SFrançois Tigeot */
18288621f407SFrançois Tigeot bool
intel_bios_is_port_hpd_inverted(struct drm_i915_private * dev_priv,enum port port)18298621f407SFrançois Tigeot intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
18308621f407SFrançois Tigeot enum port port)
18318621f407SFrançois Tigeot {
1832*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
18338621f407SFrançois Tigeot int i;
18348621f407SFrançois Tigeot
1835a85cb24fSFrançois Tigeot if (WARN_ON_ONCE(!IS_GEN9_LP(dev_priv)))
18368621f407SFrançois Tigeot return false;
18378621f407SFrançois Tigeot
18388621f407SFrançois Tigeot for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1839*3f2dd94aSFrançois Tigeot child = dev_priv->vbt.child_dev + i;
1840*3f2dd94aSFrançois Tigeot
1841*3f2dd94aSFrançois Tigeot if (!child->hpd_invert)
18428621f407SFrançois Tigeot continue;
18438621f407SFrançois Tigeot
1844*3f2dd94aSFrançois Tigeot switch (child->dvo_port) {
18458621f407SFrançois Tigeot case DVO_PORT_DPA:
18468621f407SFrançois Tigeot case DVO_PORT_HDMIA:
18478621f407SFrançois Tigeot if (port == PORT_A)
18488621f407SFrançois Tigeot return true;
18498621f407SFrançois Tigeot break;
18508621f407SFrançois Tigeot case DVO_PORT_DPB:
18518621f407SFrançois Tigeot case DVO_PORT_HDMIB:
18528621f407SFrançois Tigeot if (port == PORT_B)
18538621f407SFrançois Tigeot return true;
18548621f407SFrançois Tigeot break;
18558621f407SFrançois Tigeot case DVO_PORT_DPC:
18568621f407SFrançois Tigeot case DVO_PORT_HDMIC:
18578621f407SFrançois Tigeot if (port == PORT_C)
18588621f407SFrançois Tigeot return true;
18598621f407SFrançois Tigeot break;
18608621f407SFrançois Tigeot default:
18618621f407SFrançois Tigeot break;
18628621f407SFrançois Tigeot }
18638621f407SFrançois Tigeot }
18648621f407SFrançois Tigeot
18658621f407SFrançois Tigeot return false;
18668621f407SFrançois Tigeot }
18671e12ee3bSFrançois Tigeot
18681e12ee3bSFrançois Tigeot /**
18691e12ee3bSFrançois Tigeot * intel_bios_is_lspcon_present - if LSPCON is attached on %port
18701e12ee3bSFrançois Tigeot * @dev_priv: i915 device instance
18711e12ee3bSFrançois Tigeot * @port: port to check
18721e12ee3bSFrançois Tigeot *
18731e12ee3bSFrançois Tigeot * Return true if LSPCON is present on this port
18741e12ee3bSFrançois Tigeot */
18751e12ee3bSFrançois Tigeot bool
intel_bios_is_lspcon_present(struct drm_i915_private * dev_priv,enum port port)18761e12ee3bSFrançois Tigeot intel_bios_is_lspcon_present(struct drm_i915_private *dev_priv,
18771e12ee3bSFrançois Tigeot enum port port)
18781e12ee3bSFrançois Tigeot {
1879*3f2dd94aSFrançois Tigeot const struct child_device_config *child;
18801e12ee3bSFrançois Tigeot int i;
18811e12ee3bSFrançois Tigeot
18821e12ee3bSFrançois Tigeot if (!HAS_LSPCON(dev_priv))
18831e12ee3bSFrançois Tigeot return false;
18841e12ee3bSFrançois Tigeot
18851e12ee3bSFrançois Tigeot for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1886*3f2dd94aSFrançois Tigeot child = dev_priv->vbt.child_dev + i;
1887*3f2dd94aSFrançois Tigeot
1888*3f2dd94aSFrançois Tigeot if (!child->lspcon)
18891e12ee3bSFrançois Tigeot continue;
18901e12ee3bSFrançois Tigeot
1891*3f2dd94aSFrançois Tigeot switch (child->dvo_port) {
18921e12ee3bSFrançois Tigeot case DVO_PORT_DPA:
18931e12ee3bSFrançois Tigeot case DVO_PORT_HDMIA:
18941e12ee3bSFrançois Tigeot if (port == PORT_A)
18951e12ee3bSFrançois Tigeot return true;
18961e12ee3bSFrançois Tigeot break;
18971e12ee3bSFrançois Tigeot case DVO_PORT_DPB:
18981e12ee3bSFrançois Tigeot case DVO_PORT_HDMIB:
18991e12ee3bSFrançois Tigeot if (port == PORT_B)
19001e12ee3bSFrançois Tigeot return true;
19011e12ee3bSFrançois Tigeot break;
19021e12ee3bSFrançois Tigeot case DVO_PORT_DPC:
19031e12ee3bSFrançois Tigeot case DVO_PORT_HDMIC:
19041e12ee3bSFrançois Tigeot if (port == PORT_C)
19051e12ee3bSFrançois Tigeot return true;
19061e12ee3bSFrançois Tigeot break;
19071e12ee3bSFrançois Tigeot case DVO_PORT_DPD:
19081e12ee3bSFrançois Tigeot case DVO_PORT_HDMID:
19091e12ee3bSFrançois Tigeot if (port == PORT_D)
19101e12ee3bSFrançois Tigeot return true;
19111e12ee3bSFrançois Tigeot break;
19121e12ee3bSFrançois Tigeot default:
19131e12ee3bSFrançois Tigeot break;
19141e12ee3bSFrançois Tigeot }
19151e12ee3bSFrançois Tigeot }
19161e12ee3bSFrançois Tigeot
19171e12ee3bSFrançois Tigeot return false;
19181e12ee3bSFrançois Tigeot }
1919