intel_bios.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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_ptrs *lvds_lfp_data_ptrs;
  93. struct bdb_lvds_lfp_data_entry *entry;
  94. struct lvds_dvo_timing *dvo_timing;
  95. struct drm_display_mode *panel_fixed_mode;
  96. int lfp_data_size, dvo_timing_offset;
  97. /* Defaults if we can't find VBT info */
  98. dev_priv->lvds_dither = 0;
  99. dev_priv->lvds_vbt = 0;
  100. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  101. if (!lvds_options)
  102. return;
  103. dev_priv->lvds_dither = lvds_options->pixel_dither;
  104. if (lvds_options->panel_type == 0xff)
  105. return;
  106. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  107. if (!lvds_lfp_data)
  108. return;
  109. lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
  110. if (!lvds_lfp_data_ptrs)
  111. return;
  112. dev_priv->lvds_vbt = 1;
  113. lfp_data_size = lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
  114. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
  115. entry = (struct bdb_lvds_lfp_data_entry *)
  116. ((uint8_t *)lvds_lfp_data->data + (lfp_data_size *
  117. lvds_options->panel_type));
  118. dvo_timing_offset = lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
  119. lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
  120. /*
  121. * the size of fp_timing varies on the different platform.
  122. * So calculate the DVO timing relative offset in LVDS data
  123. * entry to get the DVO timing entry
  124. */
  125. dvo_timing = (struct lvds_dvo_timing *)
  126. ((unsigned char *)entry + dvo_timing_offset);
  127. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  128. fill_detail_timing_data(panel_fixed_mode, dvo_timing);
  129. dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;
  130. DRM_DEBUG("Found panel mode in BIOS VBT tables:\n");
  131. drm_mode_debug_printmodeline(panel_fixed_mode);
  132. return;
  133. }
  134. /* Try to find sdvo panel data */
  135. static void
  136. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  137. struct bdb_header *bdb)
  138. {
  139. struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  140. struct lvds_dvo_timing *dvo_timing;
  141. struct drm_display_mode *panel_fixed_mode;
  142. dev_priv->sdvo_lvds_vbt_mode = NULL;
  143. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  144. if (!sdvo_lvds_options)
  145. return;
  146. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  147. if (!dvo_timing)
  148. return;
  149. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  150. if (!panel_fixed_mode)
  151. return;
  152. fill_detail_timing_data(panel_fixed_mode,
  153. dvo_timing + sdvo_lvds_options->panel_type);
  154. dev_priv->sdvo_lvds_vbt_mode = panel_fixed_mode;
  155. return;
  156. }
  157. static void
  158. parse_general_features(struct drm_i915_private *dev_priv,
  159. struct bdb_header *bdb)
  160. {
  161. struct bdb_general_features *general;
  162. /* Set sensible defaults in case we can't find the general block */
  163. dev_priv->int_tv_support = 1;
  164. dev_priv->int_crt_support = 1;
  165. general = find_section(bdb, BDB_GENERAL_FEATURES);
  166. if (general) {
  167. dev_priv->int_tv_support = general->int_tv_support;
  168. dev_priv->int_crt_support = general->int_crt_support;
  169. dev_priv->lvds_use_ssc = general->enable_ssc;
  170. if (dev_priv->lvds_use_ssc) {
  171. if (IS_I85X(dev_priv->dev))
  172. dev_priv->lvds_ssc_freq =
  173. general->ssc_freq ? 66 : 48;
  174. else
  175. dev_priv->lvds_ssc_freq =
  176. general->ssc_freq ? 100 : 96;
  177. }
  178. }
  179. }
  180. static void
  181. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  182. struct bdb_header *bdb)
  183. {
  184. struct sdvo_device_mapping *p_mapping;
  185. struct bdb_general_definitions *p_defs;
  186. struct child_device_config *p_child;
  187. int i, child_device_num, count;
  188. u16 block_size, *block_ptr;
  189. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  190. if (!p_defs) {
  191. DRM_DEBUG("No general definition block is found\n");
  192. return;
  193. }
  194. /* judge whether the size of child device meets the requirements.
  195. * If the child device size obtained from general definition block
  196. * is different with sizeof(struct child_device_config), skip the
  197. * parsing of sdvo device info
  198. */
  199. if (p_defs->child_dev_size != sizeof(*p_child)) {
  200. /* different child dev size . Ignore it */
  201. DRM_DEBUG("different child size is found. Invalid.\n");
  202. return;
  203. }
  204. /* get the block size of general definitions */
  205. block_ptr = (u16 *)((char *)p_defs - 2);
  206. block_size = *block_ptr;
  207. /* get the number of child device */
  208. child_device_num = (block_size - sizeof(*p_defs)) /
  209. sizeof(*p_child);
  210. count = 0;
  211. for (i = 0; i < child_device_num; i++) {
  212. p_child = &(p_defs->devices[i]);
  213. if (!p_child->device_type) {
  214. /* skip the device block if device type is invalid */
  215. continue;
  216. }
  217. if (p_child->slave_addr != SLAVE_ADDR1 &&
  218. p_child->slave_addr != SLAVE_ADDR2) {
  219. /*
  220. * If the slave address is neither 0x70 nor 0x72,
  221. * it is not a SDVO device. Skip it.
  222. */
  223. continue;
  224. }
  225. if (p_child->dvo_port != DEVICE_PORT_DVOB &&
  226. p_child->dvo_port != DEVICE_PORT_DVOC) {
  227. /* skip the incorrect SDVO port */
  228. DRM_DEBUG("Incorrect SDVO port. Skip it \n");
  229. continue;
  230. }
  231. DRM_DEBUG("the SDVO device with slave addr %2x is found on "
  232. "%s port\n",
  233. p_child->slave_addr,
  234. (p_child->dvo_port == DEVICE_PORT_DVOB) ?
  235. "SDVOB" : "SDVOC");
  236. p_mapping = &(dev_priv->sdvo_mappings[p_child->dvo_port - 1]);
  237. if (!p_mapping->initialized) {
  238. p_mapping->dvo_port = p_child->dvo_port;
  239. p_mapping->slave_addr = p_child->slave_addr;
  240. p_mapping->dvo_wiring = p_child->dvo_wiring;
  241. p_mapping->initialized = 1;
  242. } else {
  243. DRM_DEBUG("Maybe one SDVO port is shared by "
  244. "two SDVO device.\n");
  245. }
  246. if (p_child->slave2_addr) {
  247. /* Maybe this is a SDVO device with multiple inputs */
  248. /* And the mapping info is not added */
  249. DRM_DEBUG("there exists the slave2_addr. Maybe this "
  250. "is a SDVO device with multiple inputs.\n");
  251. }
  252. count++;
  253. }
  254. if (!count) {
  255. /* No SDVO device info is found */
  256. DRM_DEBUG("No SDVO device info is found in VBT\n");
  257. }
  258. return;
  259. }
  260. static void
  261. parse_driver_features(struct drm_i915_private *dev_priv,
  262. struct bdb_header *bdb)
  263. {
  264. struct drm_device *dev = dev_priv->dev;
  265. struct bdb_driver_features *driver;
  266. /* set default for chips without eDP */
  267. if (!SUPPORTS_EDP(dev)) {
  268. dev_priv->edp_support = 0;
  269. return;
  270. }
  271. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  272. if (driver && driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
  273. dev_priv->edp_support = 1;
  274. }
  275. /**
  276. * intel_init_bios - initialize VBIOS settings & find VBT
  277. * @dev: DRM device
  278. *
  279. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  280. * to appropriate values.
  281. *
  282. * VBT existence is a sanity check that is relied on by other i830_bios.c code.
  283. * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
  284. * feed an updated VBT back through that, compared to what we'll fetch using
  285. * this method of groping around in the BIOS data.
  286. *
  287. * Returns 0 on success, nonzero on failure.
  288. */
  289. bool
  290. intel_init_bios(struct drm_device *dev)
  291. {
  292. struct drm_i915_private *dev_priv = dev->dev_private;
  293. struct pci_dev *pdev = dev->pdev;
  294. struct vbt_header *vbt = NULL;
  295. struct bdb_header *bdb;
  296. u8 __iomem *bios;
  297. size_t size;
  298. int i;
  299. bios = pci_map_rom(pdev, &size);
  300. if (!bios)
  301. return -1;
  302. /* Scour memory looking for the VBT signature */
  303. for (i = 0; i + 4 < size; i++) {
  304. if (!memcmp(bios + i, "$VBT", 4)) {
  305. vbt = (struct vbt_header *)(bios + i);
  306. break;
  307. }
  308. }
  309. if (!vbt) {
  310. DRM_ERROR("VBT signature missing\n");
  311. pci_unmap_rom(pdev, bios);
  312. return -1;
  313. }
  314. bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
  315. /* Grab useful general definitions */
  316. parse_general_features(dev_priv, bdb);
  317. parse_lfp_panel_data(dev_priv, bdb);
  318. parse_sdvo_panel_data(dev_priv, bdb);
  319. parse_sdvo_device_mapping(dev_priv, bdb);
  320. parse_driver_features(dev_priv, bdb);
  321. pci_unmap_rom(pdev, bios);
  322. return 0;
  323. }