intel_lvds.c 28 KB

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