intel_bios.c 20 KB

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