blob: 15ba52bd25380e312876ba350cdc861c04b1102d [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 Nikuladd979502015-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
Zhenyu Wang500a8cc2010-01-13 11:19:52 +0800700static void
Jani Nikula0f8689f2015-12-21 15:10:54 +0200701parse_mipi_config(struct drm_i915_private *dev_priv,
702 const struct bdb_header *bdb)
Shobhit Kumard17c5442013-08-27 15:12:25 +0300703{
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300704 const struct bdb_mipi_config *start;
Jani Nikulae8ef3b42015-04-15 15:18:28 +0300705 const struct mipi_config *config;
706 const struct mipi_pps_data *pps;
Shobhit Kumard17c5442013-08-27 15:12:25 +0300707
Shobhit Kumar3e6bd012014-05-27 19:33:59 +0530708 /* parse MIPI blocks only if LFP type is MIPI */
709 if (!dev_priv->vbt.has_mipi)
710 return;
711
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530712 /* Initialize this to undefined indicating no generic MIPI support */
713 dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
714
715 /* Block #40 is already parsed and panel_fixed_mode is
716 * stored in dev_priv->lfp_lvds_vbt_mode
717 * resuse this when needed
718 */
719
720 /* Parse #52 for panel index used from panel_type already
721 * parsed
722 */
723 start = find_section(bdb, BDB_MIPI_CONFIG);
724 if (!start) {
725 DRM_DEBUG_KMS("No MIPI config BDB found");
Shobhit Kumard17c5442013-08-27 15:12:25 +0300726 return;
727 }
728
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530729 DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
730 panel_type);
731
732 /*
733 * get hold of the correct configuration block and pps data as per
734 * the panel_type as index
735 */
736 config = &start->config[panel_type];
737 pps = &start->pps[panel_type];
738
739 /* store as of now full data. Trim when we realise all is not needed */
740 dev_priv->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
741 if (!dev_priv->vbt.dsi.config)
742 return;
743
744 dev_priv->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
745 if (!dev_priv->vbt.dsi.pps) {
746 kfree(dev_priv->vbt.dsi.config);
747 return;
748 }
749
750 /* We have mandatory mipi config blocks. Initialize as generic panel */
Shobhit Kumarea9a6ba2014-02-28 11:18:46 +0530751 dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
Jani Nikula0f8689f2015-12-21 15:10:54 +0200752}
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530753
Jani Nikula5db72092016-01-05 15:50:51 +0200754/* Find the sequence block and size for the given panel. */
755static const u8 *
756find_panel_sequence_block(const struct bdb_mipi_sequence *sequence,
Jani Nikula2a33d932016-01-11 15:15:02 +0200757 u16 panel_id, u32 *seq_size)
Jani Nikula5db72092016-01-05 15:50:51 +0200758{
759 u32 total = get_blocksize(sequence);
760 const u8 *data = &sequence->data[0];
761 u8 current_id;
Jani Nikula2a33d932016-01-11 15:15:02 +0200762 u32 current_size;
763 int header_size = sequence->version >= 3 ? 5 : 3;
Jani Nikula5db72092016-01-05 15:50:51 +0200764 int index = 0;
765 int i;
766
Jani Nikula2a33d932016-01-11 15:15:02 +0200767 /* skip new block size */
768 if (sequence->version >= 3)
769 data += 4;
Jani Nikula5db72092016-01-05 15:50:51 +0200770
Jani Nikula2a33d932016-01-11 15:15:02 +0200771 for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index < total; i++) {
772 if (index + header_size > total) {
773 DRM_ERROR("Invalid sequence block (header)\n");
774 return NULL;
775 }
776
777 current_id = *(data + index);
778 if (sequence->version >= 3)
779 current_size = *((const u32 *)(data + index + 1));
780 else
781 current_size = *((const u16 *)(data + index + 1));
782
783 index += header_size;
Jani Nikula5db72092016-01-05 15:50:51 +0200784
785 if (index + current_size > total) {
786 DRM_ERROR("Invalid sequence block\n");
787 return NULL;
788 }
789
790 if (current_id == panel_id) {
791 *seq_size = current_size;
792 return data + index;
793 }
794
795 index += current_size;
796 }
797
798 DRM_ERROR("Sequence block detected but no valid configuration\n");
799
800 return NULL;
801}
802
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200803static int goto_next_sequence(const u8 *data, int index, int total)
804{
805 u16 len;
806
807 /* Skip Sequence Byte. */
808 for (index = index + 1; index < total; index += len) {
809 u8 operation_byte = *(data + index);
810 index++;
811
812 switch (operation_byte) {
813 case MIPI_SEQ_ELEM_END:
814 return index;
815 case MIPI_SEQ_ELEM_SEND_PKT:
816 if (index + 4 > total)
817 return 0;
818
819 len = *((const u16 *)(data + index + 2)) + 4;
820 break;
821 case MIPI_SEQ_ELEM_DELAY:
822 len = 4;
823 break;
824 case MIPI_SEQ_ELEM_GPIO:
825 len = 2;
826 break;
Jani Nikulaf4d64932015-12-21 15:11:00 +0200827 case MIPI_SEQ_ELEM_I2C:
828 if (index + 7 > total)
829 return 0;
830 len = *(data + index + 6) + 7;
831 break;
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200832 default:
833 DRM_ERROR("Unknown operation byte\n");
834 return 0;
835 }
836 }
837
838 return 0;
839}
840
Jani Nikula2a33d932016-01-11 15:15:02 +0200841static int goto_next_sequence_v3(const u8 *data, int index, int total)
842{
843 int seq_end;
844 u16 len;
845
846 /*
847 * Could skip sequence based on Size of Sequence alone, but also do some
848 * checking on the structure.
849 */
850 if (total < 5) {
851 DRM_ERROR("Too small sequence size\n");
852 return 0;
853 }
854
855 seq_end = index + *((const u32 *)(data + 1));
856 if (seq_end > total) {
857 DRM_ERROR("Invalid sequence size\n");
858 return 0;
859 }
860
861 /* Skip Sequence Byte and Size of Sequence. */
862 for (index = index + 5; index < total; index += len) {
863 u8 operation_byte = *(data + index);
864 index++;
865
866 if (operation_byte == MIPI_SEQ_ELEM_END) {
867 if (index != seq_end) {
868 DRM_ERROR("Invalid element structure\n");
869 return 0;
870 }
871 return index;
872 }
873
874 len = *(data + index);
875 index++;
876
877 /*
878 * FIXME: Would be nice to check elements like for v1/v2 in
879 * goto_next_sequence() above.
880 */
881 switch (operation_byte) {
882 case MIPI_SEQ_ELEM_SEND_PKT:
883 case MIPI_SEQ_ELEM_DELAY:
884 case MIPI_SEQ_ELEM_GPIO:
885 case MIPI_SEQ_ELEM_I2C:
886 case MIPI_SEQ_ELEM_SPI:
887 case MIPI_SEQ_ELEM_PMIC:
888 break;
889 default:
890 DRM_ERROR("Unknown operation byte %u\n",
891 operation_byte);
892 break;
893 }
894 }
895
896 return 0;
897}
898
Jani Nikula0f8689f2015-12-21 15:10:54 +0200899static void
900parse_mipi_sequence(struct drm_i915_private *dev_priv,
901 const struct bdb_header *bdb)
902{
903 const struct bdb_mipi_sequence *sequence;
904 const u8 *seq_data;
Jani Nikula2a33d932016-01-11 15:15:02 +0200905 u32 seq_size;
Jani Nikula0f8689f2015-12-21 15:10:54 +0200906 u8 *data;
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200907 int index = 0;
Jani Nikula0f8689f2015-12-21 15:10:54 +0200908
909 /* Only our generic panel driver uses the sequence block. */
910 if (dev_priv->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
911 return;
912
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530913 sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
914 if (!sequence) {
915 DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
916 return;
917 }
918
Jani Nikulacd67d222015-09-17 16:42:07 +0300919 /* Fail gracefully for forward incompatible sequence block. */
Jani Nikula2a33d932016-01-11 15:15:02 +0200920 if (sequence->version >= 4) {
921 DRM_ERROR("Unable to parse MIPI Sequence Block v%u\n",
922 sequence->version);
Jani Nikulacd67d222015-09-17 16:42:07 +0300923 return;
924 }
925
Jani Nikula2a33d932016-01-11 15:15:02 +0200926 DRM_DEBUG_DRIVER("Found MIPI sequence block v%u\n", sequence->version);
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530927
Jani Nikula5db72092016-01-05 15:50:51 +0200928 seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size);
929 if (!seq_data)
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530930 return;
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530931
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200932 data = kmemdup(seq_data, seq_size, GFP_KERNEL);
933 if (!data)
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530934 return;
935
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200936 /* Parse the sequences, store pointers to each sequence. */
937 for (;;) {
938 u8 seq_id = *(data + index);
939 if (seq_id == MIPI_SEQ_END)
940 break;
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530941
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200942 if (seq_id >= MIPI_SEQ_MAX) {
943 DRM_ERROR("Unknown sequence %u\n", seq_id);
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530944 goto err;
945 }
946
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200947 dev_priv->vbt.dsi.sequence[seq_id] = data + index;
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530948
Jani Nikula2a33d932016-01-11 15:15:02 +0200949 if (sequence->version >= 3)
950 index = goto_next_sequence_v3(data, index, seq_size);
951 else
952 index = goto_next_sequence(data, index, seq_size);
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200953 if (!index) {
954 DRM_ERROR("Invalid sequence %u\n", seq_id);
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530955 goto err;
956 }
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530957 }
958
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200959 dev_priv->vbt.dsi.data = data;
960 dev_priv->vbt.dsi.size = seq_size;
961 dev_priv->vbt.dsi.seq_version = sequence->version;
Shobhit Kumard3b542f2014-04-14 11:00:34 +0530962
Jani Nikula8d3ed2f2015-12-21 15:10:57 +0200963 DRM_DEBUG_DRIVER("MIPI related VBT parsing complete\n");
964 return;
965
966err:
967 kfree(data);
Rafael Barbalhoed3b6672014-07-24 15:16:12 +0100968 memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
Shobhit Kumard17c5442013-08-27 15:12:25 +0300969}
970
Antti Koskipaa75067dd2015-07-10 14:10:55 +0300971static u8 translate_iboost(u8 val)
972{
973 static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
974
975 if (val >= ARRAY_SIZE(mapping)) {
976 DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
977 return 0;
978 }
979 return mapping[val];
980}
981
Paulo Zanoni6acab152013-09-12 17:06:24 -0300982static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
Jani Nikuladcb58a42015-05-12 15:41:32 +0300983 const struct bdb_header *bdb)
Paulo Zanoni6acab152013-09-12 17:06:24 -0300984{
985 union child_device_config *it, *child = NULL;
986 struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
987 uint8_t hdmi_level_shift;
988 int i, j;
Paulo Zanoni554d6af2013-09-12 17:10:11 -0300989 bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
Xiong Zhang11c1b652015-08-17 16:04:04 +0800990 uint8_t aux_channel, ddc_pin;
Paulo Zanoni6acab152013-09-12 17:06:24 -0300991 /* Each DDI port can have more than one value on the "DVO Port" field,
992 * so look for all the possible values for each port and abort if more
993 * than one is found. */
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -0700994 int dvo_ports[][3] = {
995 {DVO_PORT_HDMIA, DVO_PORT_DPA, -1},
996 {DVO_PORT_HDMIB, DVO_PORT_DPB, -1},
997 {DVO_PORT_HDMIC, DVO_PORT_DPC, -1},
998 {DVO_PORT_HDMID, DVO_PORT_DPD, -1},
999 {DVO_PORT_CRT, DVO_PORT_HDMIE, DVO_PORT_DPE},
Paulo Zanoni6acab152013-09-12 17:06:24 -03001000 };
1001
1002 /* Find the child device to use, abort if more than one found. */
1003 for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
1004 it = dev_priv->vbt.child_dev + i;
1005
Rodrigo Vivi2800e4c2015-08-07 17:35:21 -07001006 for (j = 0; j < 3; j++) {
Paulo Zanoni6acab152013-09-12 17:06:24 -03001007 if (dvo_ports[port][j] == -1)
1008 break;
1009
1010 if (it->common.dvo_port == dvo_ports[port][j]) {
1011 if (child) {
1012 DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
1013 port_name(port));
1014 return;
1015 }
1016 child = it;
1017 }
1018 }
1019 }
1020 if (!child)
1021 return;
1022
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001023 aux_channel = child->raw[25];
Xiong Zhang11c1b652015-08-17 16:04:04 +08001024 ddc_pin = child->common.ddc_pin;
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001025
Ville Syrjälä78eb06c2013-11-01 20:32:07 +02001026 is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
1027 is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
1028 is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
1029 is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
1030 is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
Paulo Zanoni554d6af2013-09-12 17:10:11 -03001031
Paulo Zanoni311a2092013-09-12 17:12:18 -03001032 info->supports_dvi = is_dvi;
1033 info->supports_hdmi = is_hdmi;
1034 info->supports_dp = is_dp;
1035
Paulo Zanoni554d6af2013-09-12 17:10:11 -03001036 DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
1037 port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
1038
1039 if (is_edp && is_dvi)
1040 DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
1041 port_name(port));
1042 if (is_crt && port != PORT_E)
1043 DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
1044 if (is_crt && (is_dvi || is_dp))
1045 DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
1046 port_name(port));
1047 if (is_dvi && (port == PORT_A || port == PORT_E))
Masanari Iida9b134942014-08-06 22:31:28 +09001048 DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port));
Paulo Zanoni554d6af2013-09-12 17:10:11 -03001049 if (!is_dvi && !is_dp && !is_crt)
1050 DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
1051 port_name(port));
1052 if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
1053 DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001054
1055 if (is_dvi) {
Xiong Zhang11c1b652015-08-17 16:04:04 +08001056 if (port == PORT_E) {
1057 info->alternate_ddc_pin = ddc_pin;
1058 /* if DDIE share ddc pin with other port, then
1059 * dvi/hdmi couldn't exist on the shared port.
1060 * Otherwise they share the same ddc bin and system
1061 * couldn't communicate with them seperately. */
1062 if (ddc_pin == DDC_PIN_B) {
1063 dev_priv->vbt.ddi_port_info[PORT_B].supports_dvi = 0;
1064 dev_priv->vbt.ddi_port_info[PORT_B].supports_hdmi = 0;
1065 } else if (ddc_pin == DDC_PIN_C) {
1066 dev_priv->vbt.ddi_port_info[PORT_C].supports_dvi = 0;
1067 dev_priv->vbt.ddi_port_info[PORT_C].supports_hdmi = 0;
1068 } else if (ddc_pin == DDC_PIN_D) {
1069 dev_priv->vbt.ddi_port_info[PORT_D].supports_dvi = 0;
1070 dev_priv->vbt.ddi_port_info[PORT_D].supports_hdmi = 0;
1071 }
1072 } else if (ddc_pin == DDC_PIN_B && port != PORT_B)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001073 DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
Xiong Zhang11c1b652015-08-17 16:04:04 +08001074 else if (ddc_pin == DDC_PIN_C && port != PORT_C)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001075 DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
Xiong Zhang11c1b652015-08-17 16:04:04 +08001076 else if (ddc_pin == DDC_PIN_D && port != PORT_D)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001077 DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
1078 }
1079
1080 if (is_dp) {
Rodrigo Vivi500ea702015-08-07 17:01:16 -07001081 if (port == PORT_E) {
1082 info->alternate_aux_channel = aux_channel;
1083 /* if DDIE share aux channel with other port, then
1084 * DP couldn't exist on the shared port. Otherwise
1085 * they share the same aux channel and system
1086 * couldn't communicate with them seperately. */
1087 if (aux_channel == DP_AUX_A)
1088 dev_priv->vbt.ddi_port_info[PORT_A].supports_dp = 0;
1089 else if (aux_channel == DP_AUX_B)
1090 dev_priv->vbt.ddi_port_info[PORT_B].supports_dp = 0;
1091 else if (aux_channel == DP_AUX_C)
1092 dev_priv->vbt.ddi_port_info[PORT_C].supports_dp = 0;
1093 else if (aux_channel == DP_AUX_D)
1094 dev_priv->vbt.ddi_port_info[PORT_D].supports_dp = 0;
1095 }
1096 else if (aux_channel == DP_AUX_A && port != PORT_A)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001097 DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
Rodrigo Vivi500ea702015-08-07 17:01:16 -07001098 else if (aux_channel == DP_AUX_B && port != PORT_B)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001099 DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
Rodrigo Vivi500ea702015-08-07 17:01:16 -07001100 else if (aux_channel == DP_AUX_C && port != PORT_C)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001101 DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
Rodrigo Vivi500ea702015-08-07 17:01:16 -07001102 else if (aux_channel == DP_AUX_D && port != PORT_D)
Paulo Zanoni6bf19e72013-09-12 17:07:55 -03001103 DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
1104 }
1105
Paulo Zanoni6acab152013-09-12 17:06:24 -03001106 if (bdb->version >= 158) {
1107 /* The VBT HDMI level shift values match the table we have. */
1108 hdmi_level_shift = child->raw[7] & 0xF;
Damien Lespiauce4dd492014-08-01 11:07:54 +01001109 DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
1110 port_name(port),
1111 hdmi_level_shift);
1112 info->hdmi_level_shift = hdmi_level_shift;
Paulo Zanoni6acab152013-09-12 17:06:24 -03001113 }
Antti Koskipaa75067dd2015-07-10 14:10:55 +03001114
1115 /* Parse the I_boost config for SKL and above */
1116 if (bdb->version >= 196 && (child->common.flags_1 & IBOOST_ENABLE)) {
1117 info->dp_boost_level = translate_iboost(child->common.iboost_level & 0xF);
1118 DRM_DEBUG_KMS("VBT (e)DP boost level for port %c: %d\n",
1119 port_name(port), info->dp_boost_level);
1120 info->hdmi_boost_level = translate_iboost(child->common.iboost_level >> 4);
1121 DRM_DEBUG_KMS("VBT HDMI boost level for port %c: %d\n",
1122 port_name(port), info->hdmi_boost_level);
1123 }
Paulo Zanoni6acab152013-09-12 17:06:24 -03001124}
1125
1126static void parse_ddi_ports(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +03001127 const struct bdb_header *bdb)
Paulo Zanoni6acab152013-09-12 17:06:24 -03001128{
Paulo Zanoni6acab152013-09-12 17:06:24 -03001129 enum port port;
1130
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001131 if (!HAS_DDI(dev_priv))
Paulo Zanoni6acab152013-09-12 17:06:24 -03001132 return;
1133
1134 if (!dev_priv->vbt.child_dev_num)
1135 return;
1136
1137 if (bdb->version < 155)
1138 return;
1139
1140 for (port = PORT_A; port < I915_MAX_PORTS; port++)
1141 parse_ddi_port(dev_priv, port, bdb);
1142}
1143
Shobhit Kumard17c5442013-08-27 15:12:25 +03001144static void
Zhao Yakui6363ee62009-11-24 09:48:44 +08001145parse_device_mapping(struct drm_i915_private *dev_priv,
Jani Nikuladcb58a42015-05-12 15:41:32 +03001146 const struct bdb_header *bdb)
Zhao Yakui6363ee62009-11-24 09:48:44 +08001147{
Jani Nikulae8ef3b42015-04-15 15:18:28 +03001148 const struct bdb_general_definitions *p_defs;
1149 const union child_device_config *p_child;
1150 union child_device_config *child_dev_ptr;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001151 int i, child_device_num, count;
David Weinehalle2d6cf72015-08-21 16:52:01 +03001152 u8 expected_size;
1153 u16 block_size;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001154
1155 p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
1156 if (!p_defs) {
Chris Wilson44834a62010-08-19 16:09:23 +01001157 DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
Zhao Yakui6363ee62009-11-24 09:48:44 +08001158 return;
1159 }
David Weinehalle2d6cf72015-08-21 16:52:01 +03001160 if (bdb->version < 195) {
1161 expected_size = sizeof(struct old_child_dev_config);
1162 } else if (bdb->version == 195) {
1163 expected_size = 37;
1164 } else if (bdb->version <= 197) {
1165 expected_size = 38;
1166 } else {
1167 expected_size = 38;
1168 BUILD_BUG_ON(sizeof(*p_child) < 38);
1169 DRM_DEBUG_DRIVER("Expected child device config size for VBT version %u not known; assuming %u\n",
1170 bdb->version, expected_size);
1171 }
1172
1173 /* The legacy sized child device config is the minimum we need. */
1174 if (p_defs->child_dev_size < sizeof(struct old_child_dev_config)) {
1175 DRM_ERROR("Child device config size %u is too small.\n",
1176 p_defs->child_dev_size);
Zhao Yakui6363ee62009-11-24 09:48:44 +08001177 return;
1178 }
David Weinehalle2d6cf72015-08-21 16:52:01 +03001179
1180 /* Flag an error for unexpected size, but continue anyway. */
1181 if (p_defs->child_dev_size != expected_size)
1182 DRM_ERROR("Unexpected child device config size %u (expected %u for VBT version %u)\n",
1183 p_defs->child_dev_size, expected_size, bdb->version);
1184
Zhao Yakui6363ee62009-11-24 09:48:44 +08001185 /* get the block size of general definitions */
1186 block_size = get_blocksize(p_defs);
1187 /* get the number of child device */
1188 child_device_num = (block_size - sizeof(*p_defs)) /
Ville Syrjälä90e4f152015-03-25 18:45:58 +02001189 p_defs->child_dev_size;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001190 count = 0;
1191 /* get the number of child device that is present */
1192 for (i = 0; i < child_device_num; i++) {
Ville Syrjälä90e4f152015-03-25 18:45:58 +02001193 p_child = child_device_ptr(p_defs, i);
Paulo Zanoni768f69c2013-09-11 18:02:47 -03001194 if (!p_child->common.device_type) {
Zhao Yakui6363ee62009-11-24 09:48:44 +08001195 /* skip the device block if device type is invalid */
1196 continue;
1197 }
1198 count++;
1199 }
1200 if (!count) {
Akshay Joshi0206e352011-08-16 15:34:10 -04001201 DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
Zhao Yakui6363ee62009-11-24 09:48:44 +08001202 return;
1203 }
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001204 dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
1205 if (!dev_priv->vbt.child_dev) {
Zhao Yakui6363ee62009-11-24 09:48:44 +08001206 DRM_DEBUG_KMS("No memory space for child device\n");
1207 return;
1208 }
1209
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001210 dev_priv->vbt.child_dev_num = count;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001211 count = 0;
1212 for (i = 0; i < child_device_num; i++) {
Ville Syrjälä90e4f152015-03-25 18:45:58 +02001213 p_child = child_device_ptr(p_defs, i);
Paulo Zanoni768f69c2013-09-11 18:02:47 -03001214 if (!p_child->common.device_type) {
Zhao Yakui6363ee62009-11-24 09:48:44 +08001215 /* skip the device block if device type is invalid */
1216 continue;
1217 }
Shobhit Kumar3e6bd012014-05-27 19:33:59 +05301218
1219 if (p_child->common.dvo_port >= DVO_PORT_MIPIA
1220 && p_child->common.dvo_port <= DVO_PORT_MIPID
1221 &&p_child->common.device_type & DEVICE_TYPE_MIPI_OUTPUT) {
1222 DRM_DEBUG_KMS("Found MIPI as LFP\n");
1223 dev_priv->vbt.has_mipi = 1;
1224 dev_priv->vbt.dsi.port = p_child->common.dvo_port;
1225 }
1226
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001227 child_dev_ptr = dev_priv->vbt.child_dev + count;
Zhao Yakui6363ee62009-11-24 09:48:44 +08001228 count++;
David Weinehalle2d6cf72015-08-21 16:52:01 +03001229
1230 /*
1231 * Copy as much as we know (sizeof) and is available
1232 * (child_dev_size) of the child device. Accessing the data must
1233 * depend on VBT version.
1234 */
1235 memcpy(child_dev_ptr, p_child,
1236 min_t(size_t, p_defs->child_dev_size, sizeof(*p_child)));
Zhao Yakui6363ee62009-11-24 09:48:44 +08001237 }
1238 return;
1239}
Chris Wilson44834a62010-08-19 16:09:23 +01001240
Simon Que6a040022010-09-30 09:36:39 +01001241static void
1242init_vbt_defaults(struct drm_i915_private *dev_priv)
1243{
Paulo Zanoni6acab152013-09-12 17:06:24 -03001244 enum port port;
Bryan Freed9a4114f2011-01-12 13:38:39 -08001245
Jani Nikula988c7012015-03-27 00:20:19 +02001246 dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
Simon Que6a040022010-09-30 09:36:39 +01001247
Jani Nikula56c4b632014-06-17 15:47:05 +03001248 /* Default to having backlight */
1249 dev_priv->vbt.backlight.present = true;
1250
Simon Que6a040022010-09-30 09:36:39 +01001251 /* LFP panel data */
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001252 dev_priv->vbt.lvds_dither = 1;
1253 dev_priv->vbt.lvds_vbt = 0;
Simon Que6a040022010-09-30 09:36:39 +01001254
1255 /* SDVO panel data */
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001256 dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
Simon Que6a040022010-09-30 09:36:39 +01001257
1258 /* general features */
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001259 dev_priv->vbt.int_tv_support = 1;
1260 dev_priv->vbt.int_crt_support = 1;
Bryan Freed9a4114f2011-01-12 13:38:39 -08001261
1262 /* Default to using SSC */
Rodrigo Vivi41aa3442013-05-09 20:03:18 -03001263 dev_priv->vbt.lvds_use_ssc = 1;
Duncan Laurief69e5152013-11-13 17:59:43 -08001264 /*
1265 * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
1266 * clock for LVDS.
1267 */
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001268 dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev_priv,
1269 !HAS_PCH_SPLIT(dev_priv));
Ville Syrjäläe91e9412013-12-09 18:54:16 +02001270 DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
Paulo Zanoni6acab152013-09-12 17:06:24 -03001271
1272 for (port = PORT_A; port < I915_MAX_PORTS; port++) {
Paulo Zanoni311a2092013-09-12 17:12:18 -03001273 struct ddi_vbt_port_info *info =
1274 &dev_priv->vbt.ddi_port_info[port];
1275
Damien Lespiauce4dd492014-08-01 11:07:54 +01001276 info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
Paulo Zanoni311a2092013-09-12 17:12:18 -03001277
1278 info->supports_dvi = (port != PORT_A && port != PORT_E);
1279 info->supports_hdmi = info->supports_dvi;
1280 info->supports_dp = (port != PORT_E);
Paulo Zanoni6acab152013-09-12 17:06:24 -03001281 }
Simon Que6a040022010-09-30 09:36:39 +01001282}
1283
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001284static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
1285{
1286 const void *_vbt = vbt;
1287
1288 return _vbt + vbt->bdb_offset;
1289}
1290
Jani Nikulaf0067a32015-12-15 13:16:15 +02001291/**
1292 * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
1293 * @buf: pointer to a buffer to validate
1294 * @size: size of the buffer
1295 *
1296 * Returns true on valid VBT.
1297 */
1298bool intel_bios_is_valid_vbt(const void *buf, size_t size)
Chris Wilson3dd4e842014-04-18 18:04:22 -03001299{
Jani Nikulaf0067a32015-12-15 13:16:15 +02001300 const struct vbt_header *vbt = buf;
Jani Nikuladcb58a42015-05-12 15:41:32 +03001301 const struct bdb_header *bdb;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001302
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001303 if (!vbt)
Jani Nikulaf0067a32015-12-15 13:16:15 +02001304 return false;
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001305
Jani Nikulaf0067a32015-12-15 13:16:15 +02001306 if (sizeof(struct vbt_header) > size) {
Chris Wilson3dd4e842014-04-18 18:04:22 -03001307 DRM_DEBUG_DRIVER("VBT header incomplete\n");
Jani Nikulaf0067a32015-12-15 13:16:15 +02001308 return false;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001309 }
1310
1311 if (memcmp(vbt->signature, "$VBT", 4)) {
1312 DRM_DEBUG_DRIVER("VBT invalid signature\n");
Jani Nikulaf0067a32015-12-15 13:16:15 +02001313 return false;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001314 }
1315
Jani Nikulaf0067a32015-12-15 13:16:15 +02001316 if (vbt->bdb_offset + sizeof(struct bdb_header) > size) {
Chris Wilson3dd4e842014-04-18 18:04:22 -03001317 DRM_DEBUG_DRIVER("BDB header incomplete\n");
Jani Nikulaf0067a32015-12-15 13:16:15 +02001318 return false;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001319 }
1320
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001321 bdb = get_bdb_header(vbt);
Jani Nikulaf0067a32015-12-15 13:16:15 +02001322 if (vbt->bdb_offset + bdb->bdb_size > size) {
Chris Wilson3dd4e842014-04-18 18:04:22 -03001323 DRM_DEBUG_DRIVER("BDB incomplete\n");
Jani Nikulaf0067a32015-12-15 13:16:15 +02001324 return false;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001325 }
1326
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001327 return vbt;
Chris Wilson3dd4e842014-04-18 18:04:22 -03001328}
1329
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001330static const struct vbt_header *find_vbt(void __iomem *bios, size_t size)
Jani Nikulab34a9912015-05-13 15:34:04 +03001331{
Jani Nikulab34a9912015-05-13 15:34:04 +03001332 size_t i;
1333
1334 /* Scour memory looking for the VBT signature. */
1335 for (i = 0; i + 4 < size; i++) {
Jani Nikulaf0067a32015-12-15 13:16:15 +02001336 void *vbt;
Williams, Dan J115719f2015-10-12 21:12:57 +00001337
Jani Nikulaf0067a32015-12-15 13:16:15 +02001338 if (ioread32(bios + i) != *((const u32 *) "$VBT"))
1339 continue;
1340
1341 /*
1342 * This is the one place where we explicitly discard the address
1343 * space (__iomem) of the BIOS/VBT.
1344 */
1345 vbt = (void __force *) bios + i;
1346 if (intel_bios_is_valid_vbt(vbt, size - i))
1347 return vbt;
1348
1349 break;
Jani Nikulab34a9912015-05-13 15:34:04 +03001350 }
1351
Jani Nikulaf0067a32015-12-15 13:16:15 +02001352 return NULL;
Jani Nikulab34a9912015-05-13 15:34:04 +03001353}
1354
Jesse Barnes79e53942008-11-07 14:24:08 -08001355/**
Jani Nikula8b8e1a82015-12-14 12:50:49 +02001356 * intel_bios_init - find VBT and initialize settings from the BIOS
Jani Nikuladd979502015-12-21 15:10:52 +02001357 * @dev_priv: i915 device instance
Jesse Barnes79e53942008-11-07 14:24:08 -08001358 *
1359 * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
1360 * to appropriate values.
1361 *
Jesse Barnes79e53942008-11-07 14:24:08 -08001362 * Returns 0 on success, nonzero on failure.
1363 */
Dan Carpenter0317c6c2012-06-27 12:10:30 +03001364int
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001365intel_bios_init(struct drm_i915_private *dev_priv)
Jesse Barnes79e53942008-11-07 14:24:08 -08001366{
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001367 struct pci_dev *pdev = dev_priv->dev->pdev;
Jani Nikulaf0067a32015-12-15 13:16:15 +02001368 const struct vbt_header *vbt = dev_priv->opregion.vbt;
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001369 const struct bdb_header *bdb;
Chris Wilson44834a62010-08-19 16:09:23 +01001370 u8 __iomem *bios = NULL;
Jesse Barnes79e53942008-11-07 14:24:08 -08001371
Jani Nikula98f3a1d2015-12-16 15:04:20 +02001372 if (HAS_PCH_NOP(dev_priv))
Ben Widawskyab5c6082013-04-05 13:12:41 -07001373 return -ENODEV;
1374
Simon Que6a040022010-09-30 09:36:39 +01001375 init_vbt_defaults(dev_priv);
Chris Wilsonf899fc62010-07-20 15:44:45 -07001376
Jani Nikulaf0067a32015-12-15 13:16:15 +02001377 if (!vbt) {
Jani Nikulab34a9912015-05-13 15:34:04 +03001378 size_t size;
Chris Wilson44834a62010-08-19 16:09:23 +01001379
1380 bios = pci_map_rom(pdev, &size);
1381 if (!bios)
1382 return -1;
1383
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001384 vbt = find_vbt(bios, size);
1385 if (!vbt) {
Chris Wilson44834a62010-08-19 16:09:23 +01001386 pci_unmap_rom(pdev, bios);
1387 return -1;
1388 }
Jani Nikulae2051c42015-12-15 13:14:52 +02001389
1390 DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
Chris Wilson44834a62010-08-19 16:09:23 +01001391 }
Jesse Barnes79e53942008-11-07 14:24:08 -08001392
Jani Nikulacaf37fa2015-12-14 12:50:47 +02001393 bdb = get_bdb_header(vbt);
1394
Jani Nikula3556dd42015-12-16 15:04:19 +02001395 DRM_DEBUG_KMS("VBT signature \"%.*s\", BDB version %d\n",
1396 (int)sizeof(vbt->signature), vbt->signature, bdb->version);
Jani Nikulae2051c42015-12-15 13:14:52 +02001397
Jesse Barnes79e53942008-11-07 14:24:08 -08001398 /* Grab useful general definitions */
1399 parse_general_features(dev_priv, bdb);
David Müller (ELSOFT AG)db545012009-08-29 08:54:45 +02001400 parse_general_definitions(dev_priv, bdb);
Ma Ling88631702009-05-13 11:19:55 +08001401 parse_lfp_panel_data(dev_priv, bdb);
Jani Nikulaf00076d2013-12-14 20:38:29 -02001402 parse_lfp_backlight(dev_priv, bdb);
Ma Ling88631702009-05-13 11:19:55 +08001403 parse_sdvo_panel_data(dev_priv, bdb);
yakui_zhao9b9d1722009-05-31 17:17:17 +08001404 parse_sdvo_device_mapping(dev_priv, bdb);
Zhao Yakui6363ee62009-11-24 09:48:44 +08001405 parse_device_mapping(dev_priv, bdb);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001406 parse_driver_features(dev_priv, bdb);
Zhenyu Wang500a8cc2010-01-13 11:19:52 +08001407 parse_edp(dev_priv, bdb);
Rodrigo Vivibfd7ebd2014-11-14 08:52:30 -08001408 parse_psr(dev_priv, bdb);
Jani Nikula0f8689f2015-12-21 15:10:54 +02001409 parse_mipi_config(dev_priv, bdb);
1410 parse_mipi_sequence(dev_priv, bdb);
Paulo Zanoni6acab152013-09-12 17:06:24 -03001411 parse_ddi_ports(dev_priv, bdb);
Zhenyu Wang32f9d652009-07-24 01:00:32 +08001412
Chris Wilson44834a62010-08-19 16:09:23 +01001413 if (bios)
1414 pci_unmap_rom(pdev, bios);
Jesse Barnes79e53942008-11-07 14:24:08 -08001415
1416 return 0;
1417}