intel_bios.c 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433
  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 <drm/drm_dp_helper.h>
  28. #include <drm/drmP.h>
  29. #include <drm/i915_drm.h>
  30. #include "i915_drv.h"
  31. #include "intel_bios.h"
  32. /**
  33. * DOC: Video BIOS Table (VBT)
  34. *
  35. * The Video BIOS Table, or VBT, provides platform and board specific
  36. * configuration information to the driver that is not discoverable or available
  37. * through other means. The configuration is mostly related to display
  38. * hardware. The VBT is available via the ACPI OpRegion or, on older systems, in
  39. * the PCI ROM.
  40. *
  41. * The VBT consists of a VBT Header (defined as &struct vbt_header), a BDB
  42. * Header (&struct bdb_header), and a number of BIOS Data Blocks (BDB) that
  43. * contain the actual configuration information. The VBT Header, and thus the
  44. * VBT, begins with "$VBT" signature. The VBT Header contains the offset of the
  45. * BDB Header. The data blocks are concatenated after the BDB Header. The data
  46. * blocks have a 1-byte Block ID, 2-byte Block Size, and Block Size bytes of
  47. * data. (Block 53, the MIPI Sequence Block is an exception.)
  48. *
  49. * The driver parses the VBT during load. The relevant information is stored in
  50. * driver private data for ease of use, and the actual VBT is not read after
  51. * that.
  52. */
  53. #define SLAVE_ADDR1 0x70
  54. #define SLAVE_ADDR2 0x72
  55. static int panel_type;
  56. /* Get BDB block size given a pointer to Block ID. */
  57. static u32 _get_blocksize(const u8 *block_base)
  58. {
  59. /* The MIPI Sequence Block v3+ has a separate size field. */
  60. if (*block_base == BDB_MIPI_SEQUENCE && *(block_base + 3) >= 3)
  61. return *((const u32 *)(block_base + 4));
  62. else
  63. return *((const u16 *)(block_base + 1));
  64. }
  65. /* Get BDB block size give a pointer to data after Block ID and Block Size. */
  66. static u32 get_blocksize(const void *block_data)
  67. {
  68. return _get_blocksize(block_data - 3);
  69. }
  70. static const void *
  71. find_section(const void *_bdb, int section_id)
  72. {
  73. const struct bdb_header *bdb = _bdb;
  74. const u8 *base = _bdb;
  75. int index = 0;
  76. u32 total, current_size;
  77. u8 current_id;
  78. /* skip to first section */
  79. index += bdb->header_size;
  80. total = bdb->bdb_size;
  81. /* walk the sections looking for section_id */
  82. while (index + 3 < total) {
  83. current_id = *(base + index);
  84. current_size = _get_blocksize(base + index);
  85. index += 3;
  86. if (index + current_size > total)
  87. return NULL;
  88. if (current_id == section_id)
  89. return base + index;
  90. index += current_size;
  91. }
  92. return NULL;
  93. }
  94. static void
  95. fill_detail_timing_data(struct drm_display_mode *panel_fixed_mode,
  96. const struct lvds_dvo_timing *dvo_timing)
  97. {
  98. panel_fixed_mode->hdisplay = (dvo_timing->hactive_hi << 8) |
  99. dvo_timing->hactive_lo;
  100. panel_fixed_mode->hsync_start = panel_fixed_mode->hdisplay +
  101. ((dvo_timing->hsync_off_hi << 8) | dvo_timing->hsync_off_lo);
  102. panel_fixed_mode->hsync_end = panel_fixed_mode->hsync_start +
  103. dvo_timing->hsync_pulse_width;
  104. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  105. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  106. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  107. dvo_timing->vactive_lo;
  108. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  109. dvo_timing->vsync_off;
  110. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  111. dvo_timing->vsync_pulse_width;
  112. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  113. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  114. panel_fixed_mode->clock = dvo_timing->clock * 10;
  115. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  116. if (dvo_timing->hsync_positive)
  117. panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
  118. else
  119. panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
  120. if (dvo_timing->vsync_positive)
  121. panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
  122. else
  123. panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
  124. /* Some VBTs have bogus h/vtotal values */
  125. if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
  126. panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
  127. if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
  128. panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
  129. drm_mode_set_name(panel_fixed_mode);
  130. }
  131. static const struct lvds_dvo_timing *
  132. get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
  133. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
  134. int index)
  135. {
  136. /*
  137. * the size of fp_timing varies on the different platform.
  138. * So calculate the DVO timing relative offset in LVDS data
  139. * entry to get the DVO timing entry
  140. */
  141. int lfp_data_size =
  142. lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
  143. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
  144. int dvo_timing_offset =
  145. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
  146. lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
  147. char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
  148. return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
  149. }
  150. /* get lvds_fp_timing entry
  151. * this function may return NULL if the corresponding entry is invalid
  152. */
  153. static const struct lvds_fp_timing *
  154. get_lvds_fp_timing(const struct bdb_header *bdb,
  155. const struct bdb_lvds_lfp_data *data,
  156. const struct bdb_lvds_lfp_data_ptrs *ptrs,
  157. int index)
  158. {
  159. size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
  160. u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
  161. size_t ofs;
  162. if (index >= ARRAY_SIZE(ptrs->ptr))
  163. return NULL;
  164. ofs = ptrs->ptr[index].fp_timing_offset;
  165. if (ofs < data_ofs ||
  166. ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
  167. return NULL;
  168. return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
  169. }
  170. /* Try to find integrated panel data */
  171. static void
  172. parse_lfp_panel_data(struct drm_i915_private *dev_priv,
  173. const struct bdb_header *bdb)
  174. {
  175. const struct bdb_lvds_options *lvds_options;
  176. const struct bdb_lvds_lfp_data *lvds_lfp_data;
  177. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
  178. const struct lvds_dvo_timing *panel_dvo_timing;
  179. const struct lvds_fp_timing *fp_timing;
  180. struct drm_display_mode *panel_fixed_mode;
  181. int drrs_mode;
  182. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  183. if (!lvds_options)
  184. return;
  185. dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
  186. if (lvds_options->panel_type == 0xff)
  187. return;
  188. panel_type = lvds_options->panel_type;
  189. drrs_mode = (lvds_options->dps_panel_type_bits
  190. >> (panel_type * 2)) & MODE_MASK;
  191. /*
  192. * VBT has static DRRS = 0 and seamless DRRS = 2.
  193. * The below piece of code is required to adjust vbt.drrs_type
  194. * to match the enum drrs_support_type.
  195. */
  196. switch (drrs_mode) {
  197. case 0:
  198. dev_priv->vbt.drrs_type = STATIC_DRRS_SUPPORT;
  199. DRM_DEBUG_KMS("DRRS supported mode is static\n");
  200. break;
  201. case 2:
  202. dev_priv->vbt.drrs_type = SEAMLESS_DRRS_SUPPORT;
  203. DRM_DEBUG_KMS("DRRS supported mode is seamless\n");
  204. break;
  205. default:
  206. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  207. DRM_DEBUG_KMS("DRRS not supported (VBT input)\n");
  208. break;
  209. }
  210. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  211. if (!lvds_lfp_data)
  212. return;
  213. lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
  214. if (!lvds_lfp_data_ptrs)
  215. return;
  216. dev_priv->vbt.lvds_vbt = 1;
  217. panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
  218. lvds_lfp_data_ptrs,
  219. lvds_options->panel_type);
  220. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  221. if (!panel_fixed_mode)
  222. return;
  223. fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
  224. dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
  225. DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
  226. drm_mode_debug_printmodeline(panel_fixed_mode);
  227. fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
  228. lvds_lfp_data_ptrs,
  229. lvds_options->panel_type);
  230. if (fp_timing) {
  231. /* check the resolution, just to be sure */
  232. if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
  233. fp_timing->y_res == panel_fixed_mode->vdisplay) {
  234. dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
  235. DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
  236. dev_priv->vbt.bios_lvds_val);
  237. }
  238. }
  239. }
  240. static void
  241. parse_lfp_backlight(struct drm_i915_private *dev_priv,
  242. const struct bdb_header *bdb)
  243. {
  244. const struct bdb_lfp_backlight_data *backlight_data;
  245. const struct bdb_lfp_backlight_data_entry *entry;
  246. backlight_data = find_section(bdb, BDB_LVDS_BACKLIGHT);
  247. if (!backlight_data)
  248. return;
  249. if (backlight_data->entry_size != sizeof(backlight_data->data[0])) {
  250. DRM_DEBUG_KMS("Unsupported backlight data entry size %u\n",
  251. backlight_data->entry_size);
  252. return;
  253. }
  254. entry = &backlight_data->data[panel_type];
  255. dev_priv->vbt.backlight.present = entry->type == BDB_BACKLIGHT_TYPE_PWM;
  256. if (!dev_priv->vbt.backlight.present) {
  257. DRM_DEBUG_KMS("PWM backlight not present in VBT (type %u)\n",
  258. entry->type);
  259. return;
  260. }
  261. dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
  262. dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
  263. dev_priv->vbt.backlight.min_brightness = entry->min_brightness;
  264. DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
  265. "active %s, min brightness %u, level %u\n",
  266. dev_priv->vbt.backlight.pwm_freq_hz,
  267. dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
  268. dev_priv->vbt.backlight.min_brightness,
  269. backlight_data->level[panel_type]);
  270. }
  271. /* Try to find sdvo panel data */
  272. static void
  273. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  274. const struct bdb_header *bdb)
  275. {
  276. const struct lvds_dvo_timing *dvo_timing;
  277. struct drm_display_mode *panel_fixed_mode;
  278. int index;
  279. index = i915.vbt_sdvo_panel_type;
  280. if (index == -2) {
  281. DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
  282. return;
  283. }
  284. if (index == -1) {
  285. const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  286. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  287. if (!sdvo_lvds_options)
  288. return;
  289. index = sdvo_lvds_options->panel_type;
  290. }
  291. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  292. if (!dvo_timing)
  293. return;
  294. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  295. if (!panel_fixed_mode)
  296. return;
  297. fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
  298. dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
  299. DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
  300. drm_mode_debug_printmodeline(panel_fixed_mode);
  301. }
  302. static int intel_bios_ssc_frequency(struct drm_i915_private *dev_priv,
  303. bool alternate)
  304. {
  305. switch (INTEL_INFO(dev_priv)->gen) {
  306. case 2:
  307. return alternate ? 66667 : 48000;
  308. case 3:
  309. case 4:
  310. return alternate ? 100000 : 96000;
  311. default:
  312. return alternate ? 100000 : 120000;
  313. }
  314. }
  315. static void
  316. parse_general_features(struct drm_i915_private *dev_priv,
  317. const struct bdb_header *bdb)
  318. {
  319. const struct bdb_general_features *general;
  320. general = find_section(bdb, BDB_GENERAL_FEATURES);
  321. if (!general)
  322. return;
  323. dev_priv->vbt.int_tv_support = general->int_tv_support;
  324. /* int_crt_support can't be trusted on earlier platforms */
  325. if (bdb->version >= 155 &&
  326. (HAS_DDI(dev_priv) || IS_VALLEYVIEW(dev_priv)))
  327. dev_priv->vbt.int_crt_support = general->int_crt_support;
  328. dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
  329. dev_priv->vbt.lvds_ssc_freq =
  330. intel_bios_ssc_frequency(dev_priv, general->ssc_freq);
  331. dev_priv->vbt.display_clock_mode = general->display_clock_mode;
  332. dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
  333. 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",
  334. dev_priv->vbt.int_tv_support,
  335. dev_priv->vbt.int_crt_support,
  336. dev_priv->vbt.lvds_use_ssc,
  337. dev_priv->vbt.lvds_ssc_freq,
  338. dev_priv->vbt.display_clock_mode,
  339. dev_priv->vbt.fdi_rx_polarity_inverted);
  340. }
  341. static void
  342. parse_general_definitions(struct drm_i915_private *dev_priv,
  343. const struct bdb_header *bdb)
  344. {
  345. const struct bdb_general_definitions *general;
  346. general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  347. if (general) {
  348. u16 block_size = get_blocksize(general);
  349. if (block_size >= sizeof(*general)) {
  350. int bus_pin = general->crt_ddc_gmbus_pin;
  351. DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
  352. if (intel_gmbus_is_valid_pin(dev_priv, bus_pin))
  353. dev_priv->vbt.crt_ddc_pin = bus_pin;
  354. } else {
  355. DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
  356. block_size);
  357. }
  358. }
  359. }
  360. static const union child_device_config *
  361. child_device_ptr(const struct bdb_general_definitions *p_defs, int i)
  362. {
  363. return (const void *) &p_defs->devices[i * p_defs->child_dev_size];
  364. }
  365. static void
  366. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  367. const struct bdb_header *bdb)
  368. {
  369. struct sdvo_device_mapping *p_mapping;
  370. const struct bdb_general_definitions *p_defs;
  371. const struct old_child_dev_config *child; /* legacy */
  372. int i, child_device_num, count;
  373. u16 block_size;
  374. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  375. if (!p_defs) {
  376. DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
  377. return;
  378. }
  379. /*
  380. * Only parse SDVO mappings when the general definitions block child
  381. * device size matches that of the *legacy* child device config
  382. * struct. Thus, SDVO mapping will be skipped for newer VBT.
  383. */
  384. if (p_defs->child_dev_size != sizeof(*child)) {
  385. DRM_DEBUG_KMS("Unsupported child device size for SDVO mapping.\n");
  386. return;
  387. }
  388. /* get the block size of general definitions */
  389. block_size = get_blocksize(p_defs);
  390. /* get the number of child device */
  391. child_device_num = (block_size - sizeof(*p_defs)) /
  392. p_defs->child_dev_size;
  393. count = 0;
  394. for (i = 0; i < child_device_num; i++) {
  395. child = &child_device_ptr(p_defs, i)->old;
  396. if (!child->device_type) {
  397. /* skip the device block if device type is invalid */
  398. continue;
  399. }
  400. if (child->slave_addr != SLAVE_ADDR1 &&
  401. child->slave_addr != SLAVE_ADDR2) {
  402. /*
  403. * If the slave address is neither 0x70 nor 0x72,
  404. * it is not a SDVO device. Skip it.
  405. */
  406. continue;
  407. }
  408. if (child->dvo_port != DEVICE_PORT_DVOB &&
  409. child->dvo_port != DEVICE_PORT_DVOC) {
  410. /* skip the incorrect SDVO port */
  411. DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
  412. continue;
  413. }
  414. DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
  415. " %s port\n",
  416. child->slave_addr,
  417. (child->dvo_port == DEVICE_PORT_DVOB) ?
  418. "SDVOB" : "SDVOC");
  419. p_mapping = &(dev_priv->sdvo_mappings[child->dvo_port - 1]);
  420. if (!p_mapping->initialized) {
  421. p_mapping->dvo_port = child->dvo_port;
  422. p_mapping->slave_addr = child->slave_addr;
  423. p_mapping->dvo_wiring = child->dvo_wiring;
  424. p_mapping->ddc_pin = child->ddc_pin;
  425. p_mapping->i2c_pin = child->i2c_pin;
  426. p_mapping->initialized = 1;
  427. DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
  428. p_mapping->dvo_port,
  429. p_mapping->slave_addr,
  430. p_mapping->dvo_wiring,
  431. p_mapping->ddc_pin,
  432. p_mapping->i2c_pin);
  433. } else {
  434. DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
  435. "two SDVO device.\n");
  436. }
  437. if (child->slave2_addr) {
  438. /* Maybe this is a SDVO device with multiple inputs */
  439. /* And the mapping info is not added */
  440. DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
  441. " is a SDVO device with multiple inputs.\n");
  442. }
  443. count++;
  444. }
  445. if (!count) {
  446. /* No SDVO device info is found */
  447. DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
  448. }
  449. return;
  450. }
  451. static void
  452. parse_driver_features(struct drm_i915_private *dev_priv,
  453. const struct bdb_header *bdb)
  454. {
  455. const struct bdb_driver_features *driver;
  456. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  457. if (!driver)
  458. return;
  459. if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
  460. dev_priv->vbt.edp_support = 1;
  461. if (driver->dual_frequency)
  462. dev_priv->render_reclock_avail = true;
  463. DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
  464. /*
  465. * If DRRS is not supported, drrs_type has to be set to 0.
  466. * This is because, VBT is configured in such a way that
  467. * static DRRS is 0 and DRRS not supported is represented by
  468. * driver->drrs_enabled=false
  469. */
  470. if (!driver->drrs_enabled)
  471. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  472. }
  473. static void
  474. parse_edp(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
  475. {
  476. const struct bdb_edp *edp;
  477. const struct edp_power_seq *edp_pps;
  478. const struct edp_link_params *edp_link_params;
  479. edp = find_section(bdb, BDB_EDP);
  480. if (!edp) {
  481. if (dev_priv->vbt.edp_support)
  482. DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
  483. return;
  484. }
  485. switch ((edp->color_depth >> (panel_type * 2)) & 3) {
  486. case EDP_18BPP:
  487. dev_priv->vbt.edp_bpp = 18;
  488. break;
  489. case EDP_24BPP:
  490. dev_priv->vbt.edp_bpp = 24;
  491. break;
  492. case EDP_30BPP:
  493. dev_priv->vbt.edp_bpp = 30;
  494. break;
  495. }
  496. /* Get the eDP sequencing and link info */
  497. edp_pps = &edp->power_seqs[panel_type];
  498. edp_link_params = &edp->link_params[panel_type];
  499. dev_priv->vbt.edp_pps = *edp_pps;
  500. switch (edp_link_params->rate) {
  501. case EDP_RATE_1_62:
  502. dev_priv->vbt.edp_rate = DP_LINK_BW_1_62;
  503. break;
  504. case EDP_RATE_2_7:
  505. dev_priv->vbt.edp_rate = DP_LINK_BW_2_7;
  506. break;
  507. default:
  508. DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
  509. edp_link_params->rate);
  510. break;
  511. }
  512. switch (edp_link_params->lanes) {
  513. case EDP_LANE_1:
  514. dev_priv->vbt.edp_lanes = 1;
  515. break;
  516. case EDP_LANE_2:
  517. dev_priv->vbt.edp_lanes = 2;
  518. break;
  519. case EDP_LANE_4:
  520. dev_priv->vbt.edp_lanes = 4;
  521. break;
  522. default:
  523. DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
  524. edp_link_params->lanes);
  525. break;
  526. }
  527. switch (edp_link_params->preemphasis) {
  528. case EDP_PREEMPHASIS_NONE:
  529. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
  530. break;
  531. case EDP_PREEMPHASIS_3_5dB:
  532. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
  533. break;
  534. case EDP_PREEMPHASIS_6dB:
  535. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
  536. break;
  537. case EDP_PREEMPHASIS_9_5dB:
  538. dev_priv->vbt.edp_preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
  539. break;
  540. default:
  541. DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
  542. edp_link_params->preemphasis);
  543. break;
  544. }
  545. switch (edp_link_params->vswing) {
  546. case EDP_VSWING_0_4V:
  547. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
  548. break;
  549. case EDP_VSWING_0_6V:
  550. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
  551. break;
  552. case EDP_VSWING_0_8V:
  553. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  554. break;
  555. case EDP_VSWING_1_2V:
  556. dev_priv->vbt.edp_vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  557. break;
  558. default:
  559. DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
  560. edp_link_params->vswing);
  561. break;
  562. }
  563. if (bdb->version >= 173) {
  564. uint8_t vswing;
  565. /* Don't read from VBT if module parameter has valid value*/
  566. if (i915.edp_vswing) {
  567. dev_priv->edp_low_vswing = i915.edp_vswing == 1;
  568. } else {
  569. vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
  570. dev_priv->edp_low_vswing = vswing == 0;
  571. }
  572. }
  573. }
  574. static void
  575. parse_psr(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
  576. {
  577. const struct bdb_psr *psr;
  578. const struct psr_table *psr_table;
  579. psr = find_section(bdb, BDB_PSR);
  580. if (!psr) {
  581. DRM_DEBUG_KMS("No PSR BDB found.\n");
  582. return;
  583. }
  584. psr_table = &psr->psr_table[panel_type];
  585. dev_priv->vbt.psr.full_link = psr_table->full_link;
  586. dev_priv->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
  587. /* Allowed VBT values goes from 0 to 15 */
  588. dev_priv->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
  589. psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
  590. switch (psr_table->lines_to_wait) {
  591. case 0:
  592. dev_priv->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
  593. break;
  594. case 1:
  595. dev_priv->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
  596. break;
  597. case 2:
  598. dev_priv->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
  599. break;
  600. case 3:
  601. dev_priv->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
  602. break;
  603. default:
  604. DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
  605. psr_table->lines_to_wait);
  606. break;
  607. }
  608. dev_priv->vbt.psr.tp1_wakeup_time = psr_table->tp1_wakeup_time;
  609. dev_priv->vbt.psr.tp2_tp3_wakeup_time = psr_table->tp2_tp3_wakeup_time;
  610. }
  611. static void
  612. parse_mipi_config(struct drm_i915_private *dev_priv,
  613. const struct bdb_header *bdb)
  614. {
  615. const struct bdb_mipi_config *start;
  616. const struct mipi_config *config;
  617. const struct mipi_pps_data *pps;
  618. /* parse MIPI blocks only if LFP type is MIPI */
  619. if (!dev_priv->vbt.has_mipi)
  620. return;
  621. /* Initialize this to undefined indicating no generic MIPI support */
  622. dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
  623. /* Block #40 is already parsed and panel_fixed_mode is
  624. * stored in dev_priv->lfp_lvds_vbt_mode
  625. * resuse this when needed
  626. */
  627. /* Parse #52 for panel index used from panel_type already
  628. * parsed
  629. */
  630. start = find_section(bdb, BDB_MIPI_CONFIG);
  631. if (!start) {
  632. DRM_DEBUG_KMS("No MIPI config BDB found");
  633. return;
  634. }
  635. DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
  636. panel_type);
  637. /*
  638. * get hold of the correct configuration block and pps data as per
  639. * the panel_type as index
  640. */
  641. config = &start->config[panel_type];
  642. pps = &start->pps[panel_type];
  643. /* store as of now full data. Trim when we realise all is not needed */
  644. dev_priv->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
  645. if (!dev_priv->vbt.dsi.config)
  646. return;
  647. dev_priv->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
  648. if (!dev_priv->vbt.dsi.pps) {
  649. kfree(dev_priv->vbt.dsi.config);
  650. return;
  651. }
  652. /* We have mandatory mipi config blocks. Initialize as generic panel */
  653. dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
  654. }
  655. /* Find the sequence block and size for the given panel. */
  656. static const u8 *
  657. find_panel_sequence_block(const struct bdb_mipi_sequence *sequence,
  658. u16 panel_id, u32 *seq_size)
  659. {
  660. u32 total = get_blocksize(sequence);
  661. const u8 *data = &sequence->data[0];
  662. u8 current_id;
  663. u32 current_size;
  664. int header_size = sequence->version >= 3 ? 5 : 3;
  665. int index = 0;
  666. int i;
  667. /* skip new block size */
  668. if (sequence->version >= 3)
  669. data += 4;
  670. for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index < total; i++) {
  671. if (index + header_size > total) {
  672. DRM_ERROR("Invalid sequence block (header)\n");
  673. return NULL;
  674. }
  675. current_id = *(data + index);
  676. if (sequence->version >= 3)
  677. current_size = *((const u32 *)(data + index + 1));
  678. else
  679. current_size = *((const u16 *)(data + index + 1));
  680. index += header_size;
  681. if (index + current_size > total) {
  682. DRM_ERROR("Invalid sequence block\n");
  683. return NULL;
  684. }
  685. if (current_id == panel_id) {
  686. *seq_size = current_size;
  687. return data + index;
  688. }
  689. index += current_size;
  690. }
  691. DRM_ERROR("Sequence block detected but no valid configuration\n");
  692. return NULL;
  693. }
  694. static int goto_next_sequence(const u8 *data, int index, int total)
  695. {
  696. u16 len;
  697. /* Skip Sequence Byte. */
  698. for (index = index + 1; index < total; index += len) {
  699. u8 operation_byte = *(data + index);
  700. index++;
  701. switch (operation_byte) {
  702. case MIPI_SEQ_ELEM_END:
  703. return index;
  704. case MIPI_SEQ_ELEM_SEND_PKT:
  705. if (index + 4 > total)
  706. return 0;
  707. len = *((const u16 *)(data + index + 2)) + 4;
  708. break;
  709. case MIPI_SEQ_ELEM_DELAY:
  710. len = 4;
  711. break;
  712. case MIPI_SEQ_ELEM_GPIO:
  713. len = 2;
  714. break;
  715. case MIPI_SEQ_ELEM_I2C:
  716. if (index + 7 > total)
  717. return 0;
  718. len = *(data + index + 6) + 7;
  719. break;
  720. default:
  721. DRM_ERROR("Unknown operation byte\n");
  722. return 0;
  723. }
  724. }
  725. return 0;
  726. }
  727. static int goto_next_sequence_v3(const u8 *data, int index, int total)
  728. {
  729. int seq_end;
  730. u16 len;
  731. u32 size_of_sequence;
  732. /*
  733. * Could skip sequence based on Size of Sequence alone, but also do some
  734. * checking on the structure.
  735. */
  736. if (total < 5) {
  737. DRM_ERROR("Too small sequence size\n");
  738. return 0;
  739. }
  740. /* Skip Sequence Byte. */
  741. index++;
  742. /*
  743. * Size of Sequence. Excludes the Sequence Byte and the size itself,
  744. * includes MIPI_SEQ_ELEM_END byte, excludes the final MIPI_SEQ_END
  745. * byte.
  746. */
  747. size_of_sequence = *((const uint32_t *)(data + index));
  748. index += 4;
  749. seq_end = index + size_of_sequence;
  750. if (seq_end > total) {
  751. DRM_ERROR("Invalid sequence size\n");
  752. return 0;
  753. }
  754. for (; index < total; index += len) {
  755. u8 operation_byte = *(data + index);
  756. index++;
  757. if (operation_byte == MIPI_SEQ_ELEM_END) {
  758. if (index != seq_end) {
  759. DRM_ERROR("Invalid element structure\n");
  760. return 0;
  761. }
  762. return index;
  763. }
  764. len = *(data + index);
  765. index++;
  766. /*
  767. * FIXME: Would be nice to check elements like for v1/v2 in
  768. * goto_next_sequence() above.
  769. */
  770. switch (operation_byte) {
  771. case MIPI_SEQ_ELEM_SEND_PKT:
  772. case MIPI_SEQ_ELEM_DELAY:
  773. case MIPI_SEQ_ELEM_GPIO:
  774. case MIPI_SEQ_ELEM_I2C:
  775. case MIPI_SEQ_ELEM_SPI:
  776. case MIPI_SEQ_ELEM_PMIC:
  777. break;
  778. default:
  779. DRM_ERROR("Unknown operation byte %u\n",
  780. operation_byte);
  781. break;
  782. }
  783. }
  784. return 0;
  785. }
  786. static void
  787. parse_mipi_sequence(struct drm_i915_private *dev_priv,
  788. const struct bdb_header *bdb)
  789. {
  790. const struct bdb_mipi_sequence *sequence;
  791. const u8 *seq_data;
  792. u32 seq_size;
  793. u8 *data;
  794. int index = 0;
  795. /* Only our generic panel driver uses the sequence block. */
  796. if (dev_priv->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
  797. return;
  798. sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
  799. if (!sequence) {
  800. DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
  801. return;
  802. }
  803. /* Fail gracefully for forward incompatible sequence block. */
  804. if (sequence->version >= 4) {
  805. DRM_ERROR("Unable to parse MIPI Sequence Block v%u\n",
  806. sequence->version);
  807. return;
  808. }
  809. DRM_DEBUG_DRIVER("Found MIPI sequence block v%u\n", sequence->version);
  810. seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size);
  811. if (!seq_data)
  812. return;
  813. data = kmemdup(seq_data, seq_size, GFP_KERNEL);
  814. if (!data)
  815. return;
  816. /* Parse the sequences, store pointers to each sequence. */
  817. for (;;) {
  818. u8 seq_id = *(data + index);
  819. if (seq_id == MIPI_SEQ_END)
  820. break;
  821. if (seq_id >= MIPI_SEQ_MAX) {
  822. DRM_ERROR("Unknown sequence %u\n", seq_id);
  823. goto err;
  824. }
  825. dev_priv->vbt.dsi.sequence[seq_id] = data + index;
  826. if (sequence->version >= 3)
  827. index = goto_next_sequence_v3(data, index, seq_size);
  828. else
  829. index = goto_next_sequence(data, index, seq_size);
  830. if (!index) {
  831. DRM_ERROR("Invalid sequence %u\n", seq_id);
  832. goto err;
  833. }
  834. }
  835. dev_priv->vbt.dsi.data = data;
  836. dev_priv->vbt.dsi.size = seq_size;
  837. dev_priv->vbt.dsi.seq_version = sequence->version;
  838. DRM_DEBUG_DRIVER("MIPI related VBT parsing complete\n");
  839. return;
  840. err:
  841. kfree(data);
  842. memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
  843. }
  844. static u8 translate_iboost(u8 val)
  845. {
  846. static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
  847. if (val >= ARRAY_SIZE(mapping)) {
  848. DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
  849. return 0;
  850. }
  851. return mapping[val];
  852. }
  853. static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
  854. const struct bdb_header *bdb)
  855. {
  856. union child_device_config *it, *child = NULL;
  857. struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
  858. uint8_t hdmi_level_shift;
  859. int i, j;
  860. bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
  861. uint8_t aux_channel, ddc_pin;
  862. /* Each DDI port can have more than one value on the "DVO Port" field,
  863. * so look for all the possible values for each port and abort if more
  864. * than one is found. */
  865. int dvo_ports[][3] = {
  866. {DVO_PORT_HDMIA, DVO_PORT_DPA, -1},
  867. {DVO_PORT_HDMIB, DVO_PORT_DPB, -1},
  868. {DVO_PORT_HDMIC, DVO_PORT_DPC, -1},
  869. {DVO_PORT_HDMID, DVO_PORT_DPD, -1},
  870. {DVO_PORT_CRT, DVO_PORT_HDMIE, DVO_PORT_DPE},
  871. };
  872. /* Find the child device to use, abort if more than one found. */
  873. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  874. it = dev_priv->vbt.child_dev + i;
  875. for (j = 0; j < 3; j++) {
  876. if (dvo_ports[port][j] == -1)
  877. break;
  878. if (it->common.dvo_port == dvo_ports[port][j]) {
  879. if (child) {
  880. DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
  881. port_name(port));
  882. return;
  883. }
  884. child = it;
  885. }
  886. }
  887. }
  888. if (!child)
  889. return;
  890. aux_channel = child->raw[25];
  891. ddc_pin = child->common.ddc_pin;
  892. is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
  893. is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
  894. is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
  895. is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
  896. is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
  897. info->supports_dvi = is_dvi;
  898. info->supports_hdmi = is_hdmi;
  899. info->supports_dp = is_dp;
  900. DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
  901. port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
  902. if (is_edp && is_dvi)
  903. DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
  904. port_name(port));
  905. if (is_crt && port != PORT_E)
  906. DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
  907. if (is_crt && (is_dvi || is_dp))
  908. DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
  909. port_name(port));
  910. if (is_dvi && (port == PORT_A || port == PORT_E))
  911. DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port));
  912. if (!is_dvi && !is_dp && !is_crt)
  913. DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
  914. port_name(port));
  915. if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
  916. DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
  917. if (is_dvi) {
  918. if (port == PORT_E) {
  919. info->alternate_ddc_pin = ddc_pin;
  920. /* if DDIE share ddc pin with other port, then
  921. * dvi/hdmi couldn't exist on the shared port.
  922. * Otherwise they share the same ddc bin and system
  923. * couldn't communicate with them seperately. */
  924. if (ddc_pin == DDC_PIN_B) {
  925. dev_priv->vbt.ddi_port_info[PORT_B].supports_dvi = 0;
  926. dev_priv->vbt.ddi_port_info[PORT_B].supports_hdmi = 0;
  927. } else if (ddc_pin == DDC_PIN_C) {
  928. dev_priv->vbt.ddi_port_info[PORT_C].supports_dvi = 0;
  929. dev_priv->vbt.ddi_port_info[PORT_C].supports_hdmi = 0;
  930. } else if (ddc_pin == DDC_PIN_D) {
  931. dev_priv->vbt.ddi_port_info[PORT_D].supports_dvi = 0;
  932. dev_priv->vbt.ddi_port_info[PORT_D].supports_hdmi = 0;
  933. }
  934. } else if (ddc_pin == DDC_PIN_B && port != PORT_B)
  935. DRM_DEBUG_KMS("Unexpected DDC pin for port B\n");
  936. else if (ddc_pin == DDC_PIN_C && port != PORT_C)
  937. DRM_DEBUG_KMS("Unexpected DDC pin for port C\n");
  938. else if (ddc_pin == DDC_PIN_D && port != PORT_D)
  939. DRM_DEBUG_KMS("Unexpected DDC pin for port D\n");
  940. }
  941. if (is_dp) {
  942. if (port == PORT_E) {
  943. info->alternate_aux_channel = aux_channel;
  944. /* if DDIE share aux channel with other port, then
  945. * DP couldn't exist on the shared port. Otherwise
  946. * they share the same aux channel and system
  947. * couldn't communicate with them seperately. */
  948. if (aux_channel == DP_AUX_A)
  949. dev_priv->vbt.ddi_port_info[PORT_A].supports_dp = 0;
  950. else if (aux_channel == DP_AUX_B)
  951. dev_priv->vbt.ddi_port_info[PORT_B].supports_dp = 0;
  952. else if (aux_channel == DP_AUX_C)
  953. dev_priv->vbt.ddi_port_info[PORT_C].supports_dp = 0;
  954. else if (aux_channel == DP_AUX_D)
  955. dev_priv->vbt.ddi_port_info[PORT_D].supports_dp = 0;
  956. }
  957. else if (aux_channel == DP_AUX_A && port != PORT_A)
  958. DRM_DEBUG_KMS("Unexpected AUX channel for port A\n");
  959. else if (aux_channel == DP_AUX_B && port != PORT_B)
  960. DRM_DEBUG_KMS("Unexpected AUX channel for port B\n");
  961. else if (aux_channel == DP_AUX_C && port != PORT_C)
  962. DRM_DEBUG_KMS("Unexpected AUX channel for port C\n");
  963. else if (aux_channel == DP_AUX_D && port != PORT_D)
  964. DRM_DEBUG_KMS("Unexpected AUX channel for port D\n");
  965. }
  966. if (bdb->version >= 158) {
  967. /* The VBT HDMI level shift values match the table we have. */
  968. hdmi_level_shift = child->raw[7] & 0xF;
  969. DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
  970. port_name(port),
  971. hdmi_level_shift);
  972. info->hdmi_level_shift = hdmi_level_shift;
  973. }
  974. /* Parse the I_boost config for SKL and above */
  975. if (bdb->version >= 196 && (child->common.flags_1 & IBOOST_ENABLE)) {
  976. info->dp_boost_level = translate_iboost(child->common.iboost_level & 0xF);
  977. DRM_DEBUG_KMS("VBT (e)DP boost level for port %c: %d\n",
  978. port_name(port), info->dp_boost_level);
  979. info->hdmi_boost_level = translate_iboost(child->common.iboost_level >> 4);
  980. DRM_DEBUG_KMS("VBT HDMI boost level for port %c: %d\n",
  981. port_name(port), info->hdmi_boost_level);
  982. }
  983. }
  984. static void parse_ddi_ports(struct drm_i915_private *dev_priv,
  985. const struct bdb_header *bdb)
  986. {
  987. enum port port;
  988. if (!HAS_DDI(dev_priv))
  989. return;
  990. if (!dev_priv->vbt.child_dev_num)
  991. return;
  992. if (bdb->version < 155)
  993. return;
  994. for (port = PORT_A; port < I915_MAX_PORTS; port++)
  995. parse_ddi_port(dev_priv, port, bdb);
  996. }
  997. static void
  998. parse_device_mapping(struct drm_i915_private *dev_priv,
  999. const struct bdb_header *bdb)
  1000. {
  1001. const struct bdb_general_definitions *p_defs;
  1002. const union child_device_config *p_child;
  1003. union child_device_config *child_dev_ptr;
  1004. int i, child_device_num, count;
  1005. u8 expected_size;
  1006. u16 block_size;
  1007. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  1008. if (!p_defs) {
  1009. DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
  1010. return;
  1011. }
  1012. if (bdb->version < 106) {
  1013. expected_size = 22;
  1014. } else if (bdb->version < 109) {
  1015. expected_size = 27;
  1016. } else if (bdb->version < 195) {
  1017. BUILD_BUG_ON(sizeof(struct old_child_dev_config) != 33);
  1018. expected_size = sizeof(struct old_child_dev_config);
  1019. } else if (bdb->version == 195) {
  1020. expected_size = 37;
  1021. } else if (bdb->version <= 197) {
  1022. expected_size = 38;
  1023. } else {
  1024. expected_size = 38;
  1025. BUILD_BUG_ON(sizeof(*p_child) < 38);
  1026. DRM_DEBUG_DRIVER("Expected child device config size for VBT version %u not known; assuming %u\n",
  1027. bdb->version, expected_size);
  1028. }
  1029. /* Flag an error for unexpected size, but continue anyway. */
  1030. if (p_defs->child_dev_size != expected_size)
  1031. DRM_ERROR("Unexpected child device config size %u (expected %u for VBT version %u)\n",
  1032. p_defs->child_dev_size, expected_size, bdb->version);
  1033. /* The legacy sized child device config is the minimum we need. */
  1034. if (p_defs->child_dev_size < sizeof(struct old_child_dev_config)) {
  1035. DRM_DEBUG_KMS("Child device config size %u is too small.\n",
  1036. p_defs->child_dev_size);
  1037. return;
  1038. }
  1039. /* get the block size of general definitions */
  1040. block_size = get_blocksize(p_defs);
  1041. /* get the number of child device */
  1042. child_device_num = (block_size - sizeof(*p_defs)) /
  1043. p_defs->child_dev_size;
  1044. count = 0;
  1045. /* get the number of child device that is present */
  1046. for (i = 0; i < child_device_num; i++) {
  1047. p_child = child_device_ptr(p_defs, i);
  1048. if (!p_child->common.device_type) {
  1049. /* skip the device block if device type is invalid */
  1050. continue;
  1051. }
  1052. count++;
  1053. }
  1054. if (!count) {
  1055. DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
  1056. return;
  1057. }
  1058. dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
  1059. if (!dev_priv->vbt.child_dev) {
  1060. DRM_DEBUG_KMS("No memory space for child device\n");
  1061. return;
  1062. }
  1063. dev_priv->vbt.child_dev_num = count;
  1064. count = 0;
  1065. for (i = 0; i < child_device_num; i++) {
  1066. p_child = child_device_ptr(p_defs, i);
  1067. if (!p_child->common.device_type) {
  1068. /* skip the device block if device type is invalid */
  1069. continue;
  1070. }
  1071. if (p_child->common.dvo_port >= DVO_PORT_MIPIA
  1072. && p_child->common.dvo_port <= DVO_PORT_MIPID
  1073. &&p_child->common.device_type & DEVICE_TYPE_MIPI_OUTPUT) {
  1074. DRM_DEBUG_KMS("Found MIPI as LFP\n");
  1075. dev_priv->vbt.has_mipi = 1;
  1076. dev_priv->vbt.dsi.port = p_child->common.dvo_port;
  1077. }
  1078. child_dev_ptr = dev_priv->vbt.child_dev + count;
  1079. count++;
  1080. /*
  1081. * Copy as much as we know (sizeof) and is available
  1082. * (child_dev_size) of the child device. Accessing the data must
  1083. * depend on VBT version.
  1084. */
  1085. memcpy(child_dev_ptr, p_child,
  1086. min_t(size_t, p_defs->child_dev_size, sizeof(*p_child)));
  1087. }
  1088. return;
  1089. }
  1090. static void
  1091. init_vbt_defaults(struct drm_i915_private *dev_priv)
  1092. {
  1093. enum port port;
  1094. dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
  1095. /* Default to having backlight */
  1096. dev_priv->vbt.backlight.present = true;
  1097. /* LFP panel data */
  1098. dev_priv->vbt.lvds_dither = 1;
  1099. dev_priv->vbt.lvds_vbt = 0;
  1100. /* SDVO panel data */
  1101. dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
  1102. /* general features */
  1103. dev_priv->vbt.int_tv_support = 1;
  1104. dev_priv->vbt.int_crt_support = 1;
  1105. /* Default to using SSC */
  1106. dev_priv->vbt.lvds_use_ssc = 1;
  1107. /*
  1108. * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
  1109. * clock for LVDS.
  1110. */
  1111. dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev_priv,
  1112. !HAS_PCH_SPLIT(dev_priv));
  1113. DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
  1114. for (port = PORT_A; port < I915_MAX_PORTS; port++) {
  1115. struct ddi_vbt_port_info *info =
  1116. &dev_priv->vbt.ddi_port_info[port];
  1117. info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
  1118. info->supports_dvi = (port != PORT_A && port != PORT_E);
  1119. info->supports_hdmi = info->supports_dvi;
  1120. info->supports_dp = (port != PORT_E);
  1121. }
  1122. }
  1123. static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
  1124. {
  1125. const void *_vbt = vbt;
  1126. return _vbt + vbt->bdb_offset;
  1127. }
  1128. /**
  1129. * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
  1130. * @buf: pointer to a buffer to validate
  1131. * @size: size of the buffer
  1132. *
  1133. * Returns true on valid VBT.
  1134. */
  1135. bool intel_bios_is_valid_vbt(const void *buf, size_t size)
  1136. {
  1137. const struct vbt_header *vbt = buf;
  1138. const struct bdb_header *bdb;
  1139. if (!vbt)
  1140. return false;
  1141. if (sizeof(struct vbt_header) > size) {
  1142. DRM_DEBUG_DRIVER("VBT header incomplete\n");
  1143. return false;
  1144. }
  1145. if (memcmp(vbt->signature, "$VBT", 4)) {
  1146. DRM_DEBUG_DRIVER("VBT invalid signature\n");
  1147. return false;
  1148. }
  1149. if (vbt->bdb_offset + sizeof(struct bdb_header) > size) {
  1150. DRM_DEBUG_DRIVER("BDB header incomplete\n");
  1151. return false;
  1152. }
  1153. bdb = get_bdb_header(vbt);
  1154. if (vbt->bdb_offset + bdb->bdb_size > size) {
  1155. DRM_DEBUG_DRIVER("BDB incomplete\n");
  1156. return false;
  1157. }
  1158. return vbt;
  1159. }
  1160. static const struct vbt_header *find_vbt(void __iomem *bios, size_t size)
  1161. {
  1162. size_t i;
  1163. /* Scour memory looking for the VBT signature. */
  1164. for (i = 0; i + 4 < size; i++) {
  1165. void *vbt;
  1166. if (ioread32(bios + i) != *((const u32 *) "$VBT"))
  1167. continue;
  1168. /*
  1169. * This is the one place where we explicitly discard the address
  1170. * space (__iomem) of the BIOS/VBT.
  1171. */
  1172. vbt = (void __force *) bios + i;
  1173. if (intel_bios_is_valid_vbt(vbt, size - i))
  1174. return vbt;
  1175. break;
  1176. }
  1177. return NULL;
  1178. }
  1179. /**
  1180. * intel_bios_init - find VBT and initialize settings from the BIOS
  1181. * @dev_priv: i915 device instance
  1182. *
  1183. * Loads the Video BIOS and checks that the VBT exists. Sets scratch registers
  1184. * to appropriate values.
  1185. *
  1186. * Returns 0 on success, nonzero on failure.
  1187. */
  1188. int
  1189. intel_bios_init(struct drm_i915_private *dev_priv)
  1190. {
  1191. struct pci_dev *pdev = dev_priv->dev->pdev;
  1192. const struct vbt_header *vbt = dev_priv->opregion.vbt;
  1193. const struct bdb_header *bdb;
  1194. u8 __iomem *bios = NULL;
  1195. if (HAS_PCH_NOP(dev_priv))
  1196. return -ENODEV;
  1197. init_vbt_defaults(dev_priv);
  1198. if (!vbt) {
  1199. size_t size;
  1200. bios = pci_map_rom(pdev, &size);
  1201. if (!bios)
  1202. return -1;
  1203. vbt = find_vbt(bios, size);
  1204. if (!vbt) {
  1205. pci_unmap_rom(pdev, bios);
  1206. return -1;
  1207. }
  1208. DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
  1209. }
  1210. bdb = get_bdb_header(vbt);
  1211. DRM_DEBUG_KMS("VBT signature \"%.*s\", BDB version %d\n",
  1212. (int)sizeof(vbt->signature), vbt->signature, bdb->version);
  1213. /* Grab useful general definitions */
  1214. parse_general_features(dev_priv, bdb);
  1215. parse_general_definitions(dev_priv, bdb);
  1216. parse_lfp_panel_data(dev_priv, bdb);
  1217. parse_lfp_backlight(dev_priv, bdb);
  1218. parse_sdvo_panel_data(dev_priv, bdb);
  1219. parse_sdvo_device_mapping(dev_priv, bdb);
  1220. parse_device_mapping(dev_priv, bdb);
  1221. parse_driver_features(dev_priv, bdb);
  1222. parse_edp(dev_priv, bdb);
  1223. parse_psr(dev_priv, bdb);
  1224. parse_mipi_config(dev_priv, bdb);
  1225. parse_mipi_sequence(dev_priv, bdb);
  1226. parse_ddi_ports(dev_priv, bdb);
  1227. if (bios)
  1228. pci_unmap_rom(pdev, bios);
  1229. return 0;
  1230. }