intel_lvds.c 37 KB

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