intel_panel.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * Copyright © 2006-2010 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. * Chris Wilson <chris@chris-wilson.co.uk>
  29. */
  30. #include "intel_drv.h"
  31. void
  32. intel_fixed_panel_mode(struct drm_display_mode *fixed_mode,
  33. struct drm_display_mode *adjusted_mode)
  34. {
  35. adjusted_mode->hdisplay = fixed_mode->hdisplay;
  36. adjusted_mode->hsync_start = fixed_mode->hsync_start;
  37. adjusted_mode->hsync_end = fixed_mode->hsync_end;
  38. adjusted_mode->htotal = fixed_mode->htotal;
  39. adjusted_mode->vdisplay = fixed_mode->vdisplay;
  40. adjusted_mode->vsync_start = fixed_mode->vsync_start;
  41. adjusted_mode->vsync_end = fixed_mode->vsync_end;
  42. adjusted_mode->vtotal = fixed_mode->vtotal;
  43. adjusted_mode->clock = fixed_mode->clock;
  44. drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
  45. }
  46. /* adjusted_mode has been preset to be the panel's fixed mode */
  47. void
  48. intel_pch_panel_fitting(struct drm_device *dev,
  49. int fitting_mode,
  50. struct drm_display_mode *mode,
  51. struct drm_display_mode *adjusted_mode)
  52. {
  53. struct drm_i915_private *dev_priv = dev->dev_private;
  54. int x, y, width, height;
  55. x = y = width = height = 0;
  56. /* Native modes don't need fitting */
  57. if (adjusted_mode->hdisplay == mode->hdisplay &&
  58. adjusted_mode->vdisplay == mode->vdisplay)
  59. goto done;
  60. switch (fitting_mode) {
  61. case DRM_MODE_SCALE_CENTER:
  62. width = mode->hdisplay;
  63. height = mode->vdisplay;
  64. x = (adjusted_mode->hdisplay - width + 1)/2;
  65. y = (adjusted_mode->vdisplay - height + 1)/2;
  66. break;
  67. case DRM_MODE_SCALE_ASPECT:
  68. /* Scale but preserve the aspect ratio */
  69. {
  70. u32 scaled_width = adjusted_mode->hdisplay * mode->vdisplay;
  71. u32 scaled_height = mode->hdisplay * adjusted_mode->vdisplay;
  72. if (scaled_width > scaled_height) { /* pillar */
  73. width = scaled_height / mode->vdisplay;
  74. x = (adjusted_mode->hdisplay - width + 1) / 2;
  75. y = 0;
  76. height = adjusted_mode->vdisplay;
  77. } else if (scaled_width < scaled_height) { /* letter */
  78. height = scaled_width / mode->hdisplay;
  79. y = (adjusted_mode->vdisplay - height + 1) / 2;
  80. x = 0;
  81. width = adjusted_mode->hdisplay;
  82. } else {
  83. x = y = 0;
  84. width = adjusted_mode->hdisplay;
  85. height = adjusted_mode->vdisplay;
  86. }
  87. }
  88. break;
  89. default:
  90. case DRM_MODE_SCALE_FULLSCREEN:
  91. x = y = 0;
  92. width = adjusted_mode->hdisplay;
  93. height = adjusted_mode->vdisplay;
  94. break;
  95. }
  96. done:
  97. dev_priv->pch_pf_pos = (x << 16) | y;
  98. dev_priv->pch_pf_size = (width << 16) | height;
  99. }