intel_bios.c 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084
  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. #define _INTEL_BIOS_PRIVATE
  32. #include "intel_vbt_defs.h"
  33. /**
  34. * DOC: Video BIOS Table (VBT)
  35. *
  36. * The Video BIOS Table, or VBT, provides platform and board specific
  37. * configuration information to the driver that is not discoverable or available
  38. * through other means. The configuration is mostly related to display
  39. * hardware. The VBT is available via the ACPI OpRegion or, on older systems, in
  40. * the PCI ROM.
  41. *
  42. * The VBT consists of a VBT Header (defined as &struct vbt_header), a BDB
  43. * Header (&struct bdb_header), and a number of BIOS Data Blocks (BDB) that
  44. * contain the actual configuration information. The VBT Header, and thus the
  45. * VBT, begins with "$VBT" signature. The VBT Header contains the offset of the
  46. * BDB Header. The data blocks are concatenated after the BDB Header. The data
  47. * blocks have a 1-byte Block ID, 2-byte Block Size, and Block Size bytes of
  48. * data. (Block 53, the MIPI Sequence Block is an exception.)
  49. *
  50. * The driver parses the VBT during load. The relevant information is stored in
  51. * driver private data for ease of use, and the actual VBT is not read after
  52. * that.
  53. */
  54. #define SLAVE_ADDR1 0x70
  55. #define SLAVE_ADDR2 0x72
  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_hi << 8) |
  104. dvo_timing->hsync_pulse_width_lo);
  105. panel_fixed_mode->htotal = panel_fixed_mode->hdisplay +
  106. ((dvo_timing->hblank_hi << 8) | dvo_timing->hblank_lo);
  107. panel_fixed_mode->vdisplay = (dvo_timing->vactive_hi << 8) |
  108. dvo_timing->vactive_lo;
  109. panel_fixed_mode->vsync_start = panel_fixed_mode->vdisplay +
  110. ((dvo_timing->vsync_off_hi << 4) | dvo_timing->vsync_off_lo);
  111. panel_fixed_mode->vsync_end = panel_fixed_mode->vsync_start +
  112. ((dvo_timing->vsync_pulse_width_hi << 4) |
  113. dvo_timing->vsync_pulse_width_lo);
  114. panel_fixed_mode->vtotal = panel_fixed_mode->vdisplay +
  115. ((dvo_timing->vblank_hi << 8) | dvo_timing->vblank_lo);
  116. panel_fixed_mode->clock = dvo_timing->clock * 10;
  117. panel_fixed_mode->type = DRM_MODE_TYPE_PREFERRED;
  118. if (dvo_timing->hsync_positive)
  119. panel_fixed_mode->flags |= DRM_MODE_FLAG_PHSYNC;
  120. else
  121. panel_fixed_mode->flags |= DRM_MODE_FLAG_NHSYNC;
  122. if (dvo_timing->vsync_positive)
  123. panel_fixed_mode->flags |= DRM_MODE_FLAG_PVSYNC;
  124. else
  125. panel_fixed_mode->flags |= DRM_MODE_FLAG_NVSYNC;
  126. panel_fixed_mode->width_mm = (dvo_timing->himage_hi << 8) |
  127. dvo_timing->himage_lo;
  128. panel_fixed_mode->height_mm = (dvo_timing->vimage_hi << 8) |
  129. dvo_timing->vimage_lo;
  130. /* Some VBTs have bogus h/vtotal values */
  131. if (panel_fixed_mode->hsync_end > panel_fixed_mode->htotal)
  132. panel_fixed_mode->htotal = panel_fixed_mode->hsync_end + 1;
  133. if (panel_fixed_mode->vsync_end > panel_fixed_mode->vtotal)
  134. panel_fixed_mode->vtotal = panel_fixed_mode->vsync_end + 1;
  135. drm_mode_set_name(panel_fixed_mode);
  136. }
  137. static const struct lvds_dvo_timing *
  138. get_lvds_dvo_timing(const struct bdb_lvds_lfp_data *lvds_lfp_data,
  139. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs,
  140. int index)
  141. {
  142. /*
  143. * the size of fp_timing varies on the different platform.
  144. * So calculate the DVO timing relative offset in LVDS data
  145. * entry to get the DVO timing entry
  146. */
  147. int lfp_data_size =
  148. lvds_lfp_data_ptrs->ptr[1].dvo_timing_offset -
  149. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset;
  150. int dvo_timing_offset =
  151. lvds_lfp_data_ptrs->ptr[0].dvo_timing_offset -
  152. lvds_lfp_data_ptrs->ptr[0].fp_timing_offset;
  153. char *entry = (char *)lvds_lfp_data->data + lfp_data_size * index;
  154. return (struct lvds_dvo_timing *)(entry + dvo_timing_offset);
  155. }
  156. /* get lvds_fp_timing entry
  157. * this function may return NULL if the corresponding entry is invalid
  158. */
  159. static const struct lvds_fp_timing *
  160. get_lvds_fp_timing(const struct bdb_header *bdb,
  161. const struct bdb_lvds_lfp_data *data,
  162. const struct bdb_lvds_lfp_data_ptrs *ptrs,
  163. int index)
  164. {
  165. size_t data_ofs = (const u8 *)data - (const u8 *)bdb;
  166. u16 data_size = ((const u16 *)data)[-1]; /* stored in header */
  167. size_t ofs;
  168. if (index >= ARRAY_SIZE(ptrs->ptr))
  169. return NULL;
  170. ofs = ptrs->ptr[index].fp_timing_offset;
  171. if (ofs < data_ofs ||
  172. ofs + sizeof(struct lvds_fp_timing) > data_ofs + data_size)
  173. return NULL;
  174. return (const struct lvds_fp_timing *)((const u8 *)bdb + ofs);
  175. }
  176. /* Try to find integrated panel data */
  177. static void
  178. parse_lfp_panel_data(struct drm_i915_private *dev_priv,
  179. const struct bdb_header *bdb)
  180. {
  181. const struct bdb_lvds_options *lvds_options;
  182. const struct bdb_lvds_lfp_data *lvds_lfp_data;
  183. const struct bdb_lvds_lfp_data_ptrs *lvds_lfp_data_ptrs;
  184. const struct lvds_dvo_timing *panel_dvo_timing;
  185. const struct lvds_fp_timing *fp_timing;
  186. struct drm_display_mode *panel_fixed_mode;
  187. int panel_type;
  188. int drrs_mode;
  189. int ret;
  190. lvds_options = find_section(bdb, BDB_LVDS_OPTIONS);
  191. if (!lvds_options)
  192. return;
  193. dev_priv->vbt.lvds_dither = lvds_options->pixel_dither;
  194. ret = intel_opregion_get_panel_type(dev_priv);
  195. if (ret >= 0) {
  196. WARN_ON(ret > 0xf);
  197. panel_type = ret;
  198. DRM_DEBUG_KMS("Panel type: %d (OpRegion)\n", panel_type);
  199. } else {
  200. if (lvds_options->panel_type > 0xf) {
  201. DRM_DEBUG_KMS("Invalid VBT panel type 0x%x\n",
  202. lvds_options->panel_type);
  203. return;
  204. }
  205. panel_type = lvds_options->panel_type;
  206. DRM_DEBUG_KMS("Panel type: %d (VBT)\n", panel_type);
  207. }
  208. dev_priv->vbt.panel_type = panel_type;
  209. drrs_mode = (lvds_options->dps_panel_type_bits
  210. >> (panel_type * 2)) & MODE_MASK;
  211. /*
  212. * VBT has static DRRS = 0 and seamless DRRS = 2.
  213. * The below piece of code is required to adjust vbt.drrs_type
  214. * to match the enum drrs_support_type.
  215. */
  216. switch (drrs_mode) {
  217. case 0:
  218. dev_priv->vbt.drrs_type = STATIC_DRRS_SUPPORT;
  219. DRM_DEBUG_KMS("DRRS supported mode is static\n");
  220. break;
  221. case 2:
  222. dev_priv->vbt.drrs_type = SEAMLESS_DRRS_SUPPORT;
  223. DRM_DEBUG_KMS("DRRS supported mode is seamless\n");
  224. break;
  225. default:
  226. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  227. DRM_DEBUG_KMS("DRRS not supported (VBT input)\n");
  228. break;
  229. }
  230. lvds_lfp_data = find_section(bdb, BDB_LVDS_LFP_DATA);
  231. if (!lvds_lfp_data)
  232. return;
  233. lvds_lfp_data_ptrs = find_section(bdb, BDB_LVDS_LFP_DATA_PTRS);
  234. if (!lvds_lfp_data_ptrs)
  235. return;
  236. dev_priv->vbt.lvds_vbt = 1;
  237. panel_dvo_timing = get_lvds_dvo_timing(lvds_lfp_data,
  238. lvds_lfp_data_ptrs,
  239. panel_type);
  240. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  241. if (!panel_fixed_mode)
  242. return;
  243. fill_detail_timing_data(panel_fixed_mode, panel_dvo_timing);
  244. dev_priv->vbt.lfp_lvds_vbt_mode = panel_fixed_mode;
  245. DRM_DEBUG_KMS("Found panel mode in BIOS VBT tables:\n");
  246. drm_mode_debug_printmodeline(panel_fixed_mode);
  247. fp_timing = get_lvds_fp_timing(bdb, lvds_lfp_data,
  248. lvds_lfp_data_ptrs,
  249. panel_type);
  250. if (fp_timing) {
  251. /* check the resolution, just to be sure */
  252. if (fp_timing->x_res == panel_fixed_mode->hdisplay &&
  253. fp_timing->y_res == panel_fixed_mode->vdisplay) {
  254. dev_priv->vbt.bios_lvds_val = fp_timing->lvds_reg_val;
  255. DRM_DEBUG_KMS("VBT initial LVDS value %x\n",
  256. dev_priv->vbt.bios_lvds_val);
  257. }
  258. }
  259. }
  260. static void
  261. parse_lfp_backlight(struct drm_i915_private *dev_priv,
  262. const struct bdb_header *bdb)
  263. {
  264. const struct bdb_lfp_backlight_data *backlight_data;
  265. const struct bdb_lfp_backlight_data_entry *entry;
  266. int panel_type = dev_priv->vbt.panel_type;
  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.type = INTEL_BACKLIGHT_DISPLAY_DDI;
  283. if (bdb->version >= 191 &&
  284. get_blocksize(backlight_data) >= sizeof(*backlight_data)) {
  285. const struct bdb_lfp_backlight_control_method *method;
  286. method = &backlight_data->backlight_control[panel_type];
  287. dev_priv->vbt.backlight.type = method->type;
  288. dev_priv->vbt.backlight.controller = method->controller;
  289. }
  290. dev_priv->vbt.backlight.pwm_freq_hz = entry->pwm_freq_hz;
  291. dev_priv->vbt.backlight.active_low_pwm = entry->active_low_pwm;
  292. dev_priv->vbt.backlight.min_brightness = entry->min_brightness;
  293. DRM_DEBUG_KMS("VBT backlight PWM modulation frequency %u Hz, "
  294. "active %s, min brightness %u, level %u, controller %u\n",
  295. dev_priv->vbt.backlight.pwm_freq_hz,
  296. dev_priv->vbt.backlight.active_low_pwm ? "low" : "high",
  297. dev_priv->vbt.backlight.min_brightness,
  298. backlight_data->level[panel_type],
  299. dev_priv->vbt.backlight.controller);
  300. }
  301. /* Try to find sdvo panel data */
  302. static void
  303. parse_sdvo_panel_data(struct drm_i915_private *dev_priv,
  304. const struct bdb_header *bdb)
  305. {
  306. const struct lvds_dvo_timing *dvo_timing;
  307. struct drm_display_mode *panel_fixed_mode;
  308. int index;
  309. index = i915_modparams.vbt_sdvo_panel_type;
  310. if (index == -2) {
  311. DRM_DEBUG_KMS("Ignore SDVO panel mode from BIOS VBT tables.\n");
  312. return;
  313. }
  314. if (index == -1) {
  315. const struct bdb_sdvo_lvds_options *sdvo_lvds_options;
  316. sdvo_lvds_options = find_section(bdb, BDB_SDVO_LVDS_OPTIONS);
  317. if (!sdvo_lvds_options)
  318. return;
  319. index = sdvo_lvds_options->panel_type;
  320. }
  321. dvo_timing = find_section(bdb, BDB_SDVO_PANEL_DTDS);
  322. if (!dvo_timing)
  323. return;
  324. panel_fixed_mode = kzalloc(sizeof(*panel_fixed_mode), GFP_KERNEL);
  325. if (!panel_fixed_mode)
  326. return;
  327. fill_detail_timing_data(panel_fixed_mode, dvo_timing + index);
  328. dev_priv->vbt.sdvo_lvds_vbt_mode = panel_fixed_mode;
  329. DRM_DEBUG_KMS("Found SDVO panel mode in BIOS VBT tables:\n");
  330. drm_mode_debug_printmodeline(panel_fixed_mode);
  331. }
  332. static int intel_bios_ssc_frequency(struct drm_i915_private *dev_priv,
  333. bool alternate)
  334. {
  335. switch (INTEL_GEN(dev_priv)) {
  336. case 2:
  337. return alternate ? 66667 : 48000;
  338. case 3:
  339. case 4:
  340. return alternate ? 100000 : 96000;
  341. default:
  342. return alternate ? 100000 : 120000;
  343. }
  344. }
  345. static void
  346. parse_general_features(struct drm_i915_private *dev_priv,
  347. const struct bdb_header *bdb)
  348. {
  349. const struct bdb_general_features *general;
  350. general = find_section(bdb, BDB_GENERAL_FEATURES);
  351. if (!general)
  352. return;
  353. dev_priv->vbt.int_tv_support = general->int_tv_support;
  354. /* int_crt_support can't be trusted on earlier platforms */
  355. if (bdb->version >= 155 &&
  356. (HAS_DDI(dev_priv) || IS_VALLEYVIEW(dev_priv)))
  357. dev_priv->vbt.int_crt_support = general->int_crt_support;
  358. dev_priv->vbt.lvds_use_ssc = general->enable_ssc;
  359. dev_priv->vbt.lvds_ssc_freq =
  360. intel_bios_ssc_frequency(dev_priv, general->ssc_freq);
  361. dev_priv->vbt.display_clock_mode = general->display_clock_mode;
  362. dev_priv->vbt.fdi_rx_polarity_inverted = general->fdi_rx_polarity_inverted;
  363. 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",
  364. dev_priv->vbt.int_tv_support,
  365. dev_priv->vbt.int_crt_support,
  366. dev_priv->vbt.lvds_use_ssc,
  367. dev_priv->vbt.lvds_ssc_freq,
  368. dev_priv->vbt.display_clock_mode,
  369. dev_priv->vbt.fdi_rx_polarity_inverted);
  370. }
  371. static const struct child_device_config *
  372. child_device_ptr(const struct bdb_general_definitions *defs, int i)
  373. {
  374. return (const void *) &defs->devices[i * defs->child_dev_size];
  375. }
  376. static void
  377. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv, u8 bdb_version)
  378. {
  379. struct sdvo_device_mapping *mapping;
  380. const struct child_device_config *child;
  381. int i, count = 0;
  382. /*
  383. * Only parse SDVO mappings on gens that could have SDVO. This isn't
  384. * accurate and doesn't have to be, as long as it's not too strict.
  385. */
  386. if (!IS_GEN(dev_priv, 3, 7)) {
  387. DRM_DEBUG_KMS("Skipping SDVO device mapping\n");
  388. return;
  389. }
  390. for (i = 0, count = 0; i < dev_priv->vbt.child_dev_num; i++) {
  391. child = dev_priv->vbt.child_dev + i;
  392. if (child->slave_addr != SLAVE_ADDR1 &&
  393. child->slave_addr != SLAVE_ADDR2) {
  394. /*
  395. * If the slave address is neither 0x70 nor 0x72,
  396. * it is not a SDVO device. Skip it.
  397. */
  398. continue;
  399. }
  400. if (child->dvo_port != DEVICE_PORT_DVOB &&
  401. child->dvo_port != DEVICE_PORT_DVOC) {
  402. /* skip the incorrect SDVO port */
  403. DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
  404. continue;
  405. }
  406. DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
  407. " %s port\n",
  408. child->slave_addr,
  409. (child->dvo_port == DEVICE_PORT_DVOB) ?
  410. "SDVOB" : "SDVOC");
  411. mapping = &dev_priv->vbt.sdvo_mappings[child->dvo_port - 1];
  412. if (!mapping->initialized) {
  413. mapping->dvo_port = child->dvo_port;
  414. mapping->slave_addr = child->slave_addr;
  415. mapping->dvo_wiring = child->dvo_wiring;
  416. mapping->ddc_pin = child->ddc_pin;
  417. mapping->i2c_pin = child->i2c_pin;
  418. mapping->initialized = 1;
  419. DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
  420. mapping->dvo_port,
  421. mapping->slave_addr,
  422. mapping->dvo_wiring,
  423. mapping->ddc_pin,
  424. mapping->i2c_pin);
  425. } else {
  426. DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
  427. "two SDVO device.\n");
  428. }
  429. if (child->slave2_addr) {
  430. /* Maybe this is a SDVO device with multiple inputs */
  431. /* And the mapping info is not added */
  432. DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
  433. " is a SDVO device with multiple inputs.\n");
  434. }
  435. count++;
  436. }
  437. if (!count) {
  438. /* No SDVO device info is found */
  439. DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
  440. }
  441. }
  442. static void
  443. parse_driver_features(struct drm_i915_private *dev_priv,
  444. const struct bdb_header *bdb)
  445. {
  446. const struct bdb_driver_features *driver;
  447. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  448. if (!driver)
  449. return;
  450. if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
  451. dev_priv->vbt.edp.support = 1;
  452. DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
  453. /*
  454. * If DRRS is not supported, drrs_type has to be set to 0.
  455. * This is because, VBT is configured in such a way that
  456. * static DRRS is 0 and DRRS not supported is represented by
  457. * driver->drrs_enabled=false
  458. */
  459. if (!driver->drrs_enabled)
  460. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  461. }
  462. static void
  463. parse_edp(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
  464. {
  465. const struct bdb_edp *edp;
  466. const struct edp_power_seq *edp_pps;
  467. const struct edp_fast_link_params *edp_link_params;
  468. int panel_type = dev_priv->vbt.panel_type;
  469. edp = find_section(bdb, BDB_EDP);
  470. if (!edp) {
  471. if (dev_priv->vbt.edp.support)
  472. DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
  473. return;
  474. }
  475. switch ((edp->color_depth >> (panel_type * 2)) & 3) {
  476. case EDP_18BPP:
  477. dev_priv->vbt.edp.bpp = 18;
  478. break;
  479. case EDP_24BPP:
  480. dev_priv->vbt.edp.bpp = 24;
  481. break;
  482. case EDP_30BPP:
  483. dev_priv->vbt.edp.bpp = 30;
  484. break;
  485. }
  486. /* Get the eDP sequencing and link info */
  487. edp_pps = &edp->power_seqs[panel_type];
  488. edp_link_params = &edp->fast_link_params[panel_type];
  489. dev_priv->vbt.edp.pps = *edp_pps;
  490. switch (edp_link_params->rate) {
  491. case EDP_RATE_1_62:
  492. dev_priv->vbt.edp.rate = DP_LINK_BW_1_62;
  493. break;
  494. case EDP_RATE_2_7:
  495. dev_priv->vbt.edp.rate = DP_LINK_BW_2_7;
  496. break;
  497. default:
  498. DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
  499. edp_link_params->rate);
  500. break;
  501. }
  502. switch (edp_link_params->lanes) {
  503. case EDP_LANE_1:
  504. dev_priv->vbt.edp.lanes = 1;
  505. break;
  506. case EDP_LANE_2:
  507. dev_priv->vbt.edp.lanes = 2;
  508. break;
  509. case EDP_LANE_4:
  510. dev_priv->vbt.edp.lanes = 4;
  511. break;
  512. default:
  513. DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
  514. edp_link_params->lanes);
  515. break;
  516. }
  517. switch (edp_link_params->preemphasis) {
  518. case EDP_PREEMPHASIS_NONE:
  519. dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
  520. break;
  521. case EDP_PREEMPHASIS_3_5dB:
  522. dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
  523. break;
  524. case EDP_PREEMPHASIS_6dB:
  525. dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
  526. break;
  527. case EDP_PREEMPHASIS_9_5dB:
  528. dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
  529. break;
  530. default:
  531. DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
  532. edp_link_params->preemphasis);
  533. break;
  534. }
  535. switch (edp_link_params->vswing) {
  536. case EDP_VSWING_0_4V:
  537. dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
  538. break;
  539. case EDP_VSWING_0_6V:
  540. dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
  541. break;
  542. case EDP_VSWING_0_8V:
  543. dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  544. break;
  545. case EDP_VSWING_1_2V:
  546. dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  547. break;
  548. default:
  549. DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
  550. edp_link_params->vswing);
  551. break;
  552. }
  553. if (bdb->version >= 173) {
  554. uint8_t vswing;
  555. /* Don't read from VBT if module parameter has valid value*/
  556. if (i915_modparams.edp_vswing) {
  557. dev_priv->vbt.edp.low_vswing =
  558. i915_modparams.edp_vswing == 1;
  559. } else {
  560. vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
  561. dev_priv->vbt.edp.low_vswing = vswing == 0;
  562. }
  563. }
  564. }
  565. static void
  566. parse_psr(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
  567. {
  568. const struct bdb_psr *psr;
  569. const struct psr_table *psr_table;
  570. int panel_type = dev_priv->vbt.panel_type;
  571. psr = find_section(bdb, BDB_PSR);
  572. if (!psr) {
  573. DRM_DEBUG_KMS("No PSR BDB found.\n");
  574. return;
  575. }
  576. psr_table = &psr->psr_table[panel_type];
  577. dev_priv->vbt.psr.full_link = psr_table->full_link;
  578. dev_priv->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
  579. /* Allowed VBT values goes from 0 to 15 */
  580. dev_priv->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
  581. psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
  582. switch (psr_table->lines_to_wait) {
  583. case 0:
  584. dev_priv->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
  585. break;
  586. case 1:
  587. dev_priv->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
  588. break;
  589. case 2:
  590. dev_priv->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
  591. break;
  592. case 3:
  593. dev_priv->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
  594. break;
  595. default:
  596. DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
  597. psr_table->lines_to_wait);
  598. break;
  599. }
  600. dev_priv->vbt.psr.tp1_wakeup_time = psr_table->tp1_wakeup_time;
  601. dev_priv->vbt.psr.tp2_tp3_wakeup_time = psr_table->tp2_tp3_wakeup_time;
  602. }
  603. static void parse_dsi_backlight_ports(struct drm_i915_private *dev_priv,
  604. u16 version, enum port port)
  605. {
  606. if (!dev_priv->vbt.dsi.config->dual_link || version < 197) {
  607. dev_priv->vbt.dsi.bl_ports = BIT(port);
  608. if (dev_priv->vbt.dsi.config->cabc_supported)
  609. dev_priv->vbt.dsi.cabc_ports = BIT(port);
  610. return;
  611. }
  612. switch (dev_priv->vbt.dsi.config->dl_dcs_backlight_ports) {
  613. case DL_DCS_PORT_A:
  614. dev_priv->vbt.dsi.bl_ports = BIT(PORT_A);
  615. break;
  616. case DL_DCS_PORT_C:
  617. dev_priv->vbt.dsi.bl_ports = BIT(PORT_C);
  618. break;
  619. default:
  620. case DL_DCS_PORT_A_AND_C:
  621. dev_priv->vbt.dsi.bl_ports = BIT(PORT_A) | BIT(PORT_C);
  622. break;
  623. }
  624. if (!dev_priv->vbt.dsi.config->cabc_supported)
  625. return;
  626. switch (dev_priv->vbt.dsi.config->dl_dcs_cabc_ports) {
  627. case DL_DCS_PORT_A:
  628. dev_priv->vbt.dsi.cabc_ports = BIT(PORT_A);
  629. break;
  630. case DL_DCS_PORT_C:
  631. dev_priv->vbt.dsi.cabc_ports = BIT(PORT_C);
  632. break;
  633. default:
  634. case DL_DCS_PORT_A_AND_C:
  635. dev_priv->vbt.dsi.cabc_ports =
  636. BIT(PORT_A) | BIT(PORT_C);
  637. break;
  638. }
  639. }
  640. static void
  641. parse_mipi_config(struct drm_i915_private *dev_priv,
  642. const struct bdb_header *bdb)
  643. {
  644. const struct bdb_mipi_config *start;
  645. const struct mipi_config *config;
  646. const struct mipi_pps_data *pps;
  647. int panel_type = dev_priv->vbt.panel_type;
  648. enum port port;
  649. /* parse MIPI blocks only if LFP type is MIPI */
  650. if (!intel_bios_is_dsi_present(dev_priv, &port))
  651. return;
  652. /* Initialize this to undefined indicating no generic MIPI support */
  653. dev_priv->vbt.dsi.panel_id = MIPI_DSI_UNDEFINED_PANEL_ID;
  654. /* Block #40 is already parsed and panel_fixed_mode is
  655. * stored in dev_priv->lfp_lvds_vbt_mode
  656. * resuse this when needed
  657. */
  658. /* Parse #52 for panel index used from panel_type already
  659. * parsed
  660. */
  661. start = find_section(bdb, BDB_MIPI_CONFIG);
  662. if (!start) {
  663. DRM_DEBUG_KMS("No MIPI config BDB found");
  664. return;
  665. }
  666. DRM_DEBUG_DRIVER("Found MIPI Config block, panel index = %d\n",
  667. panel_type);
  668. /*
  669. * get hold of the correct configuration block and pps data as per
  670. * the panel_type as index
  671. */
  672. config = &start->config[panel_type];
  673. pps = &start->pps[panel_type];
  674. /* store as of now full data. Trim when we realise all is not needed */
  675. dev_priv->vbt.dsi.config = kmemdup(config, sizeof(struct mipi_config), GFP_KERNEL);
  676. if (!dev_priv->vbt.dsi.config)
  677. return;
  678. dev_priv->vbt.dsi.pps = kmemdup(pps, sizeof(struct mipi_pps_data), GFP_KERNEL);
  679. if (!dev_priv->vbt.dsi.pps) {
  680. kfree(dev_priv->vbt.dsi.config);
  681. return;
  682. }
  683. parse_dsi_backlight_ports(dev_priv, bdb->version, port);
  684. /* We have mandatory mipi config blocks. Initialize as generic panel */
  685. dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
  686. }
  687. /* Find the sequence block and size for the given panel. */
  688. static const u8 *
  689. find_panel_sequence_block(const struct bdb_mipi_sequence *sequence,
  690. u16 panel_id, u32 *seq_size)
  691. {
  692. u32 total = get_blocksize(sequence);
  693. const u8 *data = &sequence->data[0];
  694. u8 current_id;
  695. u32 current_size;
  696. int header_size = sequence->version >= 3 ? 5 : 3;
  697. int index = 0;
  698. int i;
  699. /* skip new block size */
  700. if (sequence->version >= 3)
  701. data += 4;
  702. for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index < total; i++) {
  703. if (index + header_size > total) {
  704. DRM_ERROR("Invalid sequence block (header)\n");
  705. return NULL;
  706. }
  707. current_id = *(data + index);
  708. if (sequence->version >= 3)
  709. current_size = *((const u32 *)(data + index + 1));
  710. else
  711. current_size = *((const u16 *)(data + index + 1));
  712. index += header_size;
  713. if (index + current_size > total) {
  714. DRM_ERROR("Invalid sequence block\n");
  715. return NULL;
  716. }
  717. if (current_id == panel_id) {
  718. *seq_size = current_size;
  719. return data + index;
  720. }
  721. index += current_size;
  722. }
  723. DRM_ERROR("Sequence block detected but no valid configuration\n");
  724. return NULL;
  725. }
  726. static int goto_next_sequence(const u8 *data, int index, int total)
  727. {
  728. u16 len;
  729. /* Skip Sequence Byte. */
  730. for (index = index + 1; index < total; index += len) {
  731. u8 operation_byte = *(data + index);
  732. index++;
  733. switch (operation_byte) {
  734. case MIPI_SEQ_ELEM_END:
  735. return index;
  736. case MIPI_SEQ_ELEM_SEND_PKT:
  737. if (index + 4 > total)
  738. return 0;
  739. len = *((const u16 *)(data + index + 2)) + 4;
  740. break;
  741. case MIPI_SEQ_ELEM_DELAY:
  742. len = 4;
  743. break;
  744. case MIPI_SEQ_ELEM_GPIO:
  745. len = 2;
  746. break;
  747. case MIPI_SEQ_ELEM_I2C:
  748. if (index + 7 > total)
  749. return 0;
  750. len = *(data + index + 6) + 7;
  751. break;
  752. default:
  753. DRM_ERROR("Unknown operation byte\n");
  754. return 0;
  755. }
  756. }
  757. return 0;
  758. }
  759. static int goto_next_sequence_v3(const u8 *data, int index, int total)
  760. {
  761. int seq_end;
  762. u16 len;
  763. u32 size_of_sequence;
  764. /*
  765. * Could skip sequence based on Size of Sequence alone, but also do some
  766. * checking on the structure.
  767. */
  768. if (total < 5) {
  769. DRM_ERROR("Too small sequence size\n");
  770. return 0;
  771. }
  772. /* Skip Sequence Byte. */
  773. index++;
  774. /*
  775. * Size of Sequence. Excludes the Sequence Byte and the size itself,
  776. * includes MIPI_SEQ_ELEM_END byte, excludes the final MIPI_SEQ_END
  777. * byte.
  778. */
  779. size_of_sequence = *((const uint32_t *)(data + index));
  780. index += 4;
  781. seq_end = index + size_of_sequence;
  782. if (seq_end > total) {
  783. DRM_ERROR("Invalid sequence size\n");
  784. return 0;
  785. }
  786. for (; index < total; index += len) {
  787. u8 operation_byte = *(data + index);
  788. index++;
  789. if (operation_byte == MIPI_SEQ_ELEM_END) {
  790. if (index != seq_end) {
  791. DRM_ERROR("Invalid element structure\n");
  792. return 0;
  793. }
  794. return index;
  795. }
  796. len = *(data + index);
  797. index++;
  798. /*
  799. * FIXME: Would be nice to check elements like for v1/v2 in
  800. * goto_next_sequence() above.
  801. */
  802. switch (operation_byte) {
  803. case MIPI_SEQ_ELEM_SEND_PKT:
  804. case MIPI_SEQ_ELEM_DELAY:
  805. case MIPI_SEQ_ELEM_GPIO:
  806. case MIPI_SEQ_ELEM_I2C:
  807. case MIPI_SEQ_ELEM_SPI:
  808. case MIPI_SEQ_ELEM_PMIC:
  809. break;
  810. default:
  811. DRM_ERROR("Unknown operation byte %u\n",
  812. operation_byte);
  813. break;
  814. }
  815. }
  816. return 0;
  817. }
  818. /*
  819. * Get len of pre-fixed deassert fragment from a v1 init OTP sequence,
  820. * skip all delay + gpio operands and stop at the first DSI packet op.
  821. */
  822. static int get_init_otp_deassert_fragment_len(struct drm_i915_private *dev_priv)
  823. {
  824. const u8 *data = dev_priv->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP];
  825. int index, len;
  826. if (WARN_ON(!data || dev_priv->vbt.dsi.seq_version != 1))
  827. return 0;
  828. /* index = 1 to skip sequence byte */
  829. for (index = 1; data[index] != MIPI_SEQ_ELEM_END; index += len) {
  830. switch (data[index]) {
  831. case MIPI_SEQ_ELEM_SEND_PKT:
  832. return index == 1 ? 0 : index;
  833. case MIPI_SEQ_ELEM_DELAY:
  834. len = 5; /* 1 byte for operand + uint32 */
  835. break;
  836. case MIPI_SEQ_ELEM_GPIO:
  837. len = 3; /* 1 byte for op, 1 for gpio_nr, 1 for value */
  838. break;
  839. default:
  840. return 0;
  841. }
  842. }
  843. return 0;
  844. }
  845. /*
  846. * Some v1 VBT MIPI sequences do the deassert in the init OTP sequence.
  847. * The deassert must be done before calling intel_dsi_device_ready, so for
  848. * these devices we split the init OTP sequence into a deassert sequence and
  849. * the actual init OTP part.
  850. */
  851. static void fixup_mipi_sequences(struct drm_i915_private *dev_priv)
  852. {
  853. u8 *init_otp;
  854. int len;
  855. /* Limit this to VLV for now. */
  856. if (!IS_VALLEYVIEW(dev_priv))
  857. return;
  858. /* Limit this to v1 vid-mode sequences */
  859. if (dev_priv->vbt.dsi.config->is_cmd_mode ||
  860. dev_priv->vbt.dsi.seq_version != 1)
  861. return;
  862. /* Only do this if there are otp and assert seqs and no deassert seq */
  863. if (!dev_priv->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] ||
  864. !dev_priv->vbt.dsi.sequence[MIPI_SEQ_ASSERT_RESET] ||
  865. dev_priv->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET])
  866. return;
  867. /* The deassert-sequence ends at the first DSI packet */
  868. len = get_init_otp_deassert_fragment_len(dev_priv);
  869. if (!len)
  870. return;
  871. DRM_DEBUG_KMS("Using init OTP fragment to deassert reset\n");
  872. /* Copy the fragment, update seq byte and terminate it */
  873. init_otp = (u8 *)dev_priv->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP];
  874. dev_priv->vbt.dsi.deassert_seq = kmemdup(init_otp, len + 1, GFP_KERNEL);
  875. if (!dev_priv->vbt.dsi.deassert_seq)
  876. return;
  877. dev_priv->vbt.dsi.deassert_seq[0] = MIPI_SEQ_DEASSERT_RESET;
  878. dev_priv->vbt.dsi.deassert_seq[len] = MIPI_SEQ_ELEM_END;
  879. /* Use the copy for deassert */
  880. dev_priv->vbt.dsi.sequence[MIPI_SEQ_DEASSERT_RESET] =
  881. dev_priv->vbt.dsi.deassert_seq;
  882. /* Replace the last byte of the fragment with init OTP seq byte */
  883. init_otp[len - 1] = MIPI_SEQ_INIT_OTP;
  884. /* And make MIPI_MIPI_SEQ_INIT_OTP point to it */
  885. dev_priv->vbt.dsi.sequence[MIPI_SEQ_INIT_OTP] = init_otp + len - 1;
  886. }
  887. static void
  888. parse_mipi_sequence(struct drm_i915_private *dev_priv,
  889. const struct bdb_header *bdb)
  890. {
  891. int panel_type = dev_priv->vbt.panel_type;
  892. const struct bdb_mipi_sequence *sequence;
  893. const u8 *seq_data;
  894. u32 seq_size;
  895. u8 *data;
  896. int index = 0;
  897. /* Only our generic panel driver uses the sequence block. */
  898. if (dev_priv->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
  899. return;
  900. sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
  901. if (!sequence) {
  902. DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
  903. return;
  904. }
  905. /* Fail gracefully for forward incompatible sequence block. */
  906. if (sequence->version >= 4) {
  907. DRM_ERROR("Unable to parse MIPI Sequence Block v%u\n",
  908. sequence->version);
  909. return;
  910. }
  911. DRM_DEBUG_DRIVER("Found MIPI sequence block v%u\n", sequence->version);
  912. seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size);
  913. if (!seq_data)
  914. return;
  915. data = kmemdup(seq_data, seq_size, GFP_KERNEL);
  916. if (!data)
  917. return;
  918. /* Parse the sequences, store pointers to each sequence. */
  919. for (;;) {
  920. u8 seq_id = *(data + index);
  921. if (seq_id == MIPI_SEQ_END)
  922. break;
  923. if (seq_id >= MIPI_SEQ_MAX) {
  924. DRM_ERROR("Unknown sequence %u\n", seq_id);
  925. goto err;
  926. }
  927. /* Log about presence of sequences we won't run. */
  928. if (seq_id == MIPI_SEQ_TEAR_ON || seq_id == MIPI_SEQ_TEAR_OFF)
  929. DRM_DEBUG_KMS("Unsupported sequence %u\n", seq_id);
  930. dev_priv->vbt.dsi.sequence[seq_id] = data + index;
  931. if (sequence->version >= 3)
  932. index = goto_next_sequence_v3(data, index, seq_size);
  933. else
  934. index = goto_next_sequence(data, index, seq_size);
  935. if (!index) {
  936. DRM_ERROR("Invalid sequence %u\n", seq_id);
  937. goto err;
  938. }
  939. }
  940. dev_priv->vbt.dsi.data = data;
  941. dev_priv->vbt.dsi.size = seq_size;
  942. dev_priv->vbt.dsi.seq_version = sequence->version;
  943. fixup_mipi_sequences(dev_priv);
  944. DRM_DEBUG_DRIVER("MIPI related VBT parsing complete\n");
  945. return;
  946. err:
  947. kfree(data);
  948. memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
  949. }
  950. static u8 translate_iboost(u8 val)
  951. {
  952. static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
  953. if (val >= ARRAY_SIZE(mapping)) {
  954. DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
  955. return 0;
  956. }
  957. return mapping[val];
  958. }
  959. static void sanitize_ddc_pin(struct drm_i915_private *dev_priv,
  960. enum port port)
  961. {
  962. const struct ddi_vbt_port_info *info =
  963. &dev_priv->vbt.ddi_port_info[port];
  964. enum port p;
  965. if (!info->alternate_ddc_pin)
  966. return;
  967. for_each_port_masked(p, (1 << port) - 1) {
  968. struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
  969. if (info->alternate_ddc_pin != i->alternate_ddc_pin)
  970. continue;
  971. DRM_DEBUG_KMS("port %c trying to use the same DDC pin (0x%x) as port %c, "
  972. "disabling port %c DVI/HDMI support\n",
  973. port_name(p), i->alternate_ddc_pin,
  974. port_name(port), port_name(p));
  975. /*
  976. * If we have multiple ports supposedly sharing the
  977. * pin, then dvi/hdmi couldn't exist on the shared
  978. * port. Otherwise they share the same ddc bin and
  979. * system couldn't communicate with them separately.
  980. *
  981. * Due to parsing the ports in alphabetical order,
  982. * a higher port will always clobber a lower one.
  983. */
  984. i->supports_dvi = false;
  985. i->supports_hdmi = false;
  986. i->alternate_ddc_pin = 0;
  987. }
  988. }
  989. static void sanitize_aux_ch(struct drm_i915_private *dev_priv,
  990. enum port port)
  991. {
  992. const struct ddi_vbt_port_info *info =
  993. &dev_priv->vbt.ddi_port_info[port];
  994. enum port p;
  995. if (!info->alternate_aux_channel)
  996. return;
  997. for_each_port_masked(p, (1 << port) - 1) {
  998. struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
  999. if (info->alternate_aux_channel != i->alternate_aux_channel)
  1000. continue;
  1001. DRM_DEBUG_KMS("port %c trying to use the same AUX CH (0x%x) as port %c, "
  1002. "disabling port %c DP support\n",
  1003. port_name(p), i->alternate_aux_channel,
  1004. port_name(port), port_name(p));
  1005. /*
  1006. * If we have multiple ports supposedlt sharing the
  1007. * aux channel, then DP couldn't exist on the shared
  1008. * port. Otherwise they share the same aux channel
  1009. * and system couldn't communicate with them separately.
  1010. *
  1011. * Due to parsing the ports in alphabetical order,
  1012. * a higher port will always clobber a lower one.
  1013. */
  1014. i->supports_dp = false;
  1015. i->alternate_aux_channel = 0;
  1016. }
  1017. }
  1018. static const u8 cnp_ddc_pin_map[] = {
  1019. [0] = 0, /* N/A */
  1020. [DDC_BUS_DDI_B] = GMBUS_PIN_1_BXT,
  1021. [DDC_BUS_DDI_C] = GMBUS_PIN_2_BXT,
  1022. [DDC_BUS_DDI_D] = GMBUS_PIN_4_CNP, /* sic */
  1023. [DDC_BUS_DDI_F] = GMBUS_PIN_3_BXT, /* sic */
  1024. };
  1025. static u8 map_ddc_pin(struct drm_i915_private *dev_priv, u8 vbt_pin)
  1026. {
  1027. if (HAS_PCH_CNP(dev_priv)) {
  1028. if (vbt_pin < ARRAY_SIZE(cnp_ddc_pin_map)) {
  1029. return cnp_ddc_pin_map[vbt_pin];
  1030. } else {
  1031. DRM_DEBUG_KMS("Ignoring alternate pin: VBT claims DDC pin %d, which is not valid for this platform\n", vbt_pin);
  1032. return 0;
  1033. }
  1034. }
  1035. return vbt_pin;
  1036. }
  1037. static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
  1038. u8 bdb_version)
  1039. {
  1040. struct child_device_config *it, *child = NULL;
  1041. struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
  1042. uint8_t hdmi_level_shift;
  1043. int i, j;
  1044. bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
  1045. uint8_t aux_channel, ddc_pin;
  1046. /* Each DDI port can have more than one value on the "DVO Port" field,
  1047. * so look for all the possible values for each port.
  1048. */
  1049. int dvo_ports[][3] = {
  1050. {DVO_PORT_HDMIA, DVO_PORT_DPA, -1},
  1051. {DVO_PORT_HDMIB, DVO_PORT_DPB, -1},
  1052. {DVO_PORT_HDMIC, DVO_PORT_DPC, -1},
  1053. {DVO_PORT_HDMID, DVO_PORT_DPD, -1},
  1054. {DVO_PORT_CRT, DVO_PORT_HDMIE, DVO_PORT_DPE},
  1055. {DVO_PORT_HDMIF, DVO_PORT_DPF, -1},
  1056. };
  1057. /*
  1058. * Find the first child device to reference the port, report if more
  1059. * than one found.
  1060. */
  1061. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1062. it = dev_priv->vbt.child_dev + i;
  1063. for (j = 0; j < 3; j++) {
  1064. if (dvo_ports[port][j] == -1)
  1065. break;
  1066. if (it->dvo_port == dvo_ports[port][j]) {
  1067. if (child) {
  1068. DRM_DEBUG_KMS("More than one child device for port %c in VBT, using the first.\n",
  1069. port_name(port));
  1070. } else {
  1071. child = it;
  1072. }
  1073. }
  1074. }
  1075. }
  1076. if (!child)
  1077. return;
  1078. aux_channel = child->aux_channel;
  1079. is_dvi = child->device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
  1080. is_dp = child->device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
  1081. is_crt = child->device_type & DEVICE_TYPE_ANALOG_OUTPUT;
  1082. is_hdmi = is_dvi && (child->device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
  1083. is_edp = is_dp && (child->device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
  1084. if (port == PORT_A && is_dvi) {
  1085. DRM_DEBUG_KMS("VBT claims port A supports DVI%s, ignoring\n",
  1086. is_hdmi ? "/HDMI" : "");
  1087. is_dvi = false;
  1088. is_hdmi = false;
  1089. }
  1090. if (port == PORT_A && is_dvi) {
  1091. DRM_DEBUG_KMS("VBT claims port A supports DVI%s, ignoring\n",
  1092. is_hdmi ? "/HDMI" : "");
  1093. is_dvi = false;
  1094. is_hdmi = false;
  1095. }
  1096. info->supports_dvi = is_dvi;
  1097. info->supports_hdmi = is_hdmi;
  1098. info->supports_dp = is_dp;
  1099. info->supports_edp = is_edp;
  1100. DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
  1101. port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
  1102. if (is_edp && is_dvi)
  1103. DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
  1104. port_name(port));
  1105. if (is_crt && port != PORT_E)
  1106. DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
  1107. if (is_crt && (is_dvi || is_dp))
  1108. DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
  1109. port_name(port));
  1110. if (is_dvi && (port == PORT_A || port == PORT_E))
  1111. DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port));
  1112. if (!is_dvi && !is_dp && !is_crt)
  1113. DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
  1114. port_name(port));
  1115. if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
  1116. DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
  1117. if (is_dvi) {
  1118. ddc_pin = map_ddc_pin(dev_priv, child->ddc_pin);
  1119. if (intel_gmbus_is_valid_pin(dev_priv, ddc_pin)) {
  1120. info->alternate_ddc_pin = ddc_pin;
  1121. sanitize_ddc_pin(dev_priv, port);
  1122. } else {
  1123. DRM_DEBUG_KMS("Port %c has invalid DDC pin %d, "
  1124. "sticking to defaults\n",
  1125. port_name(port), ddc_pin);
  1126. }
  1127. }
  1128. if (is_dp) {
  1129. info->alternate_aux_channel = aux_channel;
  1130. sanitize_aux_ch(dev_priv, port);
  1131. }
  1132. if (bdb_version >= 158) {
  1133. /* The VBT HDMI level shift values match the table we have. */
  1134. hdmi_level_shift = child->hdmi_level_shifter_value;
  1135. DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
  1136. port_name(port),
  1137. hdmi_level_shift);
  1138. info->hdmi_level_shift = hdmi_level_shift;
  1139. }
  1140. if (bdb_version >= 204) {
  1141. int max_tmds_clock;
  1142. switch (child->hdmi_max_data_rate) {
  1143. default:
  1144. MISSING_CASE(child->hdmi_max_data_rate);
  1145. /* fall through */
  1146. case HDMI_MAX_DATA_RATE_PLATFORM:
  1147. max_tmds_clock = 0;
  1148. break;
  1149. case HDMI_MAX_DATA_RATE_297:
  1150. max_tmds_clock = 297000;
  1151. break;
  1152. case HDMI_MAX_DATA_RATE_165:
  1153. max_tmds_clock = 165000;
  1154. break;
  1155. }
  1156. if (max_tmds_clock)
  1157. DRM_DEBUG_KMS("VBT HDMI max TMDS clock for port %c: %d kHz\n",
  1158. port_name(port), max_tmds_clock);
  1159. info->max_tmds_clock = max_tmds_clock;
  1160. }
  1161. /* Parse the I_boost config for SKL and above */
  1162. if (bdb_version >= 196 && child->iboost) {
  1163. info->dp_boost_level = translate_iboost(child->dp_iboost_level);
  1164. DRM_DEBUG_KMS("VBT (e)DP boost level for port %c: %d\n",
  1165. port_name(port), info->dp_boost_level);
  1166. info->hdmi_boost_level = translate_iboost(child->hdmi_iboost_level);
  1167. DRM_DEBUG_KMS("VBT HDMI boost level for port %c: %d\n",
  1168. port_name(port), info->hdmi_boost_level);
  1169. }
  1170. /* DP max link rate for CNL+ */
  1171. if (bdb_version >= 216) {
  1172. switch (child->dp_max_link_rate) {
  1173. default:
  1174. case VBT_DP_MAX_LINK_RATE_HBR3:
  1175. info->dp_max_link_rate = 810000;
  1176. break;
  1177. case VBT_DP_MAX_LINK_RATE_HBR2:
  1178. info->dp_max_link_rate = 540000;
  1179. break;
  1180. case VBT_DP_MAX_LINK_RATE_HBR:
  1181. info->dp_max_link_rate = 270000;
  1182. break;
  1183. case VBT_DP_MAX_LINK_RATE_LBR:
  1184. info->dp_max_link_rate = 162000;
  1185. break;
  1186. }
  1187. DRM_DEBUG_KMS("VBT DP max link rate for port %c: %d\n",
  1188. port_name(port), info->dp_max_link_rate);
  1189. }
  1190. }
  1191. static void parse_ddi_ports(struct drm_i915_private *dev_priv, u8 bdb_version)
  1192. {
  1193. enum port port;
  1194. if (!HAS_DDI(dev_priv) && !IS_CHERRYVIEW(dev_priv))
  1195. return;
  1196. if (!dev_priv->vbt.child_dev_num)
  1197. return;
  1198. if (bdb_version < 155)
  1199. return;
  1200. for (port = PORT_A; port < I915_MAX_PORTS; port++)
  1201. parse_ddi_port(dev_priv, port, bdb_version);
  1202. }
  1203. static void
  1204. parse_general_definitions(struct drm_i915_private *dev_priv,
  1205. const struct bdb_header *bdb)
  1206. {
  1207. const struct bdb_general_definitions *defs;
  1208. const struct child_device_config *child;
  1209. int i, child_device_num, count;
  1210. u8 expected_size;
  1211. u16 block_size;
  1212. int bus_pin;
  1213. defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  1214. if (!defs) {
  1215. DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
  1216. return;
  1217. }
  1218. block_size = get_blocksize(defs);
  1219. if (block_size < sizeof(*defs)) {
  1220. DRM_DEBUG_KMS("General definitions block too small (%u)\n",
  1221. block_size);
  1222. return;
  1223. }
  1224. bus_pin = defs->crt_ddc_gmbus_pin;
  1225. DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
  1226. if (intel_gmbus_is_valid_pin(dev_priv, bus_pin))
  1227. dev_priv->vbt.crt_ddc_pin = bus_pin;
  1228. if (bdb->version < 106) {
  1229. expected_size = 22;
  1230. } else if (bdb->version < 111) {
  1231. expected_size = 27;
  1232. } else if (bdb->version < 195) {
  1233. expected_size = LEGACY_CHILD_DEVICE_CONFIG_SIZE;
  1234. } else if (bdb->version == 195) {
  1235. expected_size = 37;
  1236. } else if (bdb->version <= 215) {
  1237. expected_size = 38;
  1238. } else if (bdb->version <= 216) {
  1239. expected_size = 39;
  1240. } else {
  1241. expected_size = sizeof(*child);
  1242. BUILD_BUG_ON(sizeof(*child) < 39);
  1243. DRM_DEBUG_DRIVER("Expected child device config size for VBT version %u not known; assuming %u\n",
  1244. bdb->version, expected_size);
  1245. }
  1246. /* Flag an error for unexpected size, but continue anyway. */
  1247. if (defs->child_dev_size != expected_size)
  1248. DRM_ERROR("Unexpected child device config size %u (expected %u for VBT version %u)\n",
  1249. defs->child_dev_size, expected_size, bdb->version);
  1250. /* The legacy sized child device config is the minimum we need. */
  1251. if (defs->child_dev_size < LEGACY_CHILD_DEVICE_CONFIG_SIZE) {
  1252. DRM_DEBUG_KMS("Child device config size %u is too small.\n",
  1253. defs->child_dev_size);
  1254. return;
  1255. }
  1256. /* get the number of child device */
  1257. child_device_num = (block_size - sizeof(*defs)) / defs->child_dev_size;
  1258. count = 0;
  1259. /* get the number of child device that is present */
  1260. for (i = 0; i < child_device_num; i++) {
  1261. child = child_device_ptr(defs, i);
  1262. if (!child->device_type)
  1263. continue;
  1264. count++;
  1265. }
  1266. if (!count) {
  1267. DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
  1268. return;
  1269. }
  1270. dev_priv->vbt.child_dev = kcalloc(count, sizeof(*child), GFP_KERNEL);
  1271. if (!dev_priv->vbt.child_dev) {
  1272. DRM_DEBUG_KMS("No memory space for child device\n");
  1273. return;
  1274. }
  1275. dev_priv->vbt.child_dev_num = count;
  1276. count = 0;
  1277. for (i = 0; i < child_device_num; i++) {
  1278. child = child_device_ptr(defs, i);
  1279. if (!child->device_type)
  1280. continue;
  1281. /*
  1282. * Copy as much as we know (sizeof) and is available
  1283. * (child_dev_size) of the child device. Accessing the data must
  1284. * depend on VBT version.
  1285. */
  1286. memcpy(dev_priv->vbt.child_dev + count, child,
  1287. min_t(size_t, defs->child_dev_size, sizeof(*child)));
  1288. count++;
  1289. }
  1290. }
  1291. /* Common defaults which may be overridden by VBT. */
  1292. static void
  1293. init_vbt_defaults(struct drm_i915_private *dev_priv)
  1294. {
  1295. enum port port;
  1296. dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
  1297. /* Default to having backlight */
  1298. dev_priv->vbt.backlight.present = true;
  1299. /* LFP panel data */
  1300. dev_priv->vbt.lvds_dither = 1;
  1301. dev_priv->vbt.lvds_vbt = 0;
  1302. /* SDVO panel data */
  1303. dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
  1304. /* general features */
  1305. dev_priv->vbt.int_tv_support = 1;
  1306. dev_priv->vbt.int_crt_support = 1;
  1307. /* Default to using SSC */
  1308. dev_priv->vbt.lvds_use_ssc = 1;
  1309. /*
  1310. * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
  1311. * clock for LVDS.
  1312. */
  1313. dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev_priv,
  1314. !HAS_PCH_SPLIT(dev_priv));
  1315. DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
  1316. for (port = PORT_A; port < I915_MAX_PORTS; port++) {
  1317. struct ddi_vbt_port_info *info =
  1318. &dev_priv->vbt.ddi_port_info[port];
  1319. info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
  1320. }
  1321. }
  1322. /* Defaults to initialize only if there is no VBT. */
  1323. static void
  1324. init_vbt_missing_defaults(struct drm_i915_private *dev_priv)
  1325. {
  1326. enum port port;
  1327. for (port = PORT_A; port < I915_MAX_PORTS; port++) {
  1328. struct ddi_vbt_port_info *info =
  1329. &dev_priv->vbt.ddi_port_info[port];
  1330. info->supports_dvi = (port != PORT_A && port != PORT_E);
  1331. info->supports_hdmi = info->supports_dvi;
  1332. info->supports_dp = (port != PORT_E);
  1333. }
  1334. }
  1335. static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
  1336. {
  1337. const void *_vbt = vbt;
  1338. return _vbt + vbt->bdb_offset;
  1339. }
  1340. /**
  1341. * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
  1342. * @buf: pointer to a buffer to validate
  1343. * @size: size of the buffer
  1344. *
  1345. * Returns true on valid VBT.
  1346. */
  1347. bool intel_bios_is_valid_vbt(const void *buf, size_t size)
  1348. {
  1349. const struct vbt_header *vbt = buf;
  1350. const struct bdb_header *bdb;
  1351. if (!vbt)
  1352. return false;
  1353. if (sizeof(struct vbt_header) > size) {
  1354. DRM_DEBUG_DRIVER("VBT header incomplete\n");
  1355. return false;
  1356. }
  1357. if (memcmp(vbt->signature, "$VBT", 4)) {
  1358. DRM_DEBUG_DRIVER("VBT invalid signature\n");
  1359. return false;
  1360. }
  1361. if (range_overflows_t(size_t,
  1362. vbt->bdb_offset,
  1363. sizeof(struct bdb_header),
  1364. size)) {
  1365. DRM_DEBUG_DRIVER("BDB header incomplete\n");
  1366. return false;
  1367. }
  1368. bdb = get_bdb_header(vbt);
  1369. if (range_overflows_t(size_t, vbt->bdb_offset, bdb->bdb_size, size)) {
  1370. DRM_DEBUG_DRIVER("BDB incomplete\n");
  1371. return false;
  1372. }
  1373. return vbt;
  1374. }
  1375. static const struct vbt_header *find_vbt(void __iomem *bios, size_t size)
  1376. {
  1377. size_t i;
  1378. /* Scour memory looking for the VBT signature. */
  1379. for (i = 0; i + 4 < size; i++) {
  1380. void *vbt;
  1381. if (ioread32(bios + i) != *((const u32 *) "$VBT"))
  1382. continue;
  1383. /*
  1384. * This is the one place where we explicitly discard the address
  1385. * space (__iomem) of the BIOS/VBT.
  1386. */
  1387. vbt = (void __force *) bios + i;
  1388. if (intel_bios_is_valid_vbt(vbt, size - i))
  1389. return vbt;
  1390. break;
  1391. }
  1392. return NULL;
  1393. }
  1394. /**
  1395. * intel_bios_init - find VBT and initialize settings from the BIOS
  1396. * @dev_priv: i915 device instance
  1397. *
  1398. * Parse and initialize settings from the Video BIOS Tables (VBT). If the VBT
  1399. * was not found in ACPI OpRegion, try to find it in PCI ROM first. Also
  1400. * initialize some defaults if the VBT is not present at all.
  1401. */
  1402. void intel_bios_init(struct drm_i915_private *dev_priv)
  1403. {
  1404. struct pci_dev *pdev = dev_priv->drm.pdev;
  1405. const struct vbt_header *vbt = dev_priv->opregion.vbt;
  1406. const struct bdb_header *bdb;
  1407. u8 __iomem *bios = NULL;
  1408. if (HAS_PCH_NOP(dev_priv)) {
  1409. DRM_DEBUG_KMS("Skipping VBT init due to disabled display.\n");
  1410. return;
  1411. }
  1412. init_vbt_defaults(dev_priv);
  1413. /* If the OpRegion does not have VBT, look in PCI ROM. */
  1414. if (!vbt) {
  1415. size_t size;
  1416. bios = pci_map_rom(pdev, &size);
  1417. if (!bios)
  1418. goto out;
  1419. vbt = find_vbt(bios, size);
  1420. if (!vbt)
  1421. goto out;
  1422. DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
  1423. }
  1424. bdb = get_bdb_header(vbt);
  1425. DRM_DEBUG_KMS("VBT signature \"%.*s\", BDB version %d\n",
  1426. (int)sizeof(vbt->signature), vbt->signature, bdb->version);
  1427. /* Grab useful general definitions */
  1428. parse_general_features(dev_priv, bdb);
  1429. parse_general_definitions(dev_priv, bdb);
  1430. parse_lfp_panel_data(dev_priv, bdb);
  1431. parse_lfp_backlight(dev_priv, bdb);
  1432. parse_sdvo_panel_data(dev_priv, bdb);
  1433. parse_driver_features(dev_priv, bdb);
  1434. parse_edp(dev_priv, bdb);
  1435. parse_psr(dev_priv, bdb);
  1436. parse_mipi_config(dev_priv, bdb);
  1437. parse_mipi_sequence(dev_priv, bdb);
  1438. /* Further processing on pre-parsed data */
  1439. parse_sdvo_device_mapping(dev_priv, bdb->version);
  1440. parse_ddi_ports(dev_priv, bdb->version);
  1441. out:
  1442. if (!vbt) {
  1443. DRM_INFO("Failed to find VBIOS tables (VBT)\n");
  1444. init_vbt_missing_defaults(dev_priv);
  1445. }
  1446. if (bios)
  1447. pci_unmap_rom(pdev, bios);
  1448. }
  1449. /**
  1450. * intel_bios_cleanup - Free any resources allocated by intel_bios_init()
  1451. * @dev_priv: i915 device instance
  1452. */
  1453. void intel_bios_cleanup(struct drm_i915_private *dev_priv)
  1454. {
  1455. kfree(dev_priv->vbt.child_dev);
  1456. dev_priv->vbt.child_dev = NULL;
  1457. dev_priv->vbt.child_dev_num = 0;
  1458. kfree(dev_priv->vbt.sdvo_lvds_vbt_mode);
  1459. dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
  1460. kfree(dev_priv->vbt.lfp_lvds_vbt_mode);
  1461. dev_priv->vbt.lfp_lvds_vbt_mode = NULL;
  1462. kfree(dev_priv->vbt.dsi.data);
  1463. dev_priv->vbt.dsi.data = NULL;
  1464. kfree(dev_priv->vbt.dsi.pps);
  1465. dev_priv->vbt.dsi.pps = NULL;
  1466. kfree(dev_priv->vbt.dsi.config);
  1467. dev_priv->vbt.dsi.config = NULL;
  1468. kfree(dev_priv->vbt.dsi.deassert_seq);
  1469. dev_priv->vbt.dsi.deassert_seq = NULL;
  1470. }
  1471. /**
  1472. * intel_bios_is_tv_present - is integrated TV present in VBT
  1473. * @dev_priv: i915 device instance
  1474. *
  1475. * Return true if TV is present. If no child devices were parsed from VBT,
  1476. * assume TV is present.
  1477. */
  1478. bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv)
  1479. {
  1480. const struct child_device_config *child;
  1481. int i;
  1482. if (!dev_priv->vbt.int_tv_support)
  1483. return false;
  1484. if (!dev_priv->vbt.child_dev_num)
  1485. return true;
  1486. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1487. child = dev_priv->vbt.child_dev + i;
  1488. /*
  1489. * If the device type is not TV, continue.
  1490. */
  1491. switch (child->device_type) {
  1492. case DEVICE_TYPE_INT_TV:
  1493. case DEVICE_TYPE_TV:
  1494. case DEVICE_TYPE_TV_SVIDEO_COMPOSITE:
  1495. break;
  1496. default:
  1497. continue;
  1498. }
  1499. /* Only when the addin_offset is non-zero, it is regarded
  1500. * as present.
  1501. */
  1502. if (child->addin_offset)
  1503. return true;
  1504. }
  1505. return false;
  1506. }
  1507. /**
  1508. * intel_bios_is_lvds_present - is LVDS present in VBT
  1509. * @dev_priv: i915 device instance
  1510. * @i2c_pin: i2c pin for LVDS if present
  1511. *
  1512. * Return true if LVDS is present. If no child devices were parsed from VBT,
  1513. * assume LVDS is present.
  1514. */
  1515. bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin)
  1516. {
  1517. const struct child_device_config *child;
  1518. int i;
  1519. if (!dev_priv->vbt.child_dev_num)
  1520. return true;
  1521. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1522. child = dev_priv->vbt.child_dev + i;
  1523. /* If the device type is not LFP, continue.
  1524. * We have to check both the new identifiers as well as the
  1525. * old for compatibility with some BIOSes.
  1526. */
  1527. if (child->device_type != DEVICE_TYPE_INT_LFP &&
  1528. child->device_type != DEVICE_TYPE_LFP)
  1529. continue;
  1530. if (intel_gmbus_is_valid_pin(dev_priv, child->i2c_pin))
  1531. *i2c_pin = child->i2c_pin;
  1532. /* However, we cannot trust the BIOS writers to populate
  1533. * the VBT correctly. Since LVDS requires additional
  1534. * information from AIM blocks, a non-zero addin offset is
  1535. * a good indicator that the LVDS is actually present.
  1536. */
  1537. if (child->addin_offset)
  1538. return true;
  1539. /* But even then some BIOS writers perform some black magic
  1540. * and instantiate the device without reference to any
  1541. * additional data. Trust that if the VBT was written into
  1542. * the OpRegion then they have validated the LVDS's existence.
  1543. */
  1544. if (dev_priv->opregion.vbt)
  1545. return true;
  1546. }
  1547. return false;
  1548. }
  1549. /**
  1550. * intel_bios_is_port_present - is the specified digital port present
  1551. * @dev_priv: i915 device instance
  1552. * @port: port to check
  1553. *
  1554. * Return true if the device in %port is present.
  1555. */
  1556. bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port)
  1557. {
  1558. const struct child_device_config *child;
  1559. static const struct {
  1560. u16 dp, hdmi;
  1561. } port_mapping[] = {
  1562. [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
  1563. [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
  1564. [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
  1565. [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
  1566. [PORT_F] = { DVO_PORT_DPF, DVO_PORT_HDMIF, },
  1567. };
  1568. int i;
  1569. /* FIXME maybe deal with port A as well? */
  1570. if (WARN_ON(port == PORT_A) || port >= ARRAY_SIZE(port_mapping))
  1571. return false;
  1572. if (!dev_priv->vbt.child_dev_num)
  1573. return false;
  1574. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1575. child = dev_priv->vbt.child_dev + i;
  1576. if ((child->dvo_port == port_mapping[port].dp ||
  1577. child->dvo_port == port_mapping[port].hdmi) &&
  1578. (child->device_type & (DEVICE_TYPE_TMDS_DVI_SIGNALING |
  1579. DEVICE_TYPE_DISPLAYPORT_OUTPUT)))
  1580. return true;
  1581. }
  1582. return false;
  1583. }
  1584. /**
  1585. * intel_bios_is_port_edp - is the device in given port eDP
  1586. * @dev_priv: i915 device instance
  1587. * @port: port to check
  1588. *
  1589. * Return true if the device in %port is eDP.
  1590. */
  1591. bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
  1592. {
  1593. const struct child_device_config *child;
  1594. static const short port_mapping[] = {
  1595. [PORT_B] = DVO_PORT_DPB,
  1596. [PORT_C] = DVO_PORT_DPC,
  1597. [PORT_D] = DVO_PORT_DPD,
  1598. [PORT_E] = DVO_PORT_DPE,
  1599. [PORT_F] = DVO_PORT_DPF,
  1600. };
  1601. int i;
  1602. if (HAS_DDI(dev_priv))
  1603. return dev_priv->vbt.ddi_port_info[port].supports_edp;
  1604. if (!dev_priv->vbt.child_dev_num)
  1605. return false;
  1606. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1607. child = dev_priv->vbt.child_dev + i;
  1608. if (child->dvo_port == port_mapping[port] &&
  1609. (child->device_type & DEVICE_TYPE_eDP_BITS) ==
  1610. (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
  1611. return true;
  1612. }
  1613. return false;
  1614. }
  1615. static bool child_dev_is_dp_dual_mode(const struct child_device_config *child,
  1616. enum port port)
  1617. {
  1618. static const struct {
  1619. u16 dp, hdmi;
  1620. } port_mapping[] = {
  1621. /*
  1622. * Buggy VBTs may declare DP ports as having
  1623. * HDMI type dvo_port :( So let's check both.
  1624. */
  1625. [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
  1626. [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
  1627. [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
  1628. [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
  1629. [PORT_F] = { DVO_PORT_DPF, DVO_PORT_HDMIF, },
  1630. };
  1631. if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
  1632. return false;
  1633. if ((child->device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) !=
  1634. (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
  1635. return false;
  1636. if (child->dvo_port == port_mapping[port].dp)
  1637. return true;
  1638. /* Only accept a HDMI dvo_port as DP++ if it has an AUX channel */
  1639. if (child->dvo_port == port_mapping[port].hdmi &&
  1640. child->aux_channel != 0)
  1641. return true;
  1642. return false;
  1643. }
  1644. bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv,
  1645. enum port port)
  1646. {
  1647. const struct child_device_config *child;
  1648. int i;
  1649. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1650. child = dev_priv->vbt.child_dev + i;
  1651. if (child_dev_is_dp_dual_mode(child, port))
  1652. return true;
  1653. }
  1654. return false;
  1655. }
  1656. /**
  1657. * intel_bios_is_dsi_present - is DSI present in VBT
  1658. * @dev_priv: i915 device instance
  1659. * @port: port for DSI if present
  1660. *
  1661. * Return true if DSI is present, and return the port in %port.
  1662. */
  1663. bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv,
  1664. enum port *port)
  1665. {
  1666. const struct child_device_config *child;
  1667. u8 dvo_port;
  1668. int i;
  1669. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1670. child = dev_priv->vbt.child_dev + i;
  1671. if (!(child->device_type & DEVICE_TYPE_MIPI_OUTPUT))
  1672. continue;
  1673. dvo_port = child->dvo_port;
  1674. switch (dvo_port) {
  1675. case DVO_PORT_MIPIA:
  1676. case DVO_PORT_MIPIC:
  1677. if (port)
  1678. *port = dvo_port - DVO_PORT_MIPIA;
  1679. return true;
  1680. case DVO_PORT_MIPIB:
  1681. case DVO_PORT_MIPID:
  1682. DRM_DEBUG_KMS("VBT has unsupported DSI port %c\n",
  1683. port_name(dvo_port - DVO_PORT_MIPIA));
  1684. break;
  1685. }
  1686. }
  1687. return false;
  1688. }
  1689. /**
  1690. * intel_bios_is_port_hpd_inverted - is HPD inverted for %port
  1691. * @dev_priv: i915 device instance
  1692. * @port: port to check
  1693. *
  1694. * Return true if HPD should be inverted for %port.
  1695. */
  1696. bool
  1697. intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
  1698. enum port port)
  1699. {
  1700. const struct child_device_config *child;
  1701. int i;
  1702. if (WARN_ON_ONCE(!IS_GEN9_LP(dev_priv)))
  1703. return false;
  1704. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1705. child = dev_priv->vbt.child_dev + i;
  1706. if (!child->hpd_invert)
  1707. continue;
  1708. switch (child->dvo_port) {
  1709. case DVO_PORT_DPA:
  1710. case DVO_PORT_HDMIA:
  1711. if (port == PORT_A)
  1712. return true;
  1713. break;
  1714. case DVO_PORT_DPB:
  1715. case DVO_PORT_HDMIB:
  1716. if (port == PORT_B)
  1717. return true;
  1718. break;
  1719. case DVO_PORT_DPC:
  1720. case DVO_PORT_HDMIC:
  1721. if (port == PORT_C)
  1722. return true;
  1723. break;
  1724. default:
  1725. break;
  1726. }
  1727. }
  1728. return false;
  1729. }
  1730. /**
  1731. * intel_bios_is_lspcon_present - if LSPCON is attached on %port
  1732. * @dev_priv: i915 device instance
  1733. * @port: port to check
  1734. *
  1735. * Return true if LSPCON is present on this port
  1736. */
  1737. bool
  1738. intel_bios_is_lspcon_present(struct drm_i915_private *dev_priv,
  1739. enum port port)
  1740. {
  1741. const struct child_device_config *child;
  1742. int i;
  1743. if (!HAS_LSPCON(dev_priv))
  1744. return false;
  1745. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1746. child = dev_priv->vbt.child_dev + i;
  1747. if (!child->lspcon)
  1748. continue;
  1749. switch (child->dvo_port) {
  1750. case DVO_PORT_DPA:
  1751. case DVO_PORT_HDMIA:
  1752. if (port == PORT_A)
  1753. return true;
  1754. break;
  1755. case DVO_PORT_DPB:
  1756. case DVO_PORT_HDMIB:
  1757. if (port == PORT_B)
  1758. return true;
  1759. break;
  1760. case DVO_PORT_DPC:
  1761. case DVO_PORT_HDMIC:
  1762. if (port == PORT_C)
  1763. return true;
  1764. break;
  1765. case DVO_PORT_DPD:
  1766. case DVO_PORT_HDMID:
  1767. if (port == PORT_D)
  1768. return true;
  1769. break;
  1770. case DVO_PORT_DPF:
  1771. case DVO_PORT_HDMIF:
  1772. if (port == PORT_F)
  1773. return true;
  1774. break;
  1775. default:
  1776. break;
  1777. }
  1778. }
  1779. return false;
  1780. }