intel_bios.c 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321
  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. dev_priv->vbt.backlight.min_brightness = entry->min_brightness;
  285. DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
  286. "active %s, min brightness %u, level %u\n",
  287. dev_priv->vbt.backlight.pwm_freq_hz,
  288. dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
  289. dev_priv->vbt.backlight.min_brightness,
  290. backlight_data->level[panel_type]);
  291. }
  292. /* Try to find sdvo panel data */
  293. static void
  294. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  295. struct bdb_header *bdb)
  296. {
  297. struct lvds_dvo_timing *dvo_timing;
  298. struct drm_display_mode *panel_fixed_mode;
  299. int index;
  300. index = i915.vbt_sdvo_panel_type;
  301. if (index == -2) {
  302. DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
  303. return;
  304. }
  305. if (index == -1) {
  306. struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  307. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  308. if (!sdvo_lvds_options)
  309. return;
  310. index = sdvo_lvds_options->panel_type;
  311. }
  312. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  313. if (!dvo_timing)
  314. return;
  315. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  316. if (!panel_fixed_mode)
  317. return;
  318. fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
  319. dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
  320. DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
  321. drm_mode_debug_printmodeline(panel_fixed_mode);
  322. }
  323. static int intel_bios_ssc_frequency(struct drm_device *dev,
  324. bool alternate)
  325. {
  326. switch (INTEL_INFO(dev)->gen) {
  327. case 2:
  328. return alternate ? 66667 : 48000;
  329. case 3:
  330. case 4:
  331. return alternate ? 100000 : 96000;
  332. default:
  333. return alternate ? 100000 : 120000;
  334. }
  335. }
  336. static void
  337. parse_general_features(struct drm_i915_private *dev_priv,
  338. struct bdb_header *bdb)
  339. {
  340. struct drm_device *dev = dev_priv->dev;
  341. struct bdb_general_features *general;
  342. general = find_section(bdb, BDB_GENERAL_FEATURES);
  343. if (general) {
  344. dev_priv->vbt.int_tv_support = general->int_tv_support;
  345. dev_priv->vbt.int_crt_support = general->int_crt_support;
  346. dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
  347. dev_priv->vbt.lvds_ssc_freq =
  348. intel_bios_ssc_frequency(dev, general->ssc_freq);
  349. dev_priv->vbt.display_clock_mode = general->display_clock_mode;
  350. dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
  351. 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",
  352. dev_priv->vbt.int_tv_support,
  353. dev_priv->vbt.int_crt_support,
  354. dev_priv->vbt.lvds_use_ssc,
  355. dev_priv->vbt.lvds_ssc_freq,
  356. dev_priv->vbt.display_clock_mode,
  357. dev_priv->vbt.fdi_rx_polarity_inverted);
  358. }
  359. }
  360. static void
  361. parse_general_definitions(struct drm_i915_private *dev_priv,
  362. struct bdb_header *bdb)
  363. {
  364. struct bdb_general_definitions *general;
  365. general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  366. if (general) {
  367. u16 block_size = get_blocksize(general);
  368. if (block_size >= sizeof(*general)) {
  369. int bus_pin = general->crt_ddc_gmbus_pin;
  370. DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
  371. if (intel_gmbus_is_port_valid(bus_pin))
  372. dev_priv->vbt.crt_ddc_pin = bus_pin;
  373. } else {
  374. DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
  375. block_size);
  376. }
  377. }
  378. }
  379. static void
  380. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  381. struct bdb_header *bdb)
  382. {
  383. struct sdvo_device_mapping *p_mapping;
  384. struct bdb_general_definitions *p_defs;
  385. union child_device_config *p_child;
  386. int i, child_device_num, count;
  387. u16 block_size;
  388. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  389. if (!p_defs) {
  390. DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
  391. return;
  392. }
  393. /* judge whether the size of child device meets the requirements.
  394. * If the child device size obtained from general definition block
  395. * is different with sizeof(struct child_device_config), skip the
  396. * parsing of sdvo device info
  397. */
  398. if (p_defs->child_dev_size != sizeof(*p_child)) {
  399. /* different child dev size . Ignore it */
  400. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  401. return;
  402. }
  403. /* get the block size of general definitions */
  404. block_size = get_blocksize(p_defs);
  405. /* get the number of child device */
  406. child_device_num = (block_size - sizeof(*p_defs)) /
  407. sizeof(*p_child);
  408. count = 0;
  409. for (i = 0; i < child_device_num; i++) {
  410. p_child = &(p_defs->devices[i]);
  411. if (!p_child->old.device_type) {
  412. /* skip the device block if device type is invalid */
  413. continue;
  414. }
  415. if (p_child->old.slave_addr != SLAVE_ADDR1 &&
  416. p_child->old.slave_addr != SLAVE_ADDR2) {
  417. /*
  418. * If the slave address is neither 0x70 nor 0x72,
  419. * it is not a SDVO device. Skip it.
  420. */
  421. continue;
  422. }
  423. if (p_child->old.dvo_port != DEVICE_PORT_DVOB &&
  424. p_child->old.dvo_port != DEVICE_PORT_DVOC) {
  425. /* skip the incorrect SDVO port */
  426. DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
  427. continue;
  428. }
  429. DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
  430. " %s port\n",
  431. p_child->old.slave_addr,
  432. (p_child->old.dvo_port == DEVICE_PORT_DVOB) ?
  433. "SDVOB" : "SDVOC");
  434. p_mapping = &(dev_priv->sdvo_mappings[p_child->old.dvo_port - 1]);
  435. if (!p_mapping->initialized) {
  436. p_mapping->dvo_port = p_child->old.dvo_port;
  437. p_mapping->slave_addr = p_child->old.slave_addr;
  438. p_mapping->dvo_wiring = p_child->old.dvo_wiring;
  439. p_mapping->ddc_pin = p_child->old.ddc_pin;
  440. p_mapping->i2c_pin = p_child->old.i2c_pin;
  441. p_mapping->initialized = 1;
  442. DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
  443. p_mapping->dvo_port,
  444. p_mapping->slave_addr,
  445. p_mapping->dvo_wiring,
  446. p_mapping->ddc_pin,
  447. p_mapping->i2c_pin);
  448. } else {
  449. DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
  450. "two SDVO device.\n");
  451. }
  452. if (p_child->old.slave2_addr) {
  453. /* Maybe this is a SDVO device with multiple inputs */
  454. /* And the mapping info is not added */
  455. DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
  456. " is a SDVO device with multiple inputs.\n");
  457. }
  458. count++;
  459. }
  460. if (!count) {
  461. /* No SDVO device info is found */
  462. DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
  463. }
  464. return;
  465. }
  466. static void
  467. parse_driver_features(struct drm_i915_private *dev_priv,
  468. struct bdb_header *bdb)
  469. {
  470. struct bdb_driver_features *driver;
  471. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  472. if (!driver)
  473. return;
  474. if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
  475. dev_priv->vbt.edp_support = 1;
  476. if (driver->dual_frequency)
  477. dev_priv->render_reclock_avail = true;
  478. DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
  479. /*
  480. * If DRRS is not supported, drrs_type has to be set to 0.
  481. * This is because, VBT is configured in such a way that
  482. * static DRRS is 0 and DRRS not supported is represented by
  483. * driver->drrs_enabled=false
  484. */
  485. if (!driver->drrs_enabled)
  486. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  487. }
  488. static void
  489. parse_edp(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  490. {
  491. struct bdb_edp *edp;
  492. struct edp_power_seq *edp_pps;
  493. struct edp_link_params *edp_link_params;
  494. edp = find_section(bdb, BDB_EDP);
  495. if (!edp) {
  496. if (dev_priv->vbt.edp_support)
  497. DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
  498. return;
  499. }
  500. switch ((edp->color_depth >> (panel_type * 2)) & 3) {
  501. case EDP_18BPP:
  502. dev_priv->vbt.edp_bpp = 18;
  503. break;
  504. case EDP_24BPP:
  505. dev_priv->vbt.edp_bpp = 24;
  506. break;
  507. case EDP_30BPP:
  508. dev_priv->vbt.edp_bpp = 30;
  509. break;
  510. }
  511. /* Get the eDP sequencing and link info */
  512. edp_pps = &edp->power_seqs[panel_type];
  513. edp_link_params = &edp->link_params[panel_type];
  514. dev_priv->vbt.edp_pps = *edp_pps;
  515. switch (edp_link_params->rate) {
  516. case EDP_RATE_1_62:
  517. dev_priv->vbt.edp_rate = DP_LINK_BW_1_62;
  518. break;
  519. case EDP_RATE_2_7:
  520. dev_priv->vbt.edp_rate = DP_LINK_BW_2_7;
  521. break;
  522. default:
  523. DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
  524. edp_link_params->rate);
  525. break;
  526. }
  527. switch (edp_link_params->lanes) {
  528. case EDP_LANE_1:
  529. dev_priv->vbt.edp_lanes = 1;
  530. break;
  531. case EDP_LANE_2:
  532. dev_priv->vbt.edp_lanes = 2;
  533. break;
  534. case EDP_LANE_4:
  535. dev_priv->vbt.edp_lanes = 4;
  536. break;
  537. default:
  538. DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
  539. edp_link_params->lanes);
  540. break;
  541. }
  542. switch (edp_link_params->preemphasis) {
  543. case EDP_PREEMPHASIS_NONE:
  544. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
  545. break;
  546. case EDP_PREEMPHASIS_3_5dB:
  547. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
  548. break;
  549. case EDP_PREEMPHASIS_6dB:
  550. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
  551. break;
  552. case EDP_PREEMPHASIS_9_5dB:
  553. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
  554. break;
  555. default:
  556. DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
  557. edp_link_params->preemphasis);
  558. break;
  559. }
  560. switch (edp_link_params->vswing) {
  561. case EDP_VSWING_0_4V:
  562. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
  563. break;
  564. case EDP_VSWING_0_6V:
  565. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
  566. break;
  567. case EDP_VSWING_0_8V:
  568. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  569. break;
  570. case EDP_VSWING_1_2V:
  571. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  572. break;
  573. default:
  574. DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
  575. edp_link_params->vswing);
  576. break;
  577. }
  578. if (bdb->version >= 173) {
  579. uint8_t vswing;
  580. vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
  581. dev_priv->vbt.edp_low_vswing = vswing == 0;
  582. }
  583. }
  584. static void
  585. parse_psr(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  586. {
  587. struct bdb_psr *psr;
  588. struct psr_table *psr_table;
  589. psr = find_section(bdb, BDB_PSR);
  590. if (!psr) {
  591. DRM_DEBUG_KMS("No PSR BDB found.\n");
  592. return;
  593. }
  594. psr_table = &psr->psr_table[panel_type];
  595. dev_priv->vbt.psr.full_link = psr_table->full_link;
  596. dev_priv->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
  597. /* Allowed VBT values goes from 0 to 15 */
  598. dev_priv->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
  599. psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
  600. switch (psr_table->lines_to_wait) {
  601. case 0:
  602. dev_priv->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
  603. break;
  604. case 1:
  605. dev_priv->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
  606. break;
  607. case 2:
  608. dev_priv->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
  609. break;
  610. case 3:
  611. dev_priv->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
  612. break;
  613. default:
  614. DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
  615. psr_table->lines_to_wait);
  616. break;
  617. }
  618. dev_priv->vbt.psr.tp1_wakeup_time = psr_table->tp1_wakeup_time;
  619. dev_priv->vbt.psr.tp2_tp3_wakeup_time = psr_table->tp2_tp3_wakeup_time;
  620. }
  621. static u8 *goto_next_sequence(u8 *data, int *size)
  622. {
  623. u16 len;
  624. int tmp = *size;
  625. if (--tmp < 0)
  626. return NULL;
  627. /* goto first element */
  628. data++;
  629. while (1) {
  630. switch (*data) {
  631. case MIPI_SEQ_ELEM_SEND_PKT:
  632. /*
  633. * skip by this element payload size
  634. * skip elem id, command flag and data type
  635. */
  636. tmp -= 5;
  637. if (tmp < 0)
  638. return NULL;
  639. data += 3;
  640. len = *((u16 *)data);
  641. tmp -= len;
  642. if (tmp < 0)
  643. return NULL;
  644. /* skip by len */
  645. data = data + 2 + len;
  646. break;
  647. case MIPI_SEQ_ELEM_DELAY:
  648. /* skip by elem id, and delay is 4 bytes */
  649. tmp -= 5;
  650. if (tmp < 0)
  651. return NULL;
  652. data += 5;
  653. break;
  654. case MIPI_SEQ_ELEM_GPIO:
  655. tmp -= 3;
  656. if (tmp < 0)
  657. return NULL;
  658. data += 3;
  659. break;
  660. default:
  661. DRM_ERROR("Unknown element\n");
  662. return NULL;
  663. }
  664. /* end of sequence ? */
  665. if (*data == 0)
  666. break;
  667. }
  668. /* goto next sequence or end of block byte */
  669. if (--tmp < 0)
  670. return NULL;
  671. data++;
  672. /* update amount of data left for the sequence block to be parsed */
  673. *size = tmp;
  674. return data;
  675. }
  676. static void
  677. parse_mipi(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  678. {
  679. struct bdb_mipi_config *start;
  680. struct bdb_mipi_sequence *sequence;
  681. struct mipi_config *config;
  682. struct mipi_pps_data *pps;
  683. u8 *data, *seq_data;
  684. int i, panel_id, seq_size;
  685. u16 block_size;
  686. /* parse MIPI blocks only if LFP type is MIPI */
  687. if (!dev_priv->vbt.has_mipi)
  688. return;
  689. /* Initialize this to undefined indicating no generic MIPI support */
  690. dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
  691. /* Block #40 is already parsed and panel_fixed_mode is
  692. * stored in dev_priv->lfp_lvds_vbt_mode
  693. * resuse this when needed
  694. */
  695. /* Parse #52 for panel index used from panel_type already
  696. * parsed
  697. */
  698. start = find_section(bdb, BDB_MIPI_CONFIG);
  699. if (!start) {
  700. DRM_DEBUG_KMS("No MIPI config BDB found");
  701. return;
  702. }
  703. DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
  704. panel_type);
  705. /*
  706. * get hold of the correct configuration block and pps data as per
  707. * the panel_type as index
  708. */
  709. config = &start->config[panel_type];
  710. pps = &start->pps[panel_type];
  711. /* store as of now full data. Trim when we realise all is not needed */
  712. dev_priv->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
  713. if (!dev_priv->vbt.dsi.config)
  714. return;
  715. dev_priv->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
  716. if (!dev_priv->vbt.dsi.pps) {
  717. kfree(dev_priv->vbt.dsi.config);
  718. return;
  719. }
  720. /* We have mandatory mipi config blocks. Initialize as generic panel */
  721. dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
  722. /* Check if we have sequence block as well */
  723. sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
  724. if (!sequence) {
  725. DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
  726. return;
  727. }
  728. DRM_DEBUG_DRIVER("Found MIPI sequence block\n");
  729. block_size = get_blocksize(sequence);
  730. /*
  731. * parse the sequence block for individual sequences
  732. */
  733. dev_priv->vbt.dsi.seq_version = sequence->version;
  734. seq_data = &sequence->data[0];
  735. /*
  736. * sequence block is variable length and hence we need to parse and
  737. * get the sequence data for specific panel id
  738. */
  739. for (i = 0; i < MAX_MIPI_CONFIGURATIONS; i++) {
  740. panel_id = *seq_data;
  741. seq_size = *((u16 *) (seq_data + 1));
  742. if (panel_id == panel_type)
  743. break;
  744. /* skip the sequence including seq header of 3 bytes */
  745. seq_data = seq_data + 3 + seq_size;
  746. if ((seq_data - &sequence->data[0]) > block_size) {
  747. DRM_ERROR("Sequence start is beyond sequence block size, corrupted sequence block\n");
  748. return;
  749. }
  750. }
  751. if (i == MAX_MIPI_CONFIGURATIONS) {
  752. DRM_ERROR("Sequence block detected but no valid configuration\n");
  753. return;
  754. }
  755. /* check if found sequence is completely within the sequence block
  756. * just being paranoid */
  757. if (seq_size > block_size) {
  758. DRM_ERROR("Corrupted sequence/size, bailing out\n");
  759. return;
  760. }
  761. /* skip the panel id(1 byte) and seq size(2 bytes) */
  762. dev_priv->vbt.dsi.data = kmemdup(seq_data + 3, seq_size, GFP_KERNEL);
  763. if (!dev_priv->vbt.dsi.data)
  764. return;
  765. /*
  766. * loop into the sequence data and split into multiple sequneces
  767. * There are only 5 types of sequences as of now
  768. */
  769. data = dev_priv->vbt.dsi.data;
  770. dev_priv->vbt.dsi.size = seq_size;
  771. /* two consecutive 0x00 indicate end of all sequences */
  772. while (1) {
  773. int seq_id = *data;
  774. if (MIPI_SEQ_MAX > seq_id && seq_id > MIPI_SEQ_UNDEFINED) {
  775. dev_priv->vbt.dsi.sequence[seq_id] = data;
  776. DRM_DEBUG_DRIVER("Found mipi sequence - %d\n", seq_id);
  777. } else {
  778. DRM_ERROR("undefined sequence\n");
  779. goto err;
  780. }
  781. /* partial parsing to skip elements */
  782. data = goto_next_sequence(data, &seq_size);
  783. if (data == NULL) {
  784. DRM_ERROR("Sequence elements going beyond block itself. Sequence block parsing failed\n");
  785. goto err;
  786. }
  787. if (*data == 0)
  788. break; /* end of sequence reached */
  789. }
  790. DRM_DEBUG_DRIVER("MIPI related vbt parsing complete\n");
  791. return;
  792. err:
  793. kfree(dev_priv->vbt.dsi.data);
  794. dev_priv->vbt.dsi.data = NULL;
  795. /* error during parsing so set all pointers to null
  796. * because of partial parsing */
  797. memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
  798. }
  799. static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
  800. struct bdb_header *bdb)
  801. {
  802. union child_device_config *it, *child = NULL;
  803. struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
  804. uint8_t hdmi_level_shift;
  805. int i, j;
  806. bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
  807. uint8_t aux_channel;
  808. /* Each DDI port can have more than one value on the "DVO Port" field,
  809. * so look for all the possible values for each port and abort if more
  810. * than one is found. */
  811. int dvo_ports[][2] = {
  812. {DVO_PORT_HDMIA, DVO_PORT_DPA},
  813. {DVO_PORT_HDMIB, DVO_PORT_DPB},
  814. {DVO_PORT_HDMIC, DVO_PORT_DPC},
  815. {DVO_PORT_HDMID, DVO_PORT_DPD},
  816. {DVO_PORT_CRT, -1 /* Port E can only be DVO_PORT_CRT */ },
  817. };
  818. /* Find the child device to use, abort if more than one found. */
  819. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  820. it = dev_priv->vbt.child_dev + i;
  821. for (j = 0; j < 2; j++) {
  822. if (dvo_ports[port][j] == -1)
  823. break;
  824. if (it->common.dvo_port == dvo_ports[port][j]) {
  825. if (child) {
  826. DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
  827. port_name(port));
  828. return;
  829. }
  830. child = it;
  831. }
  832. }
  833. }
  834. if (!child)
  835. return;
  836. aux_channel = child->raw[25];
  837. is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
  838. is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
  839. is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
  840. is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
  841. is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
  842. info->supports_dvi = is_dvi;
  843. info->supports_hdmi = is_hdmi;
  844. info->supports_dp = is_dp;
  845. DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
  846. port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
  847. if (is_edp && is_dvi)
  848. DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
  849. port_name(port));
  850. if (is_crt && port != PORT_E)
  851. DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
  852. if (is_crt && (is_dvi || is_dp))
  853. DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
  854. port_name(port));
  855. if (is_dvi && (port == PORT_A || port == PORT_E))
  856. DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port));
  857. if (!is_dvi && !is_dp && !is_crt)
  858. DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
  859. port_name(port));
  860. if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
  861. DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
  862. if (is_dvi) {
  863. if (child->common.ddc_pin == 0x05 && port != PORT_B)
  864. DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
  865. if (child->common.ddc_pin == 0x04 && port != PORT_C)
  866. DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
  867. if (child->common.ddc_pin == 0x06 && port != PORT_D)
  868. DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
  869. }
  870. if (is_dp) {
  871. if (aux_channel == 0x40 && port != PORT_A)
  872. DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
  873. if (aux_channel == 0x10 && port != PORT_B)
  874. DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
  875. if (aux_channel == 0x20 && port != PORT_C)
  876. DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
  877. if (aux_channel == 0x30 && port != PORT_D)
  878. DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
  879. }
  880. if (bdb->version >= 158) {
  881. /* The VBT HDMI level shift values match the table we have. */
  882. hdmi_level_shift = child->raw[7] & 0xF;
  883. DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
  884. port_name(port),
  885. hdmi_level_shift);
  886. info->hdmi_level_shift = hdmi_level_shift;
  887. }
  888. }
  889. static void parse_ddi_ports(struct drm_i915_private *dev_priv,
  890. struct bdb_header *bdb)
  891. {
  892. struct drm_device *dev = dev_priv->dev;
  893. enum port port;
  894. if (!HAS_DDI(dev))
  895. return;
  896. if (!dev_priv->vbt.child_dev_num)
  897. return;
  898. if (bdb->version < 155)
  899. return;
  900. for (port = PORT_A; port < I915_MAX_PORTS; port++)
  901. parse_ddi_port(dev_priv, port, bdb);
  902. }
  903. static void
  904. parse_device_mapping(struct drm_i915_private *dev_priv,
  905. struct bdb_header *bdb)
  906. {
  907. struct bdb_general_definitions *p_defs;
  908. union child_device_config *p_child, *child_dev_ptr;
  909. int i, child_device_num, count;
  910. u16 block_size;
  911. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  912. if (!p_defs) {
  913. DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
  914. return;
  915. }
  916. /* judge whether the size of child device meets the requirements.
  917. * If the child device size obtained from general definition block
  918. * is different with sizeof(struct child_device_config), skip the
  919. * parsing of sdvo device info
  920. */
  921. if (p_defs->child_dev_size != sizeof(*p_child)) {
  922. /* different child dev size . Ignore it */
  923. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  924. return;
  925. }
  926. /* get the block size of general definitions */
  927. block_size = get_blocksize(p_defs);
  928. /* get the number of child device */
  929. child_device_num = (block_size - sizeof(*p_defs)) /
  930. sizeof(*p_child);
  931. count = 0;
  932. /* get the number of child device that is present */
  933. for (i = 0; i < child_device_num; i++) {
  934. p_child = &(p_defs->devices[i]);
  935. if (!p_child->common.device_type) {
  936. /* skip the device block if device type is invalid */
  937. continue;
  938. }
  939. count++;
  940. }
  941. if (!count) {
  942. DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
  943. return;
  944. }
  945. dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
  946. if (!dev_priv->vbt.child_dev) {
  947. DRM_DEBUG_KMS("No memory space for child device\n");
  948. return;
  949. }
  950. dev_priv->vbt.child_dev_num = count;
  951. count = 0;
  952. for (i = 0; i < child_device_num; i++) {
  953. p_child = &(p_defs->devices[i]);
  954. if (!p_child->common.device_type) {
  955. /* skip the device block if device type is invalid */
  956. continue;
  957. }
  958. if (p_child->common.dvo_port >= DVO_PORT_MIPIA
  959. && p_child->common.dvo_port <= DVO_PORT_MIPID
  960. &&p_child->common.device_type & DEVICE_TYPE_MIPI_OUTPUT) {
  961. DRM_DEBUG_KMS("Found MIPI as LFP\n");
  962. dev_priv->vbt.has_mipi = 1;
  963. dev_priv->vbt.dsi.port = p_child->common.dvo_port;
  964. }
  965. child_dev_ptr = dev_priv->vbt.child_dev + count;
  966. count++;
  967. memcpy((void *)child_dev_ptr, (void *)p_child,
  968. sizeof(*p_child));
  969. }
  970. return;
  971. }
  972. static void
  973. init_vbt_defaults(struct drm_i915_private *dev_priv)
  974. {
  975. struct drm_device *dev = dev_priv->dev;
  976. enum port port;
  977. dev_priv->vbt.crt_ddc_pin = GMBUS_PORT_VGADDC;
  978. /* Default to having backlight */
  979. dev_priv->vbt.backlight.present = true;
  980. /* LFP panel data */
  981. dev_priv->vbt.lvds_dither = 1;
  982. dev_priv->vbt.lvds_vbt = 0;
  983. /* SDVO panel data */
  984. dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
  985. /* general features */
  986. dev_priv->vbt.int_tv_support = 1;
  987. dev_priv->vbt.int_crt_support = 1;
  988. /* Default to using SSC */
  989. dev_priv->vbt.lvds_use_ssc = 1;
  990. /*
  991. * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
  992. * clock for LVDS.
  993. */
  994. dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev,
  995. !HAS_PCH_SPLIT(dev));
  996. DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
  997. for (port = PORT_A; port < I915_MAX_PORTS; port++) {
  998. struct ddi_vbt_port_info *info =
  999. &dev_priv->vbt.ddi_port_info[port];
  1000. info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
  1001. info->supports_dvi = (port != PORT_A && port != PORT_E);
  1002. info->supports_hdmi = info->supports_dvi;
  1003. info->supports_dp = (port != PORT_E);
  1004. }
  1005. }
  1006. static int intel_no_opregion_vbt_callback(const struct dmi_system_id *id)
  1007. {
  1008. DRM_DEBUG_KMS("Falling back to manually reading VBT from "
  1009. "VBIOS ROM for %s\n",
  1010. id->ident);
  1011. return 1;
  1012. }
  1013. static const struct dmi_system_id intel_no_opregion_vbt[] = {
  1014. {
  1015. .callback = intel_no_opregion_vbt_callback,
  1016. .ident = "ThinkCentre A57",
  1017. .matches = {
  1018. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  1019. DMI_MATCH(DMI_PRODUCT_NAME, "97027RG"),
  1020. },
  1021. },
  1022. { }
  1023. };
  1024. static struct bdb_header *validate_vbt(char *base, size_t size,
  1025. struct vbt_header *vbt,
  1026. const char *source)
  1027. {
  1028. size_t offset;
  1029. struct bdb_header *bdb;
  1030. if (vbt == NULL) {
  1031. DRM_DEBUG_DRIVER("VBT signature missing\n");
  1032. return NULL;
  1033. }
  1034. offset = (char *)vbt - base;
  1035. if (offset + sizeof(struct vbt_header) > size) {
  1036. DRM_DEBUG_DRIVER("VBT header incomplete\n");
  1037. return NULL;
  1038. }
  1039. if (memcmp(vbt->signature, "$VBT", 4)) {
  1040. DRM_DEBUG_DRIVER("VBT invalid signature\n");
  1041. return NULL;
  1042. }
  1043. offset += vbt->bdb_offset;
  1044. if (offset + sizeof(struct bdb_header) > size) {
  1045. DRM_DEBUG_DRIVER("BDB header incomplete\n");
  1046. return NULL;
  1047. }
  1048. bdb = (struct bdb_header *)(base + offset);
  1049. if (offset + bdb->bdb_size > size) {
  1050. DRM_DEBUG_DRIVER("BDB incomplete\n");
  1051. return NULL;
  1052. }
  1053. DRM_DEBUG_KMS("Using VBT from %s: %20s\n",
  1054. source, vbt->signature);
  1055. return bdb;
  1056. }
  1057. /**
  1058. * intel_parse_bios - find VBT and initialize settings from the BIOS
  1059. * @dev: DRM device
  1060. *
  1061. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  1062. * to appropriate values.
  1063. *
  1064. * Returns 0 on success, nonzero on failure.
  1065. */
  1066. int
  1067. intel_parse_bios(struct drm_device *dev)
  1068. {
  1069. struct drm_i915_private *dev_priv = dev->dev_private;
  1070. struct pci_dev *pdev = dev->pdev;
  1071. struct bdb_header *bdb = NULL;
  1072. u8 __iomem *bios = NULL;
  1073. if (HAS_PCH_NOP(dev))
  1074. return -ENODEV;
  1075. init_vbt_defaults(dev_priv);
  1076. /* XXX Should this validation be moved to intel_opregion.c? */
  1077. if (!dmi_check_system(intel_no_opregion_vbt) && dev_priv->opregion.vbt)
  1078. bdb = validate_vbt((char *)dev_priv->opregion.header, OPREGION_SIZE,
  1079. (struct vbt_header *)dev_priv->opregion.vbt,
  1080. "OpRegion");
  1081. if (bdb == NULL) {
  1082. size_t i, size;
  1083. bios = pci_map_rom(pdev, &size);
  1084. if (!bios)
  1085. return -1;
  1086. /* Scour memory looking for the VBT signature */
  1087. for (i = 0; i + 4 < size; i++) {
  1088. if (memcmp(bios + i, "$VBT", 4) == 0) {
  1089. bdb = validate_vbt(bios, size,
  1090. (struct vbt_header *)(bios + i),
  1091. "PCI ROM");
  1092. break;
  1093. }
  1094. }
  1095. if (!bdb) {
  1096. pci_unmap_rom(pdev, bios);
  1097. return -1;
  1098. }
  1099. }
  1100. /* Grab useful general definitions */
  1101. parse_general_features(dev_priv, bdb);
  1102. parse_general_definitions(dev_priv, bdb);
  1103. parse_lfp_panel_data(dev_priv, bdb);
  1104. parse_lfp_backlight(dev_priv, bdb);
  1105. parse_sdvo_panel_data(dev_priv, bdb);
  1106. parse_sdvo_device_mapping(dev_priv, bdb);
  1107. parse_device_mapping(dev_priv, bdb);
  1108. parse_driver_features(dev_priv, bdb);
  1109. parse_edp(dev_priv, bdb);
  1110. parse_psr(dev_priv, bdb);
  1111. parse_mipi(dev_priv, bdb);
  1112. parse_ddi_ports(dev_priv, bdb);
  1113. if (bios)
  1114. pci_unmap_rom(pdev, bios);
  1115. return 0;
  1116. }
  1117. /* Ensure that vital registers have been initialised, even if the BIOS
  1118. * is absent or just failing to do its job.
  1119. */
  1120. void intel_setup_bios(struct drm_device *dev)
  1121. {
  1122. struct drm_i915_private *dev_priv = dev->dev_private;
  1123. /* Set the Panel Power On/Off timings if uninitialized. */
  1124. if (!HAS_PCH_SPLIT(dev) &&
  1125. I915_READ(PP_ON_DELAYS) == 0 && I915_READ(PP_OFF_DELAYS) == 0) {
  1126. /* Set T2 to 40ms and T5 to 200ms */
  1127. I915_WRITE(PP_ON_DELAYS, 0x019007d0);
  1128. /* Set T3 to 35ms and Tx to 200ms */
  1129. I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);
  1130. }
  1131. }