intel_bios.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. #define SLAVE_ADDR1 0x70
  33. #define SLAVE_ADDR2 0x72
  34. static void *
  35. find_section(struct bdb_header *bdb, int section_id)
  36. {
  37. u8 *base = (u8 *)bdb;
  38. int index = 0;
  39. u16 total, current_size;
  40. u8 current_id;
  41. /* skip to first section */
  42. index += bdb->header_size;
  43. total = bdb->bdb_size;
  44. /* walk the sections looking for section_id */
  45. while (index < total) {
  46. current_id = *(base + index);
  47. index++;
  48. current_size = *((u16 *)(base + index));
  49. index += 2;
  50. if (current_id == section_id)
  51. return base + index;
  52. index += current_size;
  53. }
  54. return NULL;
  55. }
  56. static void
  57. fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
  58. struct lvds_dvo_timing *dvo_timing)
  59. {
  60. panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
  61. dvo_timing->hactive_lo;
  62. panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
  63. ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
  64. panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
  65. dvo_timing->hsync_pulse_width;
  66. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  67. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  68. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  69. dvo_timing->vactive_lo;
  70. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  71. dvo_timing->vsync_off;
  72. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  73. dvo_timing->vsync_pulse_width;
  74. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  75. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  76. panel_fixed_mode->clock = dvo_timing->clock * 10;
  77. 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;
  83. drm_mode_set_name(panel_fixed_mode);
  84. }
  85. /* Try to find integrated panel data */
  86. static void
  87. parse_lfp_panel_data(struct drm_i915_private *dev_priv,
  88. struct bdb_header *bdb)
  89. {
  90. struct bdb_lvds_options *lvds_options;
  91. struct bdb_lvds_lfp_data *lvds_lfp_data;
  92. struct bdb_lvds_lfp_data_entry *entry;
  93. struct lvds_dvo_timing *dvo_timing;
  94. struct drm_display_mode *panel_fixed_mode;
  95. /* Defaults if we can't find VBT info */
  96. dev_priv->lvds_dither = 0;
  97. dev_priv->lvds_vbt = 0;
  98. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  99. if (!lvds_options)
  100. return;
  101. dev_priv->lvds_dither = lvds_options->pixel_dither;
  102. if (lvds_options->panel_type == 0xff)
  103. return;
  104. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  105. if (!lvds_lfp_data)
  106. return;
  107. dev_priv->lvds_vbt = 1;
  108. entry = &lvds_lfp_data->data[lvds_options->panel_type];
  109. dvo_timing = &entry->dvo_timing;
  110. panel_fixed_mode = drm_calloc(1, sizeof(*panel_fixed_mode),
  111. DRM_MEM_DRIVER);
  112. fill_detail_timing_data(panel_fixed_mode, dvo_timing);
  113. dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;
  114. DRM_DEBUG("Found panel mode in BIOS VBT tables:\n");
  115. drm_mode_debug_printmodeline(panel_fixed_mode);
  116. return;
  117. }
  118. /* Try to find sdvo panel data */
  119. static void
  120. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  121. struct bdb_header *bdb)
  122. {
  123. struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  124. struct lvds_dvo_timing *dvo_timing;
  125. struct drm_display_mode *panel_fixed_mode;
  126. dev_priv->sdvo_lvds_vbt_mode = NULL;
  127. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  128. if (!sdvo_lvds_options)
  129. return;
  130. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  131. if (!dvo_timing)
  132. return;
  133. panel_fixed_mode = drm_calloc(1, sizeof(*panel_fixed_mode),
  134. DRM_MEM_DRIVER);
  135. if (!panel_fixed_mode)
  136. return;
  137. fill_detail_timing_data(panel_fixed_mode,
  138. dvo_timing + sdvo_lvds_options->panel_type);
  139. dev_priv->sdvo_lvds_vbt_mode = panel_fixed_mode;
  140. return;
  141. }
  142. static void
  143. parse_general_features(struct drm_i915_private *dev_priv,
  144. struct bdb_header *bdb)
  145. {
  146. struct bdb_general_features *general;
  147. /* Set sensible defaults in case we can't find the general block */
  148. dev_priv->int_tv_support = 1;
  149. dev_priv->int_crt_support = 1;
  150. general = find_section(bdb, BDB_GENERAL_FEATURES);
  151. if (general) {
  152. dev_priv->int_tv_support = general->int_tv_support;
  153. dev_priv->int_crt_support = general->int_crt_support;
  154. dev_priv->lvds_use_ssc = general->enable_ssc;
  155. if (dev_priv->lvds_use_ssc) {
  156. if (IS_I855(dev_priv->dev))
  157. dev_priv->lvds_ssc_freq = general->ssc_freq ? 66 : 48;
  158. else
  159. dev_priv->lvds_ssc_freq = general->ssc_freq ? 100 : 96;
  160. }
  161. }
  162. }
  163. static void
  164. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  165. struct bdb_header *bdb)
  166. {
  167. struct sdvo_device_mapping *p_mapping;
  168. struct bdb_general_definitions *p_defs;
  169. struct child_device_config *p_child;
  170. int i, child_device_num, count;
  171. u16 block_size, *block_ptr;
  172. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  173. if (!p_defs) {
  174. DRM_DEBUG("No general definition block is found\n");
  175. return;
  176. }
  177. /* judge whether the size of child device meets the requirements.
  178. * If the child device size obtained from general definition block
  179. * is different with sizeof(struct child_device_config), skip the
  180. * parsing of sdvo device info
  181. */
  182. if (p_defs->child_dev_size != sizeof(*p_child)) {
  183. /* different child dev size . Ignore it */
  184. DRM_DEBUG("different child size is found. Invalid.\n");
  185. return;
  186. }
  187. /* get the block size of general definitions */
  188. block_ptr = (u16 *)((char *)p_defs - 2);
  189. block_size = *block_ptr;
  190. /* get the number of child device */
  191. child_device_num = (block_size - sizeof(*p_defs)) /
  192. sizeof(*p_child);
  193. count = 0;
  194. for (i = 0; i < child_device_num; i++) {
  195. p_child = &(p_defs->devices[i]);
  196. if (!p_child->device_type) {
  197. /* skip the device block if device type is invalid */
  198. continue;
  199. }
  200. if (p_child->slave_addr != SLAVE_ADDR1 &&
  201. p_child->slave_addr != SLAVE_ADDR2) {
  202. /*
  203. * If the slave address is neither 0x70 nor 0x72,
  204. * it is not a SDVO device. Skip it.
  205. */
  206. continue;
  207. }
  208. if (p_child->dvo_port != DEVICE_PORT_DVOB &&
  209. p_child->dvo_port != DEVICE_PORT_DVOC) {
  210. /* skip the incorrect SDVO port */
  211. DRM_DEBUG("Incorrect SDVO port. Skip it \n");
  212. continue;
  213. }
  214. DRM_DEBUG("the SDVO device with slave addr %2x is found on "
  215. "%s port\n",
  216. p_child->slave_addr,
  217. (p_child->dvo_port == DEVICE_PORT_DVOB) ?
  218. "SDVOB" : "SDVOC");
  219. p_mapping = &(dev_priv->sdvo_mappings[p_child->dvo_port - 1]);
  220. if (!p_mapping->initialized) {
  221. p_mapping->dvo_port = p_child->dvo_port;
  222. p_mapping->slave_addr = p_child->slave_addr;
  223. p_mapping->dvo_wiring = p_child->dvo_wiring;
  224. p_mapping->initialized = 1;
  225. } else {
  226. DRM_DEBUG("Maybe one SDVO port is shared by "
  227. "two SDVO device.\n");
  228. }
  229. if (p_child->slave2_addr) {
  230. /* Maybe this is a SDVO device with multiple inputs */
  231. /* And the mapping info is not added */
  232. DRM_DEBUG("there exists the slave2_addr. Maybe this "
  233. "is a SDVO device with multiple inputs.\n");
  234. }
  235. count++;
  236. }
  237. if (!count) {
  238. /* No SDVO device info is found */
  239. DRM_DEBUG("No SDVO device info is found in VBT\n");
  240. }
  241. return;
  242. }
  243. /**
  244. * intel_init_bios - initialize VBIOS settings & find VBT
  245. * @dev: DRM device
  246. *
  247. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  248. * to appropriate values.
  249. *
  250. * VBT existence is a sanity check that is relied on by other i830_bios.c code.
  251. * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
  252. * feed an updated VBT back through that, compared to what we'll fetch using
  253. * this method of groping around in the BIOS data.
  254. *
  255. * Returns 0 on success, nonzero on failure.
  256. */
  257. bool
  258. intel_init_bios(struct drm_device *dev)
  259. {
  260. struct drm_i915_private *dev_priv = dev->dev_private;
  261. struct pci_dev *pdev = dev->pdev;
  262. struct vbt_header *vbt = NULL;
  263. struct bdb_header *bdb;
  264. u8 __iomem *bios;
  265. size_t size;
  266. int i;
  267. bios = pci_map_rom(pdev, &size);
  268. if (!bios)
  269. return -1;
  270. /* Scour memory looking for the VBT signature */
  271. for (i = 0; i + 4 < size; i++) {
  272. if (!memcmp(bios + i, "$VBT", 4)) {
  273. vbt = (struct vbt_header *)(bios + i);
  274. break;
  275. }
  276. }
  277. if (!vbt) {
  278. DRM_ERROR("VBT signature missing\n");
  279. pci_unmap_rom(pdev, bios);
  280. return -1;
  281. }
  282. bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
  283. /* Grab useful general definitions */
  284. parse_general_features(dev_priv, bdb);
  285. parse_lfp_panel_data(dev_priv, bdb);
  286. parse_sdvo_panel_data(dev_priv, bdb);
  287. parse_sdvo_device_mapping(dev_priv, bdb);
  288. pci_unmap_rom(pdev, bios);
  289. return 0;
  290. }