Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2006-2007 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 21 | * DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | */ |
| 26 | |
Daniel Vetter | 618563e | 2012-04-01 13:38:50 +0200 | [diff] [blame] | 27 | #include <linux/dmi.h> |
Jesse Barnes | c1c7af6 | 2009-09-10 15:28:03 -0700 | [diff] [blame] | 28 | #include <linux/module.h> |
| 29 | #include <linux/input.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 30 | #include <linux/i2c.h> |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 31 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 33 | #include <linux/vgaarb.h> |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 34 | #include <drm/drm_edid.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drmP.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 36 | #include "intel_drv.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 37 | #include <drm/i915_drm.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 38 | #include "i915_drv.h" |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 39 | #include "i915_trace.h" |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 40 | #include <drm/drm_dp_helper.h> |
| 41 | #include <drm/drm_crtc_helper.h> |
Keith Packard | c0f372b3 | 2011-11-16 22:24:52 -0800 | [diff] [blame] | 42 | #include <linux/dma_remapping.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 43 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 44 | bool intel_pipe_has_type(struct drm_crtc *crtc, int type); |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 45 | static void intel_increase_pllclock(struct drm_crtc *crtc); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 46 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 47 | |
| 48 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 49 | /* given values */ |
| 50 | int n; |
| 51 | int m1, m2; |
| 52 | int p1, p2; |
| 53 | /* derived values */ |
| 54 | int dot; |
| 55 | int vco; |
| 56 | int m; |
| 57 | int p; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 58 | } intel_clock_t; |
| 59 | |
| 60 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 61 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 62 | } intel_range_t; |
| 63 | |
| 64 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 65 | int dot_limit; |
| 66 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 67 | } intel_p2_t; |
| 68 | |
| 69 | #define INTEL_P2_NUM 2 |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 70 | typedef struct intel_limit intel_limit_t; |
| 71 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 72 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 73 | intel_p2_t p2; |
| 74 | bool (* find_pll)(const intel_limit_t *, struct drm_crtc *, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 75 | int, int, intel_clock_t *, intel_clock_t *); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 76 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 77 | |
Jesse Barnes | 2377b74 | 2010-07-07 14:06:43 -0700 | [diff] [blame] | 78 | /* FDI */ |
| 79 | #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */ |
| 80 | |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 81 | int |
| 82 | intel_pch_rawclk(struct drm_device *dev) |
| 83 | { |
| 84 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 85 | |
| 86 | WARN_ON(!HAS_PCH_SPLIT(dev)); |
| 87 | |
| 88 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; |
| 89 | } |
| 90 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 91 | static bool |
| 92 | intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 93 | int target, int refclk, intel_clock_t *match_clock, |
| 94 | intel_clock_t *best_clock); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 95 | static bool |
| 96 | intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 97 | int target, int refclk, intel_clock_t *match_clock, |
| 98 | intel_clock_t *best_clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 99 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 100 | static bool |
| 101 | intel_find_pll_g4x_dp(const intel_limit_t *, struct drm_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 102 | int target, int refclk, intel_clock_t *match_clock, |
| 103 | intel_clock_t *best_clock); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 104 | static bool |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 105 | intel_find_pll_ironlake_dp(const intel_limit_t *, struct drm_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 106 | int target, int refclk, intel_clock_t *match_clock, |
| 107 | intel_clock_t *best_clock); |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 108 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 109 | static bool |
| 110 | intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 111 | int target, int refclk, intel_clock_t *match_clock, |
| 112 | intel_clock_t *best_clock); |
| 113 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 114 | static inline u32 /* units of 100MHz */ |
| 115 | intel_fdi_link_freq(struct drm_device *dev) |
| 116 | { |
Chris Wilson | 8b99e68 | 2010-10-13 09:59:17 +0100 | [diff] [blame] | 117 | if (IS_GEN5(dev)) { |
| 118 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 119 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; |
| 120 | } else |
| 121 | return 27; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 122 | } |
| 123 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 124 | static const intel_limit_t intel_limits_i8xx_dvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 125 | .dot = { .min = 25000, .max = 350000 }, |
| 126 | .vco = { .min = 930000, .max = 1400000 }, |
| 127 | .n = { .min = 3, .max = 16 }, |
| 128 | .m = { .min = 96, .max = 140 }, |
| 129 | .m1 = { .min = 18, .max = 26 }, |
| 130 | .m2 = { .min = 6, .max = 16 }, |
| 131 | .p = { .min = 4, .max = 128 }, |
| 132 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 133 | .p2 = { .dot_limit = 165000, |
| 134 | .p2_slow = 4, .p2_fast = 2 }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 135 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
| 138 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 139 | .dot = { .min = 25000, .max = 350000 }, |
| 140 | .vco = { .min = 930000, .max = 1400000 }, |
| 141 | .n = { .min = 3, .max = 16 }, |
| 142 | .m = { .min = 96, .max = 140 }, |
| 143 | .m1 = { .min = 18, .max = 26 }, |
| 144 | .m2 = { .min = 6, .max = 16 }, |
| 145 | .p = { .min = 4, .max = 128 }, |
| 146 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 147 | .p2 = { .dot_limit = 165000, |
| 148 | .p2_slow = 14, .p2_fast = 7 }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 149 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 150 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 151 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 152 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 153 | .dot = { .min = 20000, .max = 400000 }, |
| 154 | .vco = { .min = 1400000, .max = 2800000 }, |
| 155 | .n = { .min = 1, .max = 6 }, |
| 156 | .m = { .min = 70, .max = 120 }, |
| 157 | .m1 = { .min = 10, .max = 22 }, |
| 158 | .m2 = { .min = 5, .max = 9 }, |
| 159 | .p = { .min = 5, .max = 80 }, |
| 160 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 161 | .p2 = { .dot_limit = 200000, |
| 162 | .p2_slow = 10, .p2_fast = 5 }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 163 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 167 | .dot = { .min = 20000, .max = 400000 }, |
| 168 | .vco = { .min = 1400000, .max = 2800000 }, |
| 169 | .n = { .min = 1, .max = 6 }, |
| 170 | .m = { .min = 70, .max = 120 }, |
| 171 | .m1 = { .min = 10, .max = 22 }, |
| 172 | .m2 = { .min = 5, .max = 9 }, |
| 173 | .p = { .min = 7, .max = 98 }, |
| 174 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 175 | .p2 = { .dot_limit = 112000, |
| 176 | .p2_slow = 14, .p2_fast = 7 }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 177 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 178 | }; |
| 179 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 180 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 181 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 182 | .dot = { .min = 25000, .max = 270000 }, |
| 183 | .vco = { .min = 1750000, .max = 3500000}, |
| 184 | .n = { .min = 1, .max = 4 }, |
| 185 | .m = { .min = 104, .max = 138 }, |
| 186 | .m1 = { .min = 17, .max = 23 }, |
| 187 | .m2 = { .min = 5, .max = 11 }, |
| 188 | .p = { .min = 10, .max = 30 }, |
| 189 | .p1 = { .min = 1, .max = 3}, |
| 190 | .p2 = { .dot_limit = 270000, |
| 191 | .p2_slow = 10, |
| 192 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 193 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 194 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 195 | }; |
| 196 | |
| 197 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 198 | .dot = { .min = 22000, .max = 400000 }, |
| 199 | .vco = { .min = 1750000, .max = 3500000}, |
| 200 | .n = { .min = 1, .max = 4 }, |
| 201 | .m = { .min = 104, .max = 138 }, |
| 202 | .m1 = { .min = 16, .max = 23 }, |
| 203 | .m2 = { .min = 5, .max = 11 }, |
| 204 | .p = { .min = 5, .max = 80 }, |
| 205 | .p1 = { .min = 1, .max = 8}, |
| 206 | .p2 = { .dot_limit = 165000, |
| 207 | .p2_slow = 10, .p2_fast = 5 }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 208 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 209 | }; |
| 210 | |
| 211 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 212 | .dot = { .min = 20000, .max = 115000 }, |
| 213 | .vco = { .min = 1750000, .max = 3500000 }, |
| 214 | .n = { .min = 1, .max = 3 }, |
| 215 | .m = { .min = 104, .max = 138 }, |
| 216 | .m1 = { .min = 17, .max = 23 }, |
| 217 | .m2 = { .min = 5, .max = 11 }, |
| 218 | .p = { .min = 28, .max = 112 }, |
| 219 | .p1 = { .min = 2, .max = 8 }, |
| 220 | .p2 = { .dot_limit = 0, |
| 221 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 222 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 223 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 224 | }; |
| 225 | |
| 226 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 227 | .dot = { .min = 80000, .max = 224000 }, |
| 228 | .vco = { .min = 1750000, .max = 3500000 }, |
| 229 | .n = { .min = 1, .max = 3 }, |
| 230 | .m = { .min = 104, .max = 138 }, |
| 231 | .m1 = { .min = 17, .max = 23 }, |
| 232 | .m2 = { .min = 5, .max = 11 }, |
| 233 | .p = { .min = 14, .max = 42 }, |
| 234 | .p1 = { .min = 2, .max = 6 }, |
| 235 | .p2 = { .dot_limit = 0, |
| 236 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 237 | }, |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 238 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 239 | }; |
| 240 | |
| 241 | static const intel_limit_t intel_limits_g4x_display_port = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 242 | .dot = { .min = 161670, .max = 227000 }, |
| 243 | .vco = { .min = 1750000, .max = 3500000}, |
| 244 | .n = { .min = 1, .max = 2 }, |
| 245 | .m = { .min = 97, .max = 108 }, |
| 246 | .m1 = { .min = 0x10, .max = 0x12 }, |
| 247 | .m2 = { .min = 0x05, .max = 0x06 }, |
| 248 | .p = { .min = 10, .max = 20 }, |
| 249 | .p1 = { .min = 1, .max = 2}, |
| 250 | .p2 = { .dot_limit = 0, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 251 | .p2_slow = 10, .p2_fast = 10 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 252 | .find_pll = intel_find_pll_g4x_dp, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 253 | }; |
| 254 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 255 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 256 | .dot = { .min = 20000, .max = 400000}, |
| 257 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 258 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 259 | .n = { .min = 3, .max = 6 }, |
| 260 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 261 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 262 | .m1 = { .min = 0, .max = 0 }, |
| 263 | .m2 = { .min = 0, .max = 254 }, |
| 264 | .p = { .min = 5, .max = 80 }, |
| 265 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 266 | .p2 = { .dot_limit = 200000, |
| 267 | .p2_slow = 10, .p2_fast = 5 }, |
Shaohua Li | 6115707 | 2009-04-03 15:24:43 +0800 | [diff] [blame] | 268 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 269 | }; |
| 270 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 271 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 272 | .dot = { .min = 20000, .max = 400000 }, |
| 273 | .vco = { .min = 1700000, .max = 3500000 }, |
| 274 | .n = { .min = 3, .max = 6 }, |
| 275 | .m = { .min = 2, .max = 256 }, |
| 276 | .m1 = { .min = 0, .max = 0 }, |
| 277 | .m2 = { .min = 0, .max = 254 }, |
| 278 | .p = { .min = 7, .max = 112 }, |
| 279 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 280 | .p2 = { .dot_limit = 112000, |
| 281 | .p2_slow = 14, .p2_fast = 14 }, |
Shaohua Li | 6115707 | 2009-04-03 15:24:43 +0800 | [diff] [blame] | 282 | .find_pll = intel_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 285 | /* Ironlake / Sandybridge |
| 286 | * |
| 287 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 288 | * the range value for them is (actual_value - 2). |
| 289 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 290 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 291 | .dot = { .min = 25000, .max = 350000 }, |
| 292 | .vco = { .min = 1760000, .max = 3510000 }, |
| 293 | .n = { .min = 1, .max = 5 }, |
| 294 | .m = { .min = 79, .max = 127 }, |
| 295 | .m1 = { .min = 12, .max = 22 }, |
| 296 | .m2 = { .min = 5, .max = 9 }, |
| 297 | .p = { .min = 5, .max = 80 }, |
| 298 | .p1 = { .min = 1, .max = 8 }, |
| 299 | .p2 = { .dot_limit = 225000, |
| 300 | .p2_slow = 10, .p2_fast = 5 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 301 | .find_pll = intel_g4x_find_best_PLL, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 302 | }; |
| 303 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 304 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 305 | .dot = { .min = 25000, .max = 350000 }, |
| 306 | .vco = { .min = 1760000, .max = 3510000 }, |
| 307 | .n = { .min = 1, .max = 3 }, |
| 308 | .m = { .min = 79, .max = 118 }, |
| 309 | .m1 = { .min = 12, .max = 22 }, |
| 310 | .m2 = { .min = 5, .max = 9 }, |
| 311 | .p = { .min = 28, .max = 112 }, |
| 312 | .p1 = { .min = 2, .max = 8 }, |
| 313 | .p2 = { .dot_limit = 225000, |
| 314 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 315 | .find_pll = intel_g4x_find_best_PLL, |
| 316 | }; |
| 317 | |
| 318 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 319 | .dot = { .min = 25000, .max = 350000 }, |
| 320 | .vco = { .min = 1760000, .max = 3510000 }, |
| 321 | .n = { .min = 1, .max = 3 }, |
| 322 | .m = { .min = 79, .max = 127 }, |
| 323 | .m1 = { .min = 12, .max = 22 }, |
| 324 | .m2 = { .min = 5, .max = 9 }, |
| 325 | .p = { .min = 14, .max = 56 }, |
| 326 | .p1 = { .min = 2, .max = 8 }, |
| 327 | .p2 = { .dot_limit = 225000, |
| 328 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 329 | .find_pll = intel_g4x_find_best_PLL, |
| 330 | }; |
| 331 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 332 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 333 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 334 | .dot = { .min = 25000, .max = 350000 }, |
| 335 | .vco = { .min = 1760000, .max = 3510000 }, |
| 336 | .n = { .min = 1, .max = 2 }, |
| 337 | .m = { .min = 79, .max = 126 }, |
| 338 | .m1 = { .min = 12, .max = 22 }, |
| 339 | .m2 = { .min = 5, .max = 9 }, |
| 340 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 341 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 342 | .p2 = { .dot_limit = 225000, |
| 343 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 344 | .find_pll = intel_g4x_find_best_PLL, |
| 345 | }; |
| 346 | |
| 347 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 348 | .dot = { .min = 25000, .max = 350000 }, |
| 349 | .vco = { .min = 1760000, .max = 3510000 }, |
| 350 | .n = { .min = 1, .max = 3 }, |
| 351 | .m = { .min = 79, .max = 126 }, |
| 352 | .m1 = { .min = 12, .max = 22 }, |
| 353 | .m2 = { .min = 5, .max = 9 }, |
| 354 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 355 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 356 | .p2 = { .dot_limit = 225000, |
| 357 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 358 | .find_pll = intel_g4x_find_best_PLL, |
| 359 | }; |
| 360 | |
| 361 | static const intel_limit_t intel_limits_ironlake_display_port = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 362 | .dot = { .min = 25000, .max = 350000 }, |
| 363 | .vco = { .min = 1760000, .max = 3510000}, |
| 364 | .n = { .min = 1, .max = 2 }, |
| 365 | .m = { .min = 81, .max = 90 }, |
| 366 | .m1 = { .min = 12, .max = 22 }, |
| 367 | .m2 = { .min = 5, .max = 9 }, |
| 368 | .p = { .min = 10, .max = 20 }, |
| 369 | .p1 = { .min = 1, .max = 2}, |
| 370 | .p2 = { .dot_limit = 0, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 371 | .p2_slow = 10, .p2_fast = 10 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 372 | .find_pll = intel_find_pll_ironlake_dp, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 373 | }; |
| 374 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 375 | static const intel_limit_t intel_limits_vlv_dac = { |
| 376 | .dot = { .min = 25000, .max = 270000 }, |
| 377 | .vco = { .min = 4000000, .max = 6000000 }, |
| 378 | .n = { .min = 1, .max = 7 }, |
| 379 | .m = { .min = 22, .max = 450 }, /* guess */ |
| 380 | .m1 = { .min = 2, .max = 3 }, |
| 381 | .m2 = { .min = 11, .max = 156 }, |
| 382 | .p = { .min = 10, .max = 30 }, |
| 383 | .p1 = { .min = 2, .max = 3 }, |
| 384 | .p2 = { .dot_limit = 270000, |
| 385 | .p2_slow = 2, .p2_fast = 20 }, |
| 386 | .find_pll = intel_vlv_find_best_pll, |
| 387 | }; |
| 388 | |
| 389 | static const intel_limit_t intel_limits_vlv_hdmi = { |
| 390 | .dot = { .min = 20000, .max = 165000 }, |
Vijay Purushothaman | 17dc925 | 2012-09-27 19:13:09 +0530 | [diff] [blame] | 391 | .vco = { .min = 4000000, .max = 5994000}, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 392 | .n = { .min = 1, .max = 7 }, |
| 393 | .m = { .min = 60, .max = 300 }, /* guess */ |
| 394 | .m1 = { .min = 2, .max = 3 }, |
| 395 | .m2 = { .min = 11, .max = 156 }, |
| 396 | .p = { .min = 10, .max = 30 }, |
| 397 | .p1 = { .min = 2, .max = 3 }, |
| 398 | .p2 = { .dot_limit = 270000, |
| 399 | .p2_slow = 2, .p2_fast = 20 }, |
| 400 | .find_pll = intel_vlv_find_best_pll, |
| 401 | }; |
| 402 | |
| 403 | static const intel_limit_t intel_limits_vlv_dp = { |
Vijay Purushothaman | 74a4dd2 | 2012-09-27 19:13:04 +0530 | [diff] [blame] | 404 | .dot = { .min = 25000, .max = 270000 }, |
| 405 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 406 | .n = { .min = 1, .max = 7 }, |
Vijay Purushothaman | 74a4dd2 | 2012-09-27 19:13:04 +0530 | [diff] [blame] | 407 | .m = { .min = 22, .max = 450 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 408 | .m1 = { .min = 2, .max = 3 }, |
| 409 | .m2 = { .min = 11, .max = 156 }, |
| 410 | .p = { .min = 10, .max = 30 }, |
| 411 | .p1 = { .min = 2, .max = 3 }, |
| 412 | .p2 = { .dot_limit = 270000, |
| 413 | .p2_slow = 2, .p2_fast = 20 }, |
| 414 | .find_pll = intel_vlv_find_best_pll, |
| 415 | }; |
| 416 | |
Jesse Barnes | 57f350b | 2012-03-28 13:39:25 -0700 | [diff] [blame] | 417 | u32 intel_dpio_read(struct drm_i915_private *dev_priv, int reg) |
| 418 | { |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 419 | WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock)); |
Jesse Barnes | 57f350b | 2012-03-28 13:39:25 -0700 | [diff] [blame] | 420 | |
Jesse Barnes | 57f350b | 2012-03-28 13:39:25 -0700 | [diff] [blame] | 421 | if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) { |
| 422 | DRM_ERROR("DPIO idle wait timed out\n"); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 423 | return 0; |
Jesse Barnes | 57f350b | 2012-03-28 13:39:25 -0700 | [diff] [blame] | 424 | } |
| 425 | |
| 426 | I915_WRITE(DPIO_REG, reg); |
| 427 | I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_READ | DPIO_PORTID | |
| 428 | DPIO_BYTE); |
| 429 | if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) { |
| 430 | DRM_ERROR("DPIO read wait timed out\n"); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 431 | return 0; |
Jesse Barnes | 57f350b | 2012-03-28 13:39:25 -0700 | [diff] [blame] | 432 | } |
Jesse Barnes | 57f350b | 2012-03-28 13:39:25 -0700 | [diff] [blame] | 433 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 434 | return I915_READ(DPIO_DATA); |
Jesse Barnes | 57f350b | 2012-03-28 13:39:25 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 437 | static void intel_dpio_write(struct drm_i915_private *dev_priv, int reg, |
| 438 | u32 val) |
| 439 | { |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 440 | WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock)); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 441 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 442 | if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) { |
| 443 | DRM_ERROR("DPIO idle wait timed out\n"); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 444 | return; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | I915_WRITE(DPIO_DATA, val); |
| 448 | I915_WRITE(DPIO_REG, reg); |
| 449 | I915_WRITE(DPIO_PKT, DPIO_RID | DPIO_OP_WRITE | DPIO_PORTID | |
| 450 | DPIO_BYTE); |
| 451 | if (wait_for_atomic_us((I915_READ(DPIO_PKT) & DPIO_BUSY) == 0, 100)) |
| 452 | DRM_ERROR("DPIO write wait timed out\n"); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 453 | } |
| 454 | |
Jesse Barnes | 57f350b | 2012-03-28 13:39:25 -0700 | [diff] [blame] | 455 | static void vlv_init_dpio(struct drm_device *dev) |
| 456 | { |
| 457 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 458 | |
| 459 | /* Reset the DPIO config */ |
| 460 | I915_WRITE(DPIO_CTL, 0); |
| 461 | POSTING_READ(DPIO_CTL); |
| 462 | I915_WRITE(DPIO_CTL, 1); |
| 463 | POSTING_READ(DPIO_CTL); |
| 464 | } |
| 465 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 466 | static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc, |
| 467 | int refclk) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 468 | { |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 469 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 470 | const intel_limit_t *limit; |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 471 | |
| 472 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 473 | if (intel_is_dual_link_lvds(dev)) { |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 474 | /* LVDS dual channel */ |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 475 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 476 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 477 | else |
| 478 | limit = &intel_limits_ironlake_dual_lvds; |
| 479 | } else { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 480 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 481 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 482 | else |
| 483 | limit = &intel_limits_ironlake_single_lvds; |
| 484 | } |
| 485 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
Jani Nikula | 547dc04 | 2012-11-02 11:24:03 +0200 | [diff] [blame] | 486 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 487 | limit = &intel_limits_ironlake_display_port; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 488 | else |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 489 | limit = &intel_limits_ironlake_dac; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 490 | |
| 491 | return limit; |
| 492 | } |
| 493 | |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 494 | static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc) |
| 495 | { |
| 496 | struct drm_device *dev = crtc->dev; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 497 | const intel_limit_t *limit; |
| 498 | |
| 499 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 500 | if (intel_is_dual_link_lvds(dev)) |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 501 | /* LVDS with dual channel */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 502 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 503 | else |
| 504 | /* LVDS with dual channel */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 505 | limit = &intel_limits_g4x_single_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 506 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) || |
| 507 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 508 | limit = &intel_limits_g4x_hdmi; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 509 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 510 | limit = &intel_limits_g4x_sdvo; |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 511 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 512 | limit = &intel_limits_g4x_display_port; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 513 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 514 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 515 | |
| 516 | return limit; |
| 517 | } |
| 518 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 519 | static const intel_limit_t *intel_limit(struct drm_crtc *crtc, int refclk) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 520 | { |
| 521 | struct drm_device *dev = crtc->dev; |
| 522 | const intel_limit_t *limit; |
| 523 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 524 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 525 | limit = intel_ironlake_limit(crtc, refclk); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 526 | else if (IS_G4X(dev)) { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 527 | limit = intel_g4x_limit(crtc); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 528 | } else if (IS_PINEVIEW(dev)) { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 529 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 530 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 531 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 532 | limit = &intel_limits_pineview_sdvo; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 533 | } else if (IS_VALLEYVIEW(dev)) { |
| 534 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) |
| 535 | limit = &intel_limits_vlv_dac; |
| 536 | else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
| 537 | limit = &intel_limits_vlv_hdmi; |
| 538 | else |
| 539 | limit = &intel_limits_vlv_dp; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 540 | } else if (!IS_GEN2(dev)) { |
| 541 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
| 542 | limit = &intel_limits_i9xx_lvds; |
| 543 | else |
| 544 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 545 | } else { |
| 546 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 547 | limit = &intel_limits_i8xx_lvds; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 548 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 549 | limit = &intel_limits_i8xx_dvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 550 | } |
| 551 | return limit; |
| 552 | } |
| 553 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 554 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
| 555 | static void pineview_clock(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 556 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 557 | clock->m = clock->m2 + 2; |
| 558 | clock->p = clock->p1 * clock->p2; |
| 559 | clock->vco = refclk * clock->m / clock->n; |
| 560 | clock->dot = clock->vco / clock->p; |
| 561 | } |
| 562 | |
| 563 | static void intel_clock(struct drm_device *dev, int refclk, intel_clock_t *clock) |
| 564 | { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 565 | if (IS_PINEVIEW(dev)) { |
| 566 | pineview_clock(refclk, clock); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 567 | return; |
| 568 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 569 | clock->m = 5 * (clock->m1 + 2) + (clock->m2 + 2); |
| 570 | clock->p = clock->p1 * clock->p2; |
| 571 | clock->vco = refclk * clock->m / (clock->n + 2); |
| 572 | clock->dot = clock->vco / clock->p; |
| 573 | } |
| 574 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 575 | /** |
| 576 | * Returns whether any output on the specified pipe is of the specified type |
| 577 | */ |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 578 | bool intel_pipe_has_type(struct drm_crtc *crtc, int type) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 579 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 580 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 581 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 582 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 583 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 584 | if (encoder->type == type) |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 585 | return true; |
| 586 | |
| 587 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 588 | } |
| 589 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 590 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 591 | /** |
| 592 | * Returns whether the given set of divisors are valid for a given refclk with |
| 593 | * the given connectors. |
| 594 | */ |
| 595 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 596 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 597 | const intel_limit_t *limit, |
| 598 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 599 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 600 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 601 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 602 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 603 | INTELPllInvalid("p out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 604 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 605 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 606 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 607 | INTELPllInvalid("m1 out of range\n"); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 608 | if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev)) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 609 | INTELPllInvalid("m1 <= m2\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 610 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 611 | INTELPllInvalid("m out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 612 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 613 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 614 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 615 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 616 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 617 | * connector, etc., rather than just a single range. |
| 618 | */ |
| 619 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 620 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 621 | |
| 622 | return true; |
| 623 | } |
| 624 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 625 | static bool |
| 626 | intel_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 627 | int target, int refclk, intel_clock_t *match_clock, |
| 628 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 629 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 630 | { |
| 631 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 632 | intel_clock_t clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 633 | int err = target; |
| 634 | |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 635 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 636 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 637 | * For LVDS just rely on its current settings for dual-channel. |
| 638 | * We haven't figured out how to reliably set up different |
| 639 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 640 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 641 | if (intel_is_dual_link_lvds(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 642 | clock.p2 = limit->p2.p2_fast; |
| 643 | else |
| 644 | clock.p2 = limit->p2.p2_slow; |
| 645 | } else { |
| 646 | if (target < limit->p2.dot_limit) |
| 647 | clock.p2 = limit->p2.p2_slow; |
| 648 | else |
| 649 | clock.p2 = limit->p2.p2_fast; |
| 650 | } |
| 651 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 652 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 653 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 654 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 655 | clock.m1++) { |
| 656 | for (clock.m2 = limit->m2.min; |
| 657 | clock.m2 <= limit->m2.max; clock.m2++) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 658 | /* m1 is always 0 in Pineview */ |
| 659 | if (clock.m2 >= clock.m1 && !IS_PINEVIEW(dev)) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 660 | break; |
| 661 | for (clock.n = limit->n.min; |
| 662 | clock.n <= limit->n.max; clock.n++) { |
| 663 | for (clock.p1 = limit->p1.min; |
| 664 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 665 | int this_err; |
| 666 | |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 667 | intel_clock(dev, refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 668 | if (!intel_PLL_is_valid(dev, limit, |
| 669 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 670 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 671 | if (match_clock && |
| 672 | clock.p != match_clock->p) |
| 673 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 674 | |
| 675 | this_err = abs(clock.dot - target); |
| 676 | if (this_err < err) { |
| 677 | *best_clock = clock; |
| 678 | err = this_err; |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | } |
| 683 | } |
| 684 | |
| 685 | return (err != target); |
| 686 | } |
| 687 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 688 | static bool |
| 689 | intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 690 | int target, int refclk, intel_clock_t *match_clock, |
| 691 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 692 | { |
| 693 | struct drm_device *dev = crtc->dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 694 | intel_clock_t clock; |
| 695 | int max_n; |
| 696 | bool found; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 697 | /* approximately equals target * 0.00585 */ |
| 698 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 699 | found = false; |
| 700 | |
| 701 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 702 | int lvds_reg; |
| 703 | |
Eric Anholt | c619eed | 2010-01-28 16:45:52 -0800 | [diff] [blame] | 704 | if (HAS_PCH_SPLIT(dev)) |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 705 | lvds_reg = PCH_LVDS; |
| 706 | else |
| 707 | lvds_reg = LVDS; |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 708 | if (intel_is_dual_link_lvds(dev)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 709 | clock.p2 = limit->p2.p2_fast; |
| 710 | else |
| 711 | clock.p2 = limit->p2.p2_slow; |
| 712 | } else { |
| 713 | if (target < limit->p2.dot_limit) |
| 714 | clock.p2 = limit->p2.p2_slow; |
| 715 | else |
| 716 | clock.p2 = limit->p2.p2_fast; |
| 717 | } |
| 718 | |
| 719 | memset(best_clock, 0, sizeof(*best_clock)); |
| 720 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 721 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 722 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 723 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 724 | for (clock.m1 = limit->m1.max; |
| 725 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 726 | for (clock.m2 = limit->m2.max; |
| 727 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 728 | for (clock.p1 = limit->p1.max; |
| 729 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 730 | int this_err; |
| 731 | |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 732 | intel_clock(dev, refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 733 | if (!intel_PLL_is_valid(dev, limit, |
| 734 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 735 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 736 | if (match_clock && |
| 737 | clock.p != match_clock->p) |
| 738 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 739 | |
| 740 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 741 | if (this_err < err_most) { |
| 742 | *best_clock = clock; |
| 743 | err_most = this_err; |
| 744 | max_n = clock.n; |
| 745 | found = true; |
| 746 | } |
| 747 | } |
| 748 | } |
| 749 | } |
| 750 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 751 | return found; |
| 752 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 753 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 754 | static bool |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 755 | intel_find_pll_ironlake_dp(const intel_limit_t *limit, struct drm_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 756 | int target, int refclk, intel_clock_t *match_clock, |
| 757 | intel_clock_t *best_clock) |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 758 | { |
| 759 | struct drm_device *dev = crtc->dev; |
| 760 | intel_clock_t clock; |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 761 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 762 | if (target < 200000) { |
| 763 | clock.n = 1; |
| 764 | clock.p1 = 2; |
| 765 | clock.p2 = 10; |
| 766 | clock.m1 = 12; |
| 767 | clock.m2 = 9; |
| 768 | } else { |
| 769 | clock.n = 2; |
| 770 | clock.p1 = 1; |
| 771 | clock.p2 = 10; |
| 772 | clock.m1 = 14; |
| 773 | clock.m2 = 8; |
| 774 | } |
| 775 | intel_clock(dev, refclk, &clock); |
| 776 | memcpy(best_clock, &clock, sizeof(intel_clock_t)); |
| 777 | return true; |
| 778 | } |
| 779 | |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 780 | /* DisplayPort has only two frequencies, 162MHz and 270MHz */ |
| 781 | static bool |
| 782 | intel_find_pll_g4x_dp(const intel_limit_t *limit, struct drm_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 783 | int target, int refclk, intel_clock_t *match_clock, |
| 784 | intel_clock_t *best_clock) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 785 | { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 786 | intel_clock_t clock; |
| 787 | if (target < 200000) { |
| 788 | clock.p1 = 2; |
| 789 | clock.p2 = 10; |
| 790 | clock.n = 2; |
| 791 | clock.m1 = 23; |
| 792 | clock.m2 = 8; |
| 793 | } else { |
| 794 | clock.p1 = 1; |
| 795 | clock.p2 = 10; |
| 796 | clock.n = 1; |
| 797 | clock.m1 = 14; |
| 798 | clock.m2 = 2; |
| 799 | } |
| 800 | clock.m = 5 * (clock.m1 + 2) + (clock.m2 + 2); |
| 801 | clock.p = (clock.p1 * clock.p2); |
| 802 | clock.dot = 96000 * clock.m / (clock.n + 2) / clock.p; |
| 803 | clock.vco = 0; |
| 804 | memcpy(best_clock, &clock, sizeof(intel_clock_t)); |
| 805 | return true; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 806 | } |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 807 | static bool |
| 808 | intel_vlv_find_best_pll(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 809 | int target, int refclk, intel_clock_t *match_clock, |
| 810 | intel_clock_t *best_clock) |
| 811 | { |
| 812 | u32 p1, p2, m1, m2, vco, bestn, bestm1, bestm2, bestp1, bestp2; |
| 813 | u32 m, n, fastclk; |
| 814 | u32 updrate, minupdate, fracbits, p; |
| 815 | unsigned long bestppm, ppm, absppm; |
| 816 | int dotclk, flag; |
| 817 | |
Alan Cox | af447bd | 2012-07-25 13:49:18 +0100 | [diff] [blame] | 818 | flag = 0; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 819 | dotclk = target * 1000; |
| 820 | bestppm = 1000000; |
| 821 | ppm = absppm = 0; |
| 822 | fastclk = dotclk / (2*100); |
| 823 | updrate = 0; |
| 824 | minupdate = 19200; |
| 825 | fracbits = 1; |
| 826 | n = p = p1 = p2 = m = m1 = m2 = vco = bestn = 0; |
| 827 | bestm1 = bestm2 = bestp1 = bestp2 = 0; |
| 828 | |
| 829 | /* based on hardware requirement, prefer smaller n to precision */ |
| 830 | for (n = limit->n.min; n <= ((refclk) / minupdate); n++) { |
| 831 | updrate = refclk / n; |
| 832 | for (p1 = limit->p1.max; p1 > limit->p1.min; p1--) { |
| 833 | for (p2 = limit->p2.p2_fast+1; p2 > 0; p2--) { |
| 834 | if (p2 > 10) |
| 835 | p2 = p2 - 1; |
| 836 | p = p1 * p2; |
| 837 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
| 838 | for (m1 = limit->m1.min; m1 <= limit->m1.max; m1++) { |
| 839 | m2 = (((2*(fastclk * p * n / m1 )) + |
| 840 | refclk) / (2*refclk)); |
| 841 | m = m1 * m2; |
| 842 | vco = updrate * m; |
| 843 | if (vco >= limit->vco.min && vco < limit->vco.max) { |
| 844 | ppm = 1000000 * ((vco / p) - fastclk) / fastclk; |
| 845 | absppm = (ppm > 0) ? ppm : (-ppm); |
| 846 | if (absppm < 100 && ((p1 * p2) > (bestp1 * bestp2))) { |
| 847 | bestppm = 0; |
| 848 | flag = 1; |
| 849 | } |
| 850 | if (absppm < bestppm - 10) { |
| 851 | bestppm = absppm; |
| 852 | flag = 1; |
| 853 | } |
| 854 | if (flag) { |
| 855 | bestn = n; |
| 856 | bestm1 = m1; |
| 857 | bestm2 = m2; |
| 858 | bestp1 = p1; |
| 859 | bestp2 = p2; |
| 860 | flag = 0; |
| 861 | } |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | } |
| 866 | } |
| 867 | best_clock->n = bestn; |
| 868 | best_clock->m1 = bestm1; |
| 869 | best_clock->m2 = bestm2; |
| 870 | best_clock->p1 = bestp1; |
| 871 | best_clock->p2 = bestp2; |
| 872 | |
| 873 | return true; |
| 874 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 875 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 876 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 877 | enum pipe pipe) |
| 878 | { |
| 879 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 880 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 881 | |
| 882 | return intel_crtc->cpu_transcoder; |
| 883 | } |
| 884 | |
Paulo Zanoni | a928d53 | 2012-05-04 17:18:15 -0300 | [diff] [blame] | 885 | static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe) |
| 886 | { |
| 887 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 888 | u32 frame, frame_reg = PIPEFRAME(pipe); |
| 889 | |
| 890 | frame = I915_READ(frame_reg); |
| 891 | |
| 892 | if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50)) |
| 893 | DRM_DEBUG_KMS("vblank wait timed out\n"); |
| 894 | } |
| 895 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 896 | /** |
| 897 | * intel_wait_for_vblank - wait for vblank on a given pipe |
| 898 | * @dev: drm device |
| 899 | * @pipe: pipe to wait for |
| 900 | * |
| 901 | * Wait for vblank to occur on a given pipe. Needed for various bits of |
| 902 | * mode setting code. |
| 903 | */ |
| 904 | void intel_wait_for_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 905 | { |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 906 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 907 | int pipestat_reg = PIPESTAT(pipe); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 908 | |
Paulo Zanoni | a928d53 | 2012-05-04 17:18:15 -0300 | [diff] [blame] | 909 | if (INTEL_INFO(dev)->gen >= 5) { |
| 910 | ironlake_wait_for_vblank(dev, pipe); |
| 911 | return; |
| 912 | } |
| 913 | |
Chris Wilson | 300387c | 2010-09-05 20:25:43 +0100 | [diff] [blame] | 914 | /* Clear existing vblank status. Note this will clear any other |
| 915 | * sticky status fields as well. |
| 916 | * |
| 917 | * This races with i915_driver_irq_handler() with the result |
| 918 | * that either function could miss a vblank event. Here it is not |
| 919 | * fatal, as we will either wait upon the next vblank interrupt or |
| 920 | * timeout. Generally speaking intel_wait_for_vblank() is only |
| 921 | * called during modeset at which time the GPU should be idle and |
| 922 | * should *not* be performing page flips and thus not waiting on |
| 923 | * vblanks... |
| 924 | * Currently, the result of us stealing a vblank from the irq |
| 925 | * handler is that a single frame will be skipped during swapbuffers. |
| 926 | */ |
| 927 | I915_WRITE(pipestat_reg, |
| 928 | I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS); |
| 929 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 930 | /* Wait for vblank interrupt bit to set */ |
Chris Wilson | 481b6af | 2010-08-23 17:43:35 +0100 | [diff] [blame] | 931 | if (wait_for(I915_READ(pipestat_reg) & |
| 932 | PIPE_VBLANK_INTERRUPT_STATUS, |
| 933 | 50)) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 934 | DRM_DEBUG_KMS("vblank wait timed out\n"); |
| 935 | } |
| 936 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 937 | /* |
| 938 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 939 | * @dev: drm device |
| 940 | * @pipe: pipe to wait for |
| 941 | * |
| 942 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 943 | * spinning on the vblank interrupt status bit, since we won't actually |
| 944 | * see an interrupt when the pipe is disabled. |
| 945 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 946 | * On Gen4 and above: |
| 947 | * wait for the pipe register state bit to turn off |
| 948 | * |
| 949 | * Otherwise: |
| 950 | * wait for the display line value to settle (it usually |
| 951 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 952 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 953 | */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 954 | void intel_wait_for_pipe_off(struct drm_device *dev, int pipe) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 955 | { |
| 956 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 957 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 958 | pipe); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 959 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 960 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 961 | int reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 962 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 963 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 964 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 965 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 966 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 967 | } else { |
Paulo Zanoni | 837ba00 | 2012-05-04 17:18:14 -0300 | [diff] [blame] | 968 | u32 last_line, line_mask; |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 969 | int reg = PIPEDSL(pipe); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 970 | unsigned long timeout = jiffies + msecs_to_jiffies(100); |
| 971 | |
Paulo Zanoni | 837ba00 | 2012-05-04 17:18:14 -0300 | [diff] [blame] | 972 | if (IS_GEN2(dev)) |
| 973 | line_mask = DSL_LINEMASK_GEN2; |
| 974 | else |
| 975 | line_mask = DSL_LINEMASK_GEN3; |
| 976 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 977 | /* Wait for the display line to settle */ |
| 978 | do { |
Paulo Zanoni | 837ba00 | 2012-05-04 17:18:14 -0300 | [diff] [blame] | 979 | last_line = I915_READ(reg) & line_mask; |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 980 | mdelay(5); |
Paulo Zanoni | 837ba00 | 2012-05-04 17:18:14 -0300 | [diff] [blame] | 981 | } while (((I915_READ(reg) & line_mask) != last_line) && |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 982 | time_after(timeout, jiffies)); |
| 983 | if (time_after(jiffies, timeout)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 984 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 985 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 986 | } |
| 987 | |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 988 | /* |
| 989 | * ibx_digital_port_connected - is the specified port connected? |
| 990 | * @dev_priv: i915 private structure |
| 991 | * @port: the port to test |
| 992 | * |
| 993 | * Returns true if @port is connected, false otherwise. |
| 994 | */ |
| 995 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 996 | struct intel_digital_port *port) |
| 997 | { |
| 998 | u32 bit; |
| 999 | |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1000 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1001 | switch(port->port) { |
| 1002 | case PORT_B: |
| 1003 | bit = SDE_PORTB_HOTPLUG; |
| 1004 | break; |
| 1005 | case PORT_C: |
| 1006 | bit = SDE_PORTC_HOTPLUG; |
| 1007 | break; |
| 1008 | case PORT_D: |
| 1009 | bit = SDE_PORTD_HOTPLUG; |
| 1010 | break; |
| 1011 | default: |
| 1012 | return true; |
| 1013 | } |
| 1014 | } else { |
| 1015 | switch(port->port) { |
| 1016 | case PORT_B: |
| 1017 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 1018 | break; |
| 1019 | case PORT_C: |
| 1020 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 1021 | break; |
| 1022 | case PORT_D: |
| 1023 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 1024 | break; |
| 1025 | default: |
| 1026 | return true; |
| 1027 | } |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | return I915_READ(SDEISR) & bit; |
| 1031 | } |
| 1032 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1033 | static const char *state_string(bool enabled) |
| 1034 | { |
| 1035 | return enabled ? "on" : "off"; |
| 1036 | } |
| 1037 | |
| 1038 | /* Only for pre-ILK configs */ |
| 1039 | static void assert_pll(struct drm_i915_private *dev_priv, |
| 1040 | enum pipe pipe, bool state) |
| 1041 | { |
| 1042 | int reg; |
| 1043 | u32 val; |
| 1044 | bool cur_state; |
| 1045 | |
| 1046 | reg = DPLL(pipe); |
| 1047 | val = I915_READ(reg); |
| 1048 | cur_state = !!(val & DPLL_VCO_ENABLE); |
| 1049 | WARN(cur_state != state, |
| 1050 | "PLL state assertion failure (expected %s, current %s)\n", |
| 1051 | state_string(state), state_string(cur_state)); |
| 1052 | } |
| 1053 | #define assert_pll_enabled(d, p) assert_pll(d, p, true) |
| 1054 | #define assert_pll_disabled(d, p) assert_pll(d, p, false) |
| 1055 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1056 | /* For ILK+ */ |
| 1057 | static void assert_pch_pll(struct drm_i915_private *dev_priv, |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1058 | struct intel_pch_pll *pll, |
| 1059 | struct intel_crtc *crtc, |
| 1060 | bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1061 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1062 | u32 val; |
| 1063 | bool cur_state; |
| 1064 | |
Eugeni Dodonov | 9d82aa1 | 2012-05-09 15:37:17 -0300 | [diff] [blame] | 1065 | if (HAS_PCH_LPT(dev_priv->dev)) { |
| 1066 | DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n"); |
| 1067 | return; |
| 1068 | } |
| 1069 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1070 | if (WARN (!pll, |
| 1071 | "asserting PCH PLL %s with no PLL\n", state_string(state))) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1072 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1073 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1074 | val = I915_READ(pll->pll_reg); |
| 1075 | cur_state = !!(val & DPLL_VCO_ENABLE); |
| 1076 | WARN(cur_state != state, |
| 1077 | "PCH PLL state for reg %x assertion failure (expected %s, current %s), val=%08x\n", |
| 1078 | pll->pll_reg, state_string(state), state_string(cur_state), val); |
| 1079 | |
| 1080 | /* Make sure the selected PLL is correctly attached to the transcoder */ |
| 1081 | if (crtc && HAS_PCH_CPT(dev_priv->dev)) { |
Jesse Barnes | d3ccbe8 | 2011-10-12 09:27:42 -0700 | [diff] [blame] | 1082 | u32 pch_dpll; |
| 1083 | |
| 1084 | pch_dpll = I915_READ(PCH_DPLL_SEL); |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1085 | cur_state = pll->pll_reg == _PCH_DPLL_B; |
| 1086 | if (!WARN(((pch_dpll >> (4 * crtc->pipe)) & 1) != cur_state, |
| 1087 | "PLL[%d] not attached to this transcoder %d: %08x\n", |
| 1088 | cur_state, crtc->pipe, pch_dpll)) { |
| 1089 | cur_state = !!(val >> (4*crtc->pipe + 3)); |
| 1090 | WARN(cur_state != state, |
| 1091 | "PLL[%d] not %s on this transcoder %d: %08x\n", |
| 1092 | pll->pll_reg == _PCH_DPLL_B, |
| 1093 | state_string(state), |
| 1094 | crtc->pipe, |
| 1095 | val); |
| 1096 | } |
Jesse Barnes | d3ccbe8 | 2011-10-12 09:27:42 -0700 | [diff] [blame] | 1097 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1098 | } |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1099 | #define assert_pch_pll_enabled(d, p, c) assert_pch_pll(d, p, c, true) |
| 1100 | #define assert_pch_pll_disabled(d, p, c) assert_pch_pll(d, p, c, false) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1101 | |
| 1102 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1103 | enum pipe pipe, bool state) |
| 1104 | { |
| 1105 | int reg; |
| 1106 | u32 val; |
| 1107 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1108 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1109 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1110 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1111 | if (HAS_DDI(dev_priv->dev)) { |
| 1112 | /* DDI does not have a specific FDI_TX register */ |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1113 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1114 | val = I915_READ(reg); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1115 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1116 | } else { |
| 1117 | reg = FDI_TX_CTL(pipe); |
| 1118 | val = I915_READ(reg); |
| 1119 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1120 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1121 | WARN(cur_state != state, |
| 1122 | "FDI TX state assertion failure (expected %s, current %s)\n", |
| 1123 | state_string(state), state_string(cur_state)); |
| 1124 | } |
| 1125 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1126 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1127 | |
| 1128 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1129 | enum pipe pipe, bool state) |
| 1130 | { |
| 1131 | int reg; |
| 1132 | u32 val; |
| 1133 | bool cur_state; |
| 1134 | |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1135 | reg = FDI_RX_CTL(pipe); |
| 1136 | val = I915_READ(reg); |
| 1137 | cur_state = !!(val & FDI_RX_ENABLE); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1138 | WARN(cur_state != state, |
| 1139 | "FDI RX state assertion failure (expected %s, current %s)\n", |
| 1140 | state_string(state), state_string(cur_state)); |
| 1141 | } |
| 1142 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1143 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1144 | |
| 1145 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1146 | enum pipe pipe) |
| 1147 | { |
| 1148 | int reg; |
| 1149 | u32 val; |
| 1150 | |
| 1151 | /* ILK FDI PLL is always enabled */ |
| 1152 | if (dev_priv->info->gen == 5) |
| 1153 | return; |
| 1154 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1155 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1156 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1157 | return; |
| 1158 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1159 | reg = FDI_TX_CTL(pipe); |
| 1160 | val = I915_READ(reg); |
| 1161 | WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
| 1162 | } |
| 1163 | |
| 1164 | static void assert_fdi_rx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1165 | enum pipe pipe) |
| 1166 | { |
| 1167 | int reg; |
| 1168 | u32 val; |
| 1169 | |
| 1170 | reg = FDI_RX_CTL(pipe); |
| 1171 | val = I915_READ(reg); |
| 1172 | WARN(!(val & FDI_RX_PLL_ENABLE), "FDI RX PLL assertion failure, should be active but is disabled\n"); |
| 1173 | } |
| 1174 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1175 | static void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1176 | enum pipe pipe) |
| 1177 | { |
| 1178 | int pp_reg, lvds_reg; |
| 1179 | u32 val; |
| 1180 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1181 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1182 | |
| 1183 | if (HAS_PCH_SPLIT(dev_priv->dev)) { |
| 1184 | pp_reg = PCH_PP_CONTROL; |
| 1185 | lvds_reg = PCH_LVDS; |
| 1186 | } else { |
| 1187 | pp_reg = PP_CONTROL; |
| 1188 | lvds_reg = LVDS; |
| 1189 | } |
| 1190 | |
| 1191 | val = I915_READ(pp_reg); |
| 1192 | if (!(val & PANEL_POWER_ON) || |
| 1193 | ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS)) |
| 1194 | locked = false; |
| 1195 | |
| 1196 | if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT) |
| 1197 | panel_pipe = PIPE_B; |
| 1198 | |
| 1199 | WARN(panel_pipe == pipe && locked, |
| 1200 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1201 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1202 | } |
| 1203 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1204 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1205 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1206 | { |
| 1207 | int reg; |
| 1208 | u32 val; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1209 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1210 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1211 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1212 | |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1213 | /* if we need the pipe A quirk it must be always on */ |
| 1214 | if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) |
| 1215 | state = true; |
| 1216 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1217 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1218 | val = I915_READ(reg); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1219 | cur_state = !!(val & PIPECONF_ENABLE); |
| 1220 | WARN(cur_state != state, |
| 1221 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1222 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1223 | } |
| 1224 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1225 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1226 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1227 | { |
| 1228 | int reg; |
| 1229 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1230 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1231 | |
| 1232 | reg = DSPCNTR(plane); |
| 1233 | val = I915_READ(reg); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1234 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
| 1235 | WARN(cur_state != state, |
| 1236 | "plane %c assertion failure (expected %s, current %s)\n", |
| 1237 | plane_name(plane), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1238 | } |
| 1239 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1240 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1241 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1242 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1243 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1244 | enum pipe pipe) |
| 1245 | { |
| 1246 | int reg, i; |
| 1247 | u32 val; |
| 1248 | int cur_pipe; |
| 1249 | |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1250 | /* Planes are fixed to pipes on ILK+ */ |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1251 | if (HAS_PCH_SPLIT(dev_priv->dev)) { |
| 1252 | reg = DSPCNTR(pipe); |
| 1253 | val = I915_READ(reg); |
| 1254 | WARN((val & DISPLAY_PLANE_ENABLE), |
| 1255 | "plane %c assertion failure, should be disabled but not\n", |
| 1256 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1257 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1258 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1259 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1260 | /* Need to check both planes against the pipe */ |
| 1261 | for (i = 0; i < 2; i++) { |
| 1262 | reg = DSPCNTR(i); |
| 1263 | val = I915_READ(reg); |
| 1264 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 1265 | DISPPLANE_SEL_PIPE_SHIFT; |
| 1266 | WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1267 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1268 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1269 | } |
| 1270 | } |
| 1271 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1272 | static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
| 1273 | { |
| 1274 | u32 val; |
| 1275 | bool enabled; |
| 1276 | |
Eugeni Dodonov | 9d82aa1 | 2012-05-09 15:37:17 -0300 | [diff] [blame] | 1277 | if (HAS_PCH_LPT(dev_priv->dev)) { |
| 1278 | DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n"); |
| 1279 | return; |
| 1280 | } |
| 1281 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1282 | val = I915_READ(PCH_DREF_CONTROL); |
| 1283 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | |
| 1284 | DREF_SUPERSPREAD_SOURCE_MASK)); |
| 1285 | WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
| 1286 | } |
| 1287 | |
| 1288 | static void assert_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1289 | enum pipe pipe) |
| 1290 | { |
| 1291 | int reg; |
| 1292 | u32 val; |
| 1293 | bool enabled; |
| 1294 | |
| 1295 | reg = TRANSCONF(pipe); |
| 1296 | val = I915_READ(reg); |
| 1297 | enabled = !!(val & TRANS_ENABLE); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1298 | WARN(enabled, |
| 1299 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1300 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1301 | } |
| 1302 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1303 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1304 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1305 | { |
| 1306 | if ((val & DP_PORT_EN) == 0) |
| 1307 | return false; |
| 1308 | |
| 1309 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1310 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); |
| 1311 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); |
| 1312 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1313 | return false; |
| 1314 | } else { |
| 1315 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1316 | return false; |
| 1317 | } |
| 1318 | return true; |
| 1319 | } |
| 1320 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1321 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1322 | enum pipe pipe, u32 val) |
| 1323 | { |
| 1324 | if ((val & PORT_ENABLE) == 0) |
| 1325 | return false; |
| 1326 | |
| 1327 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1328 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1329 | return false; |
| 1330 | } else { |
| 1331 | if ((val & TRANSCODER_MASK) != TRANSCODER(pipe)) |
| 1332 | return false; |
| 1333 | } |
| 1334 | return true; |
| 1335 | } |
| 1336 | |
| 1337 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1338 | enum pipe pipe, u32 val) |
| 1339 | { |
| 1340 | if ((val & LVDS_PORT_EN) == 0) |
| 1341 | return false; |
| 1342 | |
| 1343 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1344 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1345 | return false; |
| 1346 | } else { |
| 1347 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1348 | return false; |
| 1349 | } |
| 1350 | return true; |
| 1351 | } |
| 1352 | |
| 1353 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1354 | enum pipe pipe, u32 val) |
| 1355 | { |
| 1356 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1357 | return false; |
| 1358 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1359 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1360 | return false; |
| 1361 | } else { |
| 1362 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1363 | return false; |
| 1364 | } |
| 1365 | return true; |
| 1366 | } |
| 1367 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1368 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1369 | enum pipe pipe, int reg, u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1370 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1371 | u32 val = I915_READ(reg); |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1372 | WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1373 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1374 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1375 | |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1376 | WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
| 1377 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1378 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1379 | } |
| 1380 | |
| 1381 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
| 1382 | enum pipe pipe, int reg) |
| 1383 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1384 | u32 val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1385 | WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1386 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1387 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1388 | |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1389 | WARN(HAS_PCH_IBX(dev_priv->dev) && (val & PORT_ENABLE) == 0 |
| 1390 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1391 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1395 | enum pipe pipe) |
| 1396 | { |
| 1397 | int reg; |
| 1398 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1399 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1400 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1401 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1402 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_D, TRANS_DP_PORT_SEL_D); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1403 | |
| 1404 | reg = PCH_ADPA; |
| 1405 | val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1406 | WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1407 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1408 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1409 | |
| 1410 | reg = PCH_LVDS; |
| 1411 | val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1412 | WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1413 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1414 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1415 | |
| 1416 | assert_pch_hdmi_disabled(dev_priv, pipe, HDMIB); |
| 1417 | assert_pch_hdmi_disabled(dev_priv, pipe, HDMIC); |
| 1418 | assert_pch_hdmi_disabled(dev_priv, pipe, HDMID); |
| 1419 | } |
| 1420 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1421 | /** |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1422 | * intel_enable_pll - enable a PLL |
| 1423 | * @dev_priv: i915 private structure |
| 1424 | * @pipe: pipe PLL to enable |
| 1425 | * |
| 1426 | * Enable @pipe's PLL so we can start pumping pixels from a plane. Check to |
| 1427 | * make sure the PLL reg is writable first though, since the panel write |
| 1428 | * protect mechanism may be enabled. |
| 1429 | * |
| 1430 | * Note! This is for pre-ILK only. |
Thomas Richter | 7434a25 | 2012-07-18 19:22:30 +0200 | [diff] [blame] | 1431 | * |
| 1432 | * Unfortunately needed by dvo_ns2501 since the dvo depends on it running. |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1433 | */ |
| 1434 | static void intel_enable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1435 | { |
| 1436 | int reg; |
| 1437 | u32 val; |
| 1438 | |
| 1439 | /* No really, not for ILK+ */ |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 1440 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev) && dev_priv->info->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1441 | |
| 1442 | /* PLL is protected by panel, make sure we can write it */ |
| 1443 | if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev)) |
| 1444 | assert_panel_unlocked(dev_priv, pipe); |
| 1445 | |
| 1446 | reg = DPLL(pipe); |
| 1447 | val = I915_READ(reg); |
| 1448 | val |= DPLL_VCO_ENABLE; |
| 1449 | |
| 1450 | /* We do this three times for luck */ |
| 1451 | I915_WRITE(reg, val); |
| 1452 | POSTING_READ(reg); |
| 1453 | udelay(150); /* wait for warmup */ |
| 1454 | I915_WRITE(reg, val); |
| 1455 | POSTING_READ(reg); |
| 1456 | udelay(150); /* wait for warmup */ |
| 1457 | I915_WRITE(reg, val); |
| 1458 | POSTING_READ(reg); |
| 1459 | udelay(150); /* wait for warmup */ |
| 1460 | } |
| 1461 | |
| 1462 | /** |
| 1463 | * intel_disable_pll - disable a PLL |
| 1464 | * @dev_priv: i915 private structure |
| 1465 | * @pipe: pipe PLL to disable |
| 1466 | * |
| 1467 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1468 | * |
| 1469 | * Note! This is for pre-ILK only. |
| 1470 | */ |
| 1471 | static void intel_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1472 | { |
| 1473 | int reg; |
| 1474 | u32 val; |
| 1475 | |
| 1476 | /* Don't disable pipe A or pipe A PLLs if needed */ |
| 1477 | if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE)) |
| 1478 | return; |
| 1479 | |
| 1480 | /* Make sure the pipe isn't still relying on us */ |
| 1481 | assert_pipe_disabled(dev_priv, pipe); |
| 1482 | |
| 1483 | reg = DPLL(pipe); |
| 1484 | val = I915_READ(reg); |
| 1485 | val &= ~DPLL_VCO_ENABLE; |
| 1486 | I915_WRITE(reg, val); |
| 1487 | POSTING_READ(reg); |
| 1488 | } |
| 1489 | |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1490 | /* SBI access */ |
| 1491 | static void |
| 1492 | intel_sbi_write(struct drm_i915_private *dev_priv, u16 reg, u32 value) |
| 1493 | { |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 1494 | WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock)); |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1495 | |
Eugeni Dodonov | 39fb50f | 2012-06-08 16:43:19 -0300 | [diff] [blame] | 1496 | if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0, |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1497 | 100)) { |
| 1498 | DRM_ERROR("timeout waiting for SBI to become ready\n"); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 1499 | return; |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | I915_WRITE(SBI_ADDR, |
| 1503 | (reg << 16)); |
| 1504 | I915_WRITE(SBI_DATA, |
| 1505 | value); |
| 1506 | I915_WRITE(SBI_CTL_STAT, |
| 1507 | SBI_BUSY | |
| 1508 | SBI_CTL_OP_CRWR); |
| 1509 | |
Eugeni Dodonov | 39fb50f | 2012-06-08 16:43:19 -0300 | [diff] [blame] | 1510 | if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0, |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1511 | 100)) { |
| 1512 | DRM_ERROR("timeout waiting for SBI to complete write transaction\n"); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 1513 | return; |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1514 | } |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1515 | } |
| 1516 | |
| 1517 | static u32 |
| 1518 | intel_sbi_read(struct drm_i915_private *dev_priv, u16 reg) |
| 1519 | { |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 1520 | WARN_ON(!mutex_is_locked(&dev_priv->dpio_lock)); |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1521 | |
Eugeni Dodonov | 39fb50f | 2012-06-08 16:43:19 -0300 | [diff] [blame] | 1522 | if (wait_for((I915_READ(SBI_CTL_STAT) & SBI_BUSY) == 0, |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1523 | 100)) { |
| 1524 | DRM_ERROR("timeout waiting for SBI to become ready\n"); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 1525 | return 0; |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1526 | } |
| 1527 | |
| 1528 | I915_WRITE(SBI_ADDR, |
| 1529 | (reg << 16)); |
| 1530 | I915_WRITE(SBI_CTL_STAT, |
| 1531 | SBI_BUSY | |
| 1532 | SBI_CTL_OP_CRRD); |
| 1533 | |
Eugeni Dodonov | 39fb50f | 2012-06-08 16:43:19 -0300 | [diff] [blame] | 1534 | if (wait_for((I915_READ(SBI_CTL_STAT) & (SBI_BUSY | SBI_RESPONSE_FAIL)) == 0, |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1535 | 100)) { |
| 1536 | DRM_ERROR("timeout waiting for SBI to complete read transaction\n"); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 1537 | return 0; |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1538 | } |
| 1539 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 1540 | return I915_READ(SBI_DATA); |
Eugeni Dodonov | a416ede | 2012-05-09 15:37:10 -0300 | [diff] [blame] | 1541 | } |
| 1542 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1543 | /** |
Paulo Zanoni | b6b4e18 | 2012-10-31 18:12:38 -0200 | [diff] [blame] | 1544 | * ironlake_enable_pch_pll - enable PCH PLL |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1545 | * @dev_priv: i915 private structure |
| 1546 | * @pipe: pipe PLL to enable |
| 1547 | * |
| 1548 | * The PCH PLL needs to be enabled before the PCH transcoder, since it |
| 1549 | * drives the transcoder clock. |
| 1550 | */ |
Paulo Zanoni | b6b4e18 | 2012-10-31 18:12:38 -0200 | [diff] [blame] | 1551 | static void ironlake_enable_pch_pll(struct intel_crtc *intel_crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1552 | { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1553 | struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private; |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1554 | struct intel_pch_pll *pll; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1555 | int reg; |
| 1556 | u32 val; |
| 1557 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1558 | /* PCH PLLs only available on ILK, SNB and IVB */ |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1559 | BUG_ON(dev_priv->info->gen < 5); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1560 | pll = intel_crtc->pch_pll; |
| 1561 | if (pll == NULL) |
| 1562 | return; |
| 1563 | |
| 1564 | if (WARN_ON(pll->refcount == 0)) |
| 1565 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1566 | |
| 1567 | DRM_DEBUG_KMS("enable PCH PLL %x (active %d, on? %d)for crtc %d\n", |
| 1568 | pll->pll_reg, pll->active, pll->on, |
| 1569 | intel_crtc->base.base.id); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1570 | |
| 1571 | /* PCH refclock must be enabled first */ |
| 1572 | assert_pch_refclk_enabled(dev_priv); |
| 1573 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1574 | if (pll->active++ && pll->on) { |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1575 | assert_pch_pll_enabled(dev_priv, pll, NULL); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1576 | return; |
| 1577 | } |
| 1578 | |
| 1579 | DRM_DEBUG_KMS("enabling PCH PLL %x\n", pll->pll_reg); |
| 1580 | |
| 1581 | reg = pll->pll_reg; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1582 | val = I915_READ(reg); |
| 1583 | val |= DPLL_VCO_ENABLE; |
| 1584 | I915_WRITE(reg, val); |
| 1585 | POSTING_READ(reg); |
| 1586 | udelay(200); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1587 | |
| 1588 | pll->on = true; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1589 | } |
| 1590 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1591 | static void intel_disable_pch_pll(struct intel_crtc *intel_crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1592 | { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1593 | struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private; |
| 1594 | struct intel_pch_pll *pll = intel_crtc->pch_pll; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1595 | int reg; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1596 | u32 val; |
Jesse Barnes | 4c609cb | 2011-09-02 12:52:11 -0700 | [diff] [blame] | 1597 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1598 | /* PCH only available on ILK+ */ |
| 1599 | BUG_ON(dev_priv->info->gen < 5); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1600 | if (pll == NULL) |
| 1601 | return; |
| 1602 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1603 | if (WARN_ON(pll->refcount == 0)) |
| 1604 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1605 | |
| 1606 | DRM_DEBUG_KMS("disable PCH PLL %x (active %d, on? %d) for crtc %d\n", |
| 1607 | pll->pll_reg, pll->active, pll->on, |
| 1608 | intel_crtc->base.base.id); |
| 1609 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1610 | if (WARN_ON(pll->active == 0)) { |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1611 | assert_pch_pll_disabled(dev_priv, pll, NULL); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1612 | return; |
| 1613 | } |
| 1614 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1615 | if (--pll->active) { |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1616 | assert_pch_pll_enabled(dev_priv, pll, NULL); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1617 | return; |
| 1618 | } |
| 1619 | |
| 1620 | DRM_DEBUG_KMS("disabling PCH PLL %x\n", pll->pll_reg); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1621 | |
| 1622 | /* Make sure transcoder isn't still depending on us */ |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1623 | assert_transcoder_disabled(dev_priv, intel_crtc->pipe); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1624 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1625 | reg = pll->pll_reg; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1626 | val = I915_READ(reg); |
| 1627 | val &= ~DPLL_VCO_ENABLE; |
| 1628 | I915_WRITE(reg, val); |
| 1629 | POSTING_READ(reg); |
| 1630 | udelay(200); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1631 | |
| 1632 | pll->on = false; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1633 | } |
| 1634 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1635 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1636 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1637 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1638 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1639 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1640 | uint32_t reg, val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1641 | |
| 1642 | /* PCH only available on ILK+ */ |
| 1643 | BUG_ON(dev_priv->info->gen < 5); |
| 1644 | |
| 1645 | /* Make sure PCH DPLL is enabled */ |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1646 | assert_pch_pll_enabled(dev_priv, |
| 1647 | to_intel_crtc(crtc)->pch_pll, |
| 1648 | to_intel_crtc(crtc)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1649 | |
| 1650 | /* FDI must be feeding us bits for PCH ports */ |
| 1651 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1652 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1653 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1654 | if (HAS_PCH_CPT(dev)) { |
| 1655 | /* Workaround: Set the timing override bit before enabling the |
| 1656 | * pch transcoder. */ |
| 1657 | reg = TRANS_CHICKEN2(pipe); |
| 1658 | val = I915_READ(reg); |
| 1659 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1660 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1661 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1662 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1663 | reg = TRANSCONF(pipe); |
| 1664 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1665 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1666 | |
| 1667 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1668 | /* |
| 1669 | * make the BPC in transcoder be consistent with |
| 1670 | * that in pipeconf reg. |
| 1671 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1672 | val &= ~PIPECONF_BPC_MASK; |
| 1673 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1674 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1675 | |
| 1676 | val &= ~TRANS_INTERLACE_MASK; |
| 1677 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1678 | if (HAS_PCH_IBX(dev_priv->dev) && |
| 1679 | intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) |
| 1680 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1681 | else |
| 1682 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1683 | else |
| 1684 | val |= TRANS_PROGRESSIVE; |
| 1685 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1686 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1687 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
| 1688 | DRM_ERROR("failed to enable transcoder %d\n", pipe); |
| 1689 | } |
| 1690 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1691 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1692 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1693 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1694 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1695 | |
| 1696 | /* PCH only available on ILK+ */ |
| 1697 | BUG_ON(dev_priv->info->gen < 5); |
| 1698 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1699 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1700 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1701 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1702 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1703 | /* Workaround: set timing override bit. */ |
| 1704 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1705 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1706 | I915_WRITE(_TRANSA_CHICKEN2, val); |
| 1707 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1708 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1709 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1710 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1711 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1712 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1713 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1714 | else |
| 1715 | val |= TRANS_PROGRESSIVE; |
| 1716 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1717 | I915_WRITE(TRANSCONF(TRANSCODER_A), val); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1718 | if (wait_for(I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE, 100)) |
| 1719 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1720 | } |
| 1721 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1722 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1723 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1724 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1725 | struct drm_device *dev = dev_priv->dev; |
| 1726 | uint32_t reg, val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1727 | |
| 1728 | /* FDI relies on the transcoder */ |
| 1729 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1730 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1731 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1732 | /* Ports must be off as well */ |
| 1733 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1734 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1735 | reg = TRANSCONF(pipe); |
| 1736 | val = I915_READ(reg); |
| 1737 | val &= ~TRANS_ENABLE; |
| 1738 | I915_WRITE(reg, val); |
| 1739 | /* wait for PCH transcoder off, transcoder state */ |
| 1740 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Jesse Barnes | 4c9c18c | 2011-10-13 09:46:32 -0700 | [diff] [blame] | 1741 | DRM_ERROR("failed to disable transcoder %d\n", pipe); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1742 | |
| 1743 | if (!HAS_PCH_IBX(dev)) { |
| 1744 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1745 | reg = TRANS_CHICKEN2(pipe); |
| 1746 | val = I915_READ(reg); |
| 1747 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1748 | I915_WRITE(reg, val); |
| 1749 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1750 | } |
| 1751 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 1752 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1753 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1754 | u32 val; |
| 1755 | |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1756 | val = I915_READ(_TRANSACONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1757 | val &= ~TRANS_ENABLE; |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1758 | I915_WRITE(_TRANSACONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1759 | /* wait for PCH transcoder off, transcoder state */ |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1760 | if (wait_for((I915_READ(_TRANSACONF) & TRANS_STATE_ENABLE) == 0, 50)) |
| 1761 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1762 | |
| 1763 | /* Workaround: clear timing override bit. */ |
| 1764 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1765 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1766 | I915_WRITE(_TRANSA_CHICKEN2, val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1767 | } |
| 1768 | |
| 1769 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1770 | * intel_enable_pipe - enable a pipe, asserting requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1771 | * @dev_priv: i915 private structure |
| 1772 | * @pipe: pipe to enable |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1773 | * @pch_port: on ILK+, is this pipe driving a PCH port or not |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1774 | * |
| 1775 | * Enable @pipe, making sure that various hardware specific requirements |
| 1776 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
| 1777 | * |
| 1778 | * @pipe should be %PIPE_A or %PIPE_B. |
| 1779 | * |
| 1780 | * Will wait until the pipe is actually running (i.e. first vblank) before |
| 1781 | * returning. |
| 1782 | */ |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1783 | static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe, |
| 1784 | bool pch_port) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1785 | { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1786 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1787 | pipe); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1788 | enum pipe pch_transcoder; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1789 | int reg; |
| 1790 | u32 val; |
| 1791 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 1792 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1793 | pch_transcoder = TRANSCODER_A; |
| 1794 | else |
| 1795 | pch_transcoder = pipe; |
| 1796 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1797 | /* |
| 1798 | * A pipe without a PLL won't actually be able to drive bits from |
| 1799 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1800 | * need the check. |
| 1801 | */ |
| 1802 | if (!HAS_PCH_SPLIT(dev_priv->dev)) |
| 1803 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1804 | else { |
| 1805 | if (pch_port) { |
| 1806 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1807 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1808 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1809 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1810 | } |
| 1811 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1812 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1813 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1814 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1815 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1816 | if (val & PIPECONF_ENABLE) |
| 1817 | return; |
| 1818 | |
| 1819 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1820 | intel_wait_for_vblank(dev_priv->dev, pipe); |
| 1821 | } |
| 1822 | |
| 1823 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1824 | * intel_disable_pipe - disable a pipe, asserting requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1825 | * @dev_priv: i915 private structure |
| 1826 | * @pipe: pipe to disable |
| 1827 | * |
| 1828 | * Disable @pipe, making sure that various hardware specific requirements |
| 1829 | * are met, if applicable, e.g. plane disabled, panel fitter off, etc. |
| 1830 | * |
| 1831 | * @pipe should be %PIPE_A or %PIPE_B. |
| 1832 | * |
| 1833 | * Will wait until the pipe has shut down before returning. |
| 1834 | */ |
| 1835 | static void intel_disable_pipe(struct drm_i915_private *dev_priv, |
| 1836 | enum pipe pipe) |
| 1837 | { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1838 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1839 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1840 | int reg; |
| 1841 | u32 val; |
| 1842 | |
| 1843 | /* |
| 1844 | * Make sure planes won't keep trying to pump pixels to us, |
| 1845 | * or we might hang the display. |
| 1846 | */ |
| 1847 | assert_planes_disabled(dev_priv, pipe); |
| 1848 | |
| 1849 | /* Don't disable pipe A or pipe A PLLs if needed */ |
| 1850 | if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE)) |
| 1851 | return; |
| 1852 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1853 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1854 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1855 | if ((val & PIPECONF_ENABLE) == 0) |
| 1856 | return; |
| 1857 | |
| 1858 | I915_WRITE(reg, val & ~PIPECONF_ENABLE); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1859 | intel_wait_for_pipe_off(dev_priv->dev, pipe); |
| 1860 | } |
| 1861 | |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 1862 | /* |
| 1863 | * Plane regs are double buffered, going from enabled->disabled needs a |
| 1864 | * trigger in order to latch. The display address reg provides this. |
| 1865 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 1866 | void intel_flush_display_plane(struct drm_i915_private *dev_priv, |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 1867 | enum plane plane) |
| 1868 | { |
Damien Lespiau | 14f8614 | 2012-10-29 15:24:49 +0000 | [diff] [blame] | 1869 | if (dev_priv->info->gen >= 4) |
| 1870 | I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane))); |
| 1871 | else |
| 1872 | I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane))); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 1873 | } |
| 1874 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1875 | /** |
| 1876 | * intel_enable_plane - enable a display plane on a given pipe |
| 1877 | * @dev_priv: i915 private structure |
| 1878 | * @plane: plane to enable |
| 1879 | * @pipe: pipe being fed |
| 1880 | * |
| 1881 | * Enable @plane on @pipe, making sure that @pipe is running first. |
| 1882 | */ |
| 1883 | static void intel_enable_plane(struct drm_i915_private *dev_priv, |
| 1884 | enum plane plane, enum pipe pipe) |
| 1885 | { |
| 1886 | int reg; |
| 1887 | u32 val; |
| 1888 | |
| 1889 | /* If the pipe isn't enabled, we can't pump pixels and may hang */ |
| 1890 | assert_pipe_enabled(dev_priv, pipe); |
| 1891 | |
| 1892 | reg = DSPCNTR(plane); |
| 1893 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1894 | if (val & DISPLAY_PLANE_ENABLE) |
| 1895 | return; |
| 1896 | |
| 1897 | I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 1898 | intel_flush_display_plane(dev_priv, plane); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1899 | intel_wait_for_vblank(dev_priv->dev, pipe); |
| 1900 | } |
| 1901 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1902 | /** |
| 1903 | * intel_disable_plane - disable a display plane |
| 1904 | * @dev_priv: i915 private structure |
| 1905 | * @plane: plane to disable |
| 1906 | * @pipe: pipe consuming the data |
| 1907 | * |
| 1908 | * Disable @plane; should be an independent operation. |
| 1909 | */ |
| 1910 | static void intel_disable_plane(struct drm_i915_private *dev_priv, |
| 1911 | enum plane plane, enum pipe pipe) |
| 1912 | { |
| 1913 | int reg; |
| 1914 | u32 val; |
| 1915 | |
| 1916 | reg = DSPCNTR(plane); |
| 1917 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1918 | if ((val & DISPLAY_PLANE_ENABLE) == 0) |
| 1919 | return; |
| 1920 | |
| 1921 | I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1922 | intel_flush_display_plane(dev_priv, plane); |
| 1923 | intel_wait_for_vblank(dev_priv->dev, pipe); |
| 1924 | } |
| 1925 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 1926 | int |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1927 | intel_pin_and_fence_fb_obj(struct drm_device *dev, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1928 | struct drm_i915_gem_object *obj, |
Chris Wilson | 919926a | 2010-11-12 13:42:53 +0000 | [diff] [blame] | 1929 | struct intel_ring_buffer *pipelined) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1930 | { |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1931 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1932 | u32 alignment; |
| 1933 | int ret; |
| 1934 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1935 | switch (obj->tiling_mode) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1936 | case I915_TILING_NONE: |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 1937 | if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
| 1938 | alignment = 128 * 1024; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1939 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 1940 | alignment = 4 * 1024; |
| 1941 | else |
| 1942 | alignment = 64 * 1024; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1943 | break; |
| 1944 | case I915_TILING_X: |
| 1945 | /* pin() will align the object as required by fence */ |
| 1946 | alignment = 0; |
| 1947 | break; |
| 1948 | case I915_TILING_Y: |
| 1949 | /* FIXME: Is this true? */ |
| 1950 | DRM_ERROR("Y tiled not allowed for scan out buffers\n"); |
| 1951 | return -EINVAL; |
| 1952 | default: |
| 1953 | BUG(); |
| 1954 | } |
| 1955 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1956 | dev_priv->mm.interruptible = false; |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 1957 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1958 | if (ret) |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1959 | goto err_interruptible; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1960 | |
| 1961 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 1962 | * fence, whereas 965+ only requires a fence if using |
| 1963 | * framebuffer compression. For simplicity, we always install |
| 1964 | * a fence as the cost is not that onerous. |
| 1965 | */ |
Chris Wilson | 06d9813 | 2012-04-17 15:31:24 +0100 | [diff] [blame] | 1966 | ret = i915_gem_object_get_fence(obj); |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 1967 | if (ret) |
| 1968 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 1969 | |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 1970 | i915_gem_object_pin_fence(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1971 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1972 | dev_priv->mm.interruptible = true; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1973 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1974 | |
| 1975 | err_unpin: |
| 1976 | i915_gem_object_unpin(obj); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1977 | err_interruptible: |
| 1978 | dev_priv->mm.interruptible = true; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1979 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1980 | } |
| 1981 | |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 1982 | void intel_unpin_fb_obj(struct drm_i915_gem_object *obj) |
| 1983 | { |
| 1984 | i915_gem_object_unpin_fence(obj); |
| 1985 | i915_gem_object_unpin(obj); |
| 1986 | } |
| 1987 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1988 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
| 1989 | * is assumed to be a power-of-two. */ |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 1990 | unsigned long intel_gen4_compute_offset_xtiled(int *x, int *y, |
| 1991 | unsigned int bpp, |
| 1992 | unsigned int pitch) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1993 | { |
| 1994 | int tile_rows, tiles; |
| 1995 | |
| 1996 | tile_rows = *y / 8; |
| 1997 | *y %= 8; |
| 1998 | tiles = *x / (512/bpp); |
| 1999 | *x %= 512/bpp; |
| 2000 | |
| 2001 | return tile_rows * pitch * 8 + tiles * 4096; |
| 2002 | } |
| 2003 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2004 | static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 2005 | int x, int y) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2006 | { |
| 2007 | struct drm_device *dev = crtc->dev; |
| 2008 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2009 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2010 | struct intel_framebuffer *intel_fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2011 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2012 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2013 | unsigned long linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2014 | u32 dspcntr; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2015 | u32 reg; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2016 | |
| 2017 | switch (plane) { |
| 2018 | case 0: |
| 2019 | case 1: |
| 2020 | break; |
| 2021 | default: |
| 2022 | DRM_ERROR("Can't update plane %d in SAREA\n", plane); |
| 2023 | return -EINVAL; |
| 2024 | } |
| 2025 | |
| 2026 | intel_fb = to_intel_framebuffer(fb); |
| 2027 | obj = intel_fb->obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2028 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2029 | reg = DSPCNTR(plane); |
| 2030 | dspcntr = I915_READ(reg); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2031 | /* Mask out pixel format bits in case we change it */ |
| 2032 | dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2033 | switch (fb->pixel_format) { |
| 2034 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2035 | dspcntr |= DISPPLANE_8BPP; |
| 2036 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2037 | case DRM_FORMAT_XRGB1555: |
| 2038 | case DRM_FORMAT_ARGB1555: |
| 2039 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2040 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2041 | case DRM_FORMAT_RGB565: |
| 2042 | dspcntr |= DISPPLANE_BGRX565; |
| 2043 | break; |
| 2044 | case DRM_FORMAT_XRGB8888: |
| 2045 | case DRM_FORMAT_ARGB8888: |
| 2046 | dspcntr |= DISPPLANE_BGRX888; |
| 2047 | break; |
| 2048 | case DRM_FORMAT_XBGR8888: |
| 2049 | case DRM_FORMAT_ABGR8888: |
| 2050 | dspcntr |= DISPPLANE_RGBX888; |
| 2051 | break; |
| 2052 | case DRM_FORMAT_XRGB2101010: |
| 2053 | case DRM_FORMAT_ARGB2101010: |
| 2054 | dspcntr |= DISPPLANE_BGRX101010; |
| 2055 | break; |
| 2056 | case DRM_FORMAT_XBGR2101010: |
| 2057 | case DRM_FORMAT_ABGR2101010: |
| 2058 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2059 | break; |
| 2060 | default: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2061 | DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2062 | return -EINVAL; |
| 2063 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2064 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2065 | if (INTEL_INFO(dev)->gen >= 4) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2066 | if (obj->tiling_mode != I915_TILING_NONE) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2067 | dspcntr |= DISPPLANE_TILED; |
| 2068 | else |
| 2069 | dspcntr &= ~DISPPLANE_TILED; |
| 2070 | } |
| 2071 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2072 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2073 | |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2074 | linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2075 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2076 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2077 | intel_crtc->dspaddr_offset = |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 2078 | intel_gen4_compute_offset_xtiled(&x, &y, |
| 2079 | fb->bits_per_pixel / 8, |
| 2080 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2081 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2082 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2083 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2084 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2085 | |
| 2086 | DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n", |
| 2087 | obj->gtt_offset, linear_offset, x, y, fb->pitches[0]); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2088 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2089 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2090 | I915_MODIFY_DISPBASE(DSPSURF(plane), |
| 2091 | obj->gtt_offset + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2092 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2093 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2094 | } else |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2095 | I915_WRITE(DSPADDR(plane), obj->gtt_offset + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2096 | POSTING_READ(reg); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2097 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2098 | return 0; |
| 2099 | } |
| 2100 | |
| 2101 | static int ironlake_update_plane(struct drm_crtc *crtc, |
| 2102 | struct drm_framebuffer *fb, int x, int y) |
| 2103 | { |
| 2104 | struct drm_device *dev = crtc->dev; |
| 2105 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2106 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2107 | struct intel_framebuffer *intel_fb; |
| 2108 | struct drm_i915_gem_object *obj; |
| 2109 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2110 | unsigned long linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2111 | u32 dspcntr; |
| 2112 | u32 reg; |
| 2113 | |
| 2114 | switch (plane) { |
| 2115 | case 0: |
| 2116 | case 1: |
Jesse Barnes | 27f8227 | 2011-09-02 12:54:37 -0700 | [diff] [blame] | 2117 | case 2: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2118 | break; |
| 2119 | default: |
| 2120 | DRM_ERROR("Can't update plane %d in SAREA\n", plane); |
| 2121 | return -EINVAL; |
| 2122 | } |
| 2123 | |
| 2124 | intel_fb = to_intel_framebuffer(fb); |
| 2125 | obj = intel_fb->obj; |
| 2126 | |
| 2127 | reg = DSPCNTR(plane); |
| 2128 | dspcntr = I915_READ(reg); |
| 2129 | /* Mask out pixel format bits in case we change it */ |
| 2130 | dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2131 | switch (fb->pixel_format) { |
| 2132 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2133 | dspcntr |= DISPPLANE_8BPP; |
| 2134 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2135 | case DRM_FORMAT_RGB565: |
| 2136 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2137 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2138 | case DRM_FORMAT_XRGB8888: |
| 2139 | case DRM_FORMAT_ARGB8888: |
| 2140 | dspcntr |= DISPPLANE_BGRX888; |
| 2141 | break; |
| 2142 | case DRM_FORMAT_XBGR8888: |
| 2143 | case DRM_FORMAT_ABGR8888: |
| 2144 | dspcntr |= DISPPLANE_RGBX888; |
| 2145 | break; |
| 2146 | case DRM_FORMAT_XRGB2101010: |
| 2147 | case DRM_FORMAT_ARGB2101010: |
| 2148 | dspcntr |= DISPPLANE_BGRX101010; |
| 2149 | break; |
| 2150 | case DRM_FORMAT_XBGR2101010: |
| 2151 | case DRM_FORMAT_ABGR2101010: |
| 2152 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2153 | break; |
| 2154 | default: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2155 | DRM_ERROR("Unknown pixel format 0x%08x\n", fb->pixel_format); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2156 | return -EINVAL; |
| 2157 | } |
| 2158 | |
| 2159 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2160 | dspcntr |= DISPPLANE_TILED; |
| 2161 | else |
| 2162 | dspcntr &= ~DISPPLANE_TILED; |
| 2163 | |
| 2164 | /* must disable */ |
| 2165 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2166 | |
| 2167 | I915_WRITE(reg, dspcntr); |
| 2168 | |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2169 | linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2170 | intel_crtc->dspaddr_offset = |
Damien Lespiau | 5a35e99 | 2012-10-26 18:20:12 +0100 | [diff] [blame] | 2171 | intel_gen4_compute_offset_xtiled(&x, &y, |
| 2172 | fb->bits_per_pixel / 8, |
| 2173 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2174 | linear_offset -= intel_crtc->dspaddr_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2175 | |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2176 | DRM_DEBUG_KMS("Writing base %08X %08lX %d %d %d\n", |
| 2177 | obj->gtt_offset, linear_offset, x, y, fb->pitches[0]); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2178 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2179 | I915_MODIFY_DISPBASE(DSPSURF(plane), |
| 2180 | obj->gtt_offset + intel_crtc->dspaddr_offset); |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2181 | if (IS_HASWELL(dev)) { |
| 2182 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2183 | } else { |
| 2184 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2185 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2186 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2187 | POSTING_READ(reg); |
| 2188 | |
| 2189 | return 0; |
| 2190 | } |
| 2191 | |
| 2192 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 2193 | static int |
| 2194 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 2195 | int x, int y, enum mode_set_atomic state) |
| 2196 | { |
| 2197 | struct drm_device *dev = crtc->dev; |
| 2198 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2199 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2200 | if (dev_priv->display.disable_fbc) |
| 2201 | dev_priv->display.disable_fbc(dev); |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 2202 | intel_increase_pllclock(crtc); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2203 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2204 | return dev_priv->display.update_plane(crtc, fb, x, y); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2205 | } |
| 2206 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2207 | static int |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2208 | intel_finish_fb(struct drm_framebuffer *old_fb) |
| 2209 | { |
| 2210 | struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj; |
| 2211 | struct drm_i915_private *dev_priv = obj->base.dev->dev_private; |
| 2212 | bool was_interruptible = dev_priv->mm.interruptible; |
| 2213 | int ret; |
| 2214 | |
| 2215 | wait_event(dev_priv->pending_flip_queue, |
| 2216 | atomic_read(&dev_priv->mm.wedged) || |
| 2217 | atomic_read(&obj->pending_flip) == 0); |
| 2218 | |
| 2219 | /* Big Hammer, we also need to ensure that any pending |
| 2220 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 2221 | * current scanout is retired before unpinning the old |
| 2222 | * framebuffer. |
| 2223 | * |
| 2224 | * This should only fail upon a hung GPU, in which case we |
| 2225 | * can safely continue. |
| 2226 | */ |
| 2227 | dev_priv->mm.interruptible = false; |
| 2228 | ret = i915_gem_object_finish_gpu(obj); |
| 2229 | dev_priv->mm.interruptible = was_interruptible; |
| 2230 | |
| 2231 | return ret; |
| 2232 | } |
| 2233 | |
Ville Syrjälä | 198598d | 2012-10-31 17:50:24 +0200 | [diff] [blame] | 2234 | static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y) |
| 2235 | { |
| 2236 | struct drm_device *dev = crtc->dev; |
| 2237 | struct drm_i915_master_private *master_priv; |
| 2238 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2239 | |
| 2240 | if (!dev->primary->master) |
| 2241 | return; |
| 2242 | |
| 2243 | master_priv = dev->primary->master->driver_priv; |
| 2244 | if (!master_priv->sarea_priv) |
| 2245 | return; |
| 2246 | |
| 2247 | switch (intel_crtc->pipe) { |
| 2248 | case 0: |
| 2249 | master_priv->sarea_priv->pipeA_x = x; |
| 2250 | master_priv->sarea_priv->pipeA_y = y; |
| 2251 | break; |
| 2252 | case 1: |
| 2253 | master_priv->sarea_priv->pipeB_x = x; |
| 2254 | master_priv->sarea_priv->pipeB_y = y; |
| 2255 | break; |
| 2256 | default: |
| 2257 | break; |
| 2258 | } |
| 2259 | } |
| 2260 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2261 | static int |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2262 | intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2263 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2264 | { |
| 2265 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2266 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2267 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2268 | struct drm_framebuffer *old_fb; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2269 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2270 | |
| 2271 | /* no fb bound */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2272 | if (!fb) { |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2273 | DRM_ERROR("No FB bound\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2274 | return 0; |
| 2275 | } |
| 2276 | |
Eugeni Dodonov | 5826eca | 2012-05-09 15:37:12 -0300 | [diff] [blame] | 2277 | if(intel_crtc->plane > dev_priv->num_pipe) { |
| 2278 | DRM_ERROR("no plane for crtc: plane %d, num_pipes %d\n", |
| 2279 | intel_crtc->plane, |
| 2280 | dev_priv->num_pipe); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2281 | return -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2282 | } |
| 2283 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2284 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 2285 | ret = intel_pin_and_fence_fb_obj(dev, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2286 | to_intel_framebuffer(fb)->obj, |
Chris Wilson | 919926a | 2010-11-12 13:42:53 +0000 | [diff] [blame] | 2287 | NULL); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2288 | if (ret != 0) { |
| 2289 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2290 | DRM_ERROR("pin & fence failed\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2291 | return ret; |
| 2292 | } |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2293 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2294 | if (crtc->fb) |
| 2295 | intel_finish_fb(crtc->fb); |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 2296 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2297 | ret = dev_priv->display.update_plane(crtc, fb, x, y); |
Chris Wilson | 4e6cfef | 2010-08-08 13:20:19 +0100 | [diff] [blame] | 2298 | if (ret) { |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2299 | intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2300 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2301 | DRM_ERROR("failed to update base address\n"); |
Chris Wilson | 4e6cfef | 2010-08-08 13:20:19 +0100 | [diff] [blame] | 2302 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2303 | } |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2304 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2305 | old_fb = crtc->fb; |
| 2306 | crtc->fb = fb; |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 2307 | crtc->x = x; |
| 2308 | crtc->y = y; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2309 | |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 2310 | if (old_fb) { |
| 2311 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2312 | intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj); |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 2313 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2314 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2315 | intel_update_fbc(dev); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2316 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2317 | |
Ville Syrjälä | 198598d | 2012-10-31 17:50:24 +0200 | [diff] [blame] | 2318 | intel_crtc_update_sarea_pos(crtc, x, y); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2319 | |
| 2320 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2321 | } |
| 2322 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2323 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 2324 | { |
| 2325 | struct drm_device *dev = crtc->dev; |
| 2326 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2327 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2328 | int pipe = intel_crtc->pipe; |
| 2329 | u32 reg, temp; |
| 2330 | |
| 2331 | /* enable normal train */ |
| 2332 | reg = FDI_TX_CTL(pipe); |
| 2333 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 2334 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2335 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 2336 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 2337 | } else { |
| 2338 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2339 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2340 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2341 | I915_WRITE(reg, temp); |
| 2342 | |
| 2343 | reg = FDI_RX_CTL(pipe); |
| 2344 | temp = I915_READ(reg); |
| 2345 | if (HAS_PCH_CPT(dev)) { |
| 2346 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2347 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 2348 | } else { |
| 2349 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2350 | temp |= FDI_LINK_TRAIN_NONE; |
| 2351 | } |
| 2352 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 2353 | |
| 2354 | /* wait one idle pattern time */ |
| 2355 | POSTING_READ(reg); |
| 2356 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2357 | |
| 2358 | /* IVB wants error correction enabled */ |
| 2359 | if (IS_IVYBRIDGE(dev)) |
| 2360 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 2361 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2362 | } |
| 2363 | |
Jesse Barnes | 291427f | 2011-07-29 12:42:37 -0700 | [diff] [blame] | 2364 | static void cpt_phase_pointer_enable(struct drm_device *dev, int pipe) |
| 2365 | { |
| 2366 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2367 | u32 flags = I915_READ(SOUTH_CHICKEN1); |
| 2368 | |
| 2369 | flags |= FDI_PHASE_SYNC_OVR(pipe); |
| 2370 | I915_WRITE(SOUTH_CHICKEN1, flags); /* once to unlock... */ |
| 2371 | flags |= FDI_PHASE_SYNC_EN(pipe); |
| 2372 | I915_WRITE(SOUTH_CHICKEN1, flags); /* then again to enable */ |
| 2373 | POSTING_READ(SOUTH_CHICKEN1); |
| 2374 | } |
| 2375 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2376 | static void ivb_modeset_global_resources(struct drm_device *dev) |
| 2377 | { |
| 2378 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2379 | struct intel_crtc *pipe_B_crtc = |
| 2380 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]); |
| 2381 | struct intel_crtc *pipe_C_crtc = |
| 2382 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]); |
| 2383 | uint32_t temp; |
| 2384 | |
| 2385 | /* When everything is off disable fdi C so that we could enable fdi B |
| 2386 | * with all lanes. XXX: This misses the case where a pipe is not using |
| 2387 | * any pch resources and so doesn't need any fdi lanes. */ |
| 2388 | if (!pipe_B_crtc->base.enabled && !pipe_C_crtc->base.enabled) { |
| 2389 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 2390 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 2391 | |
| 2392 | temp = I915_READ(SOUTH_CHICKEN1); |
| 2393 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 2394 | DRM_DEBUG_KMS("disabling fdi C rx\n"); |
| 2395 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 2396 | } |
| 2397 | } |
| 2398 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2399 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 2400 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 2401 | { |
| 2402 | struct drm_device *dev = crtc->dev; |
| 2403 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2404 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2405 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2406 | int plane = intel_crtc->plane; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2407 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2408 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2409 | /* FDI needs bits from pipe & plane first */ |
| 2410 | assert_pipe_enabled(dev_priv, pipe); |
| 2411 | assert_plane_enabled(dev_priv, plane); |
| 2412 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2413 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 2414 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2415 | reg = FDI_RX_IMR(pipe); |
| 2416 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2417 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 2418 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2419 | I915_WRITE(reg, temp); |
| 2420 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2421 | udelay(150); |
| 2422 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2423 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2424 | reg = FDI_TX_CTL(pipe); |
| 2425 | temp = I915_READ(reg); |
Adam Jackson | 77ffb59 | 2010-04-12 11:38:44 -0400 | [diff] [blame] | 2426 | temp &= ~(7 << 19); |
| 2427 | temp |= (intel_crtc->fdi_lanes - 1) << 19; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2428 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2429 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2430 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2431 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2432 | reg = FDI_RX_CTL(pipe); |
| 2433 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2434 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2435 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2436 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 2437 | |
| 2438 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2439 | udelay(150); |
| 2440 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2441 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 2442 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 2443 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 2444 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2445 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2446 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2447 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2448 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2449 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2450 | |
| 2451 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 2452 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2453 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2454 | break; |
| 2455 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2456 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2457 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2458 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2459 | |
| 2460 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2461 | reg = FDI_TX_CTL(pipe); |
| 2462 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2463 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2464 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2465 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2466 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2467 | reg = FDI_RX_CTL(pipe); |
| 2468 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2469 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2470 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2471 | I915_WRITE(reg, temp); |
| 2472 | |
| 2473 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2474 | udelay(150); |
| 2475 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2476 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2477 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2478 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2479 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2480 | |
| 2481 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2482 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2483 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 2484 | break; |
| 2485 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2486 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2487 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2488 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2489 | |
| 2490 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 2491 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2492 | } |
| 2493 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2494 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2495 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 2496 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 2497 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 2498 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 2499 | }; |
| 2500 | |
| 2501 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 2502 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 2503 | { |
| 2504 | struct drm_device *dev = crtc->dev; |
| 2505 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2506 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2507 | int pipe = intel_crtc->pipe; |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2508 | u32 reg, temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2509 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2510 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 2511 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2512 | reg = FDI_RX_IMR(pipe); |
| 2513 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2514 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 2515 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2516 | I915_WRITE(reg, temp); |
| 2517 | |
| 2518 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2519 | udelay(150); |
| 2520 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2521 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2522 | reg = FDI_TX_CTL(pipe); |
| 2523 | temp = I915_READ(reg); |
Adam Jackson | 77ffb59 | 2010-04-12 11:38:44 -0400 | [diff] [blame] | 2524 | temp &= ~(7 << 19); |
| 2525 | temp |= (intel_crtc->fdi_lanes - 1) << 19; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2526 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2527 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2528 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2529 | /* SNB-B */ |
| 2530 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2531 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2532 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 2533 | I915_WRITE(FDI_RX_MISC(pipe), |
| 2534 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 2535 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2536 | reg = FDI_RX_CTL(pipe); |
| 2537 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2538 | if (HAS_PCH_CPT(dev)) { |
| 2539 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2540 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 2541 | } else { |
| 2542 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2543 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2544 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2545 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 2546 | |
| 2547 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2548 | udelay(150); |
| 2549 | |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 2550 | cpt_phase_pointer_enable(dev, pipe); |
Jesse Barnes | 291427f | 2011-07-29 12:42:37 -0700 | [diff] [blame] | 2551 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2552 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2553 | reg = FDI_TX_CTL(pipe); |
| 2554 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2555 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2556 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2557 | I915_WRITE(reg, temp); |
| 2558 | |
| 2559 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2560 | udelay(500); |
| 2561 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2562 | for (retry = 0; retry < 5; retry++) { |
| 2563 | reg = FDI_RX_IIR(pipe); |
| 2564 | temp = I915_READ(reg); |
| 2565 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2566 | if (temp & FDI_RX_BIT_LOCK) { |
| 2567 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 2568 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 2569 | break; |
| 2570 | } |
| 2571 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2572 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2573 | if (retry < 5) |
| 2574 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2575 | } |
| 2576 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2577 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2578 | |
| 2579 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2580 | reg = FDI_TX_CTL(pipe); |
| 2581 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2582 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2583 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 2584 | if (IS_GEN6(dev)) { |
| 2585 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2586 | /* SNB-B */ |
| 2587 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 2588 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2589 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2590 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2591 | reg = FDI_RX_CTL(pipe); |
| 2592 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2593 | if (HAS_PCH_CPT(dev)) { |
| 2594 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2595 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 2596 | } else { |
| 2597 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2598 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 2599 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2600 | I915_WRITE(reg, temp); |
| 2601 | |
| 2602 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2603 | udelay(150); |
| 2604 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2605 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2606 | reg = FDI_TX_CTL(pipe); |
| 2607 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2608 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2609 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2610 | I915_WRITE(reg, temp); |
| 2611 | |
| 2612 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2613 | udelay(500); |
| 2614 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2615 | for (retry = 0; retry < 5; retry++) { |
| 2616 | reg = FDI_RX_IIR(pipe); |
| 2617 | temp = I915_READ(reg); |
| 2618 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2619 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 2620 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 2621 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 2622 | break; |
| 2623 | } |
| 2624 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2625 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2626 | if (retry < 5) |
| 2627 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2628 | } |
| 2629 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2630 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2631 | |
| 2632 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 2633 | } |
| 2634 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2635 | /* Manual link training for Ivy Bridge A0 parts */ |
| 2636 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 2637 | { |
| 2638 | struct drm_device *dev = crtc->dev; |
| 2639 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2640 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2641 | int pipe = intel_crtc->pipe; |
| 2642 | u32 reg, temp, i; |
| 2643 | |
| 2644 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 2645 | for train result */ |
| 2646 | reg = FDI_RX_IMR(pipe); |
| 2647 | temp = I915_READ(reg); |
| 2648 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 2649 | temp &= ~FDI_RX_BIT_LOCK; |
| 2650 | I915_WRITE(reg, temp); |
| 2651 | |
| 2652 | POSTING_READ(reg); |
| 2653 | udelay(150); |
| 2654 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2655 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 2656 | I915_READ(FDI_RX_IIR(pipe))); |
| 2657 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2658 | /* enable CPU FDI TX and PCH FDI RX */ |
| 2659 | reg = FDI_TX_CTL(pipe); |
| 2660 | temp = I915_READ(reg); |
| 2661 | temp &= ~(7 << 19); |
| 2662 | temp |= (intel_crtc->fdi_lanes - 1) << 19; |
| 2663 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 2664 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
| 2665 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2666 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Jesse Barnes | c4f9c4c | 2011-10-10 14:28:52 -0700 | [diff] [blame] | 2667 | temp |= FDI_COMPOSITE_SYNC; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2668 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 2669 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 2670 | I915_WRITE(FDI_RX_MISC(pipe), |
| 2671 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 2672 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2673 | reg = FDI_RX_CTL(pipe); |
| 2674 | temp = I915_READ(reg); |
| 2675 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 2676 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2677 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
Jesse Barnes | c4f9c4c | 2011-10-10 14:28:52 -0700 | [diff] [blame] | 2678 | temp |= FDI_COMPOSITE_SYNC; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2679 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 2680 | |
| 2681 | POSTING_READ(reg); |
| 2682 | udelay(150); |
| 2683 | |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 2684 | cpt_phase_pointer_enable(dev, pipe); |
Jesse Barnes | 291427f | 2011-07-29 12:42:37 -0700 | [diff] [blame] | 2685 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2686 | for (i = 0; i < 4; i++) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2687 | reg = FDI_TX_CTL(pipe); |
| 2688 | temp = I915_READ(reg); |
| 2689 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2690 | temp |= snb_b_fdi_train_param[i]; |
| 2691 | I915_WRITE(reg, temp); |
| 2692 | |
| 2693 | POSTING_READ(reg); |
| 2694 | udelay(500); |
| 2695 | |
| 2696 | reg = FDI_RX_IIR(pipe); |
| 2697 | temp = I915_READ(reg); |
| 2698 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2699 | |
| 2700 | if (temp & FDI_RX_BIT_LOCK || |
| 2701 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 2702 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2703 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2704 | break; |
| 2705 | } |
| 2706 | } |
| 2707 | if (i == 4) |
| 2708 | DRM_ERROR("FDI train 1 fail!\n"); |
| 2709 | |
| 2710 | /* Train 2 */ |
| 2711 | reg = FDI_TX_CTL(pipe); |
| 2712 | temp = I915_READ(reg); |
| 2713 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 2714 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 2715 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2716 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 2717 | I915_WRITE(reg, temp); |
| 2718 | |
| 2719 | reg = FDI_RX_CTL(pipe); |
| 2720 | temp = I915_READ(reg); |
| 2721 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2722 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 2723 | I915_WRITE(reg, temp); |
| 2724 | |
| 2725 | POSTING_READ(reg); |
| 2726 | udelay(150); |
| 2727 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2728 | for (i = 0; i < 4; i++) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2729 | reg = FDI_TX_CTL(pipe); |
| 2730 | temp = I915_READ(reg); |
| 2731 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2732 | temp |= snb_b_fdi_train_param[i]; |
| 2733 | I915_WRITE(reg, temp); |
| 2734 | |
| 2735 | POSTING_READ(reg); |
| 2736 | udelay(500); |
| 2737 | |
| 2738 | reg = FDI_RX_IIR(pipe); |
| 2739 | temp = I915_READ(reg); |
| 2740 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2741 | |
| 2742 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 2743 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2744 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2745 | break; |
| 2746 | } |
| 2747 | } |
| 2748 | if (i == 4) |
| 2749 | DRM_ERROR("FDI train 2 fail!\n"); |
| 2750 | |
| 2751 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 2752 | } |
| 2753 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 2754 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2755 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 2756 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2757 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2758 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2759 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2760 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 2761 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2762 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2763 | reg = FDI_RX_CTL(pipe); |
| 2764 | temp = I915_READ(reg); |
| 2765 | temp &= ~((0x7 << 19) | (0x7 << 16)); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2766 | temp |= (intel_crtc->fdi_lanes - 1) << 19; |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 2767 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2768 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 2769 | |
| 2770 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2771 | udelay(200); |
| 2772 | |
| 2773 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2774 | temp = I915_READ(reg); |
| 2775 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 2776 | |
| 2777 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2778 | udelay(200); |
| 2779 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 2780 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 2781 | reg = FDI_TX_CTL(pipe); |
| 2782 | temp = I915_READ(reg); |
| 2783 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 2784 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2785 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 2786 | POSTING_READ(reg); |
| 2787 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2788 | } |
| 2789 | } |
| 2790 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 2791 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 2792 | { |
| 2793 | struct drm_device *dev = intel_crtc->base.dev; |
| 2794 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2795 | int pipe = intel_crtc->pipe; |
| 2796 | u32 reg, temp; |
| 2797 | |
| 2798 | /* Switch from PCDclk to Rawclk */ |
| 2799 | reg = FDI_RX_CTL(pipe); |
| 2800 | temp = I915_READ(reg); |
| 2801 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 2802 | |
| 2803 | /* Disable CPU FDI TX PLL */ |
| 2804 | reg = FDI_TX_CTL(pipe); |
| 2805 | temp = I915_READ(reg); |
| 2806 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 2807 | |
| 2808 | POSTING_READ(reg); |
| 2809 | udelay(100); |
| 2810 | |
| 2811 | reg = FDI_RX_CTL(pipe); |
| 2812 | temp = I915_READ(reg); |
| 2813 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 2814 | |
| 2815 | /* Wait for the clocks to turn off. */ |
| 2816 | POSTING_READ(reg); |
| 2817 | udelay(100); |
| 2818 | } |
| 2819 | |
Jesse Barnes | 291427f | 2011-07-29 12:42:37 -0700 | [diff] [blame] | 2820 | static void cpt_phase_pointer_disable(struct drm_device *dev, int pipe) |
| 2821 | { |
| 2822 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2823 | u32 flags = I915_READ(SOUTH_CHICKEN1); |
| 2824 | |
| 2825 | flags &= ~(FDI_PHASE_SYNC_EN(pipe)); |
| 2826 | I915_WRITE(SOUTH_CHICKEN1, flags); /* once to disable... */ |
| 2827 | flags &= ~(FDI_PHASE_SYNC_OVR(pipe)); |
| 2828 | I915_WRITE(SOUTH_CHICKEN1, flags); /* then again to lock */ |
| 2829 | POSTING_READ(SOUTH_CHICKEN1); |
| 2830 | } |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2831 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 2832 | { |
| 2833 | struct drm_device *dev = crtc->dev; |
| 2834 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2835 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2836 | int pipe = intel_crtc->pipe; |
| 2837 | u32 reg, temp; |
| 2838 | |
| 2839 | /* disable CPU FDI tx and PCH FDI rx */ |
| 2840 | reg = FDI_TX_CTL(pipe); |
| 2841 | temp = I915_READ(reg); |
| 2842 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 2843 | POSTING_READ(reg); |
| 2844 | |
| 2845 | reg = FDI_RX_CTL(pipe); |
| 2846 | temp = I915_READ(reg); |
| 2847 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 2848 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2849 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 2850 | |
| 2851 | POSTING_READ(reg); |
| 2852 | udelay(100); |
| 2853 | |
| 2854 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 2855 | if (HAS_PCH_IBX(dev)) { |
| 2856 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 291427f | 2011-07-29 12:42:37 -0700 | [diff] [blame] | 2857 | } else if (HAS_PCH_CPT(dev)) { |
| 2858 | cpt_phase_pointer_disable(dev, pipe); |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 2859 | } |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2860 | |
| 2861 | /* still set train pattern 1 */ |
| 2862 | reg = FDI_TX_CTL(pipe); |
| 2863 | temp = I915_READ(reg); |
| 2864 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2865 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2866 | I915_WRITE(reg, temp); |
| 2867 | |
| 2868 | reg = FDI_RX_CTL(pipe); |
| 2869 | temp = I915_READ(reg); |
| 2870 | if (HAS_PCH_CPT(dev)) { |
| 2871 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2872 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 2873 | } else { |
| 2874 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2875 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2876 | } |
| 2877 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 2878 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 2879 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2880 | I915_WRITE(reg, temp); |
| 2881 | |
| 2882 | POSTING_READ(reg); |
| 2883 | udelay(100); |
| 2884 | } |
| 2885 | |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 2886 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 2887 | { |
| 2888 | struct drm_device *dev = crtc->dev; |
| 2889 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2890 | unsigned long flags; |
| 2891 | bool pending; |
| 2892 | |
| 2893 | if (atomic_read(&dev_priv->mm.wedged)) |
| 2894 | return false; |
| 2895 | |
| 2896 | spin_lock_irqsave(&dev->event_lock, flags); |
| 2897 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
| 2898 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 2899 | |
| 2900 | return pending; |
| 2901 | } |
| 2902 | |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2903 | static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
| 2904 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 2905 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 2906 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2907 | |
| 2908 | if (crtc->fb == NULL) |
| 2909 | return; |
| 2910 | |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 2911 | wait_event(dev_priv->pending_flip_queue, |
| 2912 | !intel_crtc_has_pending_flip(crtc)); |
| 2913 | |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 2914 | mutex_lock(&dev->struct_mutex); |
| 2915 | intel_finish_fb(crtc->fb); |
| 2916 | mutex_unlock(&dev->struct_mutex); |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2917 | } |
| 2918 | |
Paulo Zanoni | fc316cb | 2012-10-25 10:37:43 -0200 | [diff] [blame] | 2919 | static bool ironlake_crtc_driving_pch(struct drm_crtc *crtc) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2920 | { |
| 2921 | struct drm_device *dev = crtc->dev; |
Paulo Zanoni | 228d3e3 | 2012-08-10 10:05:10 -0300 | [diff] [blame] | 2922 | struct intel_encoder *intel_encoder; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2923 | |
| 2924 | /* |
| 2925 | * If there's a non-PCH eDP on this crtc, it must be DP_A, and that |
| 2926 | * must be driven by its own crtc; no sharing is possible. |
| 2927 | */ |
Paulo Zanoni | 228d3e3 | 2012-08-10 10:05:10 -0300 | [diff] [blame] | 2928 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
Paulo Zanoni | 228d3e3 | 2012-08-10 10:05:10 -0300 | [diff] [blame] | 2929 | switch (intel_encoder->type) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2930 | case INTEL_OUTPUT_EDP: |
Paulo Zanoni | 228d3e3 | 2012-08-10 10:05:10 -0300 | [diff] [blame] | 2931 | if (!intel_encoder_is_pch_edp(&intel_encoder->base)) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2932 | return false; |
| 2933 | continue; |
| 2934 | } |
| 2935 | } |
| 2936 | |
| 2937 | return true; |
| 2938 | } |
| 2939 | |
Paulo Zanoni | fc316cb | 2012-10-25 10:37:43 -0200 | [diff] [blame] | 2940 | static bool haswell_crtc_driving_pch(struct drm_crtc *crtc) |
| 2941 | { |
| 2942 | return intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG); |
| 2943 | } |
| 2944 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2945 | /* Program iCLKIP clock to the desired frequency */ |
| 2946 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 2947 | { |
| 2948 | struct drm_device *dev = crtc->dev; |
| 2949 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2950 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 2951 | u32 temp; |
| 2952 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 2953 | mutex_lock(&dev_priv->dpio_lock); |
| 2954 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2955 | /* It is necessary to ungate the pixclk gate prior to programming |
| 2956 | * the divisors, and gate it back when it is done. |
| 2957 | */ |
| 2958 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 2959 | |
| 2960 | /* Disable SSCCTL */ |
| 2961 | intel_sbi_write(dev_priv, SBI_SSCCTL6, |
| 2962 | intel_sbi_read(dev_priv, SBI_SSCCTL6) | |
| 2963 | SBI_SSCCTL_DISABLE); |
| 2964 | |
| 2965 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ |
| 2966 | if (crtc->mode.clock == 20000) { |
| 2967 | auxdiv = 1; |
| 2968 | divsel = 0x41; |
| 2969 | phaseinc = 0x20; |
| 2970 | } else { |
| 2971 | /* The iCLK virtual clock root frequency is in MHz, |
| 2972 | * but the crtc->mode.clock in in KHz. To get the divisors, |
| 2973 | * it is necessary to divide one by another, so we |
| 2974 | * convert the virtual clock precision to KHz here for higher |
| 2975 | * precision. |
| 2976 | */ |
| 2977 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 2978 | u32 iclk_pi_range = 64; |
| 2979 | u32 desired_divisor, msb_divisor_value, pi_value; |
| 2980 | |
| 2981 | desired_divisor = (iclk_virtual_root_freq / crtc->mode.clock); |
| 2982 | msb_divisor_value = desired_divisor / iclk_pi_range; |
| 2983 | pi_value = desired_divisor % iclk_pi_range; |
| 2984 | |
| 2985 | auxdiv = 0; |
| 2986 | divsel = msb_divisor_value - 2; |
| 2987 | phaseinc = pi_value; |
| 2988 | } |
| 2989 | |
| 2990 | /* This should not happen with any sane values */ |
| 2991 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 2992 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 2993 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 2994 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 2995 | |
| 2996 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", |
| 2997 | crtc->mode.clock, |
| 2998 | auxdiv, |
| 2999 | divsel, |
| 3000 | phasedir, |
| 3001 | phaseinc); |
| 3002 | |
| 3003 | /* Program SSCDIVINTPHASE6 */ |
| 3004 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6); |
| 3005 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3006 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3007 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3008 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3009 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3010 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
| 3011 | |
| 3012 | intel_sbi_write(dev_priv, |
| 3013 | SBI_SSCDIVINTPHASE6, |
| 3014 | temp); |
| 3015 | |
| 3016 | /* Program SSCAUXDIV */ |
| 3017 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6); |
| 3018 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3019 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
| 3020 | intel_sbi_write(dev_priv, |
| 3021 | SBI_SSCAUXDIV6, |
| 3022 | temp); |
| 3023 | |
| 3024 | |
| 3025 | /* Enable modulator and associated divider */ |
| 3026 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6); |
| 3027 | temp &= ~SBI_SSCCTL_DISABLE; |
| 3028 | intel_sbi_write(dev_priv, |
| 3029 | SBI_SSCCTL6, |
| 3030 | temp); |
| 3031 | |
| 3032 | /* Wait for initialization time */ |
| 3033 | udelay(24); |
| 3034 | |
| 3035 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3036 | |
| 3037 | mutex_unlock(&dev_priv->dpio_lock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3038 | } |
| 3039 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3040 | /* |
| 3041 | * Enable PCH resources required for PCH ports: |
| 3042 | * - PCH PLLs |
| 3043 | * - FDI training & RX/TX |
| 3044 | * - update transcoder timings |
| 3045 | * - DP transcoding bits |
| 3046 | * - transcoder |
| 3047 | */ |
| 3048 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3049 | { |
| 3050 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3051 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3052 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3053 | int pipe = intel_crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3054 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3055 | |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 3056 | assert_transcoder_disabled(dev_priv, pipe); |
| 3057 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 3058 | /* Write the TU size bits before fdi link training, so that error |
| 3059 | * detection works. */ |
| 3060 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 3061 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 3062 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3063 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 3064 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3065 | |
Daniel Vetter | 572deb3 | 2012-10-27 18:46:14 +0200 | [diff] [blame] | 3066 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 3067 | * transcoder, and we actually should do this to not upset any PCH |
| 3068 | * transcoder that already use the clock when we share it. |
| 3069 | * |
| 3070 | * Note that enable_pch_pll tries to do the right thing, but get_pch_pll |
| 3071 | * unconditionally resets the pll - we need that to have the right LVDS |
| 3072 | * enable sequence. */ |
Paulo Zanoni | b6b4e18 | 2012-10-31 18:12:38 -0200 | [diff] [blame] | 3073 | ironlake_enable_pch_pll(intel_crtc); |
Chris Wilson | 6f13b7b | 2012-05-13 09:54:09 +0100 | [diff] [blame] | 3074 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3075 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3076 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 3077 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3078 | temp = I915_READ(PCH_DPLL_SEL); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3079 | switch (pipe) { |
| 3080 | default: |
| 3081 | case 0: |
| 3082 | temp |= TRANSA_DPLL_ENABLE; |
| 3083 | sel = TRANSA_DPLLB_SEL; |
| 3084 | break; |
| 3085 | case 1: |
| 3086 | temp |= TRANSB_DPLL_ENABLE; |
| 3087 | sel = TRANSB_DPLLB_SEL; |
| 3088 | break; |
| 3089 | case 2: |
| 3090 | temp |= TRANSC_DPLL_ENABLE; |
| 3091 | sel = TRANSC_DPLLB_SEL; |
| 3092 | break; |
Jesse Barnes | d64311a | 2011-10-12 15:01:33 -0700 | [diff] [blame] | 3093 | } |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3094 | if (intel_crtc->pch_pll->pll_reg == _PCH_DPLL_B) |
| 3095 | temp |= sel; |
| 3096 | else |
| 3097 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3098 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3099 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3100 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 3101 | /* set transcoder timing, panel must allow it */ |
| 3102 | assert_panel_unlocked(dev_priv, pipe); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3103 | I915_WRITE(TRANS_HTOTAL(pipe), I915_READ(HTOTAL(pipe))); |
| 3104 | I915_WRITE(TRANS_HBLANK(pipe), I915_READ(HBLANK(pipe))); |
| 3105 | I915_WRITE(TRANS_HSYNC(pipe), I915_READ(HSYNC(pipe))); |
| 3106 | |
| 3107 | I915_WRITE(TRANS_VTOTAL(pipe), I915_READ(VTOTAL(pipe))); |
| 3108 | I915_WRITE(TRANS_VBLANK(pipe), I915_READ(VBLANK(pipe))); |
| 3109 | I915_WRITE(TRANS_VSYNC(pipe), I915_READ(VSYNC(pipe))); |
Daniel Vetter | 0529a0d | 2012-01-28 14:49:24 +0100 | [diff] [blame] | 3110 | I915_WRITE(TRANS_VSYNCSHIFT(pipe), I915_READ(VSYNCSHIFT(pipe))); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3111 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3112 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3113 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3114 | /* For PCH DP, enable TRANS_DP_CTL */ |
| 3115 | if (HAS_PCH_CPT(dev) && |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 3116 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 3117 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3118 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3119 | reg = TRANS_DP_CTL(pipe); |
| 3120 | temp = I915_READ(reg); |
| 3121 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 3122 | TRANS_DP_SYNC_MASK | |
| 3123 | TRANS_DP_BPC_MASK); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3124 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
| 3125 | TRANS_DP_ENH_FRAMING); |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 3126 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3127 | |
| 3128 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3129 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3130 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3131 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3132 | |
| 3133 | switch (intel_trans_dp_port_sel(crtc)) { |
| 3134 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3135 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3136 | break; |
| 3137 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3138 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3139 | break; |
| 3140 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3141 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3142 | break; |
| 3143 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 3144 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3145 | } |
| 3146 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3147 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3148 | } |
| 3149 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 3150 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3151 | } |
| 3152 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3153 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 3154 | { |
| 3155 | struct drm_device *dev = crtc->dev; |
| 3156 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3157 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | daed2db | 2012-10-31 18:12:41 -0200 | [diff] [blame] | 3158 | enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3159 | |
Paulo Zanoni | daed2db | 2012-10-31 18:12:41 -0200 | [diff] [blame] | 3160 | assert_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3161 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 3162 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3163 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 3164 | /* Set transcoder timing. */ |
Paulo Zanoni | daed2db | 2012-10-31 18:12:41 -0200 | [diff] [blame] | 3165 | I915_WRITE(_TRANS_HTOTAL_A, I915_READ(HTOTAL(cpu_transcoder))); |
| 3166 | I915_WRITE(_TRANS_HBLANK_A, I915_READ(HBLANK(cpu_transcoder))); |
| 3167 | I915_WRITE(_TRANS_HSYNC_A, I915_READ(HSYNC(cpu_transcoder))); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3168 | |
Paulo Zanoni | daed2db | 2012-10-31 18:12:41 -0200 | [diff] [blame] | 3169 | I915_WRITE(_TRANS_VTOTAL_A, I915_READ(VTOTAL(cpu_transcoder))); |
| 3170 | I915_WRITE(_TRANS_VBLANK_A, I915_READ(VBLANK(cpu_transcoder))); |
| 3171 | I915_WRITE(_TRANS_VSYNC_A, I915_READ(VSYNC(cpu_transcoder))); |
| 3172 | I915_WRITE(_TRANS_VSYNCSHIFT_A, I915_READ(VSYNCSHIFT(cpu_transcoder))); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3173 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 3174 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3175 | } |
| 3176 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3177 | static void intel_put_pch_pll(struct intel_crtc *intel_crtc) |
| 3178 | { |
| 3179 | struct intel_pch_pll *pll = intel_crtc->pch_pll; |
| 3180 | |
| 3181 | if (pll == NULL) |
| 3182 | return; |
| 3183 | |
| 3184 | if (pll->refcount == 0) { |
| 3185 | WARN(1, "bad PCH PLL refcount\n"); |
| 3186 | return; |
| 3187 | } |
| 3188 | |
| 3189 | --pll->refcount; |
| 3190 | intel_crtc->pch_pll = NULL; |
| 3191 | } |
| 3192 | |
| 3193 | static struct intel_pch_pll *intel_get_pch_pll(struct intel_crtc *intel_crtc, u32 dpll, u32 fp) |
| 3194 | { |
| 3195 | struct drm_i915_private *dev_priv = intel_crtc->base.dev->dev_private; |
| 3196 | struct intel_pch_pll *pll; |
| 3197 | int i; |
| 3198 | |
| 3199 | pll = intel_crtc->pch_pll; |
| 3200 | if (pll) { |
| 3201 | DRM_DEBUG_KMS("CRTC:%d reusing existing PCH PLL %x\n", |
| 3202 | intel_crtc->base.base.id, pll->pll_reg); |
| 3203 | goto prepare; |
| 3204 | } |
| 3205 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3206 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 3207 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ |
| 3208 | i = intel_crtc->pipe; |
| 3209 | pll = &dev_priv->pch_plls[i]; |
| 3210 | |
| 3211 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated PCH PLL %x\n", |
| 3212 | intel_crtc->base.base.id, pll->pll_reg); |
| 3213 | |
| 3214 | goto found; |
| 3215 | } |
| 3216 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3217 | for (i = 0; i < dev_priv->num_pch_pll; i++) { |
| 3218 | pll = &dev_priv->pch_plls[i]; |
| 3219 | |
| 3220 | /* Only want to check enabled timings first */ |
| 3221 | if (pll->refcount == 0) |
| 3222 | continue; |
| 3223 | |
| 3224 | if (dpll == (I915_READ(pll->pll_reg) & 0x7fffffff) && |
| 3225 | fp == I915_READ(pll->fp0_reg)) { |
| 3226 | DRM_DEBUG_KMS("CRTC:%d sharing existing PCH PLL %x (refcount %d, ative %d)\n", |
| 3227 | intel_crtc->base.base.id, |
| 3228 | pll->pll_reg, pll->refcount, pll->active); |
| 3229 | |
| 3230 | goto found; |
| 3231 | } |
| 3232 | } |
| 3233 | |
| 3234 | /* Ok no matching timings, maybe there's a free one? */ |
| 3235 | for (i = 0; i < dev_priv->num_pch_pll; i++) { |
| 3236 | pll = &dev_priv->pch_plls[i]; |
| 3237 | if (pll->refcount == 0) { |
| 3238 | DRM_DEBUG_KMS("CRTC:%d allocated PCH PLL %x\n", |
| 3239 | intel_crtc->base.base.id, pll->pll_reg); |
| 3240 | goto found; |
| 3241 | } |
| 3242 | } |
| 3243 | |
| 3244 | return NULL; |
| 3245 | |
| 3246 | found: |
| 3247 | intel_crtc->pch_pll = pll; |
| 3248 | pll->refcount++; |
| 3249 | DRM_DEBUG_DRIVER("using pll %d for pipe %d\n", i, intel_crtc->pipe); |
| 3250 | prepare: /* separate function? */ |
| 3251 | DRM_DEBUG_DRIVER("switching PLL %x off\n", pll->pll_reg); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3252 | |
Chris Wilson | e04c735 | 2012-05-02 20:43:56 +0100 | [diff] [blame] | 3253 | /* Wait for the clocks to stabilize before rewriting the regs */ |
| 3254 | I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3255 | POSTING_READ(pll->pll_reg); |
| 3256 | udelay(150); |
Chris Wilson | e04c735 | 2012-05-02 20:43:56 +0100 | [diff] [blame] | 3257 | |
| 3258 | I915_WRITE(pll->fp0_reg, fp); |
| 3259 | I915_WRITE(pll->pll_reg, dpll & ~DPLL_VCO_ENABLE); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3260 | pll->on = false; |
| 3261 | return pll; |
| 3262 | } |
| 3263 | |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3264 | void intel_cpt_verify_modeset(struct drm_device *dev, int pipe) |
| 3265 | { |
| 3266 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 3267 | int dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3268 | u32 temp; |
| 3269 | |
| 3270 | temp = I915_READ(dslreg); |
| 3271 | udelay(500); |
| 3272 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3273 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
| 3274 | DRM_ERROR("mode set failed: pipe %d stuck\n", pipe); |
| 3275 | } |
| 3276 | } |
| 3277 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3278 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 3279 | { |
| 3280 | struct drm_device *dev = crtc->dev; |
| 3281 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3282 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3283 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3284 | int pipe = intel_crtc->pipe; |
| 3285 | int plane = intel_crtc->plane; |
| 3286 | u32 temp; |
| 3287 | bool is_pch_port; |
| 3288 | |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 3289 | WARN_ON(!crtc->enabled); |
| 3290 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3291 | if (intel_crtc->active) |
| 3292 | return; |
| 3293 | |
| 3294 | intel_crtc->active = true; |
| 3295 | intel_update_watermarks(dev); |
| 3296 | |
| 3297 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 3298 | temp = I915_READ(PCH_LVDS); |
| 3299 | if ((temp & LVDS_PORT_EN) == 0) |
| 3300 | I915_WRITE(PCH_LVDS, temp | LVDS_PORT_EN); |
| 3301 | } |
| 3302 | |
Paulo Zanoni | fc316cb | 2012-10-25 10:37:43 -0200 | [diff] [blame] | 3303 | is_pch_port = ironlake_crtc_driving_pch(crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3304 | |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 3305 | if (is_pch_port) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 3306 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 3307 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 3308 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3309 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 3310 | } else { |
| 3311 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 3312 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 3313 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3314 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 3315 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3316 | if (encoder->pre_enable) |
| 3317 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3318 | |
| 3319 | /* Enable panel fitting for LVDS */ |
| 3320 | if (dev_priv->pch_pf_size && |
Jani Nikula | 547dc04 | 2012-11-02 11:24:03 +0200 | [diff] [blame] | 3321 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
| 3322 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3323 | /* Force use of hard-coded filter coefficients |
| 3324 | * as some pre-programmed values are broken, |
| 3325 | * e.g. x201. |
| 3326 | */ |
Paulo Zanoni | 13888d7 | 2012-11-20 13:27:41 -0200 | [diff] [blame] | 3327 | if (IS_IVYBRIDGE(dev)) |
| 3328 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 3329 | PF_PIPE_SEL_IVB(pipe)); |
| 3330 | else |
| 3331 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 3332 | I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos); |
| 3333 | I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3334 | } |
| 3335 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 3336 | /* |
| 3337 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 3338 | * clocks enabled |
| 3339 | */ |
| 3340 | intel_crtc_load_lut(crtc); |
| 3341 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3342 | intel_enable_pipe(dev_priv, pipe, is_pch_port); |
| 3343 | intel_enable_plane(dev_priv, plane, pipe); |
| 3344 | |
| 3345 | if (is_pch_port) |
| 3346 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3347 | |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 3348 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 3349 | intel_update_fbc(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 3350 | mutex_unlock(&dev->struct_mutex); |
| 3351 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3352 | intel_crtc_update_cursor(crtc, true); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3353 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 3354 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3355 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 3356 | |
| 3357 | if (HAS_PCH_CPT(dev)) |
| 3358 | intel_cpt_verify_modeset(dev, intel_crtc->pipe); |
Daniel Vetter | 6ce9410 | 2012-10-04 19:20:03 +0200 | [diff] [blame] | 3359 | |
| 3360 | /* |
| 3361 | * There seems to be a race in PCH platform hw (at least on some |
| 3362 | * outputs) where an enabled pipe still completes any pageflip right |
| 3363 | * away (as if the pipe is off) instead of waiting for vblank. As soon |
| 3364 | * as the first vblank happend, everything works as expected. Hence just |
| 3365 | * wait for one vblank before returning to avoid strange things |
| 3366 | * happening. |
| 3367 | */ |
| 3368 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3369 | } |
| 3370 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3371 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 3372 | { |
| 3373 | struct drm_device *dev = crtc->dev; |
| 3374 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3375 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3376 | struct intel_encoder *encoder; |
| 3377 | int pipe = intel_crtc->pipe; |
| 3378 | int plane = intel_crtc->plane; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3379 | bool is_pch_port; |
| 3380 | |
| 3381 | WARN_ON(!crtc->enabled); |
| 3382 | |
| 3383 | if (intel_crtc->active) |
| 3384 | return; |
| 3385 | |
| 3386 | intel_crtc->active = true; |
| 3387 | intel_update_watermarks(dev); |
| 3388 | |
Paulo Zanoni | fc316cb | 2012-10-25 10:37:43 -0200 | [diff] [blame] | 3389 | is_pch_port = haswell_crtc_driving_pch(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3390 | |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 3391 | if (is_pch_port) |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 3392 | dev_priv->display.fdi_link_train(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3393 | |
| 3394 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3395 | if (encoder->pre_enable) |
| 3396 | encoder->pre_enable(encoder); |
| 3397 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 3398 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3399 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 3400 | /* Enable panel fitting for eDP */ |
Jani Nikula | 547dc04 | 2012-11-02 11:24:03 +0200 | [diff] [blame] | 3401 | if (dev_priv->pch_pf_size && |
| 3402 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3403 | /* Force use of hard-coded filter coefficients |
| 3404 | * as some pre-programmed values are broken, |
| 3405 | * e.g. x201. |
| 3406 | */ |
Paulo Zanoni | 54075a7 | 2012-11-20 13:27:42 -0200 | [diff] [blame] | 3407 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 3408 | PF_PIPE_SEL_IVB(pipe)); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3409 | I915_WRITE(PF_WIN_POS(pipe), dev_priv->pch_pf_pos); |
| 3410 | I915_WRITE(PF_WIN_SZ(pipe), dev_priv->pch_pf_size); |
| 3411 | } |
| 3412 | |
| 3413 | /* |
| 3414 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 3415 | * clocks enabled |
| 3416 | */ |
| 3417 | intel_crtc_load_lut(crtc); |
| 3418 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 3419 | intel_ddi_set_pipe_settings(crtc); |
| 3420 | intel_ddi_enable_pipe_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3421 | |
| 3422 | intel_enable_pipe(dev_priv, pipe, is_pch_port); |
| 3423 | intel_enable_plane(dev_priv, plane, pipe); |
| 3424 | |
| 3425 | if (is_pch_port) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3426 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3427 | |
| 3428 | mutex_lock(&dev->struct_mutex); |
| 3429 | intel_update_fbc(dev); |
| 3430 | mutex_unlock(&dev->struct_mutex); |
| 3431 | |
| 3432 | intel_crtc_update_cursor(crtc, true); |
| 3433 | |
| 3434 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3435 | encoder->enable(encoder); |
| 3436 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3437 | /* |
| 3438 | * There seems to be a race in PCH platform hw (at least on some |
| 3439 | * outputs) where an enabled pipe still completes any pageflip right |
| 3440 | * away (as if the pipe is off) instead of waiting for vblank. As soon |
| 3441 | * as the first vblank happend, everything works as expected. Hence just |
| 3442 | * wait for one vblank before returning to avoid strange things |
| 3443 | * happening. |
| 3444 | */ |
| 3445 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 3446 | } |
| 3447 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3448 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 3449 | { |
| 3450 | struct drm_device *dev = crtc->dev; |
| 3451 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3452 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3453 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3454 | int pipe = intel_crtc->pipe; |
| 3455 | int plane = intel_crtc->plane; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3456 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3457 | |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3458 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3459 | if (!intel_crtc->active) |
| 3460 | return; |
| 3461 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 3462 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3463 | encoder->disable(encoder); |
| 3464 | |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3465 | intel_crtc_wait_for_pending_flips(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3466 | drm_vblank_off(dev, pipe); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3467 | intel_crtc_update_cursor(crtc, false); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3468 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 3469 | intel_disable_plane(dev_priv, plane, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3470 | |
Chris Wilson | 973d04f | 2011-07-08 12:22:37 +0100 | [diff] [blame] | 3471 | if (dev_priv->cfb_plane == plane) |
| 3472 | intel_disable_fbc(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3473 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 3474 | intel_disable_pipe(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3475 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3476 | /* Disable PF */ |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 3477 | I915_WRITE(PF_CTL(pipe), 0); |
| 3478 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3479 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 3480 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3481 | if (encoder->post_disable) |
| 3482 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3483 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3484 | ironlake_fdi_disable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3485 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 3486 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3487 | |
| 3488 | if (HAS_PCH_CPT(dev)) { |
| 3489 | /* disable TRANS_DP_CTL */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3490 | reg = TRANS_DP_CTL(pipe); |
| 3491 | temp = I915_READ(reg); |
| 3492 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK); |
Eric Anholt | cb3543c | 2011-02-02 12:08:07 -0800 | [diff] [blame] | 3493 | temp |= TRANS_DP_PORT_SEL_NONE; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3494 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3495 | |
| 3496 | /* disable DPLL_SEL */ |
| 3497 | temp = I915_READ(PCH_DPLL_SEL); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 3498 | switch (pipe) { |
| 3499 | case 0: |
Jesse Barnes | d64311a | 2011-10-12 15:01:33 -0700 | [diff] [blame] | 3500 | temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 3501 | break; |
| 3502 | case 1: |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3503 | temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 3504 | break; |
| 3505 | case 2: |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 3506 | /* C shares PLL A or B */ |
Jesse Barnes | d64311a | 2011-10-12 15:01:33 -0700 | [diff] [blame] | 3507 | temp &= ~(TRANSC_DPLL_ENABLE | TRANSC_DPLLB_SEL); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 3508 | break; |
| 3509 | default: |
| 3510 | BUG(); /* wtf */ |
| 3511 | } |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3512 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3513 | } |
| 3514 | |
| 3515 | /* disable PCH DPLL */ |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3516 | intel_disable_pch_pll(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3517 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3518 | ironlake_fdi_pll_disable(intel_crtc); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3519 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3520 | intel_crtc->active = false; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3521 | intel_update_watermarks(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 3522 | |
| 3523 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3524 | intel_update_fbc(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 3525 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3526 | } |
| 3527 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3528 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 3529 | { |
| 3530 | struct drm_device *dev = crtc->dev; |
| 3531 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3532 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3533 | struct intel_encoder *encoder; |
| 3534 | int pipe = intel_crtc->pipe; |
| 3535 | int plane = intel_crtc->plane; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 3536 | enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder; |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 3537 | bool is_pch_port; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3538 | |
| 3539 | if (!intel_crtc->active) |
| 3540 | return; |
| 3541 | |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 3542 | is_pch_port = haswell_crtc_driving_pch(crtc); |
| 3543 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3544 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3545 | encoder->disable(encoder); |
| 3546 | |
| 3547 | intel_crtc_wait_for_pending_flips(crtc); |
| 3548 | drm_vblank_off(dev, pipe); |
| 3549 | intel_crtc_update_cursor(crtc, false); |
| 3550 | |
| 3551 | intel_disable_plane(dev_priv, plane, pipe); |
| 3552 | |
| 3553 | if (dev_priv->cfb_plane == plane) |
| 3554 | intel_disable_fbc(dev); |
| 3555 | |
| 3556 | intel_disable_pipe(dev_priv, pipe); |
| 3557 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 3558 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3559 | |
| 3560 | /* Disable PF */ |
| 3561 | I915_WRITE(PF_CTL(pipe), 0); |
| 3562 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 3563 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 3564 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3565 | |
| 3566 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3567 | if (encoder->post_disable) |
| 3568 | encoder->post_disable(encoder); |
| 3569 | |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 3570 | if (is_pch_port) { |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 3571 | lpt_disable_pch_transcoder(dev_priv); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 3572 | intel_ddi_fdi_disable(crtc); |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 3573 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3574 | |
| 3575 | intel_crtc->active = false; |
| 3576 | intel_update_watermarks(dev); |
| 3577 | |
| 3578 | mutex_lock(&dev->struct_mutex); |
| 3579 | intel_update_fbc(dev); |
| 3580 | mutex_unlock(&dev->struct_mutex); |
| 3581 | } |
| 3582 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3583 | static void ironlake_crtc_off(struct drm_crtc *crtc) |
| 3584 | { |
| 3585 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3586 | intel_put_pch_pll(intel_crtc); |
| 3587 | } |
| 3588 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 3589 | static void haswell_crtc_off(struct drm_crtc *crtc) |
| 3590 | { |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 3591 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3592 | |
| 3593 | /* Stop saying we're using TRANSCODER_EDP because some other CRTC might |
| 3594 | * start using it. */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 3595 | intel_crtc->cpu_transcoder = (enum transcoder) intel_crtc->pipe; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 3596 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 3597 | intel_ddi_put_crtc_pll(crtc); |
| 3598 | } |
| 3599 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3600 | static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable) |
| 3601 | { |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3602 | if (!enable && intel_crtc->overlay) { |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 3603 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 3604 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 3605 | |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 3606 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 3607 | dev_priv->mm.interruptible = false; |
| 3608 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 3609 | dev_priv->mm.interruptible = true; |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 3610 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3611 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3612 | |
Chris Wilson | 5dcdbcb | 2010-08-12 13:50:28 +0100 | [diff] [blame] | 3613 | /* Let userspace switch the overlay on again. In most cases userspace |
| 3614 | * has to recompute where to put it anyway. |
| 3615 | */ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3616 | } |
| 3617 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3618 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3619 | { |
| 3620 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3621 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3622 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3623 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3624 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 3625 | int plane = intel_crtc->plane; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3626 | |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 3627 | WARN_ON(!crtc->enabled); |
| 3628 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3629 | if (intel_crtc->active) |
| 3630 | return; |
| 3631 | |
| 3632 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3633 | intel_update_watermarks(dev); |
| 3634 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 3635 | intel_enable_pll(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 3636 | intel_enable_pipe(dev_priv, pipe, false); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 3637 | intel_enable_plane(dev_priv, plane, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3638 | |
| 3639 | intel_crtc_load_lut(crtc); |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 3640 | intel_update_fbc(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3641 | |
| 3642 | /* Give the overlay scaler a chance to enable if it's on this pipe */ |
| 3643 | intel_crtc_dpms_overlay(intel_crtc, true); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3644 | intel_crtc_update_cursor(crtc, true); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3645 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 3646 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3647 | encoder->enable(encoder); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3648 | } |
| 3649 | |
| 3650 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 3651 | { |
| 3652 | struct drm_device *dev = crtc->dev; |
| 3653 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3654 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3655 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3656 | int pipe = intel_crtc->pipe; |
| 3657 | int plane = intel_crtc->plane; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3658 | |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3659 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3660 | if (!intel_crtc->active) |
| 3661 | return; |
| 3662 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 3663 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3664 | encoder->disable(encoder); |
| 3665 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3666 | /* Give the overlay scaler a chance to disable if it's on this pipe */ |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3667 | intel_crtc_wait_for_pending_flips(crtc); |
| 3668 | drm_vblank_off(dev, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3669 | intel_crtc_dpms_overlay(intel_crtc, false); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3670 | intel_crtc_update_cursor(crtc, false); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3671 | |
Chris Wilson | 973d04f | 2011-07-08 12:22:37 +0100 | [diff] [blame] | 3672 | if (dev_priv->cfb_plane == plane) |
| 3673 | intel_disable_fbc(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3674 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 3675 | intel_disable_plane(dev_priv, plane, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 3676 | intel_disable_pipe(dev_priv, pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 3677 | intel_disable_pll(dev_priv, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3678 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3679 | intel_crtc->active = false; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3680 | intel_update_fbc(dev); |
| 3681 | intel_update_watermarks(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3682 | } |
| 3683 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3684 | static void i9xx_crtc_off(struct drm_crtc *crtc) |
| 3685 | { |
| 3686 | } |
| 3687 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3688 | static void intel_crtc_update_sarea(struct drm_crtc *crtc, |
| 3689 | bool enabled) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3690 | { |
| 3691 | struct drm_device *dev = crtc->dev; |
| 3692 | struct drm_i915_master_private *master_priv; |
| 3693 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3694 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3695 | |
| 3696 | if (!dev->primary->master) |
| 3697 | return; |
| 3698 | |
| 3699 | master_priv = dev->primary->master->driver_priv; |
| 3700 | if (!master_priv->sarea_priv) |
| 3701 | return; |
| 3702 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3703 | switch (pipe) { |
| 3704 | case 0: |
| 3705 | master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0; |
| 3706 | master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0; |
| 3707 | break; |
| 3708 | case 1: |
| 3709 | master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0; |
| 3710 | master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0; |
| 3711 | break; |
| 3712 | default: |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 3713 | DRM_ERROR("Can't update pipe %c in SAREA\n", pipe_name(pipe)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3714 | break; |
| 3715 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3716 | } |
| 3717 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3718 | /** |
| 3719 | * Sets the power management mode of the pipe and plane. |
| 3720 | */ |
| 3721 | void intel_crtc_update_dpms(struct drm_crtc *crtc) |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3722 | { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3723 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3724 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3725 | struct intel_encoder *intel_encoder; |
| 3726 | bool enable = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3727 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3728 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 3729 | enable |= intel_encoder->connectors_active; |
| 3730 | |
| 3731 | if (enable) |
| 3732 | dev_priv->display.crtc_enable(crtc); |
| 3733 | else |
| 3734 | dev_priv->display.crtc_disable(crtc); |
| 3735 | |
| 3736 | intel_crtc_update_sarea(crtc, enable); |
| 3737 | } |
| 3738 | |
| 3739 | static void intel_crtc_noop(struct drm_crtc *crtc) |
| 3740 | { |
| 3741 | } |
| 3742 | |
| 3743 | static void intel_crtc_disable(struct drm_crtc *crtc) |
| 3744 | { |
| 3745 | struct drm_device *dev = crtc->dev; |
| 3746 | struct drm_connector *connector; |
| 3747 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3748 | |
| 3749 | /* crtc should still be enabled when we disable it. */ |
| 3750 | WARN_ON(!crtc->enabled); |
| 3751 | |
| 3752 | dev_priv->display.crtc_disable(crtc); |
| 3753 | intel_crtc_update_sarea(crtc, false); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3754 | dev_priv->display.off(crtc); |
| 3755 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 3756 | assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane); |
| 3757 | assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe); |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3758 | |
| 3759 | if (crtc->fb) { |
| 3760 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 3761 | intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj); |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3762 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3763 | crtc->fb = NULL; |
| 3764 | } |
| 3765 | |
| 3766 | /* Update computed state. */ |
| 3767 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 3768 | if (!connector->encoder || !connector->encoder->crtc) |
| 3769 | continue; |
| 3770 | |
| 3771 | if (connector->encoder->crtc != crtc) |
| 3772 | continue; |
| 3773 | |
| 3774 | connector->dpms = DRM_MODE_DPMS_OFF; |
| 3775 | to_intel_encoder(connector->encoder)->connectors_active = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3776 | } |
| 3777 | } |
| 3778 | |
Daniel Vetter | a261b24 | 2012-07-26 19:21:47 +0200 | [diff] [blame] | 3779 | void intel_modeset_disable(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3780 | { |
Daniel Vetter | a261b24 | 2012-07-26 19:21:47 +0200 | [diff] [blame] | 3781 | struct drm_crtc *crtc; |
| 3782 | |
| 3783 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 3784 | if (crtc->enabled) |
| 3785 | intel_crtc_disable(crtc); |
| 3786 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3787 | } |
| 3788 | |
Daniel Vetter | 1f70385 | 2012-07-11 16:51:39 +0200 | [diff] [blame] | 3789 | void intel_encoder_noop(struct drm_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3790 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3791 | } |
| 3792 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3793 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 3794 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 3795 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3796 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3797 | drm_encoder_cleanup(encoder); |
| 3798 | kfree(intel_encoder); |
| 3799 | } |
| 3800 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3801 | /* Simple dpms helper for encodres with just one connector, no cloning and only |
| 3802 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
| 3803 | * state of the entire output pipe. */ |
| 3804 | void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
| 3805 | { |
| 3806 | if (mode == DRM_MODE_DPMS_ON) { |
| 3807 | encoder->connectors_active = true; |
| 3808 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 3809 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3810 | } else { |
| 3811 | encoder->connectors_active = false; |
| 3812 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 3813 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3814 | } |
| 3815 | } |
| 3816 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 3817 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 3818 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 3819 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 3820 | { |
| 3821 | if (connector->get_hw_state(connector)) { |
| 3822 | struct intel_encoder *encoder = connector->encoder; |
| 3823 | struct drm_crtc *crtc; |
| 3824 | bool encoder_enabled; |
| 3825 | enum pipe pipe; |
| 3826 | |
| 3827 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 3828 | connector->base.base.id, |
| 3829 | drm_get_connector_name(&connector->base)); |
| 3830 | |
| 3831 | WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
| 3832 | "wrong connector dpms state\n"); |
| 3833 | WARN(connector->base.encoder != &encoder->base, |
| 3834 | "active connector not linked to encoder\n"); |
| 3835 | WARN(!encoder->connectors_active, |
| 3836 | "encoder->connectors_active not set\n"); |
| 3837 | |
| 3838 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); |
| 3839 | WARN(!encoder_enabled, "encoder not enabled\n"); |
| 3840 | if (WARN_ON(!encoder->base.crtc)) |
| 3841 | return; |
| 3842 | |
| 3843 | crtc = encoder->base.crtc; |
| 3844 | |
| 3845 | WARN(!crtc->enabled, "crtc not enabled\n"); |
| 3846 | WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
| 3847 | WARN(pipe != to_intel_crtc(crtc)->pipe, |
| 3848 | "encoder active on the wrong pipe\n"); |
| 3849 | } |
| 3850 | } |
| 3851 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3852 | /* Even simpler default implementation, if there's really no special case to |
| 3853 | * consider. */ |
| 3854 | void intel_connector_dpms(struct drm_connector *connector, int mode) |
| 3855 | { |
| 3856 | struct intel_encoder *encoder = intel_attached_encoder(connector); |
| 3857 | |
| 3858 | /* All the simple cases only support two dpms states. */ |
| 3859 | if (mode != DRM_MODE_DPMS_ON) |
| 3860 | mode = DRM_MODE_DPMS_OFF; |
| 3861 | |
| 3862 | if (mode == connector->dpms) |
| 3863 | return; |
| 3864 | |
| 3865 | connector->dpms = mode; |
| 3866 | |
| 3867 | /* Only need to change hw state when actually enabled */ |
| 3868 | if (encoder->base.crtc) |
| 3869 | intel_encoder_dpms(encoder, mode); |
| 3870 | else |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 3871 | WARN_ON(encoder->connectors_active != false); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 3872 | |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 3873 | intel_modeset_check_state(connector->dev); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3874 | } |
| 3875 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 3876 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 3877 | * one connector and no cloning and hence the encoder state determines the state |
| 3878 | * of the connector. */ |
| 3879 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 3880 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 3881 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 3882 | struct intel_encoder *encoder = connector->encoder; |
| 3883 | |
| 3884 | return encoder->get_hw_state(encoder, &pipe); |
| 3885 | } |
| 3886 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3887 | static bool intel_crtc_mode_fixup(struct drm_crtc *crtc, |
Daniel Vetter | 35313cd | 2012-07-20 10:30:45 +0200 | [diff] [blame] | 3888 | const struct drm_display_mode *mode, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3889 | struct drm_display_mode *adjusted_mode) |
| 3890 | { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3891 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 3892 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 3893 | if (HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3894 | /* FDI link clock is fixed at 2.7G */ |
Jesse Barnes | 2377b74 | 2010-07-07 14:06:43 -0700 | [diff] [blame] | 3895 | if (mode->clock * 3 > IRONLAKE_FDI_FREQ * 4) |
| 3896 | return false; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3897 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 3898 | |
Daniel Vetter | f9bef08 | 2012-04-15 19:53:19 +0200 | [diff] [blame] | 3899 | /* All interlaced capable intel hw wants timings in frames. Note though |
| 3900 | * that intel_lvds_mode_fixup does some funny tricks with the crtc |
| 3901 | * timings, so we need to be careful not to clobber these.*/ |
| 3902 | if (!(adjusted_mode->private_flags & INTEL_MODE_CRTC_TIMINGS_SET)) |
| 3903 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 3904 | |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 3905 | /* WaPruneModeWithIncorrectHsyncOffset: Cantiga+ cannot handle modes |
| 3906 | * with a hsync front porch of 0. |
| 3907 | */ |
| 3908 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
| 3909 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) |
| 3910 | return false; |
| 3911 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3912 | return true; |
| 3913 | } |
| 3914 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 3915 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 3916 | { |
| 3917 | return 400000; /* FIXME */ |
| 3918 | } |
| 3919 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3920 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3921 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3922 | return 400000; |
| 3923 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3924 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3925 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 3926 | { |
| 3927 | return 333000; |
| 3928 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3929 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3930 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 3931 | { |
| 3932 | return 200000; |
| 3933 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3934 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3935 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 3936 | { |
| 3937 | u16 gcfgc = 0; |
| 3938 | |
| 3939 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 3940 | |
| 3941 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3942 | return 133000; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3943 | else { |
| 3944 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 3945 | case GC_DISPLAY_CLOCK_333_MHZ: |
| 3946 | return 333000; |
| 3947 | default: |
| 3948 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 3949 | return 190000; |
| 3950 | } |
| 3951 | } |
| 3952 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3953 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 3954 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 3955 | { |
| 3956 | return 266000; |
| 3957 | } |
| 3958 | |
| 3959 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 3960 | { |
| 3961 | u16 hpllcc = 0; |
| 3962 | /* Assume that the hardware is in the high speed state. This |
| 3963 | * should be the default. |
| 3964 | */ |
| 3965 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 3966 | case GC_CLOCK_133_200: |
| 3967 | case GC_CLOCK_100_200: |
| 3968 | return 200000; |
| 3969 | case GC_CLOCK_166_250: |
| 3970 | return 250000; |
| 3971 | case GC_CLOCK_100_133: |
| 3972 | return 133000; |
| 3973 | } |
| 3974 | |
| 3975 | /* Shouldn't happen */ |
| 3976 | return 0; |
| 3977 | } |
| 3978 | |
| 3979 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 3980 | { |
| 3981 | return 133000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3982 | } |
| 3983 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3984 | static void |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 3985 | intel_reduce_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3986 | { |
| 3987 | while (*num > 0xffffff || *den > 0xffffff) { |
| 3988 | *num >>= 1; |
| 3989 | *den >>= 1; |
| 3990 | } |
| 3991 | } |
| 3992 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 3993 | void |
| 3994 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 3995 | int pixel_clock, int link_clock, |
| 3996 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3997 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 3998 | m_n->tu = 64; |
Chris Wilson | 22ed111 | 2010-12-04 01:01:29 +0000 | [diff] [blame] | 3999 | m_n->gmch_m = bits_per_pixel * pixel_clock; |
| 4000 | m_n->gmch_n = link_clock * nlanes * 8; |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 4001 | intel_reduce_ratio(&m_n->gmch_m, &m_n->gmch_n); |
Chris Wilson | 22ed111 | 2010-12-04 01:01:29 +0000 | [diff] [blame] | 4002 | m_n->link_m = pixel_clock; |
| 4003 | m_n->link_n = link_clock; |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 4004 | intel_reduce_ratio(&m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4005 | } |
| 4006 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 4007 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 4008 | { |
Keith Packard | 72bbe58 | 2011-09-26 16:09:45 -0700 | [diff] [blame] | 4009 | if (i915_panel_use_ssc >= 0) |
| 4010 | return i915_panel_use_ssc != 0; |
| 4011 | return dev_priv->lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 4012 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 4013 | } |
| 4014 | |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4015 | /** |
| 4016 | * intel_choose_pipe_bpp_dither - figure out what color depth the pipe should send |
| 4017 | * @crtc: CRTC structure |
Adam Jackson | 3b5c78a | 2011-12-13 15:41:00 -0800 | [diff] [blame] | 4018 | * @mode: requested mode |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4019 | * |
| 4020 | * A pipe may be connected to one or more outputs. Based on the depth of the |
| 4021 | * attached framebuffer, choose a good color depth to use on the pipe. |
| 4022 | * |
| 4023 | * If possible, match the pipe depth to the fb depth. In some cases, this |
| 4024 | * isn't ideal, because the connected output supports a lesser or restricted |
| 4025 | * set of depths. Resolve that here: |
| 4026 | * LVDS typically supports only 6bpc, so clamp down in that case |
| 4027 | * HDMI supports only 8bpc or 12bpc, so clamp to 8bpc with dither for 10bpc |
| 4028 | * Displays may support a restricted set as well, check EDID and clamp as |
| 4029 | * appropriate. |
Adam Jackson | 3b5c78a | 2011-12-13 15:41:00 -0800 | [diff] [blame] | 4030 | * DP may want to dither down to 6bpc to fit larger modes |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4031 | * |
| 4032 | * RETURNS: |
| 4033 | * Dithering requirement (i.e. false if display bpc and pipe bpc match, |
| 4034 | * true if they don't match). |
| 4035 | */ |
| 4036 | static bool intel_choose_pipe_bpp_dither(struct drm_crtc *crtc, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 4037 | struct drm_framebuffer *fb, |
Adam Jackson | 3b5c78a | 2011-12-13 15:41:00 -0800 | [diff] [blame] | 4038 | unsigned int *pipe_bpp, |
| 4039 | struct drm_display_mode *mode) |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4040 | { |
| 4041 | struct drm_device *dev = crtc->dev; |
| 4042 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4043 | struct drm_connector *connector; |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 4044 | struct intel_encoder *intel_encoder; |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4045 | unsigned int display_bpc = UINT_MAX, bpc; |
| 4046 | |
| 4047 | /* Walk the encoders & connectors on this crtc, get min bpc */ |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 4048 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4049 | |
| 4050 | if (intel_encoder->type == INTEL_OUTPUT_LVDS) { |
| 4051 | unsigned int lvds_bpc; |
| 4052 | |
| 4053 | if ((I915_READ(PCH_LVDS) & LVDS_A3_POWER_MASK) == |
| 4054 | LVDS_A3_POWER_UP) |
| 4055 | lvds_bpc = 8; |
| 4056 | else |
| 4057 | lvds_bpc = 6; |
| 4058 | |
| 4059 | if (lvds_bpc < display_bpc) { |
Adam Jackson | 8282049 | 2011-10-10 16:33:34 -0400 | [diff] [blame] | 4060 | DRM_DEBUG_KMS("clamping display bpc (was %d) to LVDS (%d)\n", display_bpc, lvds_bpc); |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4061 | display_bpc = lvds_bpc; |
| 4062 | } |
| 4063 | continue; |
| 4064 | } |
| 4065 | |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4066 | /* Not one of the known troublemakers, check the EDID */ |
| 4067 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 4068 | head) { |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 4069 | if (connector->encoder != &intel_encoder->base) |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4070 | continue; |
| 4071 | |
Jesse Barnes | 62ac41a | 2011-07-28 12:55:14 -0700 | [diff] [blame] | 4072 | /* Don't use an invalid EDID bpc value */ |
| 4073 | if (connector->display_info.bpc && |
| 4074 | connector->display_info.bpc < display_bpc) { |
Adam Jackson | 8282049 | 2011-10-10 16:33:34 -0400 | [diff] [blame] | 4075 | DRM_DEBUG_KMS("clamping display bpc (was %d) to EDID reported max of %d\n", display_bpc, connector->display_info.bpc); |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4076 | display_bpc = connector->display_info.bpc; |
| 4077 | } |
| 4078 | } |
| 4079 | |
| 4080 | /* |
| 4081 | * HDMI is either 12 or 8, so if the display lets 10bpc sneak |
| 4082 | * through, clamp it down. (Note: >12bpc will be caught below.) |
| 4083 | */ |
| 4084 | if (intel_encoder->type == INTEL_OUTPUT_HDMI) { |
| 4085 | if (display_bpc > 8 && display_bpc < 12) { |
Adam Jackson | 8282049 | 2011-10-10 16:33:34 -0400 | [diff] [blame] | 4086 | DRM_DEBUG_KMS("forcing bpc to 12 for HDMI\n"); |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4087 | display_bpc = 12; |
| 4088 | } else { |
Adam Jackson | 8282049 | 2011-10-10 16:33:34 -0400 | [diff] [blame] | 4089 | DRM_DEBUG_KMS("forcing bpc to 8 for HDMI\n"); |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4090 | display_bpc = 8; |
| 4091 | } |
| 4092 | } |
| 4093 | } |
| 4094 | |
Adam Jackson | 3b5c78a | 2011-12-13 15:41:00 -0800 | [diff] [blame] | 4095 | if (mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) { |
| 4096 | DRM_DEBUG_KMS("Dithering DP to 6bpc\n"); |
| 4097 | display_bpc = 6; |
| 4098 | } |
| 4099 | |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4100 | /* |
| 4101 | * We could just drive the pipe at the highest bpc all the time and |
| 4102 | * enable dithering as needed, but that costs bandwidth. So choose |
| 4103 | * the minimum value that expresses the full color range of the fb but |
| 4104 | * also stays within the max display bpc discovered above. |
| 4105 | */ |
| 4106 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 4107 | switch (fb->depth) { |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4108 | case 8: |
| 4109 | bpc = 8; /* since we go through a colormap */ |
| 4110 | break; |
| 4111 | case 15: |
| 4112 | case 16: |
| 4113 | bpc = 6; /* min is 18bpp */ |
| 4114 | break; |
| 4115 | case 24: |
Keith Packard | 578393c | 2011-09-05 11:53:21 -0700 | [diff] [blame] | 4116 | bpc = 8; |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4117 | break; |
| 4118 | case 30: |
Keith Packard | 578393c | 2011-09-05 11:53:21 -0700 | [diff] [blame] | 4119 | bpc = 10; |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4120 | break; |
| 4121 | case 48: |
Keith Packard | 578393c | 2011-09-05 11:53:21 -0700 | [diff] [blame] | 4122 | bpc = 12; |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4123 | break; |
| 4124 | default: |
| 4125 | DRM_DEBUG("unsupported depth, assuming 24 bits\n"); |
| 4126 | bpc = min((unsigned int)8, display_bpc); |
| 4127 | break; |
| 4128 | } |
| 4129 | |
Keith Packard | 578393c | 2011-09-05 11:53:21 -0700 | [diff] [blame] | 4130 | display_bpc = min(display_bpc, bpc); |
| 4131 | |
Adam Jackson | 8282049 | 2011-10-10 16:33:34 -0400 | [diff] [blame] | 4132 | DRM_DEBUG_KMS("setting pipe bpc to %d (max display bpc %d)\n", |
| 4133 | bpc, display_bpc); |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4134 | |
Keith Packard | 578393c | 2011-09-05 11:53:21 -0700 | [diff] [blame] | 4135 | *pipe_bpp = display_bpc * 3; |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 4136 | |
| 4137 | return display_bpc != bpc; |
| 4138 | } |
| 4139 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4140 | static int vlv_get_refclk(struct drm_crtc *crtc) |
| 4141 | { |
| 4142 | struct drm_device *dev = crtc->dev; |
| 4143 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4144 | int refclk = 27000; /* for DP & HDMI */ |
| 4145 | |
| 4146 | return 100000; /* only one validated so far */ |
| 4147 | |
| 4148 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { |
| 4149 | refclk = 96000; |
| 4150 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 4151 | if (intel_panel_use_ssc(dev_priv)) |
| 4152 | refclk = 100000; |
| 4153 | else |
| 4154 | refclk = 96000; |
| 4155 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) { |
| 4156 | refclk = 100000; |
| 4157 | } |
| 4158 | |
| 4159 | return refclk; |
| 4160 | } |
| 4161 | |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4162 | static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors) |
| 4163 | { |
| 4164 | struct drm_device *dev = crtc->dev; |
| 4165 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4166 | int refclk; |
| 4167 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4168 | if (IS_VALLEYVIEW(dev)) { |
| 4169 | refclk = vlv_get_refclk(crtc); |
| 4170 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4171 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
| 4172 | refclk = dev_priv->lvds_ssc_freq * 1000; |
| 4173 | DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n", |
| 4174 | refclk / 1000); |
| 4175 | } else if (!IS_GEN2(dev)) { |
| 4176 | refclk = 96000; |
| 4177 | } else { |
| 4178 | refclk = 48000; |
| 4179 | } |
| 4180 | |
| 4181 | return refclk; |
| 4182 | } |
| 4183 | |
| 4184 | static void i9xx_adjust_sdvo_tv_clock(struct drm_display_mode *adjusted_mode, |
| 4185 | intel_clock_t *clock) |
| 4186 | { |
| 4187 | /* SDVO TV has fixed PLL values depend on its clock range, |
| 4188 | this mirrors vbios setting. */ |
| 4189 | if (adjusted_mode->clock >= 100000 |
| 4190 | && adjusted_mode->clock < 140500) { |
| 4191 | clock->p1 = 2; |
| 4192 | clock->p2 = 10; |
| 4193 | clock->n = 3; |
| 4194 | clock->m1 = 16; |
| 4195 | clock->m2 = 8; |
| 4196 | } else if (adjusted_mode->clock >= 140500 |
| 4197 | && adjusted_mode->clock <= 200000) { |
| 4198 | clock->p1 = 1; |
| 4199 | clock->p2 = 10; |
| 4200 | clock->n = 6; |
| 4201 | clock->m1 = 12; |
| 4202 | clock->m2 = 8; |
| 4203 | } |
| 4204 | } |
| 4205 | |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4206 | static void i9xx_update_pll_dividers(struct drm_crtc *crtc, |
| 4207 | intel_clock_t *clock, |
| 4208 | intel_clock_t *reduced_clock) |
| 4209 | { |
| 4210 | struct drm_device *dev = crtc->dev; |
| 4211 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4212 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4213 | int pipe = intel_crtc->pipe; |
| 4214 | u32 fp, fp2 = 0; |
| 4215 | |
| 4216 | if (IS_PINEVIEW(dev)) { |
| 4217 | fp = (1 << clock->n) << 16 | clock->m1 << 8 | clock->m2; |
| 4218 | if (reduced_clock) |
| 4219 | fp2 = (1 << reduced_clock->n) << 16 | |
| 4220 | reduced_clock->m1 << 8 | reduced_clock->m2; |
| 4221 | } else { |
| 4222 | fp = clock->n << 16 | clock->m1 << 8 | clock->m2; |
| 4223 | if (reduced_clock) |
| 4224 | fp2 = reduced_clock->n << 16 | reduced_clock->m1 << 8 | |
| 4225 | reduced_clock->m2; |
| 4226 | } |
| 4227 | |
| 4228 | I915_WRITE(FP0(pipe), fp); |
| 4229 | |
| 4230 | intel_crtc->lowfreq_avail = false; |
| 4231 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
| 4232 | reduced_clock && i915_powersave) { |
| 4233 | I915_WRITE(FP1(pipe), fp2); |
| 4234 | intel_crtc->lowfreq_avail = true; |
| 4235 | } else { |
| 4236 | I915_WRITE(FP1(pipe), fp); |
| 4237 | } |
| 4238 | } |
| 4239 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4240 | static void vlv_update_pll(struct drm_crtc *crtc, |
| 4241 | struct drm_display_mode *mode, |
| 4242 | struct drm_display_mode *adjusted_mode, |
| 4243 | intel_clock_t *clock, intel_clock_t *reduced_clock, |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4244 | int num_connectors) |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4245 | { |
| 4246 | struct drm_device *dev = crtc->dev; |
| 4247 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4248 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4249 | int pipe = intel_crtc->pipe; |
| 4250 | u32 dpll, mdiv, pdiv; |
| 4251 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4252 | bool is_sdvo; |
| 4253 | u32 temp; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4254 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 4255 | mutex_lock(&dev_priv->dpio_lock); |
| 4256 | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4257 | is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) || |
| 4258 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI); |
| 4259 | |
| 4260 | dpll = DPLL_VGA_MODE_DIS; |
| 4261 | dpll |= DPLL_EXT_BUFFER_ENABLE_VLV; |
| 4262 | dpll |= DPLL_REFA_CLK_ENABLE_VLV; |
| 4263 | dpll |= DPLL_INTEGRATED_CLOCK_VLV; |
| 4264 | |
| 4265 | I915_WRITE(DPLL(pipe), dpll); |
| 4266 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4267 | |
| 4268 | bestn = clock->n; |
| 4269 | bestm1 = clock->m1; |
| 4270 | bestm2 = clock->m2; |
| 4271 | bestp1 = clock->p1; |
| 4272 | bestp2 = clock->p2; |
| 4273 | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4274 | /* |
| 4275 | * In Valleyview PLL and program lane counter registers are exposed |
| 4276 | * through DPIO interface |
| 4277 | */ |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4278 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 4279 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 4280 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
| 4281 | mdiv |= (1 << DPIO_POST_DIV_SHIFT); |
| 4282 | mdiv |= (1 << DPIO_K_SHIFT); |
| 4283 | mdiv |= DPIO_ENABLE_CALIBRATION; |
| 4284 | intel_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv); |
| 4285 | |
| 4286 | intel_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), 0x01000000); |
| 4287 | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4288 | pdiv = (1 << DPIO_REFSEL_OVERRIDE) | (5 << DPIO_PLL_MODESEL_SHIFT) | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4289 | (3 << DPIO_BIAS_CURRENT_CTL_SHIFT) | (1<<20) | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4290 | (7 << DPIO_PLL_REFCLK_SEL_SHIFT) | (8 << DPIO_DRIVER_CTL_SHIFT) | |
| 4291 | (5 << DPIO_CLK_BIAS_CTL_SHIFT); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4292 | intel_dpio_write(dev_priv, DPIO_REFSFR(pipe), pdiv); |
| 4293 | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4294 | intel_dpio_write(dev_priv, DPIO_LFP_COEFF(pipe), 0x005f003b); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4295 | |
| 4296 | dpll |= DPLL_VCO_ENABLE; |
| 4297 | I915_WRITE(DPLL(pipe), dpll); |
| 4298 | POSTING_READ(DPLL(pipe)); |
| 4299 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 4300 | DRM_ERROR("DPLL %d failed to lock\n", pipe); |
| 4301 | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4302 | intel_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x620); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4303 | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4304 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 4305 | intel_dp_set_m_n(crtc, mode, adjusted_mode); |
| 4306 | |
| 4307 | I915_WRITE(DPLL(pipe), dpll); |
| 4308 | |
| 4309 | /* Wait for the clocks to stabilize. */ |
| 4310 | POSTING_READ(DPLL(pipe)); |
| 4311 | udelay(150); |
| 4312 | |
| 4313 | temp = 0; |
| 4314 | if (is_sdvo) { |
| 4315 | temp = intel_mode_get_pixel_multiplier(adjusted_mode); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4316 | if (temp > 1) |
| 4317 | temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 4318 | else |
| 4319 | temp = 0; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4320 | } |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4321 | I915_WRITE(DPLL_MD(pipe), temp); |
| 4322 | POSTING_READ(DPLL_MD(pipe)); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4323 | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4324 | /* Now program lane control registers */ |
| 4325 | if(intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) |
| 4326 | || intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
| 4327 | { |
| 4328 | temp = 0x1000C4; |
| 4329 | if(pipe == 1) |
| 4330 | temp |= (1 << 21); |
| 4331 | intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL1, temp); |
| 4332 | } |
| 4333 | if(intel_pipe_has_type(crtc,INTEL_OUTPUT_EDP)) |
| 4334 | { |
| 4335 | temp = 0x1000C4; |
| 4336 | if(pipe == 1) |
| 4337 | temp |= (1 << 21); |
| 4338 | intel_dpio_write(dev_priv, DPIO_DATA_CHANNEL2, temp); |
| 4339 | } |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 4340 | |
| 4341 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4342 | } |
| 4343 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4344 | static void i9xx_update_pll(struct drm_crtc *crtc, |
| 4345 | struct drm_display_mode *mode, |
| 4346 | struct drm_display_mode *adjusted_mode, |
| 4347 | intel_clock_t *clock, intel_clock_t *reduced_clock, |
| 4348 | int num_connectors) |
| 4349 | { |
| 4350 | struct drm_device *dev = crtc->dev; |
| 4351 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4352 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | dafd226 | 2012-11-26 17:22:07 +0100 | [diff] [blame] | 4353 | struct intel_encoder *encoder; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4354 | int pipe = intel_crtc->pipe; |
| 4355 | u32 dpll; |
| 4356 | bool is_sdvo; |
| 4357 | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4358 | i9xx_update_pll_dividers(crtc, clock, reduced_clock); |
| 4359 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4360 | is_sdvo = intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO) || |
| 4361 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI); |
| 4362 | |
| 4363 | dpll = DPLL_VGA_MODE_DIS; |
| 4364 | |
| 4365 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
| 4366 | dpll |= DPLLB_MODE_LVDS; |
| 4367 | else |
| 4368 | dpll |= DPLLB_MODE_DAC_SERIAL; |
| 4369 | if (is_sdvo) { |
| 4370 | int pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode); |
| 4371 | if (pixel_multiplier > 1) { |
| 4372 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) |
| 4373 | dpll |= (pixel_multiplier - 1) << SDVO_MULTIPLIER_SHIFT_HIRES; |
| 4374 | } |
| 4375 | dpll |= DPLL_DVO_HIGH_SPEED; |
| 4376 | } |
| 4377 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 4378 | dpll |= DPLL_DVO_HIGH_SPEED; |
| 4379 | |
| 4380 | /* compute bitmask from p1 value */ |
| 4381 | if (IS_PINEVIEW(dev)) |
| 4382 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 4383 | else { |
| 4384 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 4385 | if (IS_G4X(dev) && reduced_clock) |
| 4386 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 4387 | } |
| 4388 | switch (clock->p2) { |
| 4389 | case 5: |
| 4390 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 4391 | break; |
| 4392 | case 7: |
| 4393 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 4394 | break; |
| 4395 | case 10: |
| 4396 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 4397 | break; |
| 4398 | case 14: |
| 4399 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 4400 | break; |
| 4401 | } |
| 4402 | if (INTEL_INFO(dev)->gen >= 4) |
| 4403 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 4404 | |
| 4405 | if (is_sdvo && intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT)) |
| 4406 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
| 4407 | else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT)) |
| 4408 | /* XXX: just matching BIOS for now */ |
| 4409 | /* dpll |= PLL_REF_INPUT_TVCLKINBC; */ |
| 4410 | dpll |= 3; |
| 4411 | else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
| 4412 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 4413 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 4414 | else |
| 4415 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 4416 | |
| 4417 | dpll |= DPLL_VCO_ENABLE; |
| 4418 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE); |
| 4419 | POSTING_READ(DPLL(pipe)); |
| 4420 | udelay(150); |
| 4421 | |
Daniel Vetter | dafd226 | 2012-11-26 17:22:07 +0100 | [diff] [blame] | 4422 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4423 | if (encoder->pre_pll_enable) |
| 4424 | encoder->pre_pll_enable(encoder); |
| 4425 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4426 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) |
| 4427 | intel_dp_set_m_n(crtc, mode, adjusted_mode); |
| 4428 | |
| 4429 | I915_WRITE(DPLL(pipe), dpll); |
| 4430 | |
| 4431 | /* Wait for the clocks to stabilize. */ |
| 4432 | POSTING_READ(DPLL(pipe)); |
| 4433 | udelay(150); |
| 4434 | |
| 4435 | if (INTEL_INFO(dev)->gen >= 4) { |
| 4436 | u32 temp = 0; |
| 4437 | if (is_sdvo) { |
| 4438 | temp = intel_mode_get_pixel_multiplier(adjusted_mode); |
| 4439 | if (temp > 1) |
| 4440 | temp = (temp - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 4441 | else |
| 4442 | temp = 0; |
| 4443 | } |
| 4444 | I915_WRITE(DPLL_MD(pipe), temp); |
| 4445 | } else { |
| 4446 | /* The pixel multiplier can only be updated once the |
| 4447 | * DPLL is enabled and the clocks are stable. |
| 4448 | * |
| 4449 | * So write it again. |
| 4450 | */ |
| 4451 | I915_WRITE(DPLL(pipe), dpll); |
| 4452 | } |
| 4453 | } |
| 4454 | |
| 4455 | static void i8xx_update_pll(struct drm_crtc *crtc, |
| 4456 | struct drm_display_mode *adjusted_mode, |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4457 | intel_clock_t *clock, intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4458 | int num_connectors) |
| 4459 | { |
| 4460 | struct drm_device *dev = crtc->dev; |
| 4461 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4462 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | dafd226 | 2012-11-26 17:22:07 +0100 | [diff] [blame] | 4463 | struct intel_encoder *encoder; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4464 | int pipe = intel_crtc->pipe; |
| 4465 | u32 dpll; |
| 4466 | |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4467 | i9xx_update_pll_dividers(crtc, clock, reduced_clock); |
| 4468 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4469 | dpll = DPLL_VGA_MODE_DIS; |
| 4470 | |
| 4471 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 4472 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 4473 | } else { |
| 4474 | if (clock->p1 == 2) |
| 4475 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 4476 | else |
| 4477 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 4478 | if (clock->p2 == 4) |
| 4479 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 4480 | } |
| 4481 | |
| 4482 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_TVOUT)) |
| 4483 | /* XXX: just matching BIOS for now */ |
| 4484 | /* dpll |= PLL_REF_INPUT_TVCLKINBC; */ |
| 4485 | dpll |= 3; |
| 4486 | else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
| 4487 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 4488 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 4489 | else |
| 4490 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 4491 | |
| 4492 | dpll |= DPLL_VCO_ENABLE; |
| 4493 | I915_WRITE(DPLL(pipe), dpll & ~DPLL_VCO_ENABLE); |
| 4494 | POSTING_READ(DPLL(pipe)); |
| 4495 | udelay(150); |
| 4496 | |
Daniel Vetter | dafd226 | 2012-11-26 17:22:07 +0100 | [diff] [blame] | 4497 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4498 | if (encoder->pre_pll_enable) |
| 4499 | encoder->pre_pll_enable(encoder); |
| 4500 | |
Daniel Vetter | 5b5896e | 2012-09-11 12:37:55 +0200 | [diff] [blame] | 4501 | I915_WRITE(DPLL(pipe), dpll); |
| 4502 | |
| 4503 | /* Wait for the clocks to stabilize. */ |
| 4504 | POSTING_READ(DPLL(pipe)); |
| 4505 | udelay(150); |
| 4506 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4507 | /* The pixel multiplier can only be updated once the |
| 4508 | * DPLL is enabled and the clocks are stable. |
| 4509 | * |
| 4510 | * So write it again. |
| 4511 | */ |
| 4512 | I915_WRITE(DPLL(pipe), dpll); |
| 4513 | } |
| 4514 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4515 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc, |
| 4516 | struct drm_display_mode *mode, |
| 4517 | struct drm_display_mode *adjusted_mode) |
| 4518 | { |
| 4519 | struct drm_device *dev = intel_crtc->base.dev; |
| 4520 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4521 | enum pipe pipe = intel_crtc->pipe; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4522 | enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4523 | uint32_t vsyncshift; |
| 4524 | |
| 4525 | if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 4526 | /* the chip adds 2 halflines automatically */ |
| 4527 | adjusted_mode->crtc_vtotal -= 1; |
| 4528 | adjusted_mode->crtc_vblank_end -= 1; |
| 4529 | vsyncshift = adjusted_mode->crtc_hsync_start |
| 4530 | - adjusted_mode->crtc_htotal / 2; |
| 4531 | } else { |
| 4532 | vsyncshift = 0; |
| 4533 | } |
| 4534 | |
| 4535 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4536 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4537 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4538 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4539 | (adjusted_mode->crtc_hdisplay - 1) | |
| 4540 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4541 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4542 | (adjusted_mode->crtc_hblank_start - 1) | |
| 4543 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4544 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4545 | (adjusted_mode->crtc_hsync_start - 1) | |
| 4546 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 4547 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4548 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4549 | (adjusted_mode->crtc_vdisplay - 1) | |
| 4550 | ((adjusted_mode->crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4551 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4552 | (adjusted_mode->crtc_vblank_start - 1) | |
| 4553 | ((adjusted_mode->crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4554 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4555 | (adjusted_mode->crtc_vsync_start - 1) | |
| 4556 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 4557 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 4558 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 4559 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 4560 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 4561 | * bits. */ |
| 4562 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 4563 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 4564 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 4565 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4566 | /* pipesrc controls the size that is scaled from, which should |
| 4567 | * always be the user's requested size. |
| 4568 | */ |
| 4569 | I915_WRITE(PIPESRC(pipe), |
| 4570 | ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1)); |
| 4571 | } |
| 4572 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4573 | static int i9xx_crtc_mode_set(struct drm_crtc *crtc, |
| 4574 | struct drm_display_mode *mode, |
| 4575 | struct drm_display_mode *adjusted_mode, |
| 4576 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 4577 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4578 | { |
| 4579 | struct drm_device *dev = crtc->dev; |
| 4580 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4581 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4582 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 4583 | int plane = intel_crtc->plane; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 4584 | int refclk, num_connectors = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4585 | intel_clock_t clock, reduced_clock; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4586 | u32 dspcntr, pipeconf; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4587 | bool ok, has_reduced_clock = false, is_sdvo = false; |
| 4588 | bool is_lvds = false, is_tv = false, is_dp = false; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4589 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 4590 | const intel_limit_t *limit; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 4591 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4592 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 4593 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4594 | switch (encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4595 | case INTEL_OUTPUT_LVDS: |
| 4596 | is_lvds = true; |
| 4597 | break; |
| 4598 | case INTEL_OUTPUT_SDVO: |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 4599 | case INTEL_OUTPUT_HDMI: |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4600 | is_sdvo = true; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4601 | if (encoder->needs_tv_clock) |
Jesse Barnes | e2f0ba9 | 2009-02-02 15:11:52 -0800 | [diff] [blame] | 4602 | is_tv = true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4603 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4604 | case INTEL_OUTPUT_TVOUT: |
| 4605 | is_tv = true; |
| 4606 | break; |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 4607 | case INTEL_OUTPUT_DISPLAYPORT: |
| 4608 | is_dp = true; |
| 4609 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4610 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 4611 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 4612 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4613 | } |
| 4614 | |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4615 | refclk = i9xx_get_refclk(crtc, num_connectors); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4616 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 4617 | /* |
| 4618 | * Returns a set of divisors for the desired target clock with the given |
| 4619 | * refclk, or FALSE. The returned values represent the clock equation: |
| 4620 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 4621 | */ |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 4622 | limit = intel_limit(crtc, refclk); |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 4623 | ok = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL, |
| 4624 | &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4625 | if (!ok) { |
| 4626 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4627 | return -EINVAL; |
| 4628 | } |
| 4629 | |
| 4630 | /* Ensure that the cursor is valid for the new mode before changing... */ |
| 4631 | intel_crtc_update_cursor(crtc, true); |
| 4632 | |
| 4633 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 4634 | /* |
| 4635 | * Ensure we match the reduced clock's P to the target clock. |
| 4636 | * If the clocks don't match, we can't switch the display clock |
| 4637 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 4638 | * downclock feature. |
| 4639 | */ |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4640 | has_reduced_clock = limit->find_pll(limit, crtc, |
| 4641 | dev_priv->lvds_downclock, |
| 4642 | refclk, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 4643 | &clock, |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4644 | &reduced_clock); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4645 | } |
| 4646 | |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4647 | if (is_sdvo && is_tv) |
| 4648 | i9xx_adjust_sdvo_tv_clock(adjusted_mode, &clock); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4649 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4650 | if (IS_GEN2(dev)) |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4651 | i8xx_update_pll(crtc, adjusted_mode, &clock, |
| 4652 | has_reduced_clock ? &reduced_clock : NULL, |
| 4653 | num_connectors); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4654 | else if (IS_VALLEYVIEW(dev)) |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4655 | vlv_update_pll(crtc, mode, adjusted_mode, &clock, |
| 4656 | has_reduced_clock ? &reduced_clock : NULL, |
| 4657 | num_connectors); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4658 | else |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4659 | i9xx_update_pll(crtc, mode, adjusted_mode, &clock, |
| 4660 | has_reduced_clock ? &reduced_clock : NULL, |
| 4661 | num_connectors); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4662 | |
| 4663 | /* setup pipeconf */ |
| 4664 | pipeconf = I915_READ(PIPECONF(pipe)); |
| 4665 | |
| 4666 | /* Set up the display plane register */ |
| 4667 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 4668 | |
Eric Anholt | 929c77f | 2011-03-30 13:01:04 -0700 | [diff] [blame] | 4669 | if (pipe == 0) |
| 4670 | dspcntr &= ~DISPPLANE_SEL_PIPE_MASK; |
| 4671 | else |
| 4672 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4673 | |
| 4674 | if (pipe == 0 && INTEL_INFO(dev)->gen < 4) { |
| 4675 | /* Enable pixel doubling when the dot clock is > 90% of the (display) |
| 4676 | * core speed. |
| 4677 | * |
| 4678 | * XXX: No double-wide on 915GM pipe B. Is that the only reason for the |
| 4679 | * pipe == 0 check? |
| 4680 | */ |
| 4681 | if (mode->clock > |
| 4682 | dev_priv->display.get_display_clock_speed(dev) * 9 / 10) |
| 4683 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
| 4684 | else |
| 4685 | pipeconf &= ~PIPECONF_DOUBLE_WIDE; |
| 4686 | } |
| 4687 | |
Adam Jackson | 3b5c78a | 2011-12-13 15:41:00 -0800 | [diff] [blame] | 4688 | /* default to 8bpc */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4689 | pipeconf &= ~(PIPECONF_BPC_MASK | PIPECONF_DITHER_EN); |
Adam Jackson | 3b5c78a | 2011-12-13 15:41:00 -0800 | [diff] [blame] | 4690 | if (is_dp) { |
Jani Nikula | 0c96c65 | 2012-09-26 18:43:10 +0300 | [diff] [blame] | 4691 | if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4692 | pipeconf |= PIPECONF_6BPC | |
Adam Jackson | 3b5c78a | 2011-12-13 15:41:00 -0800 | [diff] [blame] | 4693 | PIPECONF_DITHER_EN | |
| 4694 | PIPECONF_DITHER_TYPE_SP; |
| 4695 | } |
| 4696 | } |
| 4697 | |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 4698 | if (IS_VALLEYVIEW(dev) && intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) { |
| 4699 | if (adjusted_mode->private_flags & INTEL_MODE_DP_FORCE_6BPC) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4700 | pipeconf |= PIPECONF_6BPC | |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 4701 | PIPECONF_ENABLE | |
| 4702 | I965_PIPECONF_ACTIVE; |
| 4703 | } |
| 4704 | } |
| 4705 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4706 | DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B'); |
| 4707 | drm_mode_debug_printmodeline(mode); |
| 4708 | |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4709 | if (HAS_PIPE_CXSR(dev)) { |
| 4710 | if (intel_crtc->lowfreq_avail) { |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4711 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 4712 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4713 | } else { |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4714 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
| 4715 | pipeconf &= ~PIPECONF_CXSR_DOWNCLOCK; |
| 4716 | } |
| 4717 | } |
| 4718 | |
Keith Packard | 617cf88 | 2012-02-08 13:53:38 -0800 | [diff] [blame] | 4719 | pipeconf &= ~PIPECONF_INTERLACE_MASK; |
Daniel Vetter | dbb0257 | 2012-01-28 14:49:23 +0100 | [diff] [blame] | 4720 | if (!IS_GEN2(dev) && |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4721 | adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4722 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4723 | else |
Keith Packard | 617cf88 | 2012-02-08 13:53:38 -0800 | [diff] [blame] | 4724 | pipeconf |= PIPECONF_PROGRESSIVE; |
Daniel Vetter | 0529a0d | 2012-01-28 14:49:24 +0100 | [diff] [blame] | 4725 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4726 | intel_set_pipe_timings(intel_crtc, mode, adjusted_mode); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4727 | |
| 4728 | /* pipesrc and dspsize control the size that is scaled from, |
| 4729 | * which should always be the user's requested size. |
| 4730 | */ |
Eric Anholt | 929c77f | 2011-03-30 13:01:04 -0700 | [diff] [blame] | 4731 | I915_WRITE(DSPSIZE(plane), |
| 4732 | ((mode->vdisplay - 1) << 16) | |
| 4733 | (mode->hdisplay - 1)); |
| 4734 | I915_WRITE(DSPPOS(plane), 0); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4735 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4736 | I915_WRITE(PIPECONF(pipe), pipeconf); |
| 4737 | POSTING_READ(PIPECONF(pipe)); |
Eric Anholt | 929c77f | 2011-03-30 13:01:04 -0700 | [diff] [blame] | 4738 | intel_enable_pipe(dev_priv, pipe, false); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4739 | |
| 4740 | intel_wait_for_vblank(dev, pipe); |
| 4741 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4742 | I915_WRITE(DSPCNTR(plane), dspcntr); |
| 4743 | POSTING_READ(DSPCNTR(plane)); |
| 4744 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 4745 | ret = intel_pipe_set_base(crtc, x, y, fb); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4746 | |
| 4747 | intel_update_watermarks(dev); |
| 4748 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4749 | return ret; |
| 4750 | } |
| 4751 | |
Keith Packard | 9fb526d | 2011-09-26 22:24:57 -0700 | [diff] [blame] | 4752 | /* |
| 4753 | * Initialize reference clocks when the driver loads |
| 4754 | */ |
| 4755 | void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4756 | { |
| 4757 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4758 | struct drm_mode_config *mode_config = &dev->mode_config; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4759 | struct intel_encoder *encoder; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4760 | u32 temp; |
| 4761 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4762 | bool has_cpu_edp = false; |
| 4763 | bool has_pch_edp = false; |
| 4764 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 4765 | bool has_ck505 = false; |
| 4766 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4767 | |
| 4768 | /* We need to take the global config into account */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4769 | list_for_each_entry(encoder, &mode_config->encoder_list, |
| 4770 | base.head) { |
| 4771 | switch (encoder->type) { |
| 4772 | case INTEL_OUTPUT_LVDS: |
| 4773 | has_panel = true; |
| 4774 | has_lvds = true; |
| 4775 | break; |
| 4776 | case INTEL_OUTPUT_EDP: |
| 4777 | has_panel = true; |
| 4778 | if (intel_encoder_is_pch_edp(&encoder->base)) |
| 4779 | has_pch_edp = true; |
| 4780 | else |
| 4781 | has_cpu_edp = true; |
| 4782 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4783 | } |
| 4784 | } |
| 4785 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 4786 | if (HAS_PCH_IBX(dev)) { |
| 4787 | has_ck505 = dev_priv->display_clock_mode; |
| 4788 | can_ssc = has_ck505; |
| 4789 | } else { |
| 4790 | has_ck505 = false; |
| 4791 | can_ssc = true; |
| 4792 | } |
| 4793 | |
| 4794 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_pch_edp %d has_cpu_edp %d has_ck505 %d\n", |
| 4795 | has_panel, has_lvds, has_pch_edp, has_cpu_edp, |
| 4796 | has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4797 | |
| 4798 | /* Ironlake: try to setup display ref clock before DPLL |
| 4799 | * enabling. This is only under driver's control after |
| 4800 | * PCH B stepping, previous chipset stepping should be |
| 4801 | * ignoring this setting. |
| 4802 | */ |
| 4803 | temp = I915_READ(PCH_DREF_CONTROL); |
| 4804 | /* Always enable nonspread source */ |
| 4805 | temp &= ~DREF_NONSPREAD_SOURCE_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4806 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 4807 | if (has_ck505) |
| 4808 | temp |= DREF_NONSPREAD_CK505_ENABLE; |
| 4809 | else |
| 4810 | temp |= DREF_NONSPREAD_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4811 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4812 | if (has_panel) { |
| 4813 | temp &= ~DREF_SSC_SOURCE_MASK; |
| 4814 | temp |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4815 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4816 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 4817 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4818 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4819 | temp |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 4820 | } else |
| 4821 | temp &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4822 | |
| 4823 | /* Get SSC going before enabling the outputs */ |
| 4824 | I915_WRITE(PCH_DREF_CONTROL, temp); |
| 4825 | POSTING_READ(PCH_DREF_CONTROL); |
| 4826 | udelay(200); |
| 4827 | |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4828 | temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 4829 | |
| 4830 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4831 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 4832 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4833 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4834 | temp |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4835 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4836 | else |
| 4837 | temp |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 4838 | } else |
| 4839 | temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 4840 | |
| 4841 | I915_WRITE(PCH_DREF_CONTROL, temp); |
| 4842 | POSTING_READ(PCH_DREF_CONTROL); |
| 4843 | udelay(200); |
| 4844 | } else { |
| 4845 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 4846 | |
| 4847 | temp &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 4848 | |
| 4849 | /* Turn off CPU output */ |
| 4850 | temp |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 4851 | |
| 4852 | I915_WRITE(PCH_DREF_CONTROL, temp); |
| 4853 | POSTING_READ(PCH_DREF_CONTROL); |
| 4854 | udelay(200); |
| 4855 | |
| 4856 | /* Turn off the SSC source */ |
| 4857 | temp &= ~DREF_SSC_SOURCE_MASK; |
| 4858 | temp |= DREF_SSC_SOURCE_DISABLE; |
| 4859 | |
| 4860 | /* Turn off SSC1 */ |
| 4861 | temp &= ~ DREF_SSC1_ENABLE; |
| 4862 | |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 4863 | I915_WRITE(PCH_DREF_CONTROL, temp); |
| 4864 | POSTING_READ(PCH_DREF_CONTROL); |
| 4865 | udelay(200); |
| 4866 | } |
| 4867 | } |
| 4868 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 4869 | static int ironlake_get_refclk(struct drm_crtc *crtc) |
| 4870 | { |
| 4871 | struct drm_device *dev = crtc->dev; |
| 4872 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4873 | struct intel_encoder *encoder; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 4874 | struct intel_encoder *edp_encoder = NULL; |
| 4875 | int num_connectors = 0; |
| 4876 | bool is_lvds = false; |
| 4877 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 4878 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 4879 | switch (encoder->type) { |
| 4880 | case INTEL_OUTPUT_LVDS: |
| 4881 | is_lvds = true; |
| 4882 | break; |
| 4883 | case INTEL_OUTPUT_EDP: |
| 4884 | edp_encoder = encoder; |
| 4885 | break; |
| 4886 | } |
| 4887 | num_connectors++; |
| 4888 | } |
| 4889 | |
| 4890 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
| 4891 | DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n", |
| 4892 | dev_priv->lvds_ssc_freq); |
| 4893 | return dev_priv->lvds_ssc_freq * 1000; |
| 4894 | } |
| 4895 | |
| 4896 | return 120000; |
| 4897 | } |
| 4898 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 4899 | static void ironlake_set_pipeconf(struct drm_crtc *crtc, |
| 4900 | struct drm_display_mode *adjusted_mode, |
| 4901 | bool dither) |
| 4902 | { |
| 4903 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 4904 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4905 | int pipe = intel_crtc->pipe; |
| 4906 | uint32_t val; |
| 4907 | |
| 4908 | val = I915_READ(PIPECONF(pipe)); |
| 4909 | |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4910 | val &= ~PIPECONF_BPC_MASK; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 4911 | switch (intel_crtc->bpp) { |
| 4912 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4913 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 4914 | break; |
| 4915 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4916 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 4917 | break; |
| 4918 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4919 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 4920 | break; |
| 4921 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4922 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 4923 | break; |
| 4924 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 4925 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 4926 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 4927 | } |
| 4928 | |
| 4929 | val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK); |
| 4930 | if (dither) |
| 4931 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 4932 | |
| 4933 | val &= ~PIPECONF_INTERLACE_MASK; |
| 4934 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 4935 | val |= PIPECONF_INTERLACED_ILK; |
| 4936 | else |
| 4937 | val |= PIPECONF_PROGRESSIVE; |
| 4938 | |
| 4939 | I915_WRITE(PIPECONF(pipe), val); |
| 4940 | POSTING_READ(PIPECONF(pipe)); |
| 4941 | } |
| 4942 | |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 4943 | static void haswell_set_pipeconf(struct drm_crtc *crtc, |
| 4944 | struct drm_display_mode *adjusted_mode, |
| 4945 | bool dither) |
| 4946 | { |
| 4947 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 4948 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 4949 | enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 4950 | uint32_t val; |
| 4951 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 4952 | val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 4953 | |
| 4954 | val &= ~(PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_MASK); |
| 4955 | if (dither) |
| 4956 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 4957 | |
| 4958 | val &= ~PIPECONF_INTERLACE_MASK_HSW; |
| 4959 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 4960 | val |= PIPECONF_INTERLACED_ILK; |
| 4961 | else |
| 4962 | val |= PIPECONF_PROGRESSIVE; |
| 4963 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 4964 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 4965 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 4966 | } |
| 4967 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 4968 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
| 4969 | struct drm_display_mode *adjusted_mode, |
| 4970 | intel_clock_t *clock, |
| 4971 | bool *has_reduced_clock, |
| 4972 | intel_clock_t *reduced_clock) |
| 4973 | { |
| 4974 | struct drm_device *dev = crtc->dev; |
| 4975 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4976 | struct intel_encoder *intel_encoder; |
| 4977 | int refclk; |
| 4978 | const intel_limit_t *limit; |
| 4979 | bool ret, is_sdvo = false, is_tv = false, is_lvds = false; |
| 4980 | |
| 4981 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 4982 | switch (intel_encoder->type) { |
| 4983 | case INTEL_OUTPUT_LVDS: |
| 4984 | is_lvds = true; |
| 4985 | break; |
| 4986 | case INTEL_OUTPUT_SDVO: |
| 4987 | case INTEL_OUTPUT_HDMI: |
| 4988 | is_sdvo = true; |
| 4989 | if (intel_encoder->needs_tv_clock) |
| 4990 | is_tv = true; |
| 4991 | break; |
| 4992 | case INTEL_OUTPUT_TVOUT: |
| 4993 | is_tv = true; |
| 4994 | break; |
| 4995 | } |
| 4996 | } |
| 4997 | |
| 4998 | refclk = ironlake_get_refclk(crtc); |
| 4999 | |
| 5000 | /* |
| 5001 | * Returns a set of divisors for the desired target clock with the given |
| 5002 | * refclk, or FALSE. The returned values represent the clock equation: |
| 5003 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 5004 | */ |
| 5005 | limit = intel_limit(crtc, refclk); |
| 5006 | ret = limit->find_pll(limit, crtc, adjusted_mode->clock, refclk, NULL, |
| 5007 | clock); |
| 5008 | if (!ret) |
| 5009 | return false; |
| 5010 | |
| 5011 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 5012 | /* |
| 5013 | * Ensure we match the reduced clock's P to the target clock. |
| 5014 | * If the clocks don't match, we can't switch the display clock |
| 5015 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 5016 | * downclock feature. |
| 5017 | */ |
| 5018 | *has_reduced_clock = limit->find_pll(limit, crtc, |
| 5019 | dev_priv->lvds_downclock, |
| 5020 | refclk, |
| 5021 | clock, |
| 5022 | reduced_clock); |
| 5023 | } |
| 5024 | |
| 5025 | if (is_sdvo && is_tv) |
| 5026 | i9xx_adjust_sdvo_tv_clock(adjusted_mode, clock); |
| 5027 | |
| 5028 | return true; |
| 5029 | } |
| 5030 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5031 | static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev) |
| 5032 | { |
| 5033 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5034 | uint32_t temp; |
| 5035 | |
| 5036 | temp = I915_READ(SOUTH_CHICKEN1); |
| 5037 | if (temp & FDI_BC_BIFURCATION_SELECT) |
| 5038 | return; |
| 5039 | |
| 5040 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 5041 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 5042 | |
| 5043 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 5044 | DRM_DEBUG_KMS("enabling fdi C rx\n"); |
| 5045 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 5046 | POSTING_READ(SOUTH_CHICKEN1); |
| 5047 | } |
| 5048 | |
| 5049 | static bool ironlake_check_fdi_lanes(struct intel_crtc *intel_crtc) |
| 5050 | { |
| 5051 | struct drm_device *dev = intel_crtc->base.dev; |
| 5052 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5053 | struct intel_crtc *pipe_B_crtc = |
| 5054 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]); |
| 5055 | |
| 5056 | DRM_DEBUG_KMS("checking fdi config on pipe %i, lanes %i\n", |
| 5057 | intel_crtc->pipe, intel_crtc->fdi_lanes); |
| 5058 | if (intel_crtc->fdi_lanes > 4) { |
| 5059 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %i: %i lanes\n", |
| 5060 | intel_crtc->pipe, intel_crtc->fdi_lanes); |
| 5061 | /* Clamp lanes to avoid programming the hw with bogus values. */ |
| 5062 | intel_crtc->fdi_lanes = 4; |
| 5063 | |
| 5064 | return false; |
| 5065 | } |
| 5066 | |
| 5067 | if (dev_priv->num_pipe == 2) |
| 5068 | return true; |
| 5069 | |
| 5070 | switch (intel_crtc->pipe) { |
| 5071 | case PIPE_A: |
| 5072 | return true; |
| 5073 | case PIPE_B: |
| 5074 | if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled && |
| 5075 | intel_crtc->fdi_lanes > 2) { |
| 5076 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n", |
| 5077 | intel_crtc->pipe, intel_crtc->fdi_lanes); |
| 5078 | /* Clamp lanes to avoid programming the hw with bogus values. */ |
| 5079 | intel_crtc->fdi_lanes = 2; |
| 5080 | |
| 5081 | return false; |
| 5082 | } |
| 5083 | |
| 5084 | if (intel_crtc->fdi_lanes > 2) |
| 5085 | WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT); |
| 5086 | else |
| 5087 | cpt_enable_fdi_bc_bifurcation(dev); |
| 5088 | |
| 5089 | return true; |
| 5090 | case PIPE_C: |
| 5091 | if (!pipe_B_crtc->base.enabled || pipe_B_crtc->fdi_lanes <= 2) { |
| 5092 | if (intel_crtc->fdi_lanes > 2) { |
| 5093 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %i: %i lanes\n", |
| 5094 | intel_crtc->pipe, intel_crtc->fdi_lanes); |
| 5095 | /* Clamp lanes to avoid programming the hw with bogus values. */ |
| 5096 | intel_crtc->fdi_lanes = 2; |
| 5097 | |
| 5098 | return false; |
| 5099 | } |
| 5100 | } else { |
| 5101 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
| 5102 | return false; |
| 5103 | } |
| 5104 | |
| 5105 | cpt_enable_fdi_bc_bifurcation(dev); |
| 5106 | |
| 5107 | return true; |
| 5108 | default: |
| 5109 | BUG(); |
| 5110 | } |
| 5111 | } |
| 5112 | |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5113 | static void ironlake_set_m_n(struct drm_crtc *crtc, |
| 5114 | struct drm_display_mode *mode, |
| 5115 | struct drm_display_mode *adjusted_mode) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5116 | { |
| 5117 | struct drm_device *dev = crtc->dev; |
| 5118 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5119 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | afe2fcf | 2012-10-23 18:30:01 -0200 | [diff] [blame] | 5120 | enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5121 | struct intel_encoder *intel_encoder, *edp_encoder = NULL; |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5122 | struct intel_link_m_n m_n = {0}; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5123 | int target_clock, pixel_multiplier, lane, link_bw; |
| 5124 | bool is_dp = false, is_cpu_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5125 | |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5126 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 5127 | switch (intel_encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5128 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5129 | is_dp = true; |
| 5130 | break; |
| 5131 | case INTEL_OUTPUT_EDP: |
Jesse Barnes | e3aef17 | 2012-04-10 11:58:03 -0700 | [diff] [blame] | 5132 | is_dp = true; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5133 | if (!intel_encoder_is_pch_edp(&intel_encoder->base)) |
Jesse Barnes | e3aef17 | 2012-04-10 11:58:03 -0700 | [diff] [blame] | 5134 | is_cpu_edp = true; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5135 | edp_encoder = intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5136 | break; |
| 5137 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 5138 | } |
| 5139 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5140 | /* FDI link */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5141 | pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode); |
| 5142 | lane = 0; |
| 5143 | /* CPU eDP doesn't require FDI link, so just set DP M/N |
| 5144 | according to current link config */ |
Jesse Barnes | e3aef17 | 2012-04-10 11:58:03 -0700 | [diff] [blame] | 5145 | if (is_cpu_edp) { |
Jesse Barnes | e3aef17 | 2012-04-10 11:58:03 -0700 | [diff] [blame] | 5146 | intel_edp_link_config(edp_encoder, &lane, &link_bw); |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5147 | } else { |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5148 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 5149 | * each output octet as 10 bits. The actual frequency |
| 5150 | * is stored as a divider into a 100MHz clock, and the |
| 5151 | * mode pixel clock is stored in units of 1KHz. |
| 5152 | * Hence the bw of each lane in terms of the mode signal |
| 5153 | * is: |
| 5154 | */ |
| 5155 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 5156 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5157 | |
Daniel Vetter | 94bf2ce | 2012-06-04 18:39:19 +0200 | [diff] [blame] | 5158 | /* [e]DP over FDI requires target mode clock instead of link clock. */ |
| 5159 | if (edp_encoder) |
| 5160 | target_clock = intel_edp_target_clock(edp_encoder, mode); |
| 5161 | else if (is_dp) |
| 5162 | target_clock = mode->clock; |
| 5163 | else |
| 5164 | target_clock = adjusted_mode->clock; |
| 5165 | |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5166 | if (!lane) { |
| 5167 | /* |
| 5168 | * Account for spread spectrum to avoid |
| 5169 | * oversubscribing the link. Max center spread |
| 5170 | * is 2.5%; use 5% for safety's sake. |
| 5171 | */ |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 5172 | u32 bps = target_clock * intel_crtc->bpp * 21 / 20; |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5173 | lane = bps / (link_bw * 8) + 1; |
| 5174 | } |
| 5175 | |
| 5176 | intel_crtc->fdi_lanes = lane; |
| 5177 | |
| 5178 | if (pixel_multiplier > 1) |
| 5179 | link_bw *= pixel_multiplier; |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5180 | intel_link_compute_m_n(intel_crtc->bpp, lane, target_clock, link_bw, &m_n); |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5181 | |
Paulo Zanoni | afe2fcf | 2012-10-23 18:30:01 -0200 | [diff] [blame] | 5182 | I915_WRITE(PIPE_DATA_M1(cpu_transcoder), TU_SIZE(m_n.tu) | m_n.gmch_m); |
| 5183 | I915_WRITE(PIPE_DATA_N1(cpu_transcoder), m_n.gmch_n); |
| 5184 | I915_WRITE(PIPE_LINK_M1(cpu_transcoder), m_n.link_m); |
| 5185 | I915_WRITE(PIPE_LINK_N1(cpu_transcoder), m_n.link_n); |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5186 | } |
| 5187 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5188 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
| 5189 | struct drm_display_mode *adjusted_mode, |
| 5190 | intel_clock_t *clock, u32 fp) |
| 5191 | { |
| 5192 | struct drm_crtc *crtc = &intel_crtc->base; |
| 5193 | struct drm_device *dev = crtc->dev; |
| 5194 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5195 | struct intel_encoder *intel_encoder; |
| 5196 | uint32_t dpll; |
| 5197 | int factor, pixel_multiplier, num_connectors = 0; |
| 5198 | bool is_lvds = false, is_sdvo = false, is_tv = false; |
| 5199 | bool is_dp = false, is_cpu_edp = false; |
| 5200 | |
| 5201 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 5202 | switch (intel_encoder->type) { |
| 5203 | case INTEL_OUTPUT_LVDS: |
| 5204 | is_lvds = true; |
| 5205 | break; |
| 5206 | case INTEL_OUTPUT_SDVO: |
| 5207 | case INTEL_OUTPUT_HDMI: |
| 5208 | is_sdvo = true; |
| 5209 | if (intel_encoder->needs_tv_clock) |
| 5210 | is_tv = true; |
| 5211 | break; |
| 5212 | case INTEL_OUTPUT_TVOUT: |
| 5213 | is_tv = true; |
| 5214 | break; |
| 5215 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5216 | is_dp = true; |
| 5217 | break; |
| 5218 | case INTEL_OUTPUT_EDP: |
| 5219 | is_dp = true; |
| 5220 | if (!intel_encoder_is_pch_edp(&intel_encoder->base)) |
| 5221 | is_cpu_edp = true; |
| 5222 | break; |
| 5223 | } |
| 5224 | |
| 5225 | num_connectors++; |
| 5226 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5227 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 5228 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5229 | factor = 21; |
| 5230 | if (is_lvds) { |
| 5231 | if ((intel_panel_use_ssc(dev_priv) && |
| 5232 | dev_priv->lvds_ssc_freq == 100) || |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 5233 | intel_is_dual_link_lvds(dev)) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5234 | factor = 25; |
| 5235 | } else if (is_sdvo && is_tv) |
| 5236 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 5237 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5238 | if (clock->m < factor * clock->n) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5239 | fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 5240 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 5241 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5242 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5243 | if (is_lvds) |
| 5244 | dpll |= DPLLB_MODE_LVDS; |
| 5245 | else |
| 5246 | dpll |= DPLLB_MODE_DAC_SERIAL; |
| 5247 | if (is_sdvo) { |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5248 | pixel_multiplier = intel_mode_get_pixel_multiplier(adjusted_mode); |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5249 | if (pixel_multiplier > 1) { |
| 5250 | dpll |= (pixel_multiplier - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5251 | } |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5252 | dpll |= DPLL_DVO_HIGH_SPEED; |
| 5253 | } |
Jesse Barnes | e3aef17 | 2012-04-10 11:58:03 -0700 | [diff] [blame] | 5254 | if (is_dp && !is_cpu_edp) |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5255 | dpll |= DPLL_DVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5256 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5257 | /* compute bitmask from p1 value */ |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5258 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5259 | /* also FPA1 */ |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5260 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5261 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5262 | switch (clock->p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5263 | case 5: |
| 5264 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 5265 | break; |
| 5266 | case 7: |
| 5267 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 5268 | break; |
| 5269 | case 10: |
| 5270 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 5271 | break; |
| 5272 | case 14: |
| 5273 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 5274 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5275 | } |
| 5276 | |
| 5277 | if (is_sdvo && is_tv) |
| 5278 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
| 5279 | else if (is_tv) |
| 5280 | /* XXX: just matching BIOS for now */ |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 5281 | /* dpll |= PLL_REF_INPUT_TVCLKINBC; */ |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5282 | dpll |= 3; |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 5283 | else if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 5284 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5285 | else |
| 5286 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 5287 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5288 | return dpll; |
| 5289 | } |
| 5290 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5291 | static int ironlake_crtc_mode_set(struct drm_crtc *crtc, |
| 5292 | struct drm_display_mode *mode, |
| 5293 | struct drm_display_mode *adjusted_mode, |
| 5294 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 5295 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5296 | { |
| 5297 | struct drm_device *dev = crtc->dev; |
| 5298 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5299 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5300 | int pipe = intel_crtc->pipe; |
| 5301 | int plane = intel_crtc->plane; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5302 | int num_connectors = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5303 | intel_clock_t clock, reduced_clock; |
Paulo Zanoni | a1f9e77 | 2012-09-12 10:06:32 -0300 | [diff] [blame] | 5304 | u32 dpll, fp = 0, fp2 = 0; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 5305 | bool ok, has_reduced_clock = false; |
| 5306 | bool is_lvds = false, is_dp = false, is_cpu_edp = false; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5307 | struct intel_encoder *encoder; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5308 | int ret; |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5309 | bool dither, fdi_config_ok; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5310 | |
| 5311 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 5312 | switch (encoder->type) { |
| 5313 | case INTEL_OUTPUT_LVDS: |
| 5314 | is_lvds = true; |
| 5315 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5316 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5317 | is_dp = true; |
| 5318 | break; |
| 5319 | case INTEL_OUTPUT_EDP: |
| 5320 | is_dp = true; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 5321 | if (!intel_encoder_is_pch_edp(&encoder->base)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5322 | is_cpu_edp = true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5323 | break; |
| 5324 | } |
| 5325 | |
| 5326 | num_connectors++; |
| 5327 | } |
| 5328 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 5329 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 5330 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 5331 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5332 | ok = ironlake_compute_clocks(crtc, adjusted_mode, &clock, |
| 5333 | &has_reduced_clock, &reduced_clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5334 | if (!ok) { |
| 5335 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 5336 | return -EINVAL; |
| 5337 | } |
| 5338 | |
| 5339 | /* Ensure that the cursor is valid for the new mode before changing... */ |
| 5340 | intel_crtc_update_cursor(crtc, true); |
| 5341 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5342 | /* determine panel color depth */ |
Jani Nikula | c824196 | 2012-11-02 10:19:55 +0200 | [diff] [blame] | 5343 | dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp, |
| 5344 | adjusted_mode); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5345 | if (is_lvds && dev_priv->lvds_dither) |
| 5346 | dither = true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5347 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5348 | fp = clock.n << 16 | clock.m1 << 8 | clock.m2; |
| 5349 | if (has_reduced_clock) |
| 5350 | fp2 = reduced_clock.n << 16 | reduced_clock.m1 << 8 | |
| 5351 | reduced_clock.m2; |
| 5352 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5353 | dpll = ironlake_compute_dpll(intel_crtc, adjusted_mode, &clock, fp); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5354 | |
Jesse Barnes | f7cb34d | 2011-10-12 10:49:14 -0700 | [diff] [blame] | 5355 | DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5356 | drm_mode_debug_printmodeline(mode); |
| 5357 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 5358 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
| 5359 | if (!is_cpu_edp) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5360 | struct intel_pch_pll *pll; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 5361 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5362 | pll = intel_get_pch_pll(intel_crtc, dpll, fp); |
| 5363 | if (pll == NULL) { |
| 5364 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %d\n", |
| 5365 | pipe); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 5366 | return -EINVAL; |
| 5367 | } |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5368 | } else |
| 5369 | intel_put_pch_pll(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5370 | |
Daniel Vetter | 2f0c2ad | 2012-11-29 15:59:35 +0100 | [diff] [blame] | 5371 | if (is_dp && !is_cpu_edp) |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 5372 | intel_dp_set_m_n(crtc, mode, adjusted_mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5373 | |
Daniel Vetter | dafd226 | 2012-11-26 17:22:07 +0100 | [diff] [blame] | 5374 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5375 | if (encoder->pre_pll_enable) |
| 5376 | encoder->pre_pll_enable(encoder); |
| 5377 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5378 | if (intel_crtc->pch_pll) { |
| 5379 | I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 5380 | |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 5381 | /* Wait for the clocks to stabilize. */ |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5382 | POSTING_READ(intel_crtc->pch_pll->pll_reg); |
Zhenyu Wang | 32f9d65 | 2009-07-24 01:00:32 +0800 | [diff] [blame] | 5383 | udelay(150); |
| 5384 | |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5385 | /* The pixel multiplier can only be updated once the |
| 5386 | * DPLL is enabled and the clocks are stable. |
| 5387 | * |
| 5388 | * So write it again. |
| 5389 | */ |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5390 | I915_WRITE(intel_crtc->pch_pll->pll_reg, dpll); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5391 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5392 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 5393 | intel_crtc->lowfreq_avail = false; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5394 | if (intel_crtc->pch_pll) { |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 5395 | if (is_lvds && has_reduced_clock && i915_powersave) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5396 | I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp2); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 5397 | intel_crtc->lowfreq_avail = true; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 5398 | } else { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5399 | I915_WRITE(intel_crtc->pch_pll->fp1_reg, fp); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 5400 | } |
| 5401 | } |
| 5402 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5403 | intel_set_pipe_timings(intel_crtc, mode, adjusted_mode); |
Krzysztof Halasa | 734b415 | 2010-05-25 18:41:46 +0200 | [diff] [blame] | 5404 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5405 | /* Note, this also computes intel_crtc->fdi_lanes which is used below in |
| 5406 | * ironlake_check_fdi_lanes. */ |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5407 | ironlake_set_m_n(crtc, mode, adjusted_mode); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 5408 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5409 | fdi_config_ok = ironlake_check_fdi_lanes(intel_crtc); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5410 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5411 | ironlake_set_pipeconf(crtc, adjusted_mode, dither); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5412 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 5413 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5414 | |
Paulo Zanoni | a1f9e77 | 2012-09-12 10:06:32 -0300 | [diff] [blame] | 5415 | /* Set up the display plane register */ |
| 5416 | I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 5417 | POSTING_READ(DSPCNTR(plane)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5418 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 5419 | ret = intel_pipe_set_base(crtc, x, y, fb); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 5420 | |
| 5421 | intel_update_watermarks(dev); |
| 5422 | |
Eugeni Dodonov | 1f8eeab | 2012-05-09 15:37:24 -0300 | [diff] [blame] | 5423 | intel_update_linetime_watermarks(dev, pipe, adjusted_mode); |
| 5424 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5425 | return fdi_config_ok ? ret : -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5426 | } |
| 5427 | |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5428 | static int haswell_crtc_mode_set(struct drm_crtc *crtc, |
| 5429 | struct drm_display_mode *mode, |
| 5430 | struct drm_display_mode *adjusted_mode, |
| 5431 | int x, int y, |
| 5432 | struct drm_framebuffer *fb) |
| 5433 | { |
| 5434 | struct drm_device *dev = crtc->dev; |
| 5435 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5436 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5437 | int pipe = intel_crtc->pipe; |
| 5438 | int plane = intel_crtc->plane; |
| 5439 | int num_connectors = 0; |
Daniel Vetter | ed7ef43 | 2012-12-06 14:24:21 +0100 | [diff] [blame] | 5440 | bool is_dp = false, is_cpu_edp = false; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5441 | struct intel_encoder *encoder; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5442 | int ret; |
| 5443 | bool dither; |
| 5444 | |
| 5445 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 5446 | switch (encoder->type) { |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5447 | case INTEL_OUTPUT_DISPLAYPORT: |
| 5448 | is_dp = true; |
| 5449 | break; |
| 5450 | case INTEL_OUTPUT_EDP: |
| 5451 | is_dp = true; |
| 5452 | if (!intel_encoder_is_pch_edp(&encoder->base)) |
| 5453 | is_cpu_edp = true; |
| 5454 | break; |
| 5455 | } |
| 5456 | |
| 5457 | num_connectors++; |
| 5458 | } |
| 5459 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 5460 | if (is_cpu_edp) |
| 5461 | intel_crtc->cpu_transcoder = TRANSCODER_EDP; |
| 5462 | else |
| 5463 | intel_crtc->cpu_transcoder = pipe; |
| 5464 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 5465 | /* We are not sure yet this won't happen. */ |
| 5466 | WARN(!HAS_PCH_LPT(dev), "Unexpected PCH type %d\n", |
| 5467 | INTEL_PCH_TYPE(dev)); |
| 5468 | |
| 5469 | WARN(num_connectors != 1, "%d connectors attached to pipe %c\n", |
| 5470 | num_connectors, pipe_name(pipe)); |
| 5471 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 5472 | WARN_ON(I915_READ(PIPECONF(intel_crtc->cpu_transcoder)) & |
Paulo Zanoni | 1ce4292 | 2012-10-05 12:06:01 -0300 | [diff] [blame] | 5473 | (PIPECONF_ENABLE | I965_PIPECONF_ACTIVE)); |
| 5474 | |
| 5475 | WARN_ON(I915_READ(DSPCNTR(plane)) & DISPLAY_PLANE_ENABLE); |
| 5476 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 5477 | if (!intel_ddi_pll_mode_set(crtc, adjusted_mode->clock)) |
| 5478 | return -EINVAL; |
| 5479 | |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5480 | /* Ensure that the cursor is valid for the new mode before changing... */ |
| 5481 | intel_crtc_update_cursor(crtc, true); |
| 5482 | |
| 5483 | /* determine panel color depth */ |
Jani Nikula | c824196 | 2012-11-02 10:19:55 +0200 | [diff] [blame] | 5484 | dither = intel_choose_pipe_bpp_dither(crtc, fb, &intel_crtc->bpp, |
| 5485 | adjusted_mode); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5486 | |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5487 | DRM_DEBUG_KMS("Mode for pipe %d:\n", pipe); |
| 5488 | drm_mode_debug_printmodeline(mode); |
| 5489 | |
Daniel Vetter | ed7ef43 | 2012-12-06 14:24:21 +0100 | [diff] [blame] | 5490 | if (is_dp && !is_cpu_edp) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5491 | intel_dp_set_m_n(crtc, mode, adjusted_mode); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5492 | |
| 5493 | intel_crtc->lowfreq_avail = false; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5494 | |
| 5495 | intel_set_pipe_timings(intel_crtc, mode, adjusted_mode); |
| 5496 | |
Paulo Zanoni | 1eb8dfe | 2012-10-18 12:42:10 -0300 | [diff] [blame] | 5497 | if (!is_dp || is_cpu_edp) |
| 5498 | ironlake_set_m_n(crtc, mode, adjusted_mode); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5499 | |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 5500 | haswell_set_pipeconf(crtc, adjusted_mode, dither); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5501 | |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5502 | /* Set up the display plane register */ |
| 5503 | I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE); |
| 5504 | POSTING_READ(DSPCNTR(plane)); |
| 5505 | |
| 5506 | ret = intel_pipe_set_base(crtc, x, y, fb); |
| 5507 | |
| 5508 | intel_update_watermarks(dev); |
| 5509 | |
| 5510 | intel_update_linetime_watermarks(dev, pipe, adjusted_mode); |
| 5511 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5512 | return ret; |
| 5513 | } |
| 5514 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 5515 | static int intel_crtc_mode_set(struct drm_crtc *crtc, |
| 5516 | struct drm_display_mode *mode, |
| 5517 | struct drm_display_mode *adjusted_mode, |
| 5518 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 5519 | struct drm_framebuffer *fb) |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 5520 | { |
| 5521 | struct drm_device *dev = crtc->dev; |
| 5522 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9256aa1 | 2012-10-31 19:26:13 +0100 | [diff] [blame] | 5523 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 5524 | struct intel_encoder *encoder; |
Eric Anholt | 0b701d2 | 2011-03-30 13:01:03 -0700 | [diff] [blame] | 5525 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5526 | int pipe = intel_crtc->pipe; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 5527 | int ret; |
| 5528 | |
Eric Anholt | 0b701d2 | 2011-03-30 13:01:03 -0700 | [diff] [blame] | 5529 | drm_vblank_pre_modeset(dev, pipe); |
| 5530 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 5531 | ret = dev_priv->display.crtc_mode_set(crtc, mode, adjusted_mode, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 5532 | x, y, fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5533 | drm_vblank_post_modeset(dev, pipe); |
| 5534 | |
Daniel Vetter | 9256aa1 | 2012-10-31 19:26:13 +0100 | [diff] [blame] | 5535 | if (ret != 0) |
| 5536 | return ret; |
| 5537 | |
| 5538 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 5539 | DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n", |
| 5540 | encoder->base.base.id, |
| 5541 | drm_get_encoder_name(&encoder->base), |
| 5542 | mode->base.id, mode->name); |
| 5543 | encoder_funcs = encoder->base.helper_private; |
| 5544 | encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode); |
| 5545 | } |
| 5546 | |
| 5547 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5548 | } |
| 5549 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 5550 | static bool intel_eld_uptodate(struct drm_connector *connector, |
| 5551 | int reg_eldv, uint32_t bits_eldv, |
| 5552 | int reg_elda, uint32_t bits_elda, |
| 5553 | int reg_edid) |
| 5554 | { |
| 5555 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 5556 | uint8_t *eld = connector->eld; |
| 5557 | uint32_t i; |
| 5558 | |
| 5559 | i = I915_READ(reg_eldv); |
| 5560 | i &= bits_eldv; |
| 5561 | |
| 5562 | if (!eld[0]) |
| 5563 | return !i; |
| 5564 | |
| 5565 | if (!i) |
| 5566 | return false; |
| 5567 | |
| 5568 | i = I915_READ(reg_elda); |
| 5569 | i &= ~bits_elda; |
| 5570 | I915_WRITE(reg_elda, i); |
| 5571 | |
| 5572 | for (i = 0; i < eld[2]; i++) |
| 5573 | if (I915_READ(reg_edid) != *((uint32_t *)eld + i)) |
| 5574 | return false; |
| 5575 | |
| 5576 | return true; |
| 5577 | } |
| 5578 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5579 | static void g4x_write_eld(struct drm_connector *connector, |
| 5580 | struct drm_crtc *crtc) |
| 5581 | { |
| 5582 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 5583 | uint8_t *eld = connector->eld; |
| 5584 | uint32_t eldv; |
| 5585 | uint32_t len; |
| 5586 | uint32_t i; |
| 5587 | |
| 5588 | i = I915_READ(G4X_AUD_VID_DID); |
| 5589 | |
| 5590 | if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL) |
| 5591 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 5592 | else |
| 5593 | eldv = G4X_ELDV_DEVCTG; |
| 5594 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 5595 | if (intel_eld_uptodate(connector, |
| 5596 | G4X_AUD_CNTL_ST, eldv, |
| 5597 | G4X_AUD_CNTL_ST, G4X_ELD_ADDR, |
| 5598 | G4X_HDMIW_HDMIEDID)) |
| 5599 | return; |
| 5600 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5601 | i = I915_READ(G4X_AUD_CNTL_ST); |
| 5602 | i &= ~(eldv | G4X_ELD_ADDR); |
| 5603 | len = (i >> 9) & 0x1f; /* ELD buffer size */ |
| 5604 | I915_WRITE(G4X_AUD_CNTL_ST, i); |
| 5605 | |
| 5606 | if (!eld[0]) |
| 5607 | return; |
| 5608 | |
| 5609 | len = min_t(uint8_t, eld[2], len); |
| 5610 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 5611 | for (i = 0; i < len; i++) |
| 5612 | I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i)); |
| 5613 | |
| 5614 | i = I915_READ(G4X_AUD_CNTL_ST); |
| 5615 | i |= eldv; |
| 5616 | I915_WRITE(G4X_AUD_CNTL_ST, i); |
| 5617 | } |
| 5618 | |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 5619 | static void haswell_write_eld(struct drm_connector *connector, |
| 5620 | struct drm_crtc *crtc) |
| 5621 | { |
| 5622 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 5623 | uint8_t *eld = connector->eld; |
| 5624 | struct drm_device *dev = crtc->dev; |
| 5625 | uint32_t eldv; |
| 5626 | uint32_t i; |
| 5627 | int len; |
| 5628 | int pipe = to_intel_crtc(crtc)->pipe; |
| 5629 | int tmp; |
| 5630 | |
| 5631 | int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe); |
| 5632 | int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe); |
| 5633 | int aud_config = HSW_AUD_CFG(pipe); |
| 5634 | int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD; |
| 5635 | |
| 5636 | |
| 5637 | DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n"); |
| 5638 | |
| 5639 | /* Audio output enable */ |
| 5640 | DRM_DEBUG_DRIVER("HDMI audio: enable codec\n"); |
| 5641 | tmp = I915_READ(aud_cntrl_st2); |
| 5642 | tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4)); |
| 5643 | I915_WRITE(aud_cntrl_st2, tmp); |
| 5644 | |
| 5645 | /* Wait for 1 vertical blank */ |
| 5646 | intel_wait_for_vblank(dev, pipe); |
| 5647 | |
| 5648 | /* Set ELD valid state */ |
| 5649 | tmp = I915_READ(aud_cntrl_st2); |
| 5650 | DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp); |
| 5651 | tmp |= (AUDIO_ELD_VALID_A << (pipe * 4)); |
| 5652 | I915_WRITE(aud_cntrl_st2, tmp); |
| 5653 | tmp = I915_READ(aud_cntrl_st2); |
| 5654 | DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp); |
| 5655 | |
| 5656 | /* Enable HDMI mode */ |
| 5657 | tmp = I915_READ(aud_config); |
| 5658 | DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp); |
| 5659 | /* clear N_programing_enable and N_value_index */ |
| 5660 | tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE); |
| 5661 | I915_WRITE(aud_config, tmp); |
| 5662 | |
| 5663 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
| 5664 | |
| 5665 | eldv = AUDIO_ELD_VALID_A << (pipe * 4); |
| 5666 | |
| 5667 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
| 5668 | DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n"); |
| 5669 | eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */ |
| 5670 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
| 5671 | } else |
| 5672 | I915_WRITE(aud_config, 0); |
| 5673 | |
| 5674 | if (intel_eld_uptodate(connector, |
| 5675 | aud_cntrl_st2, eldv, |
| 5676 | aud_cntl_st, IBX_ELD_ADDRESS, |
| 5677 | hdmiw_hdmiedid)) |
| 5678 | return; |
| 5679 | |
| 5680 | i = I915_READ(aud_cntrl_st2); |
| 5681 | i &= ~eldv; |
| 5682 | I915_WRITE(aud_cntrl_st2, i); |
| 5683 | |
| 5684 | if (!eld[0]) |
| 5685 | return; |
| 5686 | |
| 5687 | i = I915_READ(aud_cntl_st); |
| 5688 | i &= ~IBX_ELD_ADDRESS; |
| 5689 | I915_WRITE(aud_cntl_st, i); |
| 5690 | i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */ |
| 5691 | DRM_DEBUG_DRIVER("port num:%d\n", i); |
| 5692 | |
| 5693 | len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
| 5694 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 5695 | for (i = 0; i < len; i++) |
| 5696 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 5697 | |
| 5698 | i = I915_READ(aud_cntrl_st2); |
| 5699 | i |= eldv; |
| 5700 | I915_WRITE(aud_cntrl_st2, i); |
| 5701 | |
| 5702 | } |
| 5703 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5704 | static void ironlake_write_eld(struct drm_connector *connector, |
| 5705 | struct drm_crtc *crtc) |
| 5706 | { |
| 5707 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 5708 | uint8_t *eld = connector->eld; |
| 5709 | uint32_t eldv; |
| 5710 | uint32_t i; |
| 5711 | int len; |
| 5712 | int hdmiw_hdmiedid; |
Wu Fengguang | b6daa02 | 2012-01-06 14:41:31 -0600 | [diff] [blame] | 5713 | int aud_config; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5714 | int aud_cntl_st; |
| 5715 | int aud_cntrl_st2; |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 5716 | int pipe = to_intel_crtc(crtc)->pipe; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5717 | |
Wu Fengguang | b3f33cb | 2011-12-09 20:42:17 +0800 | [diff] [blame] | 5718 | if (HAS_PCH_IBX(connector->dev)) { |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 5719 | hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe); |
| 5720 | aud_config = IBX_AUD_CFG(pipe); |
| 5721 | aud_cntl_st = IBX_AUD_CNTL_ST(pipe); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 5722 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5723 | } else { |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 5724 | hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe); |
| 5725 | aud_config = CPT_AUD_CFG(pipe); |
| 5726 | aud_cntl_st = CPT_AUD_CNTL_ST(pipe); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 5727 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5728 | } |
| 5729 | |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 5730 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5731 | |
| 5732 | i = I915_READ(aud_cntl_st); |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 5733 | i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */ |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5734 | if (!i) { |
| 5735 | DRM_DEBUG_DRIVER("Audio directed to unknown port\n"); |
| 5736 | /* operate blindly on all ports */ |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 5737 | eldv = IBX_ELD_VALIDB; |
| 5738 | eldv |= IBX_ELD_VALIDB << 4; |
| 5739 | eldv |= IBX_ELD_VALIDB << 8; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5740 | } else { |
| 5741 | DRM_DEBUG_DRIVER("ELD on port %c\n", 'A' + i); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 5742 | eldv = IBX_ELD_VALIDB << ((i - 1) * 4); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5743 | } |
| 5744 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 5745 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
| 5746 | DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n"); |
| 5747 | eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */ |
Wu Fengguang | b6daa02 | 2012-01-06 14:41:31 -0600 | [diff] [blame] | 5748 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
| 5749 | } else |
| 5750 | I915_WRITE(aud_config, 0); |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 5751 | |
| 5752 | if (intel_eld_uptodate(connector, |
| 5753 | aud_cntrl_st2, eldv, |
| 5754 | aud_cntl_st, IBX_ELD_ADDRESS, |
| 5755 | hdmiw_hdmiedid)) |
| 5756 | return; |
| 5757 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5758 | i = I915_READ(aud_cntrl_st2); |
| 5759 | i &= ~eldv; |
| 5760 | I915_WRITE(aud_cntrl_st2, i); |
| 5761 | |
| 5762 | if (!eld[0]) |
| 5763 | return; |
| 5764 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5765 | i = I915_READ(aud_cntl_st); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 5766 | i &= ~IBX_ELD_ADDRESS; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 5767 | I915_WRITE(aud_cntl_st, i); |
| 5768 | |
| 5769 | len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
| 5770 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 5771 | for (i = 0; i < len; i++) |
| 5772 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 5773 | |
| 5774 | i = I915_READ(aud_cntrl_st2); |
| 5775 | i |= eldv; |
| 5776 | I915_WRITE(aud_cntrl_st2, i); |
| 5777 | } |
| 5778 | |
| 5779 | void intel_write_eld(struct drm_encoder *encoder, |
| 5780 | struct drm_display_mode *mode) |
| 5781 | { |
| 5782 | struct drm_crtc *crtc = encoder->crtc; |
| 5783 | struct drm_connector *connector; |
| 5784 | struct drm_device *dev = encoder->dev; |
| 5785 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5786 | |
| 5787 | connector = drm_select_eld(encoder, mode); |
| 5788 | if (!connector) |
| 5789 | return; |
| 5790 | |
| 5791 | DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 5792 | connector->base.id, |
| 5793 | drm_get_connector_name(connector), |
| 5794 | connector->encoder->base.id, |
| 5795 | drm_get_encoder_name(connector->encoder)); |
| 5796 | |
| 5797 | connector->eld[6] = drm_av_sync_delay(connector, mode) / 2; |
| 5798 | |
| 5799 | if (dev_priv->display.write_eld) |
| 5800 | dev_priv->display.write_eld(connector, crtc); |
| 5801 | } |
| 5802 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5803 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 5804 | void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 5805 | { |
| 5806 | struct drm_device *dev = crtc->dev; |
| 5807 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5808 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5809 | int palreg = PALETTE(intel_crtc->pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5810 | int i; |
| 5811 | |
| 5812 | /* The clocks have to be on to load the palette. */ |
Alban Browaeys | aed3f09 | 2012-02-24 17:12:45 +0000 | [diff] [blame] | 5813 | if (!crtc->enabled || !intel_crtc->active) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5814 | return; |
| 5815 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 5816 | /* use legacy palette for Ironlake */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 5817 | if (HAS_PCH_SPLIT(dev)) |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5818 | palreg = LGC_PALETTE(intel_crtc->pipe); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5819 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5820 | for (i = 0; i < 256; i++) { |
| 5821 | I915_WRITE(palreg + 4 * i, |
| 5822 | (intel_crtc->lut_r[i] << 16) | |
| 5823 | (intel_crtc->lut_g[i] << 8) | |
| 5824 | intel_crtc->lut_b[i]); |
| 5825 | } |
| 5826 | } |
| 5827 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 5828 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 5829 | { |
| 5830 | struct drm_device *dev = crtc->dev; |
| 5831 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5832 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5833 | bool visible = base != 0; |
| 5834 | u32 cntl; |
| 5835 | |
| 5836 | if (intel_crtc->cursor_visible == visible) |
| 5837 | return; |
| 5838 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5839 | cntl = I915_READ(_CURACNTR); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 5840 | if (visible) { |
| 5841 | /* On these chipsets we can only modify the base whilst |
| 5842 | * the cursor is disabled. |
| 5843 | */ |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5844 | I915_WRITE(_CURABASE, base); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 5845 | |
| 5846 | cntl &= ~(CURSOR_FORMAT_MASK); |
| 5847 | /* XXX width must be 64, stride 256 => 0x00 << 28 */ |
| 5848 | cntl |= CURSOR_ENABLE | |
| 5849 | CURSOR_GAMMA_ENABLE | |
| 5850 | CURSOR_FORMAT_ARGB; |
| 5851 | } else |
| 5852 | cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5853 | I915_WRITE(_CURACNTR, cntl); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 5854 | |
| 5855 | intel_crtc->cursor_visible = visible; |
| 5856 | } |
| 5857 | |
| 5858 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 5859 | { |
| 5860 | struct drm_device *dev = crtc->dev; |
| 5861 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5862 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5863 | int pipe = intel_crtc->pipe; |
| 5864 | bool visible = base != 0; |
| 5865 | |
| 5866 | if (intel_crtc->cursor_visible != visible) { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 5867 | uint32_t cntl = I915_READ(CURCNTR(pipe)); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 5868 | if (base) { |
| 5869 | cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT); |
| 5870 | cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; |
| 5871 | cntl |= pipe << 28; /* Connect to correct pipe */ |
| 5872 | } else { |
| 5873 | cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE); |
| 5874 | cntl |= CURSOR_MODE_DISABLE; |
| 5875 | } |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5876 | I915_WRITE(CURCNTR(pipe), cntl); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 5877 | |
| 5878 | intel_crtc->cursor_visible = visible; |
| 5879 | } |
| 5880 | /* and commit changes on next vblank */ |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 5881 | I915_WRITE(CURBASE(pipe), base); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 5882 | } |
| 5883 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 5884 | static void ivb_update_cursor(struct drm_crtc *crtc, u32 base) |
| 5885 | { |
| 5886 | struct drm_device *dev = crtc->dev; |
| 5887 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5888 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5889 | int pipe = intel_crtc->pipe; |
| 5890 | bool visible = base != 0; |
| 5891 | |
| 5892 | if (intel_crtc->cursor_visible != visible) { |
| 5893 | uint32_t cntl = I915_READ(CURCNTR_IVB(pipe)); |
| 5894 | if (base) { |
| 5895 | cntl &= ~CURSOR_MODE; |
| 5896 | cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; |
| 5897 | } else { |
| 5898 | cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE); |
| 5899 | cntl |= CURSOR_MODE_DISABLE; |
| 5900 | } |
| 5901 | I915_WRITE(CURCNTR_IVB(pipe), cntl); |
| 5902 | |
| 5903 | intel_crtc->cursor_visible = visible; |
| 5904 | } |
| 5905 | /* and commit changes on next vblank */ |
| 5906 | I915_WRITE(CURBASE_IVB(pipe), base); |
| 5907 | } |
| 5908 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 5909 | /* If no-part of the cursor is visible on the framebuffer, then the GPU may hang... */ |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 5910 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 5911 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 5912 | { |
| 5913 | struct drm_device *dev = crtc->dev; |
| 5914 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5915 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5916 | int pipe = intel_crtc->pipe; |
| 5917 | int x = intel_crtc->cursor_x; |
| 5918 | int y = intel_crtc->cursor_y; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 5919 | u32 base, pos; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 5920 | bool visible; |
| 5921 | |
| 5922 | pos = 0; |
| 5923 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 5924 | if (on && crtc->enabled && crtc->fb) { |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 5925 | base = intel_crtc->cursor_addr; |
| 5926 | if (x > (int) crtc->fb->width) |
| 5927 | base = 0; |
| 5928 | |
| 5929 | if (y > (int) crtc->fb->height) |
| 5930 | base = 0; |
| 5931 | } else |
| 5932 | base = 0; |
| 5933 | |
| 5934 | if (x < 0) { |
| 5935 | if (x + intel_crtc->cursor_width < 0) |
| 5936 | base = 0; |
| 5937 | |
| 5938 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 5939 | x = -x; |
| 5940 | } |
| 5941 | pos |= x << CURSOR_X_SHIFT; |
| 5942 | |
| 5943 | if (y < 0) { |
| 5944 | if (y + intel_crtc->cursor_height < 0) |
| 5945 | base = 0; |
| 5946 | |
| 5947 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 5948 | y = -y; |
| 5949 | } |
| 5950 | pos |= y << CURSOR_Y_SHIFT; |
| 5951 | |
| 5952 | visible = base != 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 5953 | if (!visible && !intel_crtc->cursor_visible) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 5954 | return; |
| 5955 | |
Eugeni Dodonov | 0cd83aa | 2012-04-13 17:08:48 -0300 | [diff] [blame] | 5956 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 5957 | I915_WRITE(CURPOS_IVB(pipe), pos); |
| 5958 | ivb_update_cursor(crtc, base); |
| 5959 | } else { |
| 5960 | I915_WRITE(CURPOS(pipe), pos); |
| 5961 | if (IS_845G(dev) || IS_I865G(dev)) |
| 5962 | i845_update_cursor(crtc, base); |
| 5963 | else |
| 5964 | i9xx_update_cursor(crtc, base); |
| 5965 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 5966 | } |
| 5967 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5968 | static int intel_crtc_cursor_set(struct drm_crtc *crtc, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5969 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5970 | uint32_t handle, |
| 5971 | uint32_t width, uint32_t height) |
| 5972 | { |
| 5973 | struct drm_device *dev = crtc->dev; |
| 5974 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5975 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5976 | struct drm_i915_gem_object *obj; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 5977 | uint32_t addr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 5978 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5979 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5980 | /* if we want to turn off the cursor ignore width and height */ |
| 5981 | if (!handle) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 5982 | DRM_DEBUG_KMS("cursor off\n"); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 5983 | addr = 0; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5984 | obj = NULL; |
Pierre Willenbrock | 5004417 | 2009-02-23 10:12:15 +1000 | [diff] [blame] | 5985 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 5986 | goto finish; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5987 | } |
| 5988 | |
| 5989 | /* Currently we only support 64x64 cursors */ |
| 5990 | if (width != 64 || height != 64) { |
| 5991 | DRM_ERROR("we currently only support 64x64 cursors\n"); |
| 5992 | return -EINVAL; |
| 5993 | } |
| 5994 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5995 | obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle)); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 5996 | if (&obj->base == NULL) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5997 | return -ENOENT; |
| 5998 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 5999 | if (obj->base.size < width * height * 4) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6000 | DRM_ERROR("buffer is to small\n"); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 6001 | ret = -ENOMEM; |
| 6002 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6003 | } |
| 6004 | |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6005 | /* we only need to pin inside GTT if cursor is non-phy */ |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 6006 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | b295d1b | 2009-12-16 15:16:17 -0500 | [diff] [blame] | 6007 | if (!dev_priv->info->cursor_needs_physical) { |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 6008 | if (obj->tiling_mode) { |
| 6009 | DRM_ERROR("cursor cannot be tiled\n"); |
| 6010 | ret = -EINVAL; |
| 6011 | goto fail_locked; |
| 6012 | } |
| 6013 | |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 6014 | ret = i915_gem_object_pin_to_display_plane(obj, 0, NULL); |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 6015 | if (ret) { |
| 6016 | DRM_ERROR("failed to move cursor bo into the GTT\n"); |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 6017 | goto fail_locked; |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 6018 | } |
| 6019 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 6020 | ret = i915_gem_object_put_fence(obj); |
| 6021 | if (ret) { |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 6022 | DRM_ERROR("failed to release fence for cursor"); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 6023 | goto fail_unpin; |
| 6024 | } |
| 6025 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6026 | addr = obj->gtt_offset; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6027 | } else { |
Chris Wilson | 6eeefaf | 2010-08-07 11:01:39 +0100 | [diff] [blame] | 6028 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6029 | ret = i915_gem_attach_phys_object(dev, obj, |
Chris Wilson | 6eeefaf | 2010-08-07 11:01:39 +0100 | [diff] [blame] | 6030 | (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1, |
| 6031 | align); |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6032 | if (ret) { |
| 6033 | DRM_ERROR("failed to attach phys object\n"); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 6034 | goto fail_locked; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6035 | } |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6036 | addr = obj->phys_obj->handle->busaddr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6037 | } |
| 6038 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6039 | if (IS_GEN2(dev)) |
Jesse Barnes | 14b6039 | 2009-05-20 16:47:08 -0400 | [diff] [blame] | 6040 | I915_WRITE(CURSIZE, (height << 12) | width); |
| 6041 | |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6042 | finish: |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6043 | if (intel_crtc->cursor_bo) { |
Kristian Høgsberg | b295d1b | 2009-12-16 15:16:17 -0500 | [diff] [blame] | 6044 | if (dev_priv->info->cursor_needs_physical) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6045 | if (intel_crtc->cursor_bo != obj) |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6046 | i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo); |
| 6047 | } else |
| 6048 | i915_gem_object_unpin(intel_crtc->cursor_bo); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6049 | drm_gem_object_unreference(&intel_crtc->cursor_bo->base); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6050 | } |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 6051 | |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 6052 | mutex_unlock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6053 | |
| 6054 | intel_crtc->cursor_addr = addr; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6055 | intel_crtc->cursor_bo = obj; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6056 | intel_crtc->cursor_width = width; |
| 6057 | intel_crtc->cursor_height = height; |
| 6058 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6059 | intel_crtc_update_cursor(crtc, true); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6060 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6061 | return 0; |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 6062 | fail_unpin: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6063 | i915_gem_object_unpin(obj); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 6064 | fail_locked: |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 6065 | mutex_unlock(&dev->struct_mutex); |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 6066 | fail: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6067 | drm_gem_object_unreference_unlocked(&obj->base); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 6068 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6069 | } |
| 6070 | |
| 6071 | static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 6072 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6073 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6074 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6075 | intel_crtc->cursor_x = x; |
| 6076 | intel_crtc->cursor_y = y; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6077 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6078 | intel_crtc_update_cursor(crtc, true); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6079 | |
| 6080 | return 0; |
| 6081 | } |
| 6082 | |
| 6083 | /** Sets the color ramps on behalf of RandR */ |
| 6084 | void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
| 6085 | u16 blue, int regno) |
| 6086 | { |
| 6087 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6088 | |
| 6089 | intel_crtc->lut_r[regno] = red >> 8; |
| 6090 | intel_crtc->lut_g[regno] = green >> 8; |
| 6091 | intel_crtc->lut_b[regno] = blue >> 8; |
| 6092 | } |
| 6093 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 6094 | void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
| 6095 | u16 *blue, int regno) |
| 6096 | { |
| 6097 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6098 | |
| 6099 | *red = intel_crtc->lut_r[regno] << 8; |
| 6100 | *green = intel_crtc->lut_g[regno] << 8; |
| 6101 | *blue = intel_crtc->lut_b[regno] << 8; |
| 6102 | } |
| 6103 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6104 | static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 6105 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6106 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 6107 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6108 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6109 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 6110 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6111 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 6112 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 6113 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 6114 | } |
| 6115 | |
| 6116 | intel_crtc_load_lut(crtc); |
| 6117 | } |
| 6118 | |
| 6119 | /** |
| 6120 | * Get a pipe with a simple mode set on it for doing load-based monitor |
| 6121 | * detection. |
| 6122 | * |
| 6123 | * It will be up to the load-detect code to adjust the pipe as appropriate for |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6124 | * its requirements. The pipe will be connected to no other encoders. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6125 | * |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6126 | * Currently this code will only succeed if there is a pipe with no encoders |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6127 | * configured for it. In the future, it could choose to temporarily disable |
| 6128 | * some outputs to free up a pipe for its use. |
| 6129 | * |
| 6130 | * \return crtc, or NULL if no pipes are available. |
| 6131 | */ |
| 6132 | |
| 6133 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 6134 | static struct drm_display_mode load_detect_mode = { |
| 6135 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 6136 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 6137 | }; |
| 6138 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6139 | static struct drm_framebuffer * |
| 6140 | intel_framebuffer_create(struct drm_device *dev, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 6141 | struct drm_mode_fb_cmd2 *mode_cmd, |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6142 | struct drm_i915_gem_object *obj) |
| 6143 | { |
| 6144 | struct intel_framebuffer *intel_fb; |
| 6145 | int ret; |
| 6146 | |
| 6147 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 6148 | if (!intel_fb) { |
| 6149 | drm_gem_object_unreference_unlocked(&obj->base); |
| 6150 | return ERR_PTR(-ENOMEM); |
| 6151 | } |
| 6152 | |
| 6153 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
| 6154 | if (ret) { |
| 6155 | drm_gem_object_unreference_unlocked(&obj->base); |
| 6156 | kfree(intel_fb); |
| 6157 | return ERR_PTR(ret); |
| 6158 | } |
| 6159 | |
| 6160 | return &intel_fb->base; |
| 6161 | } |
| 6162 | |
| 6163 | static u32 |
| 6164 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 6165 | { |
| 6166 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 6167 | return ALIGN(pitch, 64); |
| 6168 | } |
| 6169 | |
| 6170 | static u32 |
| 6171 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 6172 | { |
| 6173 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
| 6174 | return ALIGN(pitch * mode->vdisplay, PAGE_SIZE); |
| 6175 | } |
| 6176 | |
| 6177 | static struct drm_framebuffer * |
| 6178 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 6179 | struct drm_display_mode *mode, |
| 6180 | int depth, int bpp) |
| 6181 | { |
| 6182 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 6183 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6184 | |
| 6185 | obj = i915_gem_alloc_object(dev, |
| 6186 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 6187 | if (obj == NULL) |
| 6188 | return ERR_PTR(-ENOMEM); |
| 6189 | |
| 6190 | mode_cmd.width = mode->hdisplay; |
| 6191 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 6192 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 6193 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 6194 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6195 | |
| 6196 | return intel_framebuffer_create(dev, &mode_cmd, obj); |
| 6197 | } |
| 6198 | |
| 6199 | static struct drm_framebuffer * |
| 6200 | mode_fits_in_fbdev(struct drm_device *dev, |
| 6201 | struct drm_display_mode *mode) |
| 6202 | { |
| 6203 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6204 | struct drm_i915_gem_object *obj; |
| 6205 | struct drm_framebuffer *fb; |
| 6206 | |
| 6207 | if (dev_priv->fbdev == NULL) |
| 6208 | return NULL; |
| 6209 | |
| 6210 | obj = dev_priv->fbdev->ifb.obj; |
| 6211 | if (obj == NULL) |
| 6212 | return NULL; |
| 6213 | |
| 6214 | fb = &dev_priv->fbdev->ifb.base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 6215 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 6216 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6217 | return NULL; |
| 6218 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 6219 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6220 | return NULL; |
| 6221 | |
| 6222 | return fb; |
| 6223 | } |
| 6224 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 6225 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6226 | struct drm_display_mode *mode, |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6227 | struct intel_load_detect_pipe *old) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6228 | { |
| 6229 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 6230 | struct intel_encoder *intel_encoder = |
| 6231 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6232 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6233 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6234 | struct drm_crtc *crtc = NULL; |
| 6235 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6236 | struct drm_framebuffer *fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6237 | int i = -1; |
| 6238 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6239 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 6240 | connector->base.id, drm_get_connector_name(connector), |
| 6241 | encoder->base.id, drm_get_encoder_name(encoder)); |
| 6242 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6243 | /* |
| 6244 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 6245 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6246 | * - if the connector already has an assigned crtc, use it (but make |
| 6247 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 6248 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6249 | * - try to find the first unused crtc that can drive this connector, |
| 6250 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6251 | */ |
| 6252 | |
| 6253 | /* See if we already have a CRTC for this connector */ |
| 6254 | if (encoder->crtc) { |
| 6255 | crtc = encoder->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6256 | |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 6257 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6258 | old->load_detect_temp = false; |
| 6259 | |
| 6260 | /* Make sure the crtc and connector are running */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 6261 | if (connector->dpms != DRM_MODE_DPMS_ON) |
| 6262 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6263 | |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6264 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6265 | } |
| 6266 | |
| 6267 | /* Find an unused one (if possible) */ |
| 6268 | list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) { |
| 6269 | i++; |
| 6270 | if (!(encoder->possible_crtcs & (1 << i))) |
| 6271 | continue; |
| 6272 | if (!possible_crtc->enabled) { |
| 6273 | crtc = possible_crtc; |
| 6274 | break; |
| 6275 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6276 | } |
| 6277 | |
| 6278 | /* |
| 6279 | * If we didn't find an unused CRTC, don't use any. |
| 6280 | */ |
| 6281 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6282 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
| 6283 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6284 | } |
| 6285 | |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 6286 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
| 6287 | to_intel_connector(connector)->new_encoder = intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6288 | |
| 6289 | intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 6290 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6291 | old->load_detect_temp = true; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6292 | old->release_fb = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6293 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 6294 | if (!mode) |
| 6295 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6296 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6297 | /* We need a framebuffer large enough to accommodate all accesses |
| 6298 | * that the plane may generate whilst we perform load detection. |
| 6299 | * We can not rely on the fbcon either being present (we get called |
| 6300 | * during its initialisation to detect all boot displays, or it may |
| 6301 | * not even exist) or that it is large enough to satisfy the |
| 6302 | * requested mode. |
| 6303 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6304 | fb = mode_fits_in_fbdev(dev, mode); |
| 6305 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6306 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6307 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
| 6308 | old->release_fb = fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6309 | } else |
| 6310 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6311 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6312 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Chris Wilson | 0e8b3d3 | 2012-11-05 22:25:08 +0000 | [diff] [blame] | 6313 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6314 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6315 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 6316 | if (intel_set_mode(crtc, mode, 0, 0, fb)) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 6317 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6318 | if (old->release_fb) |
| 6319 | old->release_fb->funcs->destroy(old->release_fb); |
Chris Wilson | 0e8b3d3 | 2012-11-05 22:25:08 +0000 | [diff] [blame] | 6320 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6321 | } |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6322 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6323 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 6324 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6325 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6326 | } |
| 6327 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 6328 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6329 | struct intel_load_detect_pipe *old) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6330 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 6331 | struct intel_encoder *intel_encoder = |
| 6332 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6333 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6334 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6335 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 6336 | connector->base.id, drm_get_connector_name(connector), |
| 6337 | encoder->base.id, drm_get_encoder_name(encoder)); |
| 6338 | |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6339 | if (old->load_detect_temp) { |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 6340 | struct drm_crtc *crtc = encoder->crtc; |
| 6341 | |
| 6342 | to_intel_connector(connector)->new_encoder = NULL; |
| 6343 | intel_encoder->new_crtc = NULL; |
| 6344 | intel_set_mode(crtc, NULL, 0, 0, NULL); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6345 | |
| 6346 | if (old->release_fb) |
| 6347 | old->release_fb->funcs->destroy(old->release_fb); |
| 6348 | |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 6349 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6350 | } |
| 6351 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6352 | /* Switch crtc and encoder back off if necessary */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 6353 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
| 6354 | connector->funcs->dpms(connector, old->dpms_mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6355 | } |
| 6356 | |
| 6357 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
| 6358 | static int intel_crtc_clock_get(struct drm_device *dev, struct drm_crtc *crtc) |
| 6359 | { |
| 6360 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6361 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6362 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 6363 | u32 dpll = I915_READ(DPLL(pipe)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6364 | u32 fp; |
| 6365 | intel_clock_t clock; |
| 6366 | |
| 6367 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Chris Wilson | 39adb7a | 2011-04-22 22:17:21 +0100 | [diff] [blame] | 6368 | fp = I915_READ(FP0(pipe)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6369 | else |
Chris Wilson | 39adb7a | 2011-04-22 22:17:21 +0100 | [diff] [blame] | 6370 | fp = I915_READ(FP1(pipe)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6371 | |
| 6372 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 6373 | if (IS_PINEVIEW(dev)) { |
| 6374 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 6375 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 6376 | } else { |
| 6377 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 6378 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 6379 | } |
| 6380 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6381 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 6382 | if (IS_PINEVIEW(dev)) |
| 6383 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 6384 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 6385 | else |
| 6386 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6387 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 6388 | |
| 6389 | switch (dpll & DPLL_MODE_MASK) { |
| 6390 | case DPLLB_MODE_DAC_SERIAL: |
| 6391 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 6392 | 5 : 10; |
| 6393 | break; |
| 6394 | case DPLLB_MODE_LVDS: |
| 6395 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 6396 | 7 : 14; |
| 6397 | break; |
| 6398 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 6399 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6400 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
| 6401 | return 0; |
| 6402 | } |
| 6403 | |
| 6404 | /* XXX: Handle the 100Mhz refclk */ |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 6405 | intel_clock(dev, 96000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6406 | } else { |
| 6407 | bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN); |
| 6408 | |
| 6409 | if (is_lvds) { |
| 6410 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 6411 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 6412 | clock.p2 = 14; |
| 6413 | |
| 6414 | if ((dpll & PLL_REF_INPUT_MASK) == |
| 6415 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 6416 | /* XXX: might not be 66MHz */ |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 6417 | intel_clock(dev, 66000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6418 | } else |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 6419 | intel_clock(dev, 48000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6420 | } else { |
| 6421 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 6422 | clock.p1 = 2; |
| 6423 | else { |
| 6424 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 6425 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 6426 | } |
| 6427 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 6428 | clock.p2 = 4; |
| 6429 | else |
| 6430 | clock.p2 = 2; |
| 6431 | |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 6432 | intel_clock(dev, 48000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6433 | } |
| 6434 | } |
| 6435 | |
| 6436 | /* XXX: It would be nice to validate the clocks, but we can't reuse |
| 6437 | * i830PllIsValid() because it relies on the xf86_config connector |
| 6438 | * configuration being accurate, which it isn't necessarily. |
| 6439 | */ |
| 6440 | |
| 6441 | return clock.dot; |
| 6442 | } |
| 6443 | |
| 6444 | /** Returns the currently programmed mode of the given pipe. */ |
| 6445 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 6446 | struct drm_crtc *crtc) |
| 6447 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 6448 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6449 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6450 | enum transcoder cpu_transcoder = intel_crtc->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6451 | struct drm_display_mode *mode; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6452 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 6453 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 6454 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 6455 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6456 | |
| 6457 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 6458 | if (!mode) |
| 6459 | return NULL; |
| 6460 | |
| 6461 | mode->clock = intel_crtc_clock_get(dev, crtc); |
| 6462 | mode->hdisplay = (htot & 0xffff) + 1; |
| 6463 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 6464 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 6465 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 6466 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 6467 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 6468 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 6469 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 6470 | |
| 6471 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6472 | |
| 6473 | return mode; |
| 6474 | } |
| 6475 | |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 6476 | static void intel_increase_pllclock(struct drm_crtc *crtc) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6477 | { |
| 6478 | struct drm_device *dev = crtc->dev; |
| 6479 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 6480 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6481 | int pipe = intel_crtc->pipe; |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 6482 | int dpll_reg = DPLL(pipe); |
| 6483 | int dpll; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6484 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 6485 | if (HAS_PCH_SPLIT(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6486 | return; |
| 6487 | |
| 6488 | if (!dev_priv->lvds_downclock_avail) |
| 6489 | return; |
| 6490 | |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 6491 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6492 | if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 6493 | DRM_DEBUG_DRIVER("upclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6494 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 6495 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6496 | |
| 6497 | dpll &= ~DISPLAY_RATE_SELECT_FPA1; |
| 6498 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 6499 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 6500 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6501 | dpll = I915_READ(dpll_reg); |
| 6502 | if (dpll & DISPLAY_RATE_SELECT_FPA1) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 6503 | DRM_DEBUG_DRIVER("failed to upclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6504 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6505 | } |
| 6506 | |
| 6507 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 6508 | { |
| 6509 | struct drm_device *dev = crtc->dev; |
| 6510 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 6511 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6512 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 6513 | if (HAS_PCH_SPLIT(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6514 | return; |
| 6515 | |
| 6516 | if (!dev_priv->lvds_downclock_avail) |
| 6517 | return; |
| 6518 | |
| 6519 | /* |
| 6520 | * Since this is called by a timer, we should never get here in |
| 6521 | * the manual case. |
| 6522 | */ |
| 6523 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 6524 | int pipe = intel_crtc->pipe; |
| 6525 | int dpll_reg = DPLL(pipe); |
Daniel Vetter | dc257cf | 2012-05-07 11:30:46 +0200 | [diff] [blame] | 6526 | int dpll; |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 6527 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 6528 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6529 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 6530 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6531 | |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 6532 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6533 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 6534 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 6535 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6536 | dpll = I915_READ(dpll_reg); |
| 6537 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 6538 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6539 | } |
| 6540 | |
| 6541 | } |
| 6542 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 6543 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6544 | { |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 6545 | i915_update_gfx_val(dev->dev_private); |
| 6546 | } |
| 6547 | |
| 6548 | void intel_mark_idle(struct drm_device *dev) |
| 6549 | { |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 6550 | } |
| 6551 | |
| 6552 | void intel_mark_fb_busy(struct drm_i915_gem_object *obj) |
| 6553 | { |
| 6554 | struct drm_device *dev = obj->base.dev; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6555 | struct drm_crtc *crtc; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6556 | |
| 6557 | if (!i915_powersave) |
| 6558 | return; |
| 6559 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6560 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6561 | if (!crtc->fb) |
| 6562 | continue; |
| 6563 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 6564 | if (to_intel_framebuffer(crtc->fb)->obj == obj) |
| 6565 | intel_increase_pllclock(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6566 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6567 | } |
| 6568 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 6569 | void intel_mark_fb_idle(struct drm_i915_gem_object *obj) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6570 | { |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 6571 | struct drm_device *dev = obj->base.dev; |
| 6572 | struct drm_crtc *crtc; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6573 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 6574 | if (!i915_powersave) |
Chris Wilson | acb87df | 2012-05-03 15:47:57 +0100 | [diff] [blame] | 6575 | return; |
| 6576 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6577 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 6578 | if (!crtc->fb) |
| 6579 | continue; |
| 6580 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 6581 | if (to_intel_framebuffer(crtc->fb)->obj == obj) |
| 6582 | intel_decrease_pllclock(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6583 | } |
| 6584 | } |
| 6585 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6586 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 6587 | { |
| 6588 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 6589 | struct drm_device *dev = crtc->dev; |
| 6590 | struct intel_unpin_work *work; |
| 6591 | unsigned long flags; |
| 6592 | |
| 6593 | spin_lock_irqsave(&dev->event_lock, flags); |
| 6594 | work = intel_crtc->unpin_work; |
| 6595 | intel_crtc->unpin_work = NULL; |
| 6596 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 6597 | |
| 6598 | if (work) { |
| 6599 | cancel_work_sync(&work->work); |
| 6600 | kfree(work); |
| 6601 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6602 | |
| 6603 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 6604 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6605 | kfree(intel_crtc); |
| 6606 | } |
| 6607 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6608 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 6609 | { |
| 6610 | struct intel_unpin_work *work = |
| 6611 | container_of(__work, struct intel_unpin_work, work); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 6612 | struct drm_device *dev = work->crtc->dev; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6613 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 6614 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 6615 | intel_unpin_fb_obj(work->old_fb_obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6616 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
| 6617 | drm_gem_object_unreference(&work->old_fb_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 6618 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 6619 | intel_update_fbc(dev); |
| 6620 | mutex_unlock(&dev->struct_mutex); |
| 6621 | |
| 6622 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
| 6623 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); |
| 6624 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6625 | kfree(work); |
| 6626 | } |
| 6627 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 6628 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 6629 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6630 | { |
| 6631 | drm_i915_private_t *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6632 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6633 | struct intel_unpin_work *work; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6634 | struct drm_i915_gem_object *obj; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6635 | unsigned long flags; |
| 6636 | |
| 6637 | /* Ignore early vblank irqs */ |
| 6638 | if (intel_crtc == NULL) |
| 6639 | return; |
| 6640 | |
| 6641 | spin_lock_irqsave(&dev->event_lock, flags); |
| 6642 | work = intel_crtc->unpin_work; |
| 6643 | if (work == NULL || !work->pending) { |
| 6644 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 6645 | return; |
| 6646 | } |
| 6647 | |
| 6648 | intel_crtc->unpin_work = NULL; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6649 | |
Rob Clark | 45a066e | 2012-10-08 14:50:40 -0500 | [diff] [blame] | 6650 | if (work->event) |
| 6651 | drm_send_vblank_event(dev, intel_crtc->pipe, work->event); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6652 | |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 6653 | drm_vblank_put(dev, intel_crtc->pipe); |
| 6654 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6655 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 6656 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6657 | obj = work->old_fb_obj; |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 6658 | |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 6659 | wake_up(&dev_priv->pending_flip_queue); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 6660 | |
| 6661 | queue_work(dev_priv->wq, &work->work); |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 6662 | |
| 6663 | trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6664 | } |
| 6665 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 6666 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 6667 | { |
| 6668 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 6669 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 6670 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 6671 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 6672 | } |
| 6673 | |
| 6674 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 6675 | { |
| 6676 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 6677 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 6678 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 6679 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 6680 | } |
| 6681 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6682 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 6683 | { |
| 6684 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 6685 | struct intel_crtc *intel_crtc = |
| 6686 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 6687 | unsigned long flags; |
| 6688 | |
| 6689 | spin_lock_irqsave(&dev->event_lock, flags); |
Jesse Barnes | de3f440 | 2010-01-14 13:18:02 -0800 | [diff] [blame] | 6690 | if (intel_crtc->unpin_work) { |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 6691 | if ((++intel_crtc->unpin_work->pending) > 1) |
| 6692 | DRM_ERROR("Prepared flip multiple times\n"); |
Jesse Barnes | de3f440 | 2010-01-14 13:18:02 -0800 | [diff] [blame] | 6693 | } else { |
| 6694 | DRM_DEBUG_DRIVER("preparing flip with no unpin work?\n"); |
| 6695 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6696 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 6697 | } |
| 6698 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6699 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 6700 | struct drm_crtc *crtc, |
| 6701 | struct drm_framebuffer *fb, |
| 6702 | struct drm_i915_gem_object *obj) |
| 6703 | { |
| 6704 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6705 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6706 | u32 flip_mask; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6707 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6708 | int ret; |
| 6709 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6710 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6711 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6712 | goto err; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6713 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6714 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6715 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6716 | goto err_unpin; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6717 | |
| 6718 | /* Can't queue multiple flips, so wait for the previous |
| 6719 | * one to finish before executing the next. |
| 6720 | */ |
| 6721 | if (intel_crtc->plane) |
| 6722 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 6723 | else |
| 6724 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6725 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 6726 | intel_ring_emit(ring, MI_NOOP); |
| 6727 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 6728 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 6729 | intel_ring_emit(ring, fb->pitches[0]); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 6730 | intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6731 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
| 6732 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6733 | return 0; |
| 6734 | |
| 6735 | err_unpin: |
| 6736 | intel_unpin_fb_obj(obj); |
| 6737 | err: |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6738 | return ret; |
| 6739 | } |
| 6740 | |
| 6741 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 6742 | struct drm_crtc *crtc, |
| 6743 | struct drm_framebuffer *fb, |
| 6744 | struct drm_i915_gem_object *obj) |
| 6745 | { |
| 6746 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6747 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6748 | u32 flip_mask; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6749 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6750 | int ret; |
| 6751 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6752 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6753 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6754 | goto err; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6755 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6756 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6757 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6758 | goto err_unpin; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6759 | |
| 6760 | if (intel_crtc->plane) |
| 6761 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 6762 | else |
| 6763 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6764 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 6765 | intel_ring_emit(ring, MI_NOOP); |
| 6766 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
| 6767 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 6768 | intel_ring_emit(ring, fb->pitches[0]); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 6769 | intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6770 | intel_ring_emit(ring, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6771 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6772 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6773 | return 0; |
| 6774 | |
| 6775 | err_unpin: |
| 6776 | intel_unpin_fb_obj(obj); |
| 6777 | err: |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6778 | return ret; |
| 6779 | } |
| 6780 | |
| 6781 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 6782 | struct drm_crtc *crtc, |
| 6783 | struct drm_framebuffer *fb, |
| 6784 | struct drm_i915_gem_object *obj) |
| 6785 | { |
| 6786 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6787 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6788 | uint32_t pf, pipesrc; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6789 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6790 | int ret; |
| 6791 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6792 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6793 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6794 | goto err; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6795 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6796 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6797 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6798 | goto err_unpin; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6799 | |
| 6800 | /* i965+ uses the linear or tiled offsets from the |
| 6801 | * Display Registers (which do not change across a page-flip) |
| 6802 | * so we need only reprogram the base address. |
| 6803 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6804 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 6805 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 6806 | intel_ring_emit(ring, fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 6807 | intel_ring_emit(ring, |
| 6808 | (obj->gtt_offset + intel_crtc->dspaddr_offset) | |
| 6809 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6810 | |
| 6811 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 6812 | * untested on non-native modes, so ignore it for now. |
| 6813 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 6814 | */ |
| 6815 | pf = 0; |
| 6816 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6817 | intel_ring_emit(ring, pf | pipesrc); |
| 6818 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6819 | return 0; |
| 6820 | |
| 6821 | err_unpin: |
| 6822 | intel_unpin_fb_obj(obj); |
| 6823 | err: |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6824 | return ret; |
| 6825 | } |
| 6826 | |
| 6827 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 6828 | struct drm_crtc *crtc, |
| 6829 | struct drm_framebuffer *fb, |
| 6830 | struct drm_i915_gem_object *obj) |
| 6831 | { |
| 6832 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6833 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6834 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6835 | uint32_t pf, pipesrc; |
| 6836 | int ret; |
| 6837 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6838 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6839 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6840 | goto err; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6841 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6842 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6843 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6844 | goto err_unpin; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6845 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6846 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 6847 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 6848 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 6849 | intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6850 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 6851 | /* Contrary to the suggestions in the documentation, |
| 6852 | * "Enable Panel Fitter" does not seem to be required when page |
| 6853 | * flipping with a non-native mode, and worse causes a normal |
| 6854 | * modeset to fail. |
| 6855 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 6856 | */ |
| 6857 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6858 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 6859 | intel_ring_emit(ring, pf | pipesrc); |
| 6860 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6861 | return 0; |
| 6862 | |
| 6863 | err_unpin: |
| 6864 | intel_unpin_fb_obj(obj); |
| 6865 | err: |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6866 | return ret; |
| 6867 | } |
| 6868 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 6869 | /* |
| 6870 | * On gen7 we currently use the blit ring because (in early silicon at least) |
| 6871 | * the render ring doesn't give us interrpts for page flip completion, which |
| 6872 | * means clients will hang after the first flip is queued. Fortunately the |
| 6873 | * blit ring generates interrupts properly, so use it instead. |
| 6874 | */ |
| 6875 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 6876 | struct drm_crtc *crtc, |
| 6877 | struct drm_framebuffer *fb, |
| 6878 | struct drm_i915_gem_object *obj) |
| 6879 | { |
| 6880 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6881 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6882 | struct intel_ring_buffer *ring = &dev_priv->ring[BCS]; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 6883 | uint32_t plane_bit = 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 6884 | int ret; |
| 6885 | |
| 6886 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
| 6887 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6888 | goto err; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 6889 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 6890 | switch(intel_crtc->plane) { |
| 6891 | case PLANE_A: |
| 6892 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 6893 | break; |
| 6894 | case PLANE_B: |
| 6895 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 6896 | break; |
| 6897 | case PLANE_C: |
| 6898 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 6899 | break; |
| 6900 | default: |
| 6901 | WARN_ONCE(1, "unknown plane in flip command\n"); |
| 6902 | ret = -ENODEV; |
Eugeni Dodonov | ab3951e | 2012-06-18 19:03:38 -0300 | [diff] [blame] | 6903 | goto err_unpin; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 6904 | } |
| 6905 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 6906 | ret = intel_ring_begin(ring, 4); |
| 6907 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6908 | goto err_unpin; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 6909 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 6910 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 6911 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 6912 | intel_ring_emit(ring, obj->gtt_offset + intel_crtc->dspaddr_offset); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 6913 | intel_ring_emit(ring, (MI_NOOP)); |
| 6914 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 6915 | return 0; |
| 6916 | |
| 6917 | err_unpin: |
| 6918 | intel_unpin_fb_obj(obj); |
| 6919 | err: |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 6920 | return ret; |
| 6921 | } |
| 6922 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6923 | static int intel_default_queue_flip(struct drm_device *dev, |
| 6924 | struct drm_crtc *crtc, |
| 6925 | struct drm_framebuffer *fb, |
| 6926 | struct drm_i915_gem_object *obj) |
| 6927 | { |
| 6928 | return -ENODEV; |
| 6929 | } |
| 6930 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6931 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 6932 | struct drm_framebuffer *fb, |
| 6933 | struct drm_pending_vblank_event *event) |
| 6934 | { |
| 6935 | struct drm_device *dev = crtc->dev; |
| 6936 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6937 | struct intel_framebuffer *intel_fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6938 | struct drm_i915_gem_object *obj; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6939 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6940 | struct intel_unpin_work *work; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 6941 | unsigned long flags; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 6942 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6943 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 6944 | /* Can't change pixel format via MI display flips. */ |
| 6945 | if (fb->pixel_format != crtc->fb->pixel_format) |
| 6946 | return -EINVAL; |
| 6947 | |
| 6948 | /* |
| 6949 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 6950 | * Note that pitch changes could also affect these register. |
| 6951 | */ |
| 6952 | if (INTEL_INFO(dev)->gen > 3 && |
| 6953 | (fb->offsets[0] != crtc->fb->offsets[0] || |
| 6954 | fb->pitches[0] != crtc->fb->pitches[0])) |
| 6955 | return -EINVAL; |
| 6956 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6957 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 6958 | if (work == NULL) |
| 6959 | return -ENOMEM; |
| 6960 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6961 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 6962 | work->crtc = crtc; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6963 | intel_fb = to_intel_framebuffer(crtc->fb); |
Jesse Barnes | b1b87f6 | 2010-01-26 14:40:05 -0800 | [diff] [blame] | 6964 | work->old_fb_obj = intel_fb->obj; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6965 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 6966 | |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 6967 | ret = drm_vblank_get(dev, intel_crtc->pipe); |
| 6968 | if (ret) |
| 6969 | goto free_work; |
| 6970 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6971 | /* We borrow the event spin lock for protecting unpin_work */ |
| 6972 | spin_lock_irqsave(&dev->event_lock, flags); |
| 6973 | if (intel_crtc->unpin_work) { |
| 6974 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 6975 | kfree(work); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 6976 | drm_vblank_put(dev, intel_crtc->pipe); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 6977 | |
| 6978 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6979 | return -EBUSY; |
| 6980 | } |
| 6981 | intel_crtc->unpin_work = work; |
| 6982 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 6983 | |
| 6984 | intel_fb = to_intel_framebuffer(fb); |
| 6985 | obj = intel_fb->obj; |
| 6986 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 6987 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 6988 | flush_workqueue(dev_priv->wq); |
| 6989 | |
Chris Wilson | 7915810 | 2012-05-23 11:13:58 +0100 | [diff] [blame] | 6990 | ret = i915_mutex_lock_interruptible(dev); |
| 6991 | if (ret) |
| 6992 | goto cleanup; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6993 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 6994 | /* Reference the objects for the scheduled work. */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6995 | drm_gem_object_reference(&work->old_fb_obj->base); |
| 6996 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 6997 | |
| 6998 | crtc->fb = fb; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 6999 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 7000 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 7001 | |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 7002 | work->enable_stall_check = true; |
| 7003 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7004 | atomic_inc(&intel_crtc->unpin_work_count); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 7005 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7006 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj); |
| 7007 | if (ret) |
| 7008 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7009 | |
Chris Wilson | 7782de3 | 2011-07-08 12:22:41 +0100 | [diff] [blame] | 7010 | intel_disable_fbc(dev); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 7011 | intel_mark_fb_busy(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7012 | mutex_unlock(&dev->struct_mutex); |
| 7013 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 7014 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 7015 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7016 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 7017 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7018 | cleanup_pending: |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7019 | atomic_dec(&intel_crtc->unpin_work_count); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 7020 | drm_gem_object_unreference(&work->old_fb_obj->base); |
| 7021 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 7022 | mutex_unlock(&dev->struct_mutex); |
| 7023 | |
Chris Wilson | 7915810 | 2012-05-23 11:13:58 +0100 | [diff] [blame] | 7024 | cleanup: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 7025 | spin_lock_irqsave(&dev->event_lock, flags); |
| 7026 | intel_crtc->unpin_work = NULL; |
| 7027 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 7028 | |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 7029 | drm_vblank_put(dev, intel_crtc->pipe); |
| 7030 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 7031 | kfree(work); |
| 7032 | |
| 7033 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7034 | } |
| 7035 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 7036 | static struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 7037 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 7038 | .load_lut = intel_crtc_load_lut, |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 7039 | .disable = intel_crtc_noop, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 7040 | }; |
| 7041 | |
Daniel Vetter | 6ed0f79 | 2012-07-08 19:41:43 +0200 | [diff] [blame] | 7042 | bool intel_encoder_check_is_cloned(struct intel_encoder *encoder) |
| 7043 | { |
| 7044 | struct intel_encoder *other_encoder; |
| 7045 | struct drm_crtc *crtc = &encoder->new_crtc->base; |
| 7046 | |
| 7047 | if (WARN_ON(!crtc)) |
| 7048 | return false; |
| 7049 | |
| 7050 | list_for_each_entry(other_encoder, |
| 7051 | &crtc->dev->mode_config.encoder_list, |
| 7052 | base.head) { |
| 7053 | |
| 7054 | if (&other_encoder->new_crtc->base != crtc || |
| 7055 | encoder == other_encoder) |
| 7056 | continue; |
| 7057 | else |
| 7058 | return true; |
| 7059 | } |
| 7060 | |
| 7061 | return false; |
| 7062 | } |
| 7063 | |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7064 | static bool intel_encoder_crtc_ok(struct drm_encoder *encoder, |
| 7065 | struct drm_crtc *crtc) |
| 7066 | { |
| 7067 | struct drm_device *dev; |
| 7068 | struct drm_crtc *tmp; |
| 7069 | int crtc_mask = 1; |
| 7070 | |
| 7071 | WARN(!crtc, "checking null crtc?\n"); |
| 7072 | |
| 7073 | dev = crtc->dev; |
| 7074 | |
| 7075 | list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) { |
| 7076 | if (tmp == crtc) |
| 7077 | break; |
| 7078 | crtc_mask <<= 1; |
| 7079 | } |
| 7080 | |
| 7081 | if (encoder->possible_crtcs & crtc_mask) |
| 7082 | return true; |
| 7083 | return false; |
| 7084 | } |
| 7085 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7086 | /** |
| 7087 | * intel_modeset_update_staged_output_state |
| 7088 | * |
| 7089 | * Updates the staged output configuration state, e.g. after we've read out the |
| 7090 | * current hw state. |
| 7091 | */ |
| 7092 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) |
| 7093 | { |
| 7094 | struct intel_encoder *encoder; |
| 7095 | struct intel_connector *connector; |
| 7096 | |
| 7097 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7098 | base.head) { |
| 7099 | connector->new_encoder = |
| 7100 | to_intel_encoder(connector->base.encoder); |
| 7101 | } |
| 7102 | |
| 7103 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7104 | base.head) { |
| 7105 | encoder->new_crtc = |
| 7106 | to_intel_crtc(encoder->base.crtc); |
| 7107 | } |
| 7108 | } |
| 7109 | |
| 7110 | /** |
| 7111 | * intel_modeset_commit_output_state |
| 7112 | * |
| 7113 | * This function copies the stage display pipe configuration to the real one. |
| 7114 | */ |
| 7115 | static void intel_modeset_commit_output_state(struct drm_device *dev) |
| 7116 | { |
| 7117 | struct intel_encoder *encoder; |
| 7118 | struct intel_connector *connector; |
| 7119 | |
| 7120 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7121 | base.head) { |
| 7122 | connector->base.encoder = &connector->new_encoder->base; |
| 7123 | } |
| 7124 | |
| 7125 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7126 | base.head) { |
| 7127 | encoder->base.crtc = &encoder->new_crtc->base; |
| 7128 | } |
| 7129 | } |
| 7130 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7131 | static struct drm_display_mode * |
| 7132 | intel_modeset_adjusted_mode(struct drm_crtc *crtc, |
| 7133 | struct drm_display_mode *mode) |
| 7134 | { |
| 7135 | struct drm_device *dev = crtc->dev; |
| 7136 | struct drm_display_mode *adjusted_mode; |
| 7137 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 7138 | struct intel_encoder *encoder; |
| 7139 | |
| 7140 | adjusted_mode = drm_mode_duplicate(dev, mode); |
| 7141 | if (!adjusted_mode) |
| 7142 | return ERR_PTR(-ENOMEM); |
| 7143 | |
| 7144 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 7145 | * adjust it according to limitations or connector properties, and also |
| 7146 | * a chance to reject the mode entirely. |
| 7147 | */ |
| 7148 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7149 | base.head) { |
| 7150 | |
| 7151 | if (&encoder->new_crtc->base != crtc) |
| 7152 | continue; |
| 7153 | encoder_funcs = encoder->base.helper_private; |
| 7154 | if (!(encoder_funcs->mode_fixup(&encoder->base, mode, |
| 7155 | adjusted_mode))) { |
| 7156 | DRM_DEBUG_KMS("Encoder fixup failed\n"); |
| 7157 | goto fail; |
| 7158 | } |
| 7159 | } |
| 7160 | |
| 7161 | if (!(intel_crtc_mode_fixup(crtc, mode, adjusted_mode))) { |
| 7162 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 7163 | goto fail; |
| 7164 | } |
| 7165 | DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); |
| 7166 | |
| 7167 | return adjusted_mode; |
| 7168 | fail: |
| 7169 | drm_mode_destroy(dev, adjusted_mode); |
| 7170 | return ERR_PTR(-EINVAL); |
| 7171 | } |
| 7172 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 7173 | /* Computes which crtcs are affected and sets the relevant bits in the mask. For |
| 7174 | * simplicity we use the crtc's pipe number (because it's easier to obtain). */ |
| 7175 | static void |
| 7176 | intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes, |
| 7177 | unsigned *prepare_pipes, unsigned *disable_pipes) |
| 7178 | { |
| 7179 | struct intel_crtc *intel_crtc; |
| 7180 | struct drm_device *dev = crtc->dev; |
| 7181 | struct intel_encoder *encoder; |
| 7182 | struct intel_connector *connector; |
| 7183 | struct drm_crtc *tmp_crtc; |
| 7184 | |
| 7185 | *disable_pipes = *modeset_pipes = *prepare_pipes = 0; |
| 7186 | |
| 7187 | /* Check which crtcs have changed outputs connected to them, these need |
| 7188 | * to be part of the prepare_pipes mask. We don't (yet) support global |
| 7189 | * modeset across multiple crtcs, so modeset_pipes will only have one |
| 7190 | * bit set at most. */ |
| 7191 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7192 | base.head) { |
| 7193 | if (connector->base.encoder == &connector->new_encoder->base) |
| 7194 | continue; |
| 7195 | |
| 7196 | if (connector->base.encoder) { |
| 7197 | tmp_crtc = connector->base.encoder->crtc; |
| 7198 | |
| 7199 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 7200 | } |
| 7201 | |
| 7202 | if (connector->new_encoder) |
| 7203 | *prepare_pipes |= |
| 7204 | 1 << connector->new_encoder->new_crtc->pipe; |
| 7205 | } |
| 7206 | |
| 7207 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7208 | base.head) { |
| 7209 | if (encoder->base.crtc == &encoder->new_crtc->base) |
| 7210 | continue; |
| 7211 | |
| 7212 | if (encoder->base.crtc) { |
| 7213 | tmp_crtc = encoder->base.crtc; |
| 7214 | |
| 7215 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 7216 | } |
| 7217 | |
| 7218 | if (encoder->new_crtc) |
| 7219 | *prepare_pipes |= 1 << encoder->new_crtc->pipe; |
| 7220 | } |
| 7221 | |
| 7222 | /* Check for any pipes that will be fully disabled ... */ |
| 7223 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 7224 | base.head) { |
| 7225 | bool used = false; |
| 7226 | |
| 7227 | /* Don't try to disable disabled crtcs. */ |
| 7228 | if (!intel_crtc->base.enabled) |
| 7229 | continue; |
| 7230 | |
| 7231 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7232 | base.head) { |
| 7233 | if (encoder->new_crtc == intel_crtc) |
| 7234 | used = true; |
| 7235 | } |
| 7236 | |
| 7237 | if (!used) |
| 7238 | *disable_pipes |= 1 << intel_crtc->pipe; |
| 7239 | } |
| 7240 | |
| 7241 | |
| 7242 | /* set_mode is also used to update properties on life display pipes. */ |
| 7243 | intel_crtc = to_intel_crtc(crtc); |
| 7244 | if (crtc->enabled) |
| 7245 | *prepare_pipes |= 1 << intel_crtc->pipe; |
| 7246 | |
| 7247 | /* We only support modeset on one single crtc, hence we need to do that |
| 7248 | * only for the passed in crtc iff we change anything else than just |
| 7249 | * disable crtcs. |
| 7250 | * |
| 7251 | * This is actually not true, to be fully compatible with the old crtc |
| 7252 | * helper we automatically disable _any_ output (i.e. doesn't need to be |
| 7253 | * connected to the crtc we're modesetting on) if it's disconnected. |
| 7254 | * Which is a rather nutty api (since changed the output configuration |
| 7255 | * without userspace's explicit request can lead to confusion), but |
| 7256 | * alas. Hence we currently need to modeset on all pipes we prepare. */ |
| 7257 | if (*prepare_pipes) |
| 7258 | *modeset_pipes = *prepare_pipes; |
| 7259 | |
| 7260 | /* ... and mask these out. */ |
| 7261 | *modeset_pipes &= ~(*disable_pipes); |
| 7262 | *prepare_pipes &= ~(*disable_pipes); |
| 7263 | } |
| 7264 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 7265 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
| 7266 | { |
| 7267 | struct drm_encoder *encoder; |
| 7268 | struct drm_device *dev = crtc->dev; |
| 7269 | |
| 7270 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 7271 | if (encoder->crtc == crtc) |
| 7272 | return true; |
| 7273 | |
| 7274 | return false; |
| 7275 | } |
| 7276 | |
| 7277 | static void |
| 7278 | intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes) |
| 7279 | { |
| 7280 | struct intel_encoder *intel_encoder; |
| 7281 | struct intel_crtc *intel_crtc; |
| 7282 | struct drm_connector *connector; |
| 7283 | |
| 7284 | list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list, |
| 7285 | base.head) { |
| 7286 | if (!intel_encoder->base.crtc) |
| 7287 | continue; |
| 7288 | |
| 7289 | intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
| 7290 | |
| 7291 | if (prepare_pipes & (1 << intel_crtc->pipe)) |
| 7292 | intel_encoder->connectors_active = false; |
| 7293 | } |
| 7294 | |
| 7295 | intel_modeset_commit_output_state(dev); |
| 7296 | |
| 7297 | /* Update computed state. */ |
| 7298 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 7299 | base.head) { |
| 7300 | intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base); |
| 7301 | } |
| 7302 | |
| 7303 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 7304 | if (!connector->encoder || !connector->encoder->crtc) |
| 7305 | continue; |
| 7306 | |
| 7307 | intel_crtc = to_intel_crtc(connector->encoder->crtc); |
| 7308 | |
| 7309 | if (prepare_pipes & (1 << intel_crtc->pipe)) { |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 7310 | struct drm_property *dpms_property = |
| 7311 | dev->mode_config.dpms_property; |
| 7312 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 7313 | connector->dpms = DRM_MODE_DPMS_ON; |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 7314 | drm_object_property_set_value(&connector->base, |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 7315 | dpms_property, |
| 7316 | DRM_MODE_DPMS_ON); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 7317 | |
| 7318 | intel_encoder = to_intel_encoder(connector->encoder); |
| 7319 | intel_encoder->connectors_active = true; |
| 7320 | } |
| 7321 | } |
| 7322 | |
| 7323 | } |
| 7324 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7325 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 7326 | list_for_each_entry((intel_crtc), \ |
| 7327 | &(dev)->mode_config.crtc_list, \ |
| 7328 | base.head) \ |
| 7329 | if (mask & (1 <<(intel_crtc)->pipe)) \ |
| 7330 | |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 7331 | void |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 7332 | intel_modeset_check_state(struct drm_device *dev) |
| 7333 | { |
| 7334 | struct intel_crtc *crtc; |
| 7335 | struct intel_encoder *encoder; |
| 7336 | struct intel_connector *connector; |
| 7337 | |
| 7338 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7339 | base.head) { |
| 7340 | /* This also checks the encoder/connector hw state with the |
| 7341 | * ->get_hw_state callbacks. */ |
| 7342 | intel_connector_check_state(connector); |
| 7343 | |
| 7344 | WARN(&connector->new_encoder->base != connector->base.encoder, |
| 7345 | "connector's staged encoder doesn't match current encoder\n"); |
| 7346 | } |
| 7347 | |
| 7348 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7349 | base.head) { |
| 7350 | bool enabled = false; |
| 7351 | bool active = false; |
| 7352 | enum pipe pipe, tracked_pipe; |
| 7353 | |
| 7354 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 7355 | encoder->base.base.id, |
| 7356 | drm_get_encoder_name(&encoder->base)); |
| 7357 | |
| 7358 | WARN(&encoder->new_crtc->base != encoder->base.crtc, |
| 7359 | "encoder's stage crtc doesn't match current crtc\n"); |
| 7360 | WARN(encoder->connectors_active && !encoder->base.crtc, |
| 7361 | "encoder's active_connectors set, but no crtc\n"); |
| 7362 | |
| 7363 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7364 | base.head) { |
| 7365 | if (connector->base.encoder != &encoder->base) |
| 7366 | continue; |
| 7367 | enabled = true; |
| 7368 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) |
| 7369 | active = true; |
| 7370 | } |
| 7371 | WARN(!!encoder->base.crtc != enabled, |
| 7372 | "encoder's enabled state mismatch " |
| 7373 | "(expected %i, found %i)\n", |
| 7374 | !!encoder->base.crtc, enabled); |
| 7375 | WARN(active && !encoder->base.crtc, |
| 7376 | "active encoder with no crtc\n"); |
| 7377 | |
| 7378 | WARN(encoder->connectors_active != active, |
| 7379 | "encoder's computed active state doesn't match tracked active state " |
| 7380 | "(expected %i, found %i)\n", active, encoder->connectors_active); |
| 7381 | |
| 7382 | active = encoder->get_hw_state(encoder, &pipe); |
| 7383 | WARN(active != encoder->connectors_active, |
| 7384 | "encoder's hw state doesn't match sw tracking " |
| 7385 | "(expected %i, found %i)\n", |
| 7386 | encoder->connectors_active, active); |
| 7387 | |
| 7388 | if (!encoder->base.crtc) |
| 7389 | continue; |
| 7390 | |
| 7391 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; |
| 7392 | WARN(active && pipe != tracked_pipe, |
| 7393 | "active encoder's pipe doesn't match" |
| 7394 | "(expected %i, found %i)\n", |
| 7395 | tracked_pipe, pipe); |
| 7396 | |
| 7397 | } |
| 7398 | |
| 7399 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, |
| 7400 | base.head) { |
| 7401 | bool enabled = false; |
| 7402 | bool active = false; |
| 7403 | |
| 7404 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 7405 | crtc->base.base.id); |
| 7406 | |
| 7407 | WARN(crtc->active && !crtc->base.enabled, |
| 7408 | "active crtc, but not enabled in sw tracking\n"); |
| 7409 | |
| 7410 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7411 | base.head) { |
| 7412 | if (encoder->base.crtc != &crtc->base) |
| 7413 | continue; |
| 7414 | enabled = true; |
| 7415 | if (encoder->connectors_active) |
| 7416 | active = true; |
| 7417 | } |
| 7418 | WARN(active != crtc->active, |
| 7419 | "crtc's computed active state doesn't match tracked active state " |
| 7420 | "(expected %i, found %i)\n", active, crtc->active); |
| 7421 | WARN(enabled != crtc->base.enabled, |
| 7422 | "crtc's computed enabled state doesn't match tracked enabled state " |
| 7423 | "(expected %i, found %i)\n", enabled, crtc->base.enabled); |
| 7424 | |
| 7425 | assert_pipe(dev->dev_private, crtc->pipe, crtc->active); |
| 7426 | } |
| 7427 | } |
| 7428 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 7429 | int intel_set_mode(struct drm_crtc *crtc, |
| 7430 | struct drm_display_mode *mode, |
| 7431 | int x, int y, struct drm_framebuffer *fb) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7432 | { |
| 7433 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | dbf2b54e | 2012-07-02 11:18:29 +0200 | [diff] [blame] | 7434 | drm_i915_private_t *dev_priv = dev->dev_private; |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 7435 | struct drm_display_mode *adjusted_mode, *saved_mode, *saved_hwmode; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7436 | struct intel_crtc *intel_crtc; |
| 7437 | unsigned disable_pipes, prepare_pipes, modeset_pipes; |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 7438 | int ret = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7439 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 7440 | saved_mode = kmalloc(2 * sizeof(*saved_mode), GFP_KERNEL); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 7441 | if (!saved_mode) |
| 7442 | return -ENOMEM; |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 7443 | saved_hwmode = saved_mode + 1; |
| 7444 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 7445 | intel_modeset_affected_pipes(crtc, &modeset_pipes, |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7446 | &prepare_pipes, &disable_pipes); |
| 7447 | |
| 7448 | DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n", |
| 7449 | modeset_pipes, prepare_pipes, disable_pipes); |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 7450 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 7451 | for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc) |
| 7452 | intel_crtc_disable(&intel_crtc->base); |
| 7453 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 7454 | *saved_hwmode = crtc->hwmode; |
| 7455 | *saved_mode = crtc->mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7456 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7457 | /* Hack: Because we don't (yet) support global modeset on multiple |
| 7458 | * crtcs, we don't keep track of the new mode for more than one crtc. |
| 7459 | * Hence simply check whether any bit is set in modeset_pipes in all the |
| 7460 | * pieces of code that are not yet converted to deal with mutliple crtcs |
| 7461 | * changing their mode at the same time. */ |
| 7462 | adjusted_mode = NULL; |
| 7463 | if (modeset_pipes) { |
| 7464 | adjusted_mode = intel_modeset_adjusted_mode(crtc, mode); |
| 7465 | if (IS_ERR(adjusted_mode)) { |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 7466 | ret = PTR_ERR(adjusted_mode); |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 7467 | goto out; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7468 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7469 | } |
| 7470 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 7471 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
| 7472 | if (intel_crtc->base.enabled) |
| 7473 | dev_priv->display.crtc_disable(&intel_crtc->base); |
| 7474 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7475 | |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 7476 | /* crtc->mode is already used by the ->mode_set callbacks, hence we need |
| 7477 | * to set it here already despite that we pass it down the callchain. |
| 7478 | */ |
| 7479 | if (modeset_pipes) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7480 | crtc->mode = *mode; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7481 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 7482 | /* Only after disabling all output pipelines that will be changed can we |
| 7483 | * update the the output configuration. */ |
| 7484 | intel_modeset_update_state(dev, prepare_pipes); |
| 7485 | |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 7486 | if (dev_priv->display.modeset_global_resources) |
| 7487 | dev_priv->display.modeset_global_resources(dev); |
| 7488 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7489 | /* Set up the DPLL and any encoders state that needs to adjust or depend |
| 7490 | * on the DPLL. |
| 7491 | */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7492 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 7493 | ret = intel_crtc_mode_set(&intel_crtc->base, |
| 7494 | mode, adjusted_mode, |
| 7495 | x, y, fb); |
| 7496 | if (ret) |
| 7497 | goto done; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7498 | } |
| 7499 | |
| 7500 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7501 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) |
| 7502 | dev_priv->display.crtc_enable(&intel_crtc->base); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7503 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7504 | if (modeset_pipes) { |
| 7505 | /* Store real post-adjustment hardware mode. */ |
| 7506 | crtc->hwmode = *adjusted_mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7507 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7508 | /* Calculate and store various constants which |
| 7509 | * are later needed by vblank and swap-completion |
| 7510 | * timestamping. They are derived from true hwmode. |
| 7511 | */ |
| 7512 | drm_calc_timestamping_constants(crtc); |
| 7513 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7514 | |
| 7515 | /* FIXME: add subpixel order */ |
| 7516 | done: |
| 7517 | drm_mode_destroy(dev, adjusted_mode); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 7518 | if (ret && crtc->enabled) { |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 7519 | crtc->hwmode = *saved_hwmode; |
| 7520 | crtc->mode = *saved_mode; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 7521 | } else { |
| 7522 | intel_modeset_check_state(dev); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7523 | } |
| 7524 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 7525 | out: |
| 7526 | kfree(saved_mode); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 7527 | return ret; |
| 7528 | } |
| 7529 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 7530 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 7531 | { |
| 7532 | intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb); |
| 7533 | } |
| 7534 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 7535 | #undef for_each_intel_crtc_masked |
| 7536 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 7537 | static void intel_set_config_free(struct intel_set_config *config) |
| 7538 | { |
| 7539 | if (!config) |
| 7540 | return; |
| 7541 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 7542 | kfree(config->save_connector_encoders); |
| 7543 | kfree(config->save_encoder_crtcs); |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 7544 | kfree(config); |
| 7545 | } |
| 7546 | |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7547 | static int intel_set_config_save_state(struct drm_device *dev, |
| 7548 | struct intel_set_config *config) |
| 7549 | { |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7550 | struct drm_encoder *encoder; |
| 7551 | struct drm_connector *connector; |
| 7552 | int count; |
| 7553 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 7554 | config->save_encoder_crtcs = |
| 7555 | kcalloc(dev->mode_config.num_encoder, |
| 7556 | sizeof(struct drm_crtc *), GFP_KERNEL); |
| 7557 | if (!config->save_encoder_crtcs) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7558 | return -ENOMEM; |
| 7559 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 7560 | config->save_connector_encoders = |
| 7561 | kcalloc(dev->mode_config.num_connector, |
| 7562 | sizeof(struct drm_encoder *), GFP_KERNEL); |
| 7563 | if (!config->save_connector_encoders) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7564 | return -ENOMEM; |
| 7565 | |
| 7566 | /* Copy data. Note that driver private data is not affected. |
| 7567 | * Should anything bad happen only the expected state is |
| 7568 | * restored, not the drivers personal bookkeeping. |
| 7569 | */ |
| 7570 | count = 0; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7571 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 7572 | config->save_encoder_crtcs[count++] = encoder->crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7573 | } |
| 7574 | |
| 7575 | count = 0; |
| 7576 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 7577 | config->save_connector_encoders[count++] = connector->encoder; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7578 | } |
| 7579 | |
| 7580 | return 0; |
| 7581 | } |
| 7582 | |
| 7583 | static void intel_set_config_restore_state(struct drm_device *dev, |
| 7584 | struct intel_set_config *config) |
| 7585 | { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7586 | struct intel_encoder *encoder; |
| 7587 | struct intel_connector *connector; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7588 | int count; |
| 7589 | |
| 7590 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7591 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) { |
| 7592 | encoder->new_crtc = |
| 7593 | to_intel_crtc(config->save_encoder_crtcs[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7594 | } |
| 7595 | |
| 7596 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7597 | list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) { |
| 7598 | connector->new_encoder = |
| 7599 | to_intel_encoder(config->save_connector_encoders[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7600 | } |
| 7601 | } |
| 7602 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 7603 | static void |
| 7604 | intel_set_config_compute_mode_changes(struct drm_mode_set *set, |
| 7605 | struct intel_set_config *config) |
| 7606 | { |
| 7607 | |
| 7608 | /* We should be able to check here if the fb has the same properties |
| 7609 | * and then just flip_or_move it */ |
| 7610 | if (set->crtc->fb != set->fb) { |
| 7611 | /* If we have no fb then treat it as a full mode set */ |
| 7612 | if (set->crtc->fb == NULL) { |
| 7613 | DRM_DEBUG_KMS("crtc has no fb, full mode set\n"); |
| 7614 | config->mode_changed = true; |
| 7615 | } else if (set->fb == NULL) { |
| 7616 | config->mode_changed = true; |
| 7617 | } else if (set->fb->depth != set->crtc->fb->depth) { |
| 7618 | config->mode_changed = true; |
| 7619 | } else if (set->fb->bits_per_pixel != |
| 7620 | set->crtc->fb->bits_per_pixel) { |
| 7621 | config->mode_changed = true; |
| 7622 | } else |
| 7623 | config->fb_changed = true; |
| 7624 | } |
| 7625 | |
Daniel Vetter | 835c587 | 2012-07-10 18:11:08 +0200 | [diff] [blame] | 7626 | if (set->fb && (set->x != set->crtc->x || set->y != set->crtc->y)) |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 7627 | config->fb_changed = true; |
| 7628 | |
| 7629 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
| 7630 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
| 7631 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 7632 | drm_mode_debug_printmodeline(set->mode); |
| 7633 | config->mode_changed = true; |
| 7634 | } |
| 7635 | } |
| 7636 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 7637 | static int |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7638 | intel_modeset_stage_output_state(struct drm_device *dev, |
| 7639 | struct drm_mode_set *set, |
| 7640 | struct intel_set_config *config) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7641 | { |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7642 | struct drm_crtc *new_crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7643 | struct intel_connector *connector; |
| 7644 | struct intel_encoder *encoder; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 7645 | int count, ro; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7646 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7647 | /* The upper layers ensure that we either disabl a crtc or have a list |
| 7648 | * of connectors. For paranoia, double-check this. */ |
| 7649 | WARN_ON(!set->fb && (set->num_connectors != 0)); |
| 7650 | WARN_ON(set->fb && (set->num_connectors == 0)); |
| 7651 | |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7652 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7653 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7654 | base.head) { |
| 7655 | /* Otherwise traverse passed in connector list and get encoders |
| 7656 | * for them. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7657 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7658 | if (set->connectors[ro] == &connector->base) { |
| 7659 | connector->new_encoder = connector->encoder; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7660 | break; |
| 7661 | } |
| 7662 | } |
| 7663 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7664 | /* If we disable the crtc, disable all its connectors. Also, if |
| 7665 | * the connector is on the changing crtc but not on the new |
| 7666 | * connector list, disable it. */ |
| 7667 | if ((!set->fb || ro == set->num_connectors) && |
| 7668 | connector->base.encoder && |
| 7669 | connector->base.encoder->crtc == set->crtc) { |
| 7670 | connector->new_encoder = NULL; |
| 7671 | |
| 7672 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", |
| 7673 | connector->base.base.id, |
| 7674 | drm_get_connector_name(&connector->base)); |
| 7675 | } |
| 7676 | |
| 7677 | |
| 7678 | if (&connector->new_encoder->base != connector->base.encoder) { |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7679 | DRM_DEBUG_KMS("encoder changed, full mode switch\n"); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 7680 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7681 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7682 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7683 | /* Disable all disconnected encoders. */ |
| 7684 | if (connector->base.status == connector_status_disconnected) |
| 7685 | connector->new_encoder = NULL; |
| 7686 | } |
| 7687 | /* connector->new_encoder is now updated for all connectors. */ |
| 7688 | |
| 7689 | /* Update crtc of enabled connectors. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7690 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7691 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7692 | base.head) { |
| 7693 | if (!connector->new_encoder) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7694 | continue; |
| 7695 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7696 | new_crtc = connector->new_encoder->base.crtc; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7697 | |
| 7698 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7699 | if (set->connectors[ro] == &connector->base) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7700 | new_crtc = set->crtc; |
| 7701 | } |
| 7702 | |
| 7703 | /* Make sure the new CRTC will work with the encoder */ |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7704 | if (!intel_encoder_crtc_ok(&connector->new_encoder->base, |
| 7705 | new_crtc)) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 7706 | return -EINVAL; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7707 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7708 | connector->encoder->new_crtc = to_intel_crtc(new_crtc); |
| 7709 | |
| 7710 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
| 7711 | connector->base.base.id, |
| 7712 | drm_get_connector_name(&connector->base), |
| 7713 | new_crtc->base.id); |
| 7714 | } |
| 7715 | |
| 7716 | /* Check for any encoders that needs to be disabled. */ |
| 7717 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7718 | base.head) { |
| 7719 | list_for_each_entry(connector, |
| 7720 | &dev->mode_config.connector_list, |
| 7721 | base.head) { |
| 7722 | if (connector->new_encoder == encoder) { |
| 7723 | WARN_ON(!connector->new_encoder->new_crtc); |
| 7724 | |
| 7725 | goto next_encoder; |
| 7726 | } |
| 7727 | } |
| 7728 | encoder->new_crtc = NULL; |
| 7729 | next_encoder: |
| 7730 | /* Only now check for crtc changes so we don't miss encoders |
| 7731 | * that will be disabled. */ |
| 7732 | if (&encoder->new_crtc->base != encoder->base.crtc) { |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7733 | DRM_DEBUG_KMS("crtc changed, full mode switch\n"); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 7734 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7735 | } |
| 7736 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7737 | /* Now we've also updated encoder->new_crtc for all encoders. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7738 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 7739 | return 0; |
| 7740 | } |
| 7741 | |
| 7742 | static int intel_crtc_set_config(struct drm_mode_set *set) |
| 7743 | { |
| 7744 | struct drm_device *dev; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 7745 | struct drm_mode_set save_set; |
| 7746 | struct intel_set_config *config; |
| 7747 | int ret; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 7748 | |
Daniel Vetter | 8d3e375 | 2012-07-05 16:09:09 +0200 | [diff] [blame] | 7749 | BUG_ON(!set); |
| 7750 | BUG_ON(!set->crtc); |
| 7751 | BUG_ON(!set->crtc->helper_private); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 7752 | |
| 7753 | if (!set->mode) |
| 7754 | set->fb = NULL; |
| 7755 | |
Daniel Vetter | 431e50f | 2012-07-10 17:53:42 +0200 | [diff] [blame] | 7756 | /* The fb helper likes to play gross jokes with ->mode_set_config. |
| 7757 | * Unfortunately the crtc helper doesn't do much at all for this case, |
| 7758 | * so we have to cope with this madness until the fb helper is fixed up. */ |
| 7759 | if (set->fb && set->num_connectors == 0) |
| 7760 | return 0; |
| 7761 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 7762 | if (set->fb) { |
| 7763 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", |
| 7764 | set->crtc->base.id, set->fb->base.id, |
| 7765 | (int)set->num_connectors, set->x, set->y); |
| 7766 | } else { |
| 7767 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 7768 | } |
| 7769 | |
| 7770 | dev = set->crtc->dev; |
| 7771 | |
| 7772 | ret = -ENOMEM; |
| 7773 | config = kzalloc(sizeof(*config), GFP_KERNEL); |
| 7774 | if (!config) |
| 7775 | goto out_config; |
| 7776 | |
| 7777 | ret = intel_set_config_save_state(dev, config); |
| 7778 | if (ret) |
| 7779 | goto out_config; |
| 7780 | |
| 7781 | save_set.crtc = set->crtc; |
| 7782 | save_set.mode = &set->crtc->mode; |
| 7783 | save_set.x = set->crtc->x; |
| 7784 | save_set.y = set->crtc->y; |
| 7785 | save_set.fb = set->crtc->fb; |
| 7786 | |
| 7787 | /* Compute whether we need a full modeset, only an fb base update or no |
| 7788 | * change at all. In the future we might also check whether only the |
| 7789 | * mode changed, e.g. for LVDS where we only change the panel fitter in |
| 7790 | * such cases. */ |
| 7791 | intel_set_config_compute_mode_changes(set, config); |
| 7792 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7793 | ret = intel_modeset_stage_output_state(dev, set, config); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 7794 | if (ret) |
| 7795 | goto fail; |
| 7796 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 7797 | if (config->mode_changed) { |
Daniel Vetter | 87f1faa | 2012-07-05 23:36:17 +0200 | [diff] [blame] | 7798 | if (set->mode) { |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7799 | DRM_DEBUG_KMS("attempting to set mode from" |
| 7800 | " userspace\n"); |
| 7801 | drm_mode_debug_printmodeline(set->mode); |
Daniel Vetter | 87f1faa | 2012-07-05 23:36:17 +0200 | [diff] [blame] | 7802 | } |
| 7803 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 7804 | ret = intel_set_mode(set->crtc, set->mode, |
| 7805 | set->x, set->y, set->fb); |
| 7806 | if (ret) { |
| 7807 | DRM_ERROR("failed to set mode on [CRTC:%d], err = %d\n", |
| 7808 | set->crtc->base.id, ret); |
Daniel Vetter | 87f1faa | 2012-07-05 23:36:17 +0200 | [diff] [blame] | 7809 | goto fail; |
| 7810 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 7811 | } else if (config->fb_changed) { |
Daniel Vetter | 4f660f4 | 2012-07-02 09:47:37 +0200 | [diff] [blame] | 7812 | ret = intel_pipe_set_base(set->crtc, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 7813 | set->x, set->y, set->fb); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7814 | } |
| 7815 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 7816 | intel_set_config_free(config); |
| 7817 | |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7818 | return 0; |
| 7819 | |
| 7820 | fail: |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 7821 | intel_set_config_restore_state(dev, config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7822 | |
| 7823 | /* Try to restore the config */ |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 7824 | if (config->mode_changed && |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 7825 | intel_set_mode(save_set.crtc, save_set.mode, |
| 7826 | save_set.x, save_set.y, save_set.fb)) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7827 | DRM_ERROR("failed to restore config after modeset failure\n"); |
| 7828 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 7829 | out_config: |
| 7830 | intel_set_config_free(config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7831 | return ret; |
| 7832 | } |
| 7833 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 7834 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 7835 | .cursor_set = intel_crtc_cursor_set, |
| 7836 | .cursor_move = intel_crtc_cursor_move, |
| 7837 | .gamma_set = intel_crtc_gamma_set, |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7838 | .set_config = intel_crtc_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 7839 | .destroy = intel_crtc_destroy, |
| 7840 | .page_flip = intel_crtc_page_flip, |
| 7841 | }; |
| 7842 | |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 7843 | static void intel_cpu_pll_init(struct drm_device *dev) |
| 7844 | { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 7845 | if (HAS_DDI(dev)) |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 7846 | intel_ddi_pll_init(dev); |
| 7847 | } |
| 7848 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 7849 | static void intel_pch_pll_init(struct drm_device *dev) |
| 7850 | { |
| 7851 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 7852 | int i; |
| 7853 | |
| 7854 | if (dev_priv->num_pch_pll == 0) { |
| 7855 | DRM_DEBUG_KMS("No PCH PLLs on this hardware, skipping initialisation\n"); |
| 7856 | return; |
| 7857 | } |
| 7858 | |
| 7859 | for (i = 0; i < dev_priv->num_pch_pll; i++) { |
| 7860 | dev_priv->pch_plls[i].pll_reg = _PCH_DPLL(i); |
| 7861 | dev_priv->pch_plls[i].fp0_reg = _PCH_FP0(i); |
| 7862 | dev_priv->pch_plls[i].fp1_reg = _PCH_FP1(i); |
| 7863 | } |
| 7864 | } |
| 7865 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 7866 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7867 | { |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 7868 | drm_i915_private_t *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7869 | struct intel_crtc *intel_crtc; |
| 7870 | int i; |
| 7871 | |
| 7872 | intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
| 7873 | if (intel_crtc == NULL) |
| 7874 | return; |
| 7875 | |
| 7876 | drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs); |
| 7877 | |
| 7878 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7879 | for (i = 0; i < 256; i++) { |
| 7880 | intel_crtc->lut_r[i] = i; |
| 7881 | intel_crtc->lut_g[i] = i; |
| 7882 | intel_crtc->lut_b[i] = i; |
| 7883 | } |
| 7884 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 7885 | /* Swap pipes & planes for FBC on pre-965 */ |
| 7886 | intel_crtc->pipe = pipe; |
| 7887 | intel_crtc->plane = pipe; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 7888 | intel_crtc->cpu_transcoder = pipe; |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 7889 | if (IS_MOBILE(dev) && IS_GEN3(dev)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 7890 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 7891 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 7892 | } |
| 7893 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 7894 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 7895 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 7896 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 7897 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 7898 | |
Jesse Barnes | 5a35420 | 2011-06-24 12:19:22 -0700 | [diff] [blame] | 7899 | intel_crtc->bpp = 24; /* default for pre-Ironlake */ |
Jesse Barnes | 7e7d76c | 2010-09-10 10:47:20 -0700 | [diff] [blame] | 7900 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7901 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7902 | } |
| 7903 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 7904 | int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 7905 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 7906 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 7907 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 7908 | struct drm_mode_object *drmmode_obj; |
| 7909 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 7910 | |
Daniel Vetter | 1cff8f6 | 2012-04-24 09:55:08 +0200 | [diff] [blame] | 7911 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 7912 | return -ENODEV; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 7913 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 7914 | drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id, |
| 7915 | DRM_MODE_OBJECT_CRTC); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 7916 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 7917 | if (!drmmode_obj) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 7918 | DRM_ERROR("no such CRTC id\n"); |
| 7919 | return -EINVAL; |
| 7920 | } |
| 7921 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 7922 | crtc = to_intel_crtc(obj_to_crtc(drmmode_obj)); |
| 7923 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 7924 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 7925 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 7926 | } |
| 7927 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 7928 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7929 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 7930 | struct drm_device *dev = encoder->base.dev; |
| 7931 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7932 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7933 | int entry = 0; |
| 7934 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 7935 | list_for_each_entry(source_encoder, |
| 7936 | &dev->mode_config.encoder_list, base.head) { |
| 7937 | |
| 7938 | if (encoder == source_encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7939 | index_mask |= (1 << entry); |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 7940 | |
| 7941 | /* Intel hw has only one MUX where enocoders could be cloned. */ |
| 7942 | if (encoder->cloneable && source_encoder->cloneable) |
| 7943 | index_mask |= (1 << entry); |
| 7944 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7945 | entry++; |
| 7946 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 7947 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7948 | return index_mask; |
| 7949 | } |
| 7950 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 7951 | static bool has_edp_a(struct drm_device *dev) |
| 7952 | { |
| 7953 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7954 | |
| 7955 | if (!IS_MOBILE(dev)) |
| 7956 | return false; |
| 7957 | |
| 7958 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 7959 | return false; |
| 7960 | |
| 7961 | if (IS_GEN5(dev) && |
| 7962 | (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE)) |
| 7963 | return false; |
| 7964 | |
| 7965 | return true; |
| 7966 | } |
| 7967 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7968 | static void intel_setup_outputs(struct drm_device *dev) |
| 7969 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 7970 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 7971 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 7972 | bool dpd_is_edp = false; |
Chris Wilson | f3cfcba | 2012-02-09 09:35:53 +0000 | [diff] [blame] | 7973 | bool has_lvds; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7974 | |
Chris Wilson | f3cfcba | 2012-02-09 09:35:53 +0000 | [diff] [blame] | 7975 | has_lvds = intel_lvds_init(dev); |
Chris Wilson | c5d1b51 | 2010-11-29 18:00:23 +0000 | [diff] [blame] | 7976 | if (!has_lvds && !HAS_PCH_SPLIT(dev)) { |
| 7977 | /* disable the panel fitter on everything but LVDS */ |
| 7978 | I915_WRITE(PFIT_CONTROL, 0); |
| 7979 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7980 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 7981 | if (!(HAS_DDI(dev) && (I915_READ(DDI_BUF_CTL(PORT_A)) & DDI_A_4_LANES))) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 7982 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 7983 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 7984 | if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 7985 | int found; |
| 7986 | |
| 7987 | /* Haswell uses DDI functions to detect digital outputs */ |
| 7988 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
| 7989 | /* DDI A only supports eDP */ |
| 7990 | if (found) |
| 7991 | intel_ddi_init(dev, PORT_A); |
| 7992 | |
| 7993 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 7994 | * register */ |
| 7995 | found = I915_READ(SFUSE_STRAP); |
| 7996 | |
| 7997 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 7998 | intel_ddi_init(dev, PORT_B); |
| 7999 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 8000 | intel_ddi_init(dev, PORT_C); |
| 8001 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 8002 | intel_ddi_init(dev, PORT_D); |
| 8003 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 8004 | int found; |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 8005 | dpd_is_edp = intel_dpd_is_edp(dev); |
| 8006 | |
| 8007 | if (has_edp_a(dev)) |
| 8008 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 8009 | |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 8010 | if (I915_READ(HDMIB) & PORT_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 8011 | /* PCH SDVOB multiplex with HDMIB */ |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 8012 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 8013 | if (!found) |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 8014 | intel_hdmi_init(dev, HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 8015 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 8016 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 8017 | } |
| 8018 | |
| 8019 | if (I915_READ(HDMIC) & PORT_DETECTED) |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 8020 | intel_hdmi_init(dev, HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 8021 | |
Jesse Barnes | b708a1d | 2012-06-11 14:39:56 -0400 | [diff] [blame] | 8022 | if (!dpd_is_edp && I915_READ(HDMID) & PORT_DETECTED) |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 8023 | intel_hdmi_init(dev, HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 8024 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 8025 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 8026 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 8027 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 8028 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 8029 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 8030 | } else if (IS_VALLEYVIEW(dev)) { |
| 8031 | int found; |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 8032 | |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 8033 | /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */ |
| 8034 | if (I915_READ(DP_C) & DP_DETECTED) |
| 8035 | intel_dp_init(dev, DP_C, PORT_C); |
| 8036 | |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 8037 | if (I915_READ(SDVOB) & PORT_DETECTED) { |
| 8038 | /* SDVOB multiplex with HDMIB */ |
| 8039 | found = intel_sdvo_init(dev, SDVOB, true); |
| 8040 | if (!found) |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 8041 | intel_hdmi_init(dev, SDVOB, PORT_B); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 8042 | if (!found && (I915_READ(DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 8043 | intel_dp_init(dev, DP_B, PORT_B); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 8044 | } |
| 8045 | |
| 8046 | if (I915_READ(SDVOC) & PORT_DETECTED) |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 8047 | intel_hdmi_init(dev, SDVOC, PORT_C); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 8048 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 8049 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 8050 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 8051 | |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 8052 | if (I915_READ(SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8053 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 8054 | found = intel_sdvo_init(dev, SDVOB, true); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8055 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 8056 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 8057 | intel_hdmi_init(dev, SDVOB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8058 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 8059 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8060 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) { |
| 8061 | DRM_DEBUG_KMS("probing DP_B\n"); |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 8062 | intel_dp_init(dev, DP_B, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8063 | } |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 8064 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 8065 | |
| 8066 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 8067 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8068 | if (I915_READ(SDVOB) & SDVO_DETECTED) { |
| 8069 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 8070 | found = intel_sdvo_init(dev, SDVOC, false); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8071 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 8072 | |
| 8073 | if (!found && (I915_READ(SDVOC) & SDVO_DETECTED)) { |
| 8074 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8075 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 8076 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Daniel Vetter | 08d644a | 2012-07-12 20:19:59 +0200 | [diff] [blame] | 8077 | intel_hdmi_init(dev, SDVOC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8078 | } |
| 8079 | if (SUPPORTS_INTEGRATED_DP(dev)) { |
| 8080 | DRM_DEBUG_KMS("probing DP_C\n"); |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 8081 | intel_dp_init(dev, DP_C, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8082 | } |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 8083 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 8084 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8085 | if (SUPPORTS_INTEGRATED_DP(dev) && |
| 8086 | (I915_READ(DP_D) & DP_DETECTED)) { |
| 8087 | DRM_DEBUG_KMS("probing DP_D\n"); |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 8088 | intel_dp_init(dev, DP_D, PORT_D); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 8089 | } |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 8090 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8091 | intel_dvo_init(dev); |
| 8092 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 8093 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8094 | intel_tv_init(dev); |
| 8095 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 8096 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) { |
| 8097 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 8098 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 8099 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8100 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 8101 | |
Paulo Zanoni | 40579ab | 2012-07-03 15:57:33 -0300 | [diff] [blame] | 8102 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Keith Packard | 9fb526d | 2011-09-26 22:24:57 -0700 | [diff] [blame] | 8103 | ironlake_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 8104 | |
| 8105 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8106 | } |
| 8107 | |
| 8108 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 8109 | { |
| 8110 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8111 | |
| 8112 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8113 | drm_gem_object_unreference_unlocked(&intel_fb->obj->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8114 | |
| 8115 | kfree(intel_fb); |
| 8116 | } |
| 8117 | |
| 8118 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8119 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8120 | unsigned int *handle) |
| 8121 | { |
| 8122 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8123 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8124 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8125 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8126 | } |
| 8127 | |
| 8128 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 8129 | .destroy = intel_user_framebuffer_destroy, |
| 8130 | .create_handle = intel_user_framebuffer_create_handle, |
| 8131 | }; |
| 8132 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 8133 | int intel_framebuffer_init(struct drm_device *dev, |
| 8134 | struct intel_framebuffer *intel_fb, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 8135 | struct drm_mode_fb_cmd2 *mode_cmd, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8136 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8137 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8138 | int ret; |
| 8139 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8140 | if (obj->tiling_mode == I915_TILING_Y) |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 8141 | return -EINVAL; |
| 8142 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 8143 | if (mode_cmd->pitches[0] & 63) |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 8144 | return -EINVAL; |
| 8145 | |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 8146 | /* FIXME <= Gen4 stride limits are bit unclear */ |
| 8147 | if (mode_cmd->pitches[0] > 32768) |
| 8148 | return -EINVAL; |
| 8149 | |
| 8150 | if (obj->tiling_mode != I915_TILING_NONE && |
| 8151 | mode_cmd->pitches[0] != obj->stride) |
| 8152 | return -EINVAL; |
| 8153 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 8154 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 8155 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 8156 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 8157 | case DRM_FORMAT_RGB565: |
| 8158 | case DRM_FORMAT_XRGB8888: |
| 8159 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 8160 | break; |
| 8161 | case DRM_FORMAT_XRGB1555: |
| 8162 | case DRM_FORMAT_ARGB1555: |
| 8163 | if (INTEL_INFO(dev)->gen > 3) |
| 8164 | return -EINVAL; |
| 8165 | break; |
| 8166 | case DRM_FORMAT_XBGR8888: |
| 8167 | case DRM_FORMAT_ABGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 8168 | case DRM_FORMAT_XRGB2101010: |
| 8169 | case DRM_FORMAT_ARGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 8170 | case DRM_FORMAT_XBGR2101010: |
| 8171 | case DRM_FORMAT_ABGR2101010: |
| 8172 | if (INTEL_INFO(dev)->gen < 4) |
| 8173 | return -EINVAL; |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 8174 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 8175 | case DRM_FORMAT_YUYV: |
| 8176 | case DRM_FORMAT_UYVY: |
| 8177 | case DRM_FORMAT_YVYU: |
| 8178 | case DRM_FORMAT_VYUY: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 8179 | if (INTEL_INFO(dev)->gen < 6) |
| 8180 | return -EINVAL; |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 8181 | break; |
| 8182 | default: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 8183 | DRM_DEBUG_KMS("unsupported pixel format 0x%08x\n", mode_cmd->pixel_format); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 8184 | return -EINVAL; |
| 8185 | } |
| 8186 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 8187 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 8188 | if (mode_cmd->offsets[0] != 0) |
| 8189 | return -EINVAL; |
| 8190 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8191 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 8192 | if (ret) { |
| 8193 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 8194 | return ret; |
| 8195 | } |
| 8196 | |
| 8197 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8198 | intel_fb->obj = obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8199 | return 0; |
| 8200 | } |
| 8201 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8202 | static struct drm_framebuffer * |
| 8203 | intel_user_framebuffer_create(struct drm_device *dev, |
| 8204 | struct drm_file *filp, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 8205 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8206 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8207 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8208 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 8209 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
| 8210 | mode_cmd->handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 8211 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 8212 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8213 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8214 | return intel_framebuffer_create(dev, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8215 | } |
| 8216 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8217 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8218 | .fb_create = intel_user_framebuffer_create, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 8219 | .output_poll_changed = intel_fb_output_poll_changed, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8220 | }; |
| 8221 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8222 | /* Set up chip specific display functions */ |
| 8223 | static void intel_init_display(struct drm_device *dev) |
| 8224 | { |
| 8225 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8226 | |
| 8227 | /* We always want a DPMS function */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 8228 | if (HAS_DDI(dev)) { |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 8229 | dev_priv->display.crtc_mode_set = haswell_crtc_mode_set; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 8230 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 8231 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 8232 | dev_priv->display.off = haswell_crtc_off; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 8233 | dev_priv->display.update_plane = ironlake_update_plane; |
| 8234 | } else if (HAS_PCH_SPLIT(dev)) { |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8235 | dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 8236 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 8237 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8238 | dev_priv->display.off = ironlake_crtc_off; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 8239 | dev_priv->display.update_plane = ironlake_update_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8240 | } else { |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8241 | dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 8242 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 8243 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8244 | dev_priv->display.off = i9xx_crtc_off; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 8245 | dev_priv->display.update_plane = i9xx_update_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 8246 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8247 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8248 | /* Returns the core display clock speed */ |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 8249 | if (IS_VALLEYVIEW(dev)) |
| 8250 | dev_priv->display.get_display_clock_speed = |
| 8251 | valleyview_get_display_clock_speed; |
| 8252 | else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev))) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8253 | dev_priv->display.get_display_clock_speed = |
| 8254 | i945_get_display_clock_speed; |
| 8255 | else if (IS_I915G(dev)) |
| 8256 | dev_priv->display.get_display_clock_speed = |
| 8257 | i915_get_display_clock_speed; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 8258 | else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8259 | dev_priv->display.get_display_clock_speed = |
| 8260 | i9xx_misc_get_display_clock_speed; |
| 8261 | else if (IS_I915GM(dev)) |
| 8262 | dev_priv->display.get_display_clock_speed = |
| 8263 | i915gm_get_display_clock_speed; |
| 8264 | else if (IS_I865G(dev)) |
| 8265 | dev_priv->display.get_display_clock_speed = |
| 8266 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 8267 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8268 | dev_priv->display.get_display_clock_speed = |
| 8269 | i855_get_display_clock_speed; |
| 8270 | else /* 852, 830 */ |
| 8271 | dev_priv->display.get_display_clock_speed = |
| 8272 | i830_get_display_clock_speed; |
| 8273 | |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 8274 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 8275 | if (IS_GEN5(dev)) { |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 8276 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8277 | dev_priv->display.write_eld = ironlake_write_eld; |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 8278 | } else if (IS_GEN6(dev)) { |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 8279 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8280 | dev_priv->display.write_eld = ironlake_write_eld; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 8281 | } else if (IS_IVYBRIDGE(dev)) { |
| 8282 | /* FIXME: detect B0+ stepping and use auto training */ |
| 8283 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8284 | dev_priv->display.write_eld = ironlake_write_eld; |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 8285 | dev_priv->display.modeset_global_resources = |
| 8286 | ivb_modeset_global_resources; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 8287 | } else if (IS_HASWELL(dev)) { |
| 8288 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 8289 | dev_priv->display.write_eld = haswell_write_eld; |
Paulo Zanoni | a0e63c2 | 2012-12-06 11:12:39 -0200 | [diff] [blame] | 8290 | } |
Jesse Barnes | 6067aae | 2011-04-28 15:04:31 -0700 | [diff] [blame] | 8291 | } else if (IS_G4X(dev)) { |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8292 | dev_priv->display.write_eld = g4x_write_eld; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8293 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 8294 | |
| 8295 | /* Default just returns -ENODEV to indicate unsupported */ |
| 8296 | dev_priv->display.queue_flip = intel_default_queue_flip; |
| 8297 | |
| 8298 | switch (INTEL_INFO(dev)->gen) { |
| 8299 | case 2: |
| 8300 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 8301 | break; |
| 8302 | |
| 8303 | case 3: |
| 8304 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 8305 | break; |
| 8306 | |
| 8307 | case 4: |
| 8308 | case 5: |
| 8309 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 8310 | break; |
| 8311 | |
| 8312 | case 6: |
| 8313 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 8314 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 8315 | case 7: |
| 8316 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 8317 | break; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 8318 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8319 | } |
| 8320 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8321 | /* |
| 8322 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 8323 | * resume, or other times. This quirk makes sure that's the case for |
| 8324 | * affected systems. |
| 8325 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 8326 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8327 | { |
| 8328 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8329 | |
| 8330 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 8331 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8332 | } |
| 8333 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 8334 | /* |
| 8335 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 8336 | */ |
| 8337 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 8338 | { |
| 8339 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8340 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 8341 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 8342 | } |
| 8343 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 8344 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 8345 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 8346 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 8347 | */ |
| 8348 | static void quirk_invert_brightness(struct drm_device *dev) |
| 8349 | { |
| 8350 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8351 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 8352 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8353 | } |
| 8354 | |
| 8355 | struct intel_quirk { |
| 8356 | int device; |
| 8357 | int subsystem_vendor; |
| 8358 | int subsystem_device; |
| 8359 | void (*hook)(struct drm_device *dev); |
| 8360 | }; |
| 8361 | |
Egbert Eich | 5f85f176 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 8362 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 8363 | struct intel_dmi_quirk { |
| 8364 | void (*hook)(struct drm_device *dev); |
| 8365 | const struct dmi_system_id (*dmi_id_list)[]; |
| 8366 | }; |
| 8367 | |
| 8368 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 8369 | { |
| 8370 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 8371 | return 1; |
| 8372 | } |
| 8373 | |
| 8374 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 8375 | { |
| 8376 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 8377 | { |
| 8378 | .callback = intel_dmi_reverse_brightness, |
| 8379 | .ident = "NCR Corporation", |
| 8380 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 8381 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 8382 | }, |
| 8383 | }, |
| 8384 | { } /* terminating entry */ |
| 8385 | }, |
| 8386 | .hook = quirk_invert_brightness, |
| 8387 | }, |
| 8388 | }; |
| 8389 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 8390 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8391 | /* HP Mini needs pipe A force quirk (LP: #322104) */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 8392 | { 0x27ae, 0x103c, 0x361a, quirk_pipea_force }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8393 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8394 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 8395 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 8396 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8397 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 8398 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 8399 | |
Daniel Vetter | ccd0d36 | 2012-10-10 23:13:59 +0200 | [diff] [blame] | 8400 | /* 830/845 need to leave pipe A & dpll A up */ |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8401 | { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
Daniel Vetter | dcdaed6 | 2012-08-12 21:19:34 +0200 | [diff] [blame] | 8402 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 8403 | |
| 8404 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 8405 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 8406 | |
| 8407 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 8408 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 8409 | |
| 8410 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 8411 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8412 | }; |
| 8413 | |
| 8414 | static void intel_init_quirks(struct drm_device *dev) |
| 8415 | { |
| 8416 | struct pci_dev *d = dev->pdev; |
| 8417 | int i; |
| 8418 | |
| 8419 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 8420 | struct intel_quirk *q = &intel_quirks[i]; |
| 8421 | |
| 8422 | if (d->device == q->device && |
| 8423 | (d->subsystem_vendor == q->subsystem_vendor || |
| 8424 | q->subsystem_vendor == PCI_ANY_ID) && |
| 8425 | (d->subsystem_device == q->subsystem_device || |
| 8426 | q->subsystem_device == PCI_ANY_ID)) |
| 8427 | q->hook(dev); |
| 8428 | } |
Egbert Eich | 5f85f176 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 8429 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 8430 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 8431 | intel_dmi_quirks[i].hook(dev); |
| 8432 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8433 | } |
| 8434 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 8435 | /* Disable the VGA plane that we never use */ |
| 8436 | static void i915_disable_vga(struct drm_device *dev) |
| 8437 | { |
| 8438 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8439 | u8 sr1; |
| 8440 | u32 vga_reg; |
| 8441 | |
| 8442 | if (HAS_PCH_SPLIT(dev)) |
| 8443 | vga_reg = CPU_VGACNTRL; |
| 8444 | else |
| 8445 | vga_reg = VGACNTRL; |
| 8446 | |
| 8447 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 8448 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 8449 | sr1 = inb(VGA_SR_DATA); |
| 8450 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 8451 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 8452 | udelay(300); |
| 8453 | |
| 8454 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
| 8455 | POSTING_READ(vga_reg); |
| 8456 | } |
| 8457 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 8458 | void intel_modeset_init_hw(struct drm_device *dev) |
| 8459 | { |
Eugeni Dodonov | 0232e92 | 2012-07-06 15:42:36 -0300 | [diff] [blame] | 8460 | /* We attempt to init the necessary power wells early in the initialization |
| 8461 | * time, so the subsystems that expect power to be enabled can work. |
| 8462 | */ |
| 8463 | intel_init_power_wells(dev); |
| 8464 | |
Eugeni Dodonov | a8f78b5 | 2012-06-28 15:55:35 -0300 | [diff] [blame] | 8465 | intel_prepare_ddi(dev); |
| 8466 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 8467 | intel_init_clock_gating(dev); |
| 8468 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 8469 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 8470 | intel_enable_gt_powersave(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 8471 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 8472 | } |
| 8473 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8474 | void intel_modeset_init(struct drm_device *dev) |
| 8475 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8476 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 8477 | int i, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8478 | |
| 8479 | drm_mode_config_init(dev); |
| 8480 | |
| 8481 | dev->mode_config.min_width = 0; |
| 8482 | dev->mode_config.min_height = 0; |
| 8483 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 8484 | dev->mode_config.preferred_depth = 24; |
| 8485 | dev->mode_config.prefer_shadow = 1; |
| 8486 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 8487 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8488 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 8489 | intel_init_quirks(dev); |
| 8490 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 8491 | intel_init_pm(dev); |
| 8492 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8493 | intel_init_display(dev); |
| 8494 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 8495 | if (IS_GEN2(dev)) { |
| 8496 | dev->mode_config.max_width = 2048; |
| 8497 | dev->mode_config.max_height = 2048; |
| 8498 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 8499 | dev->mode_config.max_width = 4096; |
| 8500 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8501 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 8502 | dev->mode_config.max_width = 8192; |
| 8503 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8504 | } |
Daniel Vetter | dd2757f | 2012-06-07 15:55:57 +0200 | [diff] [blame] | 8505 | dev->mode_config.fb_base = dev_priv->mm.gtt_base_addr; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8506 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 8507 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Dave Airlie | a3524f1 | 2010-06-06 18:59:41 +1000 | [diff] [blame] | 8508 | dev_priv->num_pipe, dev_priv->num_pipe > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8509 | |
Dave Airlie | a3524f1 | 2010-06-06 18:59:41 +1000 | [diff] [blame] | 8510 | for (i = 0; i < dev_priv->num_pipe; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8511 | intel_crtc_init(dev, i); |
Jesse Barnes | 00c2064b | 2012-01-13 15:48:39 -0800 | [diff] [blame] | 8512 | ret = intel_plane_init(dev, i); |
| 8513 | if (ret) |
| 8514 | DRM_DEBUG_KMS("plane %d init failed: %d\n", i, ret); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8515 | } |
| 8516 | |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 8517 | intel_cpu_pll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8518 | intel_pch_pll_init(dev); |
| 8519 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 8520 | /* Just disable it once at startup */ |
| 8521 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8522 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 8523 | |
| 8524 | /* Just in case the BIOS is doing something questionable. */ |
| 8525 | intel_disable_fbc(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 8526 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 8527 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8528 | static void |
| 8529 | intel_connector_break_all_links(struct intel_connector *connector) |
| 8530 | { |
| 8531 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 8532 | connector->base.encoder = NULL; |
| 8533 | connector->encoder->connectors_active = false; |
| 8534 | connector->encoder->base.crtc = NULL; |
| 8535 | } |
| 8536 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 8537 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 8538 | { |
| 8539 | struct intel_connector *connector; |
| 8540 | struct drm_connector *crt = NULL; |
| 8541 | struct intel_load_detect_pipe load_detect_temp; |
| 8542 | |
| 8543 | /* We can't just switch on the pipe A, we need to set things up with a |
| 8544 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 8545 | * by enabling the load detect pipe once. */ |
| 8546 | list_for_each_entry(connector, |
| 8547 | &dev->mode_config.connector_list, |
| 8548 | base.head) { |
| 8549 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 8550 | crt = &connector->base; |
| 8551 | break; |
| 8552 | } |
| 8553 | } |
| 8554 | |
| 8555 | if (!crt) |
| 8556 | return; |
| 8557 | |
| 8558 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp)) |
| 8559 | intel_release_load_detect_pipe(crt, &load_detect_temp); |
| 8560 | |
| 8561 | |
| 8562 | } |
| 8563 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 8564 | static bool |
| 8565 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 8566 | { |
| 8567 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 8568 | u32 reg, val; |
| 8569 | |
| 8570 | if (dev_priv->num_pipe == 1) |
| 8571 | return true; |
| 8572 | |
| 8573 | reg = DSPCNTR(!crtc->plane); |
| 8574 | val = I915_READ(reg); |
| 8575 | |
| 8576 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 8577 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 8578 | return false; |
| 8579 | |
| 8580 | return true; |
| 8581 | } |
| 8582 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8583 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 8584 | { |
| 8585 | struct drm_device *dev = crtc->base.dev; |
| 8586 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 8587 | u32 reg; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8588 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8589 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8590 | reg = PIPECONF(crtc->cpu_transcoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8591 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 8592 | |
| 8593 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 8594 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 8595 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 8596 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8597 | struct intel_connector *connector; |
| 8598 | bool plane; |
| 8599 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8600 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 8601 | crtc->base.base.id); |
| 8602 | |
| 8603 | /* Pipe has the wrong plane attached and the plane is active. |
| 8604 | * Temporarily change the plane mapping and disable everything |
| 8605 | * ... */ |
| 8606 | plane = crtc->plane; |
| 8607 | crtc->plane = !plane; |
| 8608 | dev_priv->display.crtc_disable(&crtc->base); |
| 8609 | crtc->plane = plane; |
| 8610 | |
| 8611 | /* ... and break all links. */ |
| 8612 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 8613 | base.head) { |
| 8614 | if (connector->encoder->base.crtc != &crtc->base) |
| 8615 | continue; |
| 8616 | |
| 8617 | intel_connector_break_all_links(connector); |
| 8618 | } |
| 8619 | |
| 8620 | WARN_ON(crtc->active); |
| 8621 | crtc->base.enabled = false; |
| 8622 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8623 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 8624 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 8625 | crtc->pipe == PIPE_A && !crtc->active) { |
| 8626 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 8627 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 8628 | * call below we restore the pipe to the right state, but leave |
| 8629 | * the required bits on. */ |
| 8630 | intel_enable_pipe_a(dev); |
| 8631 | } |
| 8632 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8633 | /* Adjust the state of the output pipe according to whether we |
| 8634 | * have active connectors/encoders. */ |
| 8635 | intel_crtc_update_dpms(&crtc->base); |
| 8636 | |
| 8637 | if (crtc->active != crtc->base.enabled) { |
| 8638 | struct intel_encoder *encoder; |
| 8639 | |
| 8640 | /* This can happen either due to bugs in the get_hw_state |
| 8641 | * functions or because the pipe is force-enabled due to the |
| 8642 | * pipe A quirk. */ |
| 8643 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", |
| 8644 | crtc->base.base.id, |
| 8645 | crtc->base.enabled ? "enabled" : "disabled", |
| 8646 | crtc->active ? "enabled" : "disabled"); |
| 8647 | |
| 8648 | crtc->base.enabled = crtc->active; |
| 8649 | |
| 8650 | /* Because we only establish the connector -> encoder -> |
| 8651 | * crtc links if something is active, this means the |
| 8652 | * crtc is now deactivated. Break the links. connector |
| 8653 | * -> encoder links are only establish when things are |
| 8654 | * actually up, hence no need to break them. */ |
| 8655 | WARN_ON(crtc->active); |
| 8656 | |
| 8657 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
| 8658 | WARN_ON(encoder->connectors_active); |
| 8659 | encoder->base.crtc = NULL; |
| 8660 | } |
| 8661 | } |
| 8662 | } |
| 8663 | |
| 8664 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 8665 | { |
| 8666 | struct intel_connector *connector; |
| 8667 | struct drm_device *dev = encoder->base.dev; |
| 8668 | |
| 8669 | /* We need to check both for a crtc link (meaning that the |
| 8670 | * encoder is active and trying to read from a pipe) and the |
| 8671 | * pipe itself being active. */ |
| 8672 | bool has_active_crtc = encoder->base.crtc && |
| 8673 | to_intel_crtc(encoder->base.crtc)->active; |
| 8674 | |
| 8675 | if (encoder->connectors_active && !has_active_crtc) { |
| 8676 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 8677 | encoder->base.base.id, |
| 8678 | drm_get_encoder_name(&encoder->base)); |
| 8679 | |
| 8680 | /* Connector is active, but has no active pipe. This is |
| 8681 | * fallout from our resume register restoring. Disable |
| 8682 | * the encoder manually again. */ |
| 8683 | if (encoder->base.crtc) { |
| 8684 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 8685 | encoder->base.base.id, |
| 8686 | drm_get_encoder_name(&encoder->base)); |
| 8687 | encoder->disable(encoder); |
| 8688 | } |
| 8689 | |
| 8690 | /* Inconsistent output/port/pipe state happens presumably due to |
| 8691 | * a bug in one of the get_hw_state functions. Or someplace else |
| 8692 | * in our code, like the register restore mess on resume. Clamp |
| 8693 | * things to off as a safer default. */ |
| 8694 | list_for_each_entry(connector, |
| 8695 | &dev->mode_config.connector_list, |
| 8696 | base.head) { |
| 8697 | if (connector->encoder != encoder) |
| 8698 | continue; |
| 8699 | |
| 8700 | intel_connector_break_all_links(connector); |
| 8701 | } |
| 8702 | } |
| 8703 | /* Enabled encoders without active connectors will be fixed in |
| 8704 | * the crtc fixup. */ |
| 8705 | } |
| 8706 | |
| 8707 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm |
| 8708 | * and i915 state tracking structures. */ |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 8709 | void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 8710 | bool force_restore) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8711 | { |
| 8712 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8713 | enum pipe pipe; |
| 8714 | u32 tmp; |
| 8715 | struct intel_crtc *crtc; |
| 8716 | struct intel_encoder *encoder; |
| 8717 | struct intel_connector *connector; |
| 8718 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 8719 | if (HAS_DDI(dev)) { |
Paulo Zanoni | e28d54c | 2012-10-24 16:09:25 -0200 | [diff] [blame] | 8720 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 8721 | |
| 8722 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 8723 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 8724 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 8725 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 8726 | pipe = PIPE_A; |
| 8727 | break; |
| 8728 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 8729 | pipe = PIPE_B; |
| 8730 | break; |
| 8731 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 8732 | pipe = PIPE_C; |
| 8733 | break; |
| 8734 | } |
| 8735 | |
| 8736 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 8737 | crtc->cpu_transcoder = TRANSCODER_EDP; |
| 8738 | |
| 8739 | DRM_DEBUG_KMS("Pipe %c using transcoder EDP\n", |
| 8740 | pipe_name(pipe)); |
| 8741 | } |
| 8742 | } |
| 8743 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8744 | for_each_pipe(pipe) { |
| 8745 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 8746 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8747 | tmp = I915_READ(PIPECONF(crtc->cpu_transcoder)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8748 | if (tmp & PIPECONF_ENABLE) |
| 8749 | crtc->active = true; |
| 8750 | else |
| 8751 | crtc->active = false; |
| 8752 | |
| 8753 | crtc->base.enabled = crtc->active; |
| 8754 | |
| 8755 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 8756 | crtc->base.base.id, |
| 8757 | crtc->active ? "enabled" : "disabled"); |
| 8758 | } |
| 8759 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 8760 | if (HAS_DDI(dev)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 8761 | intel_ddi_setup_hw_pll_state(dev); |
| 8762 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8763 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 8764 | base.head) { |
| 8765 | pipe = 0; |
| 8766 | |
| 8767 | if (encoder->get_hw_state(encoder, &pipe)) { |
| 8768 | encoder->base.crtc = |
| 8769 | dev_priv->pipe_to_crtc_mapping[pipe]; |
| 8770 | } else { |
| 8771 | encoder->base.crtc = NULL; |
| 8772 | } |
| 8773 | |
| 8774 | encoder->connectors_active = false; |
| 8775 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n", |
| 8776 | encoder->base.base.id, |
| 8777 | drm_get_encoder_name(&encoder->base), |
| 8778 | encoder->base.crtc ? "enabled" : "disabled", |
| 8779 | pipe); |
| 8780 | } |
| 8781 | |
| 8782 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 8783 | base.head) { |
| 8784 | if (connector->get_hw_state(connector)) { |
| 8785 | connector->base.dpms = DRM_MODE_DPMS_ON; |
| 8786 | connector->encoder->connectors_active = true; |
| 8787 | connector->base.encoder = &connector->encoder->base; |
| 8788 | } else { |
| 8789 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 8790 | connector->base.encoder = NULL; |
| 8791 | } |
| 8792 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 8793 | connector->base.base.id, |
| 8794 | drm_get_connector_name(&connector->base), |
| 8795 | connector->base.encoder ? "enabled" : "disabled"); |
| 8796 | } |
| 8797 | |
| 8798 | /* HW state is read out, now we need to sanitize this mess. */ |
| 8799 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 8800 | base.head) { |
| 8801 | intel_sanitize_encoder(encoder); |
| 8802 | } |
| 8803 | |
| 8804 | for_each_pipe(pipe) { |
| 8805 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 8806 | intel_sanitize_crtc(crtc); |
| 8807 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8808 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 8809 | if (force_restore) { |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame^] | 8810 | for_each_pipe(pipe) |
| 8811 | intel_crtc_restore_mode(dev_priv->pipe_to_crtc_mapping[pipe]); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 8812 | } else { |
| 8813 | intel_modeset_update_staged_output_state(dev); |
| 8814 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 8815 | |
| 8816 | intel_modeset_check_state(dev); |
Daniel Vetter | 2e93889 | 2012-10-11 20:08:24 +0200 | [diff] [blame] | 8817 | |
| 8818 | drm_mode_config_reset(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 8819 | } |
| 8820 | |
| 8821 | void intel_modeset_gem_init(struct drm_device *dev) |
| 8822 | { |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 8823 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 8824 | |
| 8825 | intel_setup_overlay(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 8826 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 8827 | intel_modeset_setup_hw_state(dev, false); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8828 | } |
| 8829 | |
| 8830 | void intel_modeset_cleanup(struct drm_device *dev) |
| 8831 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8832 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8833 | struct drm_crtc *crtc; |
| 8834 | struct intel_crtc *intel_crtc; |
| 8835 | |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 8836 | drm_kms_helper_poll_fini(dev); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8837 | mutex_lock(&dev->struct_mutex); |
| 8838 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 8839 | intel_unregister_dsm_handler(); |
| 8840 | |
| 8841 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8842 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 8843 | /* Skip inactive CRTCs */ |
| 8844 | if (!crtc->fb) |
| 8845 | continue; |
| 8846 | |
| 8847 | intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 8848 | intel_increase_pllclock(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8849 | } |
| 8850 | |
Chris Wilson | 973d04f | 2011-07-08 12:22:37 +0100 | [diff] [blame] | 8851 | intel_disable_fbc(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 8852 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 8853 | intel_disable_gt_powersave(dev); |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 8854 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 8855 | ironlake_teardown_rc6(dev); |
| 8856 | |
Jesse Barnes | 57f350b | 2012-03-28 13:39:25 -0700 | [diff] [blame] | 8857 | if (IS_VALLEYVIEW(dev)) |
| 8858 | vlv_init_dpio(dev); |
| 8859 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 8860 | mutex_unlock(&dev->struct_mutex); |
| 8861 | |
Daniel Vetter | 6c0d9350 | 2010-08-20 18:26:46 +0200 | [diff] [blame] | 8862 | /* Disable the irq before mode object teardown, for the irq might |
| 8863 | * enqueue unpin/hotplug work. */ |
| 8864 | drm_irq_uninstall(dev); |
| 8865 | cancel_work_sync(&dev_priv->hotplug_work); |
Daniel Vetter | c6a828d | 2012-08-08 23:35:35 +0200 | [diff] [blame] | 8866 | cancel_work_sync(&dev_priv->rps.work); |
Daniel Vetter | 6c0d9350 | 2010-08-20 18:26:46 +0200 | [diff] [blame] | 8867 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 8868 | /* flush any delayed tasks or pending work */ |
| 8869 | flush_scheduled_work(); |
| 8870 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8871 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 8872 | |
| 8873 | intel_cleanup_overlay(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8874 | } |
| 8875 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 8876 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 8877 | * Return which encoder is currently attached for connector. |
| 8878 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 8879 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8880 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 8881 | return &intel_attached_encoder(connector)->base; |
| 8882 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8883 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 8884 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 8885 | struct intel_encoder *encoder) |
| 8886 | { |
| 8887 | connector->encoder = encoder; |
| 8888 | drm_mode_connector_attach_encoder(&connector->base, |
| 8889 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8890 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 8891 | |
| 8892 | /* |
| 8893 | * set vga decode state - true == enable VGA decode |
| 8894 | */ |
| 8895 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 8896 | { |
| 8897 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8898 | u16 gmch_ctrl; |
| 8899 | |
| 8900 | pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl); |
| 8901 | if (state) |
| 8902 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 8903 | else |
| 8904 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
| 8905 | pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl); |
| 8906 | return 0; |
| 8907 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8908 | |
| 8909 | #ifdef CONFIG_DEBUG_FS |
| 8910 | #include <linux/seq_file.h> |
| 8911 | |
| 8912 | struct intel_display_error_state { |
| 8913 | struct intel_cursor_error_state { |
| 8914 | u32 control; |
| 8915 | u32 position; |
| 8916 | u32 base; |
| 8917 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 8918 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8919 | |
| 8920 | struct intel_pipe_error_state { |
| 8921 | u32 conf; |
| 8922 | u32 source; |
| 8923 | |
| 8924 | u32 htotal; |
| 8925 | u32 hblank; |
| 8926 | u32 hsync; |
| 8927 | u32 vtotal; |
| 8928 | u32 vblank; |
| 8929 | u32 vsync; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 8930 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8931 | |
| 8932 | struct intel_plane_error_state { |
| 8933 | u32 control; |
| 8934 | u32 stride; |
| 8935 | u32 size; |
| 8936 | u32 pos; |
| 8937 | u32 addr; |
| 8938 | u32 surface; |
| 8939 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 8940 | } plane[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8941 | }; |
| 8942 | |
| 8943 | struct intel_display_error_state * |
| 8944 | intel_display_capture_error_state(struct drm_device *dev) |
| 8945 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 8946 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8947 | struct intel_display_error_state *error; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8948 | enum transcoder cpu_transcoder; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8949 | int i; |
| 8950 | |
| 8951 | error = kmalloc(sizeof(*error), GFP_ATOMIC); |
| 8952 | if (error == NULL) |
| 8953 | return NULL; |
| 8954 | |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 8955 | for_each_pipe(i) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8956 | cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i); |
| 8957 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8958 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 8959 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 8960 | error->cursor[i].base = I915_READ(CURBASE(i)); |
| 8961 | |
| 8962 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 8963 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
| 8964 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 8965 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8966 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
| 8967 | if (INTEL_INFO(dev)->gen >= 4) { |
| 8968 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 8969 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 8970 | } |
| 8971 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 8972 | error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8973 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8974 | error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 8975 | error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 8976 | error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 8977 | error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 8978 | error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 8979 | error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8980 | } |
| 8981 | |
| 8982 | return error; |
| 8983 | } |
| 8984 | |
| 8985 | void |
| 8986 | intel_display_print_error_state(struct seq_file *m, |
| 8987 | struct drm_device *dev, |
| 8988 | struct intel_display_error_state *error) |
| 8989 | { |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 8990 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8991 | int i; |
| 8992 | |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 8993 | seq_printf(m, "Num Pipes: %d\n", dev_priv->num_pipe); |
| 8994 | for_each_pipe(i) { |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 8995 | seq_printf(m, "Pipe [%d]:\n", i); |
| 8996 | seq_printf(m, " CONF: %08x\n", error->pipe[i].conf); |
| 8997 | seq_printf(m, " SRC: %08x\n", error->pipe[i].source); |
| 8998 | seq_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal); |
| 8999 | seq_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank); |
| 9000 | seq_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync); |
| 9001 | seq_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal); |
| 9002 | seq_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank); |
| 9003 | seq_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync); |
| 9004 | |
| 9005 | seq_printf(m, "Plane [%d]:\n", i); |
| 9006 | seq_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 9007 | seq_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
| 9008 | seq_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 9009 | seq_printf(m, " POS: %08x\n", error->plane[i].pos); |
| 9010 | seq_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
| 9011 | if (INTEL_INFO(dev)->gen >= 4) { |
| 9012 | seq_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 9013 | seq_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
| 9014 | } |
| 9015 | |
| 9016 | seq_printf(m, "Cursor [%d]:\n", i); |
| 9017 | seq_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 9018 | seq_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 9019 | seq_printf(m, " BASE: %08x\n", error->cursor[i].base); |
| 9020 | } |
| 9021 | } |
| 9022 | #endif |