intel_lvds.c 34 KB

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