intel_lvds.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203
  1. /*
  2. * Copyright © 2006-2007 Intel Corporation
  3. * Copyright (c) 2006 Dave Airlie <airlied@linux.ie>
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a
  6. * copy of this software and associated documentation files (the "Software"),
  7. * to deal in the Software without restriction, including without limitation
  8. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  9. * and/or sell copies of the Software, and to permit persons to whom the
  10. * Software is furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice (including the next
  13. * paragraph) shall be included in all copies or substantial portions of the
  14. * Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  19. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  22. * DEALINGS IN THE SOFTWARE.
  23. *
  24. * Authors:
  25. * Eric Anholt <eric@anholt.net>
  26. * Dave Airlie <airlied@linux.ie>
  27. * Jesse Barnes <jesse.barnes@intel.com>
  28. */
  29. #include <acpi/button.h>
  30. #include <linux/dmi.h>
  31. #include <linux/i2c.h>
  32. #include <linux/slab.h>
  33. #include <linux/vga_switcheroo.h>
  34. #include <drm/drmP.h>
  35. #include <drm/drm_atomic_helper.h>
  36. #include <drm/drm_crtc.h>
  37. #include <drm/drm_edid.h>
  38. #include "intel_drv.h"
  39. #include <drm/i915_drm.h>
  40. #include "i915_drv.h"
  41. #include <linux/acpi.h>
  42. /* Private structure for the integrated LVDS support */
  43. struct intel_lvds_connector {
  44. struct intel_connector base;
  45. struct notifier_block lid_notifier;
  46. };
  47. struct intel_lvds_encoder {
  48. struct intel_encoder base;
  49. bool is_dual_link;
  50. i915_reg_t reg;
  51. u32 a3_power;
  52. struct intel_lvds_connector *attached_connector;
  53. };
  54. static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
  55. {
  56. return container_of(encoder, struct intel_lvds_encoder, base.base);
  57. }
  58. static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
  59. {
  60. return container_of(connector, struct intel_lvds_connector, base.base);
  61. }
  62. static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
  63. enum pipe *pipe)
  64. {
  65. struct drm_device *dev = encoder->base.dev;
  66. struct drm_i915_private *dev_priv = dev->dev_private;
  67. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  68. enum intel_display_power_domain power_domain;
  69. u32 tmp;
  70. bool ret;
  71. power_domain = intel_display_port_power_domain(encoder);
  72. if (!intel_display_power_get_if_enabled(dev_priv, power_domain))
  73. return false;
  74. ret = false;
  75. tmp = I915_READ(lvds_encoder->reg);
  76. if (!(tmp & LVDS_PORT_EN))
  77. goto out;
  78. if (HAS_PCH_CPT(dev))
  79. *pipe = PORT_TO_PIPE_CPT(tmp);
  80. else
  81. *pipe = PORT_TO_PIPE(tmp);
  82. ret = true;
  83. out:
  84. intel_display_power_put(dev_priv, power_domain);
  85. return ret;
  86. }
  87. static void intel_lvds_get_config(struct intel_encoder *encoder,
  88. struct intel_crtc_state *pipe_config)
  89. {
  90. struct drm_device *dev = encoder->base.dev;
  91. struct drm_i915_private *dev_priv = dev->dev_private;
  92. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  93. u32 tmp, flags = 0;
  94. int dotclock;
  95. tmp = I915_READ(lvds_encoder->reg);
  96. if (tmp & LVDS_HSYNC_POLARITY)
  97. flags |= DRM_MODE_FLAG_NHSYNC;
  98. else
  99. flags |= DRM_MODE_FLAG_PHSYNC;
  100. if (tmp & LVDS_VSYNC_POLARITY)
  101. flags |= DRM_MODE_FLAG_NVSYNC;
  102. else
  103. flags |= DRM_MODE_FLAG_PVSYNC;
  104. pipe_config->base.adjusted_mode.flags |= flags;
  105. /* gen2/3 store dither state in pfit control, needs to match */
  106. if (INTEL_INFO(dev)->gen < 4) {
  107. tmp = I915_READ(PFIT_CONTROL);
  108. pipe_config->gmch_pfit.control |= tmp & PANEL_8TO6_DITHER_ENABLE;
  109. }
  110. dotclock = pipe_config->port_clock;
  111. if (HAS_PCH_SPLIT(dev_priv->dev))
  112. ironlake_check_encoder_dotclock(pipe_config, dotclock);
  113. pipe_config->base.adjusted_mode.crtc_clock = dotclock;
  114. }
  115. static void intel_pre_enable_lvds(struct intel_encoder *encoder)
  116. {
  117. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  118. struct drm_device *dev = encoder->base.dev;
  119. struct drm_i915_private *dev_priv = dev->dev_private;
  120. struct intel_crtc *crtc = to_intel_crtc(encoder->base.crtc);
  121. const struct drm_display_mode *adjusted_mode = &crtc->config->base.adjusted_mode;
  122. int pipe = crtc->pipe;
  123. u32 temp;
  124. if (HAS_PCH_SPLIT(dev)) {
  125. assert_fdi_rx_pll_disabled(dev_priv, pipe);
  126. assert_shared_dpll_disabled(dev_priv,
  127. intel_crtc_to_shared_dpll(crtc));
  128. } else {
  129. assert_pll_disabled(dev_priv, pipe);
  130. }
  131. temp = I915_READ(lvds_encoder->reg);
  132. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  133. if (HAS_PCH_CPT(dev)) {
  134. temp &= ~PORT_TRANS_SEL_MASK;
  135. temp |= PORT_TRANS_SEL_CPT(pipe);
  136. } else {
  137. if (pipe == 1) {
  138. temp |= LVDS_PIPEB_SELECT;
  139. } else {
  140. temp &= ~LVDS_PIPEB_SELECT;
  141. }
  142. }
  143. /* set the corresponsding LVDS_BORDER bit */
  144. temp &= ~LVDS_BORDER_ENABLE;
  145. temp |= crtc->config->gmch_pfit.lvds_border_bits;
  146. /* Set the B0-B3 data pairs corresponding to whether we're going to
  147. * set the DPLLs for dual-channel mode or not.
  148. */
  149. if (lvds_encoder->is_dual_link)
  150. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  151. else
  152. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  153. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  154. * appropriately here, but we need to look more thoroughly into how
  155. * panels behave in the two modes. For now, let's just maintain the
  156. * value we got from the BIOS.
  157. */
  158. temp &= ~LVDS_A3_POWER_MASK;
  159. temp |= lvds_encoder->a3_power;
  160. /* Set the dithering flag on LVDS as needed, note that there is no
  161. * special lvds dither control bit on pch-split platforms, dithering is
  162. * only controlled through the PIPECONF reg. */
  163. if (INTEL_INFO(dev)->gen == 4) {
  164. /* Bspec wording suggests that LVDS port dithering only exists
  165. * for 18bpp panels. */
  166. if (crtc->config->dither && crtc->config->pipe_bpp == 18)
  167. temp |= LVDS_ENABLE_DITHER;
  168. else
  169. temp &= ~LVDS_ENABLE_DITHER;
  170. }
  171. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  172. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  173. temp |= LVDS_HSYNC_POLARITY;
  174. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  175. temp |= LVDS_VSYNC_POLARITY;
  176. I915_WRITE(lvds_encoder->reg, temp);
  177. }
  178. /**
  179. * Sets the power state for the panel.
  180. */
  181. static void intel_enable_lvds(struct intel_encoder *encoder)
  182. {
  183. struct drm_device *dev = encoder->base.dev;
  184. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  185. struct intel_connector *intel_connector =
  186. &lvds_encoder->attached_connector->base;
  187. struct drm_i915_private *dev_priv = dev->dev_private;
  188. i915_reg_t ctl_reg, stat_reg;
  189. if (HAS_PCH_SPLIT(dev)) {
  190. ctl_reg = PCH_PP_CONTROL;
  191. stat_reg = PCH_PP_STATUS;
  192. } else {
  193. ctl_reg = PP_CONTROL;
  194. stat_reg = PP_STATUS;
  195. }
  196. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
  197. I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
  198. POSTING_READ(lvds_encoder->reg);
  199. if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
  200. DRM_ERROR("timed out waiting for panel to power on\n");
  201. intel_panel_enable_backlight(intel_connector);
  202. }
  203. static void intel_disable_lvds(struct intel_encoder *encoder)
  204. {
  205. struct drm_device *dev = encoder->base.dev;
  206. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  207. struct drm_i915_private *dev_priv = dev->dev_private;
  208. i915_reg_t ctl_reg, stat_reg;
  209. if (HAS_PCH_SPLIT(dev)) {
  210. ctl_reg = PCH_PP_CONTROL;
  211. stat_reg = PCH_PP_STATUS;
  212. } else {
  213. ctl_reg = PP_CONTROL;
  214. stat_reg = PP_STATUS;
  215. }
  216. I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
  217. if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
  218. DRM_ERROR("timed out waiting for panel to power off\n");
  219. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
  220. POSTING_READ(lvds_encoder->reg);
  221. }
  222. static void gmch_disable_lvds(struct intel_encoder *encoder)
  223. {
  224. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  225. struct intel_connector *intel_connector =
  226. &lvds_encoder->attached_connector->base;
  227. intel_panel_disable_backlight(intel_connector);
  228. intel_disable_lvds(encoder);
  229. }
  230. static void pch_disable_lvds(struct intel_encoder *encoder)
  231. {
  232. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  233. struct intel_connector *intel_connector =
  234. &lvds_encoder->attached_connector->base;
  235. intel_panel_disable_backlight(intel_connector);
  236. }
  237. static void pch_post_disable_lvds(struct intel_encoder *encoder)
  238. {
  239. intel_disable_lvds(encoder);
  240. }
  241. static enum drm_mode_status
  242. intel_lvds_mode_valid(struct drm_connector *connector,
  243. struct drm_display_mode *mode)
  244. {
  245. struct intel_connector *intel_connector = to_intel_connector(connector);
  246. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  247. int max_pixclk = to_i915(connector->dev)->max_dotclk_freq;
  248. if (mode->hdisplay > fixed_mode->hdisplay)
  249. return MODE_PANEL;
  250. if (mode->vdisplay > fixed_mode->vdisplay)
  251. return MODE_PANEL;
  252. if (fixed_mode->clock > max_pixclk)
  253. return MODE_CLOCK_HIGH;
  254. return MODE_OK;
  255. }
  256. static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
  257. struct intel_crtc_state *pipe_config)
  258. {
  259. struct drm_device *dev = intel_encoder->base.dev;
  260. struct intel_lvds_encoder *lvds_encoder =
  261. to_lvds_encoder(&intel_encoder->base);
  262. struct intel_connector *intel_connector =
  263. &lvds_encoder->attached_connector->base;
  264. struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode;
  265. struct intel_crtc *intel_crtc = to_intel_crtc(pipe_config->base.crtc);
  266. unsigned int lvds_bpp;
  267. /* Should never happen!! */
  268. if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
  269. DRM_ERROR("Can't support LVDS on pipe A\n");
  270. return false;
  271. }
  272. if (lvds_encoder->a3_power == LVDS_A3_POWER_UP)
  273. lvds_bpp = 8*3;
  274. else
  275. lvds_bpp = 6*3;
  276. if (lvds_bpp != pipe_config->pipe_bpp && !pipe_config->bw_constrained) {
  277. DRM_DEBUG_KMS("forcing display bpp (was %d) to LVDS (%d)\n",
  278. pipe_config->pipe_bpp, lvds_bpp);
  279. pipe_config->pipe_bpp = lvds_bpp;
  280. }
  281. /*
  282. * We have timings from the BIOS for the panel, put them in
  283. * to the adjusted mode. The CRTC will be set up for this mode,
  284. * with the panel scaling set up to source from the H/VDisplay
  285. * of the original mode.
  286. */
  287. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  288. adjusted_mode);
  289. if (HAS_PCH_SPLIT(dev)) {
  290. pipe_config->has_pch_encoder = true;
  291. intel_pch_panel_fitting(intel_crtc, pipe_config,
  292. intel_connector->panel.fitting_mode);
  293. } else {
  294. intel_gmch_panel_fitting(intel_crtc, pipe_config,
  295. intel_connector->panel.fitting_mode);
  296. }
  297. /*
  298. * XXX: It would be nice to support lower refresh rates on the
  299. * panels to reduce power consumption, and perhaps match the
  300. * user's requested refresh rate.
  301. */
  302. return true;
  303. }
  304. /**
  305. * Detect the LVDS connection.
  306. *
  307. * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
  308. * connected and closed means disconnected. We also send hotplug events as
  309. * needed, using lid status notification from the input layer.
  310. */
  311. static enum drm_connector_status
  312. intel_lvds_detect(struct drm_connector *connector, bool force)
  313. {
  314. struct drm_device *dev = connector->dev;
  315. enum drm_connector_status status;
  316. DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n",
  317. connector->base.id, connector->name);
  318. status = intel_panel_detect(dev);
  319. if (status != connector_status_unknown)
  320. return status;
  321. return connector_status_connected;
  322. }
  323. /**
  324. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  325. */
  326. static int intel_lvds_get_modes(struct drm_connector *connector)
  327. {
  328. struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
  329. struct drm_device *dev = connector->dev;
  330. struct drm_display_mode *mode;
  331. /* use cached edid if we have one */
  332. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  333. return drm_add_edid_modes(connector, lvds_connector->base.edid);
  334. mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
  335. if (mode == NULL)
  336. return 0;
  337. drm_mode_probed_add(connector, mode);
  338. return 1;
  339. }
  340. static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
  341. {
  342. DRM_INFO("Skipping forced modeset for %s\n", id->ident);
  343. return 1;
  344. }
  345. /* The GPU hangs up on these systems if modeset is performed on LID open */
  346. static const struct dmi_system_id intel_no_modeset_on_lid[] = {
  347. {
  348. .callback = intel_no_modeset_on_lid_dmi_callback,
  349. .ident = "Toshiba Tecra A11",
  350. .matches = {
  351. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  352. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
  353. },
  354. },
  355. { } /* terminating entry */
  356. };
  357. /*
  358. * Lid events. Note the use of 'modeset':
  359. * - we set it to MODESET_ON_LID_OPEN on lid close,
  360. * and set it to MODESET_DONE on open
  361. * - we use it as a "only once" bit (ie we ignore
  362. * duplicate events where it was already properly set)
  363. * - the suspend/resume paths will set it to
  364. * MODESET_SUSPENDED and ignore the lid open event,
  365. * because they restore the mode ("lid open").
  366. */
  367. static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
  368. void *unused)
  369. {
  370. struct intel_lvds_connector *lvds_connector =
  371. container_of(nb, struct intel_lvds_connector, lid_notifier);
  372. struct drm_connector *connector = &lvds_connector->base.base;
  373. struct drm_device *dev = connector->dev;
  374. struct drm_i915_private *dev_priv = dev->dev_private;
  375. if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
  376. return NOTIFY_OK;
  377. mutex_lock(&dev_priv->modeset_restore_lock);
  378. if (dev_priv->modeset_restore == MODESET_SUSPENDED)
  379. goto exit;
  380. /*
  381. * check and update the status of LVDS connector after receiving
  382. * the LID nofication event.
  383. */
  384. connector->status = connector->funcs->detect(connector, false);
  385. /* Don't force modeset on machines where it causes a GPU lockup */
  386. if (dmi_check_system(intel_no_modeset_on_lid))
  387. goto exit;
  388. if (!acpi_lid_open()) {
  389. /* do modeset on next lid open event */
  390. dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
  391. goto exit;
  392. }
  393. if (dev_priv->modeset_restore == MODESET_DONE)
  394. goto exit;
  395. /*
  396. * Some old platform's BIOS love to wreak havoc while the lid is closed.
  397. * We try to detect this here and undo any damage. The split for PCH
  398. * platforms is rather conservative and a bit arbitrary expect that on
  399. * those platforms VGA disabling requires actual legacy VGA I/O access,
  400. * and as part of the cleanup in the hw state restore we also redisable
  401. * the vga plane.
  402. */
  403. if (!HAS_PCH_SPLIT(dev)) {
  404. drm_modeset_lock_all(dev);
  405. intel_display_resume(dev);
  406. drm_modeset_unlock_all(dev);
  407. }
  408. dev_priv->modeset_restore = MODESET_DONE;
  409. exit:
  410. mutex_unlock(&dev_priv->modeset_restore_lock);
  411. return NOTIFY_OK;
  412. }
  413. /**
  414. * intel_lvds_destroy - unregister and free LVDS structures
  415. * @connector: connector to free
  416. *
  417. * Unregister the DDC bus for this connector then free the driver private
  418. * structure.
  419. */
  420. static void intel_lvds_destroy(struct drm_connector *connector)
  421. {
  422. struct intel_lvds_connector *lvds_connector =
  423. to_lvds_connector(connector);
  424. if (lvds_connector->lid_notifier.notifier_call)
  425. acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
  426. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  427. kfree(lvds_connector->base.edid);
  428. intel_panel_fini(&lvds_connector->base.panel);
  429. drm_connector_cleanup(connector);
  430. kfree(connector);
  431. }
  432. static int intel_lvds_set_property(struct drm_connector *connector,
  433. struct drm_property *property,
  434. uint64_t value)
  435. {
  436. struct intel_connector *intel_connector = to_intel_connector(connector);
  437. struct drm_device *dev = connector->dev;
  438. if (property == dev->mode_config.scaling_mode_property) {
  439. struct drm_crtc *crtc;
  440. if (value == DRM_MODE_SCALE_NONE) {
  441. DRM_DEBUG_KMS("no scaling not supported\n");
  442. return -EINVAL;
  443. }
  444. if (intel_connector->panel.fitting_mode == value) {
  445. /* the LVDS scaling property is not changed */
  446. return 0;
  447. }
  448. intel_connector->panel.fitting_mode = value;
  449. crtc = intel_attached_encoder(connector)->base.crtc;
  450. if (crtc && crtc->state->enable) {
  451. /*
  452. * If the CRTC is enabled, the display will be changed
  453. * according to the new panel fitting mode.
  454. */
  455. intel_crtc_restore_mode(crtc);
  456. }
  457. }
  458. return 0;
  459. }
  460. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  461. .get_modes = intel_lvds_get_modes,
  462. .mode_valid = intel_lvds_mode_valid,
  463. .best_encoder = intel_best_encoder,
  464. };
  465. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  466. .dpms = drm_atomic_helper_connector_dpms,
  467. .detect = intel_lvds_detect,
  468. .fill_modes = drm_helper_probe_single_connector_modes,
  469. .set_property = intel_lvds_set_property,
  470. .atomic_get_property = intel_connector_atomic_get_property,
  471. .destroy = intel_lvds_destroy,
  472. .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
  473. .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state,
  474. };
  475. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  476. .destroy = intel_encoder_destroy,
  477. };
  478. static int intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  479. {
  480. DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
  481. return 1;
  482. }
  483. /* These systems claim to have LVDS, but really don't */
  484. static const struct dmi_system_id intel_no_lvds[] = {
  485. {
  486. .callback = intel_no_lvds_dmi_callback,
  487. .ident = "Apple Mac Mini (Core series)",
  488. .matches = {
  489. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  490. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  491. },
  492. },
  493. {
  494. .callback = intel_no_lvds_dmi_callback,
  495. .ident = "Apple Mac Mini (Core 2 series)",
  496. .matches = {
  497. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  498. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  499. },
  500. },
  501. {
  502. .callback = intel_no_lvds_dmi_callback,
  503. .ident = "MSI IM-945GSE-A",
  504. .matches = {
  505. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  506. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  507. },
  508. },
  509. {
  510. .callback = intel_no_lvds_dmi_callback,
  511. .ident = "Dell Studio Hybrid",
  512. .matches = {
  513. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  514. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  515. },
  516. },
  517. {
  518. .callback = intel_no_lvds_dmi_callback,
  519. .ident = "Dell OptiPlex FX170",
  520. .matches = {
  521. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  522. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
  523. },
  524. },
  525. {
  526. .callback = intel_no_lvds_dmi_callback,
  527. .ident = "AOpen Mini PC",
  528. .matches = {
  529. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  530. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  531. },
  532. },
  533. {
  534. .callback = intel_no_lvds_dmi_callback,
  535. .ident = "AOpen Mini PC MP915",
  536. .matches = {
  537. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  538. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  539. },
  540. },
  541. {
  542. .callback = intel_no_lvds_dmi_callback,
  543. .ident = "AOpen i915GMm-HFS",
  544. .matches = {
  545. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  546. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  547. },
  548. },
  549. {
  550. .callback = intel_no_lvds_dmi_callback,
  551. .ident = "AOpen i45GMx-I",
  552. .matches = {
  553. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  554. DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
  555. },
  556. },
  557. {
  558. .callback = intel_no_lvds_dmi_callback,
  559. .ident = "Aopen i945GTt-VFA",
  560. .matches = {
  561. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  562. },
  563. },
  564. {
  565. .callback = intel_no_lvds_dmi_callback,
  566. .ident = "Clientron U800",
  567. .matches = {
  568. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  569. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  570. },
  571. },
  572. {
  573. .callback = intel_no_lvds_dmi_callback,
  574. .ident = "Clientron E830",
  575. .matches = {
  576. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  577. DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
  578. },
  579. },
  580. {
  581. .callback = intel_no_lvds_dmi_callback,
  582. .ident = "Asus EeeBox PC EB1007",
  583. .matches = {
  584. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  585. DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
  586. },
  587. },
  588. {
  589. .callback = intel_no_lvds_dmi_callback,
  590. .ident = "Asus AT5NM10T-I",
  591. .matches = {
  592. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  593. DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
  594. },
  595. },
  596. {
  597. .callback = intel_no_lvds_dmi_callback,
  598. .ident = "Hewlett-Packard HP t5740",
  599. .matches = {
  600. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  601. DMI_MATCH(DMI_PRODUCT_NAME, " t5740"),
  602. },
  603. },
  604. {
  605. .callback = intel_no_lvds_dmi_callback,
  606. .ident = "Hewlett-Packard t5745",
  607. .matches = {
  608. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  609. DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
  610. },
  611. },
  612. {
  613. .callback = intel_no_lvds_dmi_callback,
  614. .ident = "Hewlett-Packard st5747",
  615. .matches = {
  616. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  617. DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
  618. },
  619. },
  620. {
  621. .callback = intel_no_lvds_dmi_callback,
  622. .ident = "MSI Wind Box DC500",
  623. .matches = {
  624. DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
  625. DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
  626. },
  627. },
  628. {
  629. .callback = intel_no_lvds_dmi_callback,
  630. .ident = "Gigabyte GA-D525TUD",
  631. .matches = {
  632. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  633. DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
  634. },
  635. },
  636. {
  637. .callback = intel_no_lvds_dmi_callback,
  638. .ident = "Supermicro X7SPA-H",
  639. .matches = {
  640. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  641. DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
  642. },
  643. },
  644. {
  645. .callback = intel_no_lvds_dmi_callback,
  646. .ident = "Fujitsu Esprimo Q900",
  647. .matches = {
  648. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU"),
  649. DMI_MATCH(DMI_PRODUCT_NAME, "ESPRIMO Q900"),
  650. },
  651. },
  652. {
  653. .callback = intel_no_lvds_dmi_callback,
  654. .ident = "Intel D410PT",
  655. .matches = {
  656. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  657. DMI_MATCH(DMI_BOARD_NAME, "D410PT"),
  658. },
  659. },
  660. {
  661. .callback = intel_no_lvds_dmi_callback,
  662. .ident = "Intel D425KT",
  663. .matches = {
  664. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  665. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D425KT"),
  666. },
  667. },
  668. {
  669. .callback = intel_no_lvds_dmi_callback,
  670. .ident = "Intel D510MO",
  671. .matches = {
  672. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  673. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D510MO"),
  674. },
  675. },
  676. {
  677. .callback = intel_no_lvds_dmi_callback,
  678. .ident = "Intel D525MW",
  679. .matches = {
  680. DMI_MATCH(DMI_BOARD_VENDOR, "Intel"),
  681. DMI_EXACT_MATCH(DMI_BOARD_NAME, "D525MW"),
  682. },
  683. },
  684. { } /* terminating entry */
  685. };
  686. /*
  687. * Enumerate the child dev array parsed from VBT to check whether
  688. * the LVDS is present.
  689. * If it is present, return 1.
  690. * If it is not present, return false.
  691. * If no child dev is parsed from VBT, it assumes that the LVDS is present.
  692. */
  693. static bool lvds_is_present_in_vbt(struct drm_device *dev,
  694. u8 *i2c_pin)
  695. {
  696. struct drm_i915_private *dev_priv = dev->dev_private;
  697. int i;
  698. if (!dev_priv->vbt.child_dev_num)
  699. return true;
  700. for (i = 0; i < dev_priv->vbt.child_dev_num; i++) {
  701. union child_device_config *uchild = dev_priv->vbt.child_dev + i;
  702. struct old_child_dev_config *child = &uchild->old;
  703. /* If the device type is not LFP, continue.
  704. * We have to check both the new identifiers as well as the
  705. * old for compatibility with some BIOSes.
  706. */
  707. if (child->device_type != DEVICE_TYPE_INT_LFP &&
  708. child->device_type != DEVICE_TYPE_LFP)
  709. continue;
  710. if (intel_gmbus_is_valid_pin(dev_priv, child->i2c_pin))
  711. *i2c_pin = child->i2c_pin;
  712. /* However, we cannot trust the BIOS writers to populate
  713. * the VBT correctly. Since LVDS requires additional
  714. * information from AIM blocks, a non-zero addin offset is
  715. * a good indicator that the LVDS is actually present.
  716. */
  717. if (child->addin_offset)
  718. return true;
  719. /* But even then some BIOS writers perform some black magic
  720. * and instantiate the device without reference to any
  721. * additional data. Trust that if the VBT was written into
  722. * the OpRegion then they have validated the LVDS's existence.
  723. */
  724. if (dev_priv->opregion.vbt)
  725. return true;
  726. }
  727. return false;
  728. }
  729. static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
  730. {
  731. DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
  732. return 1;
  733. }
  734. static const struct dmi_system_id intel_dual_link_lvds[] = {
  735. {
  736. .callback = intel_dual_link_lvds_callback,
  737. .ident = "Apple MacBook Pro 15\" (2010)",
  738. .matches = {
  739. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  740. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro6,2"),
  741. },
  742. },
  743. {
  744. .callback = intel_dual_link_lvds_callback,
  745. .ident = "Apple MacBook Pro 15\" (2011)",
  746. .matches = {
  747. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  748. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
  749. },
  750. },
  751. {
  752. .callback = intel_dual_link_lvds_callback,
  753. .ident = "Apple MacBook Pro 15\" (2012)",
  754. .matches = {
  755. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  756. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro9,1"),
  757. },
  758. },
  759. { } /* terminating entry */
  760. };
  761. bool intel_is_dual_link_lvds(struct drm_device *dev)
  762. {
  763. struct intel_encoder *encoder;
  764. struct intel_lvds_encoder *lvds_encoder;
  765. for_each_intel_encoder(dev, encoder) {
  766. if (encoder->type == INTEL_OUTPUT_LVDS) {
  767. lvds_encoder = to_lvds_encoder(&encoder->base);
  768. return lvds_encoder->is_dual_link;
  769. }
  770. }
  771. return false;
  772. }
  773. static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
  774. {
  775. struct drm_device *dev = lvds_encoder->base.base.dev;
  776. unsigned int val;
  777. struct drm_i915_private *dev_priv = dev->dev_private;
  778. /* use the module option value if specified */
  779. if (i915.lvds_channel_mode > 0)
  780. return i915.lvds_channel_mode == 2;
  781. /* single channel LVDS is limited to 112 MHz */
  782. if (lvds_encoder->attached_connector->base.panel.fixed_mode->clock
  783. > 112999)
  784. return true;
  785. if (dmi_check_system(intel_dual_link_lvds))
  786. return true;
  787. /* BIOS should set the proper LVDS register value at boot, but
  788. * in reality, it doesn't set the value when the lid is closed;
  789. * we need to check "the value to be set" in VBT when LVDS
  790. * register is uninitialized.
  791. */
  792. val = I915_READ(lvds_encoder->reg);
  793. if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
  794. val = dev_priv->vbt.bios_lvds_val;
  795. return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
  796. }
  797. static bool intel_lvds_supported(struct drm_device *dev)
  798. {
  799. /* With the introduction of the PCH we gained a dedicated
  800. * LVDS presence pin, use it. */
  801. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  802. return true;
  803. /* Otherwise LVDS was only attached to mobile products,
  804. * except for the inglorious 830gm */
  805. if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
  806. return true;
  807. return false;
  808. }
  809. /**
  810. * intel_lvds_init - setup LVDS connectors on this device
  811. * @dev: drm device
  812. *
  813. * Create the connector, register the LVDS DDC bus, and try to figure out what
  814. * modes we can display on the LVDS panel (if present).
  815. */
  816. void intel_lvds_init(struct drm_device *dev)
  817. {
  818. struct drm_i915_private *dev_priv = dev->dev_private;
  819. struct intel_lvds_encoder *lvds_encoder;
  820. struct intel_encoder *intel_encoder;
  821. struct intel_lvds_connector *lvds_connector;
  822. struct intel_connector *intel_connector;
  823. struct drm_connector *connector;
  824. struct drm_encoder *encoder;
  825. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  826. struct drm_display_mode *fixed_mode = NULL;
  827. struct drm_display_mode *downclock_mode = NULL;
  828. struct edid *edid;
  829. struct drm_crtc *crtc;
  830. i915_reg_t lvds_reg;
  831. u32 lvds;
  832. int pipe;
  833. u8 pin;
  834. /*
  835. * Unlock registers and just leave them unlocked. Do this before
  836. * checking quirk lists to avoid bogus WARNINGs.
  837. */
  838. if (HAS_PCH_SPLIT(dev)) {
  839. I915_WRITE(PCH_PP_CONTROL,
  840. I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
  841. } else if (INTEL_INFO(dev_priv)->gen < 5) {
  842. I915_WRITE(PP_CONTROL,
  843. I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
  844. }
  845. if (!intel_lvds_supported(dev))
  846. return;
  847. /* Skip init on machines we know falsely report LVDS */
  848. if (dmi_check_system(intel_no_lvds))
  849. return;
  850. if (HAS_PCH_SPLIT(dev))
  851. lvds_reg = PCH_LVDS;
  852. else
  853. lvds_reg = LVDS;
  854. lvds = I915_READ(lvds_reg);
  855. if (HAS_PCH_SPLIT(dev)) {
  856. if ((lvds & LVDS_DETECTED) == 0)
  857. return;
  858. if (dev_priv->vbt.edp_support) {
  859. DRM_DEBUG_KMS("disable LVDS for eDP support\n");
  860. return;
  861. }
  862. }
  863. pin = GMBUS_PIN_PANEL;
  864. if (!lvds_is_present_in_vbt(dev, &pin)) {
  865. if ((lvds & LVDS_PORT_EN) == 0) {
  866. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  867. return;
  868. }
  869. DRM_DEBUG_KMS("LVDS is not present in VBT, but enabled anyway\n");
  870. }
  871. /* Set the Panel Power On/Off timings if uninitialized. */
  872. if (INTEL_INFO(dev_priv)->gen < 5 &&
  873. I915_READ(PP_ON_DELAYS) == 0 && I915_READ(PP_OFF_DELAYS) == 0) {
  874. /* Set T2 to 40ms and T5 to 200ms */
  875. I915_WRITE(PP_ON_DELAYS, 0x019007d0);
  876. /* Set T3 to 35ms and Tx to 200ms */
  877. I915_WRITE(PP_OFF_DELAYS, 0x015e07d0);
  878. DRM_DEBUG_KMS("Panel power timings uninitialized, setting defaults\n");
  879. }
  880. lvds_encoder = kzalloc(sizeof(*lvds_encoder), GFP_KERNEL);
  881. if (!lvds_encoder)
  882. return;
  883. lvds_connector = kzalloc(sizeof(*lvds_connector), GFP_KERNEL);
  884. if (!lvds_connector) {
  885. kfree(lvds_encoder);
  886. return;
  887. }
  888. if (intel_connector_init(&lvds_connector->base) < 0) {
  889. kfree(lvds_connector);
  890. kfree(lvds_encoder);
  891. return;
  892. }
  893. lvds_encoder->attached_connector = lvds_connector;
  894. intel_encoder = &lvds_encoder->base;
  895. encoder = &intel_encoder->base;
  896. intel_connector = &lvds_connector->base;
  897. connector = &intel_connector->base;
  898. drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
  899. DRM_MODE_CONNECTOR_LVDS);
  900. drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
  901. DRM_MODE_ENCODER_LVDS, NULL);
  902. intel_encoder->enable = intel_enable_lvds;
  903. intel_encoder->pre_enable = intel_pre_enable_lvds;
  904. intel_encoder->compute_config = intel_lvds_compute_config;
  905. if (HAS_PCH_SPLIT(dev_priv)) {
  906. intel_encoder->disable = pch_disable_lvds;
  907. intel_encoder->post_disable = pch_post_disable_lvds;
  908. } else {
  909. intel_encoder->disable = gmch_disable_lvds;
  910. }
  911. intel_encoder->get_hw_state = intel_lvds_get_hw_state;
  912. intel_encoder->get_config = intel_lvds_get_config;
  913. intel_connector->get_hw_state = intel_connector_get_hw_state;
  914. intel_connector->unregister = intel_connector_unregister;
  915. intel_connector_attach_encoder(intel_connector, intel_encoder);
  916. intel_encoder->type = INTEL_OUTPUT_LVDS;
  917. intel_encoder->cloneable = 0;
  918. if (HAS_PCH_SPLIT(dev))
  919. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  920. else if (IS_GEN4(dev))
  921. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  922. else
  923. intel_encoder->crtc_mask = (1 << 1);
  924. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  925. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  926. connector->interlace_allowed = false;
  927. connector->doublescan_allowed = false;
  928. lvds_encoder->reg = lvds_reg;
  929. /* create the scaling mode property */
  930. drm_mode_create_scaling_mode_property(dev);
  931. drm_object_attach_property(&connector->base,
  932. dev->mode_config.scaling_mode_property,
  933. DRM_MODE_SCALE_ASPECT);
  934. intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
  935. /*
  936. * LVDS discovery:
  937. * 1) check for EDID on DDC
  938. * 2) check for VBT data
  939. * 3) check to see if LVDS is already on
  940. * if none of the above, no panel
  941. * 4) make sure lid is open
  942. * if closed, act like it's not there for now
  943. */
  944. /*
  945. * Attempt to get the fixed panel mode from DDC. Assume that the
  946. * preferred mode is the right one.
  947. */
  948. mutex_lock(&dev->mode_config.mutex);
  949. if (vga_switcheroo_handler_flags() & VGA_SWITCHEROO_CAN_SWITCH_DDC)
  950. edid = drm_get_edid_switcheroo(connector,
  951. intel_gmbus_get_adapter(dev_priv, pin));
  952. else
  953. edid = drm_get_edid(connector,
  954. intel_gmbus_get_adapter(dev_priv, pin));
  955. if (edid) {
  956. if (drm_add_edid_modes(connector, edid)) {
  957. drm_mode_connector_update_edid_property(connector,
  958. edid);
  959. } else {
  960. kfree(edid);
  961. edid = ERR_PTR(-EINVAL);
  962. }
  963. } else {
  964. edid = ERR_PTR(-ENOENT);
  965. }
  966. lvds_connector->base.edid = edid;
  967. if (IS_ERR_OR_NULL(edid)) {
  968. /* Didn't get an EDID, so
  969. * Set wide sync ranges so we get all modes
  970. * handed to valid_mode for checking
  971. */
  972. connector->display_info.min_vfreq = 0;
  973. connector->display_info.max_vfreq = 200;
  974. connector->display_info.min_hfreq = 0;
  975. connector->display_info.max_hfreq = 200;
  976. }
  977. list_for_each_entry(scan, &connector->probed_modes, head) {
  978. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  979. DRM_DEBUG_KMS("using preferred mode from EDID: ");
  980. drm_mode_debug_printmodeline(scan);
  981. fixed_mode = drm_mode_duplicate(dev, scan);
  982. if (fixed_mode)
  983. goto out;
  984. }
  985. }
  986. /* Failed to get EDID, what about VBT? */
  987. if (dev_priv->vbt.lfp_lvds_vbt_mode) {
  988. DRM_DEBUG_KMS("using mode from VBT: ");
  989. drm_mode_debug_printmodeline(dev_priv->vbt.lfp_lvds_vbt_mode);
  990. fixed_mode = drm_mode_duplicate(dev, dev_priv->vbt.lfp_lvds_vbt_mode);
  991. if (fixed_mode) {
  992. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  993. goto out;
  994. }
  995. }
  996. /*
  997. * If we didn't get EDID, try checking if the panel is already turned
  998. * on. If so, assume that whatever is currently programmed is the
  999. * correct mode.
  1000. */
  1001. /* Ironlake: FIXME if still fail, not try pipe mode now */
  1002. if (HAS_PCH_SPLIT(dev))
  1003. goto failed;
  1004. pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
  1005. crtc = intel_get_crtc_for_pipe(dev, pipe);
  1006. if (crtc && (lvds & LVDS_PORT_EN)) {
  1007. fixed_mode = intel_crtc_mode_get(dev, crtc);
  1008. if (fixed_mode) {
  1009. DRM_DEBUG_KMS("using current (BIOS) mode: ");
  1010. drm_mode_debug_printmodeline(fixed_mode);
  1011. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  1012. goto out;
  1013. }
  1014. }
  1015. /* If we still don't have a mode after all that, give up. */
  1016. if (!fixed_mode)
  1017. goto failed;
  1018. out:
  1019. mutex_unlock(&dev->mode_config.mutex);
  1020. intel_panel_init(&intel_connector->panel, fixed_mode, downclock_mode);
  1021. lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
  1022. DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
  1023. lvds_encoder->is_dual_link ? "dual" : "single");
  1024. lvds_encoder->a3_power = lvds & LVDS_A3_POWER_MASK;
  1025. lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
  1026. if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
  1027. DRM_DEBUG_KMS("lid notifier registration failed\n");
  1028. lvds_connector->lid_notifier.notifier_call = NULL;
  1029. }
  1030. drm_connector_register(connector);
  1031. intel_panel_setup_backlight(connector, INVALID_PIPE);
  1032. return;
  1033. failed:
  1034. mutex_unlock(&dev->mode_config.mutex);
  1035. DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
  1036. drm_connector_cleanup(connector);
  1037. drm_encoder_cleanup(encoder);
  1038. kfree(lvds_encoder);
  1039. kfree(lvds_connector);
  1040. return;
  1041. }