intel_bios.c 56 KB

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