blob: 300aee3296c2435545702030d6e66405759e5963 [file] [log] [blame]
Jesse Barnes79e53942008-11-07 14:24:08 -08001/*
2 * Copyright © 2006 Intel Corporation
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 */
27#include "drmP.h"
28#include "drm.h"
29#include "i915_drm.h"
30#include "i915_drv.h"
31#include "intel_bios.h"
32
yakui_zhao9b9d1722009-05-31 17:17:17 +080033#define SLAVE_ADDR1 0x70
34#define SLAVE_ADDR2 0x72
Jesse Barnes79e53942008-11-07 14:24:08 -080035
36static void *
37find_section(struct bdb_header *bdb, int section_id)
38{
39 u8 *base = (u8 *)bdb;
40 int index = 0;
41 u16 total, current_size;
42 u8 current_id;
43
44 /* skip to first section */
45 index += bdb->header_size;
46 total = bdb->bdb_size;
47
48 /* walk the sections looking for section_id */
49 while (index < total) {
50 current_id = *(base + index);
51 index++;
52 current_size = *((u16 *)(base + index));
53 index += 2;
54 if (current_id == section_id)
55 return base + index;
56 index += current_size;
57 }
58
59 return NULL;
60}
61
Jesse Barnes79e53942008-11-07 14:24:08 -080062static void
Ma Ling88631702009-05-13 11:19:55 +080063fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
64 struct lvds_dvo_timing *dvo_timing)
65{
66 panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
67 dvo_timing->hactive_lo;
68 panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
69 ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
70 panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
71 dvo_timing->hsync_pulse_width;
72 panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
73 ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
74
75 panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
76 dvo_timing->vactive_lo;
77 panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
78 dvo_timing->vsync_off;
79 panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
80 dvo_timing->vsync_pulse_width;
81 panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
82 ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
83 panel_fixed_mode->clock = dvo_timing->clock * 10;
84 panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
85
86 /* Some VBTs have bogus h/vtotal values */
87 if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
88 panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
89 if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
90 panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
91
92 drm_mode_set_name(panel_fixed_mode);
93}
94
95/* Try to find integrated panel data */
96static void
97parse_lfp_panel_data(struct drm_i915_private *dev_priv,
98 struct bdb_header *bdb)
Jesse Barnes79e53942008-11-07 14:24:08 -080099{
100 struct bdb_lvds_options *lvds_options;
101 struct bdb_lvds_lfp_data *lvds_lfp_data;
Jesse Barnes1b16de02009-06-22 11:30:30 -0700102 struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
Jesse Barnes79e53942008-11-07 14:24:08 -0800103 struct bdb_lvds_lfp_data_entry *entry;
104 struct lvds_dvo_timing *dvo_timing;
105 struct drm_display_mode *panel_fixed_mode;
Zhao Yakuicdaa0522009-07-28 10:54:13 +0800106 int lfp_data_size, dvo_timing_offset;
Jesse Barnes79e53942008-11-07 14:24:08 -0800107
108 /* Defaults if we can't find VBT info */
109 dev_priv->lvds_dither = 0;
110 dev_priv->lvds_vbt = 0;
111
112 lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
113 if (!lvds_options)
114 return;
115
116 dev_priv->lvds_dither = lvds_options->pixel_dither;
117 if (lvds_options->panel_type == 0xff)
118 return;
119
120 lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
121 if (!lvds_lfp_data)
122 return;
123
Jesse Barnes1b16de02009-06-22 11:30:30 -0700124 lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
125 if (!lvds_lfp_data_ptrs)
126 return;
127
Jesse Barnes79e53942008-11-07 14:24:08 -0800128 dev_priv->lvds_vbt = 1;
129
Jesse Barnes1b16de02009-06-22 11:30:30 -0700130 lfp_data_size = lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
131 lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
132 entry = (struct bdb_lvds_lfp_data_entry *)
133 ((uint8_t *)lvds_lfp_data->data + (lfp_data_size *
134 lvds_options->panel_type));
Zhao Yakuicdaa0522009-07-28 10:54:13 +0800135 dvo_timing_offset = lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
136 lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
Zhenyu Wang50199142009-07-10 14:39:59 +0800137
Zhao Yakuicdaa0522009-07-28 10:54:13 +0800138 /*
139 * the size of fp_timing varies on the different platform.
140 * So calculate the DVO timing relative offset in LVDS data
141 * entry to get the DVO timing entry
142 */
143 dvo_timing = (struct lvds_dvo_timing *)
144 ((unsigned char *)entry + dvo_timing_offset);
Jesse Barnes79e53942008-11-07 14:24:08 -0800145
Eric Anholt9a298b22009-03-24 12:23:04 -0700146 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
Jesse Barnes79e53942008-11-07 14:24:08 -0800147
Ma Ling88631702009-05-13 11:19:55 +0800148 fill_detail_timing_data(panel_fixed_mode, dvo_timing);
Jesse Barnes79e53942008-11-07 14:24:08 -0800149
Ma Ling88631702009-05-13 11:19:55 +0800150 dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;
Jesse Barnes79e53942008-11-07 14:24:08 -0800151
152 DRM_DEBUG("Found panel mode in BIOS VBT tables:\n");
153 drm_mode_debug_printmodeline(panel_fixed_mode);
154
155 return;
156}
157
Ma Ling88631702009-05-13 11:19:55 +0800158/* Try to find sdvo panel data */
159static void
160parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
161 struct bdb_header *bdb)
162{
163 struct bdb_sdvo_lvds_options *sdvo_lvds_options;
164 struct lvds_dvo_timing *dvo_timing;
165 struct drm_display_mode *panel_fixed_mode;
166
167 dev_priv->sdvo_lvds_vbt_mode = NULL;
168
169 sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
170 if (!sdvo_lvds_options)
171 return;
172
173 dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
174 if (!dvo_timing)
175 return;
176
Eric Anholt9a298b22009-03-24 12:23:04 -0700177 panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
Ma Ling88631702009-05-13 11:19:55 +0800178
179 if (!panel_fixed_mode)
180 return;
181
182 fill_detail_timing_data(panel_fixed_mode,
183 dvo_timing + sdvo_lvds_options->panel_type);
184
185 dev_priv->sdvo_lvds_vbt_mode = panel_fixed_mode;
186
187 return;
188}
189
Jesse Barnes79e53942008-11-07 14:24:08 -0800190static void
191parse_general_features(struct drm_i915_private *dev_priv,
192 struct bdb_header *bdb)
193{
194 struct bdb_general_features *general;
195
196 /* Set sensible defaults in case we can't find the general block */
197 dev_priv->int_tv_support = 1;
198 dev_priv->int_crt_support = 1;
199
200 general = find_section(bdb, BDB_GENERAL_FEATURES);
201 if (general) {
202 dev_priv->int_tv_support = general->int_tv_support;
203 dev_priv->int_crt_support = general->int_crt_support;
Kristian Høgsberg43565a02009-02-13 20:56:52 -0500204 dev_priv->lvds_use_ssc = general->enable_ssc;
205
206 if (dev_priv->lvds_use_ssc) {
ling.ma@intel.com6ff4fd02009-06-25 10:59:22 +0800207 if (IS_I85X(dev_priv->dev))
208 dev_priv->lvds_ssc_freq =
209 general->ssc_freq ? 66 : 48;
210 else
211 dev_priv->lvds_ssc_freq =
212 general->ssc_freq ? 100 : 96;
Kristian Høgsberg43565a02009-02-13 20:56:52 -0500213 }
Jesse Barnes79e53942008-11-07 14:24:08 -0800214 }
215}
216
yakui_zhao9b9d1722009-05-31 17:17:17 +0800217static void
218parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
219 struct bdb_header *bdb)
220{
221 struct sdvo_device_mapping *p_mapping;
222 struct bdb_general_definitions *p_defs;
223 struct child_device_config *p_child;
224 int i, child_device_num, count;
225 u16 block_size, *block_ptr;
226
227 p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
228 if (!p_defs) {
229 DRM_DEBUG("No general definition block is found\n");
230 return;
231 }
232 /* judge whether the size of child device meets the requirements.
233 * If the child device size obtained from general definition block
234 * is different with sizeof(struct child_device_config), skip the
235 * parsing of sdvo device info
236 */
237 if (p_defs->child_dev_size != sizeof(*p_child)) {
238 /* different child dev size . Ignore it */
239 DRM_DEBUG("different child size is found. Invalid.\n");
240 return;
241 }
242 /* get the block size of general definitions */
243 block_ptr = (u16 *)((char *)p_defs - 2);
244 block_size = *block_ptr;
245 /* get the number of child device */
246 child_device_num = (block_size - sizeof(*p_defs)) /
247 sizeof(*p_child);
248 count = 0;
249 for (i = 0; i < child_device_num; i++) {
250 p_child = &(p_defs->devices[i]);
251 if (!p_child->device_type) {
252 /* skip the device block if device type is invalid */
253 continue;
254 }
255 if (p_child->slave_addr != SLAVE_ADDR1 &&
256 p_child->slave_addr != SLAVE_ADDR2) {
257 /*
258 * If the slave address is neither 0x70 nor 0x72,
259 * it is not a SDVO device. Skip it.
260 */
261 continue;
262 }
263 if (p_child->dvo_port != DEVICE_PORT_DVOB &&
264 p_child->dvo_port != DEVICE_PORT_DVOC) {
265 /* skip the incorrect SDVO port */
266 DRM_DEBUG("Incorrect SDVO port. Skip it \n");
267 continue;
268 }
269 DRM_DEBUG("the SDVO device with slave addr %2x is found on "
270 "%s port\n",
271 p_child->slave_addr,
272 (p_child->dvo_port == DEVICE_PORT_DVOB) ?
273 "SDVOB" : "SDVOC");
274 p_mapping = &(dev_priv->sdvo_mappings[p_child->dvo_port - 1]);
275 if (!p_mapping->initialized) {
276 p_mapping->dvo_port = p_child->dvo_port;
277 p_mapping->slave_addr = p_child->slave_addr;
278 p_mapping->dvo_wiring = p_child->dvo_wiring;
279 p_mapping->initialized = 1;
280 } else {
281 DRM_DEBUG("Maybe one SDVO port is shared by "
282 "two SDVO device.\n");
283 }
284 if (p_child->slave2_addr) {
285 /* Maybe this is a SDVO device with multiple inputs */
286 /* And the mapping info is not added */
287 DRM_DEBUG("there exists the slave2_addr. Maybe this "
288 "is a SDVO device with multiple inputs.\n");
289 }
290 count++;
291 }
292
293 if (!count) {
294 /* No SDVO device info is found */
295 DRM_DEBUG("No SDVO device info is found in VBT\n");
296 }
297 return;
298}
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800299
300static void
301parse_driver_features(struct drm_i915_private *dev_priv,
302 struct bdb_header *bdb)
303{
304 struct drm_device *dev = dev_priv->dev;
305 struct bdb_driver_features *driver;
306
307 /* set default for chips without eDP */
308 if (!SUPPORTS_EDP(dev)) {
309 dev_priv->edp_support = 0;
310 return;
311 }
312
313 driver = find_section(bdb, BDB_DRIVER_FEATURES);
314 if (driver && driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
315 dev_priv->edp_support = 1;
316}
317
Jesse Barnes79e53942008-11-07 14:24:08 -0800318/**
319 * intel_init_bios - initialize VBIOS settings & find VBT
320 * @dev: DRM device
321 *
322 * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
323 * to appropriate values.
324 *
325 * VBT existence is a sanity check that is relied on by other i830_bios.c code.
326 * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
327 * feed an updated VBT back through that, compared to what we'll fetch using
328 * this method of groping around in the BIOS data.
329 *
330 * Returns 0 on success, nonzero on failure.
331 */
332bool
333intel_init_bios(struct drm_device *dev)
334{
335 struct drm_i915_private *dev_priv = dev->dev_private;
336 struct pci_dev *pdev = dev->pdev;
337 struct vbt_header *vbt = NULL;
338 struct bdb_header *bdb;
339 u8 __iomem *bios;
340 size_t size;
341 int i;
342
343 bios = pci_map_rom(pdev, &size);
344 if (!bios)
345 return -1;
346
347 /* Scour memory looking for the VBT signature */
348 for (i = 0; i + 4 < size; i++) {
349 if (!memcmp(bios + i, "$VBT", 4)) {
350 vbt = (struct vbt_header *)(bios + i);
351 break;
352 }
353 }
354
355 if (!vbt) {
356 DRM_ERROR("VBT signature missing\n");
357 pci_unmap_rom(pdev, bios);
358 return -1;
359 }
360
361 bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
362
363 /* Grab useful general definitions */
364 parse_general_features(dev_priv, bdb);
Ma Ling88631702009-05-13 11:19:55 +0800365 parse_lfp_panel_data(dev_priv, bdb);
366 parse_sdvo_panel_data(dev_priv, bdb);
yakui_zhao9b9d1722009-05-31 17:17:17 +0800367 parse_sdvo_device_mapping(dev_priv, bdb);
Zhenyu Wang32f9d652009-07-24 01:00:32 +0800368 parse_driver_features(dev_priv, bdb);
369
Jesse Barnes79e53942008-11-07 14:24:08 -0800370 pci_unmap_rom(pdev, bios);
371
372 return 0;
373}