intel_lvds.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  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 "drmP.h"
  34. #include "drm.h"
  35. #include "drm_crtc.h"
  36. #include "drm_edid.h"
  37. #include "intel_drv.h"
  38. #include "i915_drm.h"
  39. #include "i915_drv.h"
  40. #include <linux/acpi.h>
  41. /* Private structure for the integrated LVDS support */
  42. struct intel_lvds {
  43. struct intel_encoder base;
  44. int fitting_mode;
  45. u32 pfit_control;
  46. u32 pfit_pgm_ratios;
  47. bool pfit_dirty;
  48. };
  49. static struct intel_lvds *enc_to_intel_lvds(struct drm_encoder *encoder)
  50. {
  51. return container_of(encoder, struct intel_lvds, base.base);
  52. }
  53. /**
  54. * Sets the power state for the panel.
  55. */
  56. static void intel_lvds_set_power(struct intel_lvds *intel_lvds, bool on)
  57. {
  58. struct drm_device *dev = intel_lvds->base.base.dev;
  59. struct drm_i915_private *dev_priv = dev->dev_private;
  60. u32 ctl_reg, lvds_reg;
  61. if (HAS_PCH_SPLIT(dev)) {
  62. ctl_reg = PCH_PP_CONTROL;
  63. lvds_reg = PCH_LVDS;
  64. } else {
  65. ctl_reg = PP_CONTROL;
  66. lvds_reg = LVDS;
  67. }
  68. if (on) {
  69. I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN);
  70. I915_WRITE(ctl_reg, I915_READ(ctl_reg) | POWER_TARGET_ON);
  71. intel_panel_set_backlight(dev, dev_priv->backlight_level);
  72. } else {
  73. dev_priv->backlight_level = intel_panel_get_backlight(dev);
  74. intel_panel_set_backlight(dev, 0);
  75. I915_WRITE(ctl_reg, I915_READ(ctl_reg) & ~POWER_TARGET_ON);
  76. if (intel_lvds->pfit_control) {
  77. if (wait_for((I915_READ(PP_STATUS) & PP_ON) == 0, 1000))
  78. DRM_ERROR("timed out waiting for panel to power off\n");
  79. I915_WRITE(PFIT_CONTROL, 0);
  80. intel_lvds->pfit_control = 0;
  81. }
  82. I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN);
  83. }
  84. POSTING_READ(lvds_reg);
  85. }
  86. static void intel_lvds_dpms(struct drm_encoder *encoder, int mode)
  87. {
  88. struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
  89. if (mode == DRM_MODE_DPMS_ON)
  90. intel_lvds_set_power(intel_lvds, true);
  91. else
  92. intel_lvds_set_power(intel_lvds, false);
  93. /* XXX: We never power down the LVDS pairs. */
  94. }
  95. static int intel_lvds_mode_valid(struct drm_connector *connector,
  96. struct drm_display_mode *mode)
  97. {
  98. struct drm_device *dev = connector->dev;
  99. struct drm_i915_private *dev_priv = dev->dev_private;
  100. struct drm_display_mode *fixed_mode = dev_priv->panel_fixed_mode;
  101. if (fixed_mode) {
  102. if (mode->hdisplay > fixed_mode->hdisplay)
  103. return MODE_PANEL;
  104. if (mode->vdisplay > fixed_mode->vdisplay)
  105. return MODE_PANEL;
  106. }
  107. return MODE_OK;
  108. }
  109. static void
  110. centre_horizontally(struct drm_display_mode *mode,
  111. int width)
  112. {
  113. u32 border, sync_pos, blank_width, sync_width;
  114. /* keep the hsync and hblank widths constant */
  115. sync_width = mode->crtc_hsync_end - mode->crtc_hsync_start;
  116. blank_width = mode->crtc_hblank_end - mode->crtc_hblank_start;
  117. sync_pos = (blank_width - sync_width + 1) / 2;
  118. border = (mode->hdisplay - width + 1) / 2;
  119. border += border & 1; /* make the border even */
  120. mode->crtc_hdisplay = width;
  121. mode->crtc_hblank_start = width + border;
  122. mode->crtc_hblank_end = mode->crtc_hblank_start + blank_width;
  123. mode->crtc_hsync_start = mode->crtc_hblank_start + sync_pos;
  124. mode->crtc_hsync_end = mode->crtc_hsync_start + sync_width;
  125. }
  126. static void
  127. centre_vertically(struct drm_display_mode *mode,
  128. int height)
  129. {
  130. u32 border, sync_pos, blank_width, sync_width;
  131. /* keep the vsync and vblank widths constant */
  132. sync_width = mode->crtc_vsync_end - mode->crtc_vsync_start;
  133. blank_width = mode->crtc_vblank_end - mode->crtc_vblank_start;
  134. sync_pos = (blank_width - sync_width + 1) / 2;
  135. border = (mode->vdisplay - height + 1) / 2;
  136. mode->crtc_vdisplay = height;
  137. mode->crtc_vblank_start = height + border;
  138. mode->crtc_vblank_end = mode->crtc_vblank_start + blank_width;
  139. mode->crtc_vsync_start = mode->crtc_vblank_start + sync_pos;
  140. mode->crtc_vsync_end = mode->crtc_vsync_start + sync_width;
  141. }
  142. static inline u32 panel_fitter_scaling(u32 source, u32 target)
  143. {
  144. /*
  145. * Floating point operation is not supported. So the FACTOR
  146. * is defined, which can avoid the floating point computation
  147. * when calculating the panel ratio.
  148. */
  149. #define ACCURACY 12
  150. #define FACTOR (1 << ACCURACY)
  151. u32 ratio = source * FACTOR / target;
  152. return (FACTOR * ratio + FACTOR/2) / FACTOR;
  153. }
  154. static bool intel_lvds_mode_fixup(struct drm_encoder *encoder,
  155. struct drm_display_mode *mode,
  156. struct drm_display_mode *adjusted_mode)
  157. {
  158. struct drm_device *dev = encoder->dev;
  159. struct drm_i915_private *dev_priv = dev->dev_private;
  160. struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc);
  161. struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
  162. struct drm_encoder *tmp_encoder;
  163. u32 pfit_control = 0, pfit_pgm_ratios = 0, border = 0;
  164. /* Should never happen!! */
  165. if (!IS_I965G(dev) && intel_crtc->pipe == 0) {
  166. DRM_ERROR("Can't support LVDS on pipe A\n");
  167. return false;
  168. }
  169. /* Should never happen!! */
  170. list_for_each_entry(tmp_encoder, &dev->mode_config.encoder_list, head) {
  171. if (tmp_encoder != encoder && tmp_encoder->crtc == encoder->crtc) {
  172. DRM_ERROR("Can't enable LVDS and another "
  173. "encoder on the same pipe\n");
  174. return false;
  175. }
  176. }
  177. /* If we don't have a panel mode, there is nothing we can do */
  178. if (dev_priv->panel_fixed_mode == NULL)
  179. return true;
  180. /*
  181. * We have timings from the BIOS for the panel, put them in
  182. * to the adjusted mode. The CRTC will be set up for this mode,
  183. * with the panel scaling set up to source from the H/VDisplay
  184. * of the original mode.
  185. */
  186. intel_fixed_panel_mode(dev_priv->panel_fixed_mode, adjusted_mode);
  187. if (HAS_PCH_SPLIT(dev)) {
  188. intel_pch_panel_fitting(dev, intel_lvds->fitting_mode,
  189. mode, adjusted_mode);
  190. return true;
  191. }
  192. /* Make sure pre-965s set dither correctly */
  193. if (!IS_I965G(dev)) {
  194. if (dev_priv->panel_wants_dither || dev_priv->lvds_dither)
  195. pfit_control |= PANEL_8TO6_DITHER_ENABLE;
  196. }
  197. /* Native modes don't need fitting */
  198. if (adjusted_mode->hdisplay == mode->hdisplay &&
  199. adjusted_mode->vdisplay == mode->vdisplay)
  200. goto out;
  201. /* 965+ wants fuzzy fitting */
  202. if (IS_I965G(dev))
  203. pfit_control |= ((intel_crtc->pipe << PFIT_PIPE_SHIFT) |
  204. PFIT_FILTER_FUZZY);
  205. /*
  206. * Enable automatic panel scaling for non-native modes so that they fill
  207. * the screen. Should be enabled before the pipe is enabled, according
  208. * to register description and PRM.
  209. * Change the value here to see the borders for debugging
  210. */
  211. I915_WRITE(BCLRPAT_A, 0);
  212. I915_WRITE(BCLRPAT_B, 0);
  213. switch (intel_lvds->fitting_mode) {
  214. case DRM_MODE_SCALE_CENTER:
  215. /*
  216. * For centered modes, we have to calculate border widths &
  217. * heights and modify the values programmed into the CRTC.
  218. */
  219. centre_horizontally(adjusted_mode, mode->hdisplay);
  220. centre_vertically(adjusted_mode, mode->vdisplay);
  221. border = LVDS_BORDER_ENABLE;
  222. break;
  223. case DRM_MODE_SCALE_ASPECT:
  224. /* Scale but preserve the aspect ratio */
  225. if (IS_I965G(dev)) {
  226. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  227. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  228. pfit_control |= PFIT_ENABLE;
  229. /* 965+ is easy, it does everything in hw */
  230. if (scaled_width > scaled_height)
  231. pfit_control |= PFIT_SCALING_PILLAR;
  232. else if (scaled_width < scaled_height)
  233. pfit_control |= PFIT_SCALING_LETTER;
  234. else
  235. pfit_control |= PFIT_SCALING_AUTO;
  236. } else {
  237. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  238. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  239. /*
  240. * For earlier chips we have to calculate the scaling
  241. * ratio by hand and program it into the
  242. * PFIT_PGM_RATIO register
  243. */
  244. if (scaled_width > scaled_height) { /* pillar */
  245. centre_horizontally(adjusted_mode, scaled_height / mode->vdisplay);
  246. border = LVDS_BORDER_ENABLE;
  247. if (mode->vdisplay != adjusted_mode->vdisplay) {
  248. u32 bits = panel_fitter_scaling(mode->vdisplay, adjusted_mode->vdisplay);
  249. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  250. bits << PFIT_VERT_SCALE_SHIFT);
  251. pfit_control |= (PFIT_ENABLE |
  252. VERT_INTERP_BILINEAR |
  253. HORIZ_INTERP_BILINEAR);
  254. }
  255. } else if (scaled_width < scaled_height) { /* letter */
  256. centre_vertically(adjusted_mode, scaled_width / mode->hdisplay);
  257. border = LVDS_BORDER_ENABLE;
  258. if (mode->hdisplay != adjusted_mode->hdisplay) {
  259. u32 bits = panel_fitter_scaling(mode->hdisplay, adjusted_mode->hdisplay);
  260. pfit_pgm_ratios |= (bits << PFIT_HORIZ_SCALE_SHIFT |
  261. bits << PFIT_VERT_SCALE_SHIFT);
  262. pfit_control |= (PFIT_ENABLE |
  263. VERT_INTERP_BILINEAR |
  264. HORIZ_INTERP_BILINEAR);
  265. }
  266. } else
  267. /* Aspects match, Let hw scale both directions */
  268. pfit_control |= (PFIT_ENABLE |
  269. VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
  270. VERT_INTERP_BILINEAR |
  271. HORIZ_INTERP_BILINEAR);
  272. }
  273. break;
  274. case DRM_MODE_SCALE_FULLSCREEN:
  275. /*
  276. * Full scaling, even if it changes the aspect ratio.
  277. * Fortunately this is all done for us in hw.
  278. */
  279. pfit_control |= PFIT_ENABLE;
  280. if (IS_I965G(dev))
  281. pfit_control |= PFIT_SCALING_AUTO;
  282. else
  283. pfit_control |= (VERT_AUTO_SCALE | HORIZ_AUTO_SCALE |
  284. VERT_INTERP_BILINEAR |
  285. HORIZ_INTERP_BILINEAR);
  286. break;
  287. default:
  288. break;
  289. }
  290. out:
  291. if (pfit_control != intel_lvds->pfit_control ||
  292. pfit_pgm_ratios != intel_lvds->pfit_pgm_ratios) {
  293. intel_lvds->pfit_control = pfit_control;
  294. intel_lvds->pfit_pgm_ratios = pfit_pgm_ratios;
  295. intel_lvds->pfit_dirty = true;
  296. }
  297. dev_priv->lvds_border_bits = border;
  298. /*
  299. * XXX: It would be nice to support lower refresh rates on the
  300. * panels to reduce power consumption, and perhaps match the
  301. * user's requested refresh rate.
  302. */
  303. return true;
  304. }
  305. static void intel_lvds_prepare(struct drm_encoder *encoder)
  306. {
  307. struct drm_device *dev = encoder->dev;
  308. struct drm_i915_private *dev_priv = dev->dev_private;
  309. struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
  310. dev_priv->backlight_level = intel_panel_get_backlight(dev);
  311. /* We try to do the minimum that is necessary in order to unlock
  312. * the registers for mode setting.
  313. *
  314. * On Ironlake, this is quite simple as we just set the unlock key
  315. * and ignore all subtleties. (This may cause some issues...)
  316. *
  317. * Prior to Ironlake, we must disable the pipe if we want to adjust
  318. * the panel fitter. However at all other times we can just reset
  319. * the registers regardless.
  320. */
  321. if (HAS_PCH_SPLIT(dev)) {
  322. I915_WRITE(PCH_PP_CONTROL,
  323. I915_READ(PCH_PP_CONTROL) | PANEL_UNLOCK_REGS);
  324. } else if (intel_lvds->pfit_dirty) {
  325. I915_WRITE(PP_CONTROL,
  326. I915_READ(PP_CONTROL) & ~POWER_TARGET_ON);
  327. I915_WRITE(LVDS, I915_READ(LVDS) & ~LVDS_PORT_EN);
  328. } else {
  329. I915_WRITE(PP_CONTROL,
  330. I915_READ(PP_CONTROL) | PANEL_UNLOCK_REGS);
  331. }
  332. }
  333. static void intel_lvds_commit(struct drm_encoder *encoder)
  334. {
  335. struct drm_device *dev = encoder->dev;
  336. struct drm_i915_private *dev_priv = dev->dev_private;
  337. struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
  338. if (dev_priv->backlight_level == 0)
  339. dev_priv->backlight_level = intel_panel_get_max_backlight(dev);
  340. /* Undo any unlocking done in prepare to prevent accidental
  341. * adjustment of the registers.
  342. */
  343. if (HAS_PCH_SPLIT(dev)) {
  344. u32 val = I915_READ(PCH_PP_CONTROL);
  345. if ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS)
  346. I915_WRITE(PCH_PP_CONTROL, val & 0x3);
  347. } else {
  348. u32 val = I915_READ(PP_CONTROL);
  349. if ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS)
  350. I915_WRITE(PP_CONTROL, val & 0x3);
  351. }
  352. /* Always do a full power on as we do not know what state
  353. * we were left in.
  354. */
  355. intel_lvds_set_power(intel_lvds, true);
  356. }
  357. static void intel_lvds_mode_set(struct drm_encoder *encoder,
  358. struct drm_display_mode *mode,
  359. struct drm_display_mode *adjusted_mode)
  360. {
  361. struct drm_device *dev = encoder->dev;
  362. struct drm_i915_private *dev_priv = dev->dev_private;
  363. struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
  364. /*
  365. * The LVDS pin pair will already have been turned on in the
  366. * intel_crtc_mode_set since it has a large impact on the DPLL
  367. * settings.
  368. */
  369. if (HAS_PCH_SPLIT(dev))
  370. return;
  371. if (!intel_lvds->pfit_dirty)
  372. return;
  373. /*
  374. * Enable automatic panel scaling so that non-native modes fill the
  375. * screen. Should be enabled before the pipe is enabled, according to
  376. * register description and PRM.
  377. */
  378. if (wait_for((I915_READ(PP_STATUS) & PP_ON) == 0, 1000))
  379. DRM_ERROR("timed out waiting for panel to power off\n");
  380. I915_WRITE(PFIT_PGM_RATIOS, intel_lvds->pfit_pgm_ratios);
  381. I915_WRITE(PFIT_CONTROL, intel_lvds->pfit_control);
  382. intel_lvds->pfit_dirty = false;
  383. }
  384. /**
  385. * Detect the LVDS connection.
  386. *
  387. * Since LVDS doesn't have hotlug, we use the lid as a proxy. Open means
  388. * connected and closed means disconnected. We also send hotplug events as
  389. * needed, using lid status notification from the input layer.
  390. */
  391. static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector)
  392. {
  393. struct drm_device *dev = connector->dev;
  394. enum drm_connector_status status = connector_status_connected;
  395. /* ACPI lid methods were generally unreliable in this generation, so
  396. * don't even bother.
  397. */
  398. if (IS_GEN2(dev) || IS_GEN3(dev))
  399. return connector_status_connected;
  400. return status;
  401. }
  402. /**
  403. * Return the list of DDC modes if available, or the BIOS fixed mode otherwise.
  404. */
  405. static int intel_lvds_get_modes(struct drm_connector *connector)
  406. {
  407. struct drm_device *dev = connector->dev;
  408. struct drm_i915_private *dev_priv = dev->dev_private;
  409. if (dev_priv->lvds_edid_good) {
  410. struct intel_encoder *encoder = intel_attached_encoder(connector);
  411. int ret = intel_ddc_get_modes(connector, encoder->ddc_bus);
  412. if (ret)
  413. return ret;
  414. }
  415. /* Didn't get an EDID, so
  416. * Set wide sync ranges so we get all modes
  417. * handed to valid_mode for checking
  418. */
  419. connector->display_info.min_vfreq = 0;
  420. connector->display_info.max_vfreq = 200;
  421. connector->display_info.min_hfreq = 0;
  422. connector->display_info.max_hfreq = 200;
  423. if (dev_priv->panel_fixed_mode != NULL) {
  424. struct drm_display_mode *mode;
  425. mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode);
  426. drm_mode_probed_add(connector, mode);
  427. return 1;
  428. }
  429. return 0;
  430. }
  431. static int intel_no_modeset_on_lid_dmi_callback(const struct dmi_system_id *id)
  432. {
  433. DRM_DEBUG_KMS("Skipping forced modeset for %s\n", id->ident);
  434. return 1;
  435. }
  436. /* The GPU hangs up on these systems if modeset is performed on LID open */
  437. static const struct dmi_system_id intel_no_modeset_on_lid[] = {
  438. {
  439. .callback = intel_no_modeset_on_lid_dmi_callback,
  440. .ident = "Toshiba Tecra A11",
  441. .matches = {
  442. DMI_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
  443. DMI_MATCH(DMI_PRODUCT_NAME, "TECRA A11"),
  444. },
  445. },
  446. { } /* terminating entry */
  447. };
  448. /*
  449. * Lid events. Note the use of 'modeset_on_lid':
  450. * - we set it on lid close, and reset it on open
  451. * - we use it as a "only once" bit (ie we ignore
  452. * duplicate events where it was already properly
  453. * set/reset)
  454. * - the suspend/resume paths will also set it to
  455. * zero, since they restore the mode ("lid open").
  456. */
  457. static int intel_lid_notify(struct notifier_block *nb, unsigned long val,
  458. void *unused)
  459. {
  460. struct drm_i915_private *dev_priv =
  461. container_of(nb, struct drm_i915_private, lid_notifier);
  462. struct drm_device *dev = dev_priv->dev;
  463. struct drm_connector *connector = dev_priv->int_lvds_connector;
  464. /*
  465. * check and update the status of LVDS connector after receiving
  466. * the LID nofication event.
  467. */
  468. if (connector)
  469. connector->status = connector->funcs->detect(connector);
  470. /* Don't force modeset on machines where it causes a GPU lockup */
  471. if (dmi_check_system(intel_no_modeset_on_lid))
  472. return NOTIFY_OK;
  473. if (!acpi_lid_open()) {
  474. dev_priv->modeset_on_lid = 1;
  475. return NOTIFY_OK;
  476. }
  477. if (!dev_priv->modeset_on_lid)
  478. return NOTIFY_OK;
  479. dev_priv->modeset_on_lid = 0;
  480. mutex_lock(&dev->mode_config.mutex);
  481. drm_helper_resume_force_mode(dev);
  482. mutex_unlock(&dev->mode_config.mutex);
  483. return NOTIFY_OK;
  484. }
  485. /**
  486. * intel_lvds_destroy - unregister and free LVDS structures
  487. * @connector: connector to free
  488. *
  489. * Unregister the DDC bus for this connector then free the driver private
  490. * structure.
  491. */
  492. static void intel_lvds_destroy(struct drm_connector *connector)
  493. {
  494. struct drm_device *dev = connector->dev;
  495. struct drm_i915_private *dev_priv = dev->dev_private;
  496. if (dev_priv->lid_notifier.notifier_call)
  497. acpi_lid_notifier_unregister(&dev_priv->lid_notifier);
  498. drm_sysfs_connector_remove(connector);
  499. drm_connector_cleanup(connector);
  500. kfree(connector);
  501. }
  502. static int intel_lvds_set_property(struct drm_connector *connector,
  503. struct drm_property *property,
  504. uint64_t value)
  505. {
  506. struct drm_device *dev = connector->dev;
  507. if (property == dev->mode_config.scaling_mode_property &&
  508. connector->encoder) {
  509. struct drm_crtc *crtc = connector->encoder->crtc;
  510. struct drm_encoder *encoder = connector->encoder;
  511. struct intel_lvds *intel_lvds = enc_to_intel_lvds(encoder);
  512. if (value == DRM_MODE_SCALE_NONE) {
  513. DRM_DEBUG_KMS("no scaling not supported\n");
  514. return 0;
  515. }
  516. if (intel_lvds->fitting_mode == value) {
  517. /* the LVDS scaling property is not changed */
  518. return 0;
  519. }
  520. intel_lvds->fitting_mode = value;
  521. if (crtc && crtc->enabled) {
  522. /*
  523. * If the CRTC is enabled, the display will be changed
  524. * according to the new panel fitting mode.
  525. */
  526. drm_crtc_helper_set_mode(crtc, &crtc->mode,
  527. crtc->x, crtc->y, crtc->fb);
  528. }
  529. }
  530. return 0;
  531. }
  532. static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = {
  533. .dpms = intel_lvds_dpms,
  534. .mode_fixup = intel_lvds_mode_fixup,
  535. .prepare = intel_lvds_prepare,
  536. .mode_set = intel_lvds_mode_set,
  537. .commit = intel_lvds_commit,
  538. };
  539. static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = {
  540. .get_modes = intel_lvds_get_modes,
  541. .mode_valid = intel_lvds_mode_valid,
  542. .best_encoder = intel_best_encoder,
  543. };
  544. static const struct drm_connector_funcs intel_lvds_connector_funcs = {
  545. .dpms = drm_helper_connector_dpms,
  546. .detect = intel_lvds_detect,
  547. .fill_modes = drm_helper_probe_single_connector_modes,
  548. .set_property = intel_lvds_set_property,
  549. .destroy = intel_lvds_destroy,
  550. };
  551. static const struct drm_encoder_funcs intel_lvds_enc_funcs = {
  552. .destroy = intel_encoder_destroy,
  553. };
  554. static int __init intel_no_lvds_dmi_callback(const struct dmi_system_id *id)
  555. {
  556. DRM_DEBUG_KMS("Skipping LVDS initialization for %s\n", id->ident);
  557. return 1;
  558. }
  559. /* These systems claim to have LVDS, but really don't */
  560. static const struct dmi_system_id intel_no_lvds[] = {
  561. {
  562. .callback = intel_no_lvds_dmi_callback,
  563. .ident = "Apple Mac Mini (Core series)",
  564. .matches = {
  565. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  566. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini1,1"),
  567. },
  568. },
  569. {
  570. .callback = intel_no_lvds_dmi_callback,
  571. .ident = "Apple Mac Mini (Core 2 series)",
  572. .matches = {
  573. DMI_MATCH(DMI_SYS_VENDOR, "Apple"),
  574. DMI_MATCH(DMI_PRODUCT_NAME, "Macmini2,1"),
  575. },
  576. },
  577. {
  578. .callback = intel_no_lvds_dmi_callback,
  579. .ident = "MSI IM-945GSE-A",
  580. .matches = {
  581. DMI_MATCH(DMI_SYS_VENDOR, "MSI"),
  582. DMI_MATCH(DMI_PRODUCT_NAME, "A9830IMS"),
  583. },
  584. },
  585. {
  586. .callback = intel_no_lvds_dmi_callback,
  587. .ident = "Dell Studio Hybrid",
  588. .matches = {
  589. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  590. DMI_MATCH(DMI_PRODUCT_NAME, "Studio Hybrid 140g"),
  591. },
  592. },
  593. {
  594. .callback = intel_no_lvds_dmi_callback,
  595. .ident = "AOpen Mini PC",
  596. .matches = {
  597. DMI_MATCH(DMI_SYS_VENDOR, "AOpen"),
  598. DMI_MATCH(DMI_PRODUCT_NAME, "i965GMx-IF"),
  599. },
  600. },
  601. {
  602. .callback = intel_no_lvds_dmi_callback,
  603. .ident = "AOpen Mini PC MP915",
  604. .matches = {
  605. DMI_MATCH(DMI_BOARD_VENDOR, "AOpen"),
  606. DMI_MATCH(DMI_BOARD_NAME, "i915GMx-F"),
  607. },
  608. },
  609. {
  610. .callback = intel_no_lvds_dmi_callback,
  611. .ident = "Aopen i945GTt-VFA",
  612. .matches = {
  613. DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"),
  614. },
  615. },
  616. {
  617. .callback = intel_no_lvds_dmi_callback,
  618. .ident = "Clientron U800",
  619. .matches = {
  620. DMI_MATCH(DMI_SYS_VENDOR, "Clientron"),
  621. DMI_MATCH(DMI_PRODUCT_NAME, "U800"),
  622. },
  623. },
  624. { } /* terminating entry */
  625. };
  626. /**
  627. * intel_find_lvds_downclock - find the reduced downclock for LVDS in EDID
  628. * @dev: drm device
  629. * @connector: LVDS connector
  630. *
  631. * Find the reduced downclock for LVDS in EDID.
  632. */
  633. static void intel_find_lvds_downclock(struct drm_device *dev,
  634. struct drm_connector *connector)
  635. {
  636. struct drm_i915_private *dev_priv = dev->dev_private;
  637. struct drm_display_mode *scan, *panel_fixed_mode;
  638. int temp_downclock;
  639. panel_fixed_mode = dev_priv->panel_fixed_mode;
  640. temp_downclock = panel_fixed_mode->clock;
  641. list_for_each_entry(scan, &connector->probed_modes, head) {
  642. /*
  643. * If one mode has the same resolution with the fixed_panel
  644. * mode while they have the different refresh rate, it means
  645. * that the reduced downclock is found for the LVDS. In such
  646. * case we can set the different FPx0/1 to dynamically select
  647. * between low and high frequency.
  648. */
  649. if (scan->hdisplay == panel_fixed_mode->hdisplay &&
  650. scan->hsync_start == panel_fixed_mode->hsync_start &&
  651. scan->hsync_end == panel_fixed_mode->hsync_end &&
  652. scan->htotal == panel_fixed_mode->htotal &&
  653. scan->vdisplay == panel_fixed_mode->vdisplay &&
  654. scan->vsync_start == panel_fixed_mode->vsync_start &&
  655. scan->vsync_end == panel_fixed_mode->vsync_end &&
  656. scan->vtotal == panel_fixed_mode->vtotal) {
  657. if (scan->clock < temp_downclock) {
  658. /*
  659. * The downclock is already found. But we
  660. * expect to find the lower downclock.
  661. */
  662. temp_downclock = scan->clock;
  663. }
  664. }
  665. }
  666. if (temp_downclock < panel_fixed_mode->clock &&
  667. i915_lvds_downclock) {
  668. /* We found the downclock for LVDS. */
  669. dev_priv->lvds_downclock_avail = 1;
  670. dev_priv->lvds_downclock = temp_downclock;
  671. DRM_DEBUG_KMS("LVDS downclock is found in EDID. "
  672. "Normal clock %dKhz, downclock %dKhz\n",
  673. panel_fixed_mode->clock, temp_downclock);
  674. }
  675. return;
  676. }
  677. /*
  678. * Enumerate the child dev array parsed from VBT to check whether
  679. * the LVDS is present.
  680. * If it is present, return 1.
  681. * If it is not present, return false.
  682. * If no child dev is parsed from VBT, it assumes that the LVDS is present.
  683. */
  684. static bool lvds_is_present_in_vbt(struct drm_device *dev)
  685. {
  686. struct drm_i915_private *dev_priv = dev->dev_private;
  687. int i;
  688. if (!dev_priv->child_dev_num)
  689. return true;
  690. for (i = 0; i < dev_priv->child_dev_num; i++) {
  691. struct child_device_config *child = dev_priv->child_dev + i;
  692. /* If the device type is not LFP, continue.
  693. * We have to check both the new identifiers as well as the
  694. * old for compatibility with some BIOSes.
  695. */
  696. if (child->device_type != DEVICE_TYPE_INT_LFP &&
  697. child->device_type != DEVICE_TYPE_LFP)
  698. continue;
  699. /* However, we cannot trust the BIOS writers to populate
  700. * the VBT correctly. Since LVDS requires additional
  701. * information from AIM blocks, a non-zero addin offset is
  702. * a good indicator that the LVDS is actually present.
  703. */
  704. if (child->addin_offset)
  705. return true;
  706. /* But even then some BIOS writers perform some black magic
  707. * and instantiate the device without reference to any
  708. * additional data. Trust that if the VBT was written into
  709. * the OpRegion then they have validated the LVDS's existence.
  710. */
  711. if (dev_priv->opregion.vbt)
  712. return true;
  713. }
  714. return false;
  715. }
  716. /**
  717. * intel_lvds_init - setup LVDS connectors on this device
  718. * @dev: drm device
  719. *
  720. * Create the connector, register the LVDS DDC bus, and try to figure out what
  721. * modes we can display on the LVDS panel (if present).
  722. */
  723. void intel_lvds_init(struct drm_device *dev)
  724. {
  725. struct drm_i915_private *dev_priv = dev->dev_private;
  726. struct intel_lvds *intel_lvds;
  727. struct intel_encoder *intel_encoder;
  728. struct intel_connector *intel_connector;
  729. struct drm_connector *connector;
  730. struct drm_encoder *encoder;
  731. struct drm_display_mode *scan; /* *modes, *bios_mode; */
  732. struct drm_crtc *crtc;
  733. u32 lvds;
  734. int pipe, gpio = GPIOC;
  735. /* Skip init on machines we know falsely report LVDS */
  736. if (dmi_check_system(intel_no_lvds))
  737. return;
  738. if (!lvds_is_present_in_vbt(dev)) {
  739. DRM_DEBUG_KMS("LVDS is not present in VBT\n");
  740. return;
  741. }
  742. if (HAS_PCH_SPLIT(dev)) {
  743. if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0)
  744. return;
  745. if (dev_priv->edp_support) {
  746. DRM_DEBUG_KMS("disable LVDS for eDP support\n");
  747. return;
  748. }
  749. gpio = PCH_GPIOC;
  750. }
  751. intel_lvds = kzalloc(sizeof(struct intel_lvds), GFP_KERNEL);
  752. if (!intel_lvds) {
  753. return;
  754. }
  755. intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL);
  756. if (!intel_connector) {
  757. kfree(intel_lvds);
  758. return;
  759. }
  760. if (!HAS_PCH_SPLIT(dev)) {
  761. intel_lvds->pfit_control = I915_READ(PFIT_CONTROL);
  762. }
  763. intel_encoder = &intel_lvds->base;
  764. encoder = &intel_encoder->base;
  765. connector = &intel_connector->base;
  766. drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs,
  767. DRM_MODE_CONNECTOR_LVDS);
  768. drm_encoder_init(dev, &intel_encoder->base, &intel_lvds_enc_funcs,
  769. DRM_MODE_ENCODER_LVDS);
  770. intel_connector_attach_encoder(intel_connector, intel_encoder);
  771. intel_encoder->type = INTEL_OUTPUT_LVDS;
  772. intel_encoder->clone_mask = (1 << INTEL_LVDS_CLONE_BIT);
  773. intel_encoder->crtc_mask = (1 << 1);
  774. drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs);
  775. drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs);
  776. connector->display_info.subpixel_order = SubPixelHorizontalRGB;
  777. connector->interlace_allowed = false;
  778. connector->doublescan_allowed = false;
  779. /* create the scaling mode property */
  780. drm_mode_create_scaling_mode_property(dev);
  781. /*
  782. * the initial panel fitting mode will be FULL_SCREEN.
  783. */
  784. drm_connector_attach_property(&intel_connector->base,
  785. dev->mode_config.scaling_mode_property,
  786. DRM_MODE_SCALE_ASPECT);
  787. intel_lvds->fitting_mode = DRM_MODE_SCALE_ASPECT;
  788. /*
  789. * LVDS discovery:
  790. * 1) check for EDID on DDC
  791. * 2) check for VBT data
  792. * 3) check to see if LVDS is already on
  793. * if none of the above, no panel
  794. * 4) make sure lid is open
  795. * if closed, act like it's not there for now
  796. */
  797. /* Set up the DDC bus. */
  798. intel_encoder->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C");
  799. if (!intel_encoder->ddc_bus) {
  800. dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
  801. "failed.\n");
  802. goto failed;
  803. }
  804. /*
  805. * Attempt to get the fixed panel mode from DDC. Assume that the
  806. * preferred mode is the right one.
  807. */
  808. dev_priv->lvds_edid_good = true;
  809. if (!intel_ddc_get_modes(connector, intel_encoder->ddc_bus))
  810. dev_priv->lvds_edid_good = false;
  811. list_for_each_entry(scan, &connector->probed_modes, head) {
  812. if (scan->type & DRM_MODE_TYPE_PREFERRED) {
  813. dev_priv->panel_fixed_mode =
  814. drm_mode_duplicate(dev, scan);
  815. intel_find_lvds_downclock(dev, connector);
  816. goto out;
  817. }
  818. }
  819. /* Failed to get EDID, what about VBT? */
  820. if (dev_priv->lfp_lvds_vbt_mode) {
  821. dev_priv->panel_fixed_mode =
  822. drm_mode_duplicate(dev, dev_priv->lfp_lvds_vbt_mode);
  823. if (dev_priv->panel_fixed_mode) {
  824. dev_priv->panel_fixed_mode->type |=
  825. DRM_MODE_TYPE_PREFERRED;
  826. goto out;
  827. }
  828. }
  829. /*
  830. * If we didn't get EDID, try checking if the panel is already turned
  831. * on. If so, assume that whatever is currently programmed is the
  832. * correct mode.
  833. */
  834. /* Ironlake: FIXME if still fail, not try pipe mode now */
  835. if (HAS_PCH_SPLIT(dev))
  836. goto failed;
  837. lvds = I915_READ(LVDS);
  838. pipe = (lvds & LVDS_PIPEB_SELECT) ? 1 : 0;
  839. crtc = intel_get_crtc_for_pipe(dev, pipe);
  840. if (crtc && (lvds & LVDS_PORT_EN)) {
  841. dev_priv->panel_fixed_mode = intel_crtc_mode_get(dev, crtc);
  842. if (dev_priv->panel_fixed_mode) {
  843. dev_priv->panel_fixed_mode->type |=
  844. DRM_MODE_TYPE_PREFERRED;
  845. goto out;
  846. }
  847. }
  848. /* If we still don't have a mode after all that, give up. */
  849. if (!dev_priv->panel_fixed_mode)
  850. goto failed;
  851. out:
  852. if (HAS_PCH_SPLIT(dev)) {
  853. u32 pwm;
  854. /* make sure PWM is enabled */
  855. pwm = I915_READ(BLC_PWM_CPU_CTL2);
  856. pwm |= (PWM_ENABLE | PWM_PIPE_B);
  857. I915_WRITE(BLC_PWM_CPU_CTL2, pwm);
  858. pwm = I915_READ(BLC_PWM_PCH_CTL1);
  859. pwm |= PWM_PCH_ENABLE;
  860. I915_WRITE(BLC_PWM_PCH_CTL1, pwm);
  861. }
  862. dev_priv->lid_notifier.notifier_call = intel_lid_notify;
  863. if (acpi_lid_notifier_register(&dev_priv->lid_notifier)) {
  864. DRM_DEBUG_KMS("lid notifier registration failed\n");
  865. dev_priv->lid_notifier.notifier_call = NULL;
  866. }
  867. /* keep the LVDS connector */
  868. dev_priv->int_lvds_connector = connector;
  869. drm_sysfs_connector_add(connector);
  870. return;
  871. failed:
  872. DRM_DEBUG_KMS("No LVDS modes found, disabling.\n");
  873. if (intel_encoder->ddc_bus)
  874. intel_i2c_destroy(intel_encoder->ddc_bus);
  875. drm_connector_cleanup(connector);
  876. drm_encoder_cleanup(encoder);
  877. kfree(intel_lvds);
  878. kfree(intel_connector);
  879. }