intel_lvds.c 28 KB

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