intel_lvds.c 29 KB

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