intel_bios.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  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 <drm/drmP.h>
  30. #include <drm/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 + 3 < total) {
  48. current_id = *(base + index);
  49. index++;
  50. current_size = *((u16 *)(base + index));
  51. index += 2;
  52. if (index + current_size > total)
  53. return NULL;
  54. if (current_id == section_id)
  55. return base + index;
  56. index += current_size;
  57. }
  58. return NULL;
  59. }
  60. static u16
  61. get_blocksize(void *p)
  62. {
  63. u16 *block_ptr, block_size;
  64. block_ptr = (u16 *)((char *)p - 2);
  65. block_size = *block_ptr;
  66. return block_size;
  67. }
  68. static void
  69. fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
  70. const struct lvds_dvo_timing *dvo_timing)
  71. {
  72. panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
  73. dvo_timing->hactive_lo;
  74. panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
  75. ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
  76. panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
  77. dvo_timing->hsync_pulse_width;
  78. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  79. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  80. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  81. dvo_timing->vactive_lo;
  82. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  83. dvo_timing->vsync_off;
  84. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  85. dvo_timing->vsync_pulse_width;
  86. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  87. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  88. panel_fixed_mode->clock = dvo_timing->clock * 10;
  89. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  90. if (dvo_timing->hsync_positive)
  91. panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
  92. else
  93. panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
  94. if (dvo_timing->vsync_positive)
  95. panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
  96. else
  97. panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
  98. /* Some VBTs have bogus h/vtotal values */
  99. if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
  100. panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
  101. if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
  102. panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
  103. drm_mode_set_name(panel_fixed_mode);
  104. }
  105. static bool
  106. lvds_dvo_timing_equal_size(const struct lvds_dvo_timing *a,
  107. const struct lvds_dvo_timing *b)
  108. {
  109. if (a->hactive_hi != b->hactive_hi ||
  110. a->hactive_lo != b->hactive_lo)
  111. return false;
  112. if (a->hsync_off_hi != b->hsync_off_hi ||
  113. a->hsync_off_lo != b->hsync_off_lo)
  114. return false;
  115. if (a->hsync_pulse_width != b->hsync_pulse_width)
  116. return false;
  117. if (a->hblank_hi != b->hblank_hi ||
  118. a->hblank_lo != b->hblank_lo)
  119. return false;
  120. if (a->vactive_hi != b->vactive_hi ||
  121. a->vactive_lo != b->vactive_lo)
  122. return false;
  123. if (a->vsync_off != b->vsync_off)
  124. return false;
  125. if (a->vsync_pulse_width != b->vsync_pulse_width)
  126. return false;
  127. if (a->vblank_hi != b->vblank_hi ||
  128. a->vblank_lo != b->vblank_lo)
  129. return false;
  130. return true;
  131. }
  132. static const struct lvds_dvo_timing *
  133. get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
  134. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
  135. int index)
  136. {
  137. /*
  138. * the size of fp_timing varies on the different platform.
  139. * So calculate the DVO timing relative offset in LVDS data
  140. * entry to get the DVO timing entry
  141. */
  142. int lfp_data_size =
  143. lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
  144. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
  145. int dvo_timing_offset =
  146. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
  147. lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
  148. char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
  149. return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
  150. }
  151. /* get lvds_fp_timing entry
  152. * this function may return NULL if the corresponding entry is invalid
  153. */
  154. static const struct lvds_fp_timing *
  155. get_lvds_fp_timing(const struct bdb_header *bdb,
  156. const struct bdb_lvds_lfp_data *data,
  157. const struct bdb_lvds_lfp_data_ptrs *ptrs,
  158. int index)
  159. {
  160. size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
  161. u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
  162. size_t ofs;
  163. if (index >= ARRAY_SIZE(ptrs->ptr))
  164. return NULL;
  165. ofs = ptrs->ptr[index].fp_timing_offset;
  166. if (ofs < data_ofs ||
  167. ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
  168. return NULL;
  169. return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
  170. }
  171. /* Try to find integrated panel data */
  172. static void
  173. parse_lfp_panel_data(struct drm_i915_private *dev_priv,
  174. struct bdb_header *bdb)
  175. {
  176. const struct bdb_lvds_options *lvds_options;
  177. const struct bdb_lvds_lfp_data *lvds_lfp_data;
  178. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
  179. const struct lvds_dvo_timing *panel_dvo_timing;
  180. const struct lvds_fp_timing *fp_timing;
  181. struct drm_display_mode *panel_fixed_mode;
  182. int i, downclock, drrs_mode;
  183. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  184. if (!lvds_options)
  185. return;
  186. dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
  187. if (lvds_options->panel_type == 0xff)
  188. return;
  189. panel_type = lvds_options->panel_type;
  190. drrs_mode = (lvds_options->dps_panel_type_bits
  191. >> (panel_type * 2)) & MODE_MASK;
  192. /*
  193. * VBT has static DRRS = 0 and seamless DRRS = 2.
  194. * The below piece of code is required to adjust vbt.drrs_type
  195. * to match the enum drrs_support_type.
  196. */
  197. switch (drrs_mode) {
  198. case 0:
  199. dev_priv->vbt.drrs_type = STATIC_DRRS_SUPPORT;
  200. DRM_DEBUG_KMS("DRRS supported mode is static\n");
  201. break;
  202. case 2:
  203. dev_priv->vbt.drrs_type = SEAMLESS_DRRS_SUPPORT;
  204. DRM_DEBUG_KMS("DRRS supported mode is seamless\n");
  205. break;
  206. default:
  207. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  208. DRM_DEBUG_KMS("DRRS not supported (VBT input)\n");
  209. break;
  210. }
  211. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  212. if (!lvds_lfp_data)
  213. return;
  214. lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
  215. if (!lvds_lfp_data_ptrs)
  216. return;
  217. dev_priv->vbt.lvds_vbt = 1;
  218. panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
  219. lvds_lfp_data_ptrs,
  220. lvds_options->panel_type);
  221. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  222. if (!panel_fixed_mode)
  223. return;
  224. fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
  225. dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
  226. DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
  227. drm_mode_debug_printmodeline(panel_fixed_mode);
  228. /*
  229. * Iterate over the LVDS panel timing info to find the lowest clock
  230. * for the native resolution.
  231. */
  232. downclock = panel_dvo_timing->clock;
  233. for (i = 0; i < 16; i++) {
  234. const struct lvds_dvo_timing *dvo_timing;
  235. dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
  236. lvds_lfp_data_ptrs,
  237. i);
  238. if (lvds_dvo_timing_equal_size(dvo_timing, panel_dvo_timing) &&
  239. dvo_timing->clock < downclock)
  240. downclock = dvo_timing->clock;
  241. }
  242. if (downclock < panel_dvo_timing->clock && i915.lvds_downclock) {
  243. dev_priv->lvds_downclock_avail = 1;
  244. dev_priv->lvds_downclock = downclock * 10;
  245. DRM_DEBUG_KMS("LVDS downclock is found in VBT. "
  246. "Normal Clock %dKHz, downclock %dKHz\n",
  247. panel_fixed_mode->clock, 10*downclock);
  248. }
  249. fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
  250. lvds_lfp_data_ptrs,
  251. lvds_options->panel_type);
  252. if (fp_timing) {
  253. /* check the resolution, just to be sure */
  254. if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
  255. fp_timing->y_res == panel_fixed_mode->vdisplay) {
  256. dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
  257. DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
  258. dev_priv->vbt.bios_lvds_val);
  259. }
  260. }
  261. }
  262. static void
  263. parse_lfp_backlight(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  264. {
  265. const struct bdb_lfp_backlight_data *backlight_data;
  266. const struct bdb_lfp_backlight_data_entry *entry;
  267. backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
  268. if (!backlight_data)
  269. return;
  270. if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
  271. DRM_DEBUG_KMS("Unsupported backlight data entry size %u\n",
  272. backlight_data->entry_size);
  273. return;
  274. }
  275. entry = &backlight_data->data[panel_type];
  276. dev_priv->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
  277. if (!dev_priv->vbt.backlight.present) {
  278. DRM_DEBUG_KMS("PWM backlight not present in VBT (type %u)\n",
  279. entry->type);
  280. return;
  281. }
  282. dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
  283. dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
  284. DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
  285. "active %s, min brightness %u, level %u\n",
  286. dev_priv->vbt.backlight.pwm_freq_hz,
  287. dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
  288. entry->min_brightness,
  289. backlight_data->level[panel_type]);
  290. }
  291. /* Try to find sdvo panel data */
  292. static void
  293. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  294. struct bdb_header *bdb)
  295. {
  296. struct lvds_dvo_timing *dvo_timing;
  297. struct drm_display_mode *panel_fixed_mode;
  298. int index;
  299. index = i915.vbt_sdvo_panel_type;
  300. if (index == -2) {
  301. DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
  302. return;
  303. }
  304. if (index == -1) {
  305. struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  306. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  307. if (!sdvo_lvds_options)
  308. return;
  309. index = sdvo_lvds_options->panel_type;
  310. }
  311. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  312. if (!dvo_timing)
  313. return;
  314. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  315. if (!panel_fixed_mode)
  316. return;
  317. fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
  318. dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
  319. DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
  320. drm_mode_debug_printmodeline(panel_fixed_mode);
  321. }
  322. static int intel_bios_ssc_frequency(struct drm_device *dev,
  323. bool alternate)
  324. {
  325. switch (INTEL_INFO(dev)->gen) {
  326. case 2:
  327. return alternate ? 66667 : 48000;
  328. case 3:
  329. case 4:
  330. return alternate ? 100000 : 96000;
  331. default:
  332. return alternate ? 100000 : 120000;
  333. }
  334. }
  335. static void
  336. parse_general_features(struct drm_i915_private *dev_priv,
  337. struct bdb_header *bdb)
  338. {
  339. struct drm_device *dev = dev_priv->dev;
  340. struct bdb_general_features *general;
  341. general = find_section(bdb, BDB_GENERAL_FEATURES);
  342. if (general) {
  343. dev_priv->vbt.int_tv_support = general->int_tv_support;
  344. dev_priv->vbt.int_crt_support = general->int_crt_support;
  345. dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
  346. dev_priv->vbt.lvds_ssc_freq =
  347. intel_bios_ssc_frequency(dev, general->ssc_freq);
  348. dev_priv->vbt.display_clock_mode = general->display_clock_mode;
  349. dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
  350. 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 fdi_rx_polarity_inverted %d\n",
  351. dev_priv->vbt.int_tv_support,
  352. dev_priv->vbt.int_crt_support,
  353. dev_priv->vbt.lvds_use_ssc,
  354. dev_priv->vbt.lvds_ssc_freq,
  355. dev_priv->vbt.display_clock_mode,
  356. dev_priv->vbt.fdi_rx_polarity_inverted);
  357. }
  358. }
  359. static void
  360. parse_general_definitions(struct drm_i915_private *dev_priv,
  361. struct bdb_header *bdb)
  362. {
  363. struct bdb_general_definitions *general;
  364. general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  365. if (general) {
  366. u16 block_size = get_blocksize(general);
  367. if (block_size >= sizeof(*general)) {
  368. int bus_pin = general->crt_ddc_gmbus_pin;
  369. DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
  370. if (intel_gmbus_is_port_valid(bus_pin))
  371. dev_priv->vbt.crt_ddc_pin = bus_pin;
  372. } else {
  373. DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
  374. block_size);
  375. }
  376. }
  377. }
  378. static void
  379. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  380. struct bdb_header *bdb)
  381. {
  382. struct sdvo_device_mapping *p_mapping;
  383. struct bdb_general_definitions *p_defs;
  384. union child_device_config *p_child;
  385. int i, child_device_num, count;
  386. u16 block_size;
  387. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  388. if (!p_defs) {
  389. DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
  390. return;
  391. }
  392. /* judge whether the size of child device meets the requirements.
  393. * If the child device size obtained from general definition block
  394. * is different with sizeof(struct child_device_config), skip the
  395. * parsing of sdvo device info
  396. */
  397. if (p_defs->child_dev_size != sizeof(*p_child)) {
  398. /* different child dev size . Ignore it */
  399. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  400. return;
  401. }
  402. /* get the block size of general definitions */
  403. block_size = get_blocksize(p_defs);
  404. /* get the number of child device */
  405. child_device_num = (block_size - sizeof(*p_defs)) /
  406. sizeof(*p_child);
  407. count = 0;
  408. for (i = 0; i < child_device_num; i++) {
  409. p_child = &(p_defs->devices[i]);
  410. if (!p_child->old.device_type) {
  411. /* skip the device block if device type is invalid */
  412. continue;
  413. }
  414. if (p_child->old.slave_addr != SLAVE_ADDR1 &&
  415. p_child->old.slave_addr != SLAVE_ADDR2) {
  416. /*
  417. * If the slave address is neither 0x70 nor 0x72,
  418. * it is not a SDVO device. Skip it.
  419. */
  420. continue;
  421. }
  422. if (p_child->old.dvo_port != DEVICE_PORT_DVOB &&
  423. p_child->old.dvo_port != DEVICE_PORT_DVOC) {
  424. /* skip the incorrect SDVO port */
  425. DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
  426. continue;
  427. }
  428. DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
  429. " %s port\n",
  430. p_child->old.slave_addr,
  431. (p_child->old.dvo_port == DEVICE_PORT_DVOB) ?
  432. "SDVOB" : "SDVOC");
  433. p_mapping = &(dev_priv->sdvo_mappings[p_child->old.dvo_port - 1]);
  434. if (!p_mapping->initialized) {
  435. p_mapping->dvo_port = p_child->old.dvo_port;
  436. p_mapping->slave_addr = p_child->old.slave_addr;
  437. p_mapping->dvo_wiring = p_child->old.dvo_wiring;
  438. p_mapping->ddc_pin = p_child->old.ddc_pin;
  439. p_mapping->i2c_pin = p_child->old.i2c_pin;
  440. p_mapping->initialized = 1;
  441. DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
  442. p_mapping->dvo_port,
  443. p_mapping->slave_addr,
  444. p_mapping->dvo_wiring,
  445. p_mapping->ddc_pin,
  446. p_mapping->i2c_pin);
  447. } else {
  448. DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
  449. "two SDVO device.\n");
  450. }
  451. if (p_child->old.slave2_addr) {
  452. /* Maybe this is a SDVO device with multiple inputs */
  453. /* And the mapping info is not added */
  454. DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
  455. " is a SDVO device with multiple inputs.\n");
  456. }
  457. count++;
  458. }
  459. if (!count) {
  460. /* No SDVO device info is found */
  461. DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
  462. }
  463. return;
  464. }
  465. static void
  466. parse_driver_features(struct drm_i915_private *dev_priv,
  467. struct bdb_header *bdb)
  468. {
  469. struct bdb_driver_features *driver;
  470. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  471. if (!driver)
  472. return;
  473. if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
  474. dev_priv->vbt.edp_support = 1;
  475. if (driver->dual_frequency)
  476. dev_priv->render_reclock_avail = true;
  477. DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
  478. /*
  479. * If DRRS is not supported, drrs_type has to be set to 0.
  480. * This is because, VBT is configured in such a way that
  481. * static DRRS is 0 and DRRS not supported is represented by
  482. * driver->drrs_enabled=false
  483. */
  484. if (!driver->drrs_enabled)
  485. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  486. }
  487. static void
  488. parse_edp(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  489. {
  490. struct bdb_edp *edp;
  491. struct edp_power_seq *edp_pps;
  492. struct edp_link_params *edp_link_params;
  493. edp = find_section(bdb, BDB_EDP);
  494. if (!edp) {
  495. if (dev_priv->vbt.edp_support)
  496. DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
  497. return;
  498. }
  499. switch ((edp->color_depth >> (panel_type * 2)) & 3) {
  500. case EDP_18BPP:
  501. dev_priv->vbt.edp_bpp = 18;
  502. break;
  503. case EDP_24BPP:
  504. dev_priv->vbt.edp_bpp = 24;
  505. break;
  506. case EDP_30BPP:
  507. dev_priv->vbt.edp_bpp = 30;
  508. break;
  509. }
  510. /* Get the eDP sequencing and link info */
  511. edp_pps = &edp->power_seqs[panel_type];
  512. edp_link_params = &edp->link_params[panel_type];
  513. dev_priv->vbt.edp_pps = *edp_pps;
  514. switch (edp_link_params->rate) {
  515. case EDP_RATE_1_62:
  516. dev_priv->vbt.edp_rate = DP_LINK_BW_1_62;
  517. break;
  518. case EDP_RATE_2_7:
  519. dev_priv->vbt.edp_rate = DP_LINK_BW_2_7;
  520. break;
  521. default:
  522. DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
  523. edp_link_params->rate);
  524. break;
  525. }
  526. switch (edp_link_params->lanes) {
  527. case EDP_LANE_1:
  528. dev_priv->vbt.edp_lanes = 1;
  529. break;
  530. case EDP_LANE_2:
  531. dev_priv->vbt.edp_lanes = 2;
  532. break;
  533. case EDP_LANE_4:
  534. dev_priv->vbt.edp_lanes = 4;
  535. break;
  536. default:
  537. DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
  538. edp_link_params->lanes);
  539. break;
  540. }
  541. switch (edp_link_params->preemphasis) {
  542. case EDP_PREEMPHASIS_NONE:
  543. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_0;
  544. break;
  545. case EDP_PREEMPHASIS_3_5dB:
  546. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_3_5;
  547. break;
  548. case EDP_PREEMPHASIS_6dB:
  549. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_6;
  550. break;
  551. case EDP_PREEMPHASIS_9_5dB:
  552. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_9_5;
  553. break;
  554. default:
  555. DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
  556. edp_link_params->preemphasis);
  557. break;
  558. }
  559. switch (edp_link_params->vswing) {
  560. case EDP_VSWING_0_4V:
  561. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_400;
  562. break;
  563. case EDP_VSWING_0_6V:
  564. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_600;
  565. break;
  566. case EDP_VSWING_0_8V:
  567. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_800;
  568. break;
  569. case EDP_VSWING_1_2V:
  570. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_1200;
  571. break;
  572. default:
  573. DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
  574. edp_link_params->vswing);
  575. break;
  576. }
  577. }
  578. static u8 *goto_next_sequence(u8 *data, int *size)
  579. {
  580. u16 len;
  581. int tmp = *size;
  582. if (--tmp < 0)
  583. return NULL;
  584. /* goto first element */
  585. data++;
  586. while (1) {
  587. switch (*data) {
  588. case MIPI_SEQ_ELEM_SEND_PKT:
  589. /*
  590. * skip by this element payload size
  591. * skip elem id, command flag and data type
  592. */
  593. tmp -= 5;
  594. if (tmp < 0)
  595. return NULL;
  596. data += 3;
  597. len = *((u16 *)data);
  598. tmp -= len;
  599. if (tmp < 0)
  600. return NULL;
  601. /* skip by len */
  602. data = data + 2 + len;
  603. break;
  604. case MIPI_SEQ_ELEM_DELAY:
  605. /* skip by elem id, and delay is 4 bytes */
  606. tmp -= 5;
  607. if (tmp < 0)
  608. return NULL;
  609. data += 5;
  610. break;
  611. case MIPI_SEQ_ELEM_GPIO:
  612. tmp -= 3;
  613. if (tmp < 0)
  614. return NULL;
  615. data += 3;
  616. break;
  617. default:
  618. DRM_ERROR("Unknown element\n");
  619. return NULL;
  620. }
  621. /* end of sequence ? */
  622. if (*data == 0)
  623. break;
  624. }
  625. /* goto next sequence or end of block byte */
  626. if (--tmp < 0)
  627. return NULL;
  628. data++;
  629. /* update amount of data left for the sequence block to be parsed */
  630. *size = tmp;
  631. return data;
  632. }
  633. static void
  634. parse_mipi(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  635. {
  636. struct bdb_mipi_config *start;
  637. struct bdb_mipi_sequence *sequence;
  638. struct mipi_config *config;
  639. struct mipi_pps_data *pps;
  640. u8 *data, *seq_data;
  641. int i, panel_id, seq_size;
  642. u16 block_size;
  643. /* parse MIPI blocks only if LFP type is MIPI */
  644. if (!dev_priv->vbt.has_mipi)
  645. return;
  646. /* Initialize this to undefined indicating no generic MIPI support */
  647. dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
  648. /* Block #40 is already parsed and panel_fixed_mode is
  649. * stored in dev_priv->lfp_lvds_vbt_mode
  650. * resuse this when needed
  651. */
  652. /* Parse #52 for panel index used from panel_type already
  653. * parsed
  654. */
  655. start = find_section(bdb, BDB_MIPI_CONFIG);
  656. if (!start) {
  657. DRM_DEBUG_KMS("No MIPI config BDB found");
  658. return;
  659. }
  660. DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
  661. panel_type);
  662. /*
  663. * get hold of the correct configuration block and pps data as per
  664. * the panel_type as index
  665. */
  666. config = &start->config[panel_type];
  667. pps = &start->pps[panel_type];
  668. /* store as of now full data. Trim when we realise all is not needed */
  669. dev_priv->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
  670. if (!dev_priv->vbt.dsi.config)
  671. return;
  672. dev_priv->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
  673. if (!dev_priv->vbt.dsi.pps) {
  674. kfree(dev_priv->vbt.dsi.config);
  675. return;
  676. }
  677. /* We have mandatory mipi config blocks. Initialize as generic panel */
  678. dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
  679. /* Check if we have sequence block as well */
  680. sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
  681. if (!sequence) {
  682. DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
  683. return;
  684. }
  685. DRM_DEBUG_DRIVER("Found MIPI sequence block\n");
  686. block_size = get_blocksize(sequence);
  687. /*
  688. * parse the sequence block for individual sequences
  689. */
  690. dev_priv->vbt.dsi.seq_version = sequence->version;
  691. seq_data = &sequence->data[0];
  692. /*
  693. * sequence block is variable length and hence we need to parse and
  694. * get the sequence data for specific panel id
  695. */
  696. for (i = 0; i < MAX_MIPI_CONFIGURATIONS; i++) {
  697. panel_id = *seq_data;
  698. seq_size = *((u16 *) (seq_data + 1));
  699. if (panel_id == panel_type)
  700. break;
  701. /* skip the sequence including seq header of 3 bytes */
  702. seq_data = seq_data + 3 + seq_size;
  703. if ((seq_data - &sequence->data[0]) > block_size) {
  704. DRM_ERROR("Sequence start is beyond sequence block size, corrupted sequence block\n");
  705. return;
  706. }
  707. }
  708. if (i == MAX_MIPI_CONFIGURATIONS) {
  709. DRM_ERROR("Sequence block detected but no valid configuration\n");
  710. return;
  711. }
  712. /* check if found sequence is completely within the sequence block
  713. * just being paranoid */
  714. if (seq_size > block_size) {
  715. DRM_ERROR("Corrupted sequence/size, bailing out\n");
  716. return;
  717. }
  718. /* skip the panel id(1 byte) and seq size(2 bytes) */
  719. dev_priv->vbt.dsi.data = kmemdup(seq_data + 3, seq_size, GFP_KERNEL);
  720. if (!dev_priv->vbt.dsi.data)
  721. return;
  722. /*
  723. * loop into the sequence data and split into multiple sequneces
  724. * There are only 5 types of sequences as of now
  725. */
  726. data = dev_priv->vbt.dsi.data;
  727. dev_priv->vbt.dsi.size = seq_size;
  728. /* two consecutive 0x00 indicate end of all sequences */
  729. while (1) {
  730. int seq_id = *data;
  731. if (MIPI_SEQ_MAX > seq_id && seq_id > MIPI_SEQ_UNDEFINED) {
  732. dev_priv->vbt.dsi.sequence[seq_id] = data;
  733. DRM_DEBUG_DRIVER("Found mipi sequence - %d\n", seq_id);
  734. } else {
  735. DRM_ERROR("undefined sequence\n");
  736. goto err;
  737. }
  738. /* partial parsing to skip elements */
  739. data = goto_next_sequence(data, &seq_size);
  740. if (data == NULL) {
  741. DRM_ERROR("Sequence elements going beyond block itself. Sequence block parsing failed\n");
  742. goto err;
  743. }
  744. if (*data == 0)
  745. break; /* end of sequence reached */
  746. }
  747. DRM_DEBUG_DRIVER("MIPI related vbt parsing complete\n");
  748. return;
  749. err:
  750. kfree(dev_priv->vbt.dsi.data);
  751. dev_priv->vbt.dsi.data = NULL;
  752. /* error during parsing so set all pointers to null
  753. * because of partial parsing */
  754. memset(dev_priv->vbt.dsi.sequence, 0, MIPI_SEQ_MAX);
  755. }
  756. static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
  757. struct bdb_header *bdb)
  758. {
  759. union child_device_config *it, *child = NULL;
  760. struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
  761. uint8_t hdmi_level_shift;
  762. int i, j;
  763. bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
  764. uint8_t aux_channel;
  765. /* Each DDI port can have more than one value on the "DVO Port" field,
  766. * so look for all the possible values for each port and abort if more
  767. * than one is found. */
  768. int dvo_ports[][2] = {
  769. {DVO_PORT_HDMIA, DVO_PORT_DPA},
  770. {DVO_PORT_HDMIB, DVO_PORT_DPB},
  771. {DVO_PORT_HDMIC, DVO_PORT_DPC},
  772. {DVO_PORT_HDMID, DVO_PORT_DPD},
  773. {DVO_PORT_CRT, -1 /* Port E can only be DVO_PORT_CRT */ },
  774. };
  775. /* Find the child device to use, abort if more than one found. */
  776. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  777. it = dev_priv->vbt.child_dev + i;
  778. for (j = 0; j < 2; j++) {
  779. if (dvo_ports[port][j] == -1)
  780. break;
  781. if (it->common.dvo_port == dvo_ports[port][j]) {
  782. if (child) {
  783. DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
  784. port_name(port));
  785. return;
  786. }
  787. child = it;
  788. }
  789. }
  790. }
  791. if (!child)
  792. return;
  793. aux_channel = child->raw[25];
  794. is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
  795. is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
  796. is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
  797. is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
  798. is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
  799. info->supports_dvi = is_dvi;
  800. info->supports_hdmi = is_hdmi;
  801. info->supports_dp = is_dp;
  802. DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
  803. port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
  804. if (is_edp && is_dvi)
  805. DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
  806. port_name(port));
  807. if (is_crt && port != PORT_E)
  808. DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
  809. if (is_crt && (is_dvi || is_dp))
  810. DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
  811. port_name(port));
  812. if (is_dvi && (port == PORT_A || port == PORT_E))
  813. DRM_DEBUG_KMS("Port %c is TMDS compabile\n", port_name(port));
  814. if (!is_dvi && !is_dp && !is_crt)
  815. DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
  816. port_name(port));
  817. if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
  818. DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
  819. if (is_dvi) {
  820. if (child->common.ddc_pin == 0x05 && port != PORT_B)
  821. DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
  822. if (child->common.ddc_pin == 0x04 && port != PORT_C)
  823. DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
  824. if (child->common.ddc_pin == 0x06 && port != PORT_D)
  825. DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
  826. }
  827. if (is_dp) {
  828. if (aux_channel == 0x40 && port != PORT_A)
  829. DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
  830. if (aux_channel == 0x10 && port != PORT_B)
  831. DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
  832. if (aux_channel == 0x20 && port != PORT_C)
  833. DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
  834. if (aux_channel == 0x30 && port != PORT_D)
  835. DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
  836. }
  837. if (bdb->version >= 158) {
  838. /* The VBT HDMI level shift values match the table we have. */
  839. hdmi_level_shift = child->raw[7] & 0xF;
  840. if (hdmi_level_shift < 0xC) {
  841. DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
  842. port_name(port),
  843. hdmi_level_shift);
  844. info->hdmi_level_shift = hdmi_level_shift;
  845. }
  846. }
  847. }
  848. static void parse_ddi_ports(struct drm_i915_private *dev_priv,
  849. struct bdb_header *bdb)
  850. {
  851. struct drm_device *dev = dev_priv->dev;
  852. enum port port;
  853. if (!HAS_DDI(dev))
  854. return;
  855. if (!dev_priv->vbt.child_dev_num)
  856. return;
  857. if (bdb->version < 155)
  858. return;
  859. for (port = PORT_A; port < I915_MAX_PORTS; port++)
  860. parse_ddi_port(dev_priv, port, bdb);
  861. }
  862. static void
  863. parse_device_mapping(struct drm_i915_private *dev_priv,
  864. struct bdb_header *bdb)
  865. {
  866. struct bdb_general_definitions *p_defs;
  867. union child_device_config *p_child, *child_dev_ptr;
  868. int i, child_device_num, count;
  869. u16 block_size;
  870. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  871. if (!p_defs) {
  872. DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
  873. return;
  874. }
  875. /* judge whether the size of child device meets the requirements.
  876. * If the child device size obtained from general definition block
  877. * is different with sizeof(struct child_device_config), skip the
  878. * parsing of sdvo device info
  879. */
  880. if (p_defs->child_dev_size != sizeof(*p_child)) {
  881. /* different child dev size . Ignore it */
  882. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  883. return;
  884. }
  885. /* get the block size of general definitions */
  886. block_size = get_blocksize(p_defs);
  887. /* get the number of child device */
  888. child_device_num = (block_size - sizeof(*p_defs)) /
  889. sizeof(*p_child);
  890. count = 0;
  891. /* get the number of child device that is present */
  892. for (i = 0; i < child_device_num; i++) {
  893. p_child = &(p_defs->devices[i]);
  894. if (!p_child->common.device_type) {
  895. /* skip the device block if device type is invalid */
  896. continue;
  897. }
  898. count++;
  899. }
  900. if (!count) {
  901. DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
  902. return;
  903. }
  904. dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
  905. if (!dev_priv->vbt.child_dev) {
  906. DRM_DEBUG_KMS("No memory space for child device\n");
  907. return;
  908. }
  909. dev_priv->vbt.child_dev_num = count;
  910. count = 0;
  911. for (i = 0; i < child_device_num; i++) {
  912. p_child = &(p_defs->devices[i]);
  913. if (!p_child->common.device_type) {
  914. /* skip the device block if device type is invalid */
  915. continue;
  916. }
  917. if (p_child->common.dvo_port >= DVO_PORT_MIPIA
  918. && p_child->common.dvo_port <= DVO_PORT_MIPID
  919. &&p_child->common.device_type & DEVICE_TYPE_MIPI_OUTPUT) {
  920. DRM_DEBUG_KMS("Found MIPI as LFP\n");
  921. dev_priv->vbt.has_mipi = 1;
  922. dev_priv->vbt.dsi.port = p_child->common.dvo_port;
  923. }
  924. child_dev_ptr = dev_priv->vbt.child_dev + count;
  925. count++;
  926. memcpy((void *)child_dev_ptr, (void *)p_child,
  927. sizeof(*p_child));
  928. }
  929. return;
  930. }
  931. static void
  932. init_vbt_defaults(struct drm_i915_private *dev_priv)
  933. {
  934. struct drm_device *dev = dev_priv->dev;
  935. enum port port;
  936. dev_priv->vbt.crt_ddc_pin = GMBUS_PORT_VGADDC;
  937. /* Default to having backlight */
  938. dev_priv->vbt.backlight.present = true;
  939. /* LFP panel data */
  940. dev_priv->vbt.lvds_dither = 1;
  941. dev_priv->vbt.lvds_vbt = 0;
  942. /* SDVO panel data */
  943. dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
  944. /* general features */
  945. dev_priv->vbt.int_tv_support = 1;
  946. dev_priv->vbt.int_crt_support = 1;
  947. /* Default to using SSC */
  948. dev_priv->vbt.lvds_use_ssc = 1;
  949. /*
  950. * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
  951. * clock for LVDS.
  952. */
  953. dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev,
  954. !HAS_PCH_SPLIT(dev));
  955. DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
  956. for (port = PORT_A; port < I915_MAX_PORTS; port++) {
  957. struct ddi_vbt_port_info *info =
  958. &dev_priv->vbt.ddi_port_info[port];
  959. /* Recommended BSpec default: 800mV 0dB. */
  960. info->hdmi_level_shift = 6;
  961. info->supports_dvi = (port != PORT_A && port != PORT_E);
  962. info->supports_hdmi = info->supports_dvi;
  963. info->supports_dp = (port != PORT_E);
  964. }
  965. }
  966. static int __init intel_no_opregion_vbt_callback(const struct dmi_system_id *id)
  967. {
  968. DRM_DEBUG_KMS("Falling back to manually reading VBT from "
  969. "VBIOS ROM for %s\n",
  970. id->ident);
  971. return 1;
  972. }
  973. static const struct dmi_system_id intel_no_opregion_vbt[] = {
  974. {
  975. .callback = intel_no_opregion_vbt_callback,
  976. .ident = "ThinkCentre A57",
  977. .matches = {
  978. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  979. DMI_MATCH(DMI_PRODUCT_NAME, "97027RG"),
  980. },
  981. },
  982. { }
  983. };
  984. static struct bdb_header *validate_vbt(char *base, size_t size,
  985. struct vbt_header *vbt,
  986. const char *source)
  987. {
  988. size_t offset;
  989. struct bdb_header *bdb;
  990. if (vbt == NULL) {
  991. DRM_DEBUG_DRIVER("VBT signature missing\n");
  992. return NULL;
  993. }
  994. offset = (char *)vbt - base;
  995. if (offset + sizeof(struct vbt_header) > size) {
  996. DRM_DEBUG_DRIVER("VBT header incomplete\n");
  997. return NULL;
  998. }
  999. if (memcmp(vbt->signature, "$VBT", 4)) {
  1000. DRM_DEBUG_DRIVER("VBT invalid signature\n");
  1001. return NULL;
  1002. }
  1003. offset += vbt->bdb_offset;
  1004. if (offset + sizeof(struct bdb_header) > size) {
  1005. DRM_DEBUG_DRIVER("BDB header incomplete\n");
  1006. return NULL;
  1007. }
  1008. bdb = (struct bdb_header *)(base + offset);
  1009. if (offset + bdb->bdb_size > size) {
  1010. DRM_DEBUG_DRIVER("BDB incomplete\n");
  1011. return NULL;
  1012. }
  1013. DRM_DEBUG_KMS("Using VBT from %s: %20s\n",
  1014. source, vbt->signature);
  1015. return bdb;
  1016. }
  1017. /**
  1018. * intel_parse_bios - find VBT and initialize settings from the BIOS
  1019. * @dev: DRM device
  1020. *
  1021. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  1022. * to appropriate values.
  1023. *
  1024. * Returns 0 on success, nonzero on failure.
  1025. */
  1026. int
  1027. intel_parse_bios(struct drm_device *dev)
  1028. {
  1029. struct drm_i915_private *dev_priv = dev->dev_private;
  1030. struct pci_dev *pdev = dev->pdev;
  1031. struct bdb_header *bdb = NULL;
  1032. u8 __iomem *bios = NULL;
  1033. if (HAS_PCH_NOP(dev))
  1034. return -ENODEV;
  1035. init_vbt_defaults(dev_priv);
  1036. /* XXX Should this validation be moved to intel_opregion.c? */
  1037. if (!dmi_check_system(intel_no_opregion_vbt) && dev_priv->opregion.vbt)
  1038. bdb = validate_vbt((char *)dev_priv->opregion.header, OPREGION_SIZE,
  1039. (struct vbt_header *)dev_priv->opregion.vbt,
  1040. "OpRegion");
  1041. if (bdb == NULL) {
  1042. size_t i, size;
  1043. bios = pci_map_rom(pdev, &size);
  1044. if (!bios)
  1045. return -1;
  1046. /* Scour memory looking for the VBT signature */
  1047. for (i = 0; i + 4 < size; i++) {
  1048. if (memcmp(bios + i, "$VBT", 4) == 0) {
  1049. bdb = validate_vbt(bios, size,
  1050. (struct vbt_header *)(bios + i),
  1051. "PCI ROM");
  1052. break;
  1053. }
  1054. }
  1055. if (!bdb) {
  1056. pci_unmap_rom(pdev, bios);
  1057. return -1;
  1058. }
  1059. }
  1060. /* Grab useful general definitions */
  1061. parse_general_features(dev_priv, bdb);
  1062. parse_general_definitions(dev_priv, bdb);
  1063. parse_lfp_panel_data(dev_priv, bdb);
  1064. parse_lfp_backlight(dev_priv, bdb);
  1065. parse_sdvo_panel_data(dev_priv, bdb);
  1066. parse_sdvo_device_mapping(dev_priv, bdb);
  1067. parse_device_mapping(dev_priv, bdb);
  1068. parse_driver_features(dev_priv, bdb);
  1069. parse_edp(dev_priv, bdb);
  1070. parse_mipi(dev_priv, bdb);
  1071. parse_ddi_ports(dev_priv, bdb);
  1072. if (bios)
  1073. pci_unmap_rom(pdev, bios);
  1074. return 0;
  1075. }
  1076. /* Ensure that vital registers have been initialised, even if the BIOS
  1077. * is absent or just failing to do its job.
  1078. */
  1079. void intel_setup_bios(struct drm_device *dev)
  1080. {
  1081. struct drm_i915_private *dev_priv = dev->dev_private;
  1082. /* Set the Panel Power On/Off timings if uninitialized. */
  1083. if (!HAS_PCH_SPLIT(dev) &&
  1084. I915_READ(PP_ON_DELAYS) == 0 && I915_READ(PP_OFF_DELAYS) == 0) {
  1085. /* Set T2 to 40ms and T5 to 200ms */
  1086. I915_WRITE(PP_ON_DELAYS, 0x019007d0);
  1087. /* Set T3 to 35ms and Tx to 200ms */
  1088. I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);
  1089. }
  1090. }