intel_lvds.c 35 KB

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