intel_bios.c 44 KB

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