blob: 422ba76700e3de02a36c9a7669e81a881b52258e [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
Keith Packard39507252011-09-22 12:30:16 -07002 * Copyright © 2006 Intel Corporation
Jesse Barnes79e53942008-11-07 14:24:08 -08003 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
25 *
26 */
Jani Nikulab30581a2015-12-14 12:50:46 +020027
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -070028#include <drm/drm_dp_helper.h>
David Howells760285e2012-10-02 18:01:07 +010029#include <drm/drmP.h>
30#include <drm/i915_drm.h>
Jesse Barnes79e53942008-11-07 14:24:08 -080031#include "i915_drv.h"
32#include "intel_bios.h"
33
Jani Nikuladd97950a2015-12-21 15:10:52 +020034/**
35 * DOC: Video BIOS Table (VBT)
36 *
37 * The Video BIOS Table, or VBT, provides platform and board specific
38 * configuration information to the driver that is not discoverable or available
39 * through other means. The configuration is mostly related to display
40 * hardware. The VBT is available via the ACPI OpRegion or, on older systems, in
41 * the PCI ROM.
42 *
43 * The VBT consists of a VBT Header (defined as &struct vbt_header), a BDB
44 * Header (&struct bdb_header), and a number of BIOS Data Blocks (BDB) that
45 * contain the actual configuration information. The VBT Header, and thus the
46 * VBT, begins with "$VBT" signature. The VBT Header contains the offset of the
47 * BDB Header. The data blocks are concatenated after the BDB Header. The data
48 * blocks have a 1-byte Block ID, 2-byte Block Size, and Block Size bytes of
49 * data. (Block 53, the MIPI Sequence Block is an exception.)
50 *
51 * The driver parses the VBT during load. The relevant information is stored in
52 * driver private data for ease of use, and the actual VBT is not read after
53 * that.
54 */
55
yakui_zhao9b9d1722009-05-31 17:17:17 +080056#define SLAVE_ADDR1 0x70
57#define SLAVE_ADDR2 0x72
Jesse Barnes79e53942008-11-07 14:24:08 -080058
Zhenyu Wang500a8cc2010-01-13 11:19:52 +080059static int panel_type;
60
Jani Nikula08c08882015-12-21 15:10:55 +020061/* Get BDB block size given a pointer to Block ID. */
62static u32 _get_blocksize(const u8 *block_base)
63{
64 /* The MIPI Sequence Block v3+ has a separate size field. */
65 if (*block_base == BDB_MIPI_SEQUENCE && *(block_base + 3) >= 3)
66 return *((const u32 *)(block_base + 4));
67 else
68 return *((const u16 *)(block_base + 1));
69}
70
71/* Get BDB block size give a pointer to data after Block ID and Block Size. */
72static u32 get_blocksize(const void *block_data)
73{
74 return _get_blocksize(block_data - 3);
75}
76
Jani Nikulae8ef3b42015-04-15 15:18:28 +030077static const void *
78find_section(const void *_bdb, int section_id)
Jesse Barnes79e53942008-11-07 14:24:08 -080079{
Jani Nikulae8ef3b42015-04-15 15:18:28 +030080 const struct bdb_header *bdb = _bdb;
81 const u8 *base = _bdb;
Jesse Barnes79e53942008-11-07 14:24:08 -080082 int index = 0;
Jani Nikulacd67d222015-09-17 16:42:07 +030083 u32 total, current_size;
Jesse Barnes79e53942008-11-07 14:24:08 -080084 u8 current_id;
85
86 /* skip to first section */
87 index += bdb->header_size;
88 total = bdb->bdb_size;
89
90 /* walk the sections looking for section_id */
Chris Wilsond1f13fd2014-04-18 18:04:23 -030091 while (index + 3 < total) {
Jesse Barnes79e53942008-11-07 14:24:08 -080092 current_id = *(base + index);
Jani Nikula08c08882015-12-21 15:10:55 +020093 current_size = _get_blocksize(base + index);
94 index += 3;
Jani Nikulacd67d222015-09-17 16:42:07 +030095
Chris Wilsond1f13fd2014-04-18 18:04:23 -030096 if (index + current_size > total)
97 return NULL;
98
Jesse Barnes79e53942008-11-07 14:24:08 -080099 if (current_id == section_id)
100 return base + index;
Chris Wilsond1f13fd2014-04-18 18:04:23 -0300101
Jesse Barnes79e53942008-11-07 14:24:08 -0800102 index += current_size;
103 }
104
105 return NULL;
106}
107
Jesse Barnes79e53942008-11-07 14:24:08 -0800108static void
Ma Ling88631702009-05-13 11:19:55 +0800109fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
Chris Wilson99834ea2011-07-13 21:01:46 +0100110 const struct lvds_dvo_timing *dvo_timing)
Ma Ling88631702009-05-13 11:19:55 +0800111{
112 panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
113 dvo_timing->hactive_lo;
114 panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
115 ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
116 panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
117 dvo_timing->hsync_pulse_width;
118 panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
119 ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
120
121 panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
122 dvo_timing->vactive_lo;
123 panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
124 dvo_timing->vsync_off;
125 panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
126 dvo_timing->vsync_pulse_width;
127 panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
128 ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
129 panel_fixed_mode->clock = dvo_timing->clock * 10;
130 panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
131
Adam Jackson9bc35492010-05-28 17:17:37 -0400132 if (dvo_timing->hsync_positive)
133 panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
134 else
135 panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
136
137 if (dvo_timing->vsync_positive)
138 panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
139 else
140 panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
141
Ma Ling88631702009-05-13 11:19:55 +0800142 /* Some VBTs have bogus h/vtotal values */
143 if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
144 panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
145 if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
146 panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
147
148 drm_mode_set_name(panel_fixed_mode);
149}
150
Chris Wilson99834ea2011-07-13 21:01:46 +0100151static const struct lvds_dvo_timing *
152get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
153 const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
154 int index)
155{
156 /*
157 * the size of fp_timing varies on the different platform.
158 * So calculate the DVO timing relative offset in LVDS data
159 * entry to get the DVO timing entry
160 */
161
162 int lfp_data_size =
163 lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
164 lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
165 int dvo_timing_offset =
166 lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
167 lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
168 char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
169
170 return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
171}
172
Takashi Iwaib0354382012-03-20 13:07:05 +0100173/* get lvds_fp_timing entry
174 * this function may return NULL if the corresponding entry is invalid
175 */
176static const struct lvds_fp_timing *
177get_lvds_fp_timing(const struct bdb_header *bdb,
178 const struct bdb_lvds_lfp_data *data,
179 const struct bdb_lvds_lfp_data_ptrs *ptrs,
180 int index)
181{
182 size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
183 u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
184 size_t ofs;
185
186 if (index >= ARRAY_SIZE(ptrs->ptr))
187 return NULL;
188 ofs = ptrs->ptr[index].fp_timing_offset;
189 if (ofs < data_ofs ||
190 ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
191 return NULL;
192 return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
193}
194
Ma Ling88631702009-05-13 11:19:55 +0800195/* Try to find integrated panel data */
196static void
197parse_lfp_panel_data(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +0300198 const struct bdb_header *bdb)
Jesse Barnes79e53942008-11-07 14:24:08 -0800199{
Chris Wilson99834ea2011-07-13 21:01:46 +0100200 const struct bdb_lvds_options *lvds_options;
201 const struct bdb_lvds_lfp_data *lvds_lfp_data;
202 const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
203 const struct lvds_dvo_timing *panel_dvo_timing;
Takashi Iwaib0354382012-03-20 13:07:05 +0100204 const struct lvds_fp_timing *fp_timing;
Jesse Barnes79e53942008-11-07 14:24:08 -0800205 struct drm_display_mode *panel_fixed_mode;
Daniel Vetterc329a4e2015-06-18 10:30:23 +0200206 int drrs_mode;
Jesse Barnes79e53942008-11-07 14:24:08 -0800207
Jesse Barnes79e53942008-11-07 14:24:08 -0800208 lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
209 if (!lvds_options)
210 return;
211
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300212 dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
Jesse Barnes79e53942008-11-07 14:24:08 -0800213 if (lvds_options->panel_type == 0xff)
214 return;
Simon Que6a040022010-09-30 09:36:39 +0100215
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800216 panel_type = lvds_options->panel_type;
Jesse Barnes79e53942008-11-07 14:24:08 -0800217
Pradeep Bhat83a72802014-03-28 10:14:57 +0530218 drrs_mode = (lvds_options->dps_panel_type_bits
219 >> (panel_type * 2)) & MODE_MASK;
220 /*
221 * VBT has static DRRS = 0 and seamless DRRS = 2.
222 * The below piece of code is required to adjust vbt.drrs_type
223 * to match the enum drrs_support_type.
224 */
225 switch (drrs_mode) {
226 case 0:
227 dev_priv->vbt.drrs_type = STATIC_DRRS_SUPPORT;
228 DRM_DEBUG_KMS("DRRS supported mode is static\n");
229 break;
230 case 2:
231 dev_priv->vbt.drrs_type = SEAMLESS_DRRS_SUPPORT;
232 DRM_DEBUG_KMS("DRRS supported mode is seamless\n");
233 break;
234 default:
235 dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
236 DRM_DEBUG_KMS("DRRS not supported (VBT input)\n");
237 break;
238 }
239
Jesse Barnes79e53942008-11-07 14:24:08 -0800240 lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
241 if (!lvds_lfp_data)
242 return;
243
Jesse Barnes1b16de02009-06-22 11:30:30 -0700244 lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
245 if (!lvds_lfp_data_ptrs)
246 return;
247
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300248 dev_priv->vbt.lvds_vbt = 1;
Jesse Barnes79e53942008-11-07 14:24:08 -0800249
Chris Wilson99834ea2011-07-13 21:01:46 +0100250 panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
251 lvds_lfp_data_ptrs,
252 lvds_options->panel_type);
Jesse Barnes79e53942008-11-07 14:24:08 -0800253
Eric Anholt9a298b22009-03-24 12:23:04 -0700254 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
Chris Wilson6edc3242010-09-12 17:16:17 +0100255 if (!panel_fixed_mode)
256 return;
Jesse Barnes79e53942008-11-07 14:24:08 -0800257
Chris Wilson99834ea2011-07-13 21:01:46 +0100258 fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
Jesse Barnes79e53942008-11-07 14:24:08 -0800259
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300260 dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
Jesse Barnes79e53942008-11-07 14:24:08 -0800261
Zhao Yakui28c97732009-10-09 11:39:41 +0800262 DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
Jesse Barnes79e53942008-11-07 14:24:08 -0800263 drm_mode_debug_printmodeline(panel_fixed_mode);
264
Takashi Iwaib0354382012-03-20 13:07:05 +0100265 fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
266 lvds_lfp_data_ptrs,
267 lvds_options->panel_type);
268 if (fp_timing) {
269 /* check the resolution, just to be sure */
270 if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
271 fp_timing->y_res == panel_fixed_mode->vdisplay) {
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300272 dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
Takashi Iwaib0354382012-03-20 13:07:05 +0100273 DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300274 dev_priv->vbt.bios_lvds_val);
Takashi Iwaib0354382012-03-20 13:07:05 +0100275 }
276 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800277}
278
Jani Nikulaf00076d2013-12-14 20:38:29 -0200279static void
Jani Nikuladcb58a42015-05-12 15:41:32 +0300280parse_lfp_backlight(struct drm_i915_private *dev_priv,
281 const struct bdb_header *bdb)
Jani Nikulaf00076d2013-12-14 20:38:29 -0200282{
283 const struct bdb_lfp_backlight_data *backlight_data;
284 const struct bdb_lfp_backlight_data_entry *entry;
285
286 backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
287 if (!backlight_data)
288 return;
289
290 if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
291 DRM_DEBUG_KMS("Unsupported backlight data entry size %u\n",
292 backlight_data->entry_size);
293 return;
294 }
295
296 entry = &backlight_data->data[panel_type];
297
Jani Nikula39fbc9c2014-04-09 11:22:06 +0300298 dev_priv->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
299 if (!dev_priv->vbt.backlight.present) {
300 DRM_DEBUG_KMS("PWM backlight not present in VBT (type %u)\n",
301 entry->type);
302 return;
303 }
304
Jani Nikulaf00076d2013-12-14 20:38:29 -0200305 dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
306 dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
Jani Nikula1de60682014-06-24 18:27:39 +0300307 dev_priv->vbt.backlight.min_brightness = entry->min_brightness;
Jani Nikulaf00076d2013-12-14 20:38:29 -0200308 DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
309 "active %s, min brightness %u, level %u\n",
310 dev_priv->vbt.backlight.pwm_freq_hz,
311 dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
Jani Nikula1de60682014-06-24 18:27:39 +0300312 dev_priv->vbt.backlight.min_brightness,
Jani Nikulaf00076d2013-12-14 20:38:29 -0200313 backlight_data->level[panel_type]);
314}
315
Ma Ling88631702009-05-13 11:19:55 +0800316/* Try to find sdvo panel data */
317static void
318parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +0300319 const struct bdb_header *bdb)
Ma Ling88631702009-05-13 11:19:55 +0800320{
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300321 const struct lvds_dvo_timing *dvo_timing;
Ma Ling88631702009-05-13 11:19:55 +0800322 struct drm_display_mode *panel_fixed_mode;
Chris Wilson5a1e5b62011-01-29 16:50:25 +0000323 int index;
Ma Ling88631702009-05-13 11:19:55 +0800324
Jani Nikulad330a952014-01-21 11:24:25 +0200325 index = i915.vbt_sdvo_panel_type;
Mathias Fröhlichc10e4082012-03-01 06:44:35 +0100326 if (index == -2) {
327 DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
328 return;
329 }
330
Chris Wilson5a1e5b62011-01-29 16:50:25 +0000331 if (index == -1) {
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300332 const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
Chris Wilson5a1e5b62011-01-29 16:50:25 +0000333
334 sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
335 if (!sdvo_lvds_options)
336 return;
337
338 index = sdvo_lvds_options->panel_type;
339 }
Ma Ling88631702009-05-13 11:19:55 +0800340
341 dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
342 if (!dvo_timing)
343 return;
344
Eric Anholt9a298b22009-03-24 12:23:04 -0700345 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
Ma Ling88631702009-05-13 11:19:55 +0800346 if (!panel_fixed_mode)
347 return;
348
Chris Wilson5a1e5b62011-01-29 16:50:25 +0000349 fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
Ma Ling88631702009-05-13 11:19:55 +0800350
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300351 dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
Ma Ling88631702009-05-13 11:19:55 +0800352
Chris Wilson5a1e5b62011-01-29 16:50:25 +0000353 DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
354 drm_mode_debug_printmodeline(panel_fixed_mode);
Ma Ling88631702009-05-13 11:19:55 +0800355}
356
Jani Nikula98f3a1d2015-12-16 15:04:20 +0200357static int intel_bios_ssc_frequency(struct drm_i915_private *dev_priv,
Bryan Freed9a4114f2011-01-12 13:38:39 -0800358 bool alternate)
359{
Jani Nikula98f3a1d2015-12-16 15:04:20 +0200360 switch (INTEL_INFO(dev_priv)->gen) {
Bryan Freed9a4114f2011-01-12 13:38:39 -0800361 case 2:
Ville Syrjäläe91e9412013-12-09 18:54:16 +0200362 return alternate ? 66667 : 48000;
Bryan Freed9a4114f2011-01-12 13:38:39 -0800363 case 3:
364 case 4:
Ville Syrjäläe91e9412013-12-09 18:54:16 +0200365 return alternate ? 100000 : 96000;
Bryan Freed9a4114f2011-01-12 13:38:39 -0800366 default:
Ville Syrjäläe91e9412013-12-09 18:54:16 +0200367 return alternate ? 100000 : 120000;
Bryan Freed9a4114f2011-01-12 13:38:39 -0800368 }
369}
370
Jesse Barnes79e53942008-11-07 14:24:08 -0800371static void
372parse_general_features(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +0300373 const struct bdb_header *bdb)
Jesse Barnes79e53942008-11-07 14:24:08 -0800374{
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300375 const struct bdb_general_features *general;
Jesse Barnes79e53942008-11-07 14:24:08 -0800376
Jesse Barnes79e53942008-11-07 14:24:08 -0800377 general = find_section(bdb, BDB_GENERAL_FEATURES);
Jani Nikula34957e82015-12-16 15:04:21 +0200378 if (!general)
379 return;
380
381 dev_priv->vbt.int_tv_support = general->int_tv_support;
382 /* int_crt_support can't be trusted on earlier platforms */
383 if (bdb->version >= 155 &&
384 (HAS_DDI(dev_priv) || IS_VALLEYVIEW(dev_priv)))
385 dev_priv->vbt.int_crt_support = general->int_crt_support;
386 dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
387 dev_priv->vbt.lvds_ssc_freq =
388 intel_bios_ssc_frequency(dev_priv, general->ssc_freq);
389 dev_priv->vbt.display_clock_mode = general->display_clock_mode;
390 dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
391 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",
392 dev_priv->vbt.int_tv_support,
393 dev_priv->vbt.int_crt_support,
394 dev_priv->vbt.lvds_use_ssc,
395 dev_priv->vbt.lvds_ssc_freq,
396 dev_priv->vbt.display_clock_mode,
397 dev_priv->vbt.fdi_rx_polarity_inverted);
Jesse Barnes79e53942008-11-07 14:24:08 -0800398}
399
yakui_zhao9b9d1722009-05-31 17:17:17 +0800400static void
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200401parse_general_definitions(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +0300402 const struct bdb_header *bdb)
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200403{
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300404 const struct bdb_general_definitions *general;
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200405
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200406 general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
407 if (general) {
408 u16 block_size = get_blocksize(general);
409 if (block_size >= sizeof(*general)) {
410 int bus_pin = general->crt_ddc_gmbus_pin;
Zhao Yakui28c97732009-10-09 11:39:41 +0800411 DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
Jani Nikula88ac7932015-03-27 00:20:22 +0200412 if (intel_gmbus_is_valid_pin(dev_priv, bus_pin))
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300413 dev_priv->vbt.crt_ddc_pin = bus_pin;
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200414 } else {
Zhao Yakui28c97732009-10-09 11:39:41 +0800415 DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
Daniel Kurtz3bd7d902012-03-28 02:36:14 +0800416 block_size);
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200417 }
418 }
419}
420
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300421static const union child_device_config *
422child_device_ptr(const struct bdb_general_definitions *p_defs, int i)
Ville Syrjälä90e4f152015-03-25 18:45:58 +0200423{
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300424 return (const void *) &p_defs->devices[i * p_defs->child_dev_size];
Ville Syrjälä90e4f152015-03-25 18:45:58 +0200425}
426
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200427static void
yakui_zhao9b9d1722009-05-31 17:17:17 +0800428parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +0300429 const struct bdb_header *bdb)
yakui_zhao9b9d1722009-05-31 17:17:17 +0800430{
431 struct sdvo_device_mapping *p_mapping;
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300432 const struct bdb_general_definitions *p_defs;
Jani Nikula6cc38ac2015-08-18 14:28:55 +0300433 const struct old_child_dev_config *child; /* legacy */
yakui_zhao9b9d1722009-05-31 17:17:17 +0800434 int i, child_device_num, count;
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200435 u16 block_size;
yakui_zhao9b9d1722009-05-31 17:17:17 +0800436
437 p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
438 if (!p_defs) {
Chris Wilson44834a62010-08-19 16:09:23 +0100439 DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
yakui_zhao9b9d1722009-05-31 17:17:17 +0800440 return;
441 }
Jani Nikula6cc38ac2015-08-18 14:28:55 +0300442
443 /*
444 * Only parse SDVO mappings when the general definitions block child
445 * device size matches that of the *legacy* child device config
446 * struct. Thus, SDVO mapping will be skipped for newer VBT.
yakui_zhao9b9d1722009-05-31 17:17:17 +0800447 */
Jani Nikula6cc38ac2015-08-18 14:28:55 +0300448 if (p_defs->child_dev_size != sizeof(*child)) {
449 DRM_DEBUG_KMS("Unsupported child device size for SDVO mapping.\n");
yakui_zhao9b9d1722009-05-31 17:17:17 +0800450 return;
451 }
452 /* get the block size of general definitions */
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +0200453 block_size = get_blocksize(p_defs);
yakui_zhao9b9d1722009-05-31 17:17:17 +0800454 /* get the number of child device */
455 child_device_num = (block_size - sizeof(*p_defs)) /
Ville Syrjälä90e4f152015-03-25 18:45:58 +0200456 p_defs->child_dev_size;
yakui_zhao9b9d1722009-05-31 17:17:17 +0800457 count = 0;
458 for (i = 0; i < child_device_num; i++) {
Jani Nikula6cc38ac2015-08-18 14:28:55 +0300459 child = &child_device_ptr(p_defs, i)->old;
460 if (!child->device_type) {
yakui_zhao9b9d1722009-05-31 17:17:17 +0800461 /* skip the device block if device type is invalid */
462 continue;
463 }
Jani Nikula6cc38ac2015-08-18 14:28:55 +0300464 if (child->slave_addr != SLAVE_ADDR1 &&
465 child->slave_addr != SLAVE_ADDR2) {
yakui_zhao9b9d1722009-05-31 17:17:17 +0800466 /*
467 * If the slave address is neither 0x70 nor 0x72,
468 * it is not a SDVO device. Skip it.
469 */
470 continue;
471 }
Jani Nikula6cc38ac2015-08-18 14:28:55 +0300472 if (child->dvo_port != DEVICE_PORT_DVOB &&
473 child->dvo_port != DEVICE_PORT_DVOC) {
yakui_zhao9b9d1722009-05-31 17:17:17 +0800474 /* skip the incorrect SDVO port */
Akshay Joshi0206e352011-08-16 15:34:10 -0400475 DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
yakui_zhao9b9d1722009-05-31 17:17:17 +0800476 continue;
477 }
Zhao Yakui28c97732009-10-09 11:39:41 +0800478 DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
Jani Nikula6cc38ac2015-08-18 14:28:55 +0300479 " %s port\n",
480 child->slave_addr,
481 (child->dvo_port == DEVICE_PORT_DVOB) ?
482 "SDVOB" : "SDVOC");
483 p_mapping = &(dev_priv->sdvo_mappings[child->dvo_port - 1]);
yakui_zhao9b9d1722009-05-31 17:17:17 +0800484 if (!p_mapping->initialized) {
Jani Nikula6cc38ac2015-08-18 14:28:55 +0300485 p_mapping->dvo_port = child->dvo_port;
486 p_mapping->slave_addr = child->slave_addr;
487 p_mapping->dvo_wiring = child->dvo_wiring;
488 p_mapping->ddc_pin = child->ddc_pin;
489 p_mapping->i2c_pin = child->i2c_pin;
yakui_zhao9b9d1722009-05-31 17:17:17 +0800490 p_mapping->initialized = 1;
Adam Jackson46eb3032011-06-16 16:36:23 -0400491 DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
Chris Wilsone957d772010-09-24 12:52:03 +0100492 p_mapping->dvo_port,
493 p_mapping->slave_addr,
494 p_mapping->dvo_wiring,
495 p_mapping->ddc_pin,
Adam Jackson46eb3032011-06-16 16:36:23 -0400496 p_mapping->i2c_pin);
yakui_zhao9b9d1722009-05-31 17:17:17 +0800497 } else {
Zhao Yakui28c97732009-10-09 11:39:41 +0800498 DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
yakui_zhao9b9d1722009-05-31 17:17:17 +0800499 "two SDVO device.\n");
500 }
Jani Nikula6cc38ac2015-08-18 14:28:55 +0300501 if (child->slave2_addr) {
yakui_zhao9b9d1722009-05-31 17:17:17 +0800502 /* Maybe this is a SDVO device with multiple inputs */
503 /* And the mapping info is not added */
Zhao Yakui28c97732009-10-09 11:39:41 +0800504 DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
505 " is a SDVO device with multiple inputs.\n");
yakui_zhao9b9d1722009-05-31 17:17:17 +0800506 }
507 count++;
508 }
509
510 if (!count) {
511 /* No SDVO device info is found */
Zhao Yakui28c97732009-10-09 11:39:41 +0800512 DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
yakui_zhao9b9d1722009-05-31 17:17:17 +0800513 }
514 return;
515}
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800516
517static void
518parse_driver_features(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +0300519 const struct bdb_header *bdb)
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800520{
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300521 const struct bdb_driver_features *driver;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800522
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800523 driver = find_section(bdb, BDB_DRIVER_FEATURES);
Jesse Barnes652c3932009-08-17 13:31:43 -0700524 if (!driver)
525 return;
526
Daniel Vetter6fca55b2013-09-21 00:48:39 +0200527 if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300528 dev_priv->vbt.edp_support = 1;
Jesse Barnes652c3932009-08-17 13:31:43 -0700529
Chris Wilson5ceb0f92010-09-24 10:24:28 +0100530 if (driver->dual_frequency)
Jesse Barnes652c3932009-08-17 13:31:43 -0700531 dev_priv->render_reclock_avail = true;
Pradeep Bhat83a72802014-03-28 10:14:57 +0530532
533 DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
534 /*
535 * If DRRS is not supported, drrs_type has to be set to 0.
536 * This is because, VBT is configured in such a way that
537 * static DRRS is 0 and DRRS not supported is represented by
538 * driver->drrs_enabled=false
539 */
540 if (!driver->drrs_enabled)
541 dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800542}
543
Zhao Yakui6363ee62009-11-24 09:48:44 +0800544static void
Jani Nikuladcb58a42015-05-12 15:41:32 +0300545parse_edp(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800546{
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300547 const struct bdb_edp *edp;
548 const struct edp_power_seq *edp_pps;
549 const struct edp_link_params *edp_link_params;
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800550
551 edp = find_section(bdb, BDB_EDP);
552 if (!edp) {
Daniel Vetter6fca55b2013-09-21 00:48:39 +0200553 if (dev_priv->vbt.edp_support)
Jani Nikula9a30a612012-11-12 14:33:45 +0200554 DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800555 return;
556 }
557
558 switch ((edp->color_depth >> (panel_type * 2)) & 3) {
559 case EDP_18BPP:
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300560 dev_priv->vbt.edp_bpp = 18;
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800561 break;
562 case EDP_24BPP:
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300563 dev_priv->vbt.edp_bpp = 24;
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800564 break;
565 case EDP_30BPP:
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300566 dev_priv->vbt.edp_bpp = 30;
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800567 break;
568 }
Chris Wilson5ceb0f92010-09-24 10:24:28 +0100569
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700570 /* Get the eDP sequencing and link info */
571 edp_pps = &edp->power_seqs[panel_type];
572 edp_link_params = &edp->link_params[panel_type];
Chris Wilson5ceb0f92010-09-24 10:24:28 +0100573
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300574 dev_priv->vbt.edp_pps = *edp_pps;
Chris Wilson5ceb0f92010-09-24 10:24:28 +0100575
Jani Nikulae13e2b22014-05-06 14:56:51 +0300576 switch (edp_link_params->rate) {
577 case EDP_RATE_1_62:
578 dev_priv->vbt.edp_rate = DP_LINK_BW_1_62;
579 break;
580 case EDP_RATE_2_7:
581 dev_priv->vbt.edp_rate = DP_LINK_BW_2_7;
582 break;
583 default:
584 DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
585 edp_link_params->rate);
586 break;
587 }
588
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700589 switch (edp_link_params->lanes) {
Jani Nikulae13e2b22014-05-06 14:56:51 +0300590 case EDP_LANE_1:
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300591 dev_priv->vbt.edp_lanes = 1;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700592 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300593 case EDP_LANE_2:
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300594 dev_priv->vbt.edp_lanes = 2;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700595 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300596 case EDP_LANE_4:
Rodrigo Vivi41aa3442013-05-09 20:03:18 -0300597 dev_priv->vbt.edp_lanes = 4;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700598 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300599 default:
600 DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
601 edp_link_params->lanes);
602 break;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700603 }
Jani Nikulae13e2b22014-05-06 14:56:51 +0300604
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700605 switch (edp_link_params->preemphasis) {
Jani Nikulae13e2b22014-05-06 14:56:51 +0300606 case EDP_PREEMPHASIS_NONE:
Sonika Jindalbd600182014-08-08 16:23:41 +0530607 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700608 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300609 case EDP_PREEMPHASIS_3_5dB:
Sonika Jindalbd600182014-08-08 16:23:41 +0530610 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700611 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300612 case EDP_PREEMPHASIS_6dB:
Sonika Jindalbd600182014-08-08 16:23:41 +0530613 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700614 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300615 case EDP_PREEMPHASIS_9_5dB:
Sonika Jindalbd600182014-08-08 16:23:41 +0530616 dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700617 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300618 default:
619 DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
620 edp_link_params->preemphasis);
621 break;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700622 }
Jani Nikulae13e2b22014-05-06 14:56:51 +0300623
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700624 switch (edp_link_params->vswing) {
Jani Nikulae13e2b22014-05-06 14:56:51 +0300625 case EDP_VSWING_0_4V:
Sonika Jindalbd600182014-08-08 16:23:41 +0530626 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700627 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300628 case EDP_VSWING_0_6V:
Sonika Jindalbd600182014-08-08 16:23:41 +0530629 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700630 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300631 case EDP_VSWING_0_8V:
Sonika Jindalbd600182014-08-08 16:23:41 +0530632 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700633 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300634 case EDP_VSWING_1_2V:
Sonika Jindalbd600182014-08-08 16:23:41 +0530635 dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700636 break;
Jani Nikulae13e2b22014-05-06 14:56:51 +0300637 default:
638 DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
639 edp_link_params->vswing);
640 break;
Jesse Barnes9f0e7ff42010-10-07 16:01:14 -0700641 }
Sonika Jindal9a57f5b2015-02-25 10:29:11 +0530642
643 if (bdb->version >= 173) {
644 uint8_t vswing;
645
Sonika Jindal9e458032015-05-06 17:35:48 +0530646 /* Don't read from VBT if module parameter has valid value*/
647 if (i915.edp_vswing) {
648 dev_priv->edp_low_vswing = i915.edp_vswing == 1;
649 } else {
650 vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
651 dev_priv->edp_low_vswing = vswing == 0;
652 }
Sonika Jindal9a57f5b2015-02-25 10:29:11 +0530653 }
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800654}
655
Rodrigo Vivibfd7ebd2014-11-14 08:52:30 -0800656static void
Jani Nikuladcb58a42015-05-12 15:41:32 +0300657parse_psr(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
Rodrigo Vivibfd7ebd2014-11-14 08:52:30 -0800658{
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300659 const struct bdb_psr *psr;
660 const struct psr_table *psr_table;
Rodrigo Vivibfd7ebd2014-11-14 08:52:30 -0800661
662 psr = find_section(bdb, BDB_PSR);
663 if (!psr) {
664 DRM_DEBUG_KMS("No PSR BDB found.\n");
665 return;
666 }
667
668 psr_table = &psr->psr_table[panel_type];
669
670 dev_priv->vbt.psr.full_link = psr_table->full_link;
671 dev_priv->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
672
673 /* Allowed VBT values goes from 0 to 15 */
674 dev_priv->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
675 psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
676
677 switch (psr_table->lines_to_wait) {
678 case 0:
679 dev_priv->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
680 break;
681 case 1:
682 dev_priv->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
683 break;
684 case 2:
685 dev_priv->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
686 break;
687 case 3:
688 dev_priv->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
689 break;
690 default:
691 DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
692 psr_table->lines_to_wait);
693 break;
694 }
695
696 dev_priv->vbt.psr.tp1_wakeup_time = psr_table->tp1_wakeup_time;
697 dev_priv->vbt.psr.tp2_tp3_wakeup_time = psr_table->tp2_tp3_wakeup_time;
698}
699
Jani Nikula5db72092016-01-05 15:50:51 +0200700static u8 *goto_next_sequence(u8 *data, u16 *size)
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530701{
702 u16 len;
703 int tmp = *size;
704
705 if (--tmp < 0)
706 return NULL;
707
708 /* goto first element */
709 data++;
710 while (1) {
711 switch (*data) {
712 case MIPI_SEQ_ELEM_SEND_PKT:
713 /*
714 * skip by this element payload size
715 * skip elem id, command flag and data type
716 */
Shobhit Kumarb0256cd2014-04-15 13:54:07 +0530717 tmp -= 5;
718 if (tmp < 0)
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530719 return NULL;
720
721 data += 3;
722 len = *((u16 *)data);
723
Shobhit Kumarb0256cd2014-04-15 13:54:07 +0530724 tmp -= len;
725 if (tmp < 0)
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530726 return NULL;
727
728 /* skip by len */
729 data = data + 2 + len;
730 break;
731 case MIPI_SEQ_ELEM_DELAY:
732 /* skip by elem id, and delay is 4 bytes */
Shobhit Kumarb0256cd2014-04-15 13:54:07 +0530733 tmp -= 5;
734 if (tmp < 0)
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530735 return NULL;
736
737 data += 5;
738 break;
739 case MIPI_SEQ_ELEM_GPIO:
Shobhit Kumarb0256cd2014-04-15 13:54:07 +0530740 tmp -= 3;
741 if (tmp < 0)
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530742 return NULL;
743
744 data += 3;
745 break;
746 default:
747 DRM_ERROR("Unknown element\n");
748 return NULL;
749 }
750
751 /* end of sequence ? */
752 if (*data == 0)
753 break;
754 }
755
756 /* goto next sequence or end of block byte */
757 if (--tmp < 0)
758 return NULL;
759
760 data++;
761
762 /* update amount of data left for the sequence block to be parsed */
763 *size = tmp;
764 return data;
765}
766
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800767static void
Jani Nikula0f8689f2015-12-21 15:10:54 +0200768parse_mipi_config(struct drm_i915_private *dev_priv,
769 const struct bdb_header *bdb)
Shobhit Kumard17c5442013-08-27 15:12:25 +0300770{
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300771 const struct bdb_mipi_config *start;
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300772 const struct mipi_config *config;
773 const struct mipi_pps_data *pps;
Shobhit Kumard17c5442013-08-27 15:12:25 +0300774
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530775 /* parse MIPI blocks only if LFP type is MIPI */
776 if (!dev_priv->vbt.has_mipi)
777 return;
778
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530779 /* Initialize this to undefined indicating no generic MIPI support */
780 dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
781
782 /* Block #40 is already parsed and panel_fixed_mode is
783 * stored in dev_priv->lfp_lvds_vbt_mode
784 * resuse this when needed
785 */
786
787 /* Parse #52 for panel index used from panel_type already
788 * parsed
789 */
790 start = find_section(bdb, BDB_MIPI_CONFIG);
791 if (!start) {
792 DRM_DEBUG_KMS("No MIPI config BDB found");
Shobhit Kumard17c5442013-08-27 15:12:25 +0300793 return;
794 }
795
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530796 DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
797 panel_type);
798
799 /*
800 * get hold of the correct configuration block and pps data as per
801 * the panel_type as index
802 */
803 config = &start->config[panel_type];
804 pps = &start->pps[panel_type];
805
806 /* store as of now full data. Trim when we realise all is not needed */
807 dev_priv->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
808 if (!dev_priv->vbt.dsi.config)
809 return;
810
811 dev_priv->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
812 if (!dev_priv->vbt.dsi.pps) {
813 kfree(dev_priv->vbt.dsi.config);
814 return;
815 }
816
817 /* We have mandatory mipi config blocks. Initialize as generic panel */
Shobhit Kumarea9a6ba2014-02-28 11:18:46 +0530818 dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
Jani Nikula0f8689f2015-12-21 15:10:54 +0200819}
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530820
Jani Nikula5db72092016-01-05 15:50:51 +0200821/* Find the sequence block and size for the given panel. */
822static const u8 *
823find_panel_sequence_block(const struct bdb_mipi_sequence *sequence,
824 u16 panel_id, u16 *seq_size)
825{
826 u32 total = get_blocksize(sequence);
827 const u8 *data = &sequence->data[0];
828 u8 current_id;
829 u16 current_size;
830 int index = 0;
831 int i;
832
833 for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index + 3 < total; i++) {
834 current_id = *(data + index);
835 index++;
836
837 current_size = *((const u16 *)(data + index));
838 index += 2;
839
840 if (index + current_size > total) {
841 DRM_ERROR("Invalid sequence block\n");
842 return NULL;
843 }
844
845 if (current_id == panel_id) {
846 *seq_size = current_size;
847 return data + index;
848 }
849
850 index += current_size;
851 }
852
853 DRM_ERROR("Sequence block detected but no valid configuration\n");
854
855 return NULL;
856}
857
Jani Nikula0f8689f2015-12-21 15:10:54 +0200858static void
859parse_mipi_sequence(struct drm_i915_private *dev_priv,
860 const struct bdb_header *bdb)
861{
862 const struct bdb_mipi_sequence *sequence;
863 const u8 *seq_data;
Jani Nikula5db72092016-01-05 15:50:51 +0200864 u16 seq_size;
Jani Nikula0f8689f2015-12-21 15:10:54 +0200865 u8 *data;
866 u16 block_size;
Jani Nikula0f8689f2015-12-21 15:10:54 +0200867
868 /* Only our generic panel driver uses the sequence block. */
869 if (dev_priv->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
870 return;
871
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530872 sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
873 if (!sequence) {
874 DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
875 return;
876 }
877
Jani Nikulacd67d222015-09-17 16:42:07 +0300878 /* Fail gracefully for forward incompatible sequence block. */
879 if (sequence->version >= 3) {
880 DRM_ERROR("Unable to parse MIPI Sequence Block v3+\n");
881 return;
882 }
883
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530884 DRM_DEBUG_DRIVER("Found MIPI sequence block\n");
885
886 block_size = get_blocksize(sequence);
887
888 /*
889 * parse the sequence block for individual sequences
890 */
891 dev_priv->vbt.dsi.seq_version = sequence->version;
892
Jani Nikula5db72092016-01-05 15:50:51 +0200893 seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size);
894 if (!seq_data)
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530895 return;
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530896
Jani Nikula5db72092016-01-05 15:50:51 +0200897 dev_priv->vbt.dsi.data = kmemdup(seq_data, seq_size, GFP_KERNEL);
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530898 if (!dev_priv->vbt.dsi.data)
899 return;
900
901 /*
902 * loop into the sequence data and split into multiple sequneces
903 * There are only 5 types of sequences as of now
904 */
905 data = dev_priv->vbt.dsi.data;
906 dev_priv->vbt.dsi.size = seq_size;
907
908 /* two consecutive 0x00 indicate end of all sequences */
909 while (1) {
910 int seq_id = *data;
911 if (MIPI_SEQ_MAX > seq_id && seq_id > MIPI_SEQ_UNDEFINED) {
912 dev_priv->vbt.dsi.sequence[seq_id] = data;
913 DRM_DEBUG_DRIVER("Found mipi sequence - %d\n", seq_id);
914 } else {
915 DRM_ERROR("undefined sequence\n");
916 goto err;
917 }
918
919 /* partial parsing to skip elements */
920 data = goto_next_sequence(data, &seq_size);
921
922 if (data == NULL) {
923 DRM_ERROR("Sequence elements going beyond block itself. Sequence block parsing failed\n");
924 goto err;
925 }
926
927 if (*data == 0)
928 break; /* end of sequence reached */
929 }
930
931 DRM_DEBUG_DRIVER("MIPI related vbt parsing complete\n");
932 return;
933err:
934 kfree(dev_priv->vbt.dsi.data);
935 dev_priv->vbt.dsi.data = NULL;
936
937 /* error during parsing so set all pointers to null
938 * because of partial parsing */
Rafael Barbalhoed3b6672014-07-24 15:16:12 +0100939 memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
Shobhit Kumard17c5442013-08-27 15:12:25 +0300940}
941
Antti Koskipaa75067dd2015-07-10 14:10:55 +0300942static u8 translate_iboost(u8 val)
943{
944 static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
945
946 if (val >= ARRAY_SIZE(mapping)) {
947 DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
948 return 0;
949 }
950 return mapping[val];
951}
952
Paulo Zanoni6acab152013-09-12 17:06:24 -0300953static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
Jani Nikuladcb58a42015-05-12 15:41:32 +0300954 const struct bdb_header *bdb)
Paulo Zanoni6acab152013-09-12 17:06:24 -0300955{
956 union child_device_config *it, *child = NULL;
957 struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
958 uint8_t hdmi_level_shift;
959 int i, j;
Paulo Zanoni554d6af2013-09-12 17:10:11 -0300960 bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
Xiong Zhang11c1b652015-08-17 16:04:04 +0800961 uint8_t aux_channel, ddc_pin;
Paulo Zanoni6acab152013-09-12 17:06:24 -0300962 /* Each DDI port can have more than one value on the "DVO Port" field,
963 * so look for all the possible values for each port and abort if more
964 * than one is found. */
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -0700965 int dvo_ports[][3] = {
966 {DVO_PORT_HDMIA, DVO_PORT_DPA, -1},
967 {DVO_PORT_HDMIB, DVO_PORT_DPB, -1},
968 {DVO_PORT_HDMIC, DVO_PORT_DPC, -1},
969 {DVO_PORT_HDMID, DVO_PORT_DPD, -1},
970 {DVO_PORT_CRT, DVO_PORT_HDMIE, DVO_PORT_DPE},
Paulo Zanoni6acab152013-09-12 17:06:24 -0300971 };
972
973 /* Find the child device to use, abort if more than one found. */
974 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
975 it = dev_priv->vbt.child_dev + i;
976
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -0700977 for (j = 0; j < 3; j++) {
Paulo Zanoni6acab152013-09-12 17:06:24 -0300978 if (dvo_ports[port][j] == -1)
979 break;
980
981 if (it->common.dvo_port == dvo_ports[port][j]) {
982 if (child) {
983 DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
984 port_name(port));
985 return;
986 }
987 child = it;
988 }
989 }
990 }
991 if (!child)
992 return;
993
Paulo Zanoni6bf19e72013-09-12 17:07:55 -0300994 aux_channel = child->raw[25];
Xiong Zhang11c1b652015-08-17 16:04:04 +0800995 ddc_pin = child->common.ddc_pin;
Paulo Zanoni6bf19e72013-09-12 17:07:55 -0300996
Ville Syrjälä78eb06c2013-11-01 20:32:07 +0200997 is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
998 is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
999 is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
1000 is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
1001 is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
Paulo Zanoni554d6af2013-09-12 17:10:11 -03001002
Paulo Zanoni311a2092013-09-12 17:12:18 -03001003 info->supports_dvi = is_dvi;
1004 info->supports_hdmi = is_hdmi;
1005 info->supports_dp = is_dp;
1006
Paulo Zanoni554d6af2013-09-12 17:10:11 -03001007 DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
1008 port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
1009
1010 if (is_edp && is_dvi)
1011 DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
1012 port_name(port));
1013 if (is_crt && port != PORT_E)
1014 DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
1015 if (is_crt && (is_dvi || is_dp))
1016 DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
1017 port_name(port));
1018 if (is_dvi && (port == PORT_A || port == PORT_E))
Masanari Iida9b134942014-08-06 22:31:28 +09001019 DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port));
Paulo Zanoni554d6af2013-09-12 17:10:11 -03001020 if (!is_dvi && !is_dp && !is_crt)
1021 DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
1022 port_name(port));
1023 if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
1024 DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001025
1026 if (is_dvi) {
Xiong Zhang11c1b652015-08-17 16:04:04 +08001027 if (port == PORT_E) {
1028 info->alternate_ddc_pin = ddc_pin;
1029 /* if DDIE share ddc pin with other port, then
1030 * dvi/hdmi couldn't exist on the shared port.
1031 * Otherwise they share the same ddc bin and system
1032 * couldn't communicate with them seperately. */
1033 if (ddc_pin == DDC_PIN_B) {
1034 dev_priv->vbt.ddi_port_info[PORT_B].supports_dvi = 0;
1035 dev_priv->vbt.ddi_port_info[PORT_B].supports_hdmi = 0;
1036 } else if (ddc_pin == DDC_PIN_C) {
1037 dev_priv->vbt.ddi_port_info[PORT_C].supports_dvi = 0;
1038 dev_priv->vbt.ddi_port_info[PORT_C].supports_hdmi = 0;
1039 } else if (ddc_pin == DDC_PIN_D) {
1040 dev_priv->vbt.ddi_port_info[PORT_D].supports_dvi = 0;
1041 dev_priv->vbt.ddi_port_info[PORT_D].supports_hdmi = 0;
1042 }
1043 } else if (ddc_pin == DDC_PIN_B && port != PORT_B)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001044 DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
Xiong Zhang11c1b652015-08-17 16:04:04 +08001045 else if (ddc_pin == DDC_PIN_C && port != PORT_C)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001046 DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
Xiong Zhang11c1b652015-08-17 16:04:04 +08001047 else if (ddc_pin == DDC_PIN_D && port != PORT_D)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001048 DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
1049 }
1050
1051 if (is_dp) {
Rodrigo Vivi500ea702015-08-07 17:01:16 -07001052 if (port == PORT_E) {
1053 info->alternate_aux_channel = aux_channel;
1054 /* if DDIE share aux channel with other port, then
1055 * DP couldn't exist on the shared port. Otherwise
1056 * they share the same aux channel and system
1057 * couldn't communicate with them seperately. */
1058 if (aux_channel == DP_AUX_A)
1059 dev_priv->vbt.ddi_port_info[PORT_A].supports_dp = 0;
1060 else if (aux_channel == DP_AUX_B)
1061 dev_priv->vbt.ddi_port_info[PORT_B].supports_dp = 0;
1062 else if (aux_channel == DP_AUX_C)
1063 dev_priv->vbt.ddi_port_info[PORT_C].supports_dp = 0;
1064 else if (aux_channel == DP_AUX_D)
1065 dev_priv->vbt.ddi_port_info[PORT_D].supports_dp = 0;
1066 }
1067 else if (aux_channel == DP_AUX_A && port != PORT_A)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001068 DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
Rodrigo Vivi500ea702015-08-07 17:01:16 -07001069 else if (aux_channel == DP_AUX_B && port != PORT_B)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001070 DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
Rodrigo Vivi500ea702015-08-07 17:01:16 -07001071 else if (aux_channel == DP_AUX_C && port != PORT_C)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001072 DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
Rodrigo Vivi500ea702015-08-07 17:01:16 -07001073 else if (aux_channel == DP_AUX_D && port != PORT_D)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001074 DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
1075 }
1076
Paulo Zanoni6acab152013-09-12 17:06:24 -03001077 if (bdb->version >= 158) {
1078 /* The VBT HDMI level shift values match the table we have. */
1079 hdmi_level_shift = child->raw[7] & 0xF;
Damien Lespiauce4dd492014-08-01 11:07:54 +01001080 DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
1081 port_name(port),
1082 hdmi_level_shift);
1083 info->hdmi_level_shift = hdmi_level_shift;
Paulo Zanoni6acab152013-09-12 17:06:24 -03001084 }
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001085
1086 /* Parse the I_boost config for SKL and above */
1087 if (bdb->version >= 196 && (child->common.flags_1 & IBOOST_ENABLE)) {
1088 info->dp_boost_level = translate_iboost(child->common.iboost_level & 0xF);
1089 DRM_DEBUG_KMS("VBT (e)DP boost level for port %c: %d\n",
1090 port_name(port), info->dp_boost_level);
1091 info->hdmi_boost_level = translate_iboost(child->common.iboost_level >> 4);
1092 DRM_DEBUG_KMS("VBT HDMI boost level for port %c: %d\n",
1093 port_name(port), info->hdmi_boost_level);
1094 }
Paulo Zanoni6acab152013-09-12 17:06:24 -03001095}
1096
1097static void parse_ddi_ports(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +03001098 const struct bdb_header *bdb)
Paulo Zanoni6acab152013-09-12 17:06:24 -03001099{
Paulo Zanoni6acab152013-09-12 17:06:24 -03001100 enum port port;
1101
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001102 if (!HAS_DDI(dev_priv))
Paulo Zanoni6acab152013-09-12 17:06:24 -03001103 return;
1104
1105 if (!dev_priv->vbt.child_dev_num)
1106 return;
1107
1108 if (bdb->version < 155)
1109 return;
1110
1111 for (port = PORT_A; port < I915_MAX_PORTS; port++)
1112 parse_ddi_port(dev_priv, port, bdb);
1113}
1114
Shobhit Kumard17c5442013-08-27 15:12:25 +03001115static void
Zhao Yakui6363ee62009-11-24 09:48:44 +08001116parse_device_mapping(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +03001117 const struct bdb_header *bdb)
Zhao Yakui6363ee62009-11-24 09:48:44 +08001118{
Jani Nikulae8ef3b42015-04-15 15:18:28 +03001119 const struct bdb_general_definitions *p_defs;
1120 const union child_device_config *p_child;
1121 union child_device_config *child_dev_ptr;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001122 int i, child_device_num, count;
David Weinehalle2d6cf72015-08-21 16:52:01 +03001123 u8 expected_size;
1124 u16 block_size;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001125
1126 p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
1127 if (!p_defs) {
Chris Wilson44834a62010-08-19 16:09:23 +01001128 DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
Zhao Yakui6363ee62009-11-24 09:48:44 +08001129 return;
1130 }
David Weinehalle2d6cf72015-08-21 16:52:01 +03001131 if (bdb->version < 195) {
1132 expected_size = sizeof(struct old_child_dev_config);
1133 } else if (bdb->version == 195) {
1134 expected_size = 37;
1135 } else if (bdb->version <= 197) {
1136 expected_size = 38;
1137 } else {
1138 expected_size = 38;
1139 BUILD_BUG_ON(sizeof(*p_child) < 38);
1140 DRM_DEBUG_DRIVER("Expected child device config size for VBT version %u not known; assuming %u\n",
1141 bdb->version, expected_size);
1142 }
1143
1144 /* The legacy sized child device config is the minimum we need. */
1145 if (p_defs->child_dev_size < sizeof(struct old_child_dev_config)) {
1146 DRM_ERROR("Child device config size %u is too small.\n",
1147 p_defs->child_dev_size);
Zhao Yakui6363ee62009-11-24 09:48:44 +08001148 return;
1149 }
David Weinehalle2d6cf72015-08-21 16:52:01 +03001150
1151 /* Flag an error for unexpected size, but continue anyway. */
1152 if (p_defs->child_dev_size != expected_size)
1153 DRM_ERROR("Unexpected child device config size %u (expected %u for VBT version %u)\n",
1154 p_defs->child_dev_size, expected_size, bdb->version);
1155
Zhao Yakui6363ee62009-11-24 09:48:44 +08001156 /* get the block size of general definitions */
1157 block_size = get_blocksize(p_defs);
1158 /* get the number of child device */
1159 child_device_num = (block_size - sizeof(*p_defs)) /
Ville Syrjälä90e4f152015-03-25 18:45:58 +02001160 p_defs->child_dev_size;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001161 count = 0;
1162 /* get the number of child device that is present */
1163 for (i = 0; i < child_device_num; i++) {
Ville Syrjälä90e4f152015-03-25 18:45:58 +02001164 p_child = child_device_ptr(p_defs, i);
Paulo Zanoni768f69c2013-09-11 18:02:47 -03001165 if (!p_child->common.device_type) {
Zhao Yakui6363ee62009-11-24 09:48:44 +08001166 /* skip the device block if device type is invalid */
1167 continue;
1168 }
1169 count++;
1170 }
1171 if (!count) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001172 DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
Zhao Yakui6363ee62009-11-24 09:48:44 +08001173 return;
1174 }
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001175 dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
1176 if (!dev_priv->vbt.child_dev) {
Zhao Yakui6363ee62009-11-24 09:48:44 +08001177 DRM_DEBUG_KMS("No memory space for child device\n");
1178 return;
1179 }
1180
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001181 dev_priv->vbt.child_dev_num = count;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001182 count = 0;
1183 for (i = 0; i < child_device_num; i++) {
Ville Syrjälä90e4f152015-03-25 18:45:58 +02001184 p_child = child_device_ptr(p_defs, i);
Paulo Zanoni768f69c2013-09-11 18:02:47 -03001185 if (!p_child->common.device_type) {
Zhao Yakui6363ee62009-11-24 09:48:44 +08001186 /* skip the device block if device type is invalid */
1187 continue;
1188 }
Shobhit Kumar3e6bd012014-05-27 19:33:59 +05301189
1190 if (p_child->common.dvo_port >= DVO_PORT_MIPIA
1191 && p_child->common.dvo_port <= DVO_PORT_MIPID
1192 &&p_child->common.device_type & DEVICE_TYPE_MIPI_OUTPUT) {
1193 DRM_DEBUG_KMS("Found MIPI as LFP\n");
1194 dev_priv->vbt.has_mipi = 1;
1195 dev_priv->vbt.dsi.port = p_child->common.dvo_port;
1196 }
1197
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001198 child_dev_ptr = dev_priv->vbt.child_dev + count;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001199 count++;
David Weinehalle2d6cf72015-08-21 16:52:01 +03001200
1201 /*
1202 * Copy as much as we know (sizeof) and is available
1203 * (child_dev_size) of the child device. Accessing the data must
1204 * depend on VBT version.
1205 */
1206 memcpy(child_dev_ptr, p_child,
1207 min_t(size_t, p_defs->child_dev_size, sizeof(*p_child)));
Zhao Yakui6363ee62009-11-24 09:48:44 +08001208 }
1209 return;
1210}
Chris Wilson44834a62010-08-19 16:09:23 +01001211
Simon Que6a040022010-09-30 09:36:39 +01001212static void
1213init_vbt_defaults(struct drm_i915_private *dev_priv)
1214{
Paulo Zanoni6acab152013-09-12 17:06:24 -03001215 enum port port;
Bryan Freed9a4114f2011-01-12 13:38:39 -08001216
Jani Nikula988c7012015-03-27 00:20:19 +02001217 dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
Simon Que6a040022010-09-30 09:36:39 +01001218
Jani Nikula56c4b632014-06-17 15:47:05 +03001219 /* Default to having backlight */
1220 dev_priv->vbt.backlight.present = true;
1221
Simon Que6a040022010-09-30 09:36:39 +01001222 /* LFP panel data */
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001223 dev_priv->vbt.lvds_dither = 1;
1224 dev_priv->vbt.lvds_vbt = 0;
Simon Que6a040022010-09-30 09:36:39 +01001225
1226 /* SDVO panel data */
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001227 dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
Simon Que6a040022010-09-30 09:36:39 +01001228
1229 /* general features */
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001230 dev_priv->vbt.int_tv_support = 1;
1231 dev_priv->vbt.int_crt_support = 1;
Bryan Freed9a4114f2011-01-12 13:38:39 -08001232
1233 /* Default to using SSC */
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001234 dev_priv->vbt.lvds_use_ssc = 1;
Duncan Laurief69e5152013-11-13 17:59:43 -08001235 /*
1236 * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
1237 * clock for LVDS.
1238 */
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001239 dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev_priv,
1240 !HAS_PCH_SPLIT(dev_priv));
Ville Syrjäläe91e9412013-12-09 18:54:16 +02001241 DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
Paulo Zanoni6acab152013-09-12 17:06:24 -03001242
1243 for (port = PORT_A; port < I915_MAX_PORTS; port++) {
Paulo Zanoni311a2092013-09-12 17:12:18 -03001244 struct ddi_vbt_port_info *info =
1245 &dev_priv->vbt.ddi_port_info[port];
1246
Damien Lespiauce4dd492014-08-01 11:07:54 +01001247 info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
Paulo Zanoni311a2092013-09-12 17:12:18 -03001248
1249 info->supports_dvi = (port != PORT_A && port != PORT_E);
1250 info->supports_hdmi = info->supports_dvi;
1251 info->supports_dp = (port != PORT_E);
Paulo Zanoni6acab152013-09-12 17:06:24 -03001252 }
Simon Que6a040022010-09-30 09:36:39 +01001253}
1254
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001255static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
1256{
1257 const void *_vbt = vbt;
1258
1259 return _vbt + vbt->bdb_offset;
1260}
1261
Jani Nikulaf0067a32015-12-15 13:16:15 +02001262/**
1263 * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
1264 * @buf: pointer to a buffer to validate
1265 * @size: size of the buffer
1266 *
1267 * Returns true on valid VBT.
1268 */
1269bool intel_bios_is_valid_vbt(const void *buf, size_t size)
Chris Wilson3dd4e842014-04-18 18:04:22 -03001270{
Jani Nikulaf0067a32015-12-15 13:16:15 +02001271 const struct vbt_header *vbt = buf;
Jani Nikuladcb58a42015-05-12 15:41:32 +03001272 const struct bdb_header *bdb;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001273
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001274 if (!vbt)
Jani Nikulaf0067a32015-12-15 13:16:15 +02001275 return false;
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001276
Jani Nikulaf0067a32015-12-15 13:16:15 +02001277 if (sizeof(struct vbt_header) > size) {
Chris Wilson3dd4e842014-04-18 18:04:22 -03001278 DRM_DEBUG_DRIVER("VBT header incomplete\n");
Jani Nikulaf0067a32015-12-15 13:16:15 +02001279 return false;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001280 }
1281
1282 if (memcmp(vbt->signature, "$VBT", 4)) {
1283 DRM_DEBUG_DRIVER("VBT invalid signature\n");
Jani Nikulaf0067a32015-12-15 13:16:15 +02001284 return false;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001285 }
1286
Jani Nikulaf0067a32015-12-15 13:16:15 +02001287 if (vbt->bdb_offset + sizeof(struct bdb_header) > size) {
Chris Wilson3dd4e842014-04-18 18:04:22 -03001288 DRM_DEBUG_DRIVER("BDB header incomplete\n");
Jani Nikulaf0067a32015-12-15 13:16:15 +02001289 return false;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001290 }
1291
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001292 bdb = get_bdb_header(vbt);
Jani Nikulaf0067a32015-12-15 13:16:15 +02001293 if (vbt->bdb_offset + bdb->bdb_size > size) {
Chris Wilson3dd4e842014-04-18 18:04:22 -03001294 DRM_DEBUG_DRIVER("BDB incomplete\n");
Jani Nikulaf0067a32015-12-15 13:16:15 +02001295 return false;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001296 }
1297
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001298 return vbt;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001299}
1300
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001301static const struct vbt_header *find_vbt(void __iomem *bios, size_t size)
Jani Nikulab34a9912015-05-13 15:34:04 +03001302{
Jani Nikulab34a9912015-05-13 15:34:04 +03001303 size_t i;
1304
1305 /* Scour memory looking for the VBT signature. */
1306 for (i = 0; i + 4 < size; i++) {
Jani Nikulaf0067a32015-12-15 13:16:15 +02001307 void *vbt;
Williams, Dan J115719f2015-10-12 21:12:57 +00001308
Jani Nikulaf0067a32015-12-15 13:16:15 +02001309 if (ioread32(bios + i) != *((const u32 *) "$VBT"))
1310 continue;
1311
1312 /*
1313 * This is the one place where we explicitly discard the address
1314 * space (__iomem) of the BIOS/VBT.
1315 */
1316 vbt = (void __force *) bios + i;
1317 if (intel_bios_is_valid_vbt(vbt, size - i))
1318 return vbt;
1319
1320 break;
Jani Nikulab34a9912015-05-13 15:34:04 +03001321 }
1322
Jani Nikulaf0067a32015-12-15 13:16:15 +02001323 return NULL;
Jani Nikulab34a9912015-05-13 15:34:04 +03001324}
1325
Jesse Barnes79e53942008-11-07 14:24:08 -08001326/**
Jani Nikula8b8e1a82015-12-14 12:50:49 +02001327 * intel_bios_init - find VBT and initialize settings from the BIOS
Jani Nikuladd97950a2015-12-21 15:10:52 +02001328 * @dev_priv: i915 device instance
Jesse Barnes79e53942008-11-07 14:24:08 -08001329 *
1330 * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
1331 * to appropriate values.
1332 *
Jesse Barnes79e53942008-11-07 14:24:08 -08001333 * Returns 0 on success, nonzero on failure.
1334 */
Dan Carpenter0317c6c2012-06-27 12:10:30 +03001335int
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001336intel_bios_init(struct drm_i915_private *dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -08001337{
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001338 struct pci_dev *pdev = dev_priv->dev->pdev;
Jani Nikulaf0067a32015-12-15 13:16:15 +02001339 const struct vbt_header *vbt = dev_priv->opregion.vbt;
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001340 const struct bdb_header *bdb;
Chris Wilson44834a62010-08-19 16:09:23 +01001341 u8 __iomem *bios = NULL;
Jesse Barnes79e53942008-11-07 14:24:08 -08001342
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001343 if (HAS_PCH_NOP(dev_priv))
Ben Widawskyab5c6082013-04-05 13:12:41 -07001344 return -ENODEV;
1345
Simon Que6a040022010-09-30 09:36:39 +01001346 init_vbt_defaults(dev_priv);
Chris Wilsonf899fc62010-07-20 15:44:45 -07001347
Jani Nikulaf0067a32015-12-15 13:16:15 +02001348 if (!vbt) {
Jani Nikulab34a9912015-05-13 15:34:04 +03001349 size_t size;
Chris Wilson44834a62010-08-19 16:09:23 +01001350
1351 bios = pci_map_rom(pdev, &size);
1352 if (!bios)
1353 return -1;
1354
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001355 vbt = find_vbt(bios, size);
1356 if (!vbt) {
Chris Wilson44834a62010-08-19 16:09:23 +01001357 pci_unmap_rom(pdev, bios);
1358 return -1;
1359 }
Jani Nikulae2051c42015-12-15 13:14:52 +02001360
1361 DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
Chris Wilson44834a62010-08-19 16:09:23 +01001362 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001363
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001364 bdb = get_bdb_header(vbt);
1365
Jani Nikula3556dd42015-12-16 15:04:19 +02001366 DRM_DEBUG_KMS("VBT signature \"%.*s\", BDB version %d\n",
1367 (int)sizeof(vbt->signature), vbt->signature, bdb->version);
Jani Nikulae2051c42015-12-15 13:14:52 +02001368
Jesse Barnes79e53942008-11-07 14:24:08 -08001369 /* Grab useful general definitions */
1370 parse_general_features(dev_priv, bdb);
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +02001371 parse_general_definitions(dev_priv, bdb);
Ma Ling88631702009-05-13 11:19:55 +08001372 parse_lfp_panel_data(dev_priv, bdb);
Jani Nikulaf00076d2013-12-14 20:38:29 -02001373 parse_lfp_backlight(dev_priv, bdb);
Ma Ling88631702009-05-13 11:19:55 +08001374 parse_sdvo_panel_data(dev_priv, bdb);
yakui_zhao9b9d1722009-05-31 17:17:17 +08001375 parse_sdvo_device_mapping(dev_priv, bdb);
Zhao Yakui6363ee62009-11-24 09:48:44 +08001376 parse_device_mapping(dev_priv, bdb);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001377 parse_driver_features(dev_priv, bdb);
Zhenyu Wang500a8cc2010-01-13 11:19:52 +08001378 parse_edp(dev_priv, bdb);
Rodrigo Vivibfd7ebd2014-11-14 08:52:30 -08001379 parse_psr(dev_priv, bdb);
Jani Nikula0f8689f2015-12-21 15:10:54 +02001380 parse_mipi_config(dev_priv, bdb);
1381 parse_mipi_sequence(dev_priv, bdb);
Paulo Zanoni6acab152013-09-12 17:06:24 -03001382 parse_ddi_ports(dev_priv, bdb);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001383
Chris Wilson44834a62010-08-19 16:09:23 +01001384 if (bios)
1385 pci_unmap_rom(pdev, bios);
Jesse Barnes79e53942008-11-07 14:24:08 -08001386
1387 return 0;
1388}