intel_lvds.c 36 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 pfit_dirty;
  50. bool is_dual_link;
  51. u32 reg;
  52. struct intel_lvds_connector *attached_connector;
  53. };
  54. static struct intel_lvds_encoder *to_lvds_encoder(struct drm_encoder *encoder)
  55. {
  56. return container_of(encoder, struct intel_lvds_encoder, base.base);
  57. }
  58. static struct intel_lvds_connector *to_lvds_connector(struct drm_connector *connector)
  59. {
  60. return container_of(connector, struct intel_lvds_connector, base.base);
  61. }
  62. static bool intel_lvds_get_hw_state(struct intel_encoder *encoder,
  63. enum pipe *pipe)
  64. {
  65. struct drm_device *dev = encoder->base.dev;
  66. struct drm_i915_private *dev_priv = dev->dev_private;
  67. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  68. u32 tmp;
  69. tmp = I915_READ(lvds_encoder->reg);
  70. if (!(tmp & LVDS_PORT_EN))
  71. return false;
  72. if (HAS_PCH_CPT(dev))
  73. *pipe = PORT_TO_PIPE_CPT(tmp);
  74. else
  75. *pipe = PORT_TO_PIPE(tmp);
  76. return true;
  77. }
  78. /* The LVDS pin pair needs to be on before the DPLLs are enabled.
  79. * This is an exception to the general rule that mode_set doesn't turn
  80. * things on.
  81. */
  82. static void intel_pre_pll_enable_lvds(struct intel_encoder *encoder)
  83. {
  84. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  85. struct drm_device *dev = encoder->base.dev;
  86. struct drm_i915_private *dev_priv = dev->dev_private;
  87. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  88. struct drm_display_mode *fixed_mode =
  89. lvds_encoder->attached_connector->base.panel.fixed_mode;
  90. int pipe = intel_crtc->pipe;
  91. u32 temp;
  92. temp = I915_READ(lvds_encoder->reg);
  93. temp |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP;
  94. if (HAS_PCH_CPT(dev)) {
  95. temp &= ~PORT_TRANS_SEL_MASK;
  96. temp |= PORT_TRANS_SEL_CPT(pipe);
  97. } else {
  98. if (pipe == 1) {
  99. temp |= LVDS_PIPEB_SELECT;
  100. } else {
  101. temp &= ~LVDS_PIPEB_SELECT;
  102. }
  103. }
  104. /* set the corresponsding LVDS_BORDER bit */
  105. temp |= dev_priv->lvds_border_bits;
  106. /* Set the B0-B3 data pairs corresponding to whether we're going to
  107. * set the DPLLs for dual-channel mode or not.
  108. */
  109. if (lvds_encoder->is_dual_link)
  110. temp |= LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP;
  111. else
  112. temp &= ~(LVDS_B0B3_POWER_UP | LVDS_CLKB_POWER_UP);
  113. /* It would be nice to set 24 vs 18-bit mode (LVDS_A3_POWER_UP)
  114. * appropriately here, but we need to look more thoroughly into how
  115. * panels behave in the two modes.
  116. */
  117. /* Set the dithering flag on LVDS as needed, note that there is no
  118. * special lvds dither control bit on pch-split platforms, dithering is
  119. * only controlled through the PIPECONF reg. */
  120. if (INTEL_INFO(dev)->gen == 4) {
  121. if (dev_priv->lvds_dither)
  122. temp |= LVDS_ENABLE_DITHER;
  123. else
  124. temp &= ~LVDS_ENABLE_DITHER;
  125. }
  126. temp &= ~(LVDS_HSYNC_POLARITY | LVDS_VSYNC_POLARITY);
  127. if (fixed_mode->flags & DRM_MODE_FLAG_NHSYNC)
  128. temp |= LVDS_HSYNC_POLARITY;
  129. if (fixed_mode->flags & DRM_MODE_FLAG_NVSYNC)
  130. temp |= LVDS_VSYNC_POLARITY;
  131. I915_WRITE(lvds_encoder->reg, temp);
  132. }
  133. /**
  134. * Sets the power state for the panel.
  135. */
  136. static void intel_enable_lvds(struct intel_encoder *encoder)
  137. {
  138. struct drm_device *dev = encoder->base.dev;
  139. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  140. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->base.crtc);
  141. struct drm_i915_private *dev_priv = dev->dev_private;
  142. u32 ctl_reg, stat_reg;
  143. if (HAS_PCH_SPLIT(dev)) {
  144. ctl_reg = PCH_PP_CONTROL;
  145. stat_reg = PCH_PP_STATUS;
  146. } else {
  147. ctl_reg = PP_CONTROL;
  148. stat_reg = PP_STATUS;
  149. }
  150. I915_WRITE(lvds_encoder->reg, I915_READ(lvds_encoder->reg) | LVDS_PORT_EN);
  151. if (lvds_encoder->pfit_dirty) {
  152. /*
  153. * Enable automatic panel scaling so that non-native modes
  154. * fill the screen. The panel fitter should only be
  155. * adjusted whilst the pipe is disabled, according to
  156. * register description and PRM.
  157. */
  158. DRM_DEBUG_KMS("applying panel-fitter: %x, %x\n",
  159. lvds_encoder->pfit_control,
  160. lvds_encoder->pfit_pgm_ratios);
  161. I915_WRITE(PFIT_PGM_RATIOS, lvds_encoder->pfit_pgm_ratios);
  162. I915_WRITE(PFIT_CONTROL, lvds_encoder->pfit_control);
  163. lvds_encoder->pfit_dirty = false;
  164. }
  165. I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
  166. POSTING_READ(lvds_encoder->reg);
  167. if (wait_for((I915_READ(stat_reg) & PP_ON) != 0, 1000))
  168. DRM_ERROR("timed out waiting for panel to power on\n");
  169. intel_panel_enable_backlight(dev, intel_crtc->pipe);
  170. }
  171. static void intel_disable_lvds(struct intel_encoder *encoder)
  172. {
  173. struct drm_device *dev = encoder->base.dev;
  174. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(&encoder->base);
  175. struct drm_i915_private *dev_priv = dev->dev_private;
  176. u32 ctl_reg, stat_reg;
  177. if (HAS_PCH_SPLIT(dev)) {
  178. ctl_reg = PCH_PP_CONTROL;
  179. stat_reg = PCH_PP_STATUS;
  180. } else {
  181. ctl_reg = PP_CONTROL;
  182. stat_reg = PP_STATUS;
  183. }
  184. intel_panel_disable_backlight(dev);
  185. I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
  186. if (wait_for((I915_READ(stat_reg) & PP_ON) == 0, 1000))
  187. DRM_ERROR("timed out waiting for panel to power off\n");
  188. if (lvds_encoder->pfit_control) {
  189. I915_WRITE(PFIT_CONTROL, 0);
  190. lvds_encoder->pfit_dirty = true;
  191. }
  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. mode->private_flags |= INTEL_MODE_CRTC_TIMINGS_SET;
  223. }
  224. static void
  225. centre_vertically(struct drm_display_mode *mode,
  226. int height)
  227. {
  228. u32 border, sync_pos, blank_width, sync_width;
  229. /* keep the vsync and vblank widths constant */
  230. sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;
  231. blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;
  232. sync_pos = (blank_width - sync_width + 1) / 2;
  233. border = (mode->vdisplay - height + 1) / 2;
  234. mode->crtc_vdisplay = height;
  235. mode->crtc_vblank_start = height + border;
  236. mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
  237. mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
  238. mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
  239. mode->private_flags |= INTEL_MODE_CRTC_TIMINGS_SET;
  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_mode_fixup(struct drm_encoder *encoder,
  254. const struct drm_display_mode *mode,
  255. struct drm_display_mode *adjusted_mode)
  256. {
  257. struct drm_device *dev = encoder->dev;
  258. struct drm_i915_private *dev_priv = dev->dev_private;
  259. struct intel_lvds_encoder *lvds_encoder = to_lvds_encoder(encoder);
  260. struct intel_connector *intel_connector =
  261. &lvds_encoder->attached_connector->base;
  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. switch (intel_connector->panel.fitting_mode) {
  304. case DRM_MODE_SCALE_CENTER:
  305. /*
  306. * For centered modes, we have to calculate border widths &
  307. * heights and modify the values programmed into the CRTC.
  308. */
  309. centre_horizontally(adjusted_mode, mode->hdisplay);
  310. centre_vertically(adjusted_mode, mode->vdisplay);
  311. border = LVDS_BORDER_ENABLE;
  312. break;
  313. case DRM_MODE_SCALE_ASPECT:
  314. /* Scale but preserve the aspect ratio */
  315. if (INTEL_INFO(dev)->gen >= 4) {
  316. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  317. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  318. /* 965+ is easy, it does everything in hw */
  319. if (scaled_width > scaled_height)
  320. pfit_control |= PFIT_ENABLE | PFIT_SCALING_PILLAR;
  321. else if (scaled_width < scaled_height)
  322. pfit_control |= PFIT_ENABLE | PFIT_SCALING_LETTER;
  323. else if (adjusted_mode->hdisplay != mode->hdisplay)
  324. pfit_control |= PFIT_ENABLE | PFIT_SCALING_AUTO;
  325. } else {
  326. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  327. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  328. /*
  329. * For earlier chips we have to calculate the scaling
  330. * ratio by hand and program it into the
  331. * PFIT_PGM_RATIO register
  332. */
  333. if (scaled_width > scaled_height) { /* pillar */
  334. centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay);
  335. border = LVDS_BORDER_ENABLE;
  336. if (mode->vdisplay != adjusted_mode->vdisplay) {
  337. u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay);
  338. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  339. bits << PFIT_VERT_SCALE_SHIFT);
  340. pfit_control |= (PFIT_ENABLE |
  341. VERT_INTERP_BILINEAR |
  342. HORIZ_INTERP_BILINEAR);
  343. }
  344. } else if (scaled_width < scaled_height) { /* letter */
  345. centre_vertically(adjusted_mode, scaled_width / mode->hdisplay);
  346. border = LVDS_BORDER_ENABLE;
  347. if (mode->hdisplay != adjusted_mode->hdisplay) {
  348. u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay);
  349. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  350. bits << PFIT_VERT_SCALE_SHIFT);
  351. pfit_control |= (PFIT_ENABLE |
  352. VERT_INTERP_BILINEAR |
  353. HORIZ_INTERP_BILINEAR);
  354. }
  355. } else
  356. /* Aspects match, Let hw scale both directions */
  357. pfit_control |= (PFIT_ENABLE |
  358. VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
  359. VERT_INTERP_BILINEAR |
  360. HORIZ_INTERP_BILINEAR);
  361. }
  362. break;
  363. case DRM_MODE_SCALE_FULLSCREEN:
  364. /*
  365. * Full scaling, even if it changes the aspect ratio.
  366. * Fortunately this is all done for us in hw.
  367. */
  368. if (mode->vdisplay != adjusted_mode->vdisplay ||
  369. mode->hdisplay != adjusted_mode->hdisplay) {
  370. pfit_control |= PFIT_ENABLE;
  371. if (INTEL_INFO(dev)->gen >= 4)
  372. pfit_control |= PFIT_SCALING_AUTO;
  373. else
  374. pfit_control |= (VERT_AUTO_SCALE |
  375. VERT_INTERP_BILINEAR |
  376. HORIZ_AUTO_SCALE |
  377. HORIZ_INTERP_BILINEAR);
  378. }
  379. break;
  380. default:
  381. break;
  382. }
  383. out:
  384. /* If not enabling scaling, be consistent and always use 0. */
  385. if ((pfit_control & PFIT_ENABLE) == 0) {
  386. pfit_control = 0;
  387. pfit_pgm_ratios = 0;
  388. }
  389. /* Make sure pre-965 set dither correctly */
  390. if (INTEL_INFO(dev)->gen < 4 && dev_priv->lvds_dither)
  391. pfit_control |= PANEL_8TO6_DITHER_ENABLE;
  392. if (pfit_control != lvds_encoder->pfit_control ||
  393. pfit_pgm_ratios != lvds_encoder->pfit_pgm_ratios) {
  394. lvds_encoder->pfit_control = pfit_control;
  395. lvds_encoder->pfit_pgm_ratios = pfit_pgm_ratios;
  396. lvds_encoder->pfit_dirty = true;
  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_on_lid':
  469. * - we set it on lid close, and reset it on open
  470. * - we use it as a "only once" bit (ie we ignore
  471. * duplicate events where it was already properly
  472. * set/reset)
  473. * - the suspend/resume paths will also set it to
  474. * zero, since they restore the mode ("lid open").
  475. */
  476. static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
  477. void *unused)
  478. {
  479. struct intel_lvds_connector *lvds_connector =
  480. container_of(nb, struct intel_lvds_connector, lid_notifier);
  481. struct drm_connector *connector = &lvds_connector->base.base;
  482. struct drm_device *dev = connector->dev;
  483. struct drm_i915_private *dev_priv = dev->dev_private;
  484. if (dev->switch_power_state != DRM_SWITCH_POWER_ON)
  485. return NOTIFY_OK;
  486. /*
  487. * check and update the status of LVDS connector after receiving
  488. * the LID nofication event.
  489. */
  490. connector->status = connector->funcs->detect(connector, false);
  491. /* Don't force modeset on machines where it causes a GPU lockup */
  492. if (dmi_check_system(intel_no_modeset_on_lid))
  493. return NOTIFY_OK;
  494. if (!acpi_lid_open()) {
  495. dev_priv->modeset_on_lid = 1;
  496. return NOTIFY_OK;
  497. }
  498. if (!dev_priv->modeset_on_lid)
  499. return NOTIFY_OK;
  500. dev_priv->modeset_on_lid = 0;
  501. mutex_lock(&dev->mode_config.mutex);
  502. intel_modeset_setup_hw_state(dev, true);
  503. mutex_unlock(&dev->mode_config.mutex);
  504. return NOTIFY_OK;
  505. }
  506. /**
  507. * intel_lvds_destroy - unregister and free LVDS structures
  508. * @connector: connector to free
  509. *
  510. * Unregister the DDC bus for this connector then free the driver private
  511. * structure.
  512. */
  513. static void intel_lvds_destroy(struct drm_connector *connector)
  514. {
  515. struct intel_lvds_connector *lvds_connector =
  516. to_lvds_connector(connector);
  517. if (lvds_connector->lid_notifier.notifier_call)
  518. acpi_lid_notifier_unregister(&lvds_connector->lid_notifier);
  519. if (!IS_ERR_OR_NULL(lvds_connector->base.edid))
  520. kfree(lvds_connector->base.edid);
  521. intel_panel_destroy_backlight(connector->dev);
  522. intel_panel_fini(&lvds_connector->base.panel);
  523. drm_sysfs_connector_remove(connector);
  524. drm_connector_cleanup(connector);
  525. kfree(connector);
  526. }
  527. static int intel_lvds_set_property(struct drm_connector *connector,
  528. struct drm_property *property,
  529. uint64_t value)
  530. {
  531. struct intel_connector *intel_connector = to_intel_connector(connector);
  532. struct drm_device *dev = connector->dev;
  533. if (property == dev->mode_config.scaling_mode_property) {
  534. struct drm_crtc *crtc;
  535. if (value == DRM_MODE_SCALE_NONE) {
  536. DRM_DEBUG_KMS("no scaling not supported\n");
  537. return -EINVAL;
  538. }
  539. if (intel_connector->panel.fitting_mode == value) {
  540. /* the LVDS scaling property is not changed */
  541. return 0;
  542. }
  543. intel_connector->panel.fitting_mode = value;
  544. crtc = intel_attached_encoder(connector)->base.crtc;
  545. if (crtc && crtc->enabled) {
  546. /*
  547. * If the CRTC is enabled, the display will be changed
  548. * according to the new panel fitting mode.
  549. */
  550. intel_set_mode(crtc, &crtc->mode,
  551. crtc->x, crtc->y, crtc->fb);
  552. }
  553. }
  554. return 0;
  555. }
  556. static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
  557. .mode_fixup = intel_lvds_mode_fixup,
  558. .mode_set = intel_lvds_mode_set,
  559. .disable = intel_encoder_noop,
  560. };
  561. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  562. .get_modes = intel_lvds_get_modes,
  563. .mode_valid = intel_lvds_mode_valid,
  564. .best_encoder = intel_best_encoder,
  565. };
  566. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  567. .dpms = intel_connector_dpms,
  568. .detect = intel_lvds_detect,
  569. .fill_modes = drm_helper_probe_single_connector_modes,
  570. .set_property = intel_lvds_set_property,
  571. .destroy = intel_lvds_destroy,
  572. };
  573. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  574. .destroy = intel_encoder_destroy,
  575. };
  576. static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  577. {
  578. DRM_INFO("Skipping LVDS initialization for %s\n", id->ident);
  579. return 1;
  580. }
  581. /* These systems claim to have LVDS, but really don't */
  582. static const struct dmi_system_id intel_no_lvds[] = {
  583. {
  584. .callback = intel_no_lvds_dmi_callback,
  585. .ident = "Apple Mac Mini (Core series)",
  586. .matches = {
  587. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  588. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  589. },
  590. },
  591. {
  592. .callback = intel_no_lvds_dmi_callback,
  593. .ident = "Apple Mac Mini (Core 2 series)",
  594. .matches = {
  595. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  596. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  597. },
  598. },
  599. {
  600. .callback = intel_no_lvds_dmi_callback,
  601. .ident = "MSI IM-945GSE-A",
  602. .matches = {
  603. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  604. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  605. },
  606. },
  607. {
  608. .callback = intel_no_lvds_dmi_callback,
  609. .ident = "Dell Studio Hybrid",
  610. .matches = {
  611. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  612. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  613. },
  614. },
  615. {
  616. .callback = intel_no_lvds_dmi_callback,
  617. .ident = "Dell OptiPlex FX170",
  618. .matches = {
  619. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  620. DMI_MATCH(DMI_PRODUCT_NAME, "OptiPlex FX170"),
  621. },
  622. },
  623. {
  624. .callback = intel_no_lvds_dmi_callback,
  625. .ident = "AOpen Mini PC",
  626. .matches = {
  627. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  628. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  629. },
  630. },
  631. {
  632. .callback = intel_no_lvds_dmi_callback,
  633. .ident = "AOpen Mini PC MP915",
  634. .matches = {
  635. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  636. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  637. },
  638. },
  639. {
  640. .callback = intel_no_lvds_dmi_callback,
  641. .ident = "AOpen i915GMm-HFS",
  642. .matches = {
  643. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  644. DMI_MATCH(DMI_BOARD_NAME, "i915GMm-HFS"),
  645. },
  646. },
  647. {
  648. .callback = intel_no_lvds_dmi_callback,
  649. .ident = "AOpen i45GMx-I",
  650. .matches = {
  651. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  652. DMI_MATCH(DMI_BOARD_NAME, "i45GMx-I"),
  653. },
  654. },
  655. {
  656. .callback = intel_no_lvds_dmi_callback,
  657. .ident = "Aopen i945GTt-VFA",
  658. .matches = {
  659. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  660. },
  661. },
  662. {
  663. .callback = intel_no_lvds_dmi_callback,
  664. .ident = "Clientron U800",
  665. .matches = {
  666. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  667. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  668. },
  669. },
  670. {
  671. .callback = intel_no_lvds_dmi_callback,
  672. .ident = "Clientron E830",
  673. .matches = {
  674. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  675. DMI_MATCH(DMI_PRODUCT_NAME, "E830"),
  676. },
  677. },
  678. {
  679. .callback = intel_no_lvds_dmi_callback,
  680. .ident = "Asus EeeBox PC EB1007",
  681. .matches = {
  682. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  683. DMI_MATCH(DMI_PRODUCT_NAME, "EB1007"),
  684. },
  685. },
  686. {
  687. .callback = intel_no_lvds_dmi_callback,
  688. .ident = "Asus AT5NM10T-I",
  689. .matches = {
  690. DMI_MATCH(DMI_BOARD_VENDOR, "ASUSTeK Computer INC."),
  691. DMI_MATCH(DMI_BOARD_NAME, "AT5NM10T-I"),
  692. },
  693. },
  694. {
  695. .callback = intel_no_lvds_dmi_callback,
  696. .ident = "Hewlett-Packard HP t5740e Thin Client",
  697. .matches = {
  698. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  699. DMI_MATCH(DMI_PRODUCT_NAME, "HP t5740e Thin Client"),
  700. },
  701. },
  702. {
  703. .callback = intel_no_lvds_dmi_callback,
  704. .ident = "Hewlett-Packard t5745",
  705. .matches = {
  706. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  707. DMI_MATCH(DMI_PRODUCT_NAME, "hp t5745"),
  708. },
  709. },
  710. {
  711. .callback = intel_no_lvds_dmi_callback,
  712. .ident = "Hewlett-Packard st5747",
  713. .matches = {
  714. DMI_MATCH(DMI_BOARD_VENDOR, "Hewlett-Packard"),
  715. DMI_MATCH(DMI_PRODUCT_NAME, "hp st5747"),
  716. },
  717. },
  718. {
  719. .callback = intel_no_lvds_dmi_callback,
  720. .ident = "MSI Wind Box DC500",
  721. .matches = {
  722. DMI_MATCH(DMI_BOARD_VENDOR, "MICRO-STAR INTERNATIONAL CO., LTD"),
  723. DMI_MATCH(DMI_BOARD_NAME, "MS-7469"),
  724. },
  725. },
  726. {
  727. .callback = intel_no_lvds_dmi_callback,
  728. .ident = "ZOTAC ZBOXSD-ID12/ID13",
  729. .matches = {
  730. DMI_MATCH(DMI_BOARD_VENDOR, "ZOTAC"),
  731. DMI_MATCH(DMI_BOARD_NAME, "ZBOXSD-ID12/ID13"),
  732. },
  733. },
  734. {
  735. .callback = intel_no_lvds_dmi_callback,
  736. .ident = "Gigabyte GA-D525TUD",
  737. .matches = {
  738. DMI_MATCH(DMI_BOARD_VENDOR, "Gigabyte Technology Co., Ltd."),
  739. DMI_MATCH(DMI_BOARD_NAME, "D525TUD"),
  740. },
  741. },
  742. {
  743. .callback = intel_no_lvds_dmi_callback,
  744. .ident = "Supermicro X7SPA-H",
  745. .matches = {
  746. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  747. DMI_MATCH(DMI_PRODUCT_NAME, "X7SPA-H"),
  748. },
  749. },
  750. { } /* terminating entry */
  751. };
  752. /**
  753. * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
  754. * @dev: drm device
  755. * @connector: LVDS connector
  756. *
  757. * Find the reduced downclock for LVDS in EDID.
  758. */
  759. static void intel_find_lvds_downclock(struct drm_device *dev,
  760. struct drm_display_mode *fixed_mode,
  761. struct drm_connector *connector)
  762. {
  763. struct drm_i915_private *dev_priv = dev->dev_private;
  764. struct drm_display_mode *scan;
  765. int temp_downclock;
  766. temp_downclock = fixed_mode->clock;
  767. list_for_each_entry(scan, &connector->probed_modes, head) {
  768. /*
  769. * If one mode has the same resolution with the fixed_panel
  770. * mode while they have the different refresh rate, it means
  771. * that the reduced downclock is found for the LVDS. In such
  772. * case we can set the different FPx0/1 to dynamically select
  773. * between low and high frequency.
  774. */
  775. if (scan->hdisplay == fixed_mode->hdisplay &&
  776. scan->hsync_start == fixed_mode->hsync_start &&
  777. scan->hsync_end == fixed_mode->hsync_end &&
  778. scan->htotal == fixed_mode->htotal &&
  779. scan->vdisplay == fixed_mode->vdisplay &&
  780. scan->vsync_start == fixed_mode->vsync_start &&
  781. scan->vsync_end == fixed_mode->vsync_end &&
  782. scan->vtotal == fixed_mode->vtotal) {
  783. if (scan->clock < temp_downclock) {
  784. /*
  785. * The downclock is already found. But we
  786. * expect to find the lower downclock.
  787. */
  788. temp_downclock = scan->clock;
  789. }
  790. }
  791. }
  792. if (temp_downclock < fixed_mode->clock && i915_lvds_downclock) {
  793. /* We found the downclock for LVDS. */
  794. dev_priv->lvds_downclock_avail = 1;
  795. dev_priv->lvds_downclock = temp_downclock;
  796. DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
  797. "Normal clock %dKhz, downclock %dKhz\n",
  798. fixed_mode->clock, temp_downclock);
  799. }
  800. }
  801. /*
  802. * Enumerate the child dev array parsed from VBT to check whether
  803. * the LVDS is present.
  804. * If it is present, return 1.
  805. * If it is not present, return false.
  806. * If no child dev is parsed from VBT, it assumes that the LVDS is present.
  807. */
  808. static bool lvds_is_present_in_vbt(struct drm_device *dev,
  809. u8 *i2c_pin)
  810. {
  811. struct drm_i915_private *dev_priv = dev->dev_private;
  812. int i;
  813. if (!dev_priv->child_dev_num)
  814. return true;
  815. for (i = 0; i < dev_priv->child_dev_num; i++) {
  816. struct child_device_config *child = dev_priv->child_dev + i;
  817. /* If the device type is not LFP, continue.
  818. * We have to check both the new identifiers as well as the
  819. * old for compatibility with some BIOSes.
  820. */
  821. if (child->device_type != DEVICE_TYPE_INT_LFP &&
  822. child->device_type != DEVICE_TYPE_LFP)
  823. continue;
  824. if (intel_gmbus_is_port_valid(child->i2c_pin))
  825. *i2c_pin = child->i2c_pin;
  826. /* However, we cannot trust the BIOS writers to populate
  827. * the VBT correctly. Since LVDS requires additional
  828. * information from AIM blocks, a non-zero addin offset is
  829. * a good indicator that the LVDS is actually present.
  830. */
  831. if (child->addin_offset)
  832. return true;
  833. /* But even then some BIOS writers perform some black magic
  834. * and instantiate the device without reference to any
  835. * additional data. Trust that if the VBT was written into
  836. * the OpRegion then they have validated the LVDS's existence.
  837. */
  838. if (dev_priv->opregion.vbt)
  839. return true;
  840. }
  841. return false;
  842. }
  843. static int intel_dual_link_lvds_callback(const struct dmi_system_id *id)
  844. {
  845. DRM_INFO("Forcing lvds to dual link mode on %s\n", id->ident);
  846. return 1;
  847. }
  848. static const struct dmi_system_id intel_dual_link_lvds[] = {
  849. {
  850. .callback = intel_dual_link_lvds_callback,
  851. .ident = "Apple MacBook Pro (Core i5/i7 Series)",
  852. .matches = {
  853. DMI_MATCH(DMI_SYS_VENDOR, "Apple Inc."),
  854. DMI_MATCH(DMI_PRODUCT_NAME, "MacBookPro8,2"),
  855. },
  856. },
  857. { } /* terminating entry */
  858. };
  859. bool intel_is_dual_link_lvds(struct drm_device *dev)
  860. {
  861. struct intel_encoder *encoder;
  862. struct intel_lvds_encoder *lvds_encoder;
  863. list_for_each_entry(encoder, &dev->mode_config.encoder_list,
  864. base.head) {
  865. if (encoder->type == INTEL_OUTPUT_LVDS) {
  866. lvds_encoder = to_lvds_encoder(&encoder->base);
  867. return lvds_encoder->is_dual_link;
  868. }
  869. }
  870. return false;
  871. }
  872. static bool compute_is_dual_link_lvds(struct intel_lvds_encoder *lvds_encoder)
  873. {
  874. struct drm_device *dev = lvds_encoder->base.base.dev;
  875. unsigned int val;
  876. struct drm_i915_private *dev_priv = dev->dev_private;
  877. /* use the module option value if specified */
  878. if (i915_lvds_channel_mode > 0)
  879. return i915_lvds_channel_mode == 2;
  880. if (dmi_check_system(intel_dual_link_lvds))
  881. return true;
  882. /* BIOS should set the proper LVDS register value at boot, but
  883. * in reality, it doesn't set the value when the lid is closed;
  884. * we need to check "the value to be set" in VBT when LVDS
  885. * register is uninitialized.
  886. */
  887. val = I915_READ(lvds_encoder->reg);
  888. if (!(val & ~(LVDS_PIPE_MASK | LVDS_DETECTED)))
  889. val = dev_priv->bios_lvds_val;
  890. return (val & LVDS_CLKB_POWER_MASK) == LVDS_CLKB_POWER_UP;
  891. }
  892. static bool intel_lvds_supported(struct drm_device *dev)
  893. {
  894. /* With the introduction of the PCH we gained a dedicated
  895. * LVDS presence pin, use it. */
  896. if (HAS_PCH_SPLIT(dev))
  897. return true;
  898. /* Otherwise LVDS was only attached to mobile products,
  899. * except for the inglorious 830gm */
  900. return IS_MOBILE(dev) && !IS_I830(dev);
  901. }
  902. /**
  903. * intel_lvds_init - setup LVDS connectors on this device
  904. * @dev: drm device
  905. *
  906. * Create the connector, register the LVDS DDC bus, and try to figure out what
  907. * modes we can display on the LVDS panel (if present).
  908. */
  909. bool intel_lvds_init(struct drm_device *dev)
  910. {
  911. struct drm_i915_private *dev_priv = dev->dev_private;
  912. struct intel_lvds_encoder *lvds_encoder;
  913. struct intel_encoder *intel_encoder;
  914. struct intel_lvds_connector *lvds_connector;
  915. struct intel_connector *intel_connector;
  916. struct drm_connector *connector;
  917. struct drm_encoder *encoder;
  918. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  919. struct drm_display_mode *fixed_mode = NULL;
  920. struct edid *edid;
  921. struct drm_crtc *crtc;
  922. u32 lvds;
  923. int pipe;
  924. u8 pin;
  925. if (!intel_lvds_supported(dev))
  926. return false;
  927. /* Skip init on machines we know falsely report LVDS */
  928. if (dmi_check_system(intel_no_lvds))
  929. return false;
  930. pin = GMBUS_PORT_PANEL;
  931. if (!lvds_is_present_in_vbt(dev, &pin)) {
  932. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  933. return false;
  934. }
  935. if (HAS_PCH_SPLIT(dev)) {
  936. if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
  937. return false;
  938. if (dev_priv->edp.support) {
  939. DRM_DEBUG_KMS("disable LVDS for eDP support\n");
  940. return false;
  941. }
  942. }
  943. lvds_encoder = kzalloc(sizeof(struct intel_lvds_encoder), GFP_KERNEL);
  944. if (!lvds_encoder)
  945. return false;
  946. lvds_connector = kzalloc(sizeof(struct intel_lvds_connector), GFP_KERNEL);
  947. if (!lvds_connector) {
  948. kfree(lvds_encoder);
  949. return false;
  950. }
  951. lvds_encoder->attached_connector = lvds_connector;
  952. if (!HAS_PCH_SPLIT(dev)) {
  953. lvds_encoder->pfit_control = I915_READ(PFIT_CONTROL);
  954. }
  955. intel_encoder = &lvds_encoder->base;
  956. encoder = &intel_encoder->base;
  957. intel_connector = &lvds_connector->base;
  958. connector = &intel_connector->base;
  959. drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
  960. DRM_MODE_CONNECTOR_LVDS);
  961. drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
  962. DRM_MODE_ENCODER_LVDS);
  963. intel_encoder->enable = intel_enable_lvds;
  964. intel_encoder->pre_pll_enable = intel_pre_pll_enable_lvds;
  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. }