]>
git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blob - drivers/staging/gma500/psb_intel_bios.c
2 * Copyright (c) 2006 Intel Corporation
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * You should have received a copy of the GNU General Public License along with
14 * this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 * Eric Anholt <eric@anholt.net>
25 #include "psb_intel_drv.h"
26 #include "psb_intel_reg.h"
27 #include "psb_intel_bios.h"
30 static void *find_section(struct bdb_header
*bdb
, int section_id
)
34 u16 total
, current_size
;
37 /* skip to first section */
38 index
+= bdb
->header_size
;
39 total
= bdb
->bdb_size
;
41 /* walk the sections looking for section_id */
42 while (index
< total
) {
43 current_id
= *(base
+ index
);
45 current_size
= *((u16
*)(base
+ index
));
47 if (current_id
== section_id
)
49 index
+= current_size
;
55 static void fill_detail_timing_data(struct drm_display_mode
*panel_fixed_mode
,
56 struct lvds_dvo_timing
*dvo_timing
)
58 panel_fixed_mode
->hdisplay
= (dvo_timing
->hactive_hi
<< 8) |
59 dvo_timing
->hactive_lo
;
60 panel_fixed_mode
->hsync_start
= panel_fixed_mode
->hdisplay
+
61 ((dvo_timing
->hsync_off_hi
<< 8) | dvo_timing
->hsync_off_lo
);
62 panel_fixed_mode
->hsync_end
= panel_fixed_mode
->hsync_start
+
63 dvo_timing
->hsync_pulse_width
;
64 panel_fixed_mode
->htotal
= panel_fixed_mode
->hdisplay
+
65 ((dvo_timing
->hblank_hi
<< 8) | dvo_timing
->hblank_lo
);
67 panel_fixed_mode
->vdisplay
= (dvo_timing
->vactive_hi
<< 8) |
68 dvo_timing
->vactive_lo
;
69 panel_fixed_mode
->vsync_start
= panel_fixed_mode
->vdisplay
+
70 dvo_timing
->vsync_off
;
71 panel_fixed_mode
->vsync_end
= panel_fixed_mode
->vsync_start
+
72 dvo_timing
->vsync_pulse_width
;
73 panel_fixed_mode
->vtotal
= panel_fixed_mode
->vdisplay
+
74 ((dvo_timing
->vblank_hi
<< 8) | dvo_timing
->vblank_lo
);
75 panel_fixed_mode
->clock
= dvo_timing
->clock
* 10;
76 panel_fixed_mode
->type
= DRM_MODE_TYPE_PREFERRED
;
78 /* Some VBTs have bogus h/vtotal values */
79 if (panel_fixed_mode
->hsync_end
> panel_fixed_mode
->htotal
)
80 panel_fixed_mode
->htotal
= panel_fixed_mode
->hsync_end
+ 1;
81 if (panel_fixed_mode
->vsync_end
> panel_fixed_mode
->vtotal
)
82 panel_fixed_mode
->vtotal
= panel_fixed_mode
->vsync_end
+ 1;
84 drm_mode_set_name(panel_fixed_mode
);
87 static void parse_backlight_data(struct drm_psb_private
*dev_priv
,
88 struct bdb_header
*bdb
)
90 struct bdb_lvds_backlight
*vbt_lvds_bl
= NULL
;
91 struct bdb_lvds_backlight
*lvds_bl
;
93 void *bl_start
= NULL
;
94 struct bdb_lvds_options
*lvds_opts
95 = find_section(bdb
, BDB_LVDS_OPTIONS
);
97 dev_priv
->lvds_bl
= NULL
;
100 DRM_DEBUG("lvds_options found at %p\n", lvds_opts
);
101 p_type
= lvds_opts
->panel_type
;
103 DRM_DEBUG("no lvds_options\n");
107 bl_start
= find_section(bdb
, BDB_LVDS_BACKLIGHT
);
108 vbt_lvds_bl
= (struct bdb_lvds_backlight
*)(bl_start
+ 1) + p_type
;
110 lvds_bl
= kzalloc(sizeof(*vbt_lvds_bl
), GFP_KERNEL
);
112 DRM_DEBUG("No memory\n");
116 memcpy(lvds_bl
, vbt_lvds_bl
, sizeof(*vbt_lvds_bl
));
118 dev_priv
->lvds_bl
= lvds_bl
;
121 /* Try to find integrated panel data */
122 static void parse_lfp_panel_data(struct drm_psb_private
*dev_priv
,
123 struct bdb_header
*bdb
)
125 struct bdb_lvds_options
*lvds_options
;
126 struct bdb_lvds_lfp_data
*lvds_lfp_data
;
127 struct bdb_lvds_lfp_data_entry
*entry
;
128 struct lvds_dvo_timing
*dvo_timing
;
129 struct drm_display_mode
*panel_fixed_mode
;
131 /* Defaults if we can't find VBT info */
132 dev_priv
->lvds_dither
= 0;
133 dev_priv
->lvds_vbt
= 0;
135 lvds_options
= find_section(bdb
, BDB_LVDS_OPTIONS
);
139 dev_priv
->lvds_dither
= lvds_options
->pixel_dither
;
140 if (lvds_options
->panel_type
== 0xff)
143 lvds_lfp_data
= find_section(bdb
, BDB_LVDS_LFP_DATA
);
147 dev_priv
->lvds_vbt
= 1;
149 entry
= &lvds_lfp_data
->data
[lvds_options
->panel_type
];
150 dvo_timing
= &entry
->dvo_timing
;
152 panel_fixed_mode
= kzalloc(sizeof(*panel_fixed_mode
),
155 fill_detail_timing_data(panel_fixed_mode
, dvo_timing
);
157 if (panel_fixed_mode
->htotal
> 0 && panel_fixed_mode
->vtotal
> 0) {
158 dev_priv
->lfp_lvds_vbt_mode
= panel_fixed_mode
;
159 DRM_DEBUG("Found panel mode in BIOS VBT tables:\n");
160 drm_mode_debug_printmodeline(panel_fixed_mode
);
162 DRM_DEBUG("Ignoring bogus LVDS VBT mode.\n");
163 dev_priv
->lvds_vbt
= 0;
164 kfree(panel_fixed_mode
);
170 /* Try to find sdvo panel data */
171 static void parse_sdvo_panel_data(struct drm_psb_private
*dev_priv
,
172 struct bdb_header
*bdb
)
174 struct bdb_sdvo_lvds_options
*sdvo_lvds_options
;
175 struct lvds_dvo_timing
*dvo_timing
;
176 struct drm_display_mode
*panel_fixed_mode
;
178 dev_priv
->sdvo_lvds_vbt_mode
= NULL
;
180 sdvo_lvds_options
= find_section(bdb
, BDB_SDVO_LVDS_OPTIONS
);
181 if (!sdvo_lvds_options
)
184 dvo_timing
= find_section(bdb
, BDB_SDVO_PANEL_DTDS
);
188 panel_fixed_mode
= kzalloc(sizeof(*panel_fixed_mode
), GFP_KERNEL
);
190 if (!panel_fixed_mode
)
193 fill_detail_timing_data(panel_fixed_mode
,
194 dvo_timing
+ sdvo_lvds_options
->panel_type
);
196 dev_priv
->sdvo_lvds_vbt_mode
= panel_fixed_mode
;
201 static void parse_general_features(struct drm_psb_private
*dev_priv
,
202 struct bdb_header
*bdb
)
204 struct bdb_general_features
*general
;
206 /* Set sensible defaults in case we can't find the general block */
207 dev_priv
->int_tv_support
= 1;
208 dev_priv
->int_crt_support
= 1;
210 general
= find_section(bdb
, BDB_GENERAL_FEATURES
);
212 dev_priv
->int_tv_support
= general
->int_tv_support
;
213 dev_priv
->int_crt_support
= general
->int_crt_support
;
214 dev_priv
->lvds_use_ssc
= general
->enable_ssc
;
216 if (dev_priv
->lvds_use_ssc
) {
217 dev_priv
->lvds_ssc_freq
218 = general
->ssc_freq
? 100 : 96;
224 * psb_intel_init_bios - initialize VBIOS settings & find VBT
227 * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
228 * to appropriate values.
230 * VBT existence is a sanity check that is relied on by other i830_bios.c code.
231 * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
232 * feed an updated VBT back through that, compared to what we'll fetch using
233 * this method of groping around in the BIOS data.
235 * Returns 0 on success, nonzero on failure.
237 bool psb_intel_init_bios(struct drm_device
*dev
)
239 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
240 struct pci_dev
*pdev
= dev
->pdev
;
241 struct vbt_header
*vbt
= NULL
;
242 struct bdb_header
*bdb
;
247 bios
= pci_map_rom(pdev
, &size
);
251 /* Scour memory looking for the VBT signature */
252 for (i
= 0; i
+ 4 < size
; i
++) {
253 if (!memcmp(bios
+ i
, "$VBT", 4)) {
254 vbt
= (struct vbt_header
*)(bios
+ i
);
260 DRM_ERROR("VBT signature missing\n");
261 pci_unmap_rom(pdev
, bios
);
265 bdb
= (struct bdb_header
*)(bios
+ i
+ vbt
->bdb_offset
);
267 /* Grab useful general definitions */
268 parse_general_features(dev_priv
, bdb
);
269 parse_lfp_panel_data(dev_priv
, bdb
);
270 parse_sdvo_panel_data(dev_priv
, bdb
);
271 parse_backlight_data(dev_priv
, bdb
);
273 pci_unmap_rom(pdev
, bios
);
279 * Destroy and free VBT data
281 void psb_intel_destroy_bios(struct drm_device
*dev
)
283 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
284 struct drm_display_mode
*sdvo_lvds_vbt_mode
=
285 dev_priv
->sdvo_lvds_vbt_mode
;
286 struct drm_display_mode
*lfp_lvds_vbt_mode
=
287 dev_priv
->lfp_lvds_vbt_mode
;
288 struct bdb_lvds_backlight
*lvds_bl
=
291 /*free sdvo panel mode*/
292 if (sdvo_lvds_vbt_mode
) {
293 dev_priv
->sdvo_lvds_vbt_mode
= NULL
;
294 kfree(sdvo_lvds_vbt_mode
);
297 if (lfp_lvds_vbt_mode
) {
298 dev_priv
->lfp_lvds_vbt_mode
= NULL
;
299 kfree(lfp_lvds_vbt_mode
);
303 dev_priv
->lvds_bl
= NULL
;