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