intel_bios.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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 <drm/drm_dp_helper.h>
  28. #include "drmP.h"
  29. #include "drm.h"
  30. #include "i915_drm.h"
  31. #include "i915_drv.h"
  32. #include "intel_bios.h"
  33. #define SLAVE_ADDR1 0x70
  34. #define SLAVE_ADDR2 0x72
  35. static int panel_type;
  36. static void *
  37. find_section(struct bdb_header *bdb, int section_id)
  38. {
  39. u8 *base = (u8 *)bdb;
  40. int index = 0;
  41. u16 total, current_size;
  42. u8 current_id;
  43. /* skip to first section */
  44. index += bdb->header_size;
  45. total = bdb->bdb_size;
  46. /* walk the sections looking for section_id */
  47. while (index < total) {
  48. current_id = *(base + index);
  49. index++;
  50. current_size = *((u16 *)(base + index));
  51. index += 2;
  52. if (current_id == section_id)
  53. return base + index;
  54. index += current_size;
  55. }
  56. return NULL;
  57. }
  58. static u16
  59. get_blocksize(void *p)
  60. {
  61. u16 *block_ptr, block_size;
  62. block_ptr = (u16 *)((char *)p - 2);
  63. block_size = *block_ptr;
  64. return block_size;
  65. }
  66. static void
  67. fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
  68. struct lvds_dvo_timing *dvo_timing)
  69. {
  70. panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
  71. dvo_timing->hactive_lo;
  72. panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
  73. ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
  74. panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
  75. dvo_timing->hsync_pulse_width;
  76. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  77. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  78. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  79. dvo_timing->vactive_lo;
  80. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  81. dvo_timing->vsync_off;
  82. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  83. dvo_timing->vsync_pulse_width;
  84. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  85. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  86. panel_fixed_mode->clock = dvo_timing->clock * 10;
  87. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  88. if (dvo_timing->hsync_positive)
  89. panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
  90. else
  91. panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
  92. if (dvo_timing->vsync_positive)
  93. panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
  94. else
  95. panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
  96. /* Some VBTs have bogus h/vtotal values */
  97. if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
  98. panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
  99. if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
  100. panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
  101. drm_mode_set_name(panel_fixed_mode);
  102. }
  103. /* Try to find integrated panel data */
  104. static void
  105. parse_lfp_panel_data(struct drm_i915_private *dev_priv,
  106. struct bdb_header *bdb)
  107. {
  108. struct bdb_lvds_options *lvds_options;
  109. struct bdb_lvds_lfp_data *lvds_lfp_data;
  110. struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
  111. struct bdb_lvds_lfp_data_entry *entry;
  112. struct lvds_dvo_timing *dvo_timing;
  113. struct drm_display_mode *panel_fixed_mode;
  114. int lfp_data_size, dvo_timing_offset;
  115. int i, temp_downclock;
  116. struct drm_display_mode *temp_mode;
  117. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  118. if (!lvds_options)
  119. return;
  120. dev_priv->lvds_dither = lvds_options->pixel_dither;
  121. if (lvds_options->panel_type == 0xff)
  122. return;
  123. panel_type = lvds_options->panel_type;
  124. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  125. if (!lvds_lfp_data)
  126. return;
  127. lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
  128. if (!lvds_lfp_data_ptrs)
  129. return;
  130. dev_priv->lvds_vbt = 1;
  131. lfp_data_size = lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
  132. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
  133. entry = (struct bdb_lvds_lfp_data_entry *)
  134. ((uint8_t *)lvds_lfp_data->data + (lfp_data_size *
  135. lvds_options->panel_type));
  136. dvo_timing_offset = lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
  137. lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
  138. /*
  139. * the size of fp_timing varies on the different platform.
  140. * So calculate the DVO timing relative offset in LVDS data
  141. * entry to get the DVO timing entry
  142. */
  143. dvo_timing = (struct lvds_dvo_timing *)
  144. ((unsigned char *)entry + dvo_timing_offset);
  145. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  146. if (!panel_fixed_mode)
  147. return;
  148. fill_detail_timing_data(panel_fixed_mode, dvo_timing);
  149. dev_priv->lfp_lvds_vbt_mode = panel_fixed_mode;
  150. DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
  151. drm_mode_debug_printmodeline(panel_fixed_mode);
  152. temp_mode = kzalloc(sizeof(*temp_mode), GFP_KERNEL);
  153. temp_downclock = panel_fixed_mode->clock;
  154. /*
  155. * enumerate the LVDS panel timing info entry in VBT to check whether
  156. * the LVDS downclock is found.
  157. */
  158. for (i = 0; i < 16; i++) {
  159. entry = (struct bdb_lvds_lfp_data_entry *)
  160. ((uint8_t *)lvds_lfp_data->data + (lfp_data_size * i));
  161. dvo_timing = (struct lvds_dvo_timing *)
  162. ((unsigned char *)entry + dvo_timing_offset);
  163. fill_detail_timing_data(temp_mode, dvo_timing);
  164. if (temp_mode->hdisplay == panel_fixed_mode->hdisplay &&
  165. temp_mode->hsync_start == panel_fixed_mode->hsync_start &&
  166. temp_mode->hsync_end == panel_fixed_mode->hsync_end &&
  167. temp_mode->htotal == panel_fixed_mode->htotal &&
  168. temp_mode->vdisplay == panel_fixed_mode->vdisplay &&
  169. temp_mode->vsync_start == panel_fixed_mode->vsync_start &&
  170. temp_mode->vsync_end == panel_fixed_mode->vsync_end &&
  171. temp_mode->vtotal == panel_fixed_mode->vtotal &&
  172. temp_mode->clock < temp_downclock) {
  173. /*
  174. * downclock is already found. But we expect
  175. * to find the lower downclock.
  176. */
  177. temp_downclock = temp_mode->clock;
  178. }
  179. /* clear it to zero */
  180. memset(temp_mode, 0, sizeof(*temp_mode));
  181. }
  182. kfree(temp_mode);
  183. if (temp_downclock < panel_fixed_mode->clock &&
  184. i915_lvds_downclock) {
  185. dev_priv->lvds_downclock_avail = 1;
  186. dev_priv->lvds_downclock = temp_downclock;
  187. DRM_DEBUG_KMS("LVDS downclock is found in VBT. ",
  188. "Normal Clock %dKHz, downclock %dKHz\n",
  189. temp_downclock, panel_fixed_mode->clock);
  190. }
  191. return;
  192. }
  193. /* Try to find sdvo panel data */
  194. static void
  195. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  196. struct bdb_header *bdb)
  197. {
  198. struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  199. struct lvds_dvo_timing *dvo_timing;
  200. struct drm_display_mode *panel_fixed_mode;
  201. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  202. if (!sdvo_lvds_options)
  203. return;
  204. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  205. if (!dvo_timing)
  206. return;
  207. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  208. if (!panel_fixed_mode)
  209. return;
  210. fill_detail_timing_data(panel_fixed_mode,
  211. dvo_timing + sdvo_lvds_options->panel_type);
  212. dev_priv->sdvo_lvds_vbt_mode = panel_fixed_mode;
  213. return;
  214. }
  215. static void
  216. parse_general_features(struct drm_i915_private *dev_priv,
  217. struct bdb_header *bdb)
  218. {
  219. struct drm_device *dev = dev_priv->dev;
  220. struct bdb_general_features *general;
  221. general = find_section(bdb, BDB_GENERAL_FEATURES);
  222. if (general) {
  223. dev_priv->int_tv_support = general->int_tv_support;
  224. dev_priv->int_crt_support = general->int_crt_support;
  225. dev_priv->lvds_use_ssc = general->enable_ssc;
  226. if (dev_priv->lvds_use_ssc) {
  227. if (IS_I85X(dev))
  228. dev_priv->lvds_ssc_freq =
  229. general->ssc_freq ? 66 : 48;
  230. else if (IS_GEN5(dev) || IS_GEN6(dev))
  231. dev_priv->lvds_ssc_freq =
  232. general->ssc_freq ? 100 : 120;
  233. else
  234. dev_priv->lvds_ssc_freq =
  235. general->ssc_freq ? 100 : 96;
  236. }
  237. }
  238. }
  239. static void
  240. parse_general_definitions(struct drm_i915_private *dev_priv,
  241. struct bdb_header *bdb)
  242. {
  243. struct bdb_general_definitions *general;
  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_pin = bus_pin;
  252. } else {
  253. DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
  254. block_size);
  255. }
  256. }
  257. }
  258. static void
  259. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  260. struct bdb_header *bdb)
  261. {
  262. struct sdvo_device_mapping *p_mapping;
  263. struct bdb_general_definitions *p_defs;
  264. struct child_device_config *p_child;
  265. int i, child_device_num, count;
  266. u16 block_size;
  267. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  268. if (!p_defs) {
  269. DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
  270. return;
  271. }
  272. /* judge whether the size of child device meets the requirements.
  273. * If the child device size obtained from general definition block
  274. * is different with sizeof(struct child_device_config), skip the
  275. * parsing of sdvo device info
  276. */
  277. if (p_defs->child_dev_size != sizeof(*p_child)) {
  278. /* different child dev size . Ignore it */
  279. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  280. return;
  281. }
  282. /* get the block size of general definitions */
  283. block_size = get_blocksize(p_defs);
  284. /* get the number of child device */
  285. child_device_num = (block_size - sizeof(*p_defs)) /
  286. sizeof(*p_child);
  287. count = 0;
  288. for (i = 0; i < child_device_num; i++) {
  289. p_child = &(p_defs->devices[i]);
  290. if (!p_child->device_type) {
  291. /* skip the device block if device type is invalid */
  292. continue;
  293. }
  294. if (p_child->slave_addr != SLAVE_ADDR1 &&
  295. p_child->slave_addr != SLAVE_ADDR2) {
  296. /*
  297. * If the slave address is neither 0x70 nor 0x72,
  298. * it is not a SDVO device. Skip it.
  299. */
  300. continue;
  301. }
  302. if (p_child->dvo_port != DEVICE_PORT_DVOB &&
  303. p_child->dvo_port != DEVICE_PORT_DVOC) {
  304. /* skip the incorrect SDVO port */
  305. DRM_DEBUG_KMS("Incorrect SDVO port. Skip it \n");
  306. continue;
  307. }
  308. DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
  309. " %s port\n",
  310. p_child->slave_addr,
  311. (p_child->dvo_port == DEVICE_PORT_DVOB) ?
  312. "SDVOB" : "SDVOC");
  313. p_mapping = &(dev_priv->sdvo_mappings[p_child->dvo_port - 1]);
  314. if (!p_mapping->initialized) {
  315. p_mapping->dvo_port = p_child->dvo_port;
  316. p_mapping->slave_addr = p_child->slave_addr;
  317. p_mapping->dvo_wiring = p_child->dvo_wiring;
  318. p_mapping->ddc_pin = p_child->ddc_pin;
  319. p_mapping->i2c_pin = p_child->i2c_pin;
  320. p_mapping->i2c_speed = p_child->i2c_speed;
  321. p_mapping->initialized = 1;
  322. DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d, i2c_speed=%d\n",
  323. p_mapping->dvo_port,
  324. p_mapping->slave_addr,
  325. p_mapping->dvo_wiring,
  326. p_mapping->ddc_pin,
  327. p_mapping->i2c_pin,
  328. p_mapping->i2c_speed);
  329. } else {
  330. DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
  331. "two SDVO device.\n");
  332. }
  333. if (p_child->slave2_addr) {
  334. /* Maybe this is a SDVO device with multiple inputs */
  335. /* And the mapping info is not added */
  336. DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
  337. " is a SDVO device with multiple inputs.\n");
  338. }
  339. count++;
  340. }
  341. if (!count) {
  342. /* No SDVO device info is found */
  343. DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
  344. }
  345. return;
  346. }
  347. static void
  348. parse_driver_features(struct drm_i915_private *dev_priv,
  349. struct bdb_header *bdb)
  350. {
  351. struct drm_device *dev = dev_priv->dev;
  352. struct bdb_driver_features *driver;
  353. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  354. if (!driver)
  355. return;
  356. if (SUPPORTS_EDP(dev) &&
  357. driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
  358. dev_priv->edp.support = 1;
  359. if (driver->dual_frequency)
  360. dev_priv->render_reclock_avail = true;
  361. }
  362. static void
  363. parse_edp(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  364. {
  365. struct bdb_edp *edp;
  366. struct edp_power_seq *edp_pps;
  367. struct edp_link_params *edp_link_params;
  368. edp = find_section(bdb, BDB_EDP);
  369. if (!edp) {
  370. if (SUPPORTS_EDP(dev_priv->dev) && dev_priv->edp.support) {
  371. DRM_DEBUG_KMS("No eDP BDB found but eDP panel "
  372. "supported, assume %dbpp panel color "
  373. "depth.\n",
  374. dev_priv->edp.bpp);
  375. }
  376. return;
  377. }
  378. switch ((edp->color_depth >> (panel_type * 2)) & 3) {
  379. case EDP_18BPP:
  380. dev_priv->edp.bpp = 18;
  381. break;
  382. case EDP_24BPP:
  383. dev_priv->edp.bpp = 24;
  384. break;
  385. case EDP_30BPP:
  386. dev_priv->edp.bpp = 30;
  387. break;
  388. }
  389. /* Get the eDP sequencing and link info */
  390. edp_pps = &edp->power_seqs[panel_type];
  391. edp_link_params = &edp->link_params[panel_type];
  392. dev_priv->edp.pps = *edp_pps;
  393. dev_priv->edp.rate = edp_link_params->rate ? DP_LINK_BW_2_7 :
  394. DP_LINK_BW_1_62;
  395. switch (edp_link_params->lanes) {
  396. case 0:
  397. dev_priv->edp.lanes = 1;
  398. break;
  399. case 1:
  400. dev_priv->edp.lanes = 2;
  401. break;
  402. case 3:
  403. default:
  404. dev_priv->edp.lanes = 4;
  405. break;
  406. }
  407. switch (edp_link_params->preemphasis) {
  408. case 0:
  409. dev_priv->edp.preemphasis = DP_TRAIN_PRE_EMPHASIS_0;
  410. break;
  411. case 1:
  412. dev_priv->edp.preemphasis = DP_TRAIN_PRE_EMPHASIS_3_5;
  413. break;
  414. case 2:
  415. dev_priv->edp.preemphasis = DP_TRAIN_PRE_EMPHASIS_6;
  416. break;
  417. case 3:
  418. dev_priv->edp.preemphasis = DP_TRAIN_PRE_EMPHASIS_9_5;
  419. break;
  420. }
  421. switch (edp_link_params->vswing) {
  422. case 0:
  423. dev_priv->edp.vswing = DP_TRAIN_VOLTAGE_SWING_400;
  424. break;
  425. case 1:
  426. dev_priv->edp.vswing = DP_TRAIN_VOLTAGE_SWING_600;
  427. break;
  428. case 2:
  429. dev_priv->edp.vswing = DP_TRAIN_VOLTAGE_SWING_800;
  430. break;
  431. case 3:
  432. dev_priv->edp.vswing = DP_TRAIN_VOLTAGE_SWING_1200;
  433. break;
  434. }
  435. }
  436. static void
  437. parse_device_mapping(struct drm_i915_private *dev_priv,
  438. struct bdb_header *bdb)
  439. {
  440. struct bdb_general_definitions *p_defs;
  441. struct child_device_config *p_child, *child_dev_ptr;
  442. int i, child_device_num, count;
  443. u16 block_size;
  444. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  445. if (!p_defs) {
  446. DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
  447. return;
  448. }
  449. /* judge whether the size of child device meets the requirements.
  450. * If the child device size obtained from general definition block
  451. * is different with sizeof(struct child_device_config), skip the
  452. * parsing of sdvo device info
  453. */
  454. if (p_defs->child_dev_size != sizeof(*p_child)) {
  455. /* different child dev size . Ignore it */
  456. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  457. return;
  458. }
  459. /* get the block size of general definitions */
  460. block_size = get_blocksize(p_defs);
  461. /* get the number of child device */
  462. child_device_num = (block_size - sizeof(*p_defs)) /
  463. sizeof(*p_child);
  464. count = 0;
  465. /* get the number of child device that is present */
  466. for (i = 0; i < child_device_num; i++) {
  467. p_child = &(p_defs->devices[i]);
  468. if (!p_child->device_type) {
  469. /* skip the device block if device type is invalid */
  470. continue;
  471. }
  472. count++;
  473. }
  474. if (!count) {
  475. DRM_DEBUG_KMS("no child dev is parsed from VBT \n");
  476. return;
  477. }
  478. dev_priv->child_dev = kzalloc(sizeof(*p_child) * count, GFP_KERNEL);
  479. if (!dev_priv->child_dev) {
  480. DRM_DEBUG_KMS("No memory space for child device\n");
  481. return;
  482. }
  483. dev_priv->child_dev_num = count;
  484. count = 0;
  485. for (i = 0; i < child_device_num; i++) {
  486. p_child = &(p_defs->devices[i]);
  487. if (!p_child->device_type) {
  488. /* skip the device block if device type is invalid */
  489. continue;
  490. }
  491. child_dev_ptr = dev_priv->child_dev + count;
  492. count++;
  493. memcpy((void *)child_dev_ptr, (void *)p_child,
  494. sizeof(*p_child));
  495. }
  496. return;
  497. }
  498. static void
  499. init_vbt_defaults(struct drm_i915_private *dev_priv)
  500. {
  501. dev_priv->crt_ddc_pin = GMBUS_PORT_VGADDC;
  502. /* LFP panel data */
  503. dev_priv->lvds_dither = 1;
  504. dev_priv->lvds_vbt = 0;
  505. /* SDVO panel data */
  506. dev_priv->sdvo_lvds_vbt_mode = NULL;
  507. /* general features */
  508. dev_priv->int_tv_support = 1;
  509. dev_priv->int_crt_support = 1;
  510. dev_priv->lvds_use_ssc = 0;
  511. /* eDP data */
  512. dev_priv->edp.bpp = 18;
  513. }
  514. /**
  515. * intel_parse_bios - find VBT and initialize settings from the BIOS
  516. * @dev: DRM device
  517. *
  518. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  519. * to appropriate values.
  520. *
  521. * Returns 0 on success, nonzero on failure.
  522. */
  523. bool
  524. intel_parse_bios(struct drm_device *dev)
  525. {
  526. struct drm_i915_private *dev_priv = dev->dev_private;
  527. struct pci_dev *pdev = dev->pdev;
  528. struct bdb_header *bdb = NULL;
  529. u8 __iomem *bios = NULL;
  530. init_vbt_defaults(dev_priv);
  531. /* XXX Should this validation be moved to intel_opregion.c? */
  532. if (dev_priv->opregion.vbt) {
  533. struct vbt_header *vbt = dev_priv->opregion.vbt;
  534. if (memcmp(vbt->signature, "$VBT", 4) == 0) {
  535. DRM_DEBUG_DRIVER("Using VBT from OpRegion: %20s\n",
  536. vbt->signature);
  537. bdb = (struct bdb_header *)((char *)vbt + vbt->bdb_offset);
  538. } else
  539. dev_priv->opregion.vbt = NULL;
  540. }
  541. if (bdb == NULL) {
  542. struct vbt_header *vbt = NULL;
  543. size_t size;
  544. int i;
  545. bios = pci_map_rom(pdev, &size);
  546. if (!bios)
  547. return -1;
  548. /* Scour memory looking for the VBT signature */
  549. for (i = 0; i + 4 < size; i++) {
  550. if (!memcmp(bios + i, "$VBT", 4)) {
  551. vbt = (struct vbt_header *)(bios + i);
  552. break;
  553. }
  554. }
  555. if (!vbt) {
  556. DRM_ERROR("VBT signature missing\n");
  557. pci_unmap_rom(pdev, bios);
  558. return -1;
  559. }
  560. bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
  561. }
  562. /* Grab useful general definitions */
  563. parse_general_features(dev_priv, bdb);
  564. parse_general_definitions(dev_priv, bdb);
  565. parse_lfp_panel_data(dev_priv, bdb);
  566. parse_sdvo_panel_data(dev_priv, bdb);
  567. parse_sdvo_device_mapping(dev_priv, bdb);
  568. parse_device_mapping(dev_priv, bdb);
  569. parse_driver_features(dev_priv, bdb);
  570. parse_edp(dev_priv, bdb);
  571. if (bios)
  572. pci_unmap_rom(pdev, bios);
  573. return 0;
  574. }
  575. /* Ensure that vital registers have been initialised, even if the BIOS
  576. * is absent or just failing to do its job.
  577. */
  578. void intel_setup_bios(struct drm_device *dev)
  579. {
  580. struct drm_i915_private *dev_priv = dev->dev_private;
  581. /* Set the Panel Power On/Off timings if uninitialized. */
  582. if ((I915_READ(PP_ON_DELAYS) == 0) && (I915_READ(PP_OFF_DELAYS) == 0)) {
  583. /* Set T2 to 40ms and T5 to 200ms */
  584. I915_WRITE(PP_ON_DELAYS, 0x019007d0);
  585. /* Set T3 to 35ms and Tx to 200ms */
  586. I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);
  587. }
  588. }