intel_bios.c 50 KB

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