intel_lvds.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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 <drm/drmP.h>
  34. #include <drm/drm_crtc.h>
  35. #include <drm/drm_edid.h>
  36. #include "intel_drv.h"
  37. #include <drm/i915_drm.h>
  38. #include "i915_drv.h"
  39. #include <linux/acpi.h>
  40. /* Private structure for the integrated LVDS support */
  41. struct intel_lvds_connector {
  42. struct intel_connector base;
  43. struct notifier_block lid_notifier;
  44. };
  45. struct intel_lvds_encoder {
  46. struct intel_encoder base;
  47. u32 pfit_control;
  48. u32 pfit_pgm_ratios;
  49. bool is_dual_link;
  50. u32 reg;
  51. struct intel_lvds_connector *attached_connector;
  52. };
  53. static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
  54. {
  55. return container_of(encoder, struct intel_lvds_encoder, base.base);
  56. }
  57. static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
  58. {
  59. return container_of(connector, struct intel_lvds_connector, base.base);
  60. }
  61. static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
  62. enum pipe *pipe)
  63. {
  64. struct drm_device *dev = encoder->base.dev;
  65. struct drm_i915_private *dev_priv = dev->dev_private;
  66. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  67. u32 tmp;
  68. tmp = I915_READ(lvds_encoder->reg);
  69. if (!(tmp & LVDS_PORT_EN))
  70. return false;
  71. if (HAS_PCH_CPT(dev))
  72. *pipe = PORT_TO_PIPE_CPT(tmp);
  73. else
  74. *pipe = PORT_TO_PIPE(tmp);
  75. return true;
  76. }
  77. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  78. * This is an exception to the general rule that mode_set doesn't turn
  79. * things on.
  80. */
  81. static void intel_pre_pll_enable_lvds(struct intel_encoder *encoder)
  82. {
  83. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  84. struct drm_device *dev = encoder->base.dev;
  85. struct drm_i915_private *dev_priv = dev->dev_private;
  86. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  87. struct drm_display_mode *fixed_mode =
  88. lvds_encoder->attached_connector->base.panel.fixed_mode;
  89. int pipe = intel_crtc->pipe;
  90. u32 temp;
  91. temp = I915_READ(lvds_encoder->reg);
  92. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  93. if (HAS_PCH_CPT(dev)) {
  94. temp &= ~PORT_TRANS_SEL_MASK;
  95. temp |= PORT_TRANS_SEL_CPT(pipe);
  96. } else {
  97. if (pipe == 1) {
  98. temp |= LVDS_PIPEB_SELECT;
  99. } else {
  100. temp &= ~LVDS_PIPEB_SELECT;
  101. }
  102. }
  103. /* set the corresponsding LVDS_BORDER bit */
  104. temp |= dev_priv->lvds_border_bits;
  105. /* Set the B0-B3 data pairs corresponding to whether we're going to
  106. * set the DPLLs for dual-channel mode or not.
  107. */
  108. if (lvds_encoder->is_dual_link)
  109. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  110. else
  111. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  112. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  113. * appropriately here, but we need to look more thoroughly into how
  114. * panels behave in the two modes.
  115. */
  116. /* Set the dithering flag on LVDS as needed, note that there is no
  117. * special lvds dither control bit on pch-split platforms, dithering is
  118. * only controlled through the PIPECONF reg. */
  119. if (INTEL_INFO(dev)->gen == 4) {
  120. if (dev_priv->lvds_dither)
  121. temp |= LVDS_ENABLE_DITHER;
  122. else
  123. temp &= ~LVDS_ENABLE_DITHER;
  124. }
  125. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  126. if (fixed_mode->flags & DRM_MODE_FLAG_NHSYNC)
  127. temp |= LVDS_HSYNC_POLARITY;
  128. if (fixed_mode->flags & DRM_MODE_FLAG_NVSYNC)
  129. temp |= LVDS_VSYNC_POLARITY;
  130. I915_WRITE(lvds_encoder->reg, temp);
  131. }
  132. static void intel_pre_enable_lvds(struct intel_encoder *encoder)
  133. {
  134. struct drm_device *dev = encoder->base.dev;
  135. struct intel_lvds_encoder *enc = to_lvds_encoder(&encoder->base);
  136. struct drm_i915_private *dev_priv = dev->dev_private;
  137. if (HAS_PCH_SPLIT(dev) || !enc->pfit_control)
  138. return;
  139. /*
  140. * Enable automatic panel scaling so that non-native modes
  141. * fill the screen. The panel fitter should only be
  142. * adjusted whilst the pipe is disabled, according to
  143. * register description and PRM.
  144. */
  145. DRM_DEBUG_KMS("applying panel-fitter: %x, %x\n",
  146. enc->pfit_control,
  147. enc->pfit_pgm_ratios);
  148. I915_WRITE(PFIT_PGM_RATIOS, enc->pfit_pgm_ratios);
  149. I915_WRITE(PFIT_CONTROL, enc->pfit_control);
  150. }
  151. /**
  152. * Sets the power state for the panel.
  153. */
  154. static void intel_enable_lvds(struct intel_encoder *encoder)
  155. {
  156. struct drm_device *dev = encoder->base.dev;
  157. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  158. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  159. struct drm_i915_private *dev_priv = dev->dev_private;
  160. u32 ctl_reg, stat_reg;
  161. if (HAS_PCH_SPLIT(dev)) {
  162. ctl_reg = PCH_PP_CONTROL;
  163. stat_reg = PCH_PP_STATUS;
  164. } else {
  165. ctl_reg = PP_CONTROL;
  166. stat_reg = PP_STATUS;
  167. }
  168. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
  169. I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
  170. POSTING_READ(lvds_encoder->reg);
  171. if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
  172. DRM_ERROR("timed out waiting for panel to power on\n");
  173. intel_panel_enable_backlight(dev, intel_crtc->pipe);
  174. }
  175. static void intel_disable_lvds(struct intel_encoder *encoder)
  176. {
  177. struct drm_device *dev = encoder->base.dev;
  178. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  179. struct drm_i915_private *dev_priv = dev->dev_private;
  180. u32 ctl_reg, stat_reg;
  181. if (HAS_PCH_SPLIT(dev)) {
  182. ctl_reg = PCH_PP_CONTROL;
  183. stat_reg = PCH_PP_STATUS;
  184. } else {
  185. ctl_reg = PP_CONTROL;
  186. stat_reg = PP_STATUS;
  187. }
  188. intel_panel_disable_backlight(dev);
  189. I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
  190. if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
  191. DRM_ERROR("timed out waiting for panel to power off\n");
  192. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) & ~LVDS_PORT_EN);
  193. POSTING_READ(lvds_encoder->reg);
  194. }
  195. static int intel_lvds_mode_valid(struct drm_connector *connector,
  196. struct drm_display_mode *mode)
  197. {
  198. struct intel_connector *intel_connector = to_intel_connector(connector);
  199. struct drm_display_mode *fixed_mode = intel_connector->panel.fixed_mode;
  200. if (mode->hdisplay > fixed_mode->hdisplay)
  201. return MODE_PANEL;
  202. if (mode->vdisplay > fixed_mode->vdisplay)
  203. return MODE_PANEL;
  204. return MODE_OK;
  205. }
  206. static void
  207. centre_horizontally(struct drm_display_mode *mode,
  208. int width)
  209. {
  210. u32 border, sync_pos, blank_width, sync_width;
  211. /* keep the hsync and hblank widths constant */
  212. sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start;
  213. blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start;
  214. sync_pos = (blank_width - sync_width + 1) / 2;
  215. border = (mode->hdisplay - width + 1) / 2;
  216. border += border & 1; /* make the border even */
  217. mode->crtc_hdisplay = width;
  218. mode->crtc_hblank_start = width + border;
  219. mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;
  220. mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
  221. mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
  222. }
  223. static void
  224. centre_vertically(struct drm_display_mode *mode,
  225. int height)
  226. {
  227. u32 border, sync_pos, blank_width, sync_width;
  228. /* keep the vsync and vblank widths constant */
  229. sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;
  230. blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;
  231. sync_pos = (blank_width - sync_width + 1) / 2;
  232. border = (mode->vdisplay - height + 1) / 2;
  233. mode->crtc_vdisplay = height;
  234. mode->crtc_vblank_start = height + border;
  235. mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
  236. mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
  237. mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
  238. }
  239. static inline u32 panel_fitter_scaling(u32 source, u32 target)
  240. {
  241. /*
  242. * Floating point operation is not supported. So the FACTOR
  243. * is defined, which can avoid the floating point computation
  244. * when calculating the panel ratio.
  245. */
  246. #define ACCURACY 12
  247. #define FACTOR (1 << ACCURACY)
  248. u32 ratio = source * FACTOR / target;
  249. return (FACTOR * ratio + FACTOR/2) / FACTOR;
  250. }
  251. static bool intel_lvds_compute_config(struct intel_encoder *intel_encoder,
  252. struct intel_crtc_config *pipe_config)
  253. {
  254. struct drm_device *dev = intel_encoder->base.dev;
  255. struct drm_i915_private *dev_priv = dev->dev_private;
  256. struct intel_lvds_encoder *lvds_encoder =
  257. to_lvds_encoder(&intel_encoder->base);
  258. struct intel_connector *intel_connector =
  259. &lvds_encoder->attached_connector->base;
  260. struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode;
  261. struct drm_display_mode *mode = &pipe_config->requested_mode;
  262. struct intel_crtc *intel_crtc = lvds_encoder->base.new_crtc;
  263. u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
  264. int pipe;
  265. /* Should never happen!! */
  266. if (INTEL_INFO(dev)->gen < 4 && intel_crtc->pipe == 0) {
  267. DRM_ERROR("Can't support LVDS on pipe A\n");
  268. return false;
  269. }
  270. if (intel_encoder_check_is_cloned(&lvds_encoder->base))
  271. return false;
  272. /*
  273. * We have timings from the BIOS for the panel, put them in
  274. * to the adjusted mode. The CRTC will be set up for this mode,
  275. * with the panel scaling set up to source from the H/VDisplay
  276. * of the original mode.
  277. */
  278. intel_fixed_panel_mode(intel_connector->panel.fixed_mode,
  279. adjusted_mode);
  280. if (HAS_PCH_SPLIT(dev)) {
  281. intel_pch_panel_fitting(dev,
  282. intel_connector->panel.fitting_mode,
  283. mode, adjusted_mode);
  284. return true;
  285. }
  286. /* Native modes don't need fitting */
  287. if (adjusted_mode->hdisplay == mode->hdisplay &&
  288. adjusted_mode->vdisplay == mode->vdisplay)
  289. goto out;
  290. /* 965+ wants fuzzy fitting */
  291. if (INTEL_INFO(dev)->gen >= 4)
  292. pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |
  293. PFIT_FILTER_FUZZY);
  294. /*
  295. * Enable automatic panel scaling for non-native modes so that they fill
  296. * the screen. Should be enabled before the pipe is enabled, according
  297. * to register description and PRM.
  298. * Change the value here to see the borders for debugging
  299. */
  300. for_each_pipe(pipe)
  301. I915_WRITE(BCLRPAT(pipe), 0);
  302. drm_mode_set_crtcinfo(adjusted_mode, 0);
  303. pipe_config->timings_set = true;
  304. switch (intel_connector->panel.fitting_mode) {
  305. case DRM_MODE_SCALE_CENTER:
  306. /*
  307. * For centered modes, we have to calculate border widths &
  308. * heights and modify the values programmed into the CRTC.
  309. */
  310. centre_horizontally(adjusted_mode, mode->hdisplay);
  311. centre_vertically(adjusted_mode, mode->vdisplay);
  312. border = LVDS_BORDER_ENABLE;
  313. break;
  314. case DRM_MODE_SCALE_ASPECT:
  315. /* Scale but preserve the aspect ratio */
  316. if (INTEL_INFO(dev)->gen >= 4) {
  317. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  318. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  319. /* 965+ is easy, it does everything in hw */
  320. if (scaled_width > scaled_height)
  321. pfit_control |= PFIT_ENABLE | PFIT_SCALING_PILLAR;
  322. else if (scaled_width < scaled_height)
  323. pfit_control |= PFIT_ENABLE | PFIT_SCALING_LETTER;
  324. else if (adjusted_mode->hdisplay != mode->hdisplay)
  325. pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
  326. } else {
  327. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  328. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  329. /*
  330. * For earlier chips we have to calculate the scaling
  331. * ratio by hand and program it into the
  332. * PFIT_PGM_RATIO register
  333. */
  334. if (scaled_width > scaled_height) { /* pillar */
  335. centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay);
  336. border = LVDS_BORDER_ENABLE;
  337. if (mode->vdisplay != adjusted_mode->vdisplay) {
  338. u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay);
  339. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  340. bits << PFIT_VERT_SCALE_SHIFT);
  341. pfit_control |= (PFIT_ENABLE |
  342. VERT_INTERP_BILINEAR |
  343. HORIZ_INTERP_BILINEAR);
  344. }
  345. } else if (scaled_width < scaled_height) { /* letter */
  346. centre_vertically(adjusted_mode, scaled_width / mode->hdisplay);
  347. border = LVDS_BORDER_ENABLE;
  348. if (mode->hdisplay != adjusted_mode->hdisplay) {
  349. u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay);
  350. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  351. bits << PFIT_VERT_SCALE_SHIFT);
  352. pfit_control |= (PFIT_ENABLE |
  353. VERT_INTERP_BILINEAR |
  354. HORIZ_INTERP_BILINEAR);
  355. }
  356. } else
  357. /* Aspects match, Let hw scale both directions */
  358. pfit_control |= (PFIT_ENABLE |
  359. VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
  360. VERT_INTERP_BILINEAR |
  361. HORIZ_INTERP_BILINEAR);
  362. }
  363. break;
  364. case DRM_MODE_SCALE_FULLSCREEN:
  365. /*
  366. * Full scaling, even if it changes the aspect ratio.
  367. * Fortunately this is all done for us in hw.
  368. */
  369. if (mode->vdisplay != adjusted_mode->vdisplay ||
  370. mode->hdisplay != adjusted_mode->hdisplay) {
  371. pfit_control |= PFIT_ENABLE;
  372. if (INTEL_INFO(dev)->gen >= 4)
  373. pfit_control |= PFIT_SCALING_AUTO;
  374. else
  375. pfit_control |= (VERT_AUTO_SCALE |
  376. VERT_INTERP_BILINEAR |
  377. HORIZ_AUTO_SCALE |
  378. HORIZ_INTERP_BILINEAR);
  379. }
  380. break;
  381. default:
  382. break;
  383. }
  384. out:
  385. /* If not enabling scaling, be consistent and always use 0. */
  386. if ((pfit_control & PFIT_ENABLE) == 0) {
  387. pfit_control = 0;
  388. pfit_pgm_ratios = 0;
  389. }
  390. /* Make sure pre-965 set dither correctly */
  391. if (INTEL_INFO(dev)->gen < 4 && dev_priv->lvds_dither)
  392. pfit_control |= PANEL_8TO6_DITHER_ENABLE;
  393. if (pfit_control != lvds_encoder->pfit_control ||
  394. pfit_pgm_ratios != lvds_encoder->pfit_pgm_ratios) {
  395. lvds_encoder->pfit_control = pfit_control;
  396. lvds_encoder->pfit_pgm_ratios = pfit_pgm_ratios;
  397. }
  398. dev_priv->lvds_border_bits = border;
  399. /*
  400. * XXX: It would be nice to support lower refresh rates on the
  401. * panels to reduce power consumption, and perhaps match the
  402. * user's requested refresh rate.
  403. */
  404. return true;
  405. }
  406. static void intel_lvds_mode_set(struct drm_encoder *encoder,
  407. struct drm_display_mode *mode,
  408. struct drm_display_mode *adjusted_mode)
  409. {
  410. /*
  411. * The LVDS pin pair will already have been turned on in the
  412. * intel_crtc_mode_set since it has a large impact on the DPLL
  413. * settings.
  414. */
  415. }
  416. /**
  417. * Detect the LVDS connection.
  418. *
  419. * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
  420. * connected and closed means disconnected. We also send hotplug events as
  421. * needed, using lid status notification from the input layer.
  422. */
  423. static enum drm_connector_status
  424. intel_lvds_detect(struct drm_connector *connector, bool force)
  425. {
  426. struct drm_device *dev = connector->dev;
  427. enum drm_connector_status status;
  428. status = intel_panel_detect(dev);
  429. if (status != connector_status_unknown)
  430. return status;
  431. return connector_status_connected;
  432. }
  433. /**
  434. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  435. */
  436. static int intel_lvds_get_modes(struct drm_connector *connector)
  437. {
  438. struct intel_lvds_connector *lvds_connector = to_lvds_connector(connector);
  439. struct drm_device *dev = connector->dev;
  440. struct drm_display_mode *mode;
  441. /* use cached edid if we have one */
  442. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  443. return drm_add_edid_modes(connector, lvds_connector->base.edid);
  444. mode = drm_mode_duplicate(dev, lvds_connector->base.panel.fixed_mode);
  445. if (mode == NULL)
  446. return 0;
  447. drm_mode_probed_add(connector, mode);
  448. return 1;
  449. }
  450. static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
  451. {
  452. DRM_INFO("Skipping forced modeset for %s\n", id->ident);
  453. return 1;
  454. }
  455. /* The GPU hangs up on these systems if modeset is performed on LID open */
  456. static const struct dmi_system_id intel_no_modeset_on_lid[] = {
  457. {
  458. .callback = intel_no_modeset_on_lid_dmi_callback,
  459. .ident = "Toshiba Tecra A11",
  460. .matches = {
  461. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  462. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
  463. },
  464. },
  465. { } /* terminating entry */
  466. };
  467. /*
  468. * Lid events. Note the use of 'modeset':
  469. * - we set it to MODESET_ON_LID_OPEN on lid close,
  470. * and set it to MODESET_DONE on open
  471. * - we use it as a "only once" bit (ie we ignore
  472. * duplicate events where it was already properly set)
  473. * - the suspend/resume paths will set it to
  474. * MODESET_SUSPENDED and ignore the lid open event,
  475. * because they restore the mode ("lid open").
  476. */
  477. static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
  478. void *unused)
  479. {
  480. struct intel_lvds_connector *lvds_connector =
  481. container_of(nb, struct intel_lvds_connector, lid_notifier);
  482. struct drm_connector *connector = &lvds_connector->base.base;
  483. struct drm_device *dev = connector->dev;
  484. struct drm_i915_private *dev_priv = dev->dev_private;
  485. if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
  486. return NOTIFY_OK;
  487. mutex_lock(&dev_priv->modeset_restore_lock);
  488. if (dev_priv->modeset_restore == MODESET_SUSPENDED)
  489. goto exit;
  490. /*
  491. * check and update the status of LVDS connector after receiving
  492. * the LID nofication event.
  493. */
  494. connector->status = connector->funcs->detect(connector, false);
  495. /* Don't force modeset on machines where it causes a GPU lockup */
  496. if (dmi_check_system(intel_no_modeset_on_lid))
  497. goto exit;
  498. if (!acpi_lid_open()) {
  499. /* do modeset on next lid open event */
  500. dev_priv->modeset_restore = MODESET_ON_LID_OPEN;
  501. goto exit;
  502. }
  503. if (dev_priv->modeset_restore == MODESET_DONE)
  504. goto exit;
  505. drm_modeset_lock_all(dev);
  506. intel_modeset_setup_hw_state(dev, true);
  507. drm_modeset_unlock_all(dev);
  508. dev_priv->modeset_restore = MODESET_DONE;
  509. exit:
  510. mutex_unlock(&dev_priv->modeset_restore_lock);
  511. return NOTIFY_OK;
  512. }
  513. /**
  514. * intel_lvds_destroy - unregister and free LVDS structures
  515. * @connector: connector to free
  516. *
  517. * Unregister the DDC bus for this connector then free the driver private
  518. * structure.
  519. */
  520. static void intel_lvds_destroy(struct drm_connector *connector)
  521. {
  522. struct intel_lvds_connector *lvds_connector =
  523. to_lvds_connector(connector);
  524. if (lvds_connector->lid_notifier.notifier_call)
  525. acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
  526. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  527. kfree(lvds_connector->base.edid);
  528. intel_panel_destroy_backlight(connector->dev);
  529. intel_panel_fini(&lvds_connector->base.panel);
  530. drm_sysfs_connector_remove(connector);
  531. drm_connector_cleanup(connector);
  532. kfree(connector);
  533. }
  534. static int intel_lvds_set_property(struct drm_connector *connector,
  535. struct drm_property *property,
  536. uint64_t value)
  537. {
  538. struct intel_connector *intel_connector = to_intel_connector(connector);
  539. struct drm_device *dev = connector->dev;
  540. if (property == dev->mode_config.scaling_mode_property) {
  541. struct drm_crtc *crtc;
  542. if (value == DRM_MODE_SCALE_NONE) {
  543. DRM_DEBUG_KMS("no scaling not supported\n");
  544. return -EINVAL;
  545. }
  546. if (intel_connector->panel.fitting_mode == value) {
  547. /* the LVDS scaling property is not changed */
  548. return 0;
  549. }
  550. intel_connector->panel.fitting_mode = value;
  551. crtc = intel_attached_encoder(connector)->base.crtc;
  552. if (crtc && crtc->enabled) {
  553. /*
  554. * If the CRTC is enabled, the display will be changed
  555. * according to the new panel fitting mode.
  556. */
  557. intel_crtc_restore_mode(crtc);
  558. }
  559. }
  560. return 0;
  561. }
  562. static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
  563. .mode_set = intel_lvds_mode_set,
  564. };
  565. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  566. .get_modes = intel_lvds_get_modes,
  567. .mode_valid = intel_lvds_mode_valid,
  568. .best_encoder = intel_best_encoder,
  569. };
  570. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  571. .dpms = intel_connector_dpms,
  572. .detect = intel_lvds_detect,
  573. .fill_modes = drm_helper_probe_single_connector_modes,
  574. .set_property = intel_lvds_set_property,
  575. .destroy = intel_lvds_destroy,
  576. };
  577. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  578. .destroy = intel_encoder_destroy,
  579. };
  580. static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  581. {
  582. DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
  583. return 1;
  584. }
  585. /* These systems claim to have LVDS, but really don't */
  586. static const struct dmi_system_id intel_no_lvds[] = {
  587. {
  588. .callback = intel_no_lvds_dmi_callback,
  589. .ident = "Apple Mac Mini (Core series)",
  590. .matches = {
  591. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  592. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  593. },
  594. },
  595. {
  596. .callback = intel_no_lvds_dmi_callback,
  597. .ident = "Apple Mac Mini (Core 2 series)",
  598. .matches = {
  599. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  600. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  601. },
  602. },
  603. {
  604. .callback = intel_no_lvds_dmi_callback,
  605. .ident = "MSI IM-945GSE-A",
  606. .matches = {
  607. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  608. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  609. },
  610. },
  611. {
  612. .callback = intel_no_lvds_dmi_callback,
  613. .ident = "Dell Studio Hybrid",
  614. .matches = {
  615. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  616. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  617. },
  618. },
  619. {
  620. .callback = intel_no_lvds_dmi_callback,
  621. .ident = "Dell OptiPlex FX170",
  622. .matches = {
  623. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  624. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
  625. },
  626. },
  627. {
  628. .callback = intel_no_lvds_dmi_callback,
  629. .ident = "AOpen Mini PC",
  630. .matches = {
  631. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  632. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  633. },
  634. },
  635. {
  636. .callback = intel_no_lvds_dmi_callback,
  637. .ident = "AOpen Mini PC MP915",
  638. .matches = {
  639. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  640. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  641. },
  642. },
  643. {
  644. .callback = intel_no_lvds_dmi_callback,
  645. .ident = "AOpen i915GMm-HFS",
  646. .matches = {
  647. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  648. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  649. },
  650. },
  651. {
  652. .callback = intel_no_lvds_dmi_callback,
  653. .ident = "AOpen i45GMx-I",
  654. .matches = {
  655. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  656. DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
  657. },
  658. },
  659. {
  660. .callback = intel_no_lvds_dmi_callback,
  661. .ident = "Aopen i945GTt-VFA",
  662. .matches = {
  663. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  664. },
  665. },
  666. {
  667. .callback = intel_no_lvds_dmi_callback,
  668. .ident = "Clientron U800",
  669. .matches = {
  670. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  671. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  672. },
  673. },
  674. {
  675. .callback = intel_no_lvds_dmi_callback,
  676. .ident = "Clientron E830",
  677. .matches = {
  678. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  679. DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
  680. },
  681. },
  682. {
  683. .callback = intel_no_lvds_dmi_callback,
  684. .ident = "Asus EeeBox PC EB1007",
  685. .matches = {
  686. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  687. DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
  688. },
  689. },
  690. {
  691. .callback = intel_no_lvds_dmi_callback,
  692. .ident = "Asus AT5NM10T-I",
  693. .matches = {
  694. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  695. DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
  696. },
  697. },
  698. {
  699. .callback = intel_no_lvds_dmi_callback,
  700. .ident = "Hewlett-Packard HP t5740e Thin Client",
  701. .matches = {
  702. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  703. DMI_MATCH(DMI_PRODUCT_NAME, "HP t5740e Thin Client"),
  704. },
  705. },
  706. {
  707. .callback = intel_no_lvds_dmi_callback,
  708. .ident = "Hewlett-Packard t5745",
  709. .matches = {
  710. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  711. DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
  712. },
  713. },
  714. {
  715. .callback = intel_no_lvds_dmi_callback,
  716. .ident = "Hewlett-Packard st5747",
  717. .matches = {
  718. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  719. DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
  720. },
  721. },
  722. {
  723. .callback = intel_no_lvds_dmi_callback,
  724. .ident = "MSI Wind Box DC500",
  725. .matches = {
  726. DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
  727. DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
  728. },
  729. },
  730. {
  731. .callback = intel_no_lvds_dmi_callback,
  732. .ident = "Gigabyte GA-D525TUD",
  733. .matches = {
  734. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  735. DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
  736. },
  737. },
  738. {
  739. .callback = intel_no_lvds_dmi_callback,
  740. .ident = "Supermicro X7SPA-H",
  741. .matches = {
  742. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  743. DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
  744. },
  745. },
  746. { } /* terminating entry */
  747. };
  748. /**
  749. * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
  750. * @dev: drm device
  751. * @connector: LVDS connector
  752. *
  753. * Find the reduced downclock for LVDS in EDID.
  754. */
  755. static void intel_find_lvds_downclock(struct drm_device *dev,
  756. struct drm_display_mode *fixed_mode,
  757. struct drm_connector *connector)
  758. {
  759. struct drm_i915_private *dev_priv = dev->dev_private;
  760. struct drm_display_mode *scan;
  761. int temp_downclock;
  762. temp_downclock = fixed_mode->clock;
  763. list_for_each_entry(scan, &connector->probed_modes, head) {
  764. /*
  765. * If one mode has the same resolution with the fixed_panel
  766. * mode while they have the different refresh rate, it means
  767. * that the reduced downclock is found for the LVDS. In such
  768. * case we can set the different FPx0/1 to dynamically select
  769. * between low and high frequency.
  770. */
  771. if (scan->hdisplay == fixed_mode->hdisplay &&
  772. scan->hsync_start == fixed_mode->hsync_start &&
  773. scan->hsync_end == fixed_mode->hsync_end &&
  774. scan->htotal == fixed_mode->htotal &&
  775. scan->vdisplay == fixed_mode->vdisplay &&
  776. scan->vsync_start == fixed_mode->vsync_start &&
  777. scan->vsync_end == fixed_mode->vsync_end &&
  778. scan->vtotal == fixed_mode->vtotal) {
  779. if (scan->clock < temp_downclock) {
  780. /*
  781. * The downclock is already found. But we
  782. * expect to find the lower downclock.
  783. */
  784. temp_downclock = scan->clock;
  785. }
  786. }
  787. }
  788. if (temp_downclock < fixed_mode->clock && i915_lvds_downclock) {
  789. /* We found the downclock for LVDS. */
  790. dev_priv->lvds_downclock_avail = 1;
  791. dev_priv->lvds_downclock = temp_downclock;
  792. DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
  793. "Normal clock %dKhz, downclock %dKhz\n",
  794. fixed_mode->clock, temp_downclock);
  795. }
  796. }
  797. /*
  798. * Enumerate the child dev array parsed from VBT to check whether
  799. * the LVDS is present.
  800. * If it is present, return 1.
  801. * If it is not present, return false.
  802. * If no child dev is parsed from VBT, it assumes that the LVDS is present.
  803. */
  804. static bool lvds_is_present_in_vbt(struct drm_device *dev,
  805. u8 *i2c_pin)
  806. {
  807. struct drm_i915_private *dev_priv = dev->dev_private;
  808. int i;
  809. if (!dev_priv->child_dev_num)
  810. return true;
  811. for (i = 0; i < dev_priv->child_dev_num; i++) {
  812. struct child_device_config *child = dev_priv->child_dev + i;
  813. /* If the device type is not LFP, continue.
  814. * We have to check both the new identifiers as well as the
  815. * old for compatibility with some BIOSes.
  816. */
  817. if (child->device_type != DEVICE_TYPE_INT_LFP &&
  818. child->device_type != DEVICE_TYPE_LFP)
  819. continue;
  820. if (intel_gmbus_is_port_valid(child->i2c_pin))
  821. *i2c_pin = child->i2c_pin;
  822. /* However, we cannot trust the BIOS writers to populate
  823. * the VBT correctly. Since LVDS requires additional
  824. * information from AIM blocks, a non-zero addin offset is
  825. * a good indicator that the LVDS is actually present.
  826. */
  827. if (child->addin_offset)
  828. return true;
  829. /* But even then some BIOS writers perform some black magic
  830. * and instantiate the device without reference to any
  831. * additional data. Trust that if the VBT was written into
  832. * the OpRegion then they have validated the LVDS's existence.
  833. */
  834. if (dev_priv->opregion.vbt)
  835. return true;
  836. }
  837. return false;
  838. }
  839. static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
  840. {
  841. DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
  842. return 1;
  843. }
  844. static const struct dmi_system_id intel_dual_link_lvds[] = {
  845. {
  846. .callback = intel_dual_link_lvds_callback,
  847. .ident = "Apple MacBook Pro (Core i5/i7 Series)",
  848. .matches = {
  849. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  850. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
  851. },
  852. },
  853. { } /* terminating entry */
  854. };
  855. bool intel_is_dual_link_lvds(struct drm_device *dev)
  856. {
  857. struct intel_encoder *encoder;
  858. struct intel_lvds_encoder *lvds_encoder;
  859. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  860. base.head) {
  861. if (encoder->type == INTEL_OUTPUT_LVDS) {
  862. lvds_encoder = to_lvds_encoder(&encoder->base);
  863. return lvds_encoder->is_dual_link;
  864. }
  865. }
  866. return false;
  867. }
  868. static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
  869. {
  870. struct drm_device *dev = lvds_encoder->base.base.dev;
  871. unsigned int val;
  872. struct drm_i915_private *dev_priv = dev->dev_private;
  873. /* use the module option value if specified */
  874. if (i915_lvds_channel_mode > 0)
  875. return i915_lvds_channel_mode == 2;
  876. if (dmi_check_system(intel_dual_link_lvds))
  877. return true;
  878. /* BIOS should set the proper LVDS register value at boot, but
  879. * in reality, it doesn't set the value when the lid is closed;
  880. * we need to check "the value to be set" in VBT when LVDS
  881. * register is uninitialized.
  882. */
  883. val = I915_READ(lvds_encoder->reg);
  884. if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
  885. val = dev_priv->bios_lvds_val;
  886. return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
  887. }
  888. static bool intel_lvds_supported(struct drm_device *dev)
  889. {
  890. /* With the introduction of the PCH we gained a dedicated
  891. * LVDS presence pin, use it. */
  892. if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev))
  893. return true;
  894. /* Otherwise LVDS was only attached to mobile products,
  895. * except for the inglorious 830gm */
  896. if (INTEL_INFO(dev)->gen <= 4 && IS_MOBILE(dev) && !IS_I830(dev))
  897. return true;
  898. return false;
  899. }
  900. /**
  901. * intel_lvds_init - setup LVDS connectors on this device
  902. * @dev: drm device
  903. *
  904. * Create the connector, register the LVDS DDC bus, and try to figure out what
  905. * modes we can display on the LVDS panel (if present).
  906. */
  907. bool intel_lvds_init(struct drm_device *dev)
  908. {
  909. struct drm_i915_private *dev_priv = dev->dev_private;
  910. struct intel_lvds_encoder *lvds_encoder;
  911. struct intel_encoder *intel_encoder;
  912. struct intel_lvds_connector *lvds_connector;
  913. struct intel_connector *intel_connector;
  914. struct drm_connector *connector;
  915. struct drm_encoder *encoder;
  916. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  917. struct drm_display_mode *fixed_mode = NULL;
  918. struct edid *edid;
  919. struct drm_crtc *crtc;
  920. u32 lvds;
  921. int pipe;
  922. u8 pin;
  923. if (!intel_lvds_supported(dev))
  924. return false;
  925. /* Skip init on machines we know falsely report LVDS */
  926. if (dmi_check_system(intel_no_lvds))
  927. return false;
  928. pin = GMBUS_PORT_PANEL;
  929. if (!lvds_is_present_in_vbt(dev, &pin)) {
  930. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  931. return false;
  932. }
  933. if (HAS_PCH_SPLIT(dev)) {
  934. if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
  935. return false;
  936. if (dev_priv->edp.support) {
  937. DRM_DEBUG_KMS("disable LVDS for eDP support\n");
  938. return false;
  939. }
  940. }
  941. lvds_encoder = kzalloc(sizeof(struct intel_lvds_encoder), GFP_KERNEL);
  942. if (!lvds_encoder)
  943. return false;
  944. lvds_connector = kzalloc(sizeof(struct intel_lvds_connector), GFP_KERNEL);
  945. if (!lvds_connector) {
  946. kfree(lvds_encoder);
  947. return false;
  948. }
  949. lvds_encoder->attached_connector = lvds_connector;
  950. if (!HAS_PCH_SPLIT(dev)) {
  951. lvds_encoder->pfit_control = I915_READ(PFIT_CONTROL);
  952. }
  953. intel_encoder = &lvds_encoder->base;
  954. encoder = &intel_encoder->base;
  955. intel_connector = &lvds_connector->base;
  956. connector = &intel_connector->base;
  957. drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
  958. DRM_MODE_CONNECTOR_LVDS);
  959. drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
  960. DRM_MODE_ENCODER_LVDS);
  961. intel_encoder->enable = intel_enable_lvds;
  962. intel_encoder->pre_enable = intel_pre_enable_lvds;
  963. intel_encoder->pre_pll_enable = intel_pre_pll_enable_lvds;
  964. intel_encoder->compute_config = intel_lvds_compute_config;
  965. intel_encoder->disable = intel_disable_lvds;
  966. intel_encoder->get_hw_state = intel_lvds_get_hw_state;
  967. intel_connector->get_hw_state = intel_connector_get_hw_state;
  968. intel_connector_attach_encoder(intel_connector, intel_encoder);
  969. intel_encoder->type = INTEL_OUTPUT_LVDS;
  970. intel_encoder->cloneable = false;
  971. if (HAS_PCH_SPLIT(dev))
  972. intel_encoder->crtc_mask = (1 << 0) | (1 << 1) | (1 << 2);
  973. else if (IS_GEN4(dev))
  974. intel_encoder->crtc_mask = (1 << 0) | (1 << 1);
  975. else
  976. intel_encoder->crtc_mask = (1 << 1);
  977. drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
  978. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  979. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  980. connector->interlace_allowed = false;
  981. connector->doublescan_allowed = false;
  982. if (HAS_PCH_SPLIT(dev)) {
  983. lvds_encoder->reg = PCH_LVDS;
  984. } else {
  985. lvds_encoder->reg = LVDS;
  986. }
  987. /* create the scaling mode property */
  988. drm_mode_create_scaling_mode_property(dev);
  989. drm_object_attach_property(&connector->base,
  990. dev->mode_config.scaling_mode_property,
  991. DRM_MODE_SCALE_ASPECT);
  992. intel_connector->panel.fitting_mode = DRM_MODE_SCALE_ASPECT;
  993. /*
  994. * LVDS discovery:
  995. * 1) check for EDID on DDC
  996. * 2) check for VBT data
  997. * 3) check to see if LVDS is already on
  998. * if none of the above, no panel
  999. * 4) make sure lid is open
  1000. * if closed, act like it's not there for now
  1001. */
  1002. /*
  1003. * Attempt to get the fixed panel mode from DDC. Assume that the
  1004. * preferred mode is the right one.
  1005. */
  1006. edid = drm_get_edid(connector, intel_gmbus_get_adapter(dev_priv, pin));
  1007. if (edid) {
  1008. if (drm_add_edid_modes(connector, edid)) {
  1009. drm_mode_connector_update_edid_property(connector,
  1010. edid);
  1011. } else {
  1012. kfree(edid);
  1013. edid = ERR_PTR(-EINVAL);
  1014. }
  1015. } else {
  1016. edid = ERR_PTR(-ENOENT);
  1017. }
  1018. lvds_connector->base.edid = edid;
  1019. if (IS_ERR_OR_NULL(edid)) {
  1020. /* Didn't get an EDID, so
  1021. * Set wide sync ranges so we get all modes
  1022. * handed to valid_mode for checking
  1023. */
  1024. connector->display_info.min_vfreq = 0;
  1025. connector->display_info.max_vfreq = 200;
  1026. connector->display_info.min_hfreq = 0;
  1027. connector->display_info.max_hfreq = 200;
  1028. }
  1029. list_for_each_entry(scan, &connector->probed_modes, head) {
  1030. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  1031. DRM_DEBUG_KMS("using preferred mode from EDID: ");
  1032. drm_mode_debug_printmodeline(scan);
  1033. fixed_mode = drm_mode_duplicate(dev, scan);
  1034. if (fixed_mode) {
  1035. intel_find_lvds_downclock(dev, fixed_mode,
  1036. connector);
  1037. goto out;
  1038. }
  1039. }
  1040. }
  1041. /* Failed to get EDID, what about VBT? */
  1042. if (dev_priv->lfp_lvds_vbt_mode) {
  1043. DRM_DEBUG_KMS("using mode from VBT: ");
  1044. drm_mode_debug_printmodeline(dev_priv->lfp_lvds_vbt_mode);
  1045. fixed_mode = drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  1046. if (fixed_mode) {
  1047. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  1048. goto out;
  1049. }
  1050. }
  1051. /*
  1052. * If we didn't get EDID, try checking if the panel is already turned
  1053. * on. If so, assume that whatever is currently programmed is the
  1054. * correct mode.
  1055. */
  1056. /* Ironlake: FIXME if still fail, not try pipe mode now */
  1057. if (HAS_PCH_SPLIT(dev))
  1058. goto failed;
  1059. lvds = I915_READ(LVDS);
  1060. pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
  1061. crtc = intel_get_crtc_for_pipe(dev, pipe);
  1062. if (crtc && (lvds & LVDS_PORT_EN)) {
  1063. fixed_mode = intel_crtc_mode_get(dev, crtc);
  1064. if (fixed_mode) {
  1065. DRM_DEBUG_KMS("using current (BIOS) mode: ");
  1066. drm_mode_debug_printmodeline(fixed_mode);
  1067. fixed_mode->type |= DRM_MODE_TYPE_PREFERRED;
  1068. goto out;
  1069. }
  1070. }
  1071. /* If we still don't have a mode after all that, give up. */
  1072. if (!fixed_mode)
  1073. goto failed;
  1074. out:
  1075. lvds_encoder->is_dual_link = compute_is_dual_link_lvds(lvds_encoder);
  1076. DRM_DEBUG_KMS("detected %s-link lvds configuration\n",
  1077. lvds_encoder->is_dual_link ? "dual" : "single");
  1078. /*
  1079. * Unlock registers and just
  1080. * leave them unlocked
  1081. */
  1082. if (HAS_PCH_SPLIT(dev)) {
  1083. I915_WRITE(PCH_PP_CONTROL,
  1084. I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
  1085. } else {
  1086. I915_WRITE(PP_CONTROL,
  1087. I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
  1088. }
  1089. lvds_connector->lid_notifier.notifier_call = intel_lid_notify;
  1090. if (acpi_lid_notifier_register(&lvds_connector->lid_notifier)) {
  1091. DRM_DEBUG_KMS("lid notifier registration failed\n");
  1092. lvds_connector->lid_notifier.notifier_call = NULL;
  1093. }
  1094. drm_sysfs_connector_add(connector);
  1095. intel_panel_init(&intel_connector->panel, fixed_mode);
  1096. intel_panel_setup_backlight(connector);
  1097. return true;
  1098. failed:
  1099. DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
  1100. drm_connector_cleanup(connector);
  1101. drm_encoder_cleanup(encoder);
  1102. if (fixed_mode)
  1103. drm_mode_destroy(dev, fixed_mode);
  1104. kfree(lvds_encoder);
  1105. kfree(lvds_connector);
  1106. return false;
  1107. }