intel_lvds.c 30 KB

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