intel_bios.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  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. static void *
  33. find_section(struct bdb_header *bdb, int section_id)
  34. {
  35. u8 *base = (u8 *)bdb;
  36. int index = 0;
  37. u16 total, current_size;
  38. u8 current_id;
  39. /* skip to first section */
  40. index += bdb->header_size;
  41. total = bdb->bdb_size;
  42. /* walk the sections looking for section_id */
  43. while (index < total) {
  44. current_id = *(base + index);
  45. index++;
  46. current_size = *((u16 *)(base + index));
  47. index += 2;
  48. if (current_id == section_id)
  49. return base + index;
  50. index += current_size;
  51. }
  52. return NULL;
  53. }
  54. static void
  55. fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
  56. struct lvds_dvo_timing *dvo_timing)
  57. {
  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);
  66. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  67. dvo_timing->vactive_lo;
  68. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  69. dvo_timing->vsync_off;
  70. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  71. dvo_timing->vsync_pulse_width;
  72. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  73. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  74. panel_fixed_mode->clock = dvo_timing->clock * 10;
  75. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  76. /* Some VBTs have bogus h/vtotal values */
  77. if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
  78. panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
  79. if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
  80. panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
  81. drm_mode_set_name(panel_fixed_mode);
  82. }
  83. /* Try to find integrated panel data */
  84. static void
  85. parse_lfp_panel_data(struct drm_i915_private *dev_priv,
  86. struct bdb_header *bdb)
  87. {
  88. struct bdb_lvds_options *lvds_options;
  89. struct bdb_lvds_lfp_data *lvds_lfp_data;
  90. struct bdb_lvds_lfp_data_entry *entry;
  91. struct lvds_dvo_timing *dvo_timing;
  92. struct drm_display_mode *panel_fixed_mode;
  93. /* Defaults if we can't find VBT info */
  94. dev_priv->lvds_dither = 0;
  95. dev_priv->lvds_vbt = 0;
  96. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  97. if (!lvds_options)
  98. return;
  99. dev_priv->lvds_dither = lvds_options->pixel_dither;
  100. if (lvds_options->panel_type == 0xff)
  101. return;
  102. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  103. if (!lvds_lfp_data)
  104. return;
  105. dev_priv->lvds_vbt = 1;
  106. entry = &lvds_lfp_data->data[lvds_options->panel_type];
  107. dvo_timing = &entry->dvo_timing;
  108. panel_fixed_mode = drm_calloc(1, sizeof(*panel_fixed_mode),
  109. DRM_MEM_DRIVER);
  110. fill_detail_timing_data(panel_fixed_mode, dvo_timing);
  111. dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;
  112. DRM_DEBUG("Found panel mode in BIOS VBT tables:\n");
  113. drm_mode_debug_printmodeline(panel_fixed_mode);
  114. return;
  115. }
  116. /* Try to find sdvo panel data */
  117. static void
  118. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  119. struct bdb_header *bdb)
  120. {
  121. struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  122. struct lvds_dvo_timing *dvo_timing;
  123. struct drm_display_mode *panel_fixed_mode;
  124. dev_priv->sdvo_lvds_vbt_mode = NULL;
  125. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  126. if (!sdvo_lvds_options)
  127. return;
  128. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  129. if (!dvo_timing)
  130. return;
  131. panel_fixed_mode = drm_calloc(1, sizeof(*panel_fixed_mode),
  132. DRM_MEM_DRIVER);
  133. if (!panel_fixed_mode)
  134. return;
  135. fill_detail_timing_data(panel_fixed_mode,
  136. dvo_timing + sdvo_lvds_options->panel_type);
  137. dev_priv->sdvo_lvds_vbt_mode = panel_fixed_mode;
  138. return;
  139. }
  140. static void
  141. parse_general_features(struct drm_i915_private *dev_priv,
  142. struct bdb_header *bdb)
  143. {
  144. struct bdb_general_features *general;
  145. /* Set sensible defaults in case we can't find the general block */
  146. dev_priv->int_tv_support = 1;
  147. dev_priv->int_crt_support = 1;
  148. general = find_section(bdb, BDB_GENERAL_FEATURES);
  149. if (general) {
  150. dev_priv->int_tv_support = general->int_tv_support;
  151. dev_priv->int_crt_support = general->int_crt_support;
  152. dev_priv->lvds_use_ssc = general->enable_ssc;
  153. if (dev_priv->lvds_use_ssc) {
  154. if (IS_I855(dev_priv->dev))
  155. dev_priv->lvds_ssc_freq = general->ssc_freq ? 66 : 48;
  156. else
  157. dev_priv->lvds_ssc_freq = general->ssc_freq ? 100 : 96;
  158. }
  159. }
  160. }
  161. /**
  162. * intel_init_bios - initialize VBIOS settings & find VBT
  163. * @dev: DRM device
  164. *
  165. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  166. * to appropriate values.
  167. *
  168. * VBT existence is a sanity check that is relied on by other i830_bios.c code.
  169. * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
  170. * feed an updated VBT back through that, compared to what we'll fetch using
  171. * this method of groping around in the BIOS data.
  172. *
  173. * Returns 0 on success, nonzero on failure.
  174. */
  175. bool
  176. intel_init_bios(struct drm_device *dev)
  177. {
  178. struct drm_i915_private *dev_priv = dev->dev_private;
  179. struct pci_dev *pdev = dev->pdev;
  180. struct vbt_header *vbt = NULL;
  181. struct bdb_header *bdb;
  182. u8 __iomem *bios;
  183. size_t size;
  184. int i;
  185. bios = pci_map_rom(pdev, &size);
  186. if (!bios)
  187. return -1;
  188. /* Scour memory looking for the VBT signature */
  189. for (i = 0; i + 4 < size; i++) {
  190. if (!memcmp(bios + i, "$VBT", 4)) {
  191. vbt = (struct vbt_header *)(bios + i);
  192. break;
  193. }
  194. }
  195. if (!vbt) {
  196. DRM_ERROR("VBT signature missing\n");
  197. pci_unmap_rom(pdev, bios);
  198. return -1;
  199. }
  200. bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
  201. /* Grab useful general definitions */
  202. parse_general_features(dev_priv, bdb);
  203. parse_lfp_panel_data(dev_priv, bdb);
  204. parse_sdvo_panel_data(dev_priv, bdb);
  205. pci_unmap_rom(pdev, bios);
  206. return 0;
  207. }