intel_bios.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887
  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.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_INFO(dev_priv)->gen) {
  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 void
  372. parse_general_definitions(struct drm_i915_private *dev_priv,
  373. const struct bdb_header *bdb)
  374. {
  375. const struct bdb_general_definitions *general;
  376. general = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  377. if (general) {
  378. u16 block_size = get_blocksize(general);
  379. if (block_size >= sizeof(*general)) {
  380. int bus_pin = general->crt_ddc_gmbus_pin;
  381. DRM_DEBUG_KMS("crt_ddc_bus_pin: %d\n", bus_pin);
  382. if (intel_gmbus_is_valid_pin(dev_priv, bus_pin))
  383. dev_priv->vbt.crt_ddc_pin = bus_pin;
  384. } else {
  385. DRM_DEBUG_KMS("BDB_GD too small (%d). Invalid.\n",
  386. block_size);
  387. }
  388. }
  389. }
  390. static const union child_device_config *
  391. child_device_ptr(const struct bdb_general_definitions *p_defs, int i)
  392. {
  393. return (const void *) &p_defs->devices[i * p_defs->child_dev_size];
  394. }
  395. static void
  396. parse_sdvo_device_mapping(struct drm_i915_private *dev_priv,
  397. const struct bdb_header *bdb)
  398. {
  399. struct sdvo_device_mapping *p_mapping;
  400. const struct bdb_general_definitions *p_defs;
  401. const struct old_child_dev_config *child; /* legacy */
  402. int i, child_device_num, count;
  403. u16 block_size;
  404. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  405. if (!p_defs) {
  406. DRM_DEBUG_KMS("No general definition block is found, unable to construct sdvo mapping.\n");
  407. return;
  408. }
  409. /*
  410. * Only parse SDVO mappings when the general definitions block child
  411. * device size matches that of the *legacy* child device config
  412. * struct. Thus, SDVO mapping will be skipped for newer VBT.
  413. */
  414. if (p_defs->child_dev_size != sizeof(*child)) {
  415. DRM_DEBUG_KMS("Unsupported child device size for SDVO mapping.\n");
  416. return;
  417. }
  418. /* get the block size of general definitions */
  419. block_size = get_blocksize(p_defs);
  420. /* get the number of child device */
  421. child_device_num = (block_size - sizeof(*p_defs)) /
  422. p_defs->child_dev_size;
  423. count = 0;
  424. for (i = 0; i < child_device_num; i++) {
  425. child = &child_device_ptr(p_defs, i)->old;
  426. if (!child->device_type) {
  427. /* skip the device block if device type is invalid */
  428. continue;
  429. }
  430. if (child->slave_addr != SLAVE_ADDR1 &&
  431. child->slave_addr != SLAVE_ADDR2) {
  432. /*
  433. * If the slave address is neither 0x70 nor 0x72,
  434. * it is not a SDVO device. Skip it.
  435. */
  436. continue;
  437. }
  438. if (child->dvo_port != DEVICE_PORT_DVOB &&
  439. child->dvo_port != DEVICE_PORT_DVOC) {
  440. /* skip the incorrect SDVO port */
  441. DRM_DEBUG_KMS("Incorrect SDVO port. Skip it\n");
  442. continue;
  443. }
  444. DRM_DEBUG_KMS("the SDVO device with slave addr %2x is found on"
  445. " %s port\n",
  446. child->slave_addr,
  447. (child->dvo_port == DEVICE_PORT_DVOB) ?
  448. "SDVOB" : "SDVOC");
  449. p_mapping = &dev_priv->vbt.sdvo_mappings[child->dvo_port - 1];
  450. if (!p_mapping->initialized) {
  451. p_mapping->dvo_port = child->dvo_port;
  452. p_mapping->slave_addr = child->slave_addr;
  453. p_mapping->dvo_wiring = child->dvo_wiring;
  454. p_mapping->ddc_pin = child->ddc_pin;
  455. p_mapping->i2c_pin = child->i2c_pin;
  456. p_mapping->initialized = 1;
  457. DRM_DEBUG_KMS("SDVO device: dvo=%x, addr=%x, wiring=%d, ddc_pin=%d, i2c_pin=%d\n",
  458. p_mapping->dvo_port,
  459. p_mapping->slave_addr,
  460. p_mapping->dvo_wiring,
  461. p_mapping->ddc_pin,
  462. p_mapping->i2c_pin);
  463. } else {
  464. DRM_DEBUG_KMS("Maybe one SDVO port is shared by "
  465. "two SDVO device.\n");
  466. }
  467. if (child->slave2_addr) {
  468. /* Maybe this is a SDVO device with multiple inputs */
  469. /* And the mapping info is not added */
  470. DRM_DEBUG_KMS("there exists the slave2_addr. Maybe this"
  471. " is a SDVO device with multiple inputs.\n");
  472. }
  473. count++;
  474. }
  475. if (!count) {
  476. /* No SDVO device info is found */
  477. DRM_DEBUG_KMS("No SDVO device info is found in VBT\n");
  478. }
  479. return;
  480. }
  481. static void
  482. parse_driver_features(struct drm_i915_private *dev_priv,
  483. const struct bdb_header *bdb)
  484. {
  485. const struct bdb_driver_features *driver;
  486. driver = find_section(bdb, BDB_DRIVER_FEATURES);
  487. if (!driver)
  488. return;
  489. if (driver->lvds_config == BDB_DRIVER_FEATURE_EDP)
  490. dev_priv->vbt.edp.support = 1;
  491. DRM_DEBUG_KMS("DRRS State Enabled:%d\n", driver->drrs_enabled);
  492. /*
  493. * If DRRS is not supported, drrs_type has to be set to 0.
  494. * This is because, VBT is configured in such a way that
  495. * static DRRS is 0 and DRRS not supported is represented by
  496. * driver->drrs_enabled=false
  497. */
  498. if (!driver->drrs_enabled)
  499. dev_priv->vbt.drrs_type = DRRS_NOT_SUPPORTED;
  500. }
  501. static void
  502. parse_edp(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
  503. {
  504. const struct bdb_edp *edp;
  505. const struct edp_power_seq *edp_pps;
  506. const struct edp_link_params *edp_link_params;
  507. int panel_type = dev_priv->vbt.panel_type;
  508. edp = find_section(bdb, BDB_EDP);
  509. if (!edp) {
  510. if (dev_priv->vbt.edp.support)
  511. DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported.\n");
  512. return;
  513. }
  514. switch ((edp->color_depth >> (panel_type * 2)) & 3) {
  515. case EDP_18BPP:
  516. dev_priv->vbt.edp.bpp = 18;
  517. break;
  518. case EDP_24BPP:
  519. dev_priv->vbt.edp.bpp = 24;
  520. break;
  521. case EDP_30BPP:
  522. dev_priv->vbt.edp.bpp = 30;
  523. break;
  524. }
  525. /* Get the eDP sequencing and link info */
  526. edp_pps = &edp->power_seqs[panel_type];
  527. edp_link_params = &edp->link_params[panel_type];
  528. dev_priv->vbt.edp.pps = *edp_pps;
  529. switch (edp_link_params->rate) {
  530. case EDP_RATE_1_62:
  531. dev_priv->vbt.edp.rate = DP_LINK_BW_1_62;
  532. break;
  533. case EDP_RATE_2_7:
  534. dev_priv->vbt.edp.rate = DP_LINK_BW_2_7;
  535. break;
  536. default:
  537. DRM_DEBUG_KMS("VBT has unknown eDP link rate value %u\n",
  538. edp_link_params->rate);
  539. break;
  540. }
  541. switch (edp_link_params->lanes) {
  542. case EDP_LANE_1:
  543. dev_priv->vbt.edp.lanes = 1;
  544. break;
  545. case EDP_LANE_2:
  546. dev_priv->vbt.edp.lanes = 2;
  547. break;
  548. case EDP_LANE_4:
  549. dev_priv->vbt.edp.lanes = 4;
  550. break;
  551. default:
  552. DRM_DEBUG_KMS("VBT has unknown eDP lane count value %u\n",
  553. edp_link_params->lanes);
  554. break;
  555. }
  556. switch (edp_link_params->preemphasis) {
  557. case EDP_PREEMPHASIS_NONE:
  558. dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_0;
  559. break;
  560. case EDP_PREEMPHASIS_3_5dB:
  561. dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_1;
  562. break;
  563. case EDP_PREEMPHASIS_6dB:
  564. dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_2;
  565. break;
  566. case EDP_PREEMPHASIS_9_5dB:
  567. dev_priv->vbt.edp.preemphasis = DP_TRAIN_PRE_EMPH_LEVEL_3;
  568. break;
  569. default:
  570. DRM_DEBUG_KMS("VBT has unknown eDP pre-emphasis value %u\n",
  571. edp_link_params->preemphasis);
  572. break;
  573. }
  574. switch (edp_link_params->vswing) {
  575. case EDP_VSWING_0_4V:
  576. dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_0;
  577. break;
  578. case EDP_VSWING_0_6V:
  579. dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_1;
  580. break;
  581. case EDP_VSWING_0_8V:
  582. dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_2;
  583. break;
  584. case EDP_VSWING_1_2V:
  585. dev_priv->vbt.edp.vswing = DP_TRAIN_VOLTAGE_SWING_LEVEL_3;
  586. break;
  587. default:
  588. DRM_DEBUG_KMS("VBT has unknown eDP voltage swing value %u\n",
  589. edp_link_params->vswing);
  590. break;
  591. }
  592. if (bdb->version >= 173) {
  593. uint8_t vswing;
  594. /* Don't read from VBT if module parameter has valid value*/
  595. if (i915.edp_vswing) {
  596. dev_priv->vbt.edp.low_vswing = i915.edp_vswing == 1;
  597. } else {
  598. vswing = (edp->edp_vswing_preemph >> (panel_type * 4)) & 0xF;
  599. dev_priv->vbt.edp.low_vswing = vswing == 0;
  600. }
  601. }
  602. }
  603. static void
  604. parse_psr(struct drm_i915_private *dev_priv, const struct bdb_header *bdb)
  605. {
  606. const struct bdb_psr *psr;
  607. const struct psr_table *psr_table;
  608. int panel_type = dev_priv->vbt.panel_type;
  609. psr = find_section(bdb, BDB_PSR);
  610. if (!psr) {
  611. DRM_DEBUG_KMS("No PSR BDB found.\n");
  612. return;
  613. }
  614. psr_table = &psr->psr_table[panel_type];
  615. dev_priv->vbt.psr.full_link = psr_table->full_link;
  616. dev_priv->vbt.psr.require_aux_wakeup = psr_table->require_aux_to_wakeup;
  617. /* Allowed VBT values goes from 0 to 15 */
  618. dev_priv->vbt.psr.idle_frames = psr_table->idle_frames < 0 ? 0 :
  619. psr_table->idle_frames > 15 ? 15 : psr_table->idle_frames;
  620. switch (psr_table->lines_to_wait) {
  621. case 0:
  622. dev_priv->vbt.psr.lines_to_wait = PSR_0_LINES_TO_WAIT;
  623. break;
  624. case 1:
  625. dev_priv->vbt.psr.lines_to_wait = PSR_1_LINE_TO_WAIT;
  626. break;
  627. case 2:
  628. dev_priv->vbt.psr.lines_to_wait = PSR_4_LINES_TO_WAIT;
  629. break;
  630. case 3:
  631. dev_priv->vbt.psr.lines_to_wait = PSR_8_LINES_TO_WAIT;
  632. break;
  633. default:
  634. DRM_DEBUG_KMS("VBT has unknown PSR lines to wait %u\n",
  635. psr_table->lines_to_wait);
  636. break;
  637. }
  638. dev_priv->vbt.psr.tp1_wakeup_time = psr_table->tp1_wakeup_time;
  639. dev_priv->vbt.psr.tp2_tp3_wakeup_time = psr_table->tp2_tp3_wakeup_time;
  640. }
  641. static void
  642. parse_mipi_config(struct drm_i915_private *dev_priv,
  643. const struct bdb_header *bdb)
  644. {
  645. const struct bdb_mipi_config *start;
  646. const struct mipi_config *config;
  647. const struct mipi_pps_data *pps;
  648. int panel_type = dev_priv->vbt.panel_type;
  649. /* parse MIPI blocks only if LFP type is MIPI */
  650. if (!intel_bios_is_dsi_present(dev_priv, NULL))
  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. /*
  684. * These fields are introduced from the VBT version 197 onwards,
  685. * so making sure that these bits are set zero in the previous
  686. * versions.
  687. */
  688. if (dev_priv->vbt.dsi.config->dual_link && bdb->version < 197) {
  689. dev_priv->vbt.dsi.config->dl_dcs_cabc_ports = 0;
  690. dev_priv->vbt.dsi.config->dl_dcs_backlight_ports = 0;
  691. }
  692. /* We have mandatory mipi config blocks. Initialize as generic panel */
  693. dev_priv->vbt.dsi.panel_id = MIPI_DSI_GENERIC_PANEL_ID;
  694. }
  695. /* Find the sequence block and size for the given panel. */
  696. static const u8 *
  697. find_panel_sequence_block(const struct bdb_mipi_sequence *sequence,
  698. u16 panel_id, u32 *seq_size)
  699. {
  700. u32 total = get_blocksize(sequence);
  701. const u8 *data = &sequence->data[0];
  702. u8 current_id;
  703. u32 current_size;
  704. int header_size = sequence->version >= 3 ? 5 : 3;
  705. int index = 0;
  706. int i;
  707. /* skip new block size */
  708. if (sequence->version >= 3)
  709. data += 4;
  710. for (i = 0; i < MAX_MIPI_CONFIGURATIONS && index < total; i++) {
  711. if (index + header_size > total) {
  712. DRM_ERROR("Invalid sequence block (header)\n");
  713. return NULL;
  714. }
  715. current_id = *(data + index);
  716. if (sequence->version >= 3)
  717. current_size = *((const u32 *)(data + index + 1));
  718. else
  719. current_size = *((const u16 *)(data + index + 1));
  720. index += header_size;
  721. if (index + current_size > total) {
  722. DRM_ERROR("Invalid sequence block\n");
  723. return NULL;
  724. }
  725. if (current_id == panel_id) {
  726. *seq_size = current_size;
  727. return data + index;
  728. }
  729. index += current_size;
  730. }
  731. DRM_ERROR("Sequence block detected but no valid configuration\n");
  732. return NULL;
  733. }
  734. static int goto_next_sequence(const u8 *data, int index, int total)
  735. {
  736. u16 len;
  737. /* Skip Sequence Byte. */
  738. for (index = index + 1; index < total; index += len) {
  739. u8 operation_byte = *(data + index);
  740. index++;
  741. switch (operation_byte) {
  742. case MIPI_SEQ_ELEM_END:
  743. return index;
  744. case MIPI_SEQ_ELEM_SEND_PKT:
  745. if (index + 4 > total)
  746. return 0;
  747. len = *((const u16 *)(data + index + 2)) + 4;
  748. break;
  749. case MIPI_SEQ_ELEM_DELAY:
  750. len = 4;
  751. break;
  752. case MIPI_SEQ_ELEM_GPIO:
  753. len = 2;
  754. break;
  755. case MIPI_SEQ_ELEM_I2C:
  756. if (index + 7 > total)
  757. return 0;
  758. len = *(data + index + 6) + 7;
  759. break;
  760. default:
  761. DRM_ERROR("Unknown operation byte\n");
  762. return 0;
  763. }
  764. }
  765. return 0;
  766. }
  767. static int goto_next_sequence_v3(const u8 *data, int index, int total)
  768. {
  769. int seq_end;
  770. u16 len;
  771. u32 size_of_sequence;
  772. /*
  773. * Could skip sequence based on Size of Sequence alone, but also do some
  774. * checking on the structure.
  775. */
  776. if (total < 5) {
  777. DRM_ERROR("Too small sequence size\n");
  778. return 0;
  779. }
  780. /* Skip Sequence Byte. */
  781. index++;
  782. /*
  783. * Size of Sequence. Excludes the Sequence Byte and the size itself,
  784. * includes MIPI_SEQ_ELEM_END byte, excludes the final MIPI_SEQ_END
  785. * byte.
  786. */
  787. size_of_sequence = *((const uint32_t *)(data + index));
  788. index += 4;
  789. seq_end = index + size_of_sequence;
  790. if (seq_end > total) {
  791. DRM_ERROR("Invalid sequence size\n");
  792. return 0;
  793. }
  794. for (; index < total; index += len) {
  795. u8 operation_byte = *(data + index);
  796. index++;
  797. if (operation_byte == MIPI_SEQ_ELEM_END) {
  798. if (index != seq_end) {
  799. DRM_ERROR("Invalid element structure\n");
  800. return 0;
  801. }
  802. return index;
  803. }
  804. len = *(data + index);
  805. index++;
  806. /*
  807. * FIXME: Would be nice to check elements like for v1/v2 in
  808. * goto_next_sequence() above.
  809. */
  810. switch (operation_byte) {
  811. case MIPI_SEQ_ELEM_SEND_PKT:
  812. case MIPI_SEQ_ELEM_DELAY:
  813. case MIPI_SEQ_ELEM_GPIO:
  814. case MIPI_SEQ_ELEM_I2C:
  815. case MIPI_SEQ_ELEM_SPI:
  816. case MIPI_SEQ_ELEM_PMIC:
  817. break;
  818. default:
  819. DRM_ERROR("Unknown operation byte %u\n",
  820. operation_byte);
  821. break;
  822. }
  823. }
  824. return 0;
  825. }
  826. static void
  827. parse_mipi_sequence(struct drm_i915_private *dev_priv,
  828. const struct bdb_header *bdb)
  829. {
  830. int panel_type = dev_priv->vbt.panel_type;
  831. const struct bdb_mipi_sequence *sequence;
  832. const u8 *seq_data;
  833. u32 seq_size;
  834. u8 *data;
  835. int index = 0;
  836. /* Only our generic panel driver uses the sequence block. */
  837. if (dev_priv->vbt.dsi.panel_id != MIPI_DSI_GENERIC_PANEL_ID)
  838. return;
  839. sequence = find_section(bdb, BDB_MIPI_SEQUENCE);
  840. if (!sequence) {
  841. DRM_DEBUG_KMS("No MIPI Sequence found, parsing complete\n");
  842. return;
  843. }
  844. /* Fail gracefully for forward incompatible sequence block. */
  845. if (sequence->version >= 4) {
  846. DRM_ERROR("Unable to parse MIPI Sequence Block v%u\n",
  847. sequence->version);
  848. return;
  849. }
  850. DRM_DEBUG_DRIVER("Found MIPI sequence block v%u\n", sequence->version);
  851. seq_data = find_panel_sequence_block(sequence, panel_type, &seq_size);
  852. if (!seq_data)
  853. return;
  854. data = kmemdup(seq_data, seq_size, GFP_KERNEL);
  855. if (!data)
  856. return;
  857. /* Parse the sequences, store pointers to each sequence. */
  858. for (;;) {
  859. u8 seq_id = *(data + index);
  860. if (seq_id == MIPI_SEQ_END)
  861. break;
  862. if (seq_id >= MIPI_SEQ_MAX) {
  863. DRM_ERROR("Unknown sequence %u\n", seq_id);
  864. goto err;
  865. }
  866. /* Log about presence of sequences we won't run. */
  867. if (seq_id == MIPI_SEQ_TEAR_ON || seq_id == MIPI_SEQ_TEAR_OFF)
  868. DRM_DEBUG_KMS("Unsupported sequence %u\n", seq_id);
  869. dev_priv->vbt.dsi.sequence[seq_id] = data + index;
  870. if (sequence->version >= 3)
  871. index = goto_next_sequence_v3(data, index, seq_size);
  872. else
  873. index = goto_next_sequence(data, index, seq_size);
  874. if (!index) {
  875. DRM_ERROR("Invalid sequence %u\n", seq_id);
  876. goto err;
  877. }
  878. }
  879. dev_priv->vbt.dsi.data = data;
  880. dev_priv->vbt.dsi.size = seq_size;
  881. dev_priv->vbt.dsi.seq_version = sequence->version;
  882. DRM_DEBUG_DRIVER("MIPI related VBT parsing complete\n");
  883. return;
  884. err:
  885. kfree(data);
  886. memset(dev_priv->vbt.dsi.sequence, 0, sizeof(dev_priv->vbt.dsi.sequence));
  887. }
  888. static u8 translate_iboost(u8 val)
  889. {
  890. static const u8 mapping[] = { 1, 3, 7 }; /* See VBT spec */
  891. if (val >= ARRAY_SIZE(mapping)) {
  892. DRM_DEBUG_KMS("Unsupported I_boost value found in VBT (%d), display may not work properly\n", val);
  893. return 0;
  894. }
  895. return mapping[val];
  896. }
  897. static void sanitize_ddc_pin(struct drm_i915_private *dev_priv,
  898. enum port port)
  899. {
  900. const struct ddi_vbt_port_info *info =
  901. &dev_priv->vbt.ddi_port_info[port];
  902. enum port p;
  903. if (!info->alternate_ddc_pin)
  904. return;
  905. for_each_port_masked(p, (1 << port) - 1) {
  906. struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
  907. if (info->alternate_ddc_pin != i->alternate_ddc_pin)
  908. continue;
  909. DRM_DEBUG_KMS("port %c trying to use the same DDC pin (0x%x) as port %c, "
  910. "disabling port %c DVI/HDMI support\n",
  911. port_name(p), i->alternate_ddc_pin,
  912. port_name(port), port_name(p));
  913. /*
  914. * If we have multiple ports supposedly sharing the
  915. * pin, then dvi/hdmi couldn't exist on the shared
  916. * port. Otherwise they share the same ddc bin and
  917. * system couldn't communicate with them separately.
  918. *
  919. * Due to parsing the ports in alphabetical order,
  920. * a higher port will always clobber a lower one.
  921. */
  922. i->supports_dvi = false;
  923. i->supports_hdmi = false;
  924. i->alternate_ddc_pin = 0;
  925. }
  926. }
  927. static void sanitize_aux_ch(struct drm_i915_private *dev_priv,
  928. enum port port)
  929. {
  930. const struct ddi_vbt_port_info *info =
  931. &dev_priv->vbt.ddi_port_info[port];
  932. enum port p;
  933. if (!info->alternate_aux_channel)
  934. return;
  935. for_each_port_masked(p, (1 << port) - 1) {
  936. struct ddi_vbt_port_info *i = &dev_priv->vbt.ddi_port_info[p];
  937. if (info->alternate_aux_channel != i->alternate_aux_channel)
  938. continue;
  939. DRM_DEBUG_KMS("port %c trying to use the same AUX CH (0x%x) as port %c, "
  940. "disabling port %c DP support\n",
  941. port_name(p), i->alternate_aux_channel,
  942. port_name(port), port_name(p));
  943. /*
  944. * If we have multiple ports supposedlt sharing the
  945. * aux channel, then DP couldn't exist on the shared
  946. * port. Otherwise they share the same aux channel
  947. * and system couldn't communicate with them separately.
  948. *
  949. * Due to parsing the ports in alphabetical order,
  950. * a higher port will always clobber a lower one.
  951. */
  952. i->supports_dp = false;
  953. i->alternate_aux_channel = 0;
  954. }
  955. }
  956. static void parse_ddi_port(struct drm_i915_private *dev_priv, enum port port,
  957. const struct bdb_header *bdb)
  958. {
  959. union child_device_config *it, *child = NULL;
  960. struct ddi_vbt_port_info *info = &dev_priv->vbt.ddi_port_info[port];
  961. uint8_t hdmi_level_shift;
  962. int i, j;
  963. bool is_dvi, is_hdmi, is_dp, is_edp, is_crt;
  964. uint8_t aux_channel, ddc_pin;
  965. /* Each DDI port can have more than one value on the "DVO Port" field,
  966. * so look for all the possible values for each port and abort if more
  967. * than one is found. */
  968. int dvo_ports[][3] = {
  969. {DVO_PORT_HDMIA, DVO_PORT_DPA, -1},
  970. {DVO_PORT_HDMIB, DVO_PORT_DPB, -1},
  971. {DVO_PORT_HDMIC, DVO_PORT_DPC, -1},
  972. {DVO_PORT_HDMID, DVO_PORT_DPD, -1},
  973. {DVO_PORT_CRT, DVO_PORT_HDMIE, DVO_PORT_DPE},
  974. };
  975. /* Find the child device to use, abort if more than one found. */
  976. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  977. it = dev_priv->vbt.child_dev + i;
  978. for (j = 0; j < 3; j++) {
  979. if (dvo_ports[port][j] == -1)
  980. break;
  981. if (it->common.dvo_port == dvo_ports[port][j]) {
  982. if (child) {
  983. DRM_DEBUG_KMS("More than one child device for port %c in VBT.\n",
  984. port_name(port));
  985. return;
  986. }
  987. child = it;
  988. }
  989. }
  990. }
  991. if (!child)
  992. return;
  993. aux_channel = child->common.aux_channel;
  994. ddc_pin = child->common.ddc_pin;
  995. is_dvi = child->common.device_type & DEVICE_TYPE_TMDS_DVI_SIGNALING;
  996. is_dp = child->common.device_type & DEVICE_TYPE_DISPLAYPORT_OUTPUT;
  997. is_crt = child->common.device_type & DEVICE_TYPE_ANALOG_OUTPUT;
  998. is_hdmi = is_dvi && (child->common.device_type & DEVICE_TYPE_NOT_HDMI_OUTPUT) == 0;
  999. is_edp = is_dp && (child->common.device_type & DEVICE_TYPE_INTERNAL_CONNECTOR);
  1000. info->supports_dvi = is_dvi;
  1001. info->supports_hdmi = is_hdmi;
  1002. info->supports_dp = is_dp;
  1003. info->supports_edp = is_edp;
  1004. DRM_DEBUG_KMS("Port %c VBT info: DP:%d HDMI:%d DVI:%d EDP:%d CRT:%d\n",
  1005. port_name(port), is_dp, is_hdmi, is_dvi, is_edp, is_crt);
  1006. if (is_edp && is_dvi)
  1007. DRM_DEBUG_KMS("Internal DP port %c is TMDS compatible\n",
  1008. port_name(port));
  1009. if (is_crt && port != PORT_E)
  1010. DRM_DEBUG_KMS("Port %c is analog\n", port_name(port));
  1011. if (is_crt && (is_dvi || is_dp))
  1012. DRM_DEBUG_KMS("Analog port %c is also DP or TMDS compatible\n",
  1013. port_name(port));
  1014. if (is_dvi && (port == PORT_A || port == PORT_E))
  1015. DRM_DEBUG_KMS("Port %c is TMDS compatible\n", port_name(port));
  1016. if (!is_dvi && !is_dp && !is_crt)
  1017. DRM_DEBUG_KMS("Port %c is not DP/TMDS/CRT compatible\n",
  1018. port_name(port));
  1019. if (is_edp && (port == PORT_B || port == PORT_C || port == PORT_E))
  1020. DRM_DEBUG_KMS("Port %c is internal DP\n", port_name(port));
  1021. if (is_dvi) {
  1022. info->alternate_ddc_pin = ddc_pin;
  1023. sanitize_ddc_pin(dev_priv, port);
  1024. }
  1025. if (is_dp) {
  1026. info->alternate_aux_channel = aux_channel;
  1027. sanitize_aux_ch(dev_priv, port);
  1028. }
  1029. if (bdb->version >= 158) {
  1030. /* The VBT HDMI level shift values match the table we have. */
  1031. hdmi_level_shift = child->raw[7] & 0xF;
  1032. DRM_DEBUG_KMS("VBT HDMI level shift for port %c: %d\n",
  1033. port_name(port),
  1034. hdmi_level_shift);
  1035. info->hdmi_level_shift = hdmi_level_shift;
  1036. }
  1037. /* Parse the I_boost config for SKL and above */
  1038. if (bdb->version >= 196 && child->common.iboost) {
  1039. info->dp_boost_level = translate_iboost(child->common.iboost_level & 0xF);
  1040. DRM_DEBUG_KMS("VBT (e)DP boost level for port %c: %d\n",
  1041. port_name(port), info->dp_boost_level);
  1042. info->hdmi_boost_level = translate_iboost(child->common.iboost_level >> 4);
  1043. DRM_DEBUG_KMS("VBT HDMI boost level for port %c: %d\n",
  1044. port_name(port), info->hdmi_boost_level);
  1045. }
  1046. }
  1047. static void parse_ddi_ports(struct drm_i915_private *dev_priv,
  1048. const struct bdb_header *bdb)
  1049. {
  1050. enum port port;
  1051. if (!HAS_DDI(dev_priv))
  1052. return;
  1053. if (!dev_priv->vbt.child_dev_num)
  1054. return;
  1055. if (bdb->version < 155)
  1056. return;
  1057. for (port = PORT_A; port < I915_MAX_PORTS; port++)
  1058. parse_ddi_port(dev_priv, port, bdb);
  1059. }
  1060. static void
  1061. parse_device_mapping(struct drm_i915_private *dev_priv,
  1062. const struct bdb_header *bdb)
  1063. {
  1064. const struct bdb_general_definitions *p_defs;
  1065. const union child_device_config *p_child;
  1066. union child_device_config *child_dev_ptr;
  1067. int i, child_device_num, count;
  1068. u8 expected_size;
  1069. u16 block_size;
  1070. p_defs = find_section(bdb, BDB_GENERAL_DEFINITIONS);
  1071. if (!p_defs) {
  1072. DRM_DEBUG_KMS("No general definition block is found, no devices defined.\n");
  1073. return;
  1074. }
  1075. if (bdb->version < 106) {
  1076. expected_size = 22;
  1077. } else if (bdb->version < 111) {
  1078. expected_size = 27;
  1079. } else if (bdb->version < 195) {
  1080. BUILD_BUG_ON(sizeof(struct old_child_dev_config) != 33);
  1081. expected_size = sizeof(struct old_child_dev_config);
  1082. } else if (bdb->version == 195) {
  1083. expected_size = 37;
  1084. } else if (bdb->version <= 197) {
  1085. expected_size = 38;
  1086. } else {
  1087. expected_size = 38;
  1088. BUILD_BUG_ON(sizeof(*p_child) < 38);
  1089. DRM_DEBUG_DRIVER("Expected child device config size for VBT version %u not known; assuming %u\n",
  1090. bdb->version, expected_size);
  1091. }
  1092. /* Flag an error for unexpected size, but continue anyway. */
  1093. if (p_defs->child_dev_size != expected_size)
  1094. DRM_ERROR("Unexpected child device config size %u (expected %u for VBT version %u)\n",
  1095. p_defs->child_dev_size, expected_size, bdb->version);
  1096. /* The legacy sized child device config is the minimum we need. */
  1097. if (p_defs->child_dev_size < sizeof(struct old_child_dev_config)) {
  1098. DRM_DEBUG_KMS("Child device config size %u is too small.\n",
  1099. p_defs->child_dev_size);
  1100. return;
  1101. }
  1102. /* get the block size of general definitions */
  1103. block_size = get_blocksize(p_defs);
  1104. /* get the number of child device */
  1105. child_device_num = (block_size - sizeof(*p_defs)) /
  1106. p_defs->child_dev_size;
  1107. count = 0;
  1108. /* get the number of child device that is present */
  1109. for (i = 0; i < child_device_num; i++) {
  1110. p_child = child_device_ptr(p_defs, i);
  1111. if (!p_child->common.device_type) {
  1112. /* skip the device block if device type is invalid */
  1113. continue;
  1114. }
  1115. count++;
  1116. }
  1117. if (!count) {
  1118. DRM_DEBUG_KMS("no child dev is parsed from VBT\n");
  1119. return;
  1120. }
  1121. dev_priv->vbt.child_dev = kcalloc(count, sizeof(*p_child), GFP_KERNEL);
  1122. if (!dev_priv->vbt.child_dev) {
  1123. DRM_DEBUG_KMS("No memory space for child device\n");
  1124. return;
  1125. }
  1126. dev_priv->vbt.child_dev_num = count;
  1127. count = 0;
  1128. for (i = 0; i < child_device_num; i++) {
  1129. p_child = child_device_ptr(p_defs, i);
  1130. if (!p_child->common.device_type) {
  1131. /* skip the device block if device type is invalid */
  1132. continue;
  1133. }
  1134. child_dev_ptr = dev_priv->vbt.child_dev + count;
  1135. count++;
  1136. /*
  1137. * Copy as much as we know (sizeof) and is available
  1138. * (child_dev_size) of the child device. Accessing the data must
  1139. * depend on VBT version.
  1140. */
  1141. memcpy(child_dev_ptr, p_child,
  1142. min_t(size_t, p_defs->child_dev_size, sizeof(*p_child)));
  1143. /*
  1144. * copied full block, now init values when they are not
  1145. * available in current version
  1146. */
  1147. if (bdb->version < 196) {
  1148. /* Set default values for bits added from v196 */
  1149. child_dev_ptr->common.iboost = 0;
  1150. child_dev_ptr->common.hpd_invert = 0;
  1151. }
  1152. if (bdb->version < 192)
  1153. child_dev_ptr->common.lspcon = 0;
  1154. }
  1155. return;
  1156. }
  1157. /* Common defaults which may be overridden by VBT. */
  1158. static void
  1159. init_vbt_defaults(struct drm_i915_private *dev_priv)
  1160. {
  1161. enum port port;
  1162. dev_priv->vbt.crt_ddc_pin = GMBUS_PIN_VGADDC;
  1163. /* Default to having backlight */
  1164. dev_priv->vbt.backlight.present = true;
  1165. /* LFP panel data */
  1166. dev_priv->vbt.lvds_dither = 1;
  1167. dev_priv->vbt.lvds_vbt = 0;
  1168. /* SDVO panel data */
  1169. dev_priv->vbt.sdvo_lvds_vbt_mode = NULL;
  1170. /* general features */
  1171. dev_priv->vbt.int_tv_support = 1;
  1172. dev_priv->vbt.int_crt_support = 1;
  1173. /* Default to using SSC */
  1174. dev_priv->vbt.lvds_use_ssc = 1;
  1175. /*
  1176. * Core/SandyBridge/IvyBridge use alternative (120MHz) reference
  1177. * clock for LVDS.
  1178. */
  1179. dev_priv->vbt.lvds_ssc_freq = intel_bios_ssc_frequency(dev_priv,
  1180. !HAS_PCH_SPLIT(dev_priv));
  1181. DRM_DEBUG_KMS("Set default to SSC at %d kHz\n", dev_priv->vbt.lvds_ssc_freq);
  1182. for (port = PORT_A; port < I915_MAX_PORTS; port++) {
  1183. struct ddi_vbt_port_info *info =
  1184. &dev_priv->vbt.ddi_port_info[port];
  1185. info->hdmi_level_shift = HDMI_LEVEL_SHIFT_UNKNOWN;
  1186. }
  1187. }
  1188. /* Defaults to initialize only if there is no VBT. */
  1189. static void
  1190. init_vbt_missing_defaults(struct drm_i915_private *dev_priv)
  1191. {
  1192. enum port port;
  1193. for (port = PORT_A; port < I915_MAX_PORTS; port++) {
  1194. struct ddi_vbt_port_info *info =
  1195. &dev_priv->vbt.ddi_port_info[port];
  1196. info->supports_dvi = (port != PORT_A && port != PORT_E);
  1197. info->supports_hdmi = info->supports_dvi;
  1198. info->supports_dp = (port != PORT_E);
  1199. }
  1200. }
  1201. static const struct bdb_header *get_bdb_header(const struct vbt_header *vbt)
  1202. {
  1203. const void *_vbt = vbt;
  1204. return _vbt + vbt->bdb_offset;
  1205. }
  1206. /**
  1207. * intel_bios_is_valid_vbt - does the given buffer contain a valid VBT
  1208. * @buf: pointer to a buffer to validate
  1209. * @size: size of the buffer
  1210. *
  1211. * Returns true on valid VBT.
  1212. */
  1213. bool intel_bios_is_valid_vbt(const void *buf, size_t size)
  1214. {
  1215. const struct vbt_header *vbt = buf;
  1216. const struct bdb_header *bdb;
  1217. if (!vbt)
  1218. return false;
  1219. if (sizeof(struct vbt_header) > size) {
  1220. DRM_DEBUG_DRIVER("VBT header incomplete\n");
  1221. return false;
  1222. }
  1223. if (memcmp(vbt->signature, "$VBT", 4)) {
  1224. DRM_DEBUG_DRIVER("VBT invalid signature\n");
  1225. return false;
  1226. }
  1227. if (range_overflows_t(size_t,
  1228. vbt->bdb_offset,
  1229. sizeof(struct bdb_header),
  1230. size)) {
  1231. DRM_DEBUG_DRIVER("BDB header incomplete\n");
  1232. return false;
  1233. }
  1234. bdb = get_bdb_header(vbt);
  1235. if (range_overflows_t(size_t, vbt->bdb_offset, bdb->bdb_size, size)) {
  1236. DRM_DEBUG_DRIVER("BDB incomplete\n");
  1237. return false;
  1238. }
  1239. return vbt;
  1240. }
  1241. static const struct vbt_header *find_vbt(void __iomem *bios, size_t size)
  1242. {
  1243. size_t i;
  1244. /* Scour memory looking for the VBT signature. */
  1245. for (i = 0; i + 4 < size; i++) {
  1246. void *vbt;
  1247. if (ioread32(bios + i) != *((const u32 *) "$VBT"))
  1248. continue;
  1249. /*
  1250. * This is the one place where we explicitly discard the address
  1251. * space (__iomem) of the BIOS/VBT.
  1252. */
  1253. vbt = (void __force *) bios + i;
  1254. if (intel_bios_is_valid_vbt(vbt, size - i))
  1255. return vbt;
  1256. break;
  1257. }
  1258. return NULL;
  1259. }
  1260. /**
  1261. * intel_bios_init - find VBT and initialize settings from the BIOS
  1262. * @dev_priv: i915 device instance
  1263. *
  1264. * Parse and initialize settings from the Video BIOS Tables (VBT). If the VBT
  1265. * was not found in ACPI OpRegion, try to find it in PCI ROM first. Also
  1266. * initialize some defaults if the VBT is not present at all.
  1267. */
  1268. void intel_bios_init(struct drm_i915_private *dev_priv)
  1269. {
  1270. struct pci_dev *pdev = dev_priv->drm.pdev;
  1271. const struct vbt_header *vbt = dev_priv->opregion.vbt;
  1272. const struct bdb_header *bdb;
  1273. u8 __iomem *bios = NULL;
  1274. if (HAS_PCH_NOP(dev_priv)) {
  1275. DRM_DEBUG_KMS("Skipping VBT init due to disabled display.\n");
  1276. return;
  1277. }
  1278. init_vbt_defaults(dev_priv);
  1279. /* If the OpRegion does not have VBT, look in PCI ROM. */
  1280. if (!vbt) {
  1281. size_t size;
  1282. bios = pci_map_rom(pdev, &size);
  1283. if (!bios)
  1284. goto out;
  1285. vbt = find_vbt(bios, size);
  1286. if (!vbt)
  1287. goto out;
  1288. DRM_DEBUG_KMS("Found valid VBT in PCI ROM\n");
  1289. }
  1290. bdb = get_bdb_header(vbt);
  1291. DRM_DEBUG_KMS("VBT signature \"%.*s\", BDB version %d\n",
  1292. (int)sizeof(vbt->signature), vbt->signature, bdb->version);
  1293. /* Grab useful general definitions */
  1294. parse_general_features(dev_priv, bdb);
  1295. parse_general_definitions(dev_priv, bdb);
  1296. parse_lfp_panel_data(dev_priv, bdb);
  1297. parse_lfp_backlight(dev_priv, bdb);
  1298. parse_sdvo_panel_data(dev_priv, bdb);
  1299. parse_sdvo_device_mapping(dev_priv, bdb);
  1300. parse_device_mapping(dev_priv, bdb);
  1301. parse_driver_features(dev_priv, bdb);
  1302. parse_edp(dev_priv, bdb);
  1303. parse_psr(dev_priv, bdb);
  1304. parse_mipi_config(dev_priv, bdb);
  1305. parse_mipi_sequence(dev_priv, bdb);
  1306. parse_ddi_ports(dev_priv, bdb);
  1307. out:
  1308. if (!vbt) {
  1309. DRM_INFO("Failed to find VBIOS tables (VBT)\n");
  1310. init_vbt_missing_defaults(dev_priv);
  1311. }
  1312. if (bios)
  1313. pci_unmap_rom(pdev, bios);
  1314. }
  1315. /**
  1316. * intel_bios_is_tv_present - is integrated TV present in VBT
  1317. * @dev_priv: i915 device instance
  1318. *
  1319. * Return true if TV is present. If no child devices were parsed from VBT,
  1320. * assume TV is present.
  1321. */
  1322. bool intel_bios_is_tv_present(struct drm_i915_private *dev_priv)
  1323. {
  1324. union child_device_config *p_child;
  1325. int i;
  1326. if (!dev_priv->vbt.int_tv_support)
  1327. return false;
  1328. if (!dev_priv->vbt.child_dev_num)
  1329. return true;
  1330. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1331. p_child = dev_priv->vbt.child_dev + i;
  1332. /*
  1333. * If the device type is not TV, continue.
  1334. */
  1335. switch (p_child->old.device_type) {
  1336. case DEVICE_TYPE_INT_TV:
  1337. case DEVICE_TYPE_TV:
  1338. case DEVICE_TYPE_TV_SVIDEO_COMPOSITE:
  1339. break;
  1340. default:
  1341. continue;
  1342. }
  1343. /* Only when the addin_offset is non-zero, it is regarded
  1344. * as present.
  1345. */
  1346. if (p_child->old.addin_offset)
  1347. return true;
  1348. }
  1349. return false;
  1350. }
  1351. /**
  1352. * intel_bios_is_lvds_present - is LVDS present in VBT
  1353. * @dev_priv: i915 device instance
  1354. * @i2c_pin: i2c pin for LVDS if present
  1355. *
  1356. * Return true if LVDS is present. If no child devices were parsed from VBT,
  1357. * assume LVDS is present.
  1358. */
  1359. bool intel_bios_is_lvds_present(struct drm_i915_private *dev_priv, u8 *i2c_pin)
  1360. {
  1361. int i;
  1362. if (!dev_priv->vbt.child_dev_num)
  1363. return true;
  1364. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1365. union child_device_config *uchild = dev_priv->vbt.child_dev + i;
  1366. struct old_child_dev_config *child = &uchild->old;
  1367. /* If the device type is not LFP, continue.
  1368. * We have to check both the new identifiers as well as the
  1369. * old for compatibility with some BIOSes.
  1370. */
  1371. if (child->device_type != DEVICE_TYPE_INT_LFP &&
  1372. child->device_type != DEVICE_TYPE_LFP)
  1373. continue;
  1374. if (intel_gmbus_is_valid_pin(dev_priv, child->i2c_pin))
  1375. *i2c_pin = child->i2c_pin;
  1376. /* However, we cannot trust the BIOS writers to populate
  1377. * the VBT correctly. Since LVDS requires additional
  1378. * information from AIM blocks, a non-zero addin offset is
  1379. * a good indicator that the LVDS is actually present.
  1380. */
  1381. if (child->addin_offset)
  1382. return true;
  1383. /* But even then some BIOS writers perform some black magic
  1384. * and instantiate the device without reference to any
  1385. * additional data. Trust that if the VBT was written into
  1386. * the OpRegion then they have validated the LVDS's existence.
  1387. */
  1388. if (dev_priv->opregion.vbt)
  1389. return true;
  1390. }
  1391. return false;
  1392. }
  1393. /**
  1394. * intel_bios_is_port_present - is the specified digital port present
  1395. * @dev_priv: i915 device instance
  1396. * @port: port to check
  1397. *
  1398. * Return true if the device in %port is present.
  1399. */
  1400. bool intel_bios_is_port_present(struct drm_i915_private *dev_priv, enum port port)
  1401. {
  1402. static const struct {
  1403. u16 dp, hdmi;
  1404. } port_mapping[] = {
  1405. [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
  1406. [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
  1407. [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
  1408. [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
  1409. };
  1410. int i;
  1411. /* FIXME maybe deal with port A as well? */
  1412. if (WARN_ON(port == PORT_A) || port >= ARRAY_SIZE(port_mapping))
  1413. return false;
  1414. if (!dev_priv->vbt.child_dev_num)
  1415. return false;
  1416. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1417. const union child_device_config *p_child =
  1418. &dev_priv->vbt.child_dev[i];
  1419. if ((p_child->common.dvo_port == port_mapping[port].dp ||
  1420. p_child->common.dvo_port == port_mapping[port].hdmi) &&
  1421. (p_child->common.device_type & (DEVICE_TYPE_TMDS_DVI_SIGNALING |
  1422. DEVICE_TYPE_DISPLAYPORT_OUTPUT)))
  1423. return true;
  1424. }
  1425. return false;
  1426. }
  1427. /**
  1428. * intel_bios_is_port_edp - is the device in given port eDP
  1429. * @dev_priv: i915 device instance
  1430. * @port: port to check
  1431. *
  1432. * Return true if the device in %port is eDP.
  1433. */
  1434. bool intel_bios_is_port_edp(struct drm_i915_private *dev_priv, enum port port)
  1435. {
  1436. union child_device_config *p_child;
  1437. static const short port_mapping[] = {
  1438. [PORT_B] = DVO_PORT_DPB,
  1439. [PORT_C] = DVO_PORT_DPC,
  1440. [PORT_D] = DVO_PORT_DPD,
  1441. [PORT_E] = DVO_PORT_DPE,
  1442. };
  1443. int i;
  1444. if (HAS_DDI(dev_priv))
  1445. return dev_priv->vbt.ddi_port_info[port].supports_edp;
  1446. if (!dev_priv->vbt.child_dev_num)
  1447. return false;
  1448. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1449. p_child = dev_priv->vbt.child_dev + i;
  1450. if (p_child->common.dvo_port == port_mapping[port] &&
  1451. (p_child->common.device_type & DEVICE_TYPE_eDP_BITS) ==
  1452. (DEVICE_TYPE_eDP & DEVICE_TYPE_eDP_BITS))
  1453. return true;
  1454. }
  1455. return false;
  1456. }
  1457. static bool child_dev_is_dp_dual_mode(const union child_device_config *p_child,
  1458. enum port port)
  1459. {
  1460. static const struct {
  1461. u16 dp, hdmi;
  1462. } port_mapping[] = {
  1463. /*
  1464. * Buggy VBTs may declare DP ports as having
  1465. * HDMI type dvo_port :( So let's check both.
  1466. */
  1467. [PORT_B] = { DVO_PORT_DPB, DVO_PORT_HDMIB, },
  1468. [PORT_C] = { DVO_PORT_DPC, DVO_PORT_HDMIC, },
  1469. [PORT_D] = { DVO_PORT_DPD, DVO_PORT_HDMID, },
  1470. [PORT_E] = { DVO_PORT_DPE, DVO_PORT_HDMIE, },
  1471. };
  1472. if (port == PORT_A || port >= ARRAY_SIZE(port_mapping))
  1473. return false;
  1474. if ((p_child->common.device_type & DEVICE_TYPE_DP_DUAL_MODE_BITS) !=
  1475. (DEVICE_TYPE_DP_DUAL_MODE & DEVICE_TYPE_DP_DUAL_MODE_BITS))
  1476. return false;
  1477. if (p_child->common.dvo_port == port_mapping[port].dp)
  1478. return true;
  1479. /* Only accept a HDMI dvo_port as DP++ if it has an AUX channel */
  1480. if (p_child->common.dvo_port == port_mapping[port].hdmi &&
  1481. p_child->common.aux_channel != 0)
  1482. return true;
  1483. return false;
  1484. }
  1485. bool intel_bios_is_port_dp_dual_mode(struct drm_i915_private *dev_priv,
  1486. enum port port)
  1487. {
  1488. int i;
  1489. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1490. const union child_device_config *p_child =
  1491. &dev_priv->vbt.child_dev[i];
  1492. if (child_dev_is_dp_dual_mode(p_child, port))
  1493. return true;
  1494. }
  1495. return false;
  1496. }
  1497. /**
  1498. * intel_bios_is_dsi_present - is DSI present in VBT
  1499. * @dev_priv: i915 device instance
  1500. * @port: port for DSI if present
  1501. *
  1502. * Return true if DSI is present, and return the port in %port.
  1503. */
  1504. bool intel_bios_is_dsi_present(struct drm_i915_private *dev_priv,
  1505. enum port *port)
  1506. {
  1507. union child_device_config *p_child;
  1508. u8 dvo_port;
  1509. int i;
  1510. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1511. p_child = dev_priv->vbt.child_dev + i;
  1512. if (!(p_child->common.device_type & DEVICE_TYPE_MIPI_OUTPUT))
  1513. continue;
  1514. dvo_port = p_child->common.dvo_port;
  1515. switch (dvo_port) {
  1516. case DVO_PORT_MIPIA:
  1517. case DVO_PORT_MIPIC:
  1518. if (port)
  1519. *port = dvo_port - DVO_PORT_MIPIA;
  1520. return true;
  1521. case DVO_PORT_MIPIB:
  1522. case DVO_PORT_MIPID:
  1523. DRM_DEBUG_KMS("VBT has unsupported DSI port %c\n",
  1524. port_name(dvo_port - DVO_PORT_MIPIA));
  1525. break;
  1526. }
  1527. }
  1528. return false;
  1529. }
  1530. /**
  1531. * intel_bios_is_port_hpd_inverted - is HPD inverted for %port
  1532. * @dev_priv: i915 device instance
  1533. * @port: port to check
  1534. *
  1535. * Return true if HPD should be inverted for %port.
  1536. */
  1537. bool
  1538. intel_bios_is_port_hpd_inverted(struct drm_i915_private *dev_priv,
  1539. enum port port)
  1540. {
  1541. int i;
  1542. if (WARN_ON_ONCE(!IS_GEN9_LP(dev_priv)))
  1543. return false;
  1544. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1545. if (!dev_priv->vbt.child_dev[i].common.hpd_invert)
  1546. continue;
  1547. switch (dev_priv->vbt.child_dev[i].common.dvo_port) {
  1548. case DVO_PORT_DPA:
  1549. case DVO_PORT_HDMIA:
  1550. if (port == PORT_A)
  1551. return true;
  1552. break;
  1553. case DVO_PORT_DPB:
  1554. case DVO_PORT_HDMIB:
  1555. if (port == PORT_B)
  1556. return true;
  1557. break;
  1558. case DVO_PORT_DPC:
  1559. case DVO_PORT_HDMIC:
  1560. if (port == PORT_C)
  1561. return true;
  1562. break;
  1563. default:
  1564. break;
  1565. }
  1566. }
  1567. return false;
  1568. }
  1569. /**
  1570. * intel_bios_is_lspcon_present - if LSPCON is attached on %port
  1571. * @dev_priv: i915 device instance
  1572. * @port: port to check
  1573. *
  1574. * Return true if LSPCON is present on this port
  1575. */
  1576. bool
  1577. intel_bios_is_lspcon_present(struct drm_i915_private *dev_priv,
  1578. enum port port)
  1579. {
  1580. int i;
  1581. if (!HAS_LSPCON(dev_priv))
  1582. return false;
  1583. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  1584. if (!dev_priv->vbt.child_dev[i].common.lspcon)
  1585. continue;
  1586. switch (dev_priv->vbt.child_dev[i].common.dvo_port) {
  1587. case DVO_PORT_DPA:
  1588. case DVO_PORT_HDMIA:
  1589. if (port == PORT_A)
  1590. return true;
  1591. break;
  1592. case DVO_PORT_DPB:
  1593. case DVO_PORT_HDMIB:
  1594. if (port == PORT_B)
  1595. return true;
  1596. break;
  1597. case DVO_PORT_DPC:
  1598. case DVO_PORT_HDMIC:
  1599. if (port == PORT_C)
  1600. return true;
  1601. break;
  1602. case DVO_PORT_DPD:
  1603. case DVO_PORT_HDMID:
  1604. if (port == PORT_D)
  1605. return true;
  1606. break;
  1607. default:
  1608. break;
  1609. }
  1610. }
  1611. return false;
  1612. }