intel_bios.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956
  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 < total) {
  48. current_id = *(base + index);
  49. index++;
  50. current_size = *((u16 *)(base + index));
  51. index += 2;
  52. if (current_id == section_id)
  53. return base + index;
  54. index += current_size;
  55. }
  56. return NULL;
  57. }
  58. static u16
  59. get_blocksize(void *p)
  60. {
  61. u16 *block_ptr, block_size;
  62. block_ptr = (u16 *)((char *)p - 2);
  63. block_size = *block_ptr;
  64. return block_size;
  65. }
  66. static void
  67. fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
  68. const struct lvds_dvo_timing *dvo_timing)
  69. {
  70. panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
  71. dvo_timing->hactive_lo;
  72. panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
  73. ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
  74. panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
  75. dvo_timing->hsync_pulse_width;
  76. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  77. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  78. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  79. dvo_timing->vactive_lo;
  80. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  81. dvo_timing->vsync_off;
  82. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  83. dvo_timing->vsync_pulse_width;
  84. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  85. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  86. panel_fixed_mode->clock = dvo_timing->clock * 10;
  87. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  88. if (dvo_timing->hsync_positive)
  89. panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
  90. else
  91. panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
  92. if (dvo_timing->vsync_positive)
  93. panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
  94. else
  95. panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
  96. /* Some VBTs have bogus h/vtotal values */
  97. if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
  98. panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
  99. if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
  100. panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
  101. drm_mode_set_name(panel_fixed_mode);
  102. }
  103. static bool
  104. lvds_dvo_timing_equal_size(const struct lvds_dvo_timing *a,
  105. const struct lvds_dvo_timing *b)
  106. {
  107. if (a->hactive_hi != b->hactive_hi ||
  108. a->hactive_lo != b->hactive_lo)
  109. return false;
  110. if (a->hsync_off_hi != b->hsync_off_hi ||
  111. a->hsync_off_lo != b->hsync_off_lo)
  112. return false;
  113. if (a->hsync_pulse_width != b->hsync_pulse_width)
  114. return false;
  115. if (a->hblank_hi != b->hblank_hi ||
  116. a->hblank_lo != b->hblank_lo)
  117. return false;
  118. if (a->vactive_hi != b->vactive_hi ||
  119. a->vactive_lo != b->vactive_lo)
  120. return false;
  121. if (a->vsync_off != b->vsync_off)
  122. return false;
  123. if (a->vsync_pulse_width != b->vsync_pulse_width)
  124. return false;
  125. if (a->vblank_hi != b->vblank_hi ||
  126. a->vblank_lo != b->vblank_lo)
  127. return false;
  128. return true;
  129. }
  130. static const struct lvds_dvo_timing *
  131. get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
  132. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
  133. int index)
  134. {
  135. /*
  136. * the size of fp_timing varies on the different platform.
  137. * So calculate the DVO timing relative offset in LVDS data
  138. * entry to get the DVO timing entry
  139. */
  140. int lfp_data_size =
  141. lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
  142. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
  143. int dvo_timing_offset =
  144. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
  145. lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
  146. char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
  147. return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
  148. }
  149. /* get lvds_fp_timing entry
  150. * this function may return NULL if the corresponding entry is invalid
  151. */
  152. static const struct lvds_fp_timing *
  153. get_lvds_fp_timing(const struct bdb_header *bdb,
  154. const struct bdb_lvds_lfp_data *data,
  155. const struct bdb_lvds_lfp_data_ptrs *ptrs,
  156. int index)
  157. {
  158. size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
  159. u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
  160. size_t ofs;
  161. if (index >= ARRAY_SIZE(ptrs->ptr))
  162. return NULL;
  163. ofs = ptrs->ptr[index].fp_timing_offset;
  164. if (ofs < data_ofs ||
  165. ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
  166. return NULL;
  167. return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
  168. }
  169. /* Try to find integrated panel data */
  170. static void
  171. parse_lfp_panel_data(struct drm_i915_private *dev_priv,
  172. struct bdb_header *bdb)
  173. {
  174. const struct bdb_lvds_options *lvds_options;
  175. const struct bdb_lvds_lfp_data *lvds_lfp_data;
  176. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
  177. const struct lvds_dvo_timing *panel_dvo_timing;
  178. const struct lvds_fp_timing *fp_timing;
  179. struct drm_display_mode *panel_fixed_mode;
  180. int i, downclock;
  181. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  182. if (!lvds_options)
  183. return;
  184. dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
  185. if (lvds_options->panel_type == 0xff)
  186. return;
  187. panel_type = lvds_options->panel_type;
  188. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  189. if (!lvds_lfp_data)
  190. return;
  191. lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
  192. if (!lvds_lfp_data_ptrs)
  193. return;
  194. dev_priv->vbt.lvds_vbt = 1;
  195. panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
  196. lvds_lfp_data_ptrs,
  197. lvds_options->panel_type);
  198. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  199. if (!panel_fixed_mode)
  200. return;
  201. fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
  202. dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
  203. DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
  204. drm_mode_debug_printmodeline(panel_fixed_mode);
  205. /*
  206. * Iterate over the LVDS panel timing info to find the lowest clock
  207. * for the native resolution.
  208. */
  209. downclock = panel_dvo_timing->clock;
  210. for (i = 0; i < 16; i++) {
  211. const struct lvds_dvo_timing *dvo_timing;
  212. dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
  213. lvds_lfp_data_ptrs,
  214. i);
  215. if (lvds_dvo_timing_equal_size(dvo_timing, panel_dvo_timing) &&
  216. dvo_timing->clock < downclock)
  217. downclock = dvo_timing->clock;
  218. }
  219. if (downclock < panel_dvo_timing->clock && i915_lvds_downclock) {
  220. dev_priv->lvds_downclock_avail = 1;
  221. dev_priv->lvds_downclock = downclock * 10;
  222. DRM_DEBUG_KMS("LVDS downclock is found in VBT. "
  223. "Normal Clock %dKHz, downclock %dKHz\n",
  224. panel_fixed_mode->clock, 10*downclock);
  225. }
  226. fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
  227. lvds_lfp_data_ptrs,
  228. lvds_options->panel_type);
  229. if (fp_timing) {
  230. /* check the resolution, just to be sure */
  231. if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
  232. fp_timing->y_res == panel_fixed_mode->vdisplay) {
  233. dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
  234. DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
  235. dev_priv->vbt.bios_lvds_val);
  236. }
  237. }
  238. }
  239. static void
  240. parse_lfp_backlight(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  241. {
  242. const struct bdb_lfp_backlight_data *backlight_data;
  243. const struct bdb_lfp_backlight_data_entry *entry;
  244. backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
  245. if (!backlight_data)
  246. return;
  247. if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
  248. DRM_DEBUG_KMS("Unsupported backlight data entry size %u\n",
  249. backlight_data->entry_size);
  250. return;
  251. }
  252. entry = &backlight_data->data[panel_type];
  253. dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
  254. dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
  255. DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
  256. "active %s, min brightness %u, level %u\n",
  257. dev_priv->vbt.backlight.pwm_freq_hz,
  258. dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
  259. entry->min_brightness,
  260. backlight_data->level[panel_type]);
  261. }
  262. /* Try to find sdvo panel data */
  263. static void
  264. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  265. struct bdb_header *bdb)
  266. {
  267. struct lvds_dvo_timing *dvo_timing;
  268. struct drm_display_mode *panel_fixed_mode;
  269. int index;
  270. index = i915_vbt_sdvo_panel_type;
  271. if (index == -2) {
  272. DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
  273. return;
  274. }
  275. if (index == -1) {
  276. struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  277. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  278. if (!sdvo_lvds_options)
  279. return;
  280. index = sdvo_lvds_options->panel_type;
  281. }
  282. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  283. if (!dvo_timing)
  284. return;
  285. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  286. if (!panel_fixed_mode)
  287. return;
  288. fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
  289. dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
  290. DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
  291. drm_mode_debug_printmodeline(panel_fixed_mode);
  292. }
  293. static int intel_bios_ssc_frequency(struct drm_device *dev,
  294. bool alternate)
  295. {
  296. switch (INTEL_INFO(dev)->gen) {
  297. case 2:
  298. return alternate ? 66667 : 48000;
  299. case 3:
  300. case 4:
  301. return alternate ? 100000 : 96000;
  302. default:
  303. return alternate ? 100000 : 120000;
  304. }
  305. }
  306. static void
  307. parse_general_features(struct drm_i915_private *dev_priv,
  308. struct bdb_header *bdb)
  309. {
  310. struct drm_device *dev = dev_priv->dev;
  311. struct bdb_general_features *general;
  312. general = find_section(bdb, BDB_GENERAL_FEATURES);
  313. if (general) {
  314. dev_priv->vbt.int_tv_support = general->int_tv_support;
  315. dev_priv->vbt.int_crt_support = general->int_crt_support;
  316. dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
  317. dev_priv->vbt.lvds_ssc_freq =
  318. intel_bios_ssc_frequency(dev, general->ssc_freq);
  319. dev_priv->vbt.display_clock_mode = general->display_clock_mode;
  320. dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
  321. 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",
  322. dev_priv->vbt.int_tv_support,
  323. dev_priv->vbt.int_crt_support,
  324. dev_priv->vbt.lvds_use_ssc,
  325. dev_priv->vbt.lvds_ssc_freq,
  326. dev_priv->vbt.display_clock_mode,
  327. dev_priv->vbt.fdi_rx_polarity_inverted);
  328. }
  329. }
  330. static void
  331. parse_general_definitions(struct drm_i915_private *dev_priv,
  332. struct bdb_header *bdb)
  333. {
  334. struct bdb_general_definitions *general;
  335. general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  336. if (general) {
  337. u16 block_size = get_blocksize(general);
  338. if (block_size >= sizeof(*general)) {
  339. int bus_pin = general->crt_ddc_gmbus_pin;
  340. DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
  341. if (intel_gmbus_is_port_valid(bus_pin))
  342. dev_priv->vbt.crt_ddc_pin = bus_pin;
  343. } else {
  344. DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
  345. block_size);
  346. }
  347. }
  348. }
  349. static void
  350. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  351. struct bdb_header *bdb)
  352. {
  353. struct sdvo_device_mapping *p_mapping;
  354. struct bdb_general_definitions *p_defs;
  355. union child_device_config *p_child;
  356. int i, child_device_num, count;
  357. u16 block_size;
  358. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  359. if (!p_defs) {
  360. DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
  361. return;
  362. }
  363. /* judge whether the size of child device meets the requirements.
  364. * If the child device size obtained from general definition block
  365. * is different with sizeof(struct child_device_config), skip the
  366. * parsing of sdvo device info
  367. */
  368. if (p_defs->child_dev_size != sizeof(*p_child)) {
  369. /* different child dev size . Ignore it */
  370. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  371. return;
  372. }
  373. /* get the block size of general definitions */
  374. block_size = get_blocksize(p_defs);
  375. /* get the number of child device */
  376. child_device_num = (block_size - sizeof(*p_defs)) /
  377. sizeof(*p_child);
  378. count = 0;
  379. for (i = 0; i < child_device_num; i++) {
  380. p_child = &(p_defs->devices[i]);
  381. if (!p_child->old.device_type) {
  382. /* skip the device block if device type is invalid */
  383. continue;
  384. }
  385. if (p_child->old.slave_addr != SLAVE_ADDR1 &&
  386. p_child->old.slave_addr != SLAVE_ADDR2) {
  387. /*
  388. * If the slave address is neither 0x70 nor 0x72,
  389. * it is not a SDVO device. Skip it.
  390. */
  391. continue;
  392. }
  393. if (p_child->old.dvo_port != DEVICE_PORT_DVOB &&
  394. p_child->old.dvo_port != DEVICE_PORT_DVOC) {
  395. /* skip the incorrect SDVO port */
  396. DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
  397. continue;
  398. }
  399. DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
  400. " %s port\n",
  401. p_child->old.slave_addr,
  402. (p_child->old.dvo_port == DEVICE_PORT_DVOB) ?
  403. "SDVOB" : "SDVOC");
  404. p_mapping = &(dev_priv->sdvo_mappings[p_child->old.dvo_port - 1]);
  405. if (!p_mapping->initialized) {
  406. p_mapping->dvo_port = p_child->old.dvo_port;
  407. p_mapping->slave_addr = p_child->old.slave_addr;
  408. p_mapping->dvo_wiring = p_child->old.dvo_wiring;
  409. p_mapping->ddc_pin = p_child->old.ddc_pin;
  410. p_mapping->i2c_pin = p_child->old.i2c_pin;
  411. p_mapping->initialized = 1;
  412. DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
  413. p_mapping->dvo_port,
  414. p_mapping->slave_addr,
  415. p_mapping->dvo_wiring,
  416. p_mapping->ddc_pin,
  417. p_mapping->i2c_pin);
  418. } else {
  419. DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
  420. "two SDVO device.\n");
  421. }
  422. if (p_child->old.slave2_addr) {
  423. /* Maybe this is a SDVO device with multiple inputs */
  424. /* And the mapping info is not added */
  425. DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
  426. " is a SDVO device with multiple inputs.\n");
  427. }
  428. count++;
  429. }
  430. if (!count) {
  431. /* No SDVO device info is found */
  432. DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
  433. }
  434. return;
  435. }
  436. static void
  437. parse_driver_features(struct drm_i915_private *dev_priv,
  438. struct bdb_header *bdb)
  439. {
  440. struct bdb_driver_features *driver;
  441. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  442. if (!driver)
  443. return;
  444. if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
  445. dev_priv->vbt.edp_support = 1;
  446. if (driver->dual_frequency)
  447. dev_priv->render_reclock_avail = true;
  448. }
  449. static void
  450. parse_edp(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  451. {
  452. struct bdb_edp *edp;
  453. struct edp_power_seq *edp_pps;
  454. struct edp_link_params *edp_link_params;
  455. edp = find_section(bdb, BDB_EDP);
  456. if (!edp) {
  457. if (dev_priv->vbt.edp_support)
  458. DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
  459. return;
  460. }
  461. switch ((edp->color_depth >> (panel_type * 2)) & 3) {
  462. case EDP_18BPP:
  463. dev_priv->vbt.edp_bpp = 18;
  464. break;
  465. case EDP_24BPP:
  466. dev_priv->vbt.edp_bpp = 24;
  467. break;
  468. case EDP_30BPP:
  469. dev_priv->vbt.edp_bpp = 30;
  470. break;
  471. }
  472. /* Get the eDP sequencing and link info */
  473. edp_pps = &edp->power_seqs[panel_type];
  474. edp_link_params = &edp->link_params[panel_type];
  475. dev_priv->vbt.edp_pps = *edp_pps;
  476. dev_priv->vbt.edp_rate = edp_link_params->rate ? DP_LINK_BW_2_7 :
  477. DP_LINK_BW_1_62;
  478. switch (edp_link_params->lanes) {
  479. case 0:
  480. dev_priv->vbt.edp_lanes = 1;
  481. break;
  482. case 1:
  483. dev_priv->vbt.edp_lanes = 2;
  484. break;
  485. case 3:
  486. default:
  487. dev_priv->vbt.edp_lanes = 4;
  488. break;
  489. }
  490. switch (edp_link_params->preemphasis) {
  491. case 0:
  492. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_0;
  493. break;
  494. case 1:
  495. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_3_5;
  496. break;
  497. case 2:
  498. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_6;
  499. break;
  500. case 3:
  501. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPHASIS_9_5;
  502. break;
  503. }
  504. switch (edp_link_params->vswing) {
  505. case 0:
  506. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_400;
  507. break;
  508. case 1:
  509. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_600;
  510. break;
  511. case 2:
  512. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_800;
  513. break;
  514. case 3:
  515. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_1200;
  516. break;
  517. }
  518. }
  519. static void
  520. parse_mipi(struct drm_i915_private *dev_priv, struct bdb_header *bdb)
  521. {
  522. struct bdb_mipi *mipi;
  523. mipi = find_section(bdb, BDB_MIPI);
  524. if (!mipi) {
  525. DRM_DEBUG_KMS("No MIPI BDB found");
  526. return;
  527. }
  528. /* XXX: add more info */
  529. dev_priv->vbt.dsi.panel_id = mipi->panel_id;
  530. }
  531. static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
  532. struct bdb_header *bdb)
  533. {
  534. union child_device_config *it, *child = NULL;
  535. struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
  536. uint8_t hdmi_level_shift;
  537. int i, j;
  538. bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
  539. uint8_t aux_channel;
  540. /* Each DDI port can have more than one value on the "DVO Port" field,
  541. * so look for all the possible values for each port and abort if more
  542. * than one is found. */
  543. int dvo_ports[][2] = {
  544. {DVO_PORT_HDMIA, DVO_PORT_DPA},
  545. {DVO_PORT_HDMIB, DVO_PORT_DPB},
  546. {DVO_PORT_HDMIC, DVO_PORT_DPC},
  547. {DVO_PORT_HDMID, DVO_PORT_DPD},
  548. {DVO_PORT_CRT, -1 /* Port E can only be DVO_PORT_CRT */ },
  549. };
  550. /* Find the child device to use, abort if more than one found. */
  551. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  552. it = dev_priv->vbt.child_dev + i;
  553. for (j = 0; j < 2; j++) {
  554. if (dvo_ports[port][j] == -1)
  555. break;
  556. if (it->common.dvo_port == dvo_ports[port][j]) {
  557. if (child) {
  558. DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
  559. port_name(port));
  560. return;
  561. }
  562. child = it;
  563. }
  564. }
  565. }
  566. if (!child)
  567. return;
  568. aux_channel = child->raw[25];
  569. is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
  570. is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
  571. is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
  572. is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
  573. is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
  574. info->supports_dvi = is_dvi;
  575. info->supports_hdmi = is_hdmi;
  576. info->supports_dp = is_dp;
  577. DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
  578. port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
  579. if (is_edp && is_dvi)
  580. DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
  581. port_name(port));
  582. if (is_crt && port != PORT_E)
  583. DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
  584. if (is_crt && (is_dvi || is_dp))
  585. DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
  586. port_name(port));
  587. if (is_dvi && (port == PORT_A || port == PORT_E))
  588. DRM_DEBUG_KMS("Port %c is TMDS compabile\n", port_name(port));
  589. if (!is_dvi && !is_dp && !is_crt)
  590. DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
  591. port_name(port));
  592. if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
  593. DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
  594. if (is_dvi) {
  595. if (child->common.ddc_pin == 0x05 && port != PORT_B)
  596. DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
  597. if (child->common.ddc_pin == 0x04 && port != PORT_C)
  598. DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
  599. if (child->common.ddc_pin == 0x06 && port != PORT_D)
  600. DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
  601. }
  602. if (is_dp) {
  603. if (aux_channel == 0x40 && port != PORT_A)
  604. DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
  605. if (aux_channel == 0x10 && port != PORT_B)
  606. DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
  607. if (aux_channel == 0x20 && port != PORT_C)
  608. DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
  609. if (aux_channel == 0x30 && port != PORT_D)
  610. DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
  611. }
  612. if (bdb->version >= 158) {
  613. /* The VBT HDMI level shift values match the table we have. */
  614. hdmi_level_shift = child->raw[7] & 0xF;
  615. if (hdmi_level_shift < 0xC) {
  616. DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
  617. port_name(port),
  618. hdmi_level_shift);
  619. info->hdmi_level_shift = hdmi_level_shift;
  620. }
  621. }
  622. }
  623. static void parse_ddi_ports(struct drm_i915_private *dev_priv,
  624. struct bdb_header *bdb)
  625. {
  626. struct drm_device *dev = dev_priv->dev;
  627. enum port port;
  628. if (!HAS_DDI(dev))
  629. return;
  630. if (!dev_priv->vbt.child_dev_num)
  631. return;
  632. if (bdb->version < 155)
  633. return;
  634. for (port = PORT_A; port < I915_MAX_PORTS; port++)
  635. parse_ddi_port(dev_priv, port, bdb);
  636. }
  637. static void
  638. parse_device_mapping(struct drm_i915_private *dev_priv,
  639. struct bdb_header *bdb)
  640. {
  641. struct bdb_general_definitions *p_defs;
  642. union child_device_config *p_child, *child_dev_ptr;
  643. int i, child_device_num, count;
  644. u16 block_size;
  645. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  646. if (!p_defs) {
  647. DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
  648. return;
  649. }
  650. /* judge whether the size of child device meets the requirements.
  651. * If the child device size obtained from general definition block
  652. * is different with sizeof(struct child_device_config), skip the
  653. * parsing of sdvo device info
  654. */
  655. if (p_defs->child_dev_size != sizeof(*p_child)) {
  656. /* different child dev size . Ignore it */
  657. DRM_DEBUG_KMS("different child size is found. Invalid.\n");
  658. return;
  659. }
  660. /* get the block size of general definitions */
  661. block_size = get_blocksize(p_defs);
  662. /* get the number of child device */
  663. child_device_num = (block_size - sizeof(*p_defs)) /
  664. sizeof(*p_child);
  665. count = 0;
  666. /* get the number of child device that is present */
  667. for (i = 0; i < child_device_num; i++) {
  668. p_child = &(p_defs->devices[i]);
  669. if (!p_child->common.device_type) {
  670. /* skip the device block if device type is invalid */
  671. continue;
  672. }
  673. count++;
  674. }
  675. if (!count) {
  676. DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
  677. return;
  678. }
  679. dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
  680. if (!dev_priv->vbt.child_dev) {
  681. DRM_DEBUG_KMS("No memory space for child device\n");
  682. return;
  683. }
  684. dev_priv->vbt.child_dev_num = count;
  685. count = 0;
  686. for (i = 0; i < child_device_num; i++) {
  687. p_child = &(p_defs->devices[i]);
  688. if (!p_child->common.device_type) {
  689. /* skip the device block if device type is invalid */
  690. continue;
  691. }
  692. child_dev_ptr = dev_priv->vbt.child_dev + count;
  693. count++;
  694. memcpy((void *)child_dev_ptr, (void *)p_child,
  695. sizeof(*p_child));
  696. }
  697. return;
  698. }
  699. static void
  700. init_vbt_defaults(struct drm_i915_private *dev_priv)
  701. {
  702. struct drm_device *dev = dev_priv->dev;
  703. enum port port;
  704. dev_priv->vbt.crt_ddc_pin = GMBUS_PORT_VGADDC;
  705. /* LFP panel data */
  706. dev_priv->vbt.lvds_dither = 1;
  707. dev_priv->vbt.lvds_vbt = 0;
  708. /* SDVO panel data */
  709. dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
  710. /* general features */
  711. dev_priv->vbt.int_tv_support = 1;
  712. dev_priv->vbt.int_crt_support = 1;
  713. /* Default to using SSC */
  714. dev_priv->vbt.lvds_use_ssc = 1;
  715. /*
  716. * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
  717. * clock for LVDS.
  718. */
  719. dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev,
  720. !HAS_PCH_SPLIT(dev));
  721. DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
  722. for (port = PORT_A; port < I915_MAX_PORTS; port++) {
  723. struct ddi_vbt_port_info *info =
  724. &dev_priv->vbt.ddi_port_info[port];
  725. /* Recommended BSpec default: 800mV 0dB. */
  726. info->hdmi_level_shift = 6;
  727. info->supports_dvi = (port != PORT_A && port != PORT_E);
  728. info->supports_hdmi = info->supports_dvi;
  729. info->supports_dp = (port != PORT_E);
  730. }
  731. }
  732. static int __init intel_no_opregion_vbt_callback(const struct dmi_system_id *id)
  733. {
  734. DRM_DEBUG_KMS("Falling back to manually reading VBT from "
  735. "VBIOS ROM for %s\n",
  736. id->ident);
  737. return 1;
  738. }
  739. static const struct dmi_system_id intel_no_opregion_vbt[] = {
  740. {
  741. .callback = intel_no_opregion_vbt_callback,
  742. .ident = "ThinkCentre A57",
  743. .matches = {
  744. DMI_MATCH(DMI_SYS_VENDOR, "LENOVO"),
  745. DMI_MATCH(DMI_PRODUCT_NAME, "97027RG"),
  746. },
  747. },
  748. { }
  749. };
  750. /**
  751. * intel_parse_bios - find VBT and initialize settings from the BIOS
  752. * @dev: DRM device
  753. *
  754. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  755. * to appropriate values.
  756. *
  757. * Returns 0 on success, nonzero on failure.
  758. */
  759. int
  760. intel_parse_bios(struct drm_device *dev)
  761. {
  762. struct drm_i915_private *dev_priv = dev->dev_private;
  763. struct pci_dev *pdev = dev->pdev;
  764. struct bdb_header *bdb = NULL;
  765. u8 __iomem *bios = NULL;
  766. if (HAS_PCH_NOP(dev))
  767. return -ENODEV;
  768. init_vbt_defaults(dev_priv);
  769. /* XXX Should this validation be moved to intel_opregion.c? */
  770. if (!dmi_check_system(intel_no_opregion_vbt) && dev_priv->opregion.vbt) {
  771. struct vbt_header *vbt = dev_priv->opregion.vbt;
  772. if (memcmp(vbt->signature, "$VBT", 4) == 0) {
  773. DRM_DEBUG_KMS("Using VBT from OpRegion: %20s\n",
  774. vbt->signature);
  775. bdb = (struct bdb_header *)((char *)vbt + vbt->bdb_offset);
  776. } else
  777. dev_priv->opregion.vbt = NULL;
  778. }
  779. if (bdb == NULL) {
  780. struct vbt_header *vbt = NULL;
  781. size_t size;
  782. int i;
  783. bios = pci_map_rom(pdev, &size);
  784. if (!bios)
  785. return -1;
  786. /* Scour memory looking for the VBT signature */
  787. for (i = 0; i + 4 < size; i++) {
  788. if (!memcmp(bios + i, "$VBT", 4)) {
  789. vbt = (struct vbt_header *)(bios + i);
  790. break;
  791. }
  792. }
  793. if (!vbt) {
  794. DRM_DEBUG_DRIVER("VBT signature missing\n");
  795. pci_unmap_rom(pdev, bios);
  796. return -1;
  797. }
  798. bdb = (struct bdb_header *)(bios + i + vbt->bdb_offset);
  799. }
  800. /* Grab useful general definitions */
  801. parse_general_features(dev_priv, bdb);
  802. parse_general_definitions(dev_priv, bdb);
  803. parse_lfp_panel_data(dev_priv, bdb);
  804. parse_lfp_backlight(dev_priv, bdb);
  805. parse_sdvo_panel_data(dev_priv, bdb);
  806. parse_sdvo_device_mapping(dev_priv, bdb);
  807. parse_device_mapping(dev_priv, bdb);
  808. parse_driver_features(dev_priv, bdb);
  809. parse_edp(dev_priv, bdb);
  810. parse_mipi(dev_priv, bdb);
  811. parse_ddi_ports(dev_priv, bdb);
  812. if (bios)
  813. pci_unmap_rom(pdev, bios);
  814. return 0;
  815. }
  816. /* Ensure that vital registers have been initialised, even if the BIOS
  817. * is absent or just failing to do its job.
  818. */
  819. void intel_setup_bios(struct drm_device *dev)
  820. {
  821. struct drm_i915_private *dev_priv = dev->dev_private;
  822. /* Set the Panel Power On/Off timings if uninitialized. */
  823. if (!HAS_PCH_SPLIT(dev) &&
  824. I915_READ(PP_ON_DELAYS) == 0 && I915_READ(PP_OFF_DELAYS) == 0) {
  825. /* Set T2 to 40ms and T5 to 200ms */
  826. I915_WRITE(PP_ON_DELAYS, 0x019007d0);
  827. /* Set T3 to 35ms and Tx to 200ms */
  828. I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);
  829. }
  830. }