intel_bios.c 58 KB

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