intel_bios.c 19 KB

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