]>
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 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
);
165 /* Try to find sdvo panel data */
166 static void parse_sdvo_panel_data(struct drm_psb_private
*dev_priv
,
167 struct bdb_header
*bdb
)
169 struct bdb_sdvo_lvds_options
*sdvo_lvds_options
;
170 struct lvds_dvo_timing
*dvo_timing
;
171 struct drm_display_mode
*panel_fixed_mode
;
173 dev_priv
->sdvo_lvds_vbt_mode
= NULL
;
175 sdvo_lvds_options
= find_section(bdb
, BDB_SDVO_LVDS_OPTIONS
);
176 if (!sdvo_lvds_options
)
179 dvo_timing
= find_section(bdb
, BDB_SDVO_PANEL_DTDS
);
183 panel_fixed_mode
= kzalloc(sizeof(*panel_fixed_mode
), GFP_KERNEL
);
185 if (!panel_fixed_mode
)
188 fill_detail_timing_data(panel_fixed_mode
,
189 dvo_timing
+ sdvo_lvds_options
->panel_type
);
191 dev_priv
->sdvo_lvds_vbt_mode
= panel_fixed_mode
;
196 static void parse_general_features(struct drm_psb_private
*dev_priv
,
197 struct bdb_header
*bdb
)
199 struct bdb_general_features
*general
;
201 /* Set sensible defaults in case we can't find the general block */
202 dev_priv
->int_tv_support
= 1;
203 dev_priv
->int_crt_support
= 1;
205 general
= find_section(bdb
, BDB_GENERAL_FEATURES
);
207 dev_priv
->int_tv_support
= general
->int_tv_support
;
208 dev_priv
->int_crt_support
= general
->int_crt_support
;
209 dev_priv
->lvds_use_ssc
= general
->enable_ssc
;
211 if (dev_priv
->lvds_use_ssc
) {
212 dev_priv
->lvds_ssc_freq
213 = general
->ssc_freq
? 100 : 96;
219 * psb_intel_init_bios - initialize VBIOS settings & find VBT
222 * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
223 * to appropriate values.
225 * VBT existence is a sanity check that is relied on by other i830_bios.c code.
226 * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
227 * feed an updated VBT back through that, compared to what we'll fetch using
228 * this method of groping around in the BIOS data.
230 * Returns 0 on success, nonzero on failure.
232 bool psb_intel_init_bios(struct drm_device
*dev
)
234 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
235 struct pci_dev
*pdev
= dev
->pdev
;
236 struct vbt_header
*vbt
= NULL
;
237 struct bdb_header
*bdb
;
242 bios
= pci_map_rom(pdev
, &size
);
246 /* Scour memory looking for the VBT signature */
247 for (i
= 0; i
+ 4 < size
; i
++) {
248 if (!memcmp(bios
+ i
, "$VBT", 4)) {
249 vbt
= (struct vbt_header
*)(bios
+ i
);
255 DRM_ERROR("VBT signature missing\n");
256 pci_unmap_rom(pdev
, bios
);
260 bdb
= (struct bdb_header
*)(bios
+ i
+ vbt
->bdb_offset
);
262 /* Grab useful general definitions */
263 parse_general_features(dev_priv
, bdb
);
264 parse_lfp_panel_data(dev_priv
, bdb
);
265 parse_sdvo_panel_data(dev_priv
, bdb
);
266 parse_backlight_data(dev_priv
, bdb
);
268 pci_unmap_rom(pdev
, bios
);
274 * Destroy and free VBT data
276 void psb_intel_destroy_bios(struct drm_device
*dev
)
278 struct drm_psb_private
*dev_priv
= dev
->dev_private
;
279 struct drm_display_mode
*sdvo_lvds_vbt_mode
=
280 dev_priv
->sdvo_lvds_vbt_mode
;
281 struct drm_display_mode
*lfp_lvds_vbt_mode
=
282 dev_priv
->lfp_lvds_vbt_mode
;
283 struct bdb_lvds_backlight
*lvds_bl
=
286 /*free sdvo panel mode*/
287 if (sdvo_lvds_vbt_mode
) {
288 dev_priv
->sdvo_lvds_vbt_mode
= NULL
;
289 kfree(sdvo_lvds_vbt_mode
);
292 if (lfp_lvds_vbt_mode
) {
293 dev_priv
->lfp_lvds_vbt_mode
= NULL
;
294 kfree(lfp_lvds_vbt_mode
);
298 dev_priv
->lvds_bl
= NULL
;