intel_bios.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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 u16
  57. get_blocksize(void *p)
  58. {
  59. u16 *block_ptr, block_size;
  60. block_ptr = (u16 *)((char *)p - 2);
  61. block_size = *block_ptr;
  62. return block_size;
  63. }
  64. static void
  65. fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
  66. struct lvds_dvo_timing *dvo_timing)
  67. {
  68. panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
  69. dvo_timing->hactive_lo;
  70. panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
  71. ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
  72. panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
  73. dvo_timing->hsync_pulse_width;
  74. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  75. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  76. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  77. dvo_timing->vactive_lo;
  78. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  79. dvo_timing->vsync_off;
  80. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  81. dvo_timing->vsync_pulse_width;
  82. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  83. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  84. panel_fixed_mode->clock = dvo_timing->clock * 10;
  85. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  86. /* Some VBTs have bogus h/vtotal values */
  87. if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
  88. panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
  89. if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
  90. panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
  91. drm_mode_set_name(panel_fixed_mode);
  92. }
  93. /* Try to find integrated panel data */
  94. static void
  95. parse_lfp_panel_data(struct drm_i915_private *dev_priv,
  96. struct bdb_header *bdb)
  97. {
  98. struct bdb_lvds_options *lvds_options;
  99. struct bdb_lvds_lfp_data *lvds_lfp_data;
  100. struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
  101. struct bdb_lvds_lfp_data_entry *entry;
  102. struct lvds_dvo_timing *dvo_timing;
  103. struct drm_display_mode *panel_fixed_mode;
  104. int lfp_data_size, dvo_timing_offset;
  105. int i, temp_downclock;
  106. struct drm_display_mode *temp_mode;
  107. /* Defaults if we can't find VBT info */
  108. dev_priv->lvds_dither = 0;
  109. dev_priv->lvds_vbt = 0;
  110. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  111. if (!lvds_options)
  112. return;
  113. dev_priv->lvds_dither = lvds_options->pixel_dither;
  114. if (lvds_options->panel_type == 0xff)
  115. return;
  116. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  117. if (!lvds_lfp_data)
  118. return;
  119. lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
  120. if (!lvds_lfp_data_ptrs)
  121. return;
  122. dev_priv->lvds_vbt = 1;
  123. lfp_data_size = lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
  124. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
  125. entry = (struct bdb_lvds_lfp_data_entry *)
  126. ((uint8_t *)lvds_lfp_data->data + (lfp_data_size *
  127. lvds_options->panel_type));
  128. dvo_timing_offset = lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
  129. lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
  130. /*
  131. * the size of fp_timing varies on the different platform.
  132. * So calculate the DVO timing relative offset in LVDS data
  133. * entry to get the DVO timing entry
  134. */
  135. dvo_timing = (struct lvds_dvo_timing *)
  136. ((unsigned char *)entry + dvo_timing_offset);
  137. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  138. fill_detail_timing_data(panel_fixed_mode, dvo_timing);
  139. dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;
  140. DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
  141. drm_mode_debug_printmodeline(panel_fixed_mode);
  142. temp_mode = kzalloc(sizeof(*temp_mode), GFP_KERNEL);
  143. temp_downclock = panel_fixed_mode->clock;
  144. /*
  145. * enumerate the LVDS panel timing info entry in VBT to check whether
  146. * the LVDS downclock is found.
  147. */
  148. for (i = 0; i < 16; i++) {
  149. entry = (struct bdb_lvds_lfp_data_entry *)
  150. ((uint8_t *)lvds_lfp_data->data + (lfp_data_size * i));
  151. dvo_timing = (struct lvds_dvo_timing *)
  152. ((unsigned char *)entry + dvo_timing_offset);
  153. fill_detail_timing_data(temp_mode, dvo_timing);
  154. if (temp_mode->hdisplay == panel_fixed_mode->hdisplay &&
  155. temp_mode->hsync_start == panel_fixed_mode->hsync_start &&
  156. temp_mode->hsync_end == panel_fixed_mode->hsync_end &&
  157. temp_mode->htotal == panel_fixed_mode->htotal &&
  158. temp_mode->vdisplay == panel_fixed_mode->vdisplay &&
  159. temp_mode->vsync_start == panel_fixed_mode->vsync_start &&
  160. temp_mode->vsync_end == panel_fixed_mode->vsync_end &&
  161. temp_mode->vtotal == panel_fixed_mode->vtotal &&
  162. temp_mode->clock < temp_downclock) {
  163. /*
  164. * downclock is already found. But we expect
  165. * to find the lower downclock.
  166. */
  167. temp_downclock = temp_mode->clock;
  168. }
  169. /* clear it to zero */
  170. memset(temp_mode, 0, sizeof(*temp_mode));
  171. }
  172. kfree(temp_mode);
  173. if (temp_downclock < panel_fixed_mode->clock) {
  174. dev_priv->lvds_downclock_avail = 1;
  175. dev_priv->lvds_downclock = temp_downclock;
  176. DRM_DEBUG_KMS("LVDS downclock is found in VBT. ",
  177. "Normal Clock %dKHz, downclock %dKHz\n",
  178. temp_downclock, panel_fixed_mode->clock);
  179. }
  180. return;
  181. }
  182. /* Try to find sdvo panel data */
  183. static void
  184. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  185. struct bdb_header *bdb)
  186. {
  187. struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  188. struct lvds_dvo_timing *dvo_timing;
  189. struct drm_display_mode *panel_fixed_mode;
  190. dev_priv->sdvo_lvds_vbt_mode = NULL;
  191. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  192. if (!sdvo_lvds_options)
  193. return;
  194. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  195. if (!dvo_timing)
  196. return;
  197. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  198. if (!panel_fixed_mode)
  199. return;
  200. fill_detail_timing_data(panel_fixed_mode,
  201. dvo_timing + sdvo_lvds_options->panel_type);
  202. dev_priv->sdvo_lvds_vbt_mode = panel_fixed_mode;
  203. return;
  204. }
  205. static void
  206. parse_general_features(struct drm_i915_private *dev_priv,
  207. struct bdb_header *bdb)
  208. {
  209. struct bdb_general_features *general;
  210. /* Set sensible defaults in case we can't find the general block */
  211. dev_priv->int_tv_support = 1;
  212. dev_priv->int_crt_support = 1;
  213. general = find_section(bdb, BDB_GENERAL_FEATURES);
  214. if (general) {
  215. dev_priv->int_tv_support = general->int_tv_support;
  216. dev_priv->int_crt_support = general->int_crt_support;
  217. dev_priv->lvds_use_ssc = general->enable_ssc;
  218. if (dev_priv->lvds_use_ssc) {
  219. if (IS_I85X(dev_priv->dev))
  220. dev_priv->lvds_ssc_freq =
  221. general->ssc_freq ? 66 : 48;
  222. else if (IS_IRONLAKE(dev_priv->dev))
  223. dev_priv->lvds_ssc_freq =
  224. general->ssc_freq ? 100 : 120;
  225. else
  226. dev_priv->lvds_ssc_freq =
  227. general->ssc_freq ? 100 : 96;
  228. }
  229. }
  230. }
  231. static void
  232. parse_general_definitions(struct drm_i915_private *dev_priv,
  233. struct bdb_header *bdb)
  234. {
  235. struct bdb_general_definitions *general;
  236. const int crt_bus_map_table[] = {
  237. GPIOB,
  238. GPIOA,
  239. GPIOC,
  240. GPIOD,
  241. GPIOE,
  242. GPIOF,
  243. };
  244. general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  245. if (general) {
  246. u16 block_size = get_blocksize(general);
  247. if (block_size >= sizeof(*general)) {
  248. int bus_pin = general->crt_ddc_gmbus_pin;
  249. DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
  250. if ((bus_pin >= 1) && (bus_pin <= 6)) {
  251. dev_priv->crt_ddc_bus =
  252. crt_bus_map_table[bus_pin-1];
  253. }
  254. } else {
  255. DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
  256. block_size);
  257. }
  258. }
  259. }
  260. static void
  261. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  262. struct bdb_header *bdb)
  263. {
  264. struct sdvo_device_mapping *p_mapping;
  265. struct bdb_general_definitions *p_defs;
  266. struct child_device_config *p_child;
  267. int i, child_device_num, count;
  268. u16 block_size;
  269. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  270. if (!p_defs) {
  271. DRM_DEBUG_KMS("No general definition block is found\n");
  272. return;
  273. }
  274. /* judge whether the size of child device meets the requirements.
  275. * If the child device size obtained from general definition block
  276. * is different with sizeof(struct child_device_config), skip the
  277. * parsing of sdvo device info
  278. */
  279. if (p_defs->child_dev_size != sizeof(*p_child)) {
  280. /* different child dev size . Ignore it */
  281. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  282. return;
  283. }
  284. /* get the block size of general definitions */
  285. block_size = get_blocksize(p_defs);
  286. /* get the number of child device */
  287. child_device_num = (block_size - sizeof(*p_defs)) /
  288. sizeof(*p_child);
  289. count = 0;
  290. for (i = 0; i < child_device_num; i++) {
  291. p_child = &(p_defs->devices[i]);
  292. if (!p_child->device_type) {
  293. /* skip the device block if device type is invalid */
  294. continue;
  295. }
  296. if (p_child->slave_addr != SLAVE_ADDR1 &&
  297. p_child->slave_addr != SLAVE_ADDR2) {
  298. /*
  299. * If the slave address is neither 0x70 nor 0x72,
  300. * it is not a SDVO device. Skip it.
  301. */
  302. continue;
  303. }
  304. if (p_child->dvo_port != DEVICE_PORT_DVOB &&
  305. p_child->dvo_port != DEVICE_PORT_DVOC) {
  306. /* skip the incorrect SDVO port */
  307. DRM_DEBUG_KMS("Incorrect SDVO port. Skip it \n");
  308. continue;
  309. }
  310. DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
  311. " %s port\n",
  312. p_child->slave_addr,
  313. (p_child->dvo_port == DEVICE_PORT_DVOB) ?
  314. "SDVOB" : "SDVOC");
  315. p_mapping = &(dev_priv->sdvo_mappings[p_child->dvo_port - 1]);
  316. if (!p_mapping->initialized) {
  317. p_mapping->dvo_port = p_child->dvo_port;
  318. p_mapping->slave_addr = p_child->slave_addr;
  319. p_mapping->dvo_wiring = p_child->dvo_wiring;
  320. p_mapping->initialized = 1;
  321. } else {
  322. DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
  323. "two SDVO device.\n");
  324. }
  325. if (p_child->slave2_addr) {
  326. /* Maybe this is a SDVO device with multiple inputs */
  327. /* And the mapping info is not added */
  328. DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
  329. " is a SDVO device with multiple inputs.\n");
  330. }
  331. count++;
  332. }
  333. if (!count) {
  334. /* No SDVO device info is found */
  335. DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
  336. }
  337. return;
  338. }
  339. static void
  340. parse_driver_features(struct drm_i915_private *dev_priv,
  341. struct bdb_header *bdb)
  342. {
  343. struct drm_device *dev = dev_priv->dev;
  344. struct bdb_driver_features *driver;
  345. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  346. if (!driver)
  347. return;
  348. if (driver && SUPPORTS_EDP(dev) &&
  349. driver->lvds_config == BDB_DRIVER_FEATURE_EDP) {
  350. dev_priv->edp_support = 1;
  351. } else {
  352. dev_priv->edp_support = 0;
  353. }
  354. if (driver && driver->dual_frequency)
  355. dev_priv->render_reclock_avail = true;
  356. }
  357. static void
  358. parse_device_mapping(struct drm_i915_private *dev_priv,
  359. struct bdb_header *bdb)
  360. {
  361. struct bdb_general_definitions *p_defs;
  362. struct child_device_config *p_child, *child_dev_ptr;
  363. int i, child_device_num, count;
  364. u16 block_size;
  365. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  366. if (!p_defs) {
  367. DRM_DEBUG_KMS("No general definition block is found\n");
  368. return;
  369. }
  370. /* judge whether the size of child device meets the requirements.
  371. * If the child device size obtained from general definition block
  372. * is different with sizeof(struct child_device_config), skip the
  373. * parsing of sdvo device info
  374. */
  375. if (p_defs->child_dev_size != sizeof(*p_child)) {
  376. /* different child dev size . Ignore it */
  377. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  378. return;
  379. }
  380. /* get the block size of general definitions */
  381. block_size = get_blocksize(p_defs);
  382. /* get the number of child device */
  383. child_device_num = (block_size - sizeof(*p_defs)) /
  384. sizeof(*p_child);
  385. count = 0;
  386. /* get the number of child device that is present */
  387. for (i = 0; i < child_device_num; i++) {
  388. p_child = &(p_defs->devices[i]);
  389. if (!p_child->device_type) {
  390. /* skip the device block if device type is invalid */
  391. continue;
  392. }
  393. count++;
  394. }
  395. if (!count) {
  396. DRM_DEBUG_KMS("no child dev is parsed from VBT \n");
  397. return;
  398. }
  399. dev_priv->child_dev = kzalloc(sizeof(*p_child) * count, GFP_KERNEL);
  400. if (!dev_priv->child_dev) {
  401. DRM_DEBUG_KMS("No memory space for child device\n");
  402. return;
  403. }
  404. dev_priv->child_dev_num = count;
  405. count = 0;
  406. for (i = 0; i < child_device_num; i++) {
  407. p_child = &(p_defs->devices[i]);
  408. if (!p_child->device_type) {
  409. /* skip the device block if device type is invalid */
  410. continue;
  411. }
  412. child_dev_ptr = dev_priv->child_dev + count;
  413. count++;
  414. memcpy((void *)child_dev_ptr, (void *)p_child,
  415. sizeof(*p_child));
  416. }
  417. return;
  418. }
  419. /**
  420. * intel_init_bios - initialize VBIOS settings & find VBT
  421. * @dev: DRM device
  422. *
  423. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  424. * to appropriate values.
  425. *
  426. * VBT existence is a sanity check that is relied on by other i830_bios.c code.
  427. * Note that it would be better to use a BIOS call to get the VBT, as BIOSes may
  428. * feed an updated VBT back through that, compared to what we'll fetch using
  429. * this method of groping around in the BIOS data.
  430. *
  431. * Returns 0 on success, nonzero on failure.
  432. */
  433. bool
  434. intel_init_bios(struct drm_device *dev)
  435. {
  436. struct drm_i915_private *dev_priv = dev->dev_private;
  437. struct pci_dev *pdev = dev->pdev;
  438. struct vbt_header *vbt = NULL;
  439. struct bdb_header *bdb;
  440. u8 __iomem *bios;
  441. size_t size;
  442. int i;
  443. bios = pci_map_rom(pdev, &size);
  444. if (!bios)
  445. return -1;
  446. /* Scour memory looking for the VBT signature */
  447. for (i = 0; i + 4 < size; i++) {
  448. if (!memcmp(bios + i, "$VBT", 4)) {
  449. vbt = (struct vbt_header *)(bios + i);
  450. break;
  451. }
  452. }
  453. if (!vbt) {
  454. DRM_ERROR("VBT signature missing\n");
  455. pci_unmap_rom(pdev, bios);
  456. return -1;
  457. }
  458. bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
  459. /* Grab useful general definitions */
  460. parse_general_features(dev_priv, bdb);
  461. parse_general_definitions(dev_priv, bdb);
  462. parse_lfp_panel_data(dev_priv, bdb);
  463. parse_sdvo_panel_data(dev_priv, bdb);
  464. parse_sdvo_device_mapping(dev_priv, bdb);
  465. parse_device_mapping(dev_priv, bdb);
  466. parse_driver_features(dev_priv, bdb);
  467. pci_unmap_rom(pdev, bios);
  468. return 0;
  469. }