Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
Keith Packard | 3950725 | 2011-09-22 12:30:16 -0700 | [diff] [blame] | 2 | * Copyright © 2006 Intel Corporation |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3 | * |
| 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 Nikula | b30581a | 2015-12-14 12:50:46 +0200 | [diff] [blame] | 27 | |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 28 | #include <drm/drm_dp_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 29 | #include <drm/drmP.h> |
| 30 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 31 | #include "i915_drv.h" |
| 32 | #include "intel_bios.h" |
| 33 | |
Jani Nikula | dd97950a | 2015-12-21 15:10:52 +0200 | [diff] [blame] | 34 | /** |
| 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_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 56 | #define SLAVE_ADDR1 0x70 |
| 57 | #define SLAVE_ADDR2 0x72 |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 58 | |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 59 | static int panel_type; |
| 60 | |
Jani Nikula | 08c0888 | 2015-12-21 15:10:55 +0200 | [diff] [blame] | 61 | /* Get BDB block size given a pointer to Block ID. */ |
| 62 | static 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. */ |
| 72 | static u32 get_blocksize(const void *block_data) |
| 73 | { |
| 74 | return _get_blocksize(block_data - 3); |
| 75 | } |
| 76 | |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 77 | static const void * |
| 78 | find_section(const void *_bdb, int section_id) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 79 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 80 | const struct bdb_header *bdb = _bdb; |
| 81 | const u8 *base = _bdb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 82 | int index = 0; |
Jani Nikula | cd67d22 | 2015-09-17 16:42:07 +0300 | [diff] [blame] | 83 | u32 total, current_size; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 84 | 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 Wilson | d1f13fd | 2014-04-18 18:04:23 -0300 | [diff] [blame] | 91 | while (index + 3 < total) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 92 | current_id = *(base + index); |
Jani Nikula | 08c0888 | 2015-12-21 15:10:55 +0200 | [diff] [blame] | 93 | current_size = _get_blocksize(base + index); |
| 94 | index += 3; |
Jani Nikula | cd67d22 | 2015-09-17 16:42:07 +0300 | [diff] [blame] | 95 | |
Chris Wilson | d1f13fd | 2014-04-18 18:04:23 -0300 | [diff] [blame] | 96 | if (index + current_size > total) |
| 97 | return NULL; |
| 98 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 99 | if (current_id == section_id) |
| 100 | return base + index; |
Chris Wilson | d1f13fd | 2014-04-18 18:04:23 -0300 | [diff] [blame] | 101 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 102 | index += current_size; |
| 103 | } |
| 104 | |
| 105 | return NULL; |
| 106 | } |
| 107 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 108 | static void |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 109 | fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode, |
Chris Wilson | 99834ea | 2011-07-13 21:01:46 +0100 | [diff] [blame] | 110 | const struct lvds_dvo_timing *dvo_timing) |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 111 | { |
| 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 Jackson | 9bc3549 | 2010-05-28 17:17:37 -0400 | [diff] [blame] | 132 | 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 Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 142 | /* 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 Wilson | 99834ea | 2011-07-13 21:01:46 +0100 | [diff] [blame] | 151 | static const struct lvds_dvo_timing * |
| 152 | get_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 Iwai | b035438 | 2012-03-20 13:07:05 +0100 | [diff] [blame] | 173 | /* get lvds_fp_timing entry |
| 174 | * this function may return NULL if the corresponding entry is invalid |
| 175 | */ |
| 176 | static const struct lvds_fp_timing * |
| 177 | get_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 Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 195 | /* Try to find integrated panel data */ |
| 196 | static void |
| 197 | parse_lfp_panel_data(struct drm_i915_private *dev_priv, |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 198 | const struct bdb_header *bdb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 199 | { |
Chris Wilson | 99834ea | 2011-07-13 21:01:46 +0100 | [diff] [blame] | 200 | 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 Iwai | b035438 | 2012-03-20 13:07:05 +0100 | [diff] [blame] | 204 | const struct lvds_fp_timing *fp_timing; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 205 | struct drm_display_mode *panel_fixed_mode; |
Daniel Vetter | c329a4e | 2015-06-18 10:30:23 +0200 | [diff] [blame] | 206 | int drrs_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 207 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 208 | lvds_options = find_section(bdb, BDB_LVDS_OPTIONS); |
| 209 | if (!lvds_options) |
| 210 | return; |
| 211 | |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 212 | dev_priv->vbt.lvds_dither = lvds_options->pixel_dither; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 213 | if (lvds_options->panel_type == 0xff) |
| 214 | return; |
Simon Que | 6a04002 | 2010-09-30 09:36:39 +0100 | [diff] [blame] | 215 | |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 216 | panel_type = lvds_options->panel_type; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 217 | |
Pradeep Bhat | 83a7280 | 2014-03-28 10:14:57 +0530 | [diff] [blame] | 218 | 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 Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 240 | lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA); |
| 241 | if (!lvds_lfp_data) |
| 242 | return; |
| 243 | |
Jesse Barnes | 1b16de0 | 2009-06-22 11:30:30 -0700 | [diff] [blame] | 244 | lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS); |
| 245 | if (!lvds_lfp_data_ptrs) |
| 246 | return; |
| 247 | |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 248 | dev_priv->vbt.lvds_vbt = 1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 249 | |
Chris Wilson | 99834ea | 2011-07-13 21:01:46 +0100 | [diff] [blame] | 250 | panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data, |
| 251 | lvds_lfp_data_ptrs, |
| 252 | lvds_options->panel_type); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 253 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 254 | panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL); |
Chris Wilson | 6edc324 | 2010-09-12 17:16:17 +0100 | [diff] [blame] | 255 | if (!panel_fixed_mode) |
| 256 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 257 | |
Chris Wilson | 99834ea | 2011-07-13 21:01:46 +0100 | [diff] [blame] | 258 | fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 259 | |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 260 | dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 261 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 262 | DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 263 | drm_mode_debug_printmodeline(panel_fixed_mode); |
| 264 | |
Takashi Iwai | b035438 | 2012-03-20 13:07:05 +0100 | [diff] [blame] | 265 | 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 Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 272 | dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val; |
Takashi Iwai | b035438 | 2012-03-20 13:07:05 +0100 | [diff] [blame] | 273 | DRM_DEBUG_KMS("VBT initial LVDS value %x\n", |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 274 | dev_priv->vbt.bios_lvds_val); |
Takashi Iwai | b035438 | 2012-03-20 13:07:05 +0100 | [diff] [blame] | 275 | } |
| 276 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 277 | } |
| 278 | |
Jani Nikula | f00076d | 2013-12-14 20:38:29 -0200 | [diff] [blame] | 279 | static void |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 280 | parse_lfp_backlight(struct drm_i915_private *dev_priv, |
| 281 | const struct bdb_header *bdb) |
Jani Nikula | f00076d | 2013-12-14 20:38:29 -0200 | [diff] [blame] | 282 | { |
| 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 Nikula | 39fbc9c | 2014-04-09 11:22:06 +0300 | [diff] [blame] | 298 | 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 Nikula | f00076d | 2013-12-14 20:38:29 -0200 | [diff] [blame] | 305 | dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz; |
| 306 | dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm; |
Jani Nikula | 1de6068 | 2014-06-24 18:27:39 +0300 | [diff] [blame] | 307 | dev_priv->vbt.backlight.min_brightness = entry->min_brightness; |
Jani Nikula | f00076d | 2013-12-14 20:38:29 -0200 | [diff] [blame] | 308 | 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 Nikula | 1de6068 | 2014-06-24 18:27:39 +0300 | [diff] [blame] | 312 | dev_priv->vbt.backlight.min_brightness, |
Jani Nikula | f00076d | 2013-12-14 20:38:29 -0200 | [diff] [blame] | 313 | backlight_data->level[panel_type]); |
| 314 | } |
| 315 | |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 316 | /* Try to find sdvo panel data */ |
| 317 | static void |
| 318 | parse_sdvo_panel_data(struct drm_i915_private *dev_priv, |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 319 | const struct bdb_header *bdb) |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 320 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 321 | const struct lvds_dvo_timing *dvo_timing; |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 322 | struct drm_display_mode *panel_fixed_mode; |
Chris Wilson | 5a1e5b6 | 2011-01-29 16:50:25 +0000 | [diff] [blame] | 323 | int index; |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 324 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 325 | index = i915.vbt_sdvo_panel_type; |
Mathias Fröhlich | c10e408 | 2012-03-01 06:44:35 +0100 | [diff] [blame] | 326 | if (index == -2) { |
| 327 | DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n"); |
| 328 | return; |
| 329 | } |
| 330 | |
Chris Wilson | 5a1e5b6 | 2011-01-29 16:50:25 +0000 | [diff] [blame] | 331 | if (index == -1) { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 332 | const struct bdb_sdvo_lvds_options *sdvo_lvds_options; |
Chris Wilson | 5a1e5b6 | 2011-01-29 16:50:25 +0000 | [diff] [blame] | 333 | |
| 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 Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 340 | |
| 341 | dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS); |
| 342 | if (!dvo_timing) |
| 343 | return; |
| 344 | |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 345 | panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL); |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 346 | if (!panel_fixed_mode) |
| 347 | return; |
| 348 | |
Chris Wilson | 5a1e5b6 | 2011-01-29 16:50:25 +0000 | [diff] [blame] | 349 | fill_detail_timing_data(panel_fixed_mode, dvo_timing + index); |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 350 | |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 351 | dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode; |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 352 | |
Chris Wilson | 5a1e5b6 | 2011-01-29 16:50:25 +0000 | [diff] [blame] | 353 | DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n"); |
| 354 | drm_mode_debug_printmodeline(panel_fixed_mode); |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 355 | } |
| 356 | |
Jani Nikula | 98f3a1d | 2015-12-16 15:04:20 +0200 | [diff] [blame] | 357 | static int intel_bios_ssc_frequency(struct drm_i915_private *dev_priv, |
Bryan Freed | 9a4114f | 2011-01-12 13:38:39 -0800 | [diff] [blame] | 358 | bool alternate) |
| 359 | { |
Jani Nikula | 98f3a1d | 2015-12-16 15:04:20 +0200 | [diff] [blame] | 360 | switch (INTEL_INFO(dev_priv)->gen) { |
Bryan Freed | 9a4114f | 2011-01-12 13:38:39 -0800 | [diff] [blame] | 361 | case 2: |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 362 | return alternate ? 66667 : 48000; |
Bryan Freed | 9a4114f | 2011-01-12 13:38:39 -0800 | [diff] [blame] | 363 | case 3: |
| 364 | case 4: |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 365 | return alternate ? 100000 : 96000; |
Bryan Freed | 9a4114f | 2011-01-12 13:38:39 -0800 | [diff] [blame] | 366 | default: |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 367 | return alternate ? 100000 : 120000; |
Bryan Freed | 9a4114f | 2011-01-12 13:38:39 -0800 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 371 | static void |
| 372 | parse_general_features(struct drm_i915_private *dev_priv, |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 373 | const struct bdb_header *bdb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 374 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 375 | const struct bdb_general_features *general; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 376 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 377 | general = find_section(bdb, BDB_GENERAL_FEATURES); |
Jani Nikula | 34957e8 | 2015-12-16 15:04:21 +0200 | [diff] [blame] | 378 | 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 Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 398 | } |
| 399 | |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 400 | static void |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 401 | parse_general_definitions(struct drm_i915_private *dev_priv, |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 402 | const struct bdb_header *bdb) |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 403 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 404 | const struct bdb_general_definitions *general; |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 405 | |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 406 | 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 Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 411 | DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin); |
Jani Nikula | 88ac793 | 2015-03-27 00:20:22 +0200 | [diff] [blame] | 412 | if (intel_gmbus_is_valid_pin(dev_priv, bus_pin)) |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 413 | dev_priv->vbt.crt_ddc_pin = bus_pin; |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 414 | } else { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 415 | DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n", |
Daniel Kurtz | 3bd7d90 | 2012-03-28 02:36:14 +0800 | [diff] [blame] | 416 | block_size); |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 417 | } |
| 418 | } |
| 419 | } |
| 420 | |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 421 | static const union child_device_config * |
| 422 | child_device_ptr(const struct bdb_general_definitions *p_defs, int i) |
Ville Syrjälä | 90e4f15 | 2015-03-25 18:45:58 +0200 | [diff] [blame] | 423 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 424 | return (const void *) &p_defs->devices[i * p_defs->child_dev_size]; |
Ville Syrjälä | 90e4f15 | 2015-03-25 18:45:58 +0200 | [diff] [blame] | 425 | } |
| 426 | |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 427 | static void |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 428 | parse_sdvo_device_mapping(struct drm_i915_private *dev_priv, |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 429 | const struct bdb_header *bdb) |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 430 | { |
| 431 | struct sdvo_device_mapping *p_mapping; |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 432 | const struct bdb_general_definitions *p_defs; |
Jani Nikula | 6cc38ac | 2015-08-18 14:28:55 +0300 | [diff] [blame] | 433 | const struct old_child_dev_config *child; /* legacy */ |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 434 | int i, child_device_num, count; |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 435 | u16 block_size; |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 436 | |
| 437 | p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS); |
| 438 | if (!p_defs) { |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 439 | DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n"); |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 440 | return; |
| 441 | } |
Jani Nikula | 6cc38ac | 2015-08-18 14:28:55 +0300 | [diff] [blame] | 442 | |
| 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_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 447 | */ |
Jani Nikula | 6cc38ac | 2015-08-18 14:28:55 +0300 | [diff] [blame] | 448 | if (p_defs->child_dev_size != sizeof(*child)) { |
| 449 | DRM_DEBUG_KMS("Unsupported child device size for SDVO mapping.\n"); |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 450 | return; |
| 451 | } |
| 452 | /* get the block size of general definitions */ |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 453 | block_size = get_blocksize(p_defs); |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 454 | /* get the number of child device */ |
| 455 | child_device_num = (block_size - sizeof(*p_defs)) / |
Ville Syrjälä | 90e4f15 | 2015-03-25 18:45:58 +0200 | [diff] [blame] | 456 | p_defs->child_dev_size; |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 457 | count = 0; |
| 458 | for (i = 0; i < child_device_num; i++) { |
Jani Nikula | 6cc38ac | 2015-08-18 14:28:55 +0300 | [diff] [blame] | 459 | child = &child_device_ptr(p_defs, i)->old; |
| 460 | if (!child->device_type) { |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 461 | /* skip the device block if device type is invalid */ |
| 462 | continue; |
| 463 | } |
Jani Nikula | 6cc38ac | 2015-08-18 14:28:55 +0300 | [diff] [blame] | 464 | if (child->slave_addr != SLAVE_ADDR1 && |
| 465 | child->slave_addr != SLAVE_ADDR2) { |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 466 | /* |
| 467 | * If the slave address is neither 0x70 nor 0x72, |
| 468 | * it is not a SDVO device. Skip it. |
| 469 | */ |
| 470 | continue; |
| 471 | } |
Jani Nikula | 6cc38ac | 2015-08-18 14:28:55 +0300 | [diff] [blame] | 472 | if (child->dvo_port != DEVICE_PORT_DVOB && |
| 473 | child->dvo_port != DEVICE_PORT_DVOC) { |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 474 | /* skip the incorrect SDVO port */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 475 | DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n"); |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 476 | continue; |
| 477 | } |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 478 | DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on" |
Jani Nikula | 6cc38ac | 2015-08-18 14:28:55 +0300 | [diff] [blame] | 479 | " %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_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 484 | if (!p_mapping->initialized) { |
Jani Nikula | 6cc38ac | 2015-08-18 14:28:55 +0300 | [diff] [blame] | 485 | 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_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 490 | p_mapping->initialized = 1; |
Adam Jackson | 46eb303 | 2011-06-16 16:36:23 -0400 | [diff] [blame] | 491 | DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n", |
Chris Wilson | e957d77 | 2010-09-24 12:52:03 +0100 | [diff] [blame] | 492 | p_mapping->dvo_port, |
| 493 | p_mapping->slave_addr, |
| 494 | p_mapping->dvo_wiring, |
| 495 | p_mapping->ddc_pin, |
Adam Jackson | 46eb303 | 2011-06-16 16:36:23 -0400 | [diff] [blame] | 496 | p_mapping->i2c_pin); |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 497 | } else { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 498 | DRM_DEBUG_KMS("Maybe one SDVO port is shared by " |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 499 | "two SDVO device.\n"); |
| 500 | } |
Jani Nikula | 6cc38ac | 2015-08-18 14:28:55 +0300 | [diff] [blame] | 501 | if (child->slave2_addr) { |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 502 | /* Maybe this is a SDVO device with multiple inputs */ |
| 503 | /* And the mapping info is not added */ |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 504 | DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this" |
| 505 | " is a SDVO device with multiple inputs.\n"); |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 506 | } |
| 507 | count++; |
| 508 | } |
| 509 | |
| 510 | if (!count) { |
| 511 | /* No SDVO device info is found */ |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 512 | DRM_DEBUG_KMS("No SDVO device info is found in VBT\n"); |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 513 | } |
| 514 | return; |
| 515 | } |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 516 | |
| 517 | static void |
| 518 | parse_driver_features(struct drm_i915_private *dev_priv, |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 519 | const struct bdb_header *bdb) |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 520 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 521 | const struct bdb_driver_features *driver; |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 522 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 523 | driver = find_section(bdb, BDB_DRIVER_FEATURES); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 524 | if (!driver) |
| 525 | return; |
| 526 | |
Daniel Vetter | 6fca55b | 2013-09-21 00:48:39 +0200 | [diff] [blame] | 527 | if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP) |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 528 | dev_priv->vbt.edp_support = 1; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 529 | |
Chris Wilson | 5ceb0f9 | 2010-09-24 10:24:28 +0100 | [diff] [blame] | 530 | if (driver->dual_frequency) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 531 | dev_priv->render_reclock_avail = true; |
Pradeep Bhat | 83a7280 | 2014-03-28 10:14:57 +0530 | [diff] [blame] | 532 | |
| 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 Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 542 | } |
| 543 | |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 544 | static void |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 545 | parse_edp(struct drm_i915_private *dev_priv, const struct bdb_header *bdb) |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 546 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 547 | const struct bdb_edp *edp; |
| 548 | const struct edp_power_seq *edp_pps; |
| 549 | const struct edp_link_params *edp_link_params; |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 550 | |
| 551 | edp = find_section(bdb, BDB_EDP); |
| 552 | if (!edp) { |
Daniel Vetter | 6fca55b | 2013-09-21 00:48:39 +0200 | [diff] [blame] | 553 | if (dev_priv->vbt.edp_support) |
Jani Nikula | 9a30a61 | 2012-11-12 14:33:45 +0200 | [diff] [blame] | 554 | DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n"); |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 555 | return; |
| 556 | } |
| 557 | |
| 558 | switch ((edp->color_depth >> (panel_type * 2)) & 3) { |
| 559 | case EDP_18BPP: |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 560 | dev_priv->vbt.edp_bpp = 18; |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 561 | break; |
| 562 | case EDP_24BPP: |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 563 | dev_priv->vbt.edp_bpp = 24; |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 564 | break; |
| 565 | case EDP_30BPP: |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 566 | dev_priv->vbt.edp_bpp = 30; |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 567 | break; |
| 568 | } |
Chris Wilson | 5ceb0f9 | 2010-09-24 10:24:28 +0100 | [diff] [blame] | 569 | |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 570 | /* 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 Wilson | 5ceb0f9 | 2010-09-24 10:24:28 +0100 | [diff] [blame] | 573 | |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 574 | dev_priv->vbt.edp_pps = *edp_pps; |
Chris Wilson | 5ceb0f9 | 2010-09-24 10:24:28 +0100 | [diff] [blame] | 575 | |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 576 | 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 Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 589 | switch (edp_link_params->lanes) { |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 590 | case EDP_LANE_1: |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 591 | dev_priv->vbt.edp_lanes = 1; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 592 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 593 | case EDP_LANE_2: |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 594 | dev_priv->vbt.edp_lanes = 2; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 595 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 596 | case EDP_LANE_4: |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 597 | dev_priv->vbt.edp_lanes = 4; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 598 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 599 | default: |
| 600 | DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n", |
| 601 | edp_link_params->lanes); |
| 602 | break; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 603 | } |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 604 | |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 605 | switch (edp_link_params->preemphasis) { |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 606 | case EDP_PREEMPHASIS_NONE: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 607 | dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 608 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 609 | case EDP_PREEMPHASIS_3_5dB: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 610 | dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 611 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 612 | case EDP_PREEMPHASIS_6dB: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 613 | dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 614 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 615 | case EDP_PREEMPHASIS_9_5dB: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 616 | dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 617 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 618 | default: |
| 619 | DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n", |
| 620 | edp_link_params->preemphasis); |
| 621 | break; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 622 | } |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 623 | |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 624 | switch (edp_link_params->vswing) { |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 625 | case EDP_VSWING_0_4V: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 626 | dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 627 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 628 | case EDP_VSWING_0_6V: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 629 | dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 630 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 631 | case EDP_VSWING_0_8V: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 632 | dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 633 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 634 | case EDP_VSWING_1_2V: |
Sonika Jindal | bd60018 | 2014-08-08 16:23:41 +0530 | [diff] [blame] | 635 | dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 636 | break; |
Jani Nikula | e13e2b2 | 2014-05-06 14:56:51 +0300 | [diff] [blame] | 637 | default: |
| 638 | DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n", |
| 639 | edp_link_params->vswing); |
| 640 | break; |
Jesse Barnes | 9f0e7ff4 | 2010-10-07 16:01:14 -0700 | [diff] [blame] | 641 | } |
Sonika Jindal | 9a57f5b | 2015-02-25 10:29:11 +0530 | [diff] [blame] | 642 | |
| 643 | if (bdb->version >= 173) { |
| 644 | uint8_t vswing; |
| 645 | |
Sonika Jindal | 9e45803 | 2015-05-06 17:35:48 +0530 | [diff] [blame] | 646 | /* 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 Jindal | 9a57f5b | 2015-02-25 10:29:11 +0530 | [diff] [blame] | 653 | } |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 654 | } |
| 655 | |
Rodrigo Vivi | bfd7ebd | 2014-11-14 08:52:30 -0800 | [diff] [blame] | 656 | static void |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 657 | parse_psr(struct drm_i915_private *dev_priv, const struct bdb_header *bdb) |
Rodrigo Vivi | bfd7ebd | 2014-11-14 08:52:30 -0800 | [diff] [blame] | 658 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 659 | const struct bdb_psr *psr; |
| 660 | const struct psr_table *psr_table; |
Rodrigo Vivi | bfd7ebd | 2014-11-14 08:52:30 -0800 | [diff] [blame] | 661 | |
| 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 Nikula | 5db7209 | 2016-01-05 15:50:51 +0200 | [diff] [blame^] | 700 | static u8 *goto_next_sequence(u8 *data, u16 *size) |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 701 | { |
| 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 Kumar | b0256cd | 2014-04-15 13:54:07 +0530 | [diff] [blame] | 717 | tmp -= 5; |
| 718 | if (tmp < 0) |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 719 | return NULL; |
| 720 | |
| 721 | data += 3; |
| 722 | len = *((u16 *)data); |
| 723 | |
Shobhit Kumar | b0256cd | 2014-04-15 13:54:07 +0530 | [diff] [blame] | 724 | tmp -= len; |
| 725 | if (tmp < 0) |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 726 | 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 Kumar | b0256cd | 2014-04-15 13:54:07 +0530 | [diff] [blame] | 733 | tmp -= 5; |
| 734 | if (tmp < 0) |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 735 | return NULL; |
| 736 | |
| 737 | data += 5; |
| 738 | break; |
| 739 | case MIPI_SEQ_ELEM_GPIO: |
Shobhit Kumar | b0256cd | 2014-04-15 13:54:07 +0530 | [diff] [blame] | 740 | tmp -= 3; |
| 741 | if (tmp < 0) |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 742 | 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 Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 767 | static void |
Jani Nikula | 0f8689f | 2015-12-21 15:10:54 +0200 | [diff] [blame] | 768 | parse_mipi_config(struct drm_i915_private *dev_priv, |
| 769 | const struct bdb_header *bdb) |
Shobhit Kumar | d17c544 | 2013-08-27 15:12:25 +0300 | [diff] [blame] | 770 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 771 | const struct bdb_mipi_config *start; |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 772 | const struct mipi_config *config; |
| 773 | const struct mipi_pps_data *pps; |
Shobhit Kumar | d17c544 | 2013-08-27 15:12:25 +0300 | [diff] [blame] | 774 | |
Shobhit Kumar | 3e6bd01 | 2014-05-27 19:33:59 +0530 | [diff] [blame] | 775 | /* parse MIPI blocks only if LFP type is MIPI */ |
| 776 | if (!dev_priv->vbt.has_mipi) |
| 777 | return; |
| 778 | |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 779 | /* 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 Kumar | d17c544 | 2013-08-27 15:12:25 +0300 | [diff] [blame] | 793 | return; |
| 794 | } |
| 795 | |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 796 | 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 Kumar | ea9a6ba | 2014-02-28 11:18:46 +0530 | [diff] [blame] | 818 | dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID; |
Jani Nikula | 0f8689f | 2015-12-21 15:10:54 +0200 | [diff] [blame] | 819 | } |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 820 | |
Jani Nikula | 5db7209 | 2016-01-05 15:50:51 +0200 | [diff] [blame^] | 821 | /* Find the sequence block and size for the given panel. */ |
| 822 | static const u8 * |
| 823 | find_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 Nikula | 0f8689f | 2015-12-21 15:10:54 +0200 | [diff] [blame] | 858 | static void |
| 859 | parse_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 Nikula | 5db7209 | 2016-01-05 15:50:51 +0200 | [diff] [blame^] | 864 | u16 seq_size; |
Jani Nikula | 0f8689f | 2015-12-21 15:10:54 +0200 | [diff] [blame] | 865 | u8 *data; |
| 866 | u16 block_size; |
Jani Nikula | 0f8689f | 2015-12-21 15:10:54 +0200 | [diff] [blame] | 867 | |
| 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 Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 872 | 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 Nikula | cd67d22 | 2015-09-17 16:42:07 +0300 | [diff] [blame] | 878 | /* 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 Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 884 | 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 Nikula | 5db7209 | 2016-01-05 15:50:51 +0200 | [diff] [blame^] | 893 | seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size); |
| 894 | if (!seq_data) |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 895 | return; |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 896 | |
Jani Nikula | 5db7209 | 2016-01-05 15:50:51 +0200 | [diff] [blame^] | 897 | dev_priv->vbt.dsi.data = kmemdup(seq_data, seq_size, GFP_KERNEL); |
Shobhit Kumar | d3b542f | 2014-04-14 11:00:34 +0530 | [diff] [blame] | 898 | 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; |
| 933 | err: |
| 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 Barbalho | ed3b667 | 2014-07-24 15:16:12 +0100 | [diff] [blame] | 939 | memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence)); |
Shobhit Kumar | d17c544 | 2013-08-27 15:12:25 +0300 | [diff] [blame] | 940 | } |
| 941 | |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 942 | static 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 Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 953 | static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port, |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 954 | const struct bdb_header *bdb) |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 955 | { |
| 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 Zanoni | 554d6af | 2013-09-12 17:10:11 -0300 | [diff] [blame] | 960 | bool is_dvi, is_hdmi, is_dp, is_edp, is_crt; |
Xiong Zhang | 11c1b65 | 2015-08-17 16:04:04 +0800 | [diff] [blame] | 961 | uint8_t aux_channel, ddc_pin; |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 962 | /* 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 Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 965 | 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 Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 971 | }; |
| 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 Vivi | 2800e4c | 2015-08-07 17:35:21 -0700 | [diff] [blame] | 977 | for (j = 0; j < 3; j++) { |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 978 | 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 Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 994 | aux_channel = child->raw[25]; |
Xiong Zhang | 11c1b65 | 2015-08-17 16:04:04 +0800 | [diff] [blame] | 995 | ddc_pin = child->common.ddc_pin; |
Paulo Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 996 | |
Ville Syrjälä | 78eb06c | 2013-11-01 20:32:07 +0200 | [diff] [blame] | 997 | 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 Zanoni | 554d6af | 2013-09-12 17:10:11 -0300 | [diff] [blame] | 1002 | |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 1003 | info->supports_dvi = is_dvi; |
| 1004 | info->supports_hdmi = is_hdmi; |
| 1005 | info->supports_dp = is_dp; |
| 1006 | |
Paulo Zanoni | 554d6af | 2013-09-12 17:10:11 -0300 | [diff] [blame] | 1007 | 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 Iida | 9b13494 | 2014-08-06 22:31:28 +0900 | [diff] [blame] | 1019 | DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port)); |
Paulo Zanoni | 554d6af | 2013-09-12 17:10:11 -0300 | [diff] [blame] | 1020 | 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 Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 1025 | |
| 1026 | if (is_dvi) { |
Xiong Zhang | 11c1b65 | 2015-08-17 16:04:04 +0800 | [diff] [blame] | 1027 | 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 Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 1044 | DRM_DEBUG_KMS("Unexpected DDC pin for port B\n"); |
Xiong Zhang | 11c1b65 | 2015-08-17 16:04:04 +0800 | [diff] [blame] | 1045 | else if (ddc_pin == DDC_PIN_C && port != PORT_C) |
Paulo Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 1046 | DRM_DEBUG_KMS("Unexpected DDC pin for port C\n"); |
Xiong Zhang | 11c1b65 | 2015-08-17 16:04:04 +0800 | [diff] [blame] | 1047 | else if (ddc_pin == DDC_PIN_D && port != PORT_D) |
Paulo Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 1048 | DRM_DEBUG_KMS("Unexpected DDC pin for port D\n"); |
| 1049 | } |
| 1050 | |
| 1051 | if (is_dp) { |
Rodrigo Vivi | 500ea70 | 2015-08-07 17:01:16 -0700 | [diff] [blame] | 1052 | 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 Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 1068 | DRM_DEBUG_KMS("Unexpected AUX channel for port A\n"); |
Rodrigo Vivi | 500ea70 | 2015-08-07 17:01:16 -0700 | [diff] [blame] | 1069 | else if (aux_channel == DP_AUX_B && port != PORT_B) |
Paulo Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 1070 | DRM_DEBUG_KMS("Unexpected AUX channel for port B\n"); |
Rodrigo Vivi | 500ea70 | 2015-08-07 17:01:16 -0700 | [diff] [blame] | 1071 | else if (aux_channel == DP_AUX_C && port != PORT_C) |
Paulo Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 1072 | DRM_DEBUG_KMS("Unexpected AUX channel for port C\n"); |
Rodrigo Vivi | 500ea70 | 2015-08-07 17:01:16 -0700 | [diff] [blame] | 1073 | else if (aux_channel == DP_AUX_D && port != PORT_D) |
Paulo Zanoni | 6bf19e7 | 2013-09-12 17:07:55 -0300 | [diff] [blame] | 1074 | DRM_DEBUG_KMS("Unexpected AUX channel for port D\n"); |
| 1075 | } |
| 1076 | |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1077 | 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 Lespiau | ce4dd49 | 2014-08-01 11:07:54 +0100 | [diff] [blame] | 1080 | 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 Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1084 | } |
Antti Koskipaa | 75067dd | 2015-07-10 14:10:55 +0300 | [diff] [blame] | 1085 | |
| 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 Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | static void parse_ddi_ports(struct drm_i915_private *dev_priv, |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 1098 | const struct bdb_header *bdb) |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1099 | { |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1100 | enum port port; |
| 1101 | |
Jani Nikula | 98f3a1d | 2015-12-16 15:04:20 +0200 | [diff] [blame] | 1102 | if (!HAS_DDI(dev_priv)) |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1103 | 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 Kumar | d17c544 | 2013-08-27 15:12:25 +0300 | [diff] [blame] | 1115 | static void |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1116 | parse_device_mapping(struct drm_i915_private *dev_priv, |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 1117 | const struct bdb_header *bdb) |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1118 | { |
Jani Nikula | e8ef3b4 | 2015-04-15 15:18:28 +0300 | [diff] [blame] | 1119 | const struct bdb_general_definitions *p_defs; |
| 1120 | const union child_device_config *p_child; |
| 1121 | union child_device_config *child_dev_ptr; |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1122 | int i, child_device_num, count; |
David Weinehall | e2d6cf7 | 2015-08-21 16:52:01 +0300 | [diff] [blame] | 1123 | u8 expected_size; |
| 1124 | u16 block_size; |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1125 | |
| 1126 | p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS); |
| 1127 | if (!p_defs) { |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1128 | DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n"); |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1129 | return; |
| 1130 | } |
David Weinehall | e2d6cf7 | 2015-08-21 16:52:01 +0300 | [diff] [blame] | 1131 | 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 Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1148 | return; |
| 1149 | } |
David Weinehall | e2d6cf7 | 2015-08-21 16:52:01 +0300 | [diff] [blame] | 1150 | |
| 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 Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1156 | /* 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ä | 90e4f15 | 2015-03-25 18:45:58 +0200 | [diff] [blame] | 1160 | p_defs->child_dev_size; |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1161 | count = 0; |
| 1162 | /* get the number of child device that is present */ |
| 1163 | for (i = 0; i < child_device_num; i++) { |
Ville Syrjälä | 90e4f15 | 2015-03-25 18:45:58 +0200 | [diff] [blame] | 1164 | p_child = child_device_ptr(p_defs, i); |
Paulo Zanoni | 768f69c | 2013-09-11 18:02:47 -0300 | [diff] [blame] | 1165 | if (!p_child->common.device_type) { |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1166 | /* skip the device block if device type is invalid */ |
| 1167 | continue; |
| 1168 | } |
| 1169 | count++; |
| 1170 | } |
| 1171 | if (!count) { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 1172 | DRM_DEBUG_KMS("no child dev is parsed from VBT\n"); |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1173 | return; |
| 1174 | } |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 1175 | dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL); |
| 1176 | if (!dev_priv->vbt.child_dev) { |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1177 | DRM_DEBUG_KMS("No memory space for child device\n"); |
| 1178 | return; |
| 1179 | } |
| 1180 | |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 1181 | dev_priv->vbt.child_dev_num = count; |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1182 | count = 0; |
| 1183 | for (i = 0; i < child_device_num; i++) { |
Ville Syrjälä | 90e4f15 | 2015-03-25 18:45:58 +0200 | [diff] [blame] | 1184 | p_child = child_device_ptr(p_defs, i); |
Paulo Zanoni | 768f69c | 2013-09-11 18:02:47 -0300 | [diff] [blame] | 1185 | if (!p_child->common.device_type) { |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1186 | /* skip the device block if device type is invalid */ |
| 1187 | continue; |
| 1188 | } |
Shobhit Kumar | 3e6bd01 | 2014-05-27 19:33:59 +0530 | [diff] [blame] | 1189 | |
| 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 Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 1198 | child_dev_ptr = dev_priv->vbt.child_dev + count; |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1199 | count++; |
David Weinehall | e2d6cf7 | 2015-08-21 16:52:01 +0300 | [diff] [blame] | 1200 | |
| 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 Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1208 | } |
| 1209 | return; |
| 1210 | } |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1211 | |
Simon Que | 6a04002 | 2010-09-30 09:36:39 +0100 | [diff] [blame] | 1212 | static void |
| 1213 | init_vbt_defaults(struct drm_i915_private *dev_priv) |
| 1214 | { |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1215 | enum port port; |
Bryan Freed | 9a4114f | 2011-01-12 13:38:39 -0800 | [diff] [blame] | 1216 | |
Jani Nikula | 988c701 | 2015-03-27 00:20:19 +0200 | [diff] [blame] | 1217 | dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC; |
Simon Que | 6a04002 | 2010-09-30 09:36:39 +0100 | [diff] [blame] | 1218 | |
Jani Nikula | 56c4b63 | 2014-06-17 15:47:05 +0300 | [diff] [blame] | 1219 | /* Default to having backlight */ |
| 1220 | dev_priv->vbt.backlight.present = true; |
| 1221 | |
Simon Que | 6a04002 | 2010-09-30 09:36:39 +0100 | [diff] [blame] | 1222 | /* LFP panel data */ |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 1223 | dev_priv->vbt.lvds_dither = 1; |
| 1224 | dev_priv->vbt.lvds_vbt = 0; |
Simon Que | 6a04002 | 2010-09-30 09:36:39 +0100 | [diff] [blame] | 1225 | |
| 1226 | /* SDVO panel data */ |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 1227 | dev_priv->vbt.sdvo_lvds_vbt_mode = NULL; |
Simon Que | 6a04002 | 2010-09-30 09:36:39 +0100 | [diff] [blame] | 1228 | |
| 1229 | /* general features */ |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 1230 | dev_priv->vbt.int_tv_support = 1; |
| 1231 | dev_priv->vbt.int_crt_support = 1; |
Bryan Freed | 9a4114f | 2011-01-12 13:38:39 -0800 | [diff] [blame] | 1232 | |
| 1233 | /* Default to using SSC */ |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 1234 | dev_priv->vbt.lvds_use_ssc = 1; |
Duncan Laurie | f69e515 | 2013-11-13 17:59:43 -0800 | [diff] [blame] | 1235 | /* |
| 1236 | * Core/SandyBridge/IvyBridge use alternative (120MHz) reference |
| 1237 | * clock for LVDS. |
| 1238 | */ |
Jani Nikula | 98f3a1d | 2015-12-16 15:04:20 +0200 | [diff] [blame] | 1239 | dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev_priv, |
| 1240 | !HAS_PCH_SPLIT(dev_priv)); |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 1241 | DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq); |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1242 | |
| 1243 | for (port = PORT_A; port < I915_MAX_PORTS; port++) { |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 1244 | struct ddi_vbt_port_info *info = |
| 1245 | &dev_priv->vbt.ddi_port_info[port]; |
| 1246 | |
Damien Lespiau | ce4dd49 | 2014-08-01 11:07:54 +0100 | [diff] [blame] | 1247 | info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN; |
Paulo Zanoni | 311a209 | 2013-09-12 17:12:18 -0300 | [diff] [blame] | 1248 | |
| 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 Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1252 | } |
Simon Que | 6a04002 | 2010-09-30 09:36:39 +0100 | [diff] [blame] | 1253 | } |
| 1254 | |
Jani Nikula | caf37fa | 2015-12-14 12:50:47 +0200 | [diff] [blame] | 1255 | static 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 Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1262 | /** |
| 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 | */ |
| 1269 | bool intel_bios_is_valid_vbt(const void *buf, size_t size) |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1270 | { |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1271 | const struct vbt_header *vbt = buf; |
Jani Nikula | dcb58a4 | 2015-05-12 15:41:32 +0300 | [diff] [blame] | 1272 | const struct bdb_header *bdb; |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1273 | |
Jani Nikula | caf37fa | 2015-12-14 12:50:47 +0200 | [diff] [blame] | 1274 | if (!vbt) |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1275 | return false; |
Jani Nikula | caf37fa | 2015-12-14 12:50:47 +0200 | [diff] [blame] | 1276 | |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1277 | if (sizeof(struct vbt_header) > size) { |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1278 | DRM_DEBUG_DRIVER("VBT header incomplete\n"); |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1279 | return false; |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | if (memcmp(vbt->signature, "$VBT", 4)) { |
| 1283 | DRM_DEBUG_DRIVER("VBT invalid signature\n"); |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1284 | return false; |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1285 | } |
| 1286 | |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1287 | if (vbt->bdb_offset + sizeof(struct bdb_header) > size) { |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1288 | DRM_DEBUG_DRIVER("BDB header incomplete\n"); |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1289 | return false; |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1290 | } |
| 1291 | |
Jani Nikula | caf37fa | 2015-12-14 12:50:47 +0200 | [diff] [blame] | 1292 | bdb = get_bdb_header(vbt); |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1293 | if (vbt->bdb_offset + bdb->bdb_size > size) { |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1294 | DRM_DEBUG_DRIVER("BDB incomplete\n"); |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1295 | return false; |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1296 | } |
| 1297 | |
Jani Nikula | caf37fa | 2015-12-14 12:50:47 +0200 | [diff] [blame] | 1298 | return vbt; |
Chris Wilson | 3dd4e84 | 2014-04-18 18:04:22 -0300 | [diff] [blame] | 1299 | } |
| 1300 | |
Jani Nikula | caf37fa | 2015-12-14 12:50:47 +0200 | [diff] [blame] | 1301 | static const struct vbt_header *find_vbt(void __iomem *bios, size_t size) |
Jani Nikula | b34a991 | 2015-05-13 15:34:04 +0300 | [diff] [blame] | 1302 | { |
Jani Nikula | b34a991 | 2015-05-13 15:34:04 +0300 | [diff] [blame] | 1303 | size_t i; |
| 1304 | |
| 1305 | /* Scour memory looking for the VBT signature. */ |
| 1306 | for (i = 0; i + 4 < size; i++) { |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1307 | void *vbt; |
Williams, Dan J | 115719f | 2015-10-12 21:12:57 +0000 | [diff] [blame] | 1308 | |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1309 | 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 Nikula | b34a991 | 2015-05-13 15:34:04 +0300 | [diff] [blame] | 1321 | } |
| 1322 | |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1323 | return NULL; |
Jani Nikula | b34a991 | 2015-05-13 15:34:04 +0300 | [diff] [blame] | 1324 | } |
| 1325 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1326 | /** |
Jani Nikula | 8b8e1a8 | 2015-12-14 12:50:49 +0200 | [diff] [blame] | 1327 | * intel_bios_init - find VBT and initialize settings from the BIOS |
Jani Nikula | dd97950a | 2015-12-21 15:10:52 +0200 | [diff] [blame] | 1328 | * @dev_priv: i915 device instance |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1329 | * |
| 1330 | * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers |
| 1331 | * to appropriate values. |
| 1332 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1333 | * Returns 0 on success, nonzero on failure. |
| 1334 | */ |
Dan Carpenter | 0317c6c | 2012-06-27 12:10:30 +0300 | [diff] [blame] | 1335 | int |
Jani Nikula | 98f3a1d | 2015-12-16 15:04:20 +0200 | [diff] [blame] | 1336 | intel_bios_init(struct drm_i915_private *dev_priv) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1337 | { |
Jani Nikula | 98f3a1d | 2015-12-16 15:04:20 +0200 | [diff] [blame] | 1338 | struct pci_dev *pdev = dev_priv->dev->pdev; |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1339 | const struct vbt_header *vbt = dev_priv->opregion.vbt; |
Jani Nikula | caf37fa | 2015-12-14 12:50:47 +0200 | [diff] [blame] | 1340 | const struct bdb_header *bdb; |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1341 | u8 __iomem *bios = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1342 | |
Jani Nikula | 98f3a1d | 2015-12-16 15:04:20 +0200 | [diff] [blame] | 1343 | if (HAS_PCH_NOP(dev_priv)) |
Ben Widawsky | ab5c608 | 2013-04-05 13:12:41 -0700 | [diff] [blame] | 1344 | return -ENODEV; |
| 1345 | |
Simon Que | 6a04002 | 2010-09-30 09:36:39 +0100 | [diff] [blame] | 1346 | init_vbt_defaults(dev_priv); |
Chris Wilson | f899fc6 | 2010-07-20 15:44:45 -0700 | [diff] [blame] | 1347 | |
Jani Nikula | f0067a3 | 2015-12-15 13:16:15 +0200 | [diff] [blame] | 1348 | if (!vbt) { |
Jani Nikula | b34a991 | 2015-05-13 15:34:04 +0300 | [diff] [blame] | 1349 | size_t size; |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1350 | |
| 1351 | bios = pci_map_rom(pdev, &size); |
| 1352 | if (!bios) |
| 1353 | return -1; |
| 1354 | |
Jani Nikula | caf37fa | 2015-12-14 12:50:47 +0200 | [diff] [blame] | 1355 | vbt = find_vbt(bios, size); |
| 1356 | if (!vbt) { |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1357 | pci_unmap_rom(pdev, bios); |
| 1358 | return -1; |
| 1359 | } |
Jani Nikula | e2051c4 | 2015-12-15 13:14:52 +0200 | [diff] [blame] | 1360 | |
| 1361 | DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n"); |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1362 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1363 | |
Jani Nikula | caf37fa | 2015-12-14 12:50:47 +0200 | [diff] [blame] | 1364 | bdb = get_bdb_header(vbt); |
| 1365 | |
Jani Nikula | 3556dd4 | 2015-12-16 15:04:19 +0200 | [diff] [blame] | 1366 | DRM_DEBUG_KMS("VBT signature \"%.*s\", BDB version %d\n", |
| 1367 | (int)sizeof(vbt->signature), vbt->signature, bdb->version); |
Jani Nikula | e2051c4 | 2015-12-15 13:14:52 +0200 | [diff] [blame] | 1368 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1369 | /* Grab useful general definitions */ |
| 1370 | parse_general_features(dev_priv, bdb); |
David Müller (ELSOFT AG) | db54501 | 2009-08-29 08:54:45 +0200 | [diff] [blame] | 1371 | parse_general_definitions(dev_priv, bdb); |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 1372 | parse_lfp_panel_data(dev_priv, bdb); |
Jani Nikula | f00076d | 2013-12-14 20:38:29 -0200 | [diff] [blame] | 1373 | parse_lfp_backlight(dev_priv, bdb); |
Ma Ling | 8863170 | 2009-05-13 11:19:55 +0800 | [diff] [blame] | 1374 | parse_sdvo_panel_data(dev_priv, bdb); |
yakui_zhao | 9b9d172 | 2009-05-31 17:17:17 +0800 | [diff] [blame] | 1375 | parse_sdvo_device_mapping(dev_priv, bdb); |
Zhao Yakui | 6363ee6 | 2009-11-24 09:48:44 +0800 | [diff] [blame] | 1376 | parse_device_mapping(dev_priv, bdb); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1377 | parse_driver_features(dev_priv, bdb); |
Zhenyu Wang | 500a8cc | 2010-01-13 11:19:52 +0800 | [diff] [blame] | 1378 | parse_edp(dev_priv, bdb); |
Rodrigo Vivi | bfd7ebd | 2014-11-14 08:52:30 -0800 | [diff] [blame] | 1379 | parse_psr(dev_priv, bdb); |
Jani Nikula | 0f8689f | 2015-12-21 15:10:54 +0200 | [diff] [blame] | 1380 | parse_mipi_config(dev_priv, bdb); |
| 1381 | parse_mipi_sequence(dev_priv, bdb); |
Paulo Zanoni | 6acab15 | 2013-09-12 17:06:24 -0300 | [diff] [blame] | 1382 | parse_ddi_ports(dev_priv, bdb); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 1383 | |
Chris Wilson | 44834a6 | 2010-08-19 16:09:23 +0100 | [diff] [blame] | 1384 | if (bios) |
| 1385 | pci_unmap_rom(pdev, bios); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1386 | |
| 1387 | return 0; |
| 1388 | } |