intel_lvds.c 29 KB

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