]>
git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/gpu/drm/i915/intel_bios.c
2 * Copyright © 2006 Intel Corporation
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:
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
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
24 * Eric Anholt <eric@anholt.net>
31 #include "intel_bios.h"
33 #define SLAVE_ADDR1 0x70
34 #define SLAVE_ADDR2 0x72
37 find_section(struct bdb_header
*bdb
, int section_id
)
41 u16 total
, current_size
;
44 /* skip to first section */
45 index
+= bdb
->header_size
;
46 total
= bdb
->bdb_size
;
48 /* walk the sections looking for section_id */
49 while (index
< total
) {
50 current_id
= *(base
+ index
);
52 current_size
= *((u16
*)(base
+ index
));
54 if (current_id
== section_id
)
56 index
+= current_size
;
63 fill_detail_timing_data(struct drm_display_mode
*panel_fixed_mode
,
64 struct lvds_dvo_timing
*dvo_timing
)
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
);
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
;
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;
92 drm_mode_set_name(panel_fixed_mode
);
95 /* Try to find integrated panel data */
97 parse_lfp_panel_data(struct drm_i915_private
*dev_priv
,
98 struct bdb_header
*bdb
)
100 struct drm_device
*dev
= dev_priv
->dev
;
101 struct bdb_lvds_options
*lvds_options
;
102 struct bdb_lvds_lfp_data
*lvds_lfp_data
;
103 struct bdb_lvds_lfp_data_ptrs
*lvds_lfp_data_ptrs
;
104 struct bdb_lvds_lfp_data_entry
*entry
;
105 struct lvds_dvo_timing
*dvo_timing
;
106 struct drm_display_mode
*panel_fixed_mode
;
109 /* Defaults if we can't find VBT info */
110 dev_priv
->lvds_dither
= 0;
111 dev_priv
->lvds_vbt
= 0;
113 lvds_options
= find_section(bdb
, BDB_LVDS_OPTIONS
);
117 dev_priv
->lvds_dither
= lvds_options
->pixel_dither
;
118 if (lvds_options
->panel_type
== 0xff)
121 lvds_lfp_data
= find_section(bdb
, BDB_LVDS_LFP_DATA
);
125 lvds_lfp_data_ptrs
= find_section(bdb
, BDB_LVDS_LFP_DATA_PTRS
);
126 if (!lvds_lfp_data_ptrs
)
129 dev_priv
->lvds_vbt
= 1;
131 lfp_data_size
= lvds_lfp_data_ptrs
->ptr
[1].dvo_timing_offset
-
132 lvds_lfp_data_ptrs
->ptr
[0].dvo_timing_offset
;
133 entry
= (struct bdb_lvds_lfp_data_entry
*)
134 ((uint8_t *)lvds_lfp_data
->data
+ (lfp_data_size
*
135 lvds_options
->panel_type
));
137 /* On IGDNG mobile, LVDS data block removes panel fitting registers.
138 So dec 2 dword from dvo_timing offset */
140 dvo_timing
= (struct lvds_dvo_timing
*)
141 ((u8
*)&entry
->dvo_timing
- 8);
143 dvo_timing
= &entry
->dvo_timing
;
145 panel_fixed_mode
= kzalloc(sizeof(*panel_fixed_mode
), GFP_KERNEL
);
147 fill_detail_timing_data(panel_fixed_mode
, dvo_timing
);
149 dev_priv
->lfp_lvds_vbt_mode
= panel_fixed_mode
;
151 DRM_DEBUG("Found panel mode in BIOS VBT tables:\n");
152 drm_mode_debug_printmodeline(panel_fixed_mode
);
157 /* Try to find sdvo panel data */
159 parse_sdvo_panel_data(struct drm_i915_private
*dev_priv
,
160 struct bdb_header
*bdb
)
162 struct bdb_sdvo_lvds_options
*sdvo_lvds_options
;
163 struct lvds_dvo_timing
*dvo_timing
;
164 struct drm_display_mode
*panel_fixed_mode
;
166 dev_priv
->sdvo_lvds_vbt_mode
= NULL
;
168 sdvo_lvds_options
= find_section(bdb
, BDB_SDVO_LVDS_OPTIONS
);
169 if (!sdvo_lvds_options
)
172 dvo_timing
= find_section(bdb
, BDB_SDVO_PANEL_DTDS
);
176 panel_fixed_mode
= kzalloc(sizeof(*panel_fixed_mode
), GFP_KERNEL
);
178 if (!panel_fixed_mode
)
181 fill_detail_timing_data(panel_fixed_mode
,
182 dvo_timing
+ sdvo_lvds_options
->panel_type
);
184 dev_priv
->sdvo_lvds_vbt_mode
= panel_fixed_mode
;
190 parse_general_features(struct drm_i915_private
*dev_priv
,
191 struct bdb_header
*bdb
)
193 struct bdb_general_features
*general
;
195 /* Set sensible defaults in case we can't find the general block */
196 dev_priv
->int_tv_support
= 1;
197 dev_priv
->int_crt_support
= 1;
199 general
= find_section(bdb
, BDB_GENERAL_FEATURES
);
201 dev_priv
->int_tv_support
= general
->int_tv_support
;
202 dev_priv
->int_crt_support
= general
->int_crt_support
;
203 dev_priv
->lvds_use_ssc
= general
->enable_ssc
;
205 if (dev_priv
->lvds_use_ssc
) {
206 if (IS_I85X(dev_priv
->dev
))
207 dev_priv
->lvds_ssc_freq
=
208 general
->ssc_freq
? 66 : 48;
210 dev_priv
->lvds_ssc_freq
=
211 general
->ssc_freq
? 100 : 96;
217 parse_sdvo_device_mapping(struct drm_i915_private
*dev_priv
,
218 struct bdb_header
*bdb
)
220 struct sdvo_device_mapping
*p_mapping
;
221 struct bdb_general_definitions
*p_defs
;
222 struct child_device_config
*p_child
;
223 int i
, child_device_num
, count
;
224 u16 block_size
, *block_ptr
;
226 p_defs
= find_section(bdb
, BDB_GENERAL_DEFINITIONS
);
228 DRM_DEBUG("No general definition block is found\n");
231 /* judge whether the size of child device meets the requirements.
232 * If the child device size obtained from general definition block
233 * is different with sizeof(struct child_device_config), skip the
234 * parsing of sdvo device info
236 if (p_defs
->child_dev_size
!= sizeof(*p_child
)) {
237 /* different child dev size . Ignore it */
238 DRM_DEBUG("different child size is found. Invalid.\n");
241 /* get the block size of general definitions */
242 block_ptr
= (u16
*)((char *)p_defs
- 2);
243 block_size
= *block_ptr
;
244 /* get the number of child device */
245 child_device_num
= (block_size
- sizeof(*p_defs
)) /
248 for (i
= 0; i
< child_device_num
; i
++) {
249 p_child
= &(p_defs
->devices
[i
]);
250 if (!p_child
->device_type
) {
251 /* skip the device block if device type is invalid */
254 if (p_child
->slave_addr
!= SLAVE_ADDR1
&&
255 p_child
->slave_addr
!= SLAVE_ADDR2
) {
257 * If the slave address is neither 0x70 nor 0x72,
258 * it is not a SDVO device. Skip it.
262 if (p_child
->dvo_port
!= DEVICE_PORT_DVOB
&&
263 p_child
->dvo_port
!= DEVICE_PORT_DVOC
) {
264 /* skip the incorrect SDVO port */
265 DRM_DEBUG("Incorrect SDVO port. Skip it \n");
268 DRM_DEBUG("the SDVO device with slave addr %2x is found on "
271 (p_child
->dvo_port
== DEVICE_PORT_DVOB
) ?
273 p_mapping
= &(dev_priv
->sdvo_mappings
[p_child
->dvo_port
- 1]);
274 if (!p_mapping
->initialized
) {
275 p_mapping
->dvo_port
= p_child
->dvo_port
;
276 p_mapping
->slave_addr
= p_child
->slave_addr
;
277 p_mapping
->dvo_wiring
= p_child
->dvo_wiring
;
278 p_mapping
->initialized
= 1;
280 DRM_DEBUG("Maybe one SDVO port is shared by "
281 "two SDVO device.\n");
283 if (p_child
->slave2_addr
) {
284 /* Maybe this is a SDVO device with multiple inputs */
285 /* And the mapping info is not added */
286 DRM_DEBUG("there exists the slave2_addr. Maybe this "
287 "is a SDVO device with multiple inputs.\n");
293 /* No SDVO device info is found */
294 DRM_DEBUG("No SDVO device info is found in VBT\n");
299 * intel_init_bios - initialize VBIOS settings & find VBT
302 * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
303 * to appropriate values.
305 * VBT existence is a sanity check that is relied on by other i830_bios.c code.
306 * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
307 * feed an updated VBT back through that, compared to what we'll fetch using
308 * this method of groping around in the BIOS data.
310 * Returns 0 on success, nonzero on failure.
313 intel_init_bios(struct drm_device
*dev
)
315 struct drm_i915_private
*dev_priv
= dev
->dev_private
;
316 struct pci_dev
*pdev
= dev
->pdev
;
317 struct vbt_header
*vbt
= NULL
;
318 struct bdb_header
*bdb
;
323 bios
= pci_map_rom(pdev
, &size
);
327 /* Scour memory looking for the VBT signature */
328 for (i
= 0; i
+ 4 < size
; i
++) {
329 if (!memcmp(bios
+ i
, "$VBT", 4)) {
330 vbt
= (struct vbt_header
*)(bios
+ i
);
336 DRM_ERROR("VBT signature missing\n");
337 pci_unmap_rom(pdev
, bios
);
341 bdb
= (struct bdb_header
*)(bios
+ i
+ vbt
->bdb_offset
);
343 /* Grab useful general definitions */
344 parse_general_features(dev_priv
, bdb
);
345 parse_lfp_panel_data(dev_priv
, bdb
);
346 parse_sdvo_panel_data(dev_priv
, bdb
);
347 parse_sdvo_device_mapping(dev_priv
, bdb
);
348 pci_unmap_rom(pdev
, bios
);