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 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 48 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
| 49 | struct intel_crtc_config *pipe_config); |
| 50 | static void ironlake_crtc_clock_get(struct intel_crtc *crtc, |
| 51 | struct intel_crtc_config *pipe_config); |
| 52 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 53 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 54 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 55 | } intel_range_t; |
| 56 | |
| 57 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 58 | int dot_limit; |
| 59 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 60 | } intel_p2_t; |
| 61 | |
| 62 | #define INTEL_P2_NUM 2 |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 63 | typedef struct intel_limit intel_limit_t; |
| 64 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 65 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 66 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 67 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 68 | |
Jesse Barnes | 2377b74 | 2010-07-07 14:06:43 -0700 | [diff] [blame] | 69 | /* FDI */ |
| 70 | #define IRONLAKE_FDI_FREQ 2700000 /* in kHz for mode->clock */ |
| 71 | |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 72 | int |
| 73 | intel_pch_rawclk(struct drm_device *dev) |
| 74 | { |
| 75 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 76 | |
| 77 | WARN_ON(!HAS_PCH_SPLIT(dev)); |
| 78 | |
| 79 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; |
| 80 | } |
| 81 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 82 | static inline u32 /* units of 100MHz */ |
| 83 | intel_fdi_link_freq(struct drm_device *dev) |
| 84 | { |
Chris Wilson | 8b99e68 | 2010-10-13 09:59:17 +0100 | [diff] [blame] | 85 | if (IS_GEN5(dev)) { |
| 86 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 87 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; |
| 88 | } else |
| 89 | return 27; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 90 | } |
| 91 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 92 | static const intel_limit_t intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 93 | .dot = { .min = 25000, .max = 350000 }, |
| 94 | .vco = { .min = 930000, .max = 1400000 }, |
| 95 | .n = { .min = 3, .max = 16 }, |
| 96 | .m = { .min = 96, .max = 140 }, |
| 97 | .m1 = { .min = 18, .max = 26 }, |
| 98 | .m2 = { .min = 6, .max = 16 }, |
| 99 | .p = { .min = 4, .max = 128 }, |
| 100 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 101 | .p2 = { .dot_limit = 165000, |
| 102 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 103 | }; |
| 104 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 105 | static const intel_limit_t intel_limits_i8xx_dvo = { |
| 106 | .dot = { .min = 25000, .max = 350000 }, |
| 107 | .vco = { .min = 930000, .max = 1400000 }, |
| 108 | .n = { .min = 3, .max = 16 }, |
| 109 | .m = { .min = 96, .max = 140 }, |
| 110 | .m1 = { .min = 18, .max = 26 }, |
| 111 | .m2 = { .min = 6, .max = 16 }, |
| 112 | .p = { .min = 4, .max = 128 }, |
| 113 | .p1 = { .min = 2, .max = 33 }, |
| 114 | .p2 = { .dot_limit = 165000, |
| 115 | .p2_slow = 4, .p2_fast = 4 }, |
| 116 | }; |
| 117 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 118 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 119 | .dot = { .min = 25000, .max = 350000 }, |
| 120 | .vco = { .min = 930000, .max = 1400000 }, |
| 121 | .n = { .min = 3, .max = 16 }, |
| 122 | .m = { .min = 96, .max = 140 }, |
| 123 | .m1 = { .min = 18, .max = 26 }, |
| 124 | .m2 = { .min = 6, .max = 16 }, |
| 125 | .p = { .min = 4, .max = 128 }, |
| 126 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 127 | .p2 = { .dot_limit = 165000, |
| 128 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 129 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 130 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 131 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 132 | .dot = { .min = 20000, .max = 400000 }, |
| 133 | .vco = { .min = 1400000, .max = 2800000 }, |
| 134 | .n = { .min = 1, .max = 6 }, |
| 135 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 136 | .m1 = { .min = 8, .max = 18 }, |
| 137 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 138 | .p = { .min = 5, .max = 80 }, |
| 139 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 140 | .p2 = { .dot_limit = 200000, |
| 141 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 142 | }; |
| 143 | |
| 144 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 145 | .dot = { .min = 20000, .max = 400000 }, |
| 146 | .vco = { .min = 1400000, .max = 2800000 }, |
| 147 | .n = { .min = 1, .max = 6 }, |
| 148 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 149 | .m1 = { .min = 8, .max = 18 }, |
| 150 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 151 | .p = { .min = 7, .max = 98 }, |
| 152 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 153 | .p2 = { .dot_limit = 112000, |
| 154 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 155 | }; |
| 156 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 157 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 158 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 159 | .dot = { .min = 25000, .max = 270000 }, |
| 160 | .vco = { .min = 1750000, .max = 3500000}, |
| 161 | .n = { .min = 1, .max = 4 }, |
| 162 | .m = { .min = 104, .max = 138 }, |
| 163 | .m1 = { .min = 17, .max = 23 }, |
| 164 | .m2 = { .min = 5, .max = 11 }, |
| 165 | .p = { .min = 10, .max = 30 }, |
| 166 | .p1 = { .min = 1, .max = 3}, |
| 167 | .p2 = { .dot_limit = 270000, |
| 168 | .p2_slow = 10, |
| 169 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 170 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 174 | .dot = { .min = 22000, .max = 400000 }, |
| 175 | .vco = { .min = 1750000, .max = 3500000}, |
| 176 | .n = { .min = 1, .max = 4 }, |
| 177 | .m = { .min = 104, .max = 138 }, |
| 178 | .m1 = { .min = 16, .max = 23 }, |
| 179 | .m2 = { .min = 5, .max = 11 }, |
| 180 | .p = { .min = 5, .max = 80 }, |
| 181 | .p1 = { .min = 1, .max = 8}, |
| 182 | .p2 = { .dot_limit = 165000, |
| 183 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 184 | }; |
| 185 | |
| 186 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 187 | .dot = { .min = 20000, .max = 115000 }, |
| 188 | .vco = { .min = 1750000, .max = 3500000 }, |
| 189 | .n = { .min = 1, .max = 3 }, |
| 190 | .m = { .min = 104, .max = 138 }, |
| 191 | .m1 = { .min = 17, .max = 23 }, |
| 192 | .m2 = { .min = 5, .max = 11 }, |
| 193 | .p = { .min = 28, .max = 112 }, |
| 194 | .p1 = { .min = 2, .max = 8 }, |
| 195 | .p2 = { .dot_limit = 0, |
| 196 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 197 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 201 | .dot = { .min = 80000, .max = 224000 }, |
| 202 | .vco = { .min = 1750000, .max = 3500000 }, |
| 203 | .n = { .min = 1, .max = 3 }, |
| 204 | .m = { .min = 104, .max = 138 }, |
| 205 | .m1 = { .min = 17, .max = 23 }, |
| 206 | .m2 = { .min = 5, .max = 11 }, |
| 207 | .p = { .min = 14, .max = 42 }, |
| 208 | .p1 = { .min = 2, .max = 6 }, |
| 209 | .p2 = { .dot_limit = 0, |
| 210 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 211 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 214 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 215 | .dot = { .min = 20000, .max = 400000}, |
| 216 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 217 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 218 | .n = { .min = 3, .max = 6 }, |
| 219 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 220 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 221 | .m1 = { .min = 0, .max = 0 }, |
| 222 | .m2 = { .min = 0, .max = 254 }, |
| 223 | .p = { .min = 5, .max = 80 }, |
| 224 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 225 | .p2 = { .dot_limit = 200000, |
| 226 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 229 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 230 | .dot = { .min = 20000, .max = 400000 }, |
| 231 | .vco = { .min = 1700000, .max = 3500000 }, |
| 232 | .n = { .min = 3, .max = 6 }, |
| 233 | .m = { .min = 2, .max = 256 }, |
| 234 | .m1 = { .min = 0, .max = 0 }, |
| 235 | .m2 = { .min = 0, .max = 254 }, |
| 236 | .p = { .min = 7, .max = 112 }, |
| 237 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 238 | .p2 = { .dot_limit = 112000, |
| 239 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 242 | /* Ironlake / Sandybridge |
| 243 | * |
| 244 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 245 | * the range value for them is (actual_value - 2). |
| 246 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 247 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 248 | .dot = { .min = 25000, .max = 350000 }, |
| 249 | .vco = { .min = 1760000, .max = 3510000 }, |
| 250 | .n = { .min = 1, .max = 5 }, |
| 251 | .m = { .min = 79, .max = 127 }, |
| 252 | .m1 = { .min = 12, .max = 22 }, |
| 253 | .m2 = { .min = 5, .max = 9 }, |
| 254 | .p = { .min = 5, .max = 80 }, |
| 255 | .p1 = { .min = 1, .max = 8 }, |
| 256 | .p2 = { .dot_limit = 225000, |
| 257 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 258 | }; |
| 259 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 260 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 261 | .dot = { .min = 25000, .max = 350000 }, |
| 262 | .vco = { .min = 1760000, .max = 3510000 }, |
| 263 | .n = { .min = 1, .max = 3 }, |
| 264 | .m = { .min = 79, .max = 118 }, |
| 265 | .m1 = { .min = 12, .max = 22 }, |
| 266 | .m2 = { .min = 5, .max = 9 }, |
| 267 | .p = { .min = 28, .max = 112 }, |
| 268 | .p1 = { .min = 2, .max = 8 }, |
| 269 | .p2 = { .dot_limit = 225000, |
| 270 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 274 | .dot = { .min = 25000, .max = 350000 }, |
| 275 | .vco = { .min = 1760000, .max = 3510000 }, |
| 276 | .n = { .min = 1, .max = 3 }, |
| 277 | .m = { .min = 79, .max = 127 }, |
| 278 | .m1 = { .min = 12, .max = 22 }, |
| 279 | .m2 = { .min = 5, .max = 9 }, |
| 280 | .p = { .min = 14, .max = 56 }, |
| 281 | .p1 = { .min = 2, .max = 8 }, |
| 282 | .p2 = { .dot_limit = 225000, |
| 283 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 284 | }; |
| 285 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 286 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 287 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 288 | .dot = { .min = 25000, .max = 350000 }, |
| 289 | .vco = { .min = 1760000, .max = 3510000 }, |
| 290 | .n = { .min = 1, .max = 2 }, |
| 291 | .m = { .min = 79, .max = 126 }, |
| 292 | .m1 = { .min = 12, .max = 22 }, |
| 293 | .m2 = { .min = 5, .max = 9 }, |
| 294 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 295 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 296 | .p2 = { .dot_limit = 225000, |
| 297 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 298 | }; |
| 299 | |
| 300 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 301 | .dot = { .min = 25000, .max = 350000 }, |
| 302 | .vco = { .min = 1760000, .max = 3510000 }, |
| 303 | .n = { .min = 1, .max = 3 }, |
| 304 | .m = { .min = 79, .max = 126 }, |
| 305 | .m1 = { .min = 12, .max = 22 }, |
| 306 | .m2 = { .min = 5, .max = 9 }, |
| 307 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 308 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 309 | .p2 = { .dot_limit = 225000, |
| 310 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 311 | }; |
| 312 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 313 | static const intel_limit_t intel_limits_vlv_dac = { |
| 314 | .dot = { .min = 25000, .max = 270000 }, |
| 315 | .vco = { .min = 4000000, .max = 6000000 }, |
| 316 | .n = { .min = 1, .max = 7 }, |
| 317 | .m = { .min = 22, .max = 450 }, /* guess */ |
| 318 | .m1 = { .min = 2, .max = 3 }, |
| 319 | .m2 = { .min = 11, .max = 156 }, |
| 320 | .p = { .min = 10, .max = 30 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 321 | .p1 = { .min = 1, .max = 3 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 322 | .p2 = { .dot_limit = 270000, |
| 323 | .p2_slow = 2, .p2_fast = 20 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 324 | }; |
| 325 | |
| 326 | static const intel_limit_t intel_limits_vlv_hdmi = { |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 327 | .dot = { .min = 25000, .max = 270000 }, |
| 328 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 329 | .n = { .min = 1, .max = 7 }, |
| 330 | .m = { .min = 60, .max = 300 }, /* guess */ |
| 331 | .m1 = { .min = 2, .max = 3 }, |
| 332 | .m2 = { .min = 11, .max = 156 }, |
| 333 | .p = { .min = 10, .max = 30 }, |
| 334 | .p1 = { .min = 2, .max = 3 }, |
| 335 | .p2 = { .dot_limit = 270000, |
| 336 | .p2_slow = 2, .p2_fast = 20 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 337 | }; |
| 338 | |
| 339 | static const intel_limit_t intel_limits_vlv_dp = { |
Vijay Purushothaman | 74a4dd2 | 2012-09-27 19:13:04 +0530 | [diff] [blame] | 340 | .dot = { .min = 25000, .max = 270000 }, |
| 341 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 342 | .n = { .min = 1, .max = 7 }, |
Vijay Purushothaman | 74a4dd2 | 2012-09-27 19:13:04 +0530 | [diff] [blame] | 343 | .m = { .min = 22, .max = 450 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 344 | .m1 = { .min = 2, .max = 3 }, |
| 345 | .m2 = { .min = 11, .max = 156 }, |
| 346 | .p = { .min = 10, .max = 30 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 347 | .p1 = { .min = 1, .max = 3 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 348 | .p2 = { .dot_limit = 270000, |
| 349 | .p2_slow = 2, .p2_fast = 20 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 350 | }; |
| 351 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 352 | static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc, |
| 353 | int refclk) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 354 | { |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 355 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 356 | const intel_limit_t *limit; |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 357 | |
| 358 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 359 | if (intel_is_dual_link_lvds(dev)) { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 360 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 361 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 362 | else |
| 363 | limit = &intel_limits_ironlake_dual_lvds; |
| 364 | } else { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 365 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 366 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 367 | else |
| 368 | limit = &intel_limits_ironlake_single_lvds; |
| 369 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 370 | } else |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 371 | limit = &intel_limits_ironlake_dac; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 372 | |
| 373 | return limit; |
| 374 | } |
| 375 | |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 376 | static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc) |
| 377 | { |
| 378 | struct drm_device *dev = crtc->dev; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 379 | const intel_limit_t *limit; |
| 380 | |
| 381 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 382 | if (intel_is_dual_link_lvds(dev)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 383 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 384 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 385 | limit = &intel_limits_g4x_single_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 386 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) || |
| 387 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 388 | limit = &intel_limits_g4x_hdmi; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 389 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 390 | limit = &intel_limits_g4x_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 391 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 392 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 393 | |
| 394 | return limit; |
| 395 | } |
| 396 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 397 | 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] | 398 | { |
| 399 | struct drm_device *dev = crtc->dev; |
| 400 | const intel_limit_t *limit; |
| 401 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 402 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 403 | limit = intel_ironlake_limit(crtc, refclk); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 404 | else if (IS_G4X(dev)) { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 405 | limit = intel_g4x_limit(crtc); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 406 | } else if (IS_PINEVIEW(dev)) { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 407 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 408 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 409 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 410 | limit = &intel_limits_pineview_sdvo; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 411 | } else if (IS_VALLEYVIEW(dev)) { |
| 412 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) |
| 413 | limit = &intel_limits_vlv_dac; |
| 414 | else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
| 415 | limit = &intel_limits_vlv_hdmi; |
| 416 | else |
| 417 | limit = &intel_limits_vlv_dp; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 418 | } else if (!IS_GEN2(dev)) { |
| 419 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
| 420 | limit = &intel_limits_i9xx_lvds; |
| 421 | else |
| 422 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 423 | } else { |
| 424 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 425 | limit = &intel_limits_i8xx_lvds; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 426 | else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 427 | limit = &intel_limits_i8xx_dvo; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 428 | else |
| 429 | limit = &intel_limits_i8xx_dac; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 430 | } |
| 431 | return limit; |
| 432 | } |
| 433 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 434 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
| 435 | static void pineview_clock(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 436 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 437 | clock->m = clock->m2 + 2; |
| 438 | clock->p = clock->p1 * clock->p2; |
| 439 | clock->vco = refclk * clock->m / clock->n; |
| 440 | clock->dot = clock->vco / clock->p; |
| 441 | } |
| 442 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 443 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 444 | { |
| 445 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 446 | } |
| 447 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 448 | static void i9xx_clock(int refclk, intel_clock_t *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 449 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 450 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 451 | clock->p = clock->p1 * clock->p2; |
| 452 | clock->vco = refclk * clock->m / (clock->n + 2); |
| 453 | clock->dot = clock->vco / clock->p; |
| 454 | } |
| 455 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 456 | /** |
| 457 | * Returns whether any output on the specified pipe is of the specified type |
| 458 | */ |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 459 | bool intel_pipe_has_type(struct drm_crtc *crtc, int type) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 460 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 461 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 462 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 463 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 464 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 465 | if (encoder->type == type) |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 466 | return true; |
| 467 | |
| 468 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 469 | } |
| 470 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 471 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 472 | /** |
| 473 | * Returns whether the given set of divisors are valid for a given refclk with |
| 474 | * the given connectors. |
| 475 | */ |
| 476 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 477 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 478 | const intel_limit_t *limit, |
| 479 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 480 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 481 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 482 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 483 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 484 | INTELPllInvalid("p out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 485 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 486 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 487 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 488 | INTELPllInvalid("m1 out of range\n"); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 489 | if (clock->m1 <= clock->m2 && !IS_PINEVIEW(dev)) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 490 | INTELPllInvalid("m1 <= m2\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 491 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 492 | INTELPllInvalid("m out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 493 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 494 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 495 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 496 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 497 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 498 | * connector, etc., rather than just a single range. |
| 499 | */ |
| 500 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 501 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 502 | |
| 503 | return true; |
| 504 | } |
| 505 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 506 | static bool |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 507 | i9xx_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 508 | int target, int refclk, intel_clock_t *match_clock, |
| 509 | intel_clock_t *best_clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 510 | { |
| 511 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 512 | intel_clock_t clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 513 | int err = target; |
| 514 | |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 515 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 516 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 517 | * For LVDS just rely on its current settings for dual-channel. |
| 518 | * We haven't figured out how to reliably set up different |
| 519 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 520 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 521 | if (intel_is_dual_link_lvds(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 522 | clock.p2 = limit->p2.p2_fast; |
| 523 | else |
| 524 | clock.p2 = limit->p2.p2_slow; |
| 525 | } else { |
| 526 | if (target < limit->p2.dot_limit) |
| 527 | clock.p2 = limit->p2.p2_slow; |
| 528 | else |
| 529 | clock.p2 = limit->p2.p2_fast; |
| 530 | } |
| 531 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 532 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 533 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 534 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 535 | clock.m1++) { |
| 536 | for (clock.m2 = limit->m2.min; |
| 537 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 538 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 539 | break; |
| 540 | for (clock.n = limit->n.min; |
| 541 | clock.n <= limit->n.max; clock.n++) { |
| 542 | for (clock.p1 = limit->p1.min; |
| 543 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 544 | int this_err; |
| 545 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 546 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 547 | if (!intel_PLL_is_valid(dev, limit, |
| 548 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 549 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 550 | if (match_clock && |
| 551 | clock.p != match_clock->p) |
| 552 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 553 | |
| 554 | this_err = abs(clock.dot - target); |
| 555 | if (this_err < err) { |
| 556 | *best_clock = clock; |
| 557 | err = this_err; |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | |
| 564 | return (err != target); |
| 565 | } |
| 566 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 567 | static bool |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 568 | pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 569 | int target, int refclk, intel_clock_t *match_clock, |
| 570 | intel_clock_t *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 571 | { |
| 572 | struct drm_device *dev = crtc->dev; |
| 573 | intel_clock_t clock; |
| 574 | int err = target; |
| 575 | |
| 576 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 577 | /* |
| 578 | * For LVDS just rely on its current settings for dual-channel. |
| 579 | * We haven't figured out how to reliably set up different |
| 580 | * single/dual channel state, if we even can. |
| 581 | */ |
| 582 | if (intel_is_dual_link_lvds(dev)) |
| 583 | clock.p2 = limit->p2.p2_fast; |
| 584 | else |
| 585 | clock.p2 = limit->p2.p2_slow; |
| 586 | } else { |
| 587 | if (target < limit->p2.dot_limit) |
| 588 | clock.p2 = limit->p2.p2_slow; |
| 589 | else |
| 590 | clock.p2 = limit->p2.p2_fast; |
| 591 | } |
| 592 | |
| 593 | memset(best_clock, 0, sizeof(*best_clock)); |
| 594 | |
| 595 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 596 | clock.m1++) { |
| 597 | for (clock.m2 = limit->m2.min; |
| 598 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 599 | for (clock.n = limit->n.min; |
| 600 | clock.n <= limit->n.max; clock.n++) { |
| 601 | for (clock.p1 = limit->p1.min; |
| 602 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 603 | int this_err; |
| 604 | |
| 605 | pineview_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 606 | if (!intel_PLL_is_valid(dev, limit, |
| 607 | &clock)) |
| 608 | continue; |
| 609 | if (match_clock && |
| 610 | clock.p != match_clock->p) |
| 611 | continue; |
| 612 | |
| 613 | this_err = abs(clock.dot - target); |
| 614 | if (this_err < err) { |
| 615 | *best_clock = clock; |
| 616 | err = this_err; |
| 617 | } |
| 618 | } |
| 619 | } |
| 620 | } |
| 621 | } |
| 622 | |
| 623 | return (err != target); |
| 624 | } |
| 625 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 626 | static bool |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 627 | g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 628 | int target, int refclk, intel_clock_t *match_clock, |
| 629 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 630 | { |
| 631 | struct drm_device *dev = crtc->dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 632 | intel_clock_t clock; |
| 633 | int max_n; |
| 634 | bool found; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 635 | /* approximately equals target * 0.00585 */ |
| 636 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 637 | found = false; |
| 638 | |
| 639 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 640 | if (intel_is_dual_link_lvds(dev)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 641 | clock.p2 = limit->p2.p2_fast; |
| 642 | else |
| 643 | clock.p2 = limit->p2.p2_slow; |
| 644 | } else { |
| 645 | if (target < limit->p2.dot_limit) |
| 646 | clock.p2 = limit->p2.p2_slow; |
| 647 | else |
| 648 | clock.p2 = limit->p2.p2_fast; |
| 649 | } |
| 650 | |
| 651 | memset(best_clock, 0, sizeof(*best_clock)); |
| 652 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 653 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 654 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 655 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 656 | for (clock.m1 = limit->m1.max; |
| 657 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 658 | for (clock.m2 = limit->m2.max; |
| 659 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 660 | for (clock.p1 = limit->p1.max; |
| 661 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 662 | int this_err; |
| 663 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 664 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 665 | if (!intel_PLL_is_valid(dev, limit, |
| 666 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 667 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 668 | |
| 669 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 670 | if (this_err < err_most) { |
| 671 | *best_clock = clock; |
| 672 | err_most = this_err; |
| 673 | max_n = clock.n; |
| 674 | found = true; |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 680 | return found; |
| 681 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 682 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 683 | static bool |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 684 | vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 685 | int target, int refclk, intel_clock_t *match_clock, |
| 686 | intel_clock_t *best_clock) |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 687 | { |
| 688 | u32 p1, p2, m1, m2, vco, bestn, bestm1, bestm2, bestp1, bestp2; |
| 689 | u32 m, n, fastclk; |
| 690 | u32 updrate, minupdate, fracbits, p; |
| 691 | unsigned long bestppm, ppm, absppm; |
| 692 | int dotclk, flag; |
| 693 | |
Alan Cox | af447bd | 2012-07-25 13:49:18 +0100 | [diff] [blame] | 694 | flag = 0; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 695 | dotclk = target * 1000; |
| 696 | bestppm = 1000000; |
| 697 | ppm = absppm = 0; |
| 698 | fastclk = dotclk / (2*100); |
| 699 | updrate = 0; |
| 700 | minupdate = 19200; |
| 701 | fracbits = 1; |
| 702 | n = p = p1 = p2 = m = m1 = m2 = vco = bestn = 0; |
| 703 | bestm1 = bestm2 = bestp1 = bestp2 = 0; |
| 704 | |
| 705 | /* based on hardware requirement, prefer smaller n to precision */ |
| 706 | for (n = limit->n.min; n <= ((refclk) / minupdate); n++) { |
| 707 | updrate = refclk / n; |
| 708 | for (p1 = limit->p1.max; p1 > limit->p1.min; p1--) { |
| 709 | for (p2 = limit->p2.p2_fast+1; p2 > 0; p2--) { |
| 710 | if (p2 > 10) |
| 711 | p2 = p2 - 1; |
| 712 | p = p1 * p2; |
| 713 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
| 714 | for (m1 = limit->m1.min; m1 <= limit->m1.max; m1++) { |
| 715 | m2 = (((2*(fastclk * p * n / m1 )) + |
| 716 | refclk) / (2*refclk)); |
| 717 | m = m1 * m2; |
| 718 | vco = updrate * m; |
| 719 | if (vco >= limit->vco.min && vco < limit->vco.max) { |
| 720 | ppm = 1000000 * ((vco / p) - fastclk) / fastclk; |
| 721 | absppm = (ppm > 0) ? ppm : (-ppm); |
| 722 | if (absppm < 100 && ((p1 * p2) > (bestp1 * bestp2))) { |
| 723 | bestppm = 0; |
| 724 | flag = 1; |
| 725 | } |
| 726 | if (absppm < bestppm - 10) { |
| 727 | bestppm = absppm; |
| 728 | flag = 1; |
| 729 | } |
| 730 | if (flag) { |
| 731 | bestn = n; |
| 732 | bestm1 = m1; |
| 733 | bestm2 = m2; |
| 734 | bestp1 = p1; |
| 735 | bestp2 = p2; |
| 736 | flag = 0; |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | best_clock->n = bestn; |
| 744 | best_clock->m1 = bestm1; |
| 745 | best_clock->m2 = bestm2; |
| 746 | best_clock->p1 = bestp1; |
| 747 | best_clock->p2 = bestp2; |
| 748 | |
| 749 | return true; |
| 750 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 751 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 752 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 753 | enum pipe pipe) |
| 754 | { |
| 755 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 756 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 757 | |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 758 | return intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 759 | } |
| 760 | |
Paulo Zanoni | a928d53 | 2012-05-04 17:18:15 -0300 | [diff] [blame] | 761 | static void ironlake_wait_for_vblank(struct drm_device *dev, int pipe) |
| 762 | { |
| 763 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 764 | u32 frame, frame_reg = PIPEFRAME(pipe); |
| 765 | |
| 766 | frame = I915_READ(frame_reg); |
| 767 | |
| 768 | if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50)) |
| 769 | DRM_DEBUG_KMS("vblank wait timed out\n"); |
| 770 | } |
| 771 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 772 | /** |
| 773 | * intel_wait_for_vblank - wait for vblank on a given pipe |
| 774 | * @dev: drm device |
| 775 | * @pipe: pipe to wait for |
| 776 | * |
| 777 | * Wait for vblank to occur on a given pipe. Needed for various bits of |
| 778 | * mode setting code. |
| 779 | */ |
| 780 | void intel_wait_for_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 781 | { |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 782 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 783 | int pipestat_reg = PIPESTAT(pipe); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 784 | |
Paulo Zanoni | a928d53 | 2012-05-04 17:18:15 -0300 | [diff] [blame] | 785 | if (INTEL_INFO(dev)->gen >= 5) { |
| 786 | ironlake_wait_for_vblank(dev, pipe); |
| 787 | return; |
| 788 | } |
| 789 | |
Chris Wilson | 300387c | 2010-09-05 20:25:43 +0100 | [diff] [blame] | 790 | /* Clear existing vblank status. Note this will clear any other |
| 791 | * sticky status fields as well. |
| 792 | * |
| 793 | * This races with i915_driver_irq_handler() with the result |
| 794 | * that either function could miss a vblank event. Here it is not |
| 795 | * fatal, as we will either wait upon the next vblank interrupt or |
| 796 | * timeout. Generally speaking intel_wait_for_vblank() is only |
| 797 | * called during modeset at which time the GPU should be idle and |
| 798 | * should *not* be performing page flips and thus not waiting on |
| 799 | * vblanks... |
| 800 | * Currently, the result of us stealing a vblank from the irq |
| 801 | * handler is that a single frame will be skipped during swapbuffers. |
| 802 | */ |
| 803 | I915_WRITE(pipestat_reg, |
| 804 | I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS); |
| 805 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 806 | /* Wait for vblank interrupt bit to set */ |
Chris Wilson | 481b6af | 2010-08-23 17:43:35 +0100 | [diff] [blame] | 807 | if (wait_for(I915_READ(pipestat_reg) & |
| 808 | PIPE_VBLANK_INTERRUPT_STATUS, |
| 809 | 50)) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 810 | DRM_DEBUG_KMS("vblank wait timed out\n"); |
| 811 | } |
| 812 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 813 | /* |
| 814 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 815 | * @dev: drm device |
| 816 | * @pipe: pipe to wait for |
| 817 | * |
| 818 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 819 | * spinning on the vblank interrupt status bit, since we won't actually |
| 820 | * see an interrupt when the pipe is disabled. |
| 821 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 822 | * On Gen4 and above: |
| 823 | * wait for the pipe register state bit to turn off |
| 824 | * |
| 825 | * Otherwise: |
| 826 | * wait for the display line value to settle (it usually |
| 827 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 828 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 829 | */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 830 | void intel_wait_for_pipe_off(struct drm_device *dev, int pipe) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 831 | { |
| 832 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 833 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 834 | pipe); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 835 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 836 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 837 | int reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 838 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 839 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 840 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 841 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 842 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 843 | } else { |
Paulo Zanoni | 837ba00 | 2012-05-04 17:18:14 -0300 | [diff] [blame] | 844 | u32 last_line, line_mask; |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 845 | int reg = PIPEDSL(pipe); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 846 | unsigned long timeout = jiffies + msecs_to_jiffies(100); |
| 847 | |
Paulo Zanoni | 837ba00 | 2012-05-04 17:18:14 -0300 | [diff] [blame] | 848 | if (IS_GEN2(dev)) |
| 849 | line_mask = DSL_LINEMASK_GEN2; |
| 850 | else |
| 851 | line_mask = DSL_LINEMASK_GEN3; |
| 852 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 853 | /* Wait for the display line to settle */ |
| 854 | do { |
Paulo Zanoni | 837ba00 | 2012-05-04 17:18:14 -0300 | [diff] [blame] | 855 | last_line = I915_READ(reg) & line_mask; |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 856 | mdelay(5); |
Paulo Zanoni | 837ba00 | 2012-05-04 17:18:14 -0300 | [diff] [blame] | 857 | } while (((I915_READ(reg) & line_mask) != last_line) && |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 858 | time_after(timeout, jiffies)); |
| 859 | if (time_after(jiffies, timeout)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 860 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 861 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 862 | } |
| 863 | |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 864 | /* |
| 865 | * ibx_digital_port_connected - is the specified port connected? |
| 866 | * @dev_priv: i915 private structure |
| 867 | * @port: the port to test |
| 868 | * |
| 869 | * Returns true if @port is connected, false otherwise. |
| 870 | */ |
| 871 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 872 | struct intel_digital_port *port) |
| 873 | { |
| 874 | u32 bit; |
| 875 | |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 876 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 877 | switch(port->port) { |
| 878 | case PORT_B: |
| 879 | bit = SDE_PORTB_HOTPLUG; |
| 880 | break; |
| 881 | case PORT_C: |
| 882 | bit = SDE_PORTC_HOTPLUG; |
| 883 | break; |
| 884 | case PORT_D: |
| 885 | bit = SDE_PORTD_HOTPLUG; |
| 886 | break; |
| 887 | default: |
| 888 | return true; |
| 889 | } |
| 890 | } else { |
| 891 | switch(port->port) { |
| 892 | case PORT_B: |
| 893 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 894 | break; |
| 895 | case PORT_C: |
| 896 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 897 | break; |
| 898 | case PORT_D: |
| 899 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 900 | break; |
| 901 | default: |
| 902 | return true; |
| 903 | } |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | return I915_READ(SDEISR) & bit; |
| 907 | } |
| 908 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 909 | static const char *state_string(bool enabled) |
| 910 | { |
| 911 | return enabled ? "on" : "off"; |
| 912 | } |
| 913 | |
| 914 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 915 | void assert_pll(struct drm_i915_private *dev_priv, |
| 916 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 917 | { |
| 918 | int reg; |
| 919 | u32 val; |
| 920 | bool cur_state; |
| 921 | |
| 922 | reg = DPLL(pipe); |
| 923 | val = I915_READ(reg); |
| 924 | cur_state = !!(val & DPLL_VCO_ENABLE); |
| 925 | WARN(cur_state != state, |
| 926 | "PLL state assertion failure (expected %s, current %s)\n", |
| 927 | state_string(state), state_string(cur_state)); |
| 928 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 929 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 930 | struct intel_shared_dpll * |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 931 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 932 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 933 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 934 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 935 | if (crtc->config.shared_dpll < 0) |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 936 | return NULL; |
| 937 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 938 | return &dev_priv->shared_dplls[crtc->config.shared_dpll]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 939 | } |
| 940 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 941 | /* For ILK+ */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 942 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
| 943 | struct intel_shared_dpll *pll, |
| 944 | bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 945 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 946 | bool cur_state; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 947 | struct intel_dpll_hw_state hw_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 948 | |
Eugeni Dodonov | 9d82aa1 | 2012-05-09 15:37:17 -0300 | [diff] [blame] | 949 | if (HAS_PCH_LPT(dev_priv->dev)) { |
| 950 | DRM_DEBUG_DRIVER("LPT detected: skipping PCH PLL test\n"); |
| 951 | return; |
| 952 | } |
| 953 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 954 | if (WARN (!pll, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 955 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 956 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 957 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 958 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 959 | WARN(cur_state != state, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 960 | "%s assertion failure (expected %s, current %s)\n", |
| 961 | pll->name, state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 962 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 963 | |
| 964 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 965 | enum pipe pipe, bool state) |
| 966 | { |
| 967 | int reg; |
| 968 | u32 val; |
| 969 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 970 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 971 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 972 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 973 | if (HAS_DDI(dev_priv->dev)) { |
| 974 | /* DDI does not have a specific FDI_TX register */ |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 975 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 976 | val = I915_READ(reg); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 977 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 978 | } else { |
| 979 | reg = FDI_TX_CTL(pipe); |
| 980 | val = I915_READ(reg); |
| 981 | cur_state = !!(val & FDI_TX_ENABLE); |
| 982 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 983 | WARN(cur_state != state, |
| 984 | "FDI TX state assertion failure (expected %s, current %s)\n", |
| 985 | state_string(state), state_string(cur_state)); |
| 986 | } |
| 987 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 988 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 989 | |
| 990 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 991 | enum pipe pipe, bool state) |
| 992 | { |
| 993 | int reg; |
| 994 | u32 val; |
| 995 | bool cur_state; |
| 996 | |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 997 | reg = FDI_RX_CTL(pipe); |
| 998 | val = I915_READ(reg); |
| 999 | cur_state = !!(val & FDI_RX_ENABLE); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1000 | WARN(cur_state != state, |
| 1001 | "FDI RX state assertion failure (expected %s, current %s)\n", |
| 1002 | state_string(state), state_string(cur_state)); |
| 1003 | } |
| 1004 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1005 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1006 | |
| 1007 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1008 | enum pipe pipe) |
| 1009 | { |
| 1010 | int reg; |
| 1011 | u32 val; |
| 1012 | |
| 1013 | /* ILK FDI PLL is always enabled */ |
| 1014 | if (dev_priv->info->gen == 5) |
| 1015 | return; |
| 1016 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1017 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1018 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1019 | return; |
| 1020 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1021 | reg = FDI_TX_CTL(pipe); |
| 1022 | val = I915_READ(reg); |
| 1023 | WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
| 1024 | } |
| 1025 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1026 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1027 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1028 | { |
| 1029 | int reg; |
| 1030 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1031 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1032 | |
| 1033 | reg = FDI_RX_CTL(pipe); |
| 1034 | val = I915_READ(reg); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1035 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
| 1036 | WARN(cur_state != state, |
| 1037 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
| 1038 | state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1039 | } |
| 1040 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1041 | static void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1042 | enum pipe pipe) |
| 1043 | { |
| 1044 | int pp_reg, lvds_reg; |
| 1045 | u32 val; |
| 1046 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1047 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1048 | |
| 1049 | if (HAS_PCH_SPLIT(dev_priv->dev)) { |
| 1050 | pp_reg = PCH_PP_CONTROL; |
| 1051 | lvds_reg = PCH_LVDS; |
| 1052 | } else { |
| 1053 | pp_reg = PP_CONTROL; |
| 1054 | lvds_reg = LVDS; |
| 1055 | } |
| 1056 | |
| 1057 | val = I915_READ(pp_reg); |
| 1058 | if (!(val & PANEL_POWER_ON) || |
| 1059 | ((val & PANEL_UNLOCK_REGS) == PANEL_UNLOCK_REGS)) |
| 1060 | locked = false; |
| 1061 | |
| 1062 | if (I915_READ(lvds_reg) & LVDS_PIPEB_SELECT) |
| 1063 | panel_pipe = PIPE_B; |
| 1064 | |
| 1065 | WARN(panel_pipe == pipe && locked, |
| 1066 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1067 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1068 | } |
| 1069 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1070 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1071 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1072 | { |
| 1073 | int reg; |
| 1074 | u32 val; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1075 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1076 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1077 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1078 | |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1079 | /* if we need the pipe A quirk it must be always on */ |
| 1080 | if (pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) |
| 1081 | state = true; |
| 1082 | |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 1083 | if (!intel_display_power_enabled(dev_priv->dev, |
| 1084 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1085 | cur_state = false; |
| 1086 | } else { |
| 1087 | reg = PIPECONF(cpu_transcoder); |
| 1088 | val = I915_READ(reg); |
| 1089 | cur_state = !!(val & PIPECONF_ENABLE); |
| 1090 | } |
| 1091 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1092 | WARN(cur_state != state, |
| 1093 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1094 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1095 | } |
| 1096 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1097 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1098 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1099 | { |
| 1100 | int reg; |
| 1101 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1102 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1103 | |
| 1104 | reg = DSPCNTR(plane); |
| 1105 | val = I915_READ(reg); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1106 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
| 1107 | WARN(cur_state != state, |
| 1108 | "plane %c assertion failure (expected %s, current %s)\n", |
| 1109 | plane_name(plane), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1110 | } |
| 1111 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1112 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1113 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1114 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1115 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1116 | enum pipe pipe) |
| 1117 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1118 | struct drm_device *dev = dev_priv->dev; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1119 | int reg, i; |
| 1120 | u32 val; |
| 1121 | int cur_pipe; |
| 1122 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1123 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1124 | if (INTEL_INFO(dev)->gen >= 4) { |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1125 | reg = DSPCNTR(pipe); |
| 1126 | val = I915_READ(reg); |
| 1127 | WARN((val & DISPLAY_PLANE_ENABLE), |
| 1128 | "plane %c assertion failure, should be disabled but not\n", |
| 1129 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1130 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1131 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1132 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1133 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 08e2a7d | 2013-07-11 20:10:54 +0100 | [diff] [blame] | 1134 | for_each_pipe(i) { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1135 | reg = DSPCNTR(i); |
| 1136 | val = I915_READ(reg); |
| 1137 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 1138 | DISPPLANE_SEL_PIPE_SHIFT; |
| 1139 | WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1140 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1141 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1142 | } |
| 1143 | } |
| 1144 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1145 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1146 | enum pipe pipe) |
| 1147 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1148 | struct drm_device *dev = dev_priv->dev; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1149 | int reg, i; |
| 1150 | u32 val; |
| 1151 | |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1152 | if (IS_VALLEYVIEW(dev)) { |
| 1153 | for (i = 0; i < dev_priv->num_plane; i++) { |
| 1154 | reg = SPCNTR(pipe, i); |
| 1155 | val = I915_READ(reg); |
| 1156 | WARN((val & SP_ENABLE), |
| 1157 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1158 | sprite_name(pipe, i), pipe_name(pipe)); |
| 1159 | } |
| 1160 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 1161 | reg = SPRCTL(pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1162 | val = I915_READ(reg); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1163 | WARN((val & SPRITE_ENABLE), |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1164 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1165 | plane_name(pipe), pipe_name(pipe)); |
| 1166 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1167 | reg = DVSCNTR(pipe); |
| 1168 | val = I915_READ(reg); |
| 1169 | WARN((val & DVS_ENABLE), |
| 1170 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1171 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1172 | } |
| 1173 | } |
| 1174 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1175 | static void assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
| 1176 | { |
| 1177 | u32 val; |
| 1178 | bool enabled; |
| 1179 | |
Eugeni Dodonov | 9d82aa1 | 2012-05-09 15:37:17 -0300 | [diff] [blame] | 1180 | if (HAS_PCH_LPT(dev_priv->dev)) { |
| 1181 | DRM_DEBUG_DRIVER("LPT does not has PCH refclk, skipping check\n"); |
| 1182 | return; |
| 1183 | } |
| 1184 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1185 | val = I915_READ(PCH_DREF_CONTROL); |
| 1186 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | |
| 1187 | DREF_SUPERSPREAD_SOURCE_MASK)); |
| 1188 | WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
| 1189 | } |
| 1190 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1191 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1192 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1193 | { |
| 1194 | int reg; |
| 1195 | u32 val; |
| 1196 | bool enabled; |
| 1197 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1198 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1199 | val = I915_READ(reg); |
| 1200 | enabled = !!(val & TRANS_ENABLE); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1201 | WARN(enabled, |
| 1202 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1203 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1204 | } |
| 1205 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1206 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1207 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1208 | { |
| 1209 | if ((val & DP_PORT_EN) == 0) |
| 1210 | return false; |
| 1211 | |
| 1212 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1213 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); |
| 1214 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); |
| 1215 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1216 | return false; |
| 1217 | } else { |
| 1218 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1219 | return false; |
| 1220 | } |
| 1221 | return true; |
| 1222 | } |
| 1223 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1224 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1225 | enum pipe pipe, u32 val) |
| 1226 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1227 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1228 | return false; |
| 1229 | |
| 1230 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1231 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1232 | return false; |
| 1233 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1234 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1235 | return false; |
| 1236 | } |
| 1237 | return true; |
| 1238 | } |
| 1239 | |
| 1240 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1241 | enum pipe pipe, u32 val) |
| 1242 | { |
| 1243 | if ((val & LVDS_PORT_EN) == 0) |
| 1244 | return false; |
| 1245 | |
| 1246 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1247 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1248 | return false; |
| 1249 | } else { |
| 1250 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1251 | return false; |
| 1252 | } |
| 1253 | return true; |
| 1254 | } |
| 1255 | |
| 1256 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1257 | enum pipe pipe, u32 val) |
| 1258 | { |
| 1259 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1260 | return false; |
| 1261 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1262 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1263 | return false; |
| 1264 | } else { |
| 1265 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1266 | return false; |
| 1267 | } |
| 1268 | return true; |
| 1269 | } |
| 1270 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1271 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1272 | enum pipe pipe, int reg, u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1273 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1274 | u32 val = I915_READ(reg); |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1275 | WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1276 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1277 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1278 | |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1279 | WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
| 1280 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1281 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1282 | } |
| 1283 | |
| 1284 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
| 1285 | enum pipe pipe, int reg) |
| 1286 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1287 | u32 val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1288 | WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1289 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1290 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1291 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1292 | WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1293 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1294 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1295 | } |
| 1296 | |
| 1297 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1298 | enum pipe pipe) |
| 1299 | { |
| 1300 | int reg; |
| 1301 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1302 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1303 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1304 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1305 | 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] | 1306 | |
| 1307 | reg = PCH_ADPA; |
| 1308 | val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1309 | WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1310 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1311 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1312 | |
| 1313 | reg = PCH_LVDS; |
| 1314 | val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1315 | WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1316 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1317 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1318 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1319 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1320 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1321 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1322 | } |
| 1323 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1324 | static void vlv_enable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1325 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1326 | struct drm_device *dev = crtc->base.dev; |
| 1327 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1328 | int reg = DPLL(crtc->pipe); |
| 1329 | u32 dpll = crtc->config.dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1330 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1331 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1332 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1333 | /* No really, not for ILK+ */ |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1334 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); |
| 1335 | |
| 1336 | /* PLL is protected by panel, make sure we can write it */ |
| 1337 | if (IS_MOBILE(dev_priv->dev) && !IS_I830(dev_priv->dev)) |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1338 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1339 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1340 | I915_WRITE(reg, dpll); |
| 1341 | POSTING_READ(reg); |
| 1342 | udelay(150); |
| 1343 | |
| 1344 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1345 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); |
| 1346 | |
| 1347 | I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md); |
| 1348 | POSTING_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1349 | |
| 1350 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1351 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1352 | POSTING_READ(reg); |
| 1353 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1354 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1355 | POSTING_READ(reg); |
| 1356 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1357 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1358 | POSTING_READ(reg); |
| 1359 | udelay(150); /* wait for warmup */ |
| 1360 | } |
| 1361 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1362 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1363 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1364 | struct drm_device *dev = crtc->base.dev; |
| 1365 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1366 | int reg = DPLL(crtc->pipe); |
| 1367 | u32 dpll = crtc->config.dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1368 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1369 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1370 | |
| 1371 | /* No really, not for ILK+ */ |
| 1372 | BUG_ON(dev_priv->info->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1373 | |
| 1374 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1375 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1376 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1377 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1378 | I915_WRITE(reg, dpll); |
| 1379 | |
| 1380 | /* Wait for the clocks to stabilize. */ |
| 1381 | POSTING_READ(reg); |
| 1382 | udelay(150); |
| 1383 | |
| 1384 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1385 | I915_WRITE(DPLL_MD(crtc->pipe), |
| 1386 | crtc->config.dpll_hw_state.dpll_md); |
| 1387 | } else { |
| 1388 | /* The pixel multiplier can only be updated once the |
| 1389 | * DPLL is enabled and the clocks are stable. |
| 1390 | * |
| 1391 | * So write it again. |
| 1392 | */ |
| 1393 | I915_WRITE(reg, dpll); |
| 1394 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1395 | |
| 1396 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1397 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1398 | POSTING_READ(reg); |
| 1399 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1400 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1401 | POSTING_READ(reg); |
| 1402 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1403 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1404 | POSTING_READ(reg); |
| 1405 | udelay(150); /* wait for warmup */ |
| 1406 | } |
| 1407 | |
| 1408 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame^] | 1409 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1410 | * @dev_priv: i915 private structure |
| 1411 | * @pipe: pipe PLL to disable |
| 1412 | * |
| 1413 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1414 | * |
| 1415 | * Note! This is for pre-ILK only. |
| 1416 | */ |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame^] | 1417 | static void i9xx_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1418 | { |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1419 | /* Don't disable pipe A or pipe A PLLs if needed */ |
| 1420 | if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE)) |
| 1421 | return; |
| 1422 | |
| 1423 | /* Make sure the pipe isn't still relying on us */ |
| 1424 | assert_pipe_disabled(dev_priv, pipe); |
| 1425 | |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame^] | 1426 | I915_WRITE(DPLL(pipe), 0); |
| 1427 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1428 | } |
| 1429 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1430 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, int port) |
| 1431 | { |
| 1432 | u32 port_mask; |
| 1433 | |
| 1434 | if (!port) |
| 1435 | port_mask = DPLL_PORTB_READY_MASK; |
| 1436 | else |
| 1437 | port_mask = DPLL_PORTC_READY_MASK; |
| 1438 | |
| 1439 | if (wait_for((I915_READ(DPLL(0)) & port_mask) == 0, 1000)) |
| 1440 | WARN(1, "timed out waiting for port %c ready: 0x%08x\n", |
| 1441 | 'B' + port, I915_READ(DPLL(0))); |
| 1442 | } |
| 1443 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1444 | /** |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 1445 | * ironlake_enable_shared_dpll - enable PCH PLL |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1446 | * @dev_priv: i915 private structure |
| 1447 | * @pipe: pipe PLL to enable |
| 1448 | * |
| 1449 | * The PCH PLL needs to be enabled before the PCH transcoder, since it |
| 1450 | * drives the transcoder clock. |
| 1451 | */ |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1452 | static void ironlake_enable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1453 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1454 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 1455 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1456 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1457 | /* PCH PLLs only available on ILK, SNB and IVB */ |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1458 | BUG_ON(dev_priv->info->gen < 5); |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1459 | if (WARN_ON(pll == NULL)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1460 | return; |
| 1461 | |
| 1462 | if (WARN_ON(pll->refcount == 0)) |
| 1463 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1464 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1465 | DRM_DEBUG_KMS("enable %s (active %d, on? %d)for crtc %d\n", |
| 1466 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1467 | crtc->base.base.id); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1468 | |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1469 | if (pll->active++) { |
| 1470 | WARN_ON(!pll->on); |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1471 | assert_shared_dpll_enabled(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1472 | return; |
| 1473 | } |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1474 | WARN_ON(pll->on); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1475 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1476 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1477 | pll->enable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1478 | pll->on = true; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1479 | } |
| 1480 | |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1481 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1482 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1483 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 1484 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 4c609cb | 2011-09-02 12:52:11 -0700 | [diff] [blame] | 1485 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1486 | /* PCH only available on ILK+ */ |
| 1487 | BUG_ON(dev_priv->info->gen < 5); |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1488 | if (WARN_ON(pll == NULL)) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1489 | return; |
| 1490 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1491 | if (WARN_ON(pll->refcount == 0)) |
| 1492 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1493 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1494 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
| 1495 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1496 | crtc->base.base.id); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1497 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1498 | if (WARN_ON(pll->active == 0)) { |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1499 | assert_shared_dpll_disabled(dev_priv, pll); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1500 | return; |
| 1501 | } |
| 1502 | |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1503 | assert_shared_dpll_enabled(dev_priv, pll); |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1504 | WARN_ON(!pll->on); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1505 | if (--pll->active) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1506 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1507 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1508 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1509 | pll->disable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1510 | pll->on = false; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1511 | } |
| 1512 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1513 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1514 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1515 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1516 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1517 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1518 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1519 | uint32_t reg, val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1520 | |
| 1521 | /* PCH only available on ILK+ */ |
| 1522 | BUG_ON(dev_priv->info->gen < 5); |
| 1523 | |
| 1524 | /* Make sure PCH DPLL is enabled */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 1525 | assert_shared_dpll_enabled(dev_priv, |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1526 | intel_crtc_to_shared_dpll(intel_crtc)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1527 | |
| 1528 | /* FDI must be feeding us bits for PCH ports */ |
| 1529 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1530 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1531 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1532 | if (HAS_PCH_CPT(dev)) { |
| 1533 | /* Workaround: Set the timing override bit before enabling the |
| 1534 | * pch transcoder. */ |
| 1535 | reg = TRANS_CHICKEN2(pipe); |
| 1536 | val = I915_READ(reg); |
| 1537 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1538 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1539 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1540 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1541 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1542 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1543 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1544 | |
| 1545 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1546 | /* |
| 1547 | * make the BPC in transcoder be consistent with |
| 1548 | * that in pipeconf reg. |
| 1549 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1550 | val &= ~PIPECONF_BPC_MASK; |
| 1551 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1552 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1553 | |
| 1554 | val &= ~TRANS_INTERLACE_MASK; |
| 1555 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1556 | if (HAS_PCH_IBX(dev_priv->dev) && |
| 1557 | intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) |
| 1558 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1559 | else |
| 1560 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1561 | else |
| 1562 | val |= TRANS_PROGRESSIVE; |
| 1563 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1564 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1565 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1566 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1567 | } |
| 1568 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1569 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1570 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1571 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1572 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1573 | |
| 1574 | /* PCH only available on ILK+ */ |
| 1575 | BUG_ON(dev_priv->info->gen < 5); |
| 1576 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1577 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1578 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1579 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1580 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1581 | /* Workaround: set timing override bit. */ |
| 1582 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1583 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1584 | I915_WRITE(_TRANSA_CHICKEN2, val); |
| 1585 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1586 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1587 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1588 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1589 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1590 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1591 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1592 | else |
| 1593 | val |= TRANS_PROGRESSIVE; |
| 1594 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1595 | I915_WRITE(LPT_TRANSCONF, val); |
| 1596 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1597 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1598 | } |
| 1599 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1600 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1601 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1602 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1603 | struct drm_device *dev = dev_priv->dev; |
| 1604 | uint32_t reg, val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1605 | |
| 1606 | /* FDI relies on the transcoder */ |
| 1607 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1608 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1609 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1610 | /* Ports must be off as well */ |
| 1611 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1612 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1613 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1614 | val = I915_READ(reg); |
| 1615 | val &= ~TRANS_ENABLE; |
| 1616 | I915_WRITE(reg, val); |
| 1617 | /* wait for PCH transcoder off, transcoder state */ |
| 1618 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1619 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1620 | |
| 1621 | if (!HAS_PCH_IBX(dev)) { |
| 1622 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1623 | reg = TRANS_CHICKEN2(pipe); |
| 1624 | val = I915_READ(reg); |
| 1625 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1626 | I915_WRITE(reg, val); |
| 1627 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1628 | } |
| 1629 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 1630 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1631 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1632 | u32 val; |
| 1633 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1634 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1635 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1636 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1637 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1638 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1639 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1640 | |
| 1641 | /* Workaround: clear timing override bit. */ |
| 1642 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1643 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1644 | I915_WRITE(_TRANSA_CHICKEN2, val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1645 | } |
| 1646 | |
| 1647 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1648 | * intel_enable_pipe - enable a pipe, asserting requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1649 | * @dev_priv: i915 private structure |
| 1650 | * @pipe: pipe to enable |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1651 | * @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] | 1652 | * |
| 1653 | * Enable @pipe, making sure that various hardware specific requirements |
| 1654 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
| 1655 | * |
| 1656 | * @pipe should be %PIPE_A or %PIPE_B. |
| 1657 | * |
| 1658 | * Will wait until the pipe is actually running (i.e. first vblank) before |
| 1659 | * returning. |
| 1660 | */ |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1661 | static void intel_enable_pipe(struct drm_i915_private *dev_priv, enum pipe pipe, |
| 1662 | bool pch_port) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1663 | { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1664 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1665 | pipe); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1666 | enum pipe pch_transcoder; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1667 | int reg; |
| 1668 | u32 val; |
| 1669 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1670 | assert_planes_disabled(dev_priv, pipe); |
| 1671 | assert_sprites_disabled(dev_priv, pipe); |
| 1672 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 1673 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1674 | pch_transcoder = TRANSCODER_A; |
| 1675 | else |
| 1676 | pch_transcoder = pipe; |
| 1677 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1678 | /* |
| 1679 | * A pipe without a PLL won't actually be able to drive bits from |
| 1680 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 1681 | * need the check. |
| 1682 | */ |
| 1683 | if (!HAS_PCH_SPLIT(dev_priv->dev)) |
| 1684 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1685 | else { |
| 1686 | if (pch_port) { |
| 1687 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1688 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1689 | assert_fdi_tx_pll_enabled(dev_priv, |
| 1690 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1691 | } |
| 1692 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 1693 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1694 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1695 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1696 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1697 | if (val & PIPECONF_ENABLE) |
| 1698 | return; |
| 1699 | |
| 1700 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1701 | intel_wait_for_vblank(dev_priv->dev, pipe); |
| 1702 | } |
| 1703 | |
| 1704 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1705 | * intel_disable_pipe - disable a pipe, asserting requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1706 | * @dev_priv: i915 private structure |
| 1707 | * @pipe: pipe to disable |
| 1708 | * |
| 1709 | * Disable @pipe, making sure that various hardware specific requirements |
| 1710 | * are met, if applicable, e.g. plane disabled, panel fitter off, etc. |
| 1711 | * |
| 1712 | * @pipe should be %PIPE_A or %PIPE_B. |
| 1713 | * |
| 1714 | * Will wait until the pipe has shut down before returning. |
| 1715 | */ |
| 1716 | static void intel_disable_pipe(struct drm_i915_private *dev_priv, |
| 1717 | enum pipe pipe) |
| 1718 | { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1719 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1720 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1721 | int reg; |
| 1722 | u32 val; |
| 1723 | |
| 1724 | /* |
| 1725 | * Make sure planes won't keep trying to pump pixels to us, |
| 1726 | * or we might hang the display. |
| 1727 | */ |
| 1728 | assert_planes_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1729 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1730 | |
| 1731 | /* Don't disable pipe A or pipe A PLLs if needed */ |
| 1732 | if (pipe == PIPE_A && (dev_priv->quirks & QUIRK_PIPEA_FORCE)) |
| 1733 | return; |
| 1734 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1735 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1736 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1737 | if ((val & PIPECONF_ENABLE) == 0) |
| 1738 | return; |
| 1739 | |
| 1740 | I915_WRITE(reg, val & ~PIPECONF_ENABLE); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1741 | intel_wait_for_pipe_off(dev_priv->dev, pipe); |
| 1742 | } |
| 1743 | |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 1744 | /* |
| 1745 | * Plane regs are double buffered, going from enabled->disabled needs a |
| 1746 | * trigger in order to latch. The display address reg provides this. |
| 1747 | */ |
Eugeni Dodonov | 6f1d69b | 2012-04-18 15:29:25 -0300 | [diff] [blame] | 1748 | void intel_flush_display_plane(struct drm_i915_private *dev_priv, |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 1749 | enum plane plane) |
| 1750 | { |
Damien Lespiau | 14f8614 | 2012-10-29 15:24:49 +0000 | [diff] [blame] | 1751 | if (dev_priv->info->gen >= 4) |
| 1752 | I915_WRITE(DSPSURF(plane), I915_READ(DSPSURF(plane))); |
| 1753 | else |
| 1754 | I915_WRITE(DSPADDR(plane), I915_READ(DSPADDR(plane))); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 1755 | } |
| 1756 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1757 | /** |
| 1758 | * intel_enable_plane - enable a display plane on a given pipe |
| 1759 | * @dev_priv: i915 private structure |
| 1760 | * @plane: plane to enable |
| 1761 | * @pipe: pipe being fed |
| 1762 | * |
| 1763 | * Enable @plane on @pipe, making sure that @pipe is running first. |
| 1764 | */ |
| 1765 | static void intel_enable_plane(struct drm_i915_private *dev_priv, |
| 1766 | enum plane plane, enum pipe pipe) |
| 1767 | { |
| 1768 | int reg; |
| 1769 | u32 val; |
| 1770 | |
| 1771 | /* If the pipe isn't enabled, we can't pump pixels and may hang */ |
| 1772 | assert_pipe_enabled(dev_priv, pipe); |
| 1773 | |
| 1774 | reg = DSPCNTR(plane); |
| 1775 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1776 | if (val & DISPLAY_PLANE_ENABLE) |
| 1777 | return; |
| 1778 | |
| 1779 | I915_WRITE(reg, val | DISPLAY_PLANE_ENABLE); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 1780 | intel_flush_display_plane(dev_priv, plane); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1781 | intel_wait_for_vblank(dev_priv->dev, pipe); |
| 1782 | } |
| 1783 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1784 | /** |
| 1785 | * intel_disable_plane - disable a display plane |
| 1786 | * @dev_priv: i915 private structure |
| 1787 | * @plane: plane to disable |
| 1788 | * @pipe: pipe consuming the data |
| 1789 | * |
| 1790 | * Disable @plane; should be an independent operation. |
| 1791 | */ |
| 1792 | static void intel_disable_plane(struct drm_i915_private *dev_priv, |
| 1793 | enum plane plane, enum pipe pipe) |
| 1794 | { |
| 1795 | int reg; |
| 1796 | u32 val; |
| 1797 | |
| 1798 | reg = DSPCNTR(plane); |
| 1799 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 1800 | if ((val & DISPLAY_PLANE_ENABLE) == 0) |
| 1801 | return; |
| 1802 | |
| 1803 | I915_WRITE(reg, val & ~DISPLAY_PLANE_ENABLE); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1804 | intel_flush_display_plane(dev_priv, plane); |
| 1805 | intel_wait_for_vblank(dev_priv->dev, pipe); |
| 1806 | } |
| 1807 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 1808 | static bool need_vtd_wa(struct drm_device *dev) |
| 1809 | { |
| 1810 | #ifdef CONFIG_INTEL_IOMMU |
| 1811 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 1812 | return true; |
| 1813 | #endif |
| 1814 | return false; |
| 1815 | } |
| 1816 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 1817 | int |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1818 | intel_pin_and_fence_fb_obj(struct drm_device *dev, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1819 | struct drm_i915_gem_object *obj, |
Chris Wilson | 919926a | 2010-11-12 13:42:53 +0000 | [diff] [blame] | 1820 | struct intel_ring_buffer *pipelined) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1821 | { |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1822 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1823 | u32 alignment; |
| 1824 | int ret; |
| 1825 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1826 | switch (obj->tiling_mode) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1827 | case I915_TILING_NONE: |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 1828 | if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
| 1829 | alignment = 128 * 1024; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1830 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 1831 | alignment = 4 * 1024; |
| 1832 | else |
| 1833 | alignment = 64 * 1024; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1834 | break; |
| 1835 | case I915_TILING_X: |
| 1836 | /* pin() will align the object as required by fence */ |
| 1837 | alignment = 0; |
| 1838 | break; |
| 1839 | case I915_TILING_Y: |
Daniel Vetter | 8bb6e95 | 2013-04-06 23:54:56 +0200 | [diff] [blame] | 1840 | /* Despite that we check this in framebuffer_init userspace can |
| 1841 | * screw us over and change the tiling after the fact. Only |
| 1842 | * pinned buffers can't change their tiling. */ |
| 1843 | DRM_DEBUG_DRIVER("Y tiled not allowed for scan out buffers\n"); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1844 | return -EINVAL; |
| 1845 | default: |
| 1846 | BUG(); |
| 1847 | } |
| 1848 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 1849 | /* Note that the w/a also requires 64 PTE of padding following the |
| 1850 | * bo. We currently fill all unused PTE with the shadow page and so |
| 1851 | * we should always have valid PTE following the scanout preventing |
| 1852 | * the VT-d warning. |
| 1853 | */ |
| 1854 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 1855 | alignment = 256 * 1024; |
| 1856 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1857 | dev_priv->mm.interruptible = false; |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 1858 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1859 | if (ret) |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1860 | goto err_interruptible; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1861 | |
| 1862 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 1863 | * fence, whereas 965+ only requires a fence if using |
| 1864 | * framebuffer compression. For simplicity, we always install |
| 1865 | * a fence as the cost is not that onerous. |
| 1866 | */ |
Chris Wilson | 06d9813 | 2012-04-17 15:31:24 +0100 | [diff] [blame] | 1867 | ret = i915_gem_object_get_fence(obj); |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 1868 | if (ret) |
| 1869 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 1870 | |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 1871 | i915_gem_object_pin_fence(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1872 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1873 | dev_priv->mm.interruptible = true; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1874 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1875 | |
| 1876 | err_unpin: |
| 1877 | i915_gem_object_unpin(obj); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 1878 | err_interruptible: |
| 1879 | dev_priv->mm.interruptible = true; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 1880 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 1881 | } |
| 1882 | |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 1883 | void intel_unpin_fb_obj(struct drm_i915_gem_object *obj) |
| 1884 | { |
| 1885 | i915_gem_object_unpin_fence(obj); |
| 1886 | i915_gem_object_unpin(obj); |
| 1887 | } |
| 1888 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1889 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
| 1890 | * is assumed to be a power-of-two. */ |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 1891 | unsigned long intel_gen4_compute_page_offset(int *x, int *y, |
| 1892 | unsigned int tiling_mode, |
| 1893 | unsigned int cpp, |
| 1894 | unsigned int pitch) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1895 | { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 1896 | if (tiling_mode != I915_TILING_NONE) { |
| 1897 | unsigned int tile_rows, tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1898 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 1899 | tile_rows = *y / 8; |
| 1900 | *y %= 8; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1901 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 1902 | tiles = *x / (512/cpp); |
| 1903 | *x %= 512/cpp; |
| 1904 | |
| 1905 | return tile_rows * pitch * 8 + tiles * 4096; |
| 1906 | } else { |
| 1907 | unsigned int offset; |
| 1908 | |
| 1909 | offset = *y * pitch + *x * cpp; |
| 1910 | *y = 0; |
| 1911 | *x = (offset & 4095) / cpp; |
| 1912 | return offset & -4096; |
| 1913 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1914 | } |
| 1915 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 1916 | static int i9xx_update_plane(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 1917 | int x, int y) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1918 | { |
| 1919 | struct drm_device *dev = crtc->dev; |
| 1920 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1921 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 1922 | struct intel_framebuffer *intel_fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1923 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1924 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 1925 | unsigned long linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1926 | u32 dspcntr; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1927 | u32 reg; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1928 | |
| 1929 | switch (plane) { |
| 1930 | case 0: |
| 1931 | case 1: |
| 1932 | break; |
| 1933 | default: |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 1934 | DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane)); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1935 | return -EINVAL; |
| 1936 | } |
| 1937 | |
| 1938 | intel_fb = to_intel_framebuffer(fb); |
| 1939 | obj = intel_fb->obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1940 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1941 | reg = DSPCNTR(plane); |
| 1942 | dspcntr = I915_READ(reg); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1943 | /* Mask out pixel format bits in case we change it */ |
| 1944 | dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 1945 | switch (fb->pixel_format) { |
| 1946 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1947 | dspcntr |= DISPPLANE_8BPP; |
| 1948 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 1949 | case DRM_FORMAT_XRGB1555: |
| 1950 | case DRM_FORMAT_ARGB1555: |
| 1951 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1952 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 1953 | case DRM_FORMAT_RGB565: |
| 1954 | dspcntr |= DISPPLANE_BGRX565; |
| 1955 | break; |
| 1956 | case DRM_FORMAT_XRGB8888: |
| 1957 | case DRM_FORMAT_ARGB8888: |
| 1958 | dspcntr |= DISPPLANE_BGRX888; |
| 1959 | break; |
| 1960 | case DRM_FORMAT_XBGR8888: |
| 1961 | case DRM_FORMAT_ABGR8888: |
| 1962 | dspcntr |= DISPPLANE_RGBX888; |
| 1963 | break; |
| 1964 | case DRM_FORMAT_XRGB2101010: |
| 1965 | case DRM_FORMAT_ARGB2101010: |
| 1966 | dspcntr |= DISPPLANE_BGRX101010; |
| 1967 | break; |
| 1968 | case DRM_FORMAT_XBGR2101010: |
| 1969 | case DRM_FORMAT_ABGR2101010: |
| 1970 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1971 | break; |
| 1972 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 1973 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1974 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 1975 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 1976 | if (INTEL_INFO(dev)->gen >= 4) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1977 | if (obj->tiling_mode != I915_TILING_NONE) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1978 | dspcntr |= DISPPLANE_TILED; |
| 1979 | else |
| 1980 | dspcntr &= ~DISPPLANE_TILED; |
| 1981 | } |
| 1982 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 1983 | if (IS_G4X(dev)) |
| 1984 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 1985 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 1986 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1987 | |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 1988 | linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 1989 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1990 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1991 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 1992 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
| 1993 | fb->bits_per_pixel / 8, |
| 1994 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1995 | linear_offset -= intel_crtc->dspaddr_offset; |
| 1996 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 1997 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 1998 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 1999 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2000 | DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n", |
| 2001 | i915_gem_obj_ggtt_offset(obj), linear_offset, x, y, |
| 2002 | fb->pitches[0]); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2003 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2004 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2005 | I915_MODIFY_DISPBASE(DSPSURF(plane), |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2006 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2007 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2008 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2009 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2010 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2011 | POSTING_READ(reg); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2012 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2013 | return 0; |
| 2014 | } |
| 2015 | |
| 2016 | static int ironlake_update_plane(struct drm_crtc *crtc, |
| 2017 | struct drm_framebuffer *fb, int x, int y) |
| 2018 | { |
| 2019 | struct drm_device *dev = crtc->dev; |
| 2020 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2021 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2022 | struct intel_framebuffer *intel_fb; |
| 2023 | struct drm_i915_gem_object *obj; |
| 2024 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2025 | unsigned long linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2026 | u32 dspcntr; |
| 2027 | u32 reg; |
| 2028 | |
| 2029 | switch (plane) { |
| 2030 | case 0: |
| 2031 | case 1: |
Jesse Barnes | 27f8227 | 2011-09-02 12:54:37 -0700 | [diff] [blame] | 2032 | case 2: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2033 | break; |
| 2034 | default: |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 2035 | DRM_ERROR("Can't update plane %c in SAREA\n", plane_name(plane)); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2036 | return -EINVAL; |
| 2037 | } |
| 2038 | |
| 2039 | intel_fb = to_intel_framebuffer(fb); |
| 2040 | obj = intel_fb->obj; |
| 2041 | |
| 2042 | reg = DSPCNTR(plane); |
| 2043 | dspcntr = I915_READ(reg); |
| 2044 | /* Mask out pixel format bits in case we change it */ |
| 2045 | dspcntr &= ~DISPPLANE_PIXFORMAT_MASK; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2046 | switch (fb->pixel_format) { |
| 2047 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2048 | dspcntr |= DISPPLANE_8BPP; |
| 2049 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2050 | case DRM_FORMAT_RGB565: |
| 2051 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2052 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2053 | case DRM_FORMAT_XRGB8888: |
| 2054 | case DRM_FORMAT_ARGB8888: |
| 2055 | dspcntr |= DISPPLANE_BGRX888; |
| 2056 | break; |
| 2057 | case DRM_FORMAT_XBGR8888: |
| 2058 | case DRM_FORMAT_ABGR8888: |
| 2059 | dspcntr |= DISPPLANE_RGBX888; |
| 2060 | break; |
| 2061 | case DRM_FORMAT_XRGB2101010: |
| 2062 | case DRM_FORMAT_ARGB2101010: |
| 2063 | dspcntr |= DISPPLANE_BGRX101010; |
| 2064 | break; |
| 2065 | case DRM_FORMAT_XBGR2101010: |
| 2066 | case DRM_FORMAT_ABGR2101010: |
| 2067 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2068 | break; |
| 2069 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2070 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2071 | } |
| 2072 | |
| 2073 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2074 | dspcntr |= DISPPLANE_TILED; |
| 2075 | else |
| 2076 | dspcntr &= ~DISPPLANE_TILED; |
| 2077 | |
| 2078 | /* must disable */ |
| 2079 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2080 | |
| 2081 | I915_WRITE(reg, dspcntr); |
| 2082 | |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2083 | linear_offset = y * fb->pitches[0] + x * (fb->bits_per_pixel / 8); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2084 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2085 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
| 2086 | fb->bits_per_pixel / 8, |
| 2087 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2088 | linear_offset -= intel_crtc->dspaddr_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2089 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2090 | DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n", |
| 2091 | i915_gem_obj_ggtt_offset(obj), linear_offset, x, y, |
| 2092 | fb->pitches[0]); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2093 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2094 | I915_MODIFY_DISPBASE(DSPSURF(plane), |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2095 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2096 | if (IS_HASWELL(dev)) { |
| 2097 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2098 | } else { |
| 2099 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2100 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2101 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2102 | POSTING_READ(reg); |
| 2103 | |
| 2104 | return 0; |
| 2105 | } |
| 2106 | |
| 2107 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 2108 | static int |
| 2109 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 2110 | int x, int y, enum mode_set_atomic state) |
| 2111 | { |
| 2112 | struct drm_device *dev = crtc->dev; |
| 2113 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2114 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2115 | if (dev_priv->display.disable_fbc) |
| 2116 | dev_priv->display.disable_fbc(dev); |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 2117 | intel_increase_pllclock(crtc); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2118 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2119 | return dev_priv->display.update_plane(crtc, fb, x, y); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2122 | void intel_display_handle_reset(struct drm_device *dev) |
| 2123 | { |
| 2124 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2125 | struct drm_crtc *crtc; |
| 2126 | |
| 2127 | /* |
| 2128 | * Flips in the rings have been nuked by the reset, |
| 2129 | * so complete all pending flips so that user space |
| 2130 | * will get its events and not get stuck. |
| 2131 | * |
| 2132 | * Also update the base address of all primary |
| 2133 | * planes to the the last fb to make sure we're |
| 2134 | * showing the correct fb after a reset. |
| 2135 | * |
| 2136 | * Need to make two loops over the crtcs so that we |
| 2137 | * don't try to grab a crtc mutex before the |
| 2138 | * pending_flip_queue really got woken up. |
| 2139 | */ |
| 2140 | |
| 2141 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 2142 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2143 | enum plane plane = intel_crtc->plane; |
| 2144 | |
| 2145 | intel_prepare_page_flip(dev, plane); |
| 2146 | intel_finish_page_flip_plane(dev, plane); |
| 2147 | } |
| 2148 | |
| 2149 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 2150 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2151 | |
| 2152 | mutex_lock(&crtc->mutex); |
| 2153 | if (intel_crtc->active) |
| 2154 | dev_priv->display.update_plane(crtc, crtc->fb, |
| 2155 | crtc->x, crtc->y); |
| 2156 | mutex_unlock(&crtc->mutex); |
| 2157 | } |
| 2158 | } |
| 2159 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2160 | static int |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2161 | intel_finish_fb(struct drm_framebuffer *old_fb) |
| 2162 | { |
| 2163 | struct drm_i915_gem_object *obj = to_intel_framebuffer(old_fb)->obj; |
| 2164 | struct drm_i915_private *dev_priv = obj->base.dev->dev_private; |
| 2165 | bool was_interruptible = dev_priv->mm.interruptible; |
| 2166 | int ret; |
| 2167 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2168 | /* Big Hammer, we also need to ensure that any pending |
| 2169 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 2170 | * current scanout is retired before unpinning the old |
| 2171 | * framebuffer. |
| 2172 | * |
| 2173 | * This should only fail upon a hung GPU, in which case we |
| 2174 | * can safely continue. |
| 2175 | */ |
| 2176 | dev_priv->mm.interruptible = false; |
| 2177 | ret = i915_gem_object_finish_gpu(obj); |
| 2178 | dev_priv->mm.interruptible = was_interruptible; |
| 2179 | |
| 2180 | return ret; |
| 2181 | } |
| 2182 | |
Ville Syrjälä | 198598d | 2012-10-31 17:50:24 +0200 | [diff] [blame] | 2183 | static void intel_crtc_update_sarea_pos(struct drm_crtc *crtc, int x, int y) |
| 2184 | { |
| 2185 | struct drm_device *dev = crtc->dev; |
| 2186 | struct drm_i915_master_private *master_priv; |
| 2187 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2188 | |
| 2189 | if (!dev->primary->master) |
| 2190 | return; |
| 2191 | |
| 2192 | master_priv = dev->primary->master->driver_priv; |
| 2193 | if (!master_priv->sarea_priv) |
| 2194 | return; |
| 2195 | |
| 2196 | switch (intel_crtc->pipe) { |
| 2197 | case 0: |
| 2198 | master_priv->sarea_priv->pipeA_x = x; |
| 2199 | master_priv->sarea_priv->pipeA_y = y; |
| 2200 | break; |
| 2201 | case 1: |
| 2202 | master_priv->sarea_priv->pipeB_x = x; |
| 2203 | master_priv->sarea_priv->pipeB_y = y; |
| 2204 | break; |
| 2205 | default: |
| 2206 | break; |
| 2207 | } |
| 2208 | } |
| 2209 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2210 | static int |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2211 | intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2212 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2213 | { |
| 2214 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2215 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2216 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2217 | struct drm_framebuffer *old_fb; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2218 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2219 | |
| 2220 | /* no fb bound */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2221 | if (!fb) { |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2222 | DRM_ERROR("No FB bound\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2223 | return 0; |
| 2224 | } |
| 2225 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 2226 | if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 2227 | DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n", |
| 2228 | plane_name(intel_crtc->plane), |
| 2229 | INTEL_INFO(dev)->num_pipes); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2230 | return -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2231 | } |
| 2232 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2233 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 265db95 | 2010-09-20 15:41:01 +0100 | [diff] [blame] | 2234 | ret = intel_pin_and_fence_fb_obj(dev, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2235 | to_intel_framebuffer(fb)->obj, |
Chris Wilson | 919926a | 2010-11-12 13:42:53 +0000 | [diff] [blame] | 2236 | NULL); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2237 | if (ret != 0) { |
| 2238 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2239 | DRM_ERROR("pin & fence failed\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2240 | return ret; |
| 2241 | } |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2242 | |
Jesse Barnes | 4d6a3e6 | 2013-06-26 01:38:18 +0300 | [diff] [blame] | 2243 | /* Update pipe size and adjust fitter if needed */ |
| 2244 | if (i915_fastboot) { |
| 2245 | I915_WRITE(PIPESRC(intel_crtc->pipe), |
| 2246 | ((crtc->mode.hdisplay - 1) << 16) | |
| 2247 | (crtc->mode.vdisplay - 1)); |
| 2248 | if (!intel_crtc->config.pch_pfit.size && |
| 2249 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
| 2250 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
| 2251 | I915_WRITE(PF_CTL(intel_crtc->pipe), 0); |
| 2252 | I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0); |
| 2253 | I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0); |
| 2254 | } |
| 2255 | } |
| 2256 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2257 | ret = dev_priv->display.update_plane(crtc, fb, x, y); |
Chris Wilson | 4e6cfef | 2010-08-08 13:20:19 +0100 | [diff] [blame] | 2258 | if (ret) { |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2259 | intel_unpin_fb_obj(to_intel_framebuffer(fb)->obj); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2260 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2261 | DRM_ERROR("failed to update base address\n"); |
Chris Wilson | 4e6cfef | 2010-08-08 13:20:19 +0100 | [diff] [blame] | 2262 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2263 | } |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2264 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2265 | old_fb = crtc->fb; |
| 2266 | crtc->fb = fb; |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 2267 | crtc->x = x; |
| 2268 | crtc->y = y; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2269 | |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 2270 | if (old_fb) { |
Daniel Vetter | d7697ee | 2013-06-02 17:23:01 +0200 | [diff] [blame] | 2271 | if (intel_crtc->active && old_fb != fb) |
| 2272 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2273 | intel_unpin_fb_obj(to_intel_framebuffer(old_fb)->obj); |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 2274 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2275 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2276 | intel_update_fbc(dev); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2277 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2278 | |
Ville Syrjälä | 198598d | 2012-10-31 17:50:24 +0200 | [diff] [blame] | 2279 | intel_crtc_update_sarea_pos(crtc, x, y); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2280 | |
| 2281 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2282 | } |
| 2283 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2284 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 2285 | { |
| 2286 | struct drm_device *dev = crtc->dev; |
| 2287 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2288 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2289 | int pipe = intel_crtc->pipe; |
| 2290 | u32 reg, temp; |
| 2291 | |
| 2292 | /* enable normal train */ |
| 2293 | reg = FDI_TX_CTL(pipe); |
| 2294 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 2295 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2296 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 2297 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 2298 | } else { |
| 2299 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2300 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2301 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2302 | I915_WRITE(reg, temp); |
| 2303 | |
| 2304 | reg = FDI_RX_CTL(pipe); |
| 2305 | temp = I915_READ(reg); |
| 2306 | if (HAS_PCH_CPT(dev)) { |
| 2307 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2308 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 2309 | } else { |
| 2310 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2311 | temp |= FDI_LINK_TRAIN_NONE; |
| 2312 | } |
| 2313 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 2314 | |
| 2315 | /* wait one idle pattern time */ |
| 2316 | POSTING_READ(reg); |
| 2317 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2318 | |
| 2319 | /* IVB wants error correction enabled */ |
| 2320 | if (IS_IVYBRIDGE(dev)) |
| 2321 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 2322 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2323 | } |
| 2324 | |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 2325 | static bool pipe_has_enabled_pch(struct intel_crtc *intel_crtc) |
| 2326 | { |
| 2327 | return intel_crtc->base.enabled && intel_crtc->config.has_pch_encoder; |
| 2328 | } |
| 2329 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2330 | static void ivb_modeset_global_resources(struct drm_device *dev) |
| 2331 | { |
| 2332 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2333 | struct intel_crtc *pipe_B_crtc = |
| 2334 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]); |
| 2335 | struct intel_crtc *pipe_C_crtc = |
| 2336 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]); |
| 2337 | uint32_t temp; |
| 2338 | |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 2339 | /* |
| 2340 | * When everything is off disable fdi C so that we could enable fdi B |
| 2341 | * with all lanes. Note that we don't care about enabled pipes without |
| 2342 | * an enabled pch encoder. |
| 2343 | */ |
| 2344 | if (!pipe_has_enabled_pch(pipe_B_crtc) && |
| 2345 | !pipe_has_enabled_pch(pipe_C_crtc)) { |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2346 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 2347 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 2348 | |
| 2349 | temp = I915_READ(SOUTH_CHICKEN1); |
| 2350 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 2351 | DRM_DEBUG_KMS("disabling fdi C rx\n"); |
| 2352 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 2353 | } |
| 2354 | } |
| 2355 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2356 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 2357 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 2358 | { |
| 2359 | struct drm_device *dev = crtc->dev; |
| 2360 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2361 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2362 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2363 | int plane = intel_crtc->plane; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2364 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2365 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2366 | /* FDI needs bits from pipe & plane first */ |
| 2367 | assert_pipe_enabled(dev_priv, pipe); |
| 2368 | assert_plane_enabled(dev_priv, plane); |
| 2369 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2370 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 2371 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2372 | reg = FDI_RX_IMR(pipe); |
| 2373 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2374 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 2375 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2376 | I915_WRITE(reg, temp); |
| 2377 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2378 | udelay(150); |
| 2379 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2380 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2381 | reg = FDI_TX_CTL(pipe); |
| 2382 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 2383 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
| 2384 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2385 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2386 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2387 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2388 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2389 | reg = FDI_RX_CTL(pipe); |
| 2390 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2391 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2392 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2393 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 2394 | |
| 2395 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2396 | udelay(150); |
| 2397 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2398 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 2399 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 2400 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 2401 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2402 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2403 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2404 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2405 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2406 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2407 | |
| 2408 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 2409 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2410 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2411 | break; |
| 2412 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2413 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2414 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2415 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2416 | |
| 2417 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2418 | reg = FDI_TX_CTL(pipe); |
| 2419 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2420 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2421 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2422 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2423 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2424 | reg = FDI_RX_CTL(pipe); |
| 2425 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2426 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2427 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2428 | I915_WRITE(reg, temp); |
| 2429 | |
| 2430 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2431 | udelay(150); |
| 2432 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2433 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2434 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2435 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2436 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2437 | |
| 2438 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2439 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2440 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 2441 | break; |
| 2442 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2443 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2444 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2445 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2446 | |
| 2447 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 2448 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2449 | } |
| 2450 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2451 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2452 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 2453 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 2454 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 2455 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 2456 | }; |
| 2457 | |
| 2458 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 2459 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 2460 | { |
| 2461 | struct drm_device *dev = crtc->dev; |
| 2462 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2463 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2464 | int pipe = intel_crtc->pipe; |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2465 | u32 reg, temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2466 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2467 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 2468 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2469 | reg = FDI_RX_IMR(pipe); |
| 2470 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2471 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 2472 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2473 | I915_WRITE(reg, temp); |
| 2474 | |
| 2475 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2476 | udelay(150); |
| 2477 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2478 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2479 | reg = FDI_TX_CTL(pipe); |
| 2480 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 2481 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
| 2482 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2483 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2484 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2485 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2486 | /* SNB-B */ |
| 2487 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2488 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2489 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 2490 | I915_WRITE(FDI_RX_MISC(pipe), |
| 2491 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 2492 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2493 | reg = FDI_RX_CTL(pipe); |
| 2494 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2495 | if (HAS_PCH_CPT(dev)) { |
| 2496 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2497 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 2498 | } else { |
| 2499 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2500 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2501 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2502 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 2503 | |
| 2504 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2505 | udelay(150); |
| 2506 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2507 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2508 | reg = FDI_TX_CTL(pipe); |
| 2509 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2510 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2511 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2512 | I915_WRITE(reg, temp); |
| 2513 | |
| 2514 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2515 | udelay(500); |
| 2516 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2517 | for (retry = 0; retry < 5; retry++) { |
| 2518 | reg = FDI_RX_IIR(pipe); |
| 2519 | temp = I915_READ(reg); |
| 2520 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2521 | if (temp & FDI_RX_BIT_LOCK) { |
| 2522 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 2523 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 2524 | break; |
| 2525 | } |
| 2526 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2527 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2528 | if (retry < 5) |
| 2529 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2530 | } |
| 2531 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2532 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2533 | |
| 2534 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2535 | reg = FDI_TX_CTL(pipe); |
| 2536 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2537 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2538 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 2539 | if (IS_GEN6(dev)) { |
| 2540 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2541 | /* SNB-B */ |
| 2542 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 2543 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2544 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2545 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2546 | reg = FDI_RX_CTL(pipe); |
| 2547 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2548 | if (HAS_PCH_CPT(dev)) { |
| 2549 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2550 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 2551 | } else { |
| 2552 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2553 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 2554 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2555 | I915_WRITE(reg, temp); |
| 2556 | |
| 2557 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2558 | udelay(150); |
| 2559 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2560 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2561 | reg = FDI_TX_CTL(pipe); |
| 2562 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2563 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2564 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2565 | I915_WRITE(reg, temp); |
| 2566 | |
| 2567 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2568 | udelay(500); |
| 2569 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2570 | for (retry = 0; retry < 5; retry++) { |
| 2571 | reg = FDI_RX_IIR(pipe); |
| 2572 | temp = I915_READ(reg); |
| 2573 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2574 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 2575 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 2576 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 2577 | break; |
| 2578 | } |
| 2579 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2580 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 2581 | if (retry < 5) |
| 2582 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2583 | } |
| 2584 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2585 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2586 | |
| 2587 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 2588 | } |
| 2589 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2590 | /* Manual link training for Ivy Bridge A0 parts */ |
| 2591 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 2592 | { |
| 2593 | struct drm_device *dev = crtc->dev; |
| 2594 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2595 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2596 | int pipe = intel_crtc->pipe; |
| 2597 | u32 reg, temp, i; |
| 2598 | |
| 2599 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 2600 | for train result */ |
| 2601 | reg = FDI_RX_IMR(pipe); |
| 2602 | temp = I915_READ(reg); |
| 2603 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 2604 | temp &= ~FDI_RX_BIT_LOCK; |
| 2605 | I915_WRITE(reg, temp); |
| 2606 | |
| 2607 | POSTING_READ(reg); |
| 2608 | udelay(150); |
| 2609 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2610 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 2611 | I915_READ(FDI_RX_IIR(pipe))); |
| 2612 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2613 | /* enable CPU FDI TX and PCH FDI RX */ |
| 2614 | reg = FDI_TX_CTL(pipe); |
| 2615 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 2616 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
| 2617 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2618 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 2619 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
| 2620 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2621 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Jesse Barnes | c4f9c4c | 2011-10-10 14:28:52 -0700 | [diff] [blame] | 2622 | temp |= FDI_COMPOSITE_SYNC; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2623 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 2624 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 2625 | I915_WRITE(FDI_RX_MISC(pipe), |
| 2626 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 2627 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2628 | reg = FDI_RX_CTL(pipe); |
| 2629 | temp = I915_READ(reg); |
| 2630 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 2631 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2632 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
Jesse Barnes | c4f9c4c | 2011-10-10 14:28:52 -0700 | [diff] [blame] | 2633 | temp |= FDI_COMPOSITE_SYNC; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2634 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 2635 | |
| 2636 | POSTING_READ(reg); |
| 2637 | udelay(150); |
| 2638 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2639 | for (i = 0; i < 4; i++) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2640 | reg = FDI_TX_CTL(pipe); |
| 2641 | temp = I915_READ(reg); |
| 2642 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2643 | temp |= snb_b_fdi_train_param[i]; |
| 2644 | I915_WRITE(reg, temp); |
| 2645 | |
| 2646 | POSTING_READ(reg); |
| 2647 | udelay(500); |
| 2648 | |
| 2649 | reg = FDI_RX_IIR(pipe); |
| 2650 | temp = I915_READ(reg); |
| 2651 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2652 | |
| 2653 | if (temp & FDI_RX_BIT_LOCK || |
| 2654 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 2655 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2656 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", i); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2657 | break; |
| 2658 | } |
| 2659 | } |
| 2660 | if (i == 4) |
| 2661 | DRM_ERROR("FDI train 1 fail!\n"); |
| 2662 | |
| 2663 | /* Train 2 */ |
| 2664 | reg = FDI_TX_CTL(pipe); |
| 2665 | temp = I915_READ(reg); |
| 2666 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 2667 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 2668 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2669 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 2670 | I915_WRITE(reg, temp); |
| 2671 | |
| 2672 | reg = FDI_RX_CTL(pipe); |
| 2673 | temp = I915_READ(reg); |
| 2674 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2675 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 2676 | I915_WRITE(reg, temp); |
| 2677 | |
| 2678 | POSTING_READ(reg); |
| 2679 | udelay(150); |
| 2680 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2681 | for (i = 0; i < 4; i++) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2682 | reg = FDI_TX_CTL(pipe); |
| 2683 | temp = I915_READ(reg); |
| 2684 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 2685 | temp |= snb_b_fdi_train_param[i]; |
| 2686 | I915_WRITE(reg, temp); |
| 2687 | |
| 2688 | POSTING_READ(reg); |
| 2689 | udelay(500); |
| 2690 | |
| 2691 | reg = FDI_RX_IIR(pipe); |
| 2692 | temp = I915_READ(reg); |
| 2693 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2694 | |
| 2695 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 2696 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2697 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", i); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2698 | break; |
| 2699 | } |
| 2700 | } |
| 2701 | if (i == 4) |
| 2702 | DRM_ERROR("FDI train 2 fail!\n"); |
| 2703 | |
| 2704 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 2705 | } |
| 2706 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 2707 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2708 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 2709 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2710 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2711 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2712 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2713 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 2714 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2715 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2716 | reg = FDI_RX_CTL(pipe); |
| 2717 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 2718 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
| 2719 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 2720 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2721 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 2722 | |
| 2723 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2724 | udelay(200); |
| 2725 | |
| 2726 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2727 | temp = I915_READ(reg); |
| 2728 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 2729 | |
| 2730 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2731 | udelay(200); |
| 2732 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 2733 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 2734 | reg = FDI_TX_CTL(pipe); |
| 2735 | temp = I915_READ(reg); |
| 2736 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 2737 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2738 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 2739 | POSTING_READ(reg); |
| 2740 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 2741 | } |
| 2742 | } |
| 2743 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 2744 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 2745 | { |
| 2746 | struct drm_device *dev = intel_crtc->base.dev; |
| 2747 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2748 | int pipe = intel_crtc->pipe; |
| 2749 | u32 reg, temp; |
| 2750 | |
| 2751 | /* Switch from PCDclk to Rawclk */ |
| 2752 | reg = FDI_RX_CTL(pipe); |
| 2753 | temp = I915_READ(reg); |
| 2754 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 2755 | |
| 2756 | /* Disable CPU FDI TX PLL */ |
| 2757 | reg = FDI_TX_CTL(pipe); |
| 2758 | temp = I915_READ(reg); |
| 2759 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 2760 | |
| 2761 | POSTING_READ(reg); |
| 2762 | udelay(100); |
| 2763 | |
| 2764 | reg = FDI_RX_CTL(pipe); |
| 2765 | temp = I915_READ(reg); |
| 2766 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 2767 | |
| 2768 | /* Wait for the clocks to turn off. */ |
| 2769 | POSTING_READ(reg); |
| 2770 | udelay(100); |
| 2771 | } |
| 2772 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2773 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 2774 | { |
| 2775 | struct drm_device *dev = crtc->dev; |
| 2776 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2777 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2778 | int pipe = intel_crtc->pipe; |
| 2779 | u32 reg, temp; |
| 2780 | |
| 2781 | /* disable CPU FDI tx and PCH FDI rx */ |
| 2782 | reg = FDI_TX_CTL(pipe); |
| 2783 | temp = I915_READ(reg); |
| 2784 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 2785 | POSTING_READ(reg); |
| 2786 | |
| 2787 | reg = FDI_RX_CTL(pipe); |
| 2788 | temp = I915_READ(reg); |
| 2789 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 2790 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2791 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 2792 | |
| 2793 | POSTING_READ(reg); |
| 2794 | udelay(100); |
| 2795 | |
| 2796 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 2797 | if (HAS_PCH_IBX(dev)) { |
| 2798 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 2799 | } |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2800 | |
| 2801 | /* still set train pattern 1 */ |
| 2802 | reg = FDI_TX_CTL(pipe); |
| 2803 | temp = I915_READ(reg); |
| 2804 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2805 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2806 | I915_WRITE(reg, temp); |
| 2807 | |
| 2808 | reg = FDI_RX_CTL(pipe); |
| 2809 | temp = I915_READ(reg); |
| 2810 | if (HAS_PCH_CPT(dev)) { |
| 2811 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2812 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 2813 | } else { |
| 2814 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2815 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 2816 | } |
| 2817 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 2818 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 2819 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2820 | I915_WRITE(reg, temp); |
| 2821 | |
| 2822 | POSTING_READ(reg); |
| 2823 | udelay(100); |
| 2824 | } |
| 2825 | |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 2826 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 2827 | { |
| 2828 | struct drm_device *dev = crtc->dev; |
| 2829 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 2830 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 2831 | unsigned long flags; |
| 2832 | bool pending; |
| 2833 | |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 2834 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 2835 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 2836 | return false; |
| 2837 | |
| 2838 | spin_lock_irqsave(&dev->event_lock, flags); |
| 2839 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
| 2840 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 2841 | |
| 2842 | return pending; |
| 2843 | } |
| 2844 | |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2845 | static void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
| 2846 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 2847 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 2848 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2849 | |
| 2850 | if (crtc->fb == NULL) |
| 2851 | return; |
| 2852 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 2853 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
| 2854 | |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 2855 | wait_event(dev_priv->pending_flip_queue, |
| 2856 | !intel_crtc_has_pending_flip(crtc)); |
| 2857 | |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 2858 | mutex_lock(&dev->struct_mutex); |
| 2859 | intel_finish_fb(crtc->fb); |
| 2860 | mutex_unlock(&dev->struct_mutex); |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 2861 | } |
| 2862 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2863 | /* Program iCLKIP clock to the desired frequency */ |
| 2864 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 2865 | { |
| 2866 | struct drm_device *dev = crtc->dev; |
| 2867 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2868 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 2869 | u32 temp; |
| 2870 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 2871 | mutex_lock(&dev_priv->dpio_lock); |
| 2872 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2873 | /* It is necessary to ungate the pixclk gate prior to programming |
| 2874 | * the divisors, and gate it back when it is done. |
| 2875 | */ |
| 2876 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 2877 | |
| 2878 | /* Disable SSCCTL */ |
| 2879 | intel_sbi_write(dev_priv, SBI_SSCCTL6, |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 2880 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
| 2881 | SBI_SSCCTL_DISABLE, |
| 2882 | SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2883 | |
| 2884 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ |
| 2885 | if (crtc->mode.clock == 20000) { |
| 2886 | auxdiv = 1; |
| 2887 | divsel = 0x41; |
| 2888 | phaseinc = 0x20; |
| 2889 | } else { |
| 2890 | /* The iCLK virtual clock root frequency is in MHz, |
| 2891 | * but the crtc->mode.clock in in KHz. To get the divisors, |
| 2892 | * it is necessary to divide one by another, so we |
| 2893 | * convert the virtual clock precision to KHz here for higher |
| 2894 | * precision. |
| 2895 | */ |
| 2896 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 2897 | u32 iclk_pi_range = 64; |
| 2898 | u32 desired_divisor, msb_divisor_value, pi_value; |
| 2899 | |
| 2900 | desired_divisor = (iclk_virtual_root_freq / crtc->mode.clock); |
| 2901 | msb_divisor_value = desired_divisor / iclk_pi_range; |
| 2902 | pi_value = desired_divisor % iclk_pi_range; |
| 2903 | |
| 2904 | auxdiv = 0; |
| 2905 | divsel = msb_divisor_value - 2; |
| 2906 | phaseinc = pi_value; |
| 2907 | } |
| 2908 | |
| 2909 | /* This should not happen with any sane values */ |
| 2910 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 2911 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 2912 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 2913 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 2914 | |
| 2915 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", |
| 2916 | crtc->mode.clock, |
| 2917 | auxdiv, |
| 2918 | divsel, |
| 2919 | phasedir, |
| 2920 | phaseinc); |
| 2921 | |
| 2922 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 2923 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2924 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 2925 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 2926 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 2927 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 2928 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 2929 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 2930 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2931 | |
| 2932 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 2933 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2934 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 2935 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 2936 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2937 | |
| 2938 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 2939 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2940 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 2941 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2942 | |
| 2943 | /* Wait for initialization time */ |
| 2944 | udelay(24); |
| 2945 | |
| 2946 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 2947 | |
| 2948 | mutex_unlock(&dev_priv->dpio_lock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 2949 | } |
| 2950 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 2951 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 2952 | enum pipe pch_transcoder) |
| 2953 | { |
| 2954 | struct drm_device *dev = crtc->base.dev; |
| 2955 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2956 | enum transcoder cpu_transcoder = crtc->config.cpu_transcoder; |
| 2957 | |
| 2958 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 2959 | I915_READ(HTOTAL(cpu_transcoder))); |
| 2960 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 2961 | I915_READ(HBLANK(cpu_transcoder))); |
| 2962 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 2963 | I915_READ(HSYNC(cpu_transcoder))); |
| 2964 | |
| 2965 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 2966 | I915_READ(VTOTAL(cpu_transcoder))); |
| 2967 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 2968 | I915_READ(VBLANK(cpu_transcoder))); |
| 2969 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 2970 | I915_READ(VSYNC(cpu_transcoder))); |
| 2971 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 2972 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 2973 | } |
| 2974 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 2975 | /* |
| 2976 | * Enable PCH resources required for PCH ports: |
| 2977 | * - PCH PLLs |
| 2978 | * - FDI training & RX/TX |
| 2979 | * - update transcoder timings |
| 2980 | * - DP transcoding bits |
| 2981 | * - transcoder |
| 2982 | */ |
| 2983 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2984 | { |
| 2985 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 2986 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2987 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2988 | int pipe = intel_crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 2989 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 2990 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2991 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 2992 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 2993 | /* Write the TU size bits before fdi link training, so that error |
| 2994 | * detection works. */ |
| 2995 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 2996 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 2997 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 2998 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 2999 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3000 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3001 | /* We need to program the right clock selection before writing the pixel |
| 3002 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3003 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3004 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 3005 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3006 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 3007 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 3008 | sel = TRANS_DPLLB_SEL(pipe); |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 3009 | if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3010 | temp |= sel; |
| 3011 | else |
| 3012 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3013 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3014 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3015 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3016 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 3017 | * transcoder, and we actually should do this to not upset any PCH |
| 3018 | * transcoder that already use the clock when we share it. |
| 3019 | * |
| 3020 | * Note that enable_shared_dpll tries to do the right thing, but |
| 3021 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 3022 | * the right LVDS enable sequence. */ |
| 3023 | ironlake_enable_shared_dpll(intel_crtc); |
| 3024 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 3025 | /* set transcoder timing, panel must allow it */ |
| 3026 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3027 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3028 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3029 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3030 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3031 | /* For PCH DP, enable TRANS_DP_CTL */ |
| 3032 | if (HAS_PCH_CPT(dev) && |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 3033 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 3034 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3035 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3036 | reg = TRANS_DP_CTL(pipe); |
| 3037 | temp = I915_READ(reg); |
| 3038 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 3039 | TRANS_DP_SYNC_MASK | |
| 3040 | TRANS_DP_BPC_MASK); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3041 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
| 3042 | TRANS_DP_ENH_FRAMING); |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 3043 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3044 | |
| 3045 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3046 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3047 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3048 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3049 | |
| 3050 | switch (intel_trans_dp_port_sel(crtc)) { |
| 3051 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3052 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3053 | break; |
| 3054 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3055 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3056 | break; |
| 3057 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3058 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3059 | break; |
| 3060 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 3061 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3062 | } |
| 3063 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3064 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3065 | } |
| 3066 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 3067 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3068 | } |
| 3069 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3070 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 3071 | { |
| 3072 | struct drm_device *dev = crtc->dev; |
| 3073 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3074 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 3075 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3076 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 3077 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3078 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 3079 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3080 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 3081 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3082 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3083 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 3084 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3085 | } |
| 3086 | |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3087 | static void intel_put_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3088 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3089 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3090 | |
| 3091 | if (pll == NULL) |
| 3092 | return; |
| 3093 | |
| 3094 | if (pll->refcount == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3095 | WARN(1, "bad %s refcount\n", pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3096 | return; |
| 3097 | } |
| 3098 | |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 3099 | if (--pll->refcount == 0) { |
| 3100 | WARN_ON(pll->on); |
| 3101 | WARN_ON(pll->active); |
| 3102 | } |
| 3103 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 3104 | crtc->config.shared_dpll = DPLL_ID_PRIVATE; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3105 | } |
| 3106 | |
Daniel Vetter | b89a1d3 | 2013-06-05 13:34:24 +0200 | [diff] [blame] | 3107 | static struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3108 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3109 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 3110 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 3111 | enum intel_dpll_id i; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3112 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3113 | if (pll) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3114 | DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n", |
| 3115 | crtc->base.base.id, pll->name); |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3116 | intel_put_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3117 | } |
| 3118 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3119 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 3120 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 3121 | i = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3122 | pll = &dev_priv->shared_dplls[i]; |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3123 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3124 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 3125 | crtc->base.base.id, pll->name); |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3126 | |
| 3127 | goto found; |
| 3128 | } |
| 3129 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3130 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 3131 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3132 | |
| 3133 | /* Only want to check enabled timings first */ |
| 3134 | if (pll->refcount == 0) |
| 3135 | continue; |
| 3136 | |
Daniel Vetter | b89a1d3 | 2013-06-05 13:34:24 +0200 | [diff] [blame] | 3137 | if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state, |
| 3138 | sizeof(pll->hw_state)) == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3139 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (refcount %d, ative %d)\n", |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3140 | crtc->base.base.id, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3141 | pll->name, pll->refcount, pll->active); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3142 | |
| 3143 | goto found; |
| 3144 | } |
| 3145 | } |
| 3146 | |
| 3147 | /* Ok no matching timings, maybe there's a free one? */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3148 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 3149 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3150 | if (pll->refcount == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3151 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
| 3152 | crtc->base.base.id, pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3153 | goto found; |
| 3154 | } |
| 3155 | } |
| 3156 | |
| 3157 | return NULL; |
| 3158 | |
| 3159 | found: |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 3160 | crtc->config.shared_dpll = i; |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3161 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
| 3162 | pipe_name(crtc->pipe)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 3163 | |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 3164 | if (pll->active == 0) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 3165 | memcpy(&pll->hw_state, &crtc->config.dpll_hw_state, |
| 3166 | sizeof(pll->hw_state)); |
| 3167 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3168 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 3169 | WARN_ON(pll->on); |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 3170 | assert_shared_dpll_disabled(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3171 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 3172 | pll->mode_set(dev_priv, pll); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 3173 | } |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3174 | pll->refcount++; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3175 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3176 | return pll; |
| 3177 | } |
| 3178 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 3179 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3180 | { |
| 3181 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 3182 | int dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3183 | u32 temp; |
| 3184 | |
| 3185 | temp = I915_READ(dslreg); |
| 3186 | udelay(500); |
| 3187 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3188 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 3189 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3190 | } |
| 3191 | } |
| 3192 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 3193 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 3194 | { |
| 3195 | struct drm_device *dev = crtc->base.dev; |
| 3196 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3197 | int pipe = crtc->pipe; |
| 3198 | |
Jesse Barnes | 0ef37f3 | 2013-05-03 13:26:37 -0700 | [diff] [blame] | 3199 | if (crtc->config.pch_pfit.size) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 3200 | /* Force use of hard-coded filter coefficients |
| 3201 | * as some pre-programmed values are broken, |
| 3202 | * e.g. x201. |
| 3203 | */ |
| 3204 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 3205 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 3206 | PF_PIPE_SEL_IVB(pipe)); |
| 3207 | else |
| 3208 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
| 3209 | I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos); |
| 3210 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 3211 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3212 | } |
| 3213 | |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3214 | static void intel_enable_planes(struct drm_crtc *crtc) |
| 3215 | { |
| 3216 | struct drm_device *dev = crtc->dev; |
| 3217 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
| 3218 | struct intel_plane *intel_plane; |
| 3219 | |
| 3220 | list_for_each_entry(intel_plane, &dev->mode_config.plane_list, base.head) |
| 3221 | if (intel_plane->pipe == pipe) |
| 3222 | intel_plane_restore(&intel_plane->base); |
| 3223 | } |
| 3224 | |
| 3225 | static void intel_disable_planes(struct drm_crtc *crtc) |
| 3226 | { |
| 3227 | struct drm_device *dev = crtc->dev; |
| 3228 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
| 3229 | struct intel_plane *intel_plane; |
| 3230 | |
| 3231 | list_for_each_entry(intel_plane, &dev->mode_config.plane_list, base.head) |
| 3232 | if (intel_plane->pipe == pipe) |
| 3233 | intel_plane_disable(&intel_plane->base); |
| 3234 | } |
| 3235 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3236 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 3237 | { |
| 3238 | struct drm_device *dev = crtc->dev; |
| 3239 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3240 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3241 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3242 | int pipe = intel_crtc->pipe; |
| 3243 | int plane = intel_crtc->plane; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3244 | |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 3245 | WARN_ON(!crtc->enabled); |
| 3246 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3247 | if (intel_crtc->active) |
| 3248 | return; |
| 3249 | |
| 3250 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 3251 | |
| 3252 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 3253 | intel_set_pch_fifo_underrun_reporting(dev, pipe, true); |
| 3254 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3255 | intel_update_watermarks(dev); |
| 3256 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 3257 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 3258 | if (encoder->pre_enable) |
| 3259 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3260 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 3261 | if (intel_crtc->config.has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 3262 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 3263 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 3264 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3265 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 3266 | } else { |
| 3267 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 3268 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 3269 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3270 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 3271 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3272 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 3273 | /* |
| 3274 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 3275 | * clocks enabled |
| 3276 | */ |
| 3277 | intel_crtc_load_lut(crtc); |
| 3278 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 3279 | intel_enable_pipe(dev_priv, pipe, |
| 3280 | intel_crtc->config.has_pch_encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3281 | intel_enable_plane(dev_priv, plane, pipe); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3282 | intel_enable_planes(crtc); |
Ville Syrjälä | 5c38d48 | 2013-06-04 13:49:00 +0300 | [diff] [blame] | 3283 | intel_crtc_update_cursor(crtc, true); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3284 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 3285 | if (intel_crtc->config.has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3286 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3287 | |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 3288 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | bed4a67 | 2010-09-11 10:47:47 +0100 | [diff] [blame] | 3289 | intel_update_fbc(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 3290 | mutex_unlock(&dev->struct_mutex); |
| 3291 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 3292 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3293 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 3294 | |
| 3295 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 3296 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Daniel Vetter | 6ce9410 | 2012-10-04 19:20:03 +0200 | [diff] [blame] | 3297 | |
| 3298 | /* |
| 3299 | * There seems to be a race in PCH platform hw (at least on some |
| 3300 | * outputs) where an enabled pipe still completes any pageflip right |
| 3301 | * away (as if the pipe is off) instead of waiting for vblank. As soon |
| 3302 | * as the first vblank happend, everything works as expected. Hence just |
| 3303 | * wait for one vblank before returning to avoid strange things |
| 3304 | * happening. |
| 3305 | */ |
| 3306 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3307 | } |
| 3308 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 3309 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 3310 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 3311 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 3312 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 3313 | } |
| 3314 | |
| 3315 | static void hsw_enable_ips(struct intel_crtc *crtc) |
| 3316 | { |
| 3317 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 3318 | |
| 3319 | if (!crtc->config.ips_enabled) |
| 3320 | return; |
| 3321 | |
| 3322 | /* We can only enable IPS after we enable a plane and wait for a vblank. |
| 3323 | * We guarantee that the plane is enabled by calling intel_enable_ips |
| 3324 | * only after intel_enable_plane. And intel_enable_plane already waits |
| 3325 | * for a vblank, so all we need to do here is to enable the IPS bit. */ |
| 3326 | assert_plane_enabled(dev_priv, crtc->plane); |
| 3327 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 3328 | } |
| 3329 | |
| 3330 | static void hsw_disable_ips(struct intel_crtc *crtc) |
| 3331 | { |
| 3332 | struct drm_device *dev = crtc->base.dev; |
| 3333 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3334 | |
| 3335 | if (!crtc->config.ips_enabled) |
| 3336 | return; |
| 3337 | |
| 3338 | assert_plane_enabled(dev_priv, crtc->plane); |
| 3339 | I915_WRITE(IPS_CTL, 0); |
| 3340 | |
| 3341 | /* We need to wait for a vblank before we can disable the plane. */ |
| 3342 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3343 | } |
| 3344 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3345 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 3346 | { |
| 3347 | struct drm_device *dev = crtc->dev; |
| 3348 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3349 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3350 | struct intel_encoder *encoder; |
| 3351 | int pipe = intel_crtc->pipe; |
| 3352 | int plane = intel_crtc->plane; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3353 | |
| 3354 | WARN_ON(!crtc->enabled); |
| 3355 | |
| 3356 | if (intel_crtc->active) |
| 3357 | return; |
| 3358 | |
| 3359 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 3360 | |
| 3361 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 3362 | if (intel_crtc->config.has_pch_encoder) |
| 3363 | intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true); |
| 3364 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3365 | intel_update_watermarks(dev); |
| 3366 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 3367 | if (intel_crtc->config.has_pch_encoder) |
Paulo Zanoni | 0494564 | 2012-11-01 21:00:59 -0200 | [diff] [blame] | 3368 | dev_priv->display.fdi_link_train(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3369 | |
| 3370 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3371 | if (encoder->pre_enable) |
| 3372 | encoder->pre_enable(encoder); |
| 3373 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 3374 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3375 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 3376 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3377 | |
| 3378 | /* |
| 3379 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 3380 | * clocks enabled |
| 3381 | */ |
| 3382 | intel_crtc_load_lut(crtc); |
| 3383 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 3384 | intel_ddi_set_pipe_settings(crtc); |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 3385 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3386 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 3387 | intel_enable_pipe(dev_priv, pipe, |
| 3388 | intel_crtc->config.has_pch_encoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3389 | intel_enable_plane(dev_priv, plane, pipe); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3390 | intel_enable_planes(crtc); |
Ville Syrjälä | 5c38d48 | 2013-06-04 13:49:00 +0300 | [diff] [blame] | 3391 | intel_crtc_update_cursor(crtc, true); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3392 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 3393 | hsw_enable_ips(intel_crtc); |
| 3394 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 3395 | if (intel_crtc->config.has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3396 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3397 | |
| 3398 | mutex_lock(&dev->struct_mutex); |
| 3399 | intel_update_fbc(dev); |
| 3400 | mutex_unlock(&dev->struct_mutex); |
| 3401 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3402 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3403 | encoder->enable(encoder); |
| 3404 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3405 | /* |
| 3406 | * There seems to be a race in PCH platform hw (at least on some |
| 3407 | * outputs) where an enabled pipe still completes any pageflip right |
| 3408 | * away (as if the pipe is off) instead of waiting for vblank. As soon |
| 3409 | * as the first vblank happend, everything works as expected. Hence just |
| 3410 | * wait for one vblank before returning to avoid strange things |
| 3411 | * happening. |
| 3412 | */ |
| 3413 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 3414 | } |
| 3415 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 3416 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
| 3417 | { |
| 3418 | struct drm_device *dev = crtc->base.dev; |
| 3419 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3420 | int pipe = crtc->pipe; |
| 3421 | |
| 3422 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 3423 | * it's in use. The hw state code will make sure we get this right. */ |
| 3424 | if (crtc->config.pch_pfit.size) { |
| 3425 | I915_WRITE(PF_CTL(pipe), 0); |
| 3426 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 3427 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 3428 | } |
| 3429 | } |
| 3430 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3431 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 3432 | { |
| 3433 | struct drm_device *dev = crtc->dev; |
| 3434 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3435 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3436 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3437 | int pipe = intel_crtc->pipe; |
| 3438 | int plane = intel_crtc->plane; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3439 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3440 | |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3441 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3442 | if (!intel_crtc->active) |
| 3443 | return; |
| 3444 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 3445 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3446 | encoder->disable(encoder); |
| 3447 | |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3448 | intel_crtc_wait_for_pending_flips(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3449 | drm_vblank_off(dev, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3450 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 3451 | if (dev_priv->fbc.plane == plane) |
Chris Wilson | 973d04f | 2011-07-08 12:22:37 +0100 | [diff] [blame] | 3452 | intel_disable_fbc(dev); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3453 | |
Ville Syrjälä | 0d5b8c6 | 2013-06-04 13:49:02 +0300 | [diff] [blame] | 3454 | intel_crtc_update_cursor(crtc, false); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3455 | intel_disable_planes(crtc); |
Ville Syrjälä | 0d5b8c6 | 2013-06-04 13:49:02 +0300 | [diff] [blame] | 3456 | intel_disable_plane(dev_priv, plane, pipe); |
| 3457 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 3458 | if (intel_crtc->config.has_pch_encoder) |
| 3459 | intel_set_pch_fifo_underrun_reporting(dev, pipe, false); |
| 3460 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 3461 | intel_disable_pipe(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3462 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 3463 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3464 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 3465 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3466 | if (encoder->post_disable) |
| 3467 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3468 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 3469 | if (intel_crtc->config.has_pch_encoder) { |
| 3470 | ironlake_fdi_disable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3471 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 3472 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
| 3473 | intel_set_pch_fifo_underrun_reporting(dev, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3474 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 3475 | if (HAS_PCH_CPT(dev)) { |
| 3476 | /* disable TRANS_DP_CTL */ |
| 3477 | reg = TRANS_DP_CTL(pipe); |
| 3478 | temp = I915_READ(reg); |
| 3479 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 3480 | TRANS_DP_PORT_SEL_MASK); |
| 3481 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 3482 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3483 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 3484 | /* disable DPLL_SEL */ |
| 3485 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 3486 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 3487 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 3488 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 3489 | |
| 3490 | /* disable PCH DPLL */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3491 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 3492 | |
| 3493 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3494 | } |
| 3495 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3496 | intel_crtc->active = false; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3497 | intel_update_watermarks(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 3498 | |
| 3499 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3500 | intel_update_fbc(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 3501 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3502 | } |
| 3503 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3504 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 3505 | { |
| 3506 | struct drm_device *dev = crtc->dev; |
| 3507 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3508 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3509 | struct intel_encoder *encoder; |
| 3510 | int pipe = intel_crtc->pipe; |
| 3511 | int plane = intel_crtc->plane; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 3512 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3513 | |
| 3514 | if (!intel_crtc->active) |
| 3515 | return; |
| 3516 | |
| 3517 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3518 | encoder->disable(encoder); |
| 3519 | |
| 3520 | intel_crtc_wait_for_pending_flips(crtc); |
| 3521 | drm_vblank_off(dev, pipe); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3522 | |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 3523 | /* FBC must be disabled before disabling the plane on HSW. */ |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 3524 | if (dev_priv->fbc.plane == plane) |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3525 | intel_disable_fbc(dev); |
| 3526 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 3527 | hsw_disable_ips(intel_crtc); |
| 3528 | |
Ville Syrjälä | 0d5b8c6 | 2013-06-04 13:49:02 +0300 | [diff] [blame] | 3529 | intel_crtc_update_cursor(crtc, false); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3530 | intel_disable_planes(crtc); |
Rodrigo Vivi | 891348b | 2013-05-06 19:37:36 -0300 | [diff] [blame] | 3531 | intel_disable_plane(dev_priv, plane, pipe); |
| 3532 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 3533 | if (intel_crtc->config.has_pch_encoder) |
| 3534 | intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3535 | intel_disable_pipe(dev_priv, pipe); |
| 3536 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 3537 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3538 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 3539 | ironlake_pfit_disable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3540 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 3541 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3542 | |
| 3543 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3544 | if (encoder->post_disable) |
| 3545 | encoder->post_disable(encoder); |
| 3546 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 3547 | if (intel_crtc->config.has_pch_encoder) { |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 3548 | lpt_disable_pch_transcoder(dev_priv); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 3549 | intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 3550 | intel_ddi_fdi_disable(crtc); |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 3551 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 3552 | |
| 3553 | intel_crtc->active = false; |
| 3554 | intel_update_watermarks(dev); |
| 3555 | |
| 3556 | mutex_lock(&dev->struct_mutex); |
| 3557 | intel_update_fbc(dev); |
| 3558 | mutex_unlock(&dev->struct_mutex); |
| 3559 | } |
| 3560 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3561 | static void ironlake_crtc_off(struct drm_crtc *crtc) |
| 3562 | { |
| 3563 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3564 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3565 | } |
| 3566 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 3567 | static void haswell_crtc_off(struct drm_crtc *crtc) |
| 3568 | { |
| 3569 | intel_ddi_put_crtc_pll(crtc); |
| 3570 | } |
| 3571 | |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3572 | static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable) |
| 3573 | { |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3574 | if (!enable && intel_crtc->overlay) { |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 3575 | struct drm_device *dev = intel_crtc->base.dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 3576 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 03f77ea | 2009-09-15 22:57:37 +0200 | [diff] [blame] | 3577 | |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 3578 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 3579 | dev_priv->mm.interruptible = false; |
| 3580 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 3581 | dev_priv->mm.interruptible = true; |
Chris Wilson | 23f09ce | 2010-08-12 13:53:37 +0100 | [diff] [blame] | 3582 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3583 | } |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3584 | |
Chris Wilson | 5dcdbcb | 2010-08-12 13:50:28 +0100 | [diff] [blame] | 3585 | /* Let userspace switch the overlay on again. In most cases userspace |
| 3586 | * has to recompute where to put it anyway. |
| 3587 | */ |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 3588 | } |
| 3589 | |
Egbert Eich | 61bc95c | 2013-03-04 09:24:38 -0500 | [diff] [blame] | 3590 | /** |
| 3591 | * i9xx_fixup_plane - ugly workaround for G45 to fire up the hardware |
| 3592 | * cursor plane briefly if not already running after enabling the display |
| 3593 | * plane. |
| 3594 | * This workaround avoids occasional blank screens when self refresh is |
| 3595 | * enabled. |
| 3596 | */ |
| 3597 | static void |
| 3598 | g4x_fixup_plane(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 3599 | { |
| 3600 | u32 cntl = I915_READ(CURCNTR(pipe)); |
| 3601 | |
| 3602 | if ((cntl & CURSOR_MODE) == 0) { |
| 3603 | u32 fw_bcl_self = I915_READ(FW_BLC_SELF); |
| 3604 | |
| 3605 | I915_WRITE(FW_BLC_SELF, fw_bcl_self & ~FW_BLC_SELF_EN); |
| 3606 | I915_WRITE(CURCNTR(pipe), CURSOR_MODE_64_ARGB_AX); |
| 3607 | intel_wait_for_vblank(dev_priv->dev, pipe); |
| 3608 | I915_WRITE(CURCNTR(pipe), cntl); |
| 3609 | I915_WRITE(CURBASE(pipe), I915_READ(CURBASE(pipe))); |
| 3610 | I915_WRITE(FW_BLC_SELF, fw_bcl_self); |
| 3611 | } |
| 3612 | } |
| 3613 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 3614 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 3615 | { |
| 3616 | struct drm_device *dev = crtc->base.dev; |
| 3617 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3618 | struct intel_crtc_config *pipe_config = &crtc->config; |
| 3619 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 3620 | if (!crtc->config.gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 3621 | return; |
| 3622 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 3623 | /* |
| 3624 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 3625 | * according to register description and PRM. |
| 3626 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 3627 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 3628 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 3629 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 3630 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 3631 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 3632 | |
| 3633 | /* Border color in case we don't scale up to the full screen. Black by |
| 3634 | * default, change to something else for debugging. */ |
| 3635 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3638 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 3639 | { |
| 3640 | struct drm_device *dev = crtc->dev; |
| 3641 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3642 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3643 | struct intel_encoder *encoder; |
| 3644 | int pipe = intel_crtc->pipe; |
| 3645 | int plane = intel_crtc->plane; |
| 3646 | |
| 3647 | WARN_ON(!crtc->enabled); |
| 3648 | |
| 3649 | if (intel_crtc->active) |
| 3650 | return; |
| 3651 | |
| 3652 | intel_crtc->active = true; |
| 3653 | intel_update_watermarks(dev); |
| 3654 | |
| 3655 | mutex_lock(&dev_priv->dpio_lock); |
| 3656 | |
| 3657 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3658 | if (encoder->pre_pll_enable) |
| 3659 | encoder->pre_pll_enable(encoder); |
| 3660 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 3661 | vlv_enable_pll(intel_crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3662 | |
| 3663 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3664 | if (encoder->pre_enable) |
| 3665 | encoder->pre_enable(encoder); |
| 3666 | |
| 3667 | /* VLV wants encoder enabling _before_ the pipe is up. */ |
| 3668 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3669 | encoder->enable(encoder); |
| 3670 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 3671 | i9xx_pfit_enable(intel_crtc); |
| 3672 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 3673 | intel_crtc_load_lut(crtc); |
| 3674 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3675 | intel_enable_pipe(dev_priv, pipe, false); |
| 3676 | intel_enable_plane(dev_priv, plane, pipe); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3677 | intel_enable_planes(crtc); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3678 | intel_crtc_update_cursor(crtc, true); |
| 3679 | |
Ville Syrjälä | f440eb1 | 2013-06-04 13:49:01 +0300 | [diff] [blame] | 3680 | intel_update_fbc(dev); |
| 3681 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3682 | mutex_unlock(&dev_priv->dpio_lock); |
| 3683 | } |
| 3684 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3685 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3686 | { |
| 3687 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3688 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3689 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3690 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3691 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 3692 | int plane = intel_crtc->plane; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3693 | |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 3694 | WARN_ON(!crtc->enabled); |
| 3695 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3696 | if (intel_crtc->active) |
| 3697 | return; |
| 3698 | |
| 3699 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3700 | intel_update_watermarks(dev); |
| 3701 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 3702 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 3703 | if (encoder->pre_enable) |
| 3704 | encoder->pre_enable(encoder); |
| 3705 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 3706 | i9xx_enable_pll(intel_crtc); |
| 3707 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 3708 | i9xx_pfit_enable(intel_crtc); |
| 3709 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 3710 | intel_crtc_load_lut(crtc); |
| 3711 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 3712 | intel_enable_pipe(dev_priv, pipe, false); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 3713 | intel_enable_plane(dev_priv, plane, pipe); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3714 | intel_enable_planes(crtc); |
Ville Syrjälä | 22e407d | 2013-06-07 18:52:24 +0300 | [diff] [blame] | 3715 | /* The fixup needs to happen before cursor is enabled */ |
Egbert Eich | 61bc95c | 2013-03-04 09:24:38 -0500 | [diff] [blame] | 3716 | if (IS_G4X(dev)) |
| 3717 | g4x_fixup_plane(dev_priv, pipe); |
Ville Syrjälä | 22e407d | 2013-06-07 18:52:24 +0300 | [diff] [blame] | 3718 | intel_crtc_update_cursor(crtc, true); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3719 | |
| 3720 | /* Give the overlay scaler a chance to enable if it's on this pipe */ |
| 3721 | intel_crtc_dpms_overlay(intel_crtc, true); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3722 | |
Ville Syrjälä | f440eb1 | 2013-06-04 13:49:01 +0300 | [diff] [blame] | 3723 | intel_update_fbc(dev); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3724 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 3725 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3726 | encoder->enable(encoder); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3727 | } |
| 3728 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 3729 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 3730 | { |
| 3731 | struct drm_device *dev = crtc->base.dev; |
| 3732 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 3733 | |
| 3734 | if (!crtc->config.gmch_pfit.control) |
| 3735 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 3736 | |
| 3737 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 3738 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 3739 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 3740 | I915_READ(PFIT_CONTROL)); |
| 3741 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 3742 | } |
| 3743 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3744 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 3745 | { |
| 3746 | struct drm_device *dev = crtc->dev; |
| 3747 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3748 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3749 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3750 | int pipe = intel_crtc->pipe; |
| 3751 | int plane = intel_crtc->plane; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 3752 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3753 | if (!intel_crtc->active) |
| 3754 | return; |
| 3755 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 3756 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3757 | encoder->disable(encoder); |
| 3758 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3759 | /* 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] | 3760 | intel_crtc_wait_for_pending_flips(crtc); |
| 3761 | drm_vblank_off(dev, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3762 | |
Ben Widawsky | 5c3fe8b | 2013-06-27 16:30:21 -0700 | [diff] [blame] | 3763 | if (dev_priv->fbc.plane == plane) |
Chris Wilson | 973d04f | 2011-07-08 12:22:37 +0100 | [diff] [blame] | 3764 | intel_disable_fbc(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3765 | |
Ville Syrjälä | 0d5b8c6 | 2013-06-04 13:49:02 +0300 | [diff] [blame] | 3766 | intel_crtc_dpms_overlay(intel_crtc, false); |
| 3767 | intel_crtc_update_cursor(crtc, false); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3768 | intel_disable_planes(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 3769 | intel_disable_plane(dev_priv, plane, pipe); |
Ville Syrjälä | 0d5b8c6 | 2013-06-04 13:49:02 +0300 | [diff] [blame] | 3770 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 3771 | intel_disable_pipe(dev_priv, pipe); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 3772 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 3773 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 3774 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 3775 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 3776 | if (encoder->post_disable) |
| 3777 | encoder->post_disable(encoder); |
| 3778 | |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame^] | 3779 | i9xx_disable_pll(dev_priv, pipe); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3780 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 3781 | intel_crtc->active = false; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 3782 | intel_update_fbc(dev); |
| 3783 | intel_update_watermarks(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 3784 | } |
| 3785 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3786 | static void i9xx_crtc_off(struct drm_crtc *crtc) |
| 3787 | { |
| 3788 | } |
| 3789 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3790 | static void intel_crtc_update_sarea(struct drm_crtc *crtc, |
| 3791 | bool enabled) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3792 | { |
| 3793 | struct drm_device *dev = crtc->dev; |
| 3794 | struct drm_i915_master_private *master_priv; |
| 3795 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3796 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3797 | |
| 3798 | if (!dev->primary->master) |
| 3799 | return; |
| 3800 | |
| 3801 | master_priv = dev->primary->master->driver_priv; |
| 3802 | if (!master_priv->sarea_priv) |
| 3803 | return; |
| 3804 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3805 | switch (pipe) { |
| 3806 | case 0: |
| 3807 | master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0; |
| 3808 | master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0; |
| 3809 | break; |
| 3810 | case 1: |
| 3811 | master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0; |
| 3812 | master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0; |
| 3813 | break; |
| 3814 | default: |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 3815 | 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] | 3816 | break; |
| 3817 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3818 | } |
| 3819 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3820 | /** |
| 3821 | * Sets the power management mode of the pipe and plane. |
| 3822 | */ |
| 3823 | void intel_crtc_update_dpms(struct drm_crtc *crtc) |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3824 | { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3825 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3826 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3827 | struct intel_encoder *intel_encoder; |
| 3828 | bool enable = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3829 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3830 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 3831 | enable |= intel_encoder->connectors_active; |
| 3832 | |
| 3833 | if (enable) |
| 3834 | dev_priv->display.crtc_enable(crtc); |
| 3835 | else |
| 3836 | dev_priv->display.crtc_disable(crtc); |
| 3837 | |
| 3838 | intel_crtc_update_sarea(crtc, enable); |
| 3839 | } |
| 3840 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3841 | static void intel_crtc_disable(struct drm_crtc *crtc) |
| 3842 | { |
| 3843 | struct drm_device *dev = crtc->dev; |
| 3844 | struct drm_connector *connector; |
| 3845 | struct drm_i915_private *dev_priv = dev->dev_private; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 3846 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3847 | |
| 3848 | /* crtc should still be enabled when we disable it. */ |
| 3849 | WARN_ON(!crtc->enabled); |
| 3850 | |
| 3851 | dev_priv->display.crtc_disable(crtc); |
Paulo Zanoni | c77bf56 | 2013-05-03 12:15:40 -0300 | [diff] [blame] | 3852 | intel_crtc->eld_vld = false; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3853 | intel_crtc_update_sarea(crtc, false); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3854 | dev_priv->display.off(crtc); |
| 3855 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 3856 | assert_plane_disabled(dev->dev_private, to_intel_crtc(crtc)->plane); |
| 3857 | assert_pipe_disabled(dev->dev_private, to_intel_crtc(crtc)->pipe); |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3858 | |
| 3859 | if (crtc->fb) { |
| 3860 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 3861 | intel_unpin_fb_obj(to_intel_framebuffer(crtc->fb)->obj); |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3862 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 3863 | crtc->fb = NULL; |
| 3864 | } |
| 3865 | |
| 3866 | /* Update computed state. */ |
| 3867 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 3868 | if (!connector->encoder || !connector->encoder->crtc) |
| 3869 | continue; |
| 3870 | |
| 3871 | if (connector->encoder->crtc != crtc) |
| 3872 | continue; |
| 3873 | |
| 3874 | connector->dpms = DRM_MODE_DPMS_OFF; |
| 3875 | to_intel_encoder(connector->encoder)->connectors_active = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 3876 | } |
| 3877 | } |
| 3878 | |
Daniel Vetter | a261b24 | 2012-07-26 19:21:47 +0200 | [diff] [blame] | 3879 | void intel_modeset_disable(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3880 | { |
Daniel Vetter | a261b24 | 2012-07-26 19:21:47 +0200 | [diff] [blame] | 3881 | struct drm_crtc *crtc; |
| 3882 | |
| 3883 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 3884 | if (crtc->enabled) |
| 3885 | intel_crtc_disable(crtc); |
| 3886 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3887 | } |
| 3888 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3889 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 3890 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 3891 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3892 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 3893 | drm_encoder_cleanup(encoder); |
| 3894 | kfree(intel_encoder); |
| 3895 | } |
| 3896 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3897 | /* Simple dpms helper for encodres with just one connector, no cloning and only |
| 3898 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
| 3899 | * state of the entire output pipe. */ |
| 3900 | void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
| 3901 | { |
| 3902 | if (mode == DRM_MODE_DPMS_ON) { |
| 3903 | encoder->connectors_active = true; |
| 3904 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 3905 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3906 | } else { |
| 3907 | encoder->connectors_active = false; |
| 3908 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 3909 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3910 | } |
| 3911 | } |
| 3912 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 3913 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 3914 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 3915 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 3916 | { |
| 3917 | if (connector->get_hw_state(connector)) { |
| 3918 | struct intel_encoder *encoder = connector->encoder; |
| 3919 | struct drm_crtc *crtc; |
| 3920 | bool encoder_enabled; |
| 3921 | enum pipe pipe; |
| 3922 | |
| 3923 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 3924 | connector->base.base.id, |
| 3925 | drm_get_connector_name(&connector->base)); |
| 3926 | |
| 3927 | WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
| 3928 | "wrong connector dpms state\n"); |
| 3929 | WARN(connector->base.encoder != &encoder->base, |
| 3930 | "active connector not linked to encoder\n"); |
| 3931 | WARN(!encoder->connectors_active, |
| 3932 | "encoder->connectors_active not set\n"); |
| 3933 | |
| 3934 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); |
| 3935 | WARN(!encoder_enabled, "encoder not enabled\n"); |
| 3936 | if (WARN_ON(!encoder->base.crtc)) |
| 3937 | return; |
| 3938 | |
| 3939 | crtc = encoder->base.crtc; |
| 3940 | |
| 3941 | WARN(!crtc->enabled, "crtc not enabled\n"); |
| 3942 | WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
| 3943 | WARN(pipe != to_intel_crtc(crtc)->pipe, |
| 3944 | "encoder active on the wrong pipe\n"); |
| 3945 | } |
| 3946 | } |
| 3947 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3948 | /* Even simpler default implementation, if there's really no special case to |
| 3949 | * consider. */ |
| 3950 | void intel_connector_dpms(struct drm_connector *connector, int mode) |
| 3951 | { |
| 3952 | struct intel_encoder *encoder = intel_attached_encoder(connector); |
| 3953 | |
| 3954 | /* All the simple cases only support two dpms states. */ |
| 3955 | if (mode != DRM_MODE_DPMS_ON) |
| 3956 | mode = DRM_MODE_DPMS_OFF; |
| 3957 | |
| 3958 | if (mode == connector->dpms) |
| 3959 | return; |
| 3960 | |
| 3961 | connector->dpms = mode; |
| 3962 | |
| 3963 | /* Only need to change hw state when actually enabled */ |
| 3964 | if (encoder->base.crtc) |
| 3965 | intel_encoder_dpms(encoder, mode); |
| 3966 | else |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 3967 | WARN_ON(encoder->connectors_active != false); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 3968 | |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 3969 | intel_modeset_check_state(connector->dev); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 3970 | } |
| 3971 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 3972 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 3973 | * one connector and no cloning and hence the encoder state determines the state |
| 3974 | * of the connector. */ |
| 3975 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 3976 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 3977 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 3978 | struct intel_encoder *encoder = connector->encoder; |
| 3979 | |
| 3980 | return encoder->get_hw_state(encoder, &pipe); |
| 3981 | } |
| 3982 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 3983 | static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
| 3984 | struct intel_crtc_config *pipe_config) |
| 3985 | { |
| 3986 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3987 | struct intel_crtc *pipe_B_crtc = |
| 3988 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]); |
| 3989 | |
| 3990 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 3991 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 3992 | if (pipe_config->fdi_lanes > 4) { |
| 3993 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 3994 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 3995 | return false; |
| 3996 | } |
| 3997 | |
| 3998 | if (IS_HASWELL(dev)) { |
| 3999 | if (pipe_config->fdi_lanes > 2) { |
| 4000 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 4001 | pipe_config->fdi_lanes); |
| 4002 | return false; |
| 4003 | } else { |
| 4004 | return true; |
| 4005 | } |
| 4006 | } |
| 4007 | |
| 4008 | if (INTEL_INFO(dev)->num_pipes == 2) |
| 4009 | return true; |
| 4010 | |
| 4011 | /* Ivybridge 3 pipe is really complicated */ |
| 4012 | switch (pipe) { |
| 4013 | case PIPE_A: |
| 4014 | return true; |
| 4015 | case PIPE_B: |
| 4016 | if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled && |
| 4017 | pipe_config->fdi_lanes > 2) { |
| 4018 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 4019 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 4020 | return false; |
| 4021 | } |
| 4022 | return true; |
| 4023 | case PIPE_C: |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 4024 | if (!pipe_has_enabled_pch(pipe_B_crtc) || |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 4025 | pipe_B_crtc->config.fdi_lanes <= 2) { |
| 4026 | if (pipe_config->fdi_lanes > 2) { |
| 4027 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 4028 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 4029 | return false; |
| 4030 | } |
| 4031 | } else { |
| 4032 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
| 4033 | return false; |
| 4034 | } |
| 4035 | return true; |
| 4036 | default: |
| 4037 | BUG(); |
| 4038 | } |
| 4039 | } |
| 4040 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 4041 | #define RETRY 1 |
| 4042 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, |
| 4043 | struct intel_crtc_config *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4044 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 4045 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4046 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 4047 | int lane, link_bw, fdi_dotclock; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 4048 | bool setup_ok, needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4049 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 4050 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4051 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 4052 | * each output octet as 10 bits. The actual frequency |
| 4053 | * is stored as a divider into a 100MHz clock, and the |
| 4054 | * mode pixel clock is stored in units of 1KHz. |
| 4055 | * Hence the bw of each lane in terms of the mode signal |
| 4056 | * is: |
| 4057 | */ |
| 4058 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
| 4059 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 4060 | fdi_dotclock = adjusted_mode->clock; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 4061 | fdi_dotclock /= pipe_config->pixel_multiplier; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4062 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 4063 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4064 | pipe_config->pipe_bpp); |
| 4065 | |
| 4066 | pipe_config->fdi_lanes = lane; |
| 4067 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 4068 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4069 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 4070 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 4071 | setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
| 4072 | intel_crtc->pipe, pipe_config); |
| 4073 | if (!setup_ok && pipe_config->pipe_bpp > 6*3) { |
| 4074 | pipe_config->pipe_bpp -= 2*3; |
| 4075 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 4076 | pipe_config->pipe_bpp); |
| 4077 | needs_recompute = true; |
| 4078 | pipe_config->bw_constrained = true; |
| 4079 | |
| 4080 | goto retry; |
| 4081 | } |
| 4082 | |
| 4083 | if (needs_recompute) |
| 4084 | return RETRY; |
| 4085 | |
| 4086 | return setup_ok ? 0 : -EINVAL; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4087 | } |
| 4088 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4089 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
| 4090 | struct intel_crtc_config *pipe_config) |
| 4091 | { |
Paulo Zanoni | 3c4ca58 | 2013-05-31 16:33:23 -0300 | [diff] [blame] | 4092 | pipe_config->ips_enabled = i915_enable_ips && |
| 4093 | hsw_crtc_supports_ips(crtc) && |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4094 | pipe_config->pipe_bpp == 24; |
| 4095 | } |
| 4096 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 4097 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 4098 | struct intel_crtc_config *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4099 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 4100 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 4101 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 4102 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 4103 | if (HAS_PCH_SPLIT(dev)) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4104 | /* FDI link clock is fixed at 2.7G */ |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 4105 | if (pipe_config->requested_mode.clock * 3 |
| 4106 | > IRONLAKE_FDI_FREQ * 4) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 4107 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4108 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 4109 | |
Daniel Vetter | f9bef08 | 2012-04-15 19:53:19 +0200 | [diff] [blame] | 4110 | /* All interlaced capable intel hw wants timings in frames. Note though |
| 4111 | * that intel_lvds_mode_fixup does some funny tricks with the crtc |
| 4112 | * timings, so we need to be careful not to clobber these.*/ |
Daniel Vetter | 7ae8923 | 2013-03-27 00:44:52 +0100 | [diff] [blame] | 4113 | if (!pipe_config->timings_set) |
Daniel Vetter | f9bef08 | 2012-04-15 19:53:19 +0200 | [diff] [blame] | 4114 | drm_mode_set_crtcinfo(adjusted_mode, 0); |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 4115 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 4116 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 4117 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 4118 | */ |
| 4119 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
| 4120 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 4121 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 4122 | |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 4123 | if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) && pipe_config->pipe_bpp > 10*3) { |
Daniel Vetter | 5d2d38d | 2013-03-27 00:45:01 +0100 | [diff] [blame] | 4124 | pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */ |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 4125 | } else if (INTEL_INFO(dev)->gen <= 4 && pipe_config->pipe_bpp > 8*3) { |
Daniel Vetter | 5d2d38d | 2013-03-27 00:45:01 +0100 | [diff] [blame] | 4126 | /* only a 8bpc pipe, with 6bpc dither through the panel fitter |
| 4127 | * for lvds. */ |
| 4128 | pipe_config->pipe_bpp = 8*3; |
| 4129 | } |
| 4130 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4131 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 4132 | hsw_compute_ips_config(crtc, pipe_config); |
| 4133 | |
| 4134 | /* XXX: PCH clock sharing is done in ->mode_set, so make sure the old |
| 4135 | * clock survives for now. */ |
| 4136 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 4137 | pipe_config->shared_dpll = crtc->config.shared_dpll; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4138 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4139 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 4140 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 4141 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 4142 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4143 | } |
| 4144 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 4145 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 4146 | { |
| 4147 | return 400000; /* FIXME */ |
| 4148 | } |
| 4149 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4150 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4151 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4152 | return 400000; |
| 4153 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4154 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4155 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 4156 | { |
| 4157 | return 333000; |
| 4158 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4159 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4160 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 4161 | { |
| 4162 | return 200000; |
| 4163 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4164 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4165 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 4166 | { |
| 4167 | u16 gcfgc = 0; |
| 4168 | |
| 4169 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 4170 | |
| 4171 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4172 | return 133000; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4173 | else { |
| 4174 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 4175 | case GC_DISPLAY_CLOCK_333_MHZ: |
| 4176 | return 333000; |
| 4177 | default: |
| 4178 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 4179 | return 190000; |
| 4180 | } |
| 4181 | } |
| 4182 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4183 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 4184 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 4185 | { |
| 4186 | return 266000; |
| 4187 | } |
| 4188 | |
| 4189 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 4190 | { |
| 4191 | u16 hpllcc = 0; |
| 4192 | /* Assume that the hardware is in the high speed state. This |
| 4193 | * should be the default. |
| 4194 | */ |
| 4195 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 4196 | case GC_CLOCK_133_200: |
| 4197 | case GC_CLOCK_100_200: |
| 4198 | return 200000; |
| 4199 | case GC_CLOCK_166_250: |
| 4200 | return 250000; |
| 4201 | case GC_CLOCK_100_133: |
| 4202 | return 133000; |
| 4203 | } |
| 4204 | |
| 4205 | /* Shouldn't happen */ |
| 4206 | return 0; |
| 4207 | } |
| 4208 | |
| 4209 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 4210 | { |
| 4211 | return 133000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4212 | } |
| 4213 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4214 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 4215 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4216 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 4217 | while (*num > DATA_LINK_M_N_MASK || |
| 4218 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4219 | *num >>= 1; |
| 4220 | *den >>= 1; |
| 4221 | } |
| 4222 | } |
| 4223 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 4224 | static void compute_m_n(unsigned int m, unsigned int n, |
| 4225 | uint32_t *ret_m, uint32_t *ret_n) |
| 4226 | { |
| 4227 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 4228 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 4229 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 4230 | } |
| 4231 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 4232 | void |
| 4233 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 4234 | int pixel_clock, int link_clock, |
| 4235 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4236 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 4237 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 4238 | |
| 4239 | compute_m_n(bits_per_pixel * pixel_clock, |
| 4240 | link_clock * nlanes * 8, |
| 4241 | &m_n->gmch_m, &m_n->gmch_n); |
| 4242 | |
| 4243 | compute_m_n(pixel_clock, link_clock, |
| 4244 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4245 | } |
| 4246 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 4247 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 4248 | { |
Keith Packard | 72bbe58 | 2011-09-26 16:09:45 -0700 | [diff] [blame] | 4249 | if (i915_panel_use_ssc >= 0) |
| 4250 | return i915_panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 4251 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 4252 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 4253 | } |
| 4254 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4255 | static int vlv_get_refclk(struct drm_crtc *crtc) |
| 4256 | { |
| 4257 | struct drm_device *dev = crtc->dev; |
| 4258 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4259 | int refclk = 27000; /* for DP & HDMI */ |
| 4260 | |
| 4261 | return 100000; /* only one validated so far */ |
| 4262 | |
| 4263 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { |
| 4264 | refclk = 96000; |
| 4265 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 4266 | if (intel_panel_use_ssc(dev_priv)) |
| 4267 | refclk = 100000; |
| 4268 | else |
| 4269 | refclk = 96000; |
| 4270 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) { |
| 4271 | refclk = 100000; |
| 4272 | } |
| 4273 | |
| 4274 | return refclk; |
| 4275 | } |
| 4276 | |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4277 | static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors) |
| 4278 | { |
| 4279 | struct drm_device *dev = crtc->dev; |
| 4280 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4281 | int refclk; |
| 4282 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4283 | if (IS_VALLEYVIEW(dev)) { |
| 4284 | refclk = vlv_get_refclk(crtc); |
| 4285 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4286 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 4287 | refclk = dev_priv->vbt.lvds_ssc_freq * 1000; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4288 | DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n", |
| 4289 | refclk / 1000); |
| 4290 | } else if (!IS_GEN2(dev)) { |
| 4291 | refclk = 96000; |
| 4292 | } else { |
| 4293 | refclk = 48000; |
| 4294 | } |
| 4295 | |
| 4296 | return refclk; |
| 4297 | } |
| 4298 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 4299 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4300 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 4301 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 4302 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4303 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 4304 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 4305 | { |
| 4306 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4307 | } |
| 4308 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4309 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4310 | intel_clock_t *reduced_clock) |
| 4311 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4312 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4313 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4314 | int pipe = crtc->pipe; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4315 | u32 fp, fp2 = 0; |
| 4316 | |
| 4317 | if (IS_PINEVIEW(dev)) { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 4318 | fp = pnv_dpll_compute_fp(&crtc->config.dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4319 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 4320 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4321 | } else { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 4322 | fp = i9xx_dpll_compute_fp(&crtc->config.dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4323 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 4324 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4325 | } |
| 4326 | |
| 4327 | I915_WRITE(FP0(pipe), fp); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 4328 | crtc->config.dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4329 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4330 | crtc->lowfreq_avail = false; |
| 4331 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4332 | reduced_clock && i915_powersave) { |
| 4333 | I915_WRITE(FP1(pipe), fp2); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 4334 | crtc->config.dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4335 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4336 | } else { |
| 4337 | I915_WRITE(FP1(pipe), fp); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 4338 | crtc->config.dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 4339 | } |
| 4340 | } |
| 4341 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4342 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv) |
| 4343 | { |
| 4344 | u32 reg_val; |
| 4345 | |
| 4346 | /* |
| 4347 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 4348 | * and set it to a reasonable value instead. |
| 4349 | */ |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4350 | reg_val = vlv_dpio_read(dev_priv, DPIO_IREF(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4351 | reg_val &= 0xffffff00; |
| 4352 | reg_val |= 0x00000030; |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4353 | vlv_dpio_write(dev_priv, DPIO_IREF(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4354 | |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4355 | reg_val = vlv_dpio_read(dev_priv, DPIO_CALIBRATION); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4356 | reg_val &= 0x8cffffff; |
| 4357 | reg_val = 0x8c000000; |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4358 | vlv_dpio_write(dev_priv, DPIO_CALIBRATION, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4359 | |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4360 | reg_val = vlv_dpio_read(dev_priv, DPIO_IREF(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4361 | reg_val &= 0xffffff00; |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4362 | vlv_dpio_write(dev_priv, DPIO_IREF(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4363 | |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4364 | reg_val = vlv_dpio_read(dev_priv, DPIO_CALIBRATION); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4365 | reg_val &= 0x00ffffff; |
| 4366 | reg_val |= 0xb0000000; |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4367 | vlv_dpio_write(dev_priv, DPIO_CALIBRATION, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4368 | } |
| 4369 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 4370 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 4371 | struct intel_link_m_n *m_n) |
| 4372 | { |
| 4373 | struct drm_device *dev = crtc->base.dev; |
| 4374 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4375 | int pipe = crtc->pipe; |
| 4376 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 4377 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 4378 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 4379 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 4380 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 4381 | } |
| 4382 | |
| 4383 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
| 4384 | struct intel_link_m_n *m_n) |
| 4385 | { |
| 4386 | struct drm_device *dev = crtc->base.dev; |
| 4387 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4388 | int pipe = crtc->pipe; |
| 4389 | enum transcoder transcoder = crtc->config.cpu_transcoder; |
| 4390 | |
| 4391 | if (INTEL_INFO(dev)->gen >= 5) { |
| 4392 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 4393 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 4394 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 4395 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
| 4396 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 4397 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 4398 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 4399 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 4400 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 4401 | } |
| 4402 | } |
| 4403 | |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 4404 | static void intel_dp_set_m_n(struct intel_crtc *crtc) |
| 4405 | { |
| 4406 | if (crtc->config.has_pch_encoder) |
| 4407 | intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n); |
| 4408 | else |
| 4409 | intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n); |
| 4410 | } |
| 4411 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4412 | static void vlv_update_pll(struct intel_crtc *crtc) |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4413 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4414 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4415 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4416 | int pipe = crtc->pipe; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4417 | u32 dpll, mdiv; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4418 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4419 | bool is_hdmi; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 4420 | u32 coreclk, reg_val, dpll_md; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4421 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 4422 | mutex_lock(&dev_priv->dpio_lock); |
| 4423 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4424 | is_hdmi = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4425 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4426 | bestn = crtc->config.dpll.n; |
| 4427 | bestm1 = crtc->config.dpll.m1; |
| 4428 | bestm2 = crtc->config.dpll.m2; |
| 4429 | bestp1 = crtc->config.dpll.p1; |
| 4430 | bestp2 = crtc->config.dpll.p2; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4431 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4432 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 4433 | |
| 4434 | /* PLL B needs special handling */ |
| 4435 | if (pipe) |
| 4436 | vlv_pllb_recal_opamp(dev_priv); |
| 4437 | |
| 4438 | /* Set up Tx target for periodic Rcomp update */ |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4439 | vlv_dpio_write(dev_priv, DPIO_IREF_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4440 | |
| 4441 | /* Disable target IRef on PLL */ |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4442 | reg_val = vlv_dpio_read(dev_priv, DPIO_IREF_CTL(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4443 | reg_val &= 0x00ffffff; |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4444 | vlv_dpio_write(dev_priv, DPIO_IREF_CTL(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4445 | |
| 4446 | /* Disable fast lock */ |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4447 | vlv_dpio_write(dev_priv, DPIO_FASTCLK_DISABLE, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4448 | |
| 4449 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4450 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 4451 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 4452 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4453 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 4454 | |
| 4455 | /* |
| 4456 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 4457 | * but we don't support that). |
| 4458 | * Note: don't use the DAC post divider as it seems unstable. |
| 4459 | */ |
| 4460 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4461 | vlv_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4462 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4463 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4464 | vlv_dpio_write(dev_priv, DPIO_DIV(pipe), mdiv); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4465 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4466 | /* Set HBR and RBR LPF coefficients */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 4467 | if (crtc->config.port_clock == 162000 || |
Ville Syrjälä | 99750bd | 2013-06-14 14:02:52 +0300 | [diff] [blame] | 4468 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) || |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4469 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) |
Ville Syrjälä | 4abb2c3 | 2013-06-14 14:02:53 +0300 | [diff] [blame] | 4470 | vlv_dpio_write(dev_priv, DPIO_LPF_COEFF(pipe), |
Ville Syrjälä | 885b012 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 4471 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4472 | else |
Ville Syrjälä | 4abb2c3 | 2013-06-14 14:02:53 +0300 | [diff] [blame] | 4473 | vlv_dpio_write(dev_priv, DPIO_LPF_COEFF(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4474 | 0x00d0000f); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4475 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4476 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) || |
| 4477 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) { |
| 4478 | /* Use SSC source */ |
| 4479 | if (!pipe) |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4480 | vlv_dpio_write(dev_priv, DPIO_REFSFR(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4481 | 0x0df40000); |
| 4482 | else |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4483 | vlv_dpio_write(dev_priv, DPIO_REFSFR(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4484 | 0x0df70000); |
| 4485 | } else { /* HDMI or VGA */ |
| 4486 | /* Use bend source */ |
| 4487 | if (!pipe) |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4488 | vlv_dpio_write(dev_priv, DPIO_REFSFR(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4489 | 0x0df70000); |
| 4490 | else |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4491 | vlv_dpio_write(dev_priv, DPIO_REFSFR(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4492 | 0x0df40000); |
| 4493 | } |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4494 | |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4495 | coreclk = vlv_dpio_read(dev_priv, DPIO_CORE_CLK(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4496 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
| 4497 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) || |
| 4498 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP)) |
| 4499 | coreclk |= 0x01000000; |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4500 | vlv_dpio_write(dev_priv, DPIO_CORE_CLK(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4501 | |
Jani Nikula | ae99258 | 2013-05-22 15:36:19 +0300 | [diff] [blame] | 4502 | vlv_dpio_write(dev_priv, DPIO_PLL_CML(pipe), 0x87871000); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4503 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4504 | /* Enable DPIO clock input */ |
| 4505 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | |
| 4506 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; |
| 4507 | if (pipe) |
| 4508 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4509 | |
| 4510 | dpll |= DPLL_VCO_ENABLE; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 4511 | crtc->config.dpll_hw_state.dpll = dpll; |
| 4512 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 4513 | dpll_md = (crtc->config.pixel_multiplier - 1) |
| 4514 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 4515 | crtc->config.dpll_hw_state.dpll_md = dpll_md; |
| 4516 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4517 | if (crtc->config.has_dp_encoder) |
| 4518 | intel_dp_set_m_n(crtc); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4519 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 4520 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4521 | } |
| 4522 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4523 | static void i9xx_update_pll(struct intel_crtc *crtc, |
| 4524 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4525 | int num_connectors) |
| 4526 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4527 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4528 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4529 | u32 dpll; |
| 4530 | bool is_sdvo; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4531 | struct dpll *clock = &crtc->config.dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4532 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4533 | i9xx_update_pll_dividers(crtc, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4534 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4535 | is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) || |
| 4536 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4537 | |
| 4538 | dpll = DPLL_VGA_MODE_DIS; |
| 4539 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4540 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4541 | dpll |= DPLLB_MODE_LVDS; |
| 4542 | else |
| 4543 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 4544 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 4545 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 4546 | dpll |= (crtc->config.pixel_multiplier - 1) |
| 4547 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4548 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 4549 | |
| 4550 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 4551 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 4552 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4553 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 4554 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4555 | |
| 4556 | /* compute bitmask from p1 value */ |
| 4557 | if (IS_PINEVIEW(dev)) |
| 4558 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 4559 | else { |
| 4560 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 4561 | if (IS_G4X(dev) && reduced_clock) |
| 4562 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 4563 | } |
| 4564 | switch (clock->p2) { |
| 4565 | case 5: |
| 4566 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 4567 | break; |
| 4568 | case 7: |
| 4569 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 4570 | break; |
| 4571 | case 10: |
| 4572 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 4573 | break; |
| 4574 | case 14: |
| 4575 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 4576 | break; |
| 4577 | } |
| 4578 | if (INTEL_INFO(dev)->gen >= 4) |
| 4579 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 4580 | |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 4581 | if (crtc->config.sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4582 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4583 | else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4584 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 4585 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 4586 | else |
| 4587 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 4588 | |
| 4589 | dpll |= DPLL_VCO_ENABLE; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 4590 | crtc->config.dpll_hw_state.dpll = dpll; |
| 4591 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4592 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 4593 | u32 dpll_md = (crtc->config.pixel_multiplier - 1) |
| 4594 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 4595 | crtc->config.dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4596 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 4597 | |
| 4598 | if (crtc->config.has_dp_encoder) |
| 4599 | intel_dp_set_m_n(crtc); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4600 | } |
| 4601 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4602 | static void i8xx_update_pll(struct intel_crtc *crtc, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4603 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4604 | int num_connectors) |
| 4605 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4606 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4607 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4608 | u32 dpll; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4609 | struct dpll *clock = &crtc->config.dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4610 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4611 | i9xx_update_pll_dividers(crtc, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4612 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4613 | dpll = DPLL_VGA_MODE_DIS; |
| 4614 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4615 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4616 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 4617 | } else { |
| 4618 | if (clock->p1 == 2) |
| 4619 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 4620 | else |
| 4621 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 4622 | if (clock->p2 == 4) |
| 4623 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 4624 | } |
| 4625 | |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 4626 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO)) |
| 4627 | dpll |= DPLL_DVO_2X_MODE; |
| 4628 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4629 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4630 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 4631 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 4632 | else |
| 4633 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 4634 | |
| 4635 | dpll |= DPLL_VCO_ENABLE; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 4636 | crtc->config.dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4637 | } |
| 4638 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 4639 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4640 | { |
| 4641 | struct drm_device *dev = intel_crtc->base.dev; |
| 4642 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4643 | enum pipe pipe = intel_crtc->pipe; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 4644 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 4645 | struct drm_display_mode *adjusted_mode = |
| 4646 | &intel_crtc->config.adjusted_mode; |
| 4647 | struct drm_display_mode *mode = &intel_crtc->config.requested_mode; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 4648 | uint32_t vsyncshift, crtc_vtotal, crtc_vblank_end; |
| 4649 | |
| 4650 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 4651 | * the hw state checker will get angry at the mismatch. */ |
| 4652 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 4653 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4654 | |
| 4655 | if (!IS_GEN2(dev) && adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 4656 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 4657 | crtc_vtotal -= 1; |
| 4658 | crtc_vblank_end -= 1; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4659 | vsyncshift = adjusted_mode->crtc_hsync_start |
| 4660 | - adjusted_mode->crtc_htotal / 2; |
| 4661 | } else { |
| 4662 | vsyncshift = 0; |
| 4663 | } |
| 4664 | |
| 4665 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4666 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4667 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4668 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4669 | (adjusted_mode->crtc_hdisplay - 1) | |
| 4670 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4671 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4672 | (adjusted_mode->crtc_hblank_start - 1) | |
| 4673 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4674 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4675 | (adjusted_mode->crtc_hsync_start - 1) | |
| 4676 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 4677 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4678 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4679 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 4680 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4681 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4682 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 4683 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 4684 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4685 | (adjusted_mode->crtc_vsync_start - 1) | |
| 4686 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 4687 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 4688 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 4689 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 4690 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 4691 | * bits. */ |
| 4692 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 4693 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 4694 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 4695 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 4696 | /* pipesrc controls the size that is scaled from, which should |
| 4697 | * always be the user's requested size. |
| 4698 | */ |
| 4699 | I915_WRITE(PIPESRC(pipe), |
| 4700 | ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1)); |
| 4701 | } |
| 4702 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 4703 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
| 4704 | struct intel_crtc_config *pipe_config) |
| 4705 | { |
| 4706 | struct drm_device *dev = crtc->base.dev; |
| 4707 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4708 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 4709 | uint32_t tmp; |
| 4710 | |
| 4711 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
| 4712 | pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 4713 | pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
| 4714 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
| 4715 | pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 4716 | pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
| 4717 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
| 4718 | pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 4719 | pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
| 4720 | |
| 4721 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
| 4722 | pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 4723 | pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
| 4724 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
| 4725 | pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 4726 | pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
| 4727 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
| 4728 | pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 4729 | pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
| 4730 | |
| 4731 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
| 4732 | pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 4733 | pipe_config->adjusted_mode.crtc_vtotal += 1; |
| 4734 | pipe_config->adjusted_mode.crtc_vblank_end += 1; |
| 4735 | } |
| 4736 | |
| 4737 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
| 4738 | pipe_config->requested_mode.vdisplay = (tmp & 0xffff) + 1; |
| 4739 | pipe_config->requested_mode.hdisplay = ((tmp >> 16) & 0xffff) + 1; |
| 4740 | } |
| 4741 | |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 4742 | static void intel_crtc_mode_from_pipe_config(struct intel_crtc *intel_crtc, |
| 4743 | struct intel_crtc_config *pipe_config) |
| 4744 | { |
| 4745 | struct drm_crtc *crtc = &intel_crtc->base; |
| 4746 | |
| 4747 | crtc->mode.hdisplay = pipe_config->adjusted_mode.crtc_hdisplay; |
| 4748 | crtc->mode.htotal = pipe_config->adjusted_mode.crtc_htotal; |
| 4749 | crtc->mode.hsync_start = pipe_config->adjusted_mode.crtc_hsync_start; |
| 4750 | crtc->mode.hsync_end = pipe_config->adjusted_mode.crtc_hsync_end; |
| 4751 | |
| 4752 | crtc->mode.vdisplay = pipe_config->adjusted_mode.crtc_vdisplay; |
| 4753 | crtc->mode.vtotal = pipe_config->adjusted_mode.crtc_vtotal; |
| 4754 | crtc->mode.vsync_start = pipe_config->adjusted_mode.crtc_vsync_start; |
| 4755 | crtc->mode.vsync_end = pipe_config->adjusted_mode.crtc_vsync_end; |
| 4756 | |
| 4757 | crtc->mode.flags = pipe_config->adjusted_mode.flags; |
| 4758 | |
| 4759 | crtc->mode.clock = pipe_config->adjusted_mode.clock; |
| 4760 | crtc->mode.flags |= pipe_config->adjusted_mode.flags; |
| 4761 | } |
| 4762 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 4763 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 4764 | { |
| 4765 | struct drm_device *dev = intel_crtc->base.dev; |
| 4766 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4767 | uint32_t pipeconf; |
| 4768 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 4769 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 4770 | |
| 4771 | if (intel_crtc->pipe == 0 && INTEL_INFO(dev)->gen < 4) { |
| 4772 | /* Enable pixel doubling when the dot clock is > 90% of the (display) |
| 4773 | * core speed. |
| 4774 | * |
| 4775 | * XXX: No double-wide on 915GM pipe B. Is that the only reason for the |
| 4776 | * pipe == 0 check? |
| 4777 | */ |
| 4778 | if (intel_crtc->config.requested_mode.clock > |
| 4779 | dev_priv->display.get_display_clock_speed(dev) * 9 / 10) |
| 4780 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 4781 | } |
| 4782 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 4783 | /* only g4x and later have fancy bpc/dither controls */ |
| 4784 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 4785 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
| 4786 | if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30) |
| 4787 | pipeconf |= PIPECONF_DITHER_EN | |
| 4788 | PIPECONF_DITHER_TYPE_SP; |
| 4789 | |
| 4790 | switch (intel_crtc->config.pipe_bpp) { |
| 4791 | case 18: |
| 4792 | pipeconf |= PIPECONF_6BPC; |
| 4793 | break; |
| 4794 | case 24: |
| 4795 | pipeconf |= PIPECONF_8BPC; |
| 4796 | break; |
| 4797 | case 30: |
| 4798 | pipeconf |= PIPECONF_10BPC; |
| 4799 | break; |
| 4800 | default: |
| 4801 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 4802 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 4803 | } |
| 4804 | } |
| 4805 | |
| 4806 | if (HAS_PIPE_CXSR(dev)) { |
| 4807 | if (intel_crtc->lowfreq_avail) { |
| 4808 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 4809 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 4810 | } else { |
| 4811 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 4812 | } |
| 4813 | } |
| 4814 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 4815 | if (!IS_GEN2(dev) && |
| 4816 | intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
| 4817 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 4818 | else |
| 4819 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 4820 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 4821 | if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range) |
| 4822 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 4823 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 4824 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 4825 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 4826 | } |
| 4827 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4828 | static int i9xx_crtc_mode_set(struct drm_crtc *crtc, |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4829 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 4830 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4831 | { |
| 4832 | struct drm_device *dev = crtc->dev; |
| 4833 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4834 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 4835 | struct drm_display_mode *mode = &intel_crtc->config.requested_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4836 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 4837 | int plane = intel_crtc->plane; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 4838 | int refclk, num_connectors = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 4839 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 4840 | u32 dspcntr; |
Daniel Vetter | a16af721 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 4841 | bool ok, has_reduced_clock = false; |
| 4842 | bool is_lvds = false; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4843 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 4844 | const intel_limit_t *limit; |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 4845 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4846 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 4847 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4848 | switch (encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4849 | case INTEL_OUTPUT_LVDS: |
| 4850 | is_lvds = true; |
| 4851 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4852 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 4853 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 4854 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4855 | } |
| 4856 | |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 4857 | refclk = i9xx_get_refclk(crtc, num_connectors); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4858 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 4859 | /* |
| 4860 | * Returns a set of divisors for the desired target clock with the given |
| 4861 | * refclk, or FALSE. The returned values represent the clock equation: |
| 4862 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 4863 | */ |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 4864 | limit = intel_limit(crtc, refclk); |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 4865 | ok = dev_priv->display.find_dpll(limit, crtc, |
| 4866 | intel_crtc->config.port_clock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 4867 | refclk, NULL, &clock); |
| 4868 | if (!ok && !intel_crtc->config.clock_set) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4869 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4870 | return -EINVAL; |
| 4871 | } |
| 4872 | |
| 4873 | /* Ensure that the cursor is valid for the new mode before changing... */ |
| 4874 | intel_crtc_update_cursor(crtc, true); |
| 4875 | |
| 4876 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 4877 | /* |
| 4878 | * Ensure we match the reduced clock's P to the target clock. |
| 4879 | * If the clocks don't match, we can't switch the display clock |
| 4880 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 4881 | * downclock feature. |
| 4882 | */ |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 4883 | has_reduced_clock = |
| 4884 | dev_priv->display.find_dpll(limit, crtc, |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4885 | dev_priv->lvds_downclock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 4886 | refclk, &clock, |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4887 | &reduced_clock); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4888 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4889 | /* Compat-code for transition, will disappear. */ |
| 4890 | if (!intel_crtc->config.clock_set) { |
| 4891 | intel_crtc->config.dpll.n = clock.n; |
| 4892 | intel_crtc->config.dpll.m1 = clock.m1; |
| 4893 | intel_crtc->config.dpll.m2 = clock.m2; |
| 4894 | intel_crtc->config.dpll.p1 = clock.p1; |
| 4895 | intel_crtc->config.dpll.p2 = clock.p2; |
| 4896 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4897 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4898 | if (IS_GEN2(dev)) |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 4899 | i8xx_update_pll(intel_crtc, |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 4900 | has_reduced_clock ? &reduced_clock : NULL, |
| 4901 | num_connectors); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 4902 | else if (IS_VALLEYVIEW(dev)) |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4903 | vlv_update_pll(intel_crtc); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4904 | else |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 4905 | i9xx_update_pll(intel_crtc, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 4906 | has_reduced_clock ? &reduced_clock : NULL, |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4907 | num_connectors); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4908 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4909 | /* Set up the display plane register */ |
| 4910 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 4911 | |
Jesse Barnes | da6ecc5 | 2013-03-08 10:46:00 -0800 | [diff] [blame] | 4912 | if (!IS_VALLEYVIEW(dev)) { |
| 4913 | if (pipe == 0) |
| 4914 | dspcntr &= ~DISPPLANE_SEL_PIPE_MASK; |
| 4915 | else |
| 4916 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 4917 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4918 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 4919 | intel_set_pipe_timings(intel_crtc); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4920 | |
| 4921 | /* pipesrc and dspsize control the size that is scaled from, |
| 4922 | * which should always be the user's requested size. |
| 4923 | */ |
Eric Anholt | 929c77f | 2011-03-30 13:01:04 -0700 | [diff] [blame] | 4924 | I915_WRITE(DSPSIZE(plane), |
| 4925 | ((mode->vdisplay - 1) << 16) | |
| 4926 | (mode->hdisplay - 1)); |
| 4927 | I915_WRITE(DSPPOS(plane), 0); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4928 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 4929 | i9xx_set_pipeconf(intel_crtc); |
| 4930 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4931 | I915_WRITE(DSPCNTR(plane), dspcntr); |
| 4932 | POSTING_READ(DSPCNTR(plane)); |
| 4933 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 4934 | ret = intel_pipe_set_base(crtc, x, y, fb); |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4935 | |
| 4936 | intel_update_watermarks(dev); |
| 4937 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 4938 | return ret; |
| 4939 | } |
| 4940 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 4941 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
| 4942 | struct intel_crtc_config *pipe_config) |
| 4943 | { |
| 4944 | struct drm_device *dev = crtc->base.dev; |
| 4945 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4946 | uint32_t tmp; |
| 4947 | |
| 4948 | tmp = I915_READ(PFIT_CONTROL); |
| 4949 | |
| 4950 | if (INTEL_INFO(dev)->gen < 4) { |
| 4951 | if (crtc->pipe != PIPE_B) |
| 4952 | return; |
| 4953 | |
| 4954 | /* gen2/3 store dither state in pfit control, needs to match */ |
| 4955 | pipe_config->gmch_pfit.control = tmp & PANEL_8TO6_DITHER_ENABLE; |
| 4956 | } else { |
| 4957 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 4958 | return; |
| 4959 | } |
| 4960 | |
| 4961 | if (!(tmp & PFIT_ENABLE)) |
| 4962 | return; |
| 4963 | |
| 4964 | pipe_config->gmch_pfit.control = I915_READ(PFIT_CONTROL); |
| 4965 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 4966 | if (INTEL_INFO(dev)->gen < 5) |
| 4967 | pipe_config->gmch_pfit.lvds_border_bits = |
| 4968 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 4969 | } |
| 4970 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 4971 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
| 4972 | struct intel_crtc_config *pipe_config) |
| 4973 | { |
| 4974 | struct drm_device *dev = crtc->base.dev; |
| 4975 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4976 | uint32_t tmp; |
| 4977 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 4978 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 4979 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 4980 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 4981 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 4982 | if (!(tmp & PIPECONF_ENABLE)) |
| 4983 | return false; |
| 4984 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 4985 | intel_get_pipe_timings(crtc, pipe_config); |
| 4986 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 4987 | i9xx_get_pfit_config(crtc, pipe_config); |
| 4988 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 4989 | if (INTEL_INFO(dev)->gen >= 4) { |
| 4990 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
| 4991 | pipe_config->pixel_multiplier = |
| 4992 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 4993 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 4994 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 4995 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 4996 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 4997 | pipe_config->pixel_multiplier = |
| 4998 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 4999 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 5000 | } else { |
| 5001 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 5002 | * port and will be fixed up in the encoder->get_config |
| 5003 | * function. */ |
| 5004 | pipe_config->pixel_multiplier = 1; |
| 5005 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5006 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
| 5007 | if (!IS_VALLEYVIEW(dev)) { |
| 5008 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 5009 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 5010 | } else { |
| 5011 | /* Mask out read-only status bits. */ |
| 5012 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 5013 | DPLL_PORTC_READY_MASK | |
| 5014 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5015 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 5016 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 5017 | return true; |
| 5018 | } |
| 5019 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 5020 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5021 | { |
| 5022 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5023 | struct drm_mode_config *mode_config = &dev->mode_config; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5024 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5025 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5026 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5027 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5028 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 5029 | bool has_ck505 = false; |
| 5030 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5031 | |
| 5032 | /* We need to take the global config into account */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5033 | list_for_each_entry(encoder, &mode_config->encoder_list, |
| 5034 | base.head) { |
| 5035 | switch (encoder->type) { |
| 5036 | case INTEL_OUTPUT_LVDS: |
| 5037 | has_panel = true; |
| 5038 | has_lvds = true; |
| 5039 | break; |
| 5040 | case INTEL_OUTPUT_EDP: |
| 5041 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 5042 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5043 | has_cpu_edp = true; |
| 5044 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5045 | } |
| 5046 | } |
| 5047 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 5048 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5049 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 5050 | can_ssc = has_ck505; |
| 5051 | } else { |
| 5052 | has_ck505 = false; |
| 5053 | can_ssc = true; |
| 5054 | } |
| 5055 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 5056 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 5057 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5058 | |
| 5059 | /* Ironlake: try to setup display ref clock before DPLL |
| 5060 | * enabling. This is only under driver's control after |
| 5061 | * PCH B stepping, previous chipset stepping should be |
| 5062 | * ignoring this setting. |
| 5063 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5064 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5065 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5066 | /* As we must carefully and slowly disable/enable each source in turn, |
| 5067 | * compute the final state we want first and check if we need to |
| 5068 | * make any changes at all. |
| 5069 | */ |
| 5070 | final = val; |
| 5071 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 5072 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5073 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 5074 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5075 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 5076 | |
| 5077 | final &= ~DREF_SSC_SOURCE_MASK; |
| 5078 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 5079 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5080 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5081 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5082 | final |= DREF_SSC_SOURCE_ENABLE; |
| 5083 | |
| 5084 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 5085 | final |= DREF_SSC1_ENABLE; |
| 5086 | |
| 5087 | if (has_cpu_edp) { |
| 5088 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 5089 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 5090 | else |
| 5091 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 5092 | } else |
| 5093 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 5094 | } else { |
| 5095 | final |= DREF_SSC_SOURCE_DISABLE; |
| 5096 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 5097 | } |
| 5098 | |
| 5099 | if (final == val) |
| 5100 | return; |
| 5101 | |
| 5102 | /* Always enable nonspread source */ |
| 5103 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 5104 | |
| 5105 | if (has_ck505) |
| 5106 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 5107 | else |
| 5108 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 5109 | |
| 5110 | if (has_panel) { |
| 5111 | val &= ~DREF_SSC_SOURCE_MASK; |
| 5112 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5113 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5114 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 5115 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5116 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5117 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 5118 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5119 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5120 | |
| 5121 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5122 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5123 | POSTING_READ(PCH_DREF_CONTROL); |
| 5124 | udelay(200); |
| 5125 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5126 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5127 | |
| 5128 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5129 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 5130 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5131 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5132 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5133 | } |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5134 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5135 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5136 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5137 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5138 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5139 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5140 | POSTING_READ(PCH_DREF_CONTROL); |
| 5141 | udelay(200); |
| 5142 | } else { |
| 5143 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 5144 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5145 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5146 | |
| 5147 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5148 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5149 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5150 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5151 | POSTING_READ(PCH_DREF_CONTROL); |
| 5152 | udelay(200); |
| 5153 | |
| 5154 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5155 | val &= ~DREF_SSC_SOURCE_MASK; |
| 5156 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5157 | |
| 5158 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5159 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 5160 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5161 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5162 | POSTING_READ(PCH_DREF_CONTROL); |
| 5163 | udelay(200); |
| 5164 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 5165 | |
| 5166 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 5167 | } |
| 5168 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 5169 | /* Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O. */ |
| 5170 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 5171 | { |
| 5172 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5173 | struct drm_mode_config *mode_config = &dev->mode_config; |
| 5174 | struct intel_encoder *encoder; |
| 5175 | bool has_vga = false; |
| 5176 | bool is_sdv = false; |
| 5177 | u32 tmp; |
| 5178 | |
| 5179 | list_for_each_entry(encoder, &mode_config->encoder_list, base.head) { |
| 5180 | switch (encoder->type) { |
| 5181 | case INTEL_OUTPUT_ANALOG: |
| 5182 | has_vga = true; |
| 5183 | break; |
| 5184 | } |
| 5185 | } |
| 5186 | |
| 5187 | if (!has_vga) |
| 5188 | return; |
| 5189 | |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 5190 | mutex_lock(&dev_priv->dpio_lock); |
| 5191 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 5192 | /* XXX: Rip out SDV support once Haswell ships for real. */ |
| 5193 | if (IS_HASWELL(dev) && (dev->pci_device & 0xFF00) == 0x0C00) |
| 5194 | is_sdv = true; |
| 5195 | |
| 5196 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 5197 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 5198 | tmp |= SBI_SSCCTL_PATHALT; |
| 5199 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 5200 | |
| 5201 | udelay(24); |
| 5202 | |
| 5203 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 5204 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 5205 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 5206 | |
| 5207 | if (!is_sdv) { |
| 5208 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 5209 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 5210 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
| 5211 | |
| 5212 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 5213 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 5214 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
| 5215 | |
| 5216 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 5217 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 5218 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
| 5219 | |
| 5220 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 5221 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, |
| 5222 | 100)) |
| 5223 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
| 5224 | } |
| 5225 | |
| 5226 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 5227 | tmp &= ~(0xFF << 24); |
| 5228 | tmp |= (0x12 << 24); |
| 5229 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 5230 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 5231 | if (is_sdv) { |
| 5232 | tmp = intel_sbi_read(dev_priv, 0x800C, SBI_MPHY); |
| 5233 | tmp |= 0x7FFF; |
| 5234 | intel_sbi_write(dev_priv, 0x800C, tmp, SBI_MPHY); |
| 5235 | } |
| 5236 | |
| 5237 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 5238 | tmp |= (1 << 11); |
| 5239 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 5240 | |
| 5241 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 5242 | tmp |= (1 << 11); |
| 5243 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 5244 | |
| 5245 | if (is_sdv) { |
| 5246 | tmp = intel_sbi_read(dev_priv, 0x2038, SBI_MPHY); |
| 5247 | tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16); |
| 5248 | intel_sbi_write(dev_priv, 0x2038, tmp, SBI_MPHY); |
| 5249 | |
| 5250 | tmp = intel_sbi_read(dev_priv, 0x2138, SBI_MPHY); |
| 5251 | tmp |= (0x3F << 24) | (0xF << 20) | (0xF << 16); |
| 5252 | intel_sbi_write(dev_priv, 0x2138, tmp, SBI_MPHY); |
| 5253 | |
| 5254 | tmp = intel_sbi_read(dev_priv, 0x203C, SBI_MPHY); |
| 5255 | tmp |= (0x3F << 8); |
| 5256 | intel_sbi_write(dev_priv, 0x203C, tmp, SBI_MPHY); |
| 5257 | |
| 5258 | tmp = intel_sbi_read(dev_priv, 0x213C, SBI_MPHY); |
| 5259 | tmp |= (0x3F << 8); |
| 5260 | intel_sbi_write(dev_priv, 0x213C, tmp, SBI_MPHY); |
| 5261 | } |
| 5262 | |
| 5263 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 5264 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 5265 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 5266 | |
| 5267 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 5268 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 5269 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 5270 | |
| 5271 | if (!is_sdv) { |
| 5272 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 5273 | tmp &= ~(7 << 13); |
| 5274 | tmp |= (5 << 13); |
| 5275 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
| 5276 | |
| 5277 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 5278 | tmp &= ~(7 << 13); |
| 5279 | tmp |= (5 << 13); |
| 5280 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
| 5281 | } |
| 5282 | |
| 5283 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 5284 | tmp &= ~0xFF; |
| 5285 | tmp |= 0x1C; |
| 5286 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 5287 | |
| 5288 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 5289 | tmp &= ~0xFF; |
| 5290 | tmp |= 0x1C; |
| 5291 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 5292 | |
| 5293 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 5294 | tmp &= ~(0xFF << 16); |
| 5295 | tmp |= (0x1C << 16); |
| 5296 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 5297 | |
| 5298 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 5299 | tmp &= ~(0xFF << 16); |
| 5300 | tmp |= (0x1C << 16); |
| 5301 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 5302 | |
| 5303 | if (!is_sdv) { |
| 5304 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 5305 | tmp |= (1 << 27); |
| 5306 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
| 5307 | |
| 5308 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 5309 | tmp |= (1 << 27); |
| 5310 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
| 5311 | |
| 5312 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 5313 | tmp &= ~(0xF << 28); |
| 5314 | tmp |= (4 << 28); |
| 5315 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
| 5316 | |
| 5317 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 5318 | tmp &= ~(0xF << 28); |
| 5319 | tmp |= (4 << 28); |
| 5320 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
| 5321 | } |
| 5322 | |
| 5323 | /* ULT uses SBI_GEN0, but ULT doesn't have VGA, so we don't care. */ |
| 5324 | tmp = intel_sbi_read(dev_priv, SBI_DBUFF0, SBI_ICLK); |
| 5325 | tmp |= SBI_DBUFF0_ENABLE; |
| 5326 | intel_sbi_write(dev_priv, SBI_DBUFF0, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 5327 | |
| 5328 | mutex_unlock(&dev_priv->dpio_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 5329 | } |
| 5330 | |
| 5331 | /* |
| 5332 | * Initialize reference clocks when the driver loads |
| 5333 | */ |
| 5334 | void intel_init_pch_refclk(struct drm_device *dev) |
| 5335 | { |
| 5336 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 5337 | ironlake_init_pch_refclk(dev); |
| 5338 | else if (HAS_PCH_LPT(dev)) |
| 5339 | lpt_init_pch_refclk(dev); |
| 5340 | } |
| 5341 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 5342 | static int ironlake_get_refclk(struct drm_crtc *crtc) |
| 5343 | { |
| 5344 | struct drm_device *dev = crtc->dev; |
| 5345 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5346 | struct intel_encoder *encoder; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 5347 | int num_connectors = 0; |
| 5348 | bool is_lvds = false; |
| 5349 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 5350 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 5351 | switch (encoder->type) { |
| 5352 | case INTEL_OUTPUT_LVDS: |
| 5353 | is_lvds = true; |
| 5354 | break; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 5355 | } |
| 5356 | num_connectors++; |
| 5357 | } |
| 5358 | |
| 5359 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
| 5360 | DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n", |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5361 | dev_priv->vbt.lvds_ssc_freq); |
| 5362 | return dev_priv->vbt.lvds_ssc_freq * 1000; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 5363 | } |
| 5364 | |
| 5365 | return 120000; |
| 5366 | } |
| 5367 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 5368 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5369 | { |
| 5370 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 5371 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5372 | int pipe = intel_crtc->pipe; |
| 5373 | uint32_t val; |
| 5374 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 5375 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5376 | |
Daniel Vetter | 965e0c4 | 2013-03-27 00:44:57 +0100 | [diff] [blame] | 5377 | switch (intel_crtc->config.pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5378 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 5379 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5380 | break; |
| 5381 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 5382 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5383 | break; |
| 5384 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 5385 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5386 | break; |
| 5387 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 5388 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5389 | break; |
| 5390 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 5391 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 5392 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5393 | } |
| 5394 | |
Daniel Vetter | d8b3224 | 2013-04-25 17:54:44 +0200 | [diff] [blame] | 5395 | if (intel_crtc->config.dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5396 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 5397 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 5398 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5399 | val |= PIPECONF_INTERLACED_ILK; |
| 5400 | else |
| 5401 | val |= PIPECONF_PROGRESSIVE; |
| 5402 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 5403 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 5404 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 5405 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 5406 | I915_WRITE(PIPECONF(pipe), val); |
| 5407 | POSTING_READ(PIPECONF(pipe)); |
| 5408 | } |
| 5409 | |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 5410 | /* |
| 5411 | * Set up the pipe CSC unit. |
| 5412 | * |
| 5413 | * Currently only full range RGB to limited range RGB conversion |
| 5414 | * is supported, but eventually this should handle various |
| 5415 | * RGB<->YCbCr scenarios as well. |
| 5416 | */ |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 5417 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 5418 | { |
| 5419 | struct drm_device *dev = crtc->dev; |
| 5420 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5421 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5422 | int pipe = intel_crtc->pipe; |
| 5423 | uint16_t coeff = 0x7800; /* 1.0 */ |
| 5424 | |
| 5425 | /* |
| 5426 | * TODO: Check what kind of values actually come out of the pipe |
| 5427 | * with these coeff/postoff values and adjust to get the best |
| 5428 | * accuracy. Perhaps we even need to take the bpc value into |
| 5429 | * consideration. |
| 5430 | */ |
| 5431 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 5432 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 5433 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
| 5434 | |
| 5435 | /* |
| 5436 | * GY/GU and RY/RU should be the other way around according |
| 5437 | * to BSpec, but reality doesn't agree. Just set them up in |
| 5438 | * a way that results in the correct picture. |
| 5439 | */ |
| 5440 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); |
| 5441 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); |
| 5442 | |
| 5443 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); |
| 5444 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); |
| 5445 | |
| 5446 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); |
| 5447 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); |
| 5448 | |
| 5449 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); |
| 5450 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); |
| 5451 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); |
| 5452 | |
| 5453 | if (INTEL_INFO(dev)->gen > 6) { |
| 5454 | uint16_t postoff = 0; |
| 5455 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 5456 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 5457 | postoff = (16 * (1 << 13) / 255) & 0x1fff; |
| 5458 | |
| 5459 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); |
| 5460 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); |
| 5461 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); |
| 5462 | |
| 5463 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); |
| 5464 | } else { |
| 5465 | uint32_t mode = CSC_MODE_YUV_TO_RGB; |
| 5466 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 5467 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 5468 | mode |= CSC_BLACK_SCREEN_OFFSET; |
| 5469 | |
| 5470 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); |
| 5471 | } |
| 5472 | } |
| 5473 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 5474 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 5475 | { |
| 5476 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 5477 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 5478 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 5479 | uint32_t val; |
| 5480 | |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 5481 | val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 5482 | |
Daniel Vetter | d8b3224 | 2013-04-25 17:54:44 +0200 | [diff] [blame] | 5483 | if (intel_crtc->config.dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 5484 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 5485 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 5486 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 5487 | val |= PIPECONF_INTERLACED_ILK; |
| 5488 | else |
| 5489 | val |= PIPECONF_PROGRESSIVE; |
| 5490 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 5491 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 5492 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 5493 | |
| 5494 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); |
| 5495 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 5496 | } |
| 5497 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5498 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5499 | intel_clock_t *clock, |
| 5500 | bool *has_reduced_clock, |
| 5501 | intel_clock_t *reduced_clock) |
| 5502 | { |
| 5503 | struct drm_device *dev = crtc->dev; |
| 5504 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5505 | struct intel_encoder *intel_encoder; |
| 5506 | int refclk; |
| 5507 | const intel_limit_t *limit; |
Daniel Vetter | a16af721 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 5508 | bool ret, is_lvds = false; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5509 | |
| 5510 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 5511 | switch (intel_encoder->type) { |
| 5512 | case INTEL_OUTPUT_LVDS: |
| 5513 | is_lvds = true; |
| 5514 | break; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5515 | } |
| 5516 | } |
| 5517 | |
| 5518 | refclk = ironlake_get_refclk(crtc); |
| 5519 | |
| 5520 | /* |
| 5521 | * Returns a set of divisors for the desired target clock with the given |
| 5522 | * refclk, or FALSE. The returned values represent the clock equation: |
| 5523 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 5524 | */ |
| 5525 | limit = intel_limit(crtc, refclk); |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 5526 | ret = dev_priv->display.find_dpll(limit, crtc, |
| 5527 | to_intel_crtc(crtc)->config.port_clock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 5528 | refclk, NULL, clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5529 | if (!ret) |
| 5530 | return false; |
| 5531 | |
| 5532 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 5533 | /* |
| 5534 | * Ensure we match the reduced clock's P to the target clock. |
| 5535 | * If the clocks don't match, we can't switch the display clock |
| 5536 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 5537 | * downclock feature. |
| 5538 | */ |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 5539 | *has_reduced_clock = |
| 5540 | dev_priv->display.find_dpll(limit, crtc, |
| 5541 | dev_priv->lvds_downclock, |
| 5542 | refclk, clock, |
| 5543 | reduced_clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5544 | } |
| 5545 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5546 | return true; |
| 5547 | } |
| 5548 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5549 | static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev) |
| 5550 | { |
| 5551 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5552 | uint32_t temp; |
| 5553 | |
| 5554 | temp = I915_READ(SOUTH_CHICKEN1); |
| 5555 | if (temp & FDI_BC_BIFURCATION_SELECT) |
| 5556 | return; |
| 5557 | |
| 5558 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 5559 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 5560 | |
| 5561 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 5562 | DRM_DEBUG_KMS("enabling fdi C rx\n"); |
| 5563 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 5564 | POSTING_READ(SOUTH_CHICKEN1); |
| 5565 | } |
| 5566 | |
Daniel Vetter | ebfd86f | 2013-04-19 11:24:44 +0200 | [diff] [blame] | 5567 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5568 | { |
| 5569 | struct drm_device *dev = intel_crtc->base.dev; |
| 5570 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5571 | |
| 5572 | switch (intel_crtc->pipe) { |
| 5573 | case PIPE_A: |
Daniel Vetter | ebfd86f | 2013-04-19 11:24:44 +0200 | [diff] [blame] | 5574 | break; |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5575 | case PIPE_B: |
Daniel Vetter | ebfd86f | 2013-04-19 11:24:44 +0200 | [diff] [blame] | 5576 | if (intel_crtc->config.fdi_lanes > 2) |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5577 | WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT); |
| 5578 | else |
| 5579 | cpt_enable_fdi_bc_bifurcation(dev); |
| 5580 | |
Daniel Vetter | ebfd86f | 2013-04-19 11:24:44 +0200 | [diff] [blame] | 5581 | break; |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5582 | case PIPE_C: |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5583 | cpt_enable_fdi_bc_bifurcation(dev); |
| 5584 | |
Daniel Vetter | ebfd86f | 2013-04-19 11:24:44 +0200 | [diff] [blame] | 5585 | break; |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 5586 | default: |
| 5587 | BUG(); |
| 5588 | } |
| 5589 | } |
| 5590 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 5591 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 5592 | { |
| 5593 | /* |
| 5594 | * Account for spread spectrum to avoid |
| 5595 | * oversubscribing the link. Max center spread |
| 5596 | * is 2.5%; use 5% for safety's sake. |
| 5597 | */ |
| 5598 | u32 bps = target_clock * bpp * 21 / 20; |
| 5599 | return bps / (link_bw * 8) + 1; |
| 5600 | } |
| 5601 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5602 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 5603 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5604 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5605 | } |
| 5606 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5607 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5608 | u32 *fp, |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 5609 | intel_clock_t *reduced_clock, u32 *fp2) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5610 | { |
| 5611 | struct drm_crtc *crtc = &intel_crtc->base; |
| 5612 | struct drm_device *dev = crtc->dev; |
| 5613 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5614 | struct intel_encoder *intel_encoder; |
| 5615 | uint32_t dpll; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 5616 | int factor, num_connectors = 0; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 5617 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5618 | |
| 5619 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 5620 | switch (intel_encoder->type) { |
| 5621 | case INTEL_OUTPUT_LVDS: |
| 5622 | is_lvds = true; |
| 5623 | break; |
| 5624 | case INTEL_OUTPUT_SDVO: |
| 5625 | case INTEL_OUTPUT_HDMI: |
| 5626 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5627 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5628 | } |
| 5629 | |
| 5630 | num_connectors++; |
| 5631 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5632 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 5633 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5634 | factor = 21; |
| 5635 | if (is_lvds) { |
| 5636 | if ((intel_panel_use_ssc(dev_priv) && |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5637 | dev_priv->vbt.lvds_ssc_freq == 100) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 5638 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5639 | factor = 25; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 5640 | } else if (intel_crtc->config.sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 5641 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 5642 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5643 | if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor)) |
Daniel Vetter | 7d0ac5b | 2013-04-04 22:20:32 +0200 | [diff] [blame] | 5644 | *fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 5645 | |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 5646 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
| 5647 | *fp2 |= FP_CB_TUNE; |
| 5648 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 5649 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5650 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5651 | if (is_lvds) |
| 5652 | dpll |= DPLLB_MODE_LVDS; |
| 5653 | else |
| 5654 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 5655 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 5656 | dpll |= (intel_crtc->config.pixel_multiplier - 1) |
| 5657 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 5658 | |
| 5659 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 5660 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 9566e9a | 2013-04-19 11:14:36 +0200 | [diff] [blame] | 5661 | if (intel_crtc->config.has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 5662 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5663 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5664 | /* compute bitmask from p1 value */ |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5665 | dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5666 | /* also FPA1 */ |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5667 | dpll |= (1 << (intel_crtc->config.dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5668 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5669 | switch (intel_crtc->config.dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 5670 | case 5: |
| 5671 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 5672 | break; |
| 5673 | case 7: |
| 5674 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 5675 | break; |
| 5676 | case 10: |
| 5677 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 5678 | break; |
| 5679 | case 14: |
| 5680 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 5681 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5682 | } |
| 5683 | |
Daniel Vetter | b4c09f3 | 2013-04-30 14:01:42 +0200 | [diff] [blame] | 5684 | 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] | 5685 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5686 | else |
| 5687 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 5688 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 5689 | return dpll | DPLL_VCO_ENABLE; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5690 | } |
| 5691 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5692 | static int ironlake_crtc_mode_set(struct drm_crtc *crtc, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5693 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 5694 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5695 | { |
| 5696 | struct drm_device *dev = crtc->dev; |
| 5697 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5698 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5699 | int pipe = intel_crtc->pipe; |
| 5700 | int plane = intel_crtc->plane; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5701 | int num_connectors = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5702 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 5703 | u32 dpll = 0, fp = 0, fp2 = 0; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 5704 | bool ok, has_reduced_clock = false; |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 5705 | bool is_lvds = false; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 5706 | struct intel_encoder *encoder; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 5707 | struct intel_shared_dpll *pll; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 5708 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5709 | |
| 5710 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 5711 | switch (encoder->type) { |
| 5712 | case INTEL_OUTPUT_LVDS: |
| 5713 | is_lvds = true; |
| 5714 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5715 | } |
| 5716 | |
| 5717 | num_connectors++; |
| 5718 | } |
| 5719 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 5720 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 5721 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 5722 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 5723 | ok = ironlake_compute_clocks(crtc, &clock, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 5724 | &has_reduced_clock, &reduced_clock); |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 5725 | if (!ok && !intel_crtc->config.clock_set) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5726 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 5727 | return -EINVAL; |
| 5728 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5729 | /* Compat-code for transition, will disappear. */ |
| 5730 | if (!intel_crtc->config.clock_set) { |
| 5731 | intel_crtc->config.dpll.n = clock.n; |
| 5732 | intel_crtc->config.dpll.m1 = clock.m1; |
| 5733 | intel_crtc->config.dpll.m2 = clock.m2; |
| 5734 | intel_crtc->config.dpll.p1 = clock.p1; |
| 5735 | intel_crtc->config.dpll.p2 = clock.p2; |
| 5736 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5737 | |
| 5738 | /* Ensure that the cursor is valid for the new mode before changing... */ |
| 5739 | intel_crtc_update_cursor(crtc, true); |
| 5740 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 5741 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 5742 | if (intel_crtc->config.has_pch_encoder) { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5743 | fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 5744 | if (has_reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5745 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 5746 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5747 | dpll = ironlake_compute_dpll(intel_crtc, |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 5748 | &fp, &reduced_clock, |
| 5749 | has_reduced_clock ? &fp2 : NULL); |
| 5750 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 5751 | intel_crtc->config.dpll_hw_state.dpll = dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 5752 | intel_crtc->config.dpll_hw_state.fp0 = fp; |
| 5753 | if (has_reduced_clock) |
| 5754 | intel_crtc->config.dpll_hw_state.fp1 = fp2; |
| 5755 | else |
| 5756 | intel_crtc->config.dpll_hw_state.fp1 = fp; |
| 5757 | |
Daniel Vetter | b89a1d3 | 2013-06-05 13:34:24 +0200 | [diff] [blame] | 5758 | pll = intel_get_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5759 | if (pll == NULL) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 5760 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
| 5761 | pipe_name(pipe)); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 5762 | return -EINVAL; |
| 5763 | } |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5764 | } else |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 5765 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5766 | |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 5767 | if (intel_crtc->config.has_dp_encoder) |
| 5768 | intel_dp_set_m_n(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5769 | |
Daniel Vetter | bcd644e | 2013-06-05 13:34:22 +0200 | [diff] [blame] | 5770 | if (is_lvds && has_reduced_clock && i915_powersave) |
| 5771 | intel_crtc->lowfreq_avail = true; |
| 5772 | else |
| 5773 | intel_crtc->lowfreq_avail = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 5774 | |
| 5775 | if (intel_crtc->config.has_pch_encoder) { |
| 5776 | pll = intel_crtc_to_shared_dpll(intel_crtc); |
| 5777 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5778 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5779 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 5780 | intel_set_pipe_timings(intel_crtc); |
Krzysztof Halasa | 734b415 | 2010-05-25 18:41:46 +0200 | [diff] [blame] | 5781 | |
Daniel Vetter | ca3a0ff | 2013-02-14 16:54:22 +0100 | [diff] [blame] | 5782 | if (intel_crtc->config.has_pch_encoder) { |
Daniel Vetter | ca3a0ff | 2013-02-14 16:54:22 +0100 | [diff] [blame] | 5783 | intel_cpu_transcoder_set_m_n(intel_crtc, |
| 5784 | &intel_crtc->config.fdi_m_n); |
| 5785 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 5786 | |
Daniel Vetter | ebfd86f | 2013-04-19 11:24:44 +0200 | [diff] [blame] | 5787 | if (IS_IVYBRIDGE(dev)) |
| 5788 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5789 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 5790 | ironlake_set_pipeconf(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5791 | |
Paulo Zanoni | a1f9e77 | 2012-09-12 10:06:32 -0300 | [diff] [blame] | 5792 | /* Set up the display plane register */ |
| 5793 | I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 5794 | POSTING_READ(DSPCNTR(plane)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5795 | |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 5796 | ret = intel_pipe_set_base(crtc, x, y, fb); |
Shaohua Li | 7662c8b | 2009-06-26 11:23:55 +0800 | [diff] [blame] | 5797 | |
| 5798 | intel_update_watermarks(dev); |
| 5799 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5800 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5801 | } |
| 5802 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 5803 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
| 5804 | struct intel_crtc_config *pipe_config) |
| 5805 | { |
| 5806 | struct drm_device *dev = crtc->base.dev; |
| 5807 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5808 | enum transcoder transcoder = pipe_config->cpu_transcoder; |
| 5809 | |
| 5810 | pipe_config->fdi_m_n.link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 5811 | pipe_config->fdi_m_n.link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 5812 | pipe_config->fdi_m_n.gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 5813 | & ~TU_SIZE_MASK; |
| 5814 | pipe_config->fdi_m_n.gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 5815 | pipe_config->fdi_m_n.tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 5816 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 5817 | } |
| 5818 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 5819 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
| 5820 | struct intel_crtc_config *pipe_config) |
| 5821 | { |
| 5822 | struct drm_device *dev = crtc->base.dev; |
| 5823 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5824 | uint32_t tmp; |
| 5825 | |
| 5826 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 5827 | |
| 5828 | if (tmp & PF_ENABLE) { |
| 5829 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 5830 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 5831 | |
| 5832 | /* We currently do not free assignements of panel fitters on |
| 5833 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 5834 | * differentiates them) so just WARN about this case for now. */ |
| 5835 | if (IS_GEN7(dev)) { |
| 5836 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 5837 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 5838 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 5839 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5840 | } |
| 5841 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 5842 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
| 5843 | struct intel_crtc_config *pipe_config) |
| 5844 | { |
| 5845 | struct drm_device *dev = crtc->base.dev; |
| 5846 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5847 | uint32_t tmp; |
| 5848 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 5849 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 5850 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 5851 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 5852 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 5853 | if (!(tmp & PIPECONF_ENABLE)) |
| 5854 | return false; |
| 5855 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 5856 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 5857 | struct intel_shared_dpll *pll; |
| 5858 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 5859 | pipe_config->has_pch_encoder = true; |
| 5860 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 5861 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 5862 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 5863 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 5864 | |
| 5865 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 5866 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 5867 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 5868 | pipe_config->shared_dpll = |
| 5869 | (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 5870 | } else { |
| 5871 | tmp = I915_READ(PCH_DPLL_SEL); |
| 5872 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
| 5873 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; |
| 5874 | else |
| 5875 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; |
| 5876 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 5877 | |
| 5878 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 5879 | |
| 5880 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 5881 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 5882 | |
| 5883 | tmp = pipe_config->dpll_hw_state.dpll; |
| 5884 | pipe_config->pixel_multiplier = |
| 5885 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 5886 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 5887 | } else { |
| 5888 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 5889 | } |
| 5890 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 5891 | intel_get_pipe_timings(crtc, pipe_config); |
| 5892 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 5893 | ironlake_get_pfit_config(crtc, pipe_config); |
| 5894 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 5895 | return true; |
| 5896 | } |
| 5897 | |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 5898 | static void haswell_modeset_global_resources(struct drm_device *dev) |
| 5899 | { |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 5900 | bool enable = false; |
| 5901 | struct intel_crtc *crtc; |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 5902 | |
| 5903 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) { |
Daniel Vetter | e7a639c | 2013-05-31 17:49:17 +0200 | [diff] [blame] | 5904 | if (!crtc->base.enabled) |
| 5905 | continue; |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 5906 | |
Daniel Vetter | e7a639c | 2013-05-31 17:49:17 +0200 | [diff] [blame] | 5907 | if (crtc->pipe != PIPE_A || crtc->config.pch_pfit.size || |
| 5908 | crtc->config.cpu_transcoder != TRANSCODER_EDP) |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 5909 | enable = true; |
| 5910 | } |
| 5911 | |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 5912 | intel_set_power_well(dev, enable); |
| 5913 | } |
| 5914 | |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5915 | static int haswell_crtc_mode_set(struct drm_crtc *crtc, |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5916 | int x, int y, |
| 5917 | struct drm_framebuffer *fb) |
| 5918 | { |
| 5919 | struct drm_device *dev = crtc->dev; |
| 5920 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5921 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5922 | int plane = intel_crtc->plane; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5923 | int ret; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5924 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 5925 | if (!intel_ddi_pll_mode_set(crtc)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 5926 | return -EINVAL; |
| 5927 | |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5928 | /* Ensure that the cursor is valid for the new mode before changing... */ |
| 5929 | intel_crtc_update_cursor(crtc, true); |
| 5930 | |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 5931 | if (intel_crtc->config.has_dp_encoder) |
| 5932 | intel_dp_set_m_n(intel_crtc); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5933 | |
| 5934 | intel_crtc->lowfreq_avail = false; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5935 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 5936 | intel_set_pipe_timings(intel_crtc); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5937 | |
Daniel Vetter | ca3a0ff | 2013-02-14 16:54:22 +0100 | [diff] [blame] | 5938 | if (intel_crtc->config.has_pch_encoder) { |
Daniel Vetter | ca3a0ff | 2013-02-14 16:54:22 +0100 | [diff] [blame] | 5939 | intel_cpu_transcoder_set_m_n(intel_crtc, |
| 5940 | &intel_crtc->config.fdi_m_n); |
| 5941 | } |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5942 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 5943 | haswell_set_pipeconf(crtc); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5944 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 5945 | intel_set_pipe_csc(crtc); |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 5946 | |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5947 | /* Set up the display plane register */ |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 5948 | I915_WRITE(DSPCNTR(plane), DISPPLANE_GAMMA_ENABLE | DISPPLANE_PIPE_CSC_ENABLE); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 5949 | POSTING_READ(DSPCNTR(plane)); |
| 5950 | |
| 5951 | ret = intel_pipe_set_base(crtc, x, y, fb); |
| 5952 | |
| 5953 | intel_update_watermarks(dev); |
| 5954 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5955 | return ret; |
| 5956 | } |
| 5957 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 5958 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
| 5959 | struct intel_crtc_config *pipe_config) |
| 5960 | { |
| 5961 | struct drm_device *dev = crtc->base.dev; |
| 5962 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 5963 | enum intel_display_power_domain pfit_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 5964 | uint32_t tmp; |
| 5965 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 5966 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 5967 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
| 5968 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 5969 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 5970 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 5971 | enum pipe trans_edp_pipe; |
| 5972 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 5973 | default: |
| 5974 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 5975 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 5976 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 5977 | trans_edp_pipe = PIPE_A; |
| 5978 | break; |
| 5979 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 5980 | trans_edp_pipe = PIPE_B; |
| 5981 | break; |
| 5982 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 5983 | trans_edp_pipe = PIPE_C; |
| 5984 | break; |
| 5985 | } |
| 5986 | |
| 5987 | if (trans_edp_pipe == crtc->pipe) |
| 5988 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 5989 | } |
| 5990 | |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 5991 | if (!intel_display_power_enabled(dev, |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 5992 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
Paulo Zanoni | 2bfce95 | 2013-04-18 16:35:40 -0300 | [diff] [blame] | 5993 | return false; |
| 5994 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 5995 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 5996 | if (!(tmp & PIPECONF_ENABLE)) |
| 5997 | return false; |
| 5998 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 5999 | /* |
Paulo Zanoni | f196e6b | 2013-04-18 16:35:41 -0300 | [diff] [blame] | 6000 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 6001 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 6002 | * the PCH transcoder is on. |
| 6003 | */ |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 6004 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 6005 | if ((tmp & TRANS_DDI_PORT_MASK) == TRANS_DDI_SELECT_PORT(PORT_E) && |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 6006 | I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 6007 | pipe_config->has_pch_encoder = true; |
| 6008 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 6009 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 6010 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 6011 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 6012 | |
| 6013 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 6014 | } |
| 6015 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6016 | intel_get_pipe_timings(crtc, pipe_config); |
| 6017 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6018 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
| 6019 | if (intel_display_power_enabled(dev, pfit_domain)) |
| 6020 | ironlake_get_pfit_config(crtc, pipe_config); |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 6021 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6022 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 6023 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
| 6024 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6025 | pipe_config->pixel_multiplier = 1; |
| 6026 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6027 | return true; |
| 6028 | } |
| 6029 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6030 | static int intel_crtc_mode_set(struct drm_crtc *crtc, |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6031 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6032 | struct drm_framebuffer *fb) |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6033 | { |
| 6034 | struct drm_device *dev = crtc->dev; |
| 6035 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 9256aa1 | 2012-10-31 19:26:13 +0100 | [diff] [blame] | 6036 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 6037 | struct intel_encoder *encoder; |
Eric Anholt | 0b701d2 | 2011-03-30 13:01:03 -0700 | [diff] [blame] | 6038 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 6039 | struct drm_display_mode *adjusted_mode = |
| 6040 | &intel_crtc->config.adjusted_mode; |
| 6041 | struct drm_display_mode *mode = &intel_crtc->config.requested_mode; |
Eric Anholt | 0b701d2 | 2011-03-30 13:01:03 -0700 | [diff] [blame] | 6042 | int pipe = intel_crtc->pipe; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6043 | int ret; |
| 6044 | |
Eric Anholt | 0b701d2 | 2011-03-30 13:01:03 -0700 | [diff] [blame] | 6045 | drm_vblank_pre_modeset(dev, pipe); |
| 6046 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 6047 | ret = dev_priv->display.crtc_mode_set(crtc, x, y, fb); |
| 6048 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6049 | drm_vblank_post_modeset(dev, pipe); |
| 6050 | |
Daniel Vetter | 9256aa1 | 2012-10-31 19:26:13 +0100 | [diff] [blame] | 6051 | if (ret != 0) |
| 6052 | return ret; |
| 6053 | |
| 6054 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 6055 | DRM_DEBUG_KMS("[ENCODER:%d:%s] set [MODE:%d:%s]\n", |
| 6056 | encoder->base.base.id, |
| 6057 | drm_get_encoder_name(&encoder->base), |
| 6058 | mode->base.id, mode->name); |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 6059 | if (encoder->mode_set) { |
| 6060 | encoder->mode_set(encoder); |
| 6061 | } else { |
| 6062 | encoder_funcs = encoder->base.helper_private; |
| 6063 | encoder_funcs->mode_set(&encoder->base, mode, adjusted_mode); |
| 6064 | } |
Daniel Vetter | 9256aa1 | 2012-10-31 19:26:13 +0100 | [diff] [blame] | 6065 | } |
| 6066 | |
| 6067 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6068 | } |
| 6069 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 6070 | static bool intel_eld_uptodate(struct drm_connector *connector, |
| 6071 | int reg_eldv, uint32_t bits_eldv, |
| 6072 | int reg_elda, uint32_t bits_elda, |
| 6073 | int reg_edid) |
| 6074 | { |
| 6075 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 6076 | uint8_t *eld = connector->eld; |
| 6077 | uint32_t i; |
| 6078 | |
| 6079 | i = I915_READ(reg_eldv); |
| 6080 | i &= bits_eldv; |
| 6081 | |
| 6082 | if (!eld[0]) |
| 6083 | return !i; |
| 6084 | |
| 6085 | if (!i) |
| 6086 | return false; |
| 6087 | |
| 6088 | i = I915_READ(reg_elda); |
| 6089 | i &= ~bits_elda; |
| 6090 | I915_WRITE(reg_elda, i); |
| 6091 | |
| 6092 | for (i = 0; i < eld[2]; i++) |
| 6093 | if (I915_READ(reg_edid) != *((uint32_t *)eld + i)) |
| 6094 | return false; |
| 6095 | |
| 6096 | return true; |
| 6097 | } |
| 6098 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6099 | static void g4x_write_eld(struct drm_connector *connector, |
| 6100 | struct drm_crtc *crtc) |
| 6101 | { |
| 6102 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 6103 | uint8_t *eld = connector->eld; |
| 6104 | uint32_t eldv; |
| 6105 | uint32_t len; |
| 6106 | uint32_t i; |
| 6107 | |
| 6108 | i = I915_READ(G4X_AUD_VID_DID); |
| 6109 | |
| 6110 | if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL) |
| 6111 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 6112 | else |
| 6113 | eldv = G4X_ELDV_DEVCTG; |
| 6114 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 6115 | if (intel_eld_uptodate(connector, |
| 6116 | G4X_AUD_CNTL_ST, eldv, |
| 6117 | G4X_AUD_CNTL_ST, G4X_ELD_ADDR, |
| 6118 | G4X_HDMIW_HDMIEDID)) |
| 6119 | return; |
| 6120 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6121 | i = I915_READ(G4X_AUD_CNTL_ST); |
| 6122 | i &= ~(eldv | G4X_ELD_ADDR); |
| 6123 | len = (i >> 9) & 0x1f; /* ELD buffer size */ |
| 6124 | I915_WRITE(G4X_AUD_CNTL_ST, i); |
| 6125 | |
| 6126 | if (!eld[0]) |
| 6127 | return; |
| 6128 | |
| 6129 | len = min_t(uint8_t, eld[2], len); |
| 6130 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 6131 | for (i = 0; i < len; i++) |
| 6132 | I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i)); |
| 6133 | |
| 6134 | i = I915_READ(G4X_AUD_CNTL_ST); |
| 6135 | i |= eldv; |
| 6136 | I915_WRITE(G4X_AUD_CNTL_ST, i); |
| 6137 | } |
| 6138 | |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 6139 | static void haswell_write_eld(struct drm_connector *connector, |
| 6140 | struct drm_crtc *crtc) |
| 6141 | { |
| 6142 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 6143 | uint8_t *eld = connector->eld; |
| 6144 | struct drm_device *dev = crtc->dev; |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 6145 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 6146 | uint32_t eldv; |
| 6147 | uint32_t i; |
| 6148 | int len; |
| 6149 | int pipe = to_intel_crtc(crtc)->pipe; |
| 6150 | int tmp; |
| 6151 | |
| 6152 | int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe); |
| 6153 | int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe); |
| 6154 | int aud_config = HSW_AUD_CFG(pipe); |
| 6155 | int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD; |
| 6156 | |
| 6157 | |
| 6158 | DRM_DEBUG_DRIVER("HDMI: Haswell Audio initialize....\n"); |
| 6159 | |
| 6160 | /* Audio output enable */ |
| 6161 | DRM_DEBUG_DRIVER("HDMI audio: enable codec\n"); |
| 6162 | tmp = I915_READ(aud_cntrl_st2); |
| 6163 | tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4)); |
| 6164 | I915_WRITE(aud_cntrl_st2, tmp); |
| 6165 | |
| 6166 | /* Wait for 1 vertical blank */ |
| 6167 | intel_wait_for_vblank(dev, pipe); |
| 6168 | |
| 6169 | /* Set ELD valid state */ |
| 6170 | tmp = I915_READ(aud_cntrl_st2); |
| 6171 | DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%8x\n", tmp); |
| 6172 | tmp |= (AUDIO_ELD_VALID_A << (pipe * 4)); |
| 6173 | I915_WRITE(aud_cntrl_st2, tmp); |
| 6174 | tmp = I915_READ(aud_cntrl_st2); |
| 6175 | DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%8x\n", tmp); |
| 6176 | |
| 6177 | /* Enable HDMI mode */ |
| 6178 | tmp = I915_READ(aud_config); |
| 6179 | DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%8x\n", tmp); |
| 6180 | /* clear N_programing_enable and N_value_index */ |
| 6181 | tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE); |
| 6182 | I915_WRITE(aud_config, tmp); |
| 6183 | |
| 6184 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
| 6185 | |
| 6186 | eldv = AUDIO_ELD_VALID_A << (pipe * 4); |
Wang Xingchao | 7b9f35a | 2013-01-22 23:25:25 +0800 | [diff] [blame] | 6187 | intel_crtc->eld_vld = true; |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 6188 | |
| 6189 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
| 6190 | DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n"); |
| 6191 | eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */ |
| 6192 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
| 6193 | } else |
| 6194 | I915_WRITE(aud_config, 0); |
| 6195 | |
| 6196 | if (intel_eld_uptodate(connector, |
| 6197 | aud_cntrl_st2, eldv, |
| 6198 | aud_cntl_st, IBX_ELD_ADDRESS, |
| 6199 | hdmiw_hdmiedid)) |
| 6200 | return; |
| 6201 | |
| 6202 | i = I915_READ(aud_cntrl_st2); |
| 6203 | i &= ~eldv; |
| 6204 | I915_WRITE(aud_cntrl_st2, i); |
| 6205 | |
| 6206 | if (!eld[0]) |
| 6207 | return; |
| 6208 | |
| 6209 | i = I915_READ(aud_cntl_st); |
| 6210 | i &= ~IBX_ELD_ADDRESS; |
| 6211 | I915_WRITE(aud_cntl_st, i); |
| 6212 | i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */ |
| 6213 | DRM_DEBUG_DRIVER("port num:%d\n", i); |
| 6214 | |
| 6215 | len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
| 6216 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 6217 | for (i = 0; i < len; i++) |
| 6218 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 6219 | |
| 6220 | i = I915_READ(aud_cntrl_st2); |
| 6221 | i |= eldv; |
| 6222 | I915_WRITE(aud_cntrl_st2, i); |
| 6223 | |
| 6224 | } |
| 6225 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6226 | static void ironlake_write_eld(struct drm_connector *connector, |
| 6227 | struct drm_crtc *crtc) |
| 6228 | { |
| 6229 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 6230 | uint8_t *eld = connector->eld; |
| 6231 | uint32_t eldv; |
| 6232 | uint32_t i; |
| 6233 | int len; |
| 6234 | int hdmiw_hdmiedid; |
Wu Fengguang | b6daa02 | 2012-01-06 14:41:31 -0600 | [diff] [blame] | 6235 | int aud_config; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6236 | int aud_cntl_st; |
| 6237 | int aud_cntrl_st2; |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 6238 | int pipe = to_intel_crtc(crtc)->pipe; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6239 | |
Wu Fengguang | b3f33cb | 2011-12-09 20:42:17 +0800 | [diff] [blame] | 6240 | if (HAS_PCH_IBX(connector->dev)) { |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 6241 | hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe); |
| 6242 | aud_config = IBX_AUD_CFG(pipe); |
| 6243 | aud_cntl_st = IBX_AUD_CNTL_ST(pipe); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 6244 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6245 | } else { |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 6246 | hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe); |
| 6247 | aud_config = CPT_AUD_CFG(pipe); |
| 6248 | aud_cntl_st = CPT_AUD_CNTL_ST(pipe); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 6249 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6250 | } |
| 6251 | |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 6252 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6253 | |
| 6254 | i = I915_READ(aud_cntl_st); |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 6255 | i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */ |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6256 | if (!i) { |
| 6257 | DRM_DEBUG_DRIVER("Audio directed to unknown port\n"); |
| 6258 | /* operate blindly on all ports */ |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 6259 | eldv = IBX_ELD_VALIDB; |
| 6260 | eldv |= IBX_ELD_VALIDB << 4; |
| 6261 | eldv |= IBX_ELD_VALIDB << 8; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6262 | } else { |
Ville Syrjälä | 2582a85 | 2013-04-17 17:48:47 +0300 | [diff] [blame] | 6263 | DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i)); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 6264 | eldv = IBX_ELD_VALIDB << ((i - 1) * 4); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6265 | } |
| 6266 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 6267 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
| 6268 | DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n"); |
| 6269 | eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */ |
Wu Fengguang | b6daa02 | 2012-01-06 14:41:31 -0600 | [diff] [blame] | 6270 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
| 6271 | } else |
| 6272 | I915_WRITE(aud_config, 0); |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 6273 | |
| 6274 | if (intel_eld_uptodate(connector, |
| 6275 | aud_cntrl_st2, eldv, |
| 6276 | aud_cntl_st, IBX_ELD_ADDRESS, |
| 6277 | hdmiw_hdmiedid)) |
| 6278 | return; |
| 6279 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6280 | i = I915_READ(aud_cntrl_st2); |
| 6281 | i &= ~eldv; |
| 6282 | I915_WRITE(aud_cntrl_st2, i); |
| 6283 | |
| 6284 | if (!eld[0]) |
| 6285 | return; |
| 6286 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6287 | i = I915_READ(aud_cntl_st); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 6288 | i &= ~IBX_ELD_ADDRESS; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 6289 | I915_WRITE(aud_cntl_st, i); |
| 6290 | |
| 6291 | len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
| 6292 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 6293 | for (i = 0; i < len; i++) |
| 6294 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 6295 | |
| 6296 | i = I915_READ(aud_cntrl_st2); |
| 6297 | i |= eldv; |
| 6298 | I915_WRITE(aud_cntrl_st2, i); |
| 6299 | } |
| 6300 | |
| 6301 | void intel_write_eld(struct drm_encoder *encoder, |
| 6302 | struct drm_display_mode *mode) |
| 6303 | { |
| 6304 | struct drm_crtc *crtc = encoder->crtc; |
| 6305 | struct drm_connector *connector; |
| 6306 | struct drm_device *dev = encoder->dev; |
| 6307 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6308 | |
| 6309 | connector = drm_select_eld(encoder, mode); |
| 6310 | if (!connector) |
| 6311 | return; |
| 6312 | |
| 6313 | DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 6314 | connector->base.id, |
| 6315 | drm_get_connector_name(connector), |
| 6316 | connector->encoder->base.id, |
| 6317 | drm_get_encoder_name(connector->encoder)); |
| 6318 | |
| 6319 | connector->eld[6] = drm_av_sync_delay(connector, mode) / 2; |
| 6320 | |
| 6321 | if (dev_priv->display.write_eld) |
| 6322 | dev_priv->display.write_eld(connector, crtc); |
| 6323 | } |
| 6324 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6325 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 6326 | void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 6327 | { |
| 6328 | struct drm_device *dev = crtc->dev; |
| 6329 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6330 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6331 | enum pipe pipe = intel_crtc->pipe; |
| 6332 | int palreg = PALETTE(pipe); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6333 | int i; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6334 | bool reenable_ips = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6335 | |
| 6336 | /* The clocks have to be on to load the palette. */ |
Alban Browaeys | aed3f09 | 2012-02-24 17:12:45 +0000 | [diff] [blame] | 6337 | if (!crtc->enabled || !intel_crtc->active) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6338 | return; |
| 6339 | |
Ville Syrjälä | 14420bd | 2013-06-04 13:49:07 +0300 | [diff] [blame] | 6340 | if (!HAS_PCH_SPLIT(dev_priv->dev)) |
| 6341 | assert_pll_enabled(dev_priv, pipe); |
| 6342 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 6343 | /* use legacy palette for Ironlake */ |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 6344 | if (HAS_PCH_SPLIT(dev)) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6345 | palreg = LGC_PALETTE(pipe); |
| 6346 | |
| 6347 | /* Workaround : Do not read or write the pipe palette/gamma data while |
| 6348 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 6349 | */ |
| 6350 | if (intel_crtc->config.ips_enabled && |
| 6351 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
| 6352 | GAMMA_MODE_MODE_SPLIT)) { |
| 6353 | hsw_disable_ips(intel_crtc); |
| 6354 | reenable_ips = true; |
| 6355 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6356 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6357 | for (i = 0; i < 256; i++) { |
| 6358 | I915_WRITE(palreg + 4 * i, |
| 6359 | (intel_crtc->lut_r[i] << 16) | |
| 6360 | (intel_crtc->lut_g[i] << 8) | |
| 6361 | intel_crtc->lut_b[i]); |
| 6362 | } |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 6363 | |
| 6364 | if (reenable_ips) |
| 6365 | hsw_enable_ips(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6366 | } |
| 6367 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 6368 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 6369 | { |
| 6370 | struct drm_device *dev = crtc->dev; |
| 6371 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6372 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6373 | bool visible = base != 0; |
| 6374 | u32 cntl; |
| 6375 | |
| 6376 | if (intel_crtc->cursor_visible == visible) |
| 6377 | return; |
| 6378 | |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 6379 | cntl = I915_READ(_CURACNTR); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 6380 | if (visible) { |
| 6381 | /* On these chipsets we can only modify the base whilst |
| 6382 | * the cursor is disabled. |
| 6383 | */ |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 6384 | I915_WRITE(_CURABASE, base); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 6385 | |
| 6386 | cntl &= ~(CURSOR_FORMAT_MASK); |
| 6387 | /* XXX width must be 64, stride 256 => 0x00 << 28 */ |
| 6388 | cntl |= CURSOR_ENABLE | |
| 6389 | CURSOR_GAMMA_ENABLE | |
| 6390 | CURSOR_FORMAT_ARGB; |
| 6391 | } else |
| 6392 | cntl &= ~(CURSOR_ENABLE | CURSOR_GAMMA_ENABLE); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 6393 | I915_WRITE(_CURACNTR, cntl); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 6394 | |
| 6395 | intel_crtc->cursor_visible = visible; |
| 6396 | } |
| 6397 | |
| 6398 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 6399 | { |
| 6400 | struct drm_device *dev = crtc->dev; |
| 6401 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6402 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6403 | int pipe = intel_crtc->pipe; |
| 6404 | bool visible = base != 0; |
| 6405 | |
| 6406 | if (intel_crtc->cursor_visible != visible) { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 6407 | uint32_t cntl = I915_READ(CURCNTR(pipe)); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 6408 | if (base) { |
| 6409 | cntl &= ~(CURSOR_MODE | MCURSOR_PIPE_SELECT); |
| 6410 | cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; |
| 6411 | cntl |= pipe << 28; /* Connect to correct pipe */ |
| 6412 | } else { |
| 6413 | cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE); |
| 6414 | cntl |= CURSOR_MODE_DISABLE; |
| 6415 | } |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 6416 | I915_WRITE(CURCNTR(pipe), cntl); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 6417 | |
| 6418 | intel_crtc->cursor_visible = visible; |
| 6419 | } |
| 6420 | /* and commit changes on next vblank */ |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 6421 | I915_WRITE(CURBASE(pipe), base); |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 6422 | } |
| 6423 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 6424 | static void ivb_update_cursor(struct drm_crtc *crtc, u32 base) |
| 6425 | { |
| 6426 | struct drm_device *dev = crtc->dev; |
| 6427 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6428 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6429 | int pipe = intel_crtc->pipe; |
| 6430 | bool visible = base != 0; |
| 6431 | |
| 6432 | if (intel_crtc->cursor_visible != visible) { |
| 6433 | uint32_t cntl = I915_READ(CURCNTR_IVB(pipe)); |
| 6434 | if (base) { |
| 6435 | cntl &= ~CURSOR_MODE; |
| 6436 | cntl |= CURSOR_MODE_64_ARGB_AX | MCURSOR_GAMMA_ENABLE; |
| 6437 | } else { |
| 6438 | cntl &= ~(CURSOR_MODE | MCURSOR_GAMMA_ENABLE); |
| 6439 | cntl |= CURSOR_MODE_DISABLE; |
| 6440 | } |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6441 | if (IS_HASWELL(dev)) |
| 6442 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 6443 | I915_WRITE(CURCNTR_IVB(pipe), cntl); |
| 6444 | |
| 6445 | intel_crtc->cursor_visible = visible; |
| 6446 | } |
| 6447 | /* and commit changes on next vblank */ |
| 6448 | I915_WRITE(CURBASE_IVB(pipe), base); |
| 6449 | } |
| 6450 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6451 | /* 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] | 6452 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 6453 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6454 | { |
| 6455 | struct drm_device *dev = crtc->dev; |
| 6456 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6457 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6458 | int pipe = intel_crtc->pipe; |
| 6459 | int x = intel_crtc->cursor_x; |
| 6460 | int y = intel_crtc->cursor_y; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 6461 | u32 base, pos; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6462 | bool visible; |
| 6463 | |
| 6464 | pos = 0; |
| 6465 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 6466 | if (on && crtc->enabled && crtc->fb) { |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6467 | base = intel_crtc->cursor_addr; |
| 6468 | if (x > (int) crtc->fb->width) |
| 6469 | base = 0; |
| 6470 | |
| 6471 | if (y > (int) crtc->fb->height) |
| 6472 | base = 0; |
| 6473 | } else |
| 6474 | base = 0; |
| 6475 | |
| 6476 | if (x < 0) { |
| 6477 | if (x + intel_crtc->cursor_width < 0) |
| 6478 | base = 0; |
| 6479 | |
| 6480 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 6481 | x = -x; |
| 6482 | } |
| 6483 | pos |= x << CURSOR_X_SHIFT; |
| 6484 | |
| 6485 | if (y < 0) { |
| 6486 | if (y + intel_crtc->cursor_height < 0) |
| 6487 | base = 0; |
| 6488 | |
| 6489 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 6490 | y = -y; |
| 6491 | } |
| 6492 | pos |= y << CURSOR_Y_SHIFT; |
| 6493 | |
| 6494 | visible = base != 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 6495 | if (!visible && !intel_crtc->cursor_visible) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6496 | return; |
| 6497 | |
Eugeni Dodonov | 0cd83aa | 2012-04-13 17:08:48 -0300 | [diff] [blame] | 6498 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 6499 | I915_WRITE(CURPOS_IVB(pipe), pos); |
| 6500 | ivb_update_cursor(crtc, base); |
| 6501 | } else { |
| 6502 | I915_WRITE(CURPOS(pipe), pos); |
| 6503 | if (IS_845G(dev) || IS_I865G(dev)) |
| 6504 | i845_update_cursor(crtc, base); |
| 6505 | else |
| 6506 | i9xx_update_cursor(crtc, base); |
| 6507 | } |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6508 | } |
| 6509 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6510 | static int intel_crtc_cursor_set(struct drm_crtc *crtc, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6511 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6512 | uint32_t handle, |
| 6513 | uint32_t width, uint32_t height) |
| 6514 | { |
| 6515 | struct drm_device *dev = crtc->dev; |
| 6516 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6517 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6518 | struct drm_i915_gem_object *obj; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6519 | uint32_t addr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6520 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6521 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6522 | /* if we want to turn off the cursor ignore width and height */ |
| 6523 | if (!handle) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 6524 | DRM_DEBUG_KMS("cursor off\n"); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6525 | addr = 0; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6526 | obj = NULL; |
Pierre Willenbrock | 5004417 | 2009-02-23 10:12:15 +1000 | [diff] [blame] | 6527 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6528 | goto finish; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6529 | } |
| 6530 | |
| 6531 | /* Currently we only support 64x64 cursors */ |
| 6532 | if (width != 64 || height != 64) { |
| 6533 | DRM_ERROR("we currently only support 64x64 cursors\n"); |
| 6534 | return -EINVAL; |
| 6535 | } |
| 6536 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6537 | obj = to_intel_bo(drm_gem_object_lookup(dev, file, handle)); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 6538 | if (&obj->base == NULL) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6539 | return -ENOENT; |
| 6540 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6541 | if (obj->base.size < width * height * 4) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6542 | DRM_ERROR("buffer is to small\n"); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 6543 | ret = -ENOMEM; |
| 6544 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6545 | } |
| 6546 | |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6547 | /* 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] | 6548 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | b295d1b | 2009-12-16 15:16:17 -0500 | [diff] [blame] | 6549 | if (!dev_priv->info->cursor_needs_physical) { |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 6550 | unsigned alignment; |
| 6551 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 6552 | if (obj->tiling_mode) { |
| 6553 | DRM_ERROR("cursor cannot be tiled\n"); |
| 6554 | ret = -EINVAL; |
| 6555 | goto fail_locked; |
| 6556 | } |
| 6557 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 6558 | /* Note that the w/a also requires 2 PTE of padding following |
| 6559 | * the bo. We currently fill all unused PTE with the shadow |
| 6560 | * page and so we should always have valid PTE following the |
| 6561 | * cursor preventing the VT-d warning. |
| 6562 | */ |
| 6563 | alignment = 0; |
| 6564 | if (need_vtd_wa(dev)) |
| 6565 | alignment = 64*1024; |
| 6566 | |
| 6567 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL); |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 6568 | if (ret) { |
| 6569 | DRM_ERROR("failed to move cursor bo into the GTT\n"); |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 6570 | goto fail_locked; |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 6571 | } |
| 6572 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 6573 | ret = i915_gem_object_put_fence(obj); |
| 6574 | if (ret) { |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 6575 | DRM_ERROR("failed to release fence for cursor"); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 6576 | goto fail_unpin; |
| 6577 | } |
| 6578 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 6579 | addr = i915_gem_obj_ggtt_offset(obj); |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6580 | } else { |
Chris Wilson | 6eeefaf | 2010-08-07 11:01:39 +0100 | [diff] [blame] | 6581 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6582 | ret = i915_gem_attach_phys_object(dev, obj, |
Chris Wilson | 6eeefaf | 2010-08-07 11:01:39 +0100 | [diff] [blame] | 6583 | (intel_crtc->pipe == 0) ? I915_GEM_PHYS_CURSOR_0 : I915_GEM_PHYS_CURSOR_1, |
| 6584 | align); |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6585 | if (ret) { |
| 6586 | DRM_ERROR("failed to attach phys object\n"); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 6587 | goto fail_locked; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6588 | } |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6589 | addr = obj->phys_obj->handle->busaddr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6590 | } |
| 6591 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6592 | if (IS_GEN2(dev)) |
Jesse Barnes | 14b6039 | 2009-05-20 16:47:08 -0400 | [diff] [blame] | 6593 | I915_WRITE(CURSIZE, (height << 12) | width); |
| 6594 | |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6595 | finish: |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6596 | if (intel_crtc->cursor_bo) { |
Kristian Høgsberg | b295d1b | 2009-12-16 15:16:17 -0500 | [diff] [blame] | 6597 | if (dev_priv->info->cursor_needs_physical) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6598 | if (intel_crtc->cursor_bo != obj) |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 6599 | i915_gem_detach_phys_object(dev, intel_crtc->cursor_bo); |
| 6600 | } else |
| 6601 | i915_gem_object_unpin(intel_crtc->cursor_bo); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6602 | drm_gem_object_unreference(&intel_crtc->cursor_bo->base); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6603 | } |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 6604 | |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 6605 | mutex_unlock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6606 | |
| 6607 | intel_crtc->cursor_addr = addr; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6608 | intel_crtc->cursor_bo = obj; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6609 | intel_crtc->cursor_width = width; |
| 6610 | intel_crtc->cursor_height = height; |
| 6611 | |
Mika Kuoppala | 40ccc72 | 2013-04-23 17:27:08 +0300 | [diff] [blame] | 6612 | intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 6613 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6614 | return 0; |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 6615 | fail_unpin: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6616 | i915_gem_object_unpin(obj); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 6617 | fail_locked: |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 6618 | mutex_unlock(&dev->struct_mutex); |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 6619 | fail: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 6620 | drm_gem_object_unreference_unlocked(&obj->base); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 6621 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6622 | } |
| 6623 | |
| 6624 | static int intel_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
| 6625 | { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6626 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6627 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 6628 | intel_crtc->cursor_x = x; |
| 6629 | intel_crtc->cursor_y = y; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6630 | |
Mika Kuoppala | 40ccc72 | 2013-04-23 17:27:08 +0300 | [diff] [blame] | 6631 | intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6632 | |
| 6633 | return 0; |
| 6634 | } |
| 6635 | |
| 6636 | /** Sets the color ramps on behalf of RandR */ |
| 6637 | void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, |
| 6638 | u16 blue, int regno) |
| 6639 | { |
| 6640 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6641 | |
| 6642 | intel_crtc->lut_r[regno] = red >> 8; |
| 6643 | intel_crtc->lut_g[regno] = green >> 8; |
| 6644 | intel_crtc->lut_b[regno] = blue >> 8; |
| 6645 | } |
| 6646 | |
Dave Airlie | b8c00ac | 2009-10-06 13:54:01 +1000 | [diff] [blame] | 6647 | void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, |
| 6648 | u16 *blue, int regno) |
| 6649 | { |
| 6650 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6651 | |
| 6652 | *red = intel_crtc->lut_r[regno] << 8; |
| 6653 | *green = intel_crtc->lut_g[regno] << 8; |
| 6654 | *blue = intel_crtc->lut_b[regno] << 8; |
| 6655 | } |
| 6656 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6657 | 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] | 6658 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6659 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 6660 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6661 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6662 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 6663 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6664 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 6665 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 6666 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 6667 | } |
| 6668 | |
| 6669 | intel_crtc_load_lut(crtc); |
| 6670 | } |
| 6671 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6672 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 6673 | static struct drm_display_mode load_detect_mode = { |
| 6674 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 6675 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 6676 | }; |
| 6677 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6678 | static struct drm_framebuffer * |
| 6679 | intel_framebuffer_create(struct drm_device *dev, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 6680 | struct drm_mode_fb_cmd2 *mode_cmd, |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6681 | struct drm_i915_gem_object *obj) |
| 6682 | { |
| 6683 | struct intel_framebuffer *intel_fb; |
| 6684 | int ret; |
| 6685 | |
| 6686 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 6687 | if (!intel_fb) { |
| 6688 | drm_gem_object_unreference_unlocked(&obj->base); |
| 6689 | return ERR_PTR(-ENOMEM); |
| 6690 | } |
| 6691 | |
| 6692 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
| 6693 | if (ret) { |
| 6694 | drm_gem_object_unreference_unlocked(&obj->base); |
| 6695 | kfree(intel_fb); |
| 6696 | return ERR_PTR(ret); |
| 6697 | } |
| 6698 | |
| 6699 | return &intel_fb->base; |
| 6700 | } |
| 6701 | |
| 6702 | static u32 |
| 6703 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 6704 | { |
| 6705 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 6706 | return ALIGN(pitch, 64); |
| 6707 | } |
| 6708 | |
| 6709 | static u32 |
| 6710 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 6711 | { |
| 6712 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
| 6713 | return ALIGN(pitch * mode->vdisplay, PAGE_SIZE); |
| 6714 | } |
| 6715 | |
| 6716 | static struct drm_framebuffer * |
| 6717 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 6718 | struct drm_display_mode *mode, |
| 6719 | int depth, int bpp) |
| 6720 | { |
| 6721 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 6722 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6723 | |
| 6724 | obj = i915_gem_alloc_object(dev, |
| 6725 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 6726 | if (obj == NULL) |
| 6727 | return ERR_PTR(-ENOMEM); |
| 6728 | |
| 6729 | mode_cmd.width = mode->hdisplay; |
| 6730 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 6731 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 6732 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 6733 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6734 | |
| 6735 | return intel_framebuffer_create(dev, &mode_cmd, obj); |
| 6736 | } |
| 6737 | |
| 6738 | static struct drm_framebuffer * |
| 6739 | mode_fits_in_fbdev(struct drm_device *dev, |
| 6740 | struct drm_display_mode *mode) |
| 6741 | { |
| 6742 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6743 | struct drm_i915_gem_object *obj; |
| 6744 | struct drm_framebuffer *fb; |
| 6745 | |
| 6746 | if (dev_priv->fbdev == NULL) |
| 6747 | return NULL; |
| 6748 | |
| 6749 | obj = dev_priv->fbdev->ifb.obj; |
| 6750 | if (obj == NULL) |
| 6751 | return NULL; |
| 6752 | |
| 6753 | fb = &dev_priv->fbdev->ifb.base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 6754 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 6755 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6756 | return NULL; |
| 6757 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 6758 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6759 | return NULL; |
| 6760 | |
| 6761 | return fb; |
| 6762 | } |
| 6763 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 6764 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6765 | struct drm_display_mode *mode, |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6766 | struct intel_load_detect_pipe *old) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6767 | { |
| 6768 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 6769 | struct intel_encoder *intel_encoder = |
| 6770 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6771 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6772 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6773 | struct drm_crtc *crtc = NULL; |
| 6774 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6775 | struct drm_framebuffer *fb; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6776 | int i = -1; |
| 6777 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6778 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 6779 | connector->base.id, drm_get_connector_name(connector), |
| 6780 | encoder->base.id, drm_get_encoder_name(encoder)); |
| 6781 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6782 | /* |
| 6783 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 6784 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6785 | * - if the connector already has an assigned crtc, use it (but make |
| 6786 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 6787 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6788 | * - try to find the first unused crtc that can drive this connector, |
| 6789 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6790 | */ |
| 6791 | |
| 6792 | /* See if we already have a CRTC for this connector */ |
| 6793 | if (encoder->crtc) { |
| 6794 | crtc = encoder->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6795 | |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 6796 | mutex_lock(&crtc->mutex); |
| 6797 | |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 6798 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6799 | old->load_detect_temp = false; |
| 6800 | |
| 6801 | /* Make sure the crtc and connector are running */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 6802 | if (connector->dpms != DRM_MODE_DPMS_ON) |
| 6803 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6804 | |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6805 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6806 | } |
| 6807 | |
| 6808 | /* Find an unused one (if possible) */ |
| 6809 | list_for_each_entry(possible_crtc, &dev->mode_config.crtc_list, head) { |
| 6810 | i++; |
| 6811 | if (!(encoder->possible_crtcs & (1 << i))) |
| 6812 | continue; |
| 6813 | if (!possible_crtc->enabled) { |
| 6814 | crtc = possible_crtc; |
| 6815 | break; |
| 6816 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6817 | } |
| 6818 | |
| 6819 | /* |
| 6820 | * If we didn't find an unused CRTC, don't use any. |
| 6821 | */ |
| 6822 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6823 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
| 6824 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6825 | } |
| 6826 | |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 6827 | mutex_lock(&crtc->mutex); |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 6828 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
| 6829 | to_intel_connector(connector)->new_encoder = intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6830 | |
| 6831 | intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 6832 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6833 | old->load_detect_temp = true; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6834 | old->release_fb = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6835 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 6836 | if (!mode) |
| 6837 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6838 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6839 | /* We need a framebuffer large enough to accommodate all accesses |
| 6840 | * that the plane may generate whilst we perform load detection. |
| 6841 | * We can not rely on the fbcon either being present (we get called |
| 6842 | * during its initialisation to detect all boot displays, or it may |
| 6843 | * not even exist) or that it is large enough to satisfy the |
| 6844 | * requested mode. |
| 6845 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6846 | fb = mode_fits_in_fbdev(dev, mode); |
| 6847 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6848 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6849 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
| 6850 | old->release_fb = fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6851 | } else |
| 6852 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6853 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6854 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 6855 | mutex_unlock(&crtc->mutex); |
Chris Wilson | 0e8b3d3 | 2012-11-05 22:25:08 +0000 | [diff] [blame] | 6856 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6857 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6858 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 6859 | if (intel_set_mode(crtc, mode, 0, 0, fb)) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 6860 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6861 | if (old->release_fb) |
| 6862 | old->release_fb->funcs->destroy(old->release_fb); |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 6863 | mutex_unlock(&crtc->mutex); |
Chris Wilson | 0e8b3d3 | 2012-11-05 22:25:08 +0000 | [diff] [blame] | 6864 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6865 | } |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6866 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6867 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 6868 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 6869 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6870 | } |
| 6871 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 6872 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6873 | struct intel_load_detect_pipe *old) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6874 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 6875 | struct intel_encoder *intel_encoder = |
| 6876 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 6877 | struct drm_encoder *encoder = &intel_encoder->base; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 6878 | struct drm_crtc *crtc = encoder->crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6879 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6880 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 6881 | connector->base.id, drm_get_connector_name(connector), |
| 6882 | encoder->base.id, drm_get_encoder_name(encoder)); |
| 6883 | |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 6884 | if (old->load_detect_temp) { |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 6885 | to_intel_connector(connector)->new_encoder = NULL; |
| 6886 | intel_encoder->new_crtc = NULL; |
| 6887 | intel_set_mode(crtc, NULL, 0, 0, NULL); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6888 | |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 6889 | if (old->release_fb) { |
| 6890 | drm_framebuffer_unregister_private(old->release_fb); |
| 6891 | drm_framebuffer_unreference(old->release_fb); |
| 6892 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 6893 | |
Daniel Vetter | 67c9640 | 2013-01-23 16:25:09 +0000 | [diff] [blame] | 6894 | mutex_unlock(&crtc->mutex); |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 6895 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6896 | } |
| 6897 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6898 | /* Switch crtc and encoder back off if necessary */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 6899 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
| 6900 | connector->funcs->dpms(connector, old->dpms_mode); |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 6901 | |
| 6902 | mutex_unlock(&crtc->mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6903 | } |
| 6904 | |
| 6905 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 6906 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
| 6907 | struct intel_crtc_config *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6908 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 6909 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6910 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 6911 | int pipe = pipe_config->cpu_transcoder; |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 6912 | u32 dpll = I915_READ(DPLL(pipe)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6913 | u32 fp; |
| 6914 | intel_clock_t clock; |
| 6915 | |
| 6916 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Chris Wilson | 39adb7a | 2011-04-22 22:17:21 +0100 | [diff] [blame] | 6917 | fp = I915_READ(FP0(pipe)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6918 | else |
Chris Wilson | 39adb7a | 2011-04-22 22:17:21 +0100 | [diff] [blame] | 6919 | fp = I915_READ(FP1(pipe)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6920 | |
| 6921 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 6922 | if (IS_PINEVIEW(dev)) { |
| 6923 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 6924 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 6925 | } else { |
| 6926 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 6927 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 6928 | } |
| 6929 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 6930 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 6931 | if (IS_PINEVIEW(dev)) |
| 6932 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 6933 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 6934 | else |
| 6935 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6936 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 6937 | |
| 6938 | switch (dpll & DPLL_MODE_MASK) { |
| 6939 | case DPLLB_MODE_DAC_SERIAL: |
| 6940 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 6941 | 5 : 10; |
| 6942 | break; |
| 6943 | case DPLLB_MODE_LVDS: |
| 6944 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 6945 | 7 : 14; |
| 6946 | break; |
| 6947 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 6948 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6949 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 6950 | pipe_config->adjusted_mode.clock = 0; |
| 6951 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6952 | } |
| 6953 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 6954 | if (IS_PINEVIEW(dev)) |
| 6955 | pineview_clock(96000, &clock); |
| 6956 | else |
| 6957 | i9xx_clock(96000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6958 | } else { |
| 6959 | bool is_lvds = (pipe == 1) && (I915_READ(LVDS) & LVDS_PORT_EN); |
| 6960 | |
| 6961 | if (is_lvds) { |
| 6962 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 6963 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 6964 | clock.p2 = 14; |
| 6965 | |
| 6966 | if ((dpll & PLL_REF_INPUT_MASK) == |
| 6967 | PLLB_REF_INPUT_SPREADSPECTRUMIN) { |
| 6968 | /* XXX: might not be 66MHz */ |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 6969 | i9xx_clock(66000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6970 | } else |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 6971 | i9xx_clock(48000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6972 | } else { |
| 6973 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 6974 | clock.p1 = 2; |
| 6975 | else { |
| 6976 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 6977 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 6978 | } |
| 6979 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 6980 | clock.p2 = 4; |
| 6981 | else |
| 6982 | clock.p2 = 2; |
| 6983 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 6984 | i9xx_clock(48000, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6985 | } |
| 6986 | } |
| 6987 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 6988 | pipe_config->adjusted_mode.clock = clock.dot * |
| 6989 | pipe_config->pixel_multiplier; |
| 6990 | } |
| 6991 | |
| 6992 | static void ironlake_crtc_clock_get(struct intel_crtc *crtc, |
| 6993 | struct intel_crtc_config *pipe_config) |
| 6994 | { |
| 6995 | struct drm_device *dev = crtc->base.dev; |
| 6996 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6997 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 6998 | int link_freq, repeat; |
| 6999 | u64 clock; |
| 7000 | u32 link_m, link_n; |
| 7001 | |
| 7002 | repeat = pipe_config->pixel_multiplier; |
| 7003 | |
| 7004 | /* |
| 7005 | * The calculation for the data clock is: |
| 7006 | * pixel_clock = ((m/n)*(link_clock * nr_lanes * repeat))/bpp |
| 7007 | * But we want to avoid losing precison if possible, so: |
| 7008 | * pixel_clock = ((m * link_clock * nr_lanes * repeat)/(n*bpp)) |
| 7009 | * |
| 7010 | * and the link clock is simpler: |
| 7011 | * link_clock = (m * link_clock * repeat) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7012 | */ |
| 7013 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 7014 | /* |
| 7015 | * We need to get the FDI or DP link clock here to derive |
| 7016 | * the M/N dividers. |
| 7017 | * |
| 7018 | * For FDI, we read it from the BIOS or use a fixed 2.7GHz. |
| 7019 | * For DP, it's either 1.62GHz or 2.7GHz. |
| 7020 | * We do our calculations in 10*MHz since we don't need much precison. |
| 7021 | */ |
| 7022 | if (pipe_config->has_pch_encoder) |
| 7023 | link_freq = intel_fdi_link_freq(dev) * 10000; |
| 7024 | else |
| 7025 | link_freq = pipe_config->port_clock; |
| 7026 | |
| 7027 | link_m = I915_READ(PIPE_LINK_M1(cpu_transcoder)); |
| 7028 | link_n = I915_READ(PIPE_LINK_N1(cpu_transcoder)); |
| 7029 | |
| 7030 | if (!link_m || !link_n) |
| 7031 | return; |
| 7032 | |
| 7033 | clock = ((u64)link_m * (u64)link_freq * (u64)repeat); |
| 7034 | do_div(clock, link_n); |
| 7035 | |
| 7036 | pipe_config->adjusted_mode.clock = clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7037 | } |
| 7038 | |
| 7039 | /** Returns the currently programmed mode of the given pipe. */ |
| 7040 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 7041 | struct drm_crtc *crtc) |
| 7042 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 7043 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7044 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 7045 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7046 | struct drm_display_mode *mode; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 7047 | struct intel_crtc_config pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 7048 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 7049 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 7050 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 7051 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7052 | |
| 7053 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 7054 | if (!mode) |
| 7055 | return NULL; |
| 7056 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 7057 | /* |
| 7058 | * Construct a pipe_config sufficient for getting the clock info |
| 7059 | * back out of crtc_clock_get. |
| 7060 | * |
| 7061 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 7062 | * to use a real value here instead. |
| 7063 | */ |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7064 | pipe_config.cpu_transcoder = (enum transcoder) intel_crtc->pipe; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 7065 | pipe_config.pixel_multiplier = 1; |
| 7066 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
| 7067 | |
| 7068 | mode->clock = pipe_config.adjusted_mode.clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7069 | mode->hdisplay = (htot & 0xffff) + 1; |
| 7070 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 7071 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 7072 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 7073 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 7074 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 7075 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 7076 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 7077 | |
| 7078 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7079 | |
| 7080 | return mode; |
| 7081 | } |
| 7082 | |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 7083 | static void intel_increase_pllclock(struct drm_crtc *crtc) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7084 | { |
| 7085 | struct drm_device *dev = crtc->dev; |
| 7086 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 7087 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7088 | int pipe = intel_crtc->pipe; |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 7089 | int dpll_reg = DPLL(pipe); |
| 7090 | int dpll; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7091 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 7092 | if (HAS_PCH_SPLIT(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7093 | return; |
| 7094 | |
| 7095 | if (!dev_priv->lvds_downclock_avail) |
| 7096 | return; |
| 7097 | |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 7098 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7099 | if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 7100 | DRM_DEBUG_DRIVER("upclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7101 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 7102 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7103 | |
| 7104 | dpll &= ~DISPLAY_RATE_SELECT_FPA1; |
| 7105 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 7106 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 7107 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7108 | dpll = I915_READ(dpll_reg); |
| 7109 | if (dpll & DISPLAY_RATE_SELECT_FPA1) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 7110 | DRM_DEBUG_DRIVER("failed to upclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7111 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7112 | } |
| 7113 | |
| 7114 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 7115 | { |
| 7116 | struct drm_device *dev = crtc->dev; |
| 7117 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 7118 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7119 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 7120 | if (HAS_PCH_SPLIT(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7121 | return; |
| 7122 | |
| 7123 | if (!dev_priv->lvds_downclock_avail) |
| 7124 | return; |
| 7125 | |
| 7126 | /* |
| 7127 | * Since this is called by a timer, we should never get here in |
| 7128 | * the manual case. |
| 7129 | */ |
| 7130 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 7131 | int pipe = intel_crtc->pipe; |
| 7132 | int dpll_reg = DPLL(pipe); |
Daniel Vetter | dc257cf | 2012-05-07 11:30:46 +0200 | [diff] [blame] | 7133 | int dpll; |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 7134 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 7135 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7136 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 7137 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7138 | |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 7139 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7140 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 7141 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 7142 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7143 | dpll = I915_READ(dpll_reg); |
| 7144 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 7145 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7146 | } |
| 7147 | |
| 7148 | } |
| 7149 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 7150 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7151 | { |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 7152 | i915_update_gfx_val(dev->dev_private); |
| 7153 | } |
| 7154 | |
| 7155 | void intel_mark_idle(struct drm_device *dev) |
| 7156 | { |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 7157 | struct drm_crtc *crtc; |
| 7158 | |
| 7159 | if (!i915_powersave) |
| 7160 | return; |
| 7161 | |
| 7162 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 7163 | if (!crtc->fb) |
| 7164 | continue; |
| 7165 | |
| 7166 | intel_decrease_pllclock(crtc); |
| 7167 | } |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 7168 | } |
| 7169 | |
Chris Wilson | c65355b | 2013-06-06 16:53:41 -0300 | [diff] [blame] | 7170 | void intel_mark_fb_busy(struct drm_i915_gem_object *obj, |
| 7171 | struct intel_ring_buffer *ring) |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 7172 | { |
| 7173 | struct drm_device *dev = obj->base.dev; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7174 | struct drm_crtc *crtc; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7175 | |
| 7176 | if (!i915_powersave) |
| 7177 | return; |
| 7178 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7179 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7180 | if (!crtc->fb) |
| 7181 | continue; |
| 7182 | |
Chris Wilson | c65355b | 2013-06-06 16:53:41 -0300 | [diff] [blame] | 7183 | if (to_intel_framebuffer(crtc->fb)->obj != obj) |
| 7184 | continue; |
| 7185 | |
| 7186 | intel_increase_pllclock(crtc); |
| 7187 | if (ring && intel_fbc_enabled(dev)) |
| 7188 | ring->fbc_dirty = true; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7189 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 7190 | } |
| 7191 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7192 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 7193 | { |
| 7194 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 7195 | struct drm_device *dev = crtc->dev; |
| 7196 | struct intel_unpin_work *work; |
| 7197 | unsigned long flags; |
| 7198 | |
| 7199 | spin_lock_irqsave(&dev->event_lock, flags); |
| 7200 | work = intel_crtc->unpin_work; |
| 7201 | intel_crtc->unpin_work = NULL; |
| 7202 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 7203 | |
| 7204 | if (work) { |
| 7205 | cancel_work_sync(&work->work); |
| 7206 | kfree(work); |
| 7207 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7208 | |
Mika Kuoppala | 40ccc72 | 2013-04-23 17:27:08 +0300 | [diff] [blame] | 7209 | intel_crtc_cursor_set(crtc, NULL, 0, 0, 0); |
| 7210 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7211 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 7212 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7213 | kfree(intel_crtc); |
| 7214 | } |
| 7215 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7216 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 7217 | { |
| 7218 | struct intel_unpin_work *work = |
| 7219 | container_of(__work, struct intel_unpin_work, work); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7220 | struct drm_device *dev = work->crtc->dev; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7221 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7222 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 7223 | intel_unpin_fb_obj(work->old_fb_obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 7224 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
| 7225 | drm_gem_object_unreference(&work->old_fb_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 7226 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7227 | intel_update_fbc(dev); |
| 7228 | mutex_unlock(&dev->struct_mutex); |
| 7229 | |
| 7230 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
| 7231 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); |
| 7232 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7233 | kfree(work); |
| 7234 | } |
| 7235 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 7236 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 7237 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7238 | { |
| 7239 | drm_i915_private_t *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7240 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7241 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7242 | unsigned long flags; |
| 7243 | |
| 7244 | /* Ignore early vblank irqs */ |
| 7245 | if (intel_crtc == NULL) |
| 7246 | return; |
| 7247 | |
| 7248 | spin_lock_irqsave(&dev->event_lock, flags); |
| 7249 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7250 | |
| 7251 | /* Ensure we don't miss a work->pending update ... */ |
| 7252 | smp_rmb(); |
| 7253 | |
| 7254 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7255 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 7256 | return; |
| 7257 | } |
| 7258 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7259 | /* and that the unpin work is consistent wrt ->pending. */ |
| 7260 | smp_rmb(); |
| 7261 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7262 | intel_crtc->unpin_work = NULL; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7263 | |
Rob Clark | 45a066e | 2012-10-08 14:50:40 -0500 | [diff] [blame] | 7264 | if (work->event) |
| 7265 | drm_send_vblank_event(dev, intel_crtc->pipe, work->event); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7266 | |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 7267 | drm_vblank_put(dev, intel_crtc->pipe); |
| 7268 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7269 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 7270 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 7271 | wake_up_all(&dev_priv->pending_flip_queue); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7272 | |
| 7273 | queue_work(dev_priv->wq, &work->work); |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 7274 | |
| 7275 | trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7276 | } |
| 7277 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 7278 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 7279 | { |
| 7280 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 7281 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 7282 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 7283 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 7284 | } |
| 7285 | |
| 7286 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 7287 | { |
| 7288 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 7289 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 7290 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 7291 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 7292 | } |
| 7293 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7294 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 7295 | { |
| 7296 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 7297 | struct intel_crtc *intel_crtc = |
| 7298 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 7299 | unsigned long flags; |
| 7300 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7301 | /* NB: An MMIO update of the plane base pointer will also |
| 7302 | * generate a page-flip completion irq, i.e. every modeset |
| 7303 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 7304 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7305 | spin_lock_irqsave(&dev->event_lock, flags); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7306 | if (intel_crtc->unpin_work) |
| 7307 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7308 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 7309 | } |
| 7310 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7311 | inline static void intel_mark_page_flip_active(struct intel_crtc *intel_crtc) |
| 7312 | { |
| 7313 | /* Ensure that the work item is consistent when activating it ... */ |
| 7314 | smp_wmb(); |
| 7315 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); |
| 7316 | /* and that it is marked active as soon as the irq could fire. */ |
| 7317 | smp_wmb(); |
| 7318 | } |
| 7319 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7320 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 7321 | struct drm_crtc *crtc, |
| 7322 | struct drm_framebuffer *fb, |
| 7323 | struct drm_i915_gem_object *obj) |
| 7324 | { |
| 7325 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7326 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7327 | u32 flip_mask; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7328 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7329 | int ret; |
| 7330 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7331 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7332 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7333 | goto err; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7334 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7335 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7336 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7337 | goto err_unpin; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7338 | |
| 7339 | /* Can't queue multiple flips, so wait for the previous |
| 7340 | * one to finish before executing the next. |
| 7341 | */ |
| 7342 | if (intel_crtc->plane) |
| 7343 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 7344 | else |
| 7345 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7346 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 7347 | intel_ring_emit(ring, MI_NOOP); |
| 7348 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 7349 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 7350 | intel_ring_emit(ring, fb->pitches[0]); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 7351 | intel_ring_emit(ring, i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7352 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7353 | |
| 7354 | intel_mark_page_flip_active(intel_crtc); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7355 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7356 | return 0; |
| 7357 | |
| 7358 | err_unpin: |
| 7359 | intel_unpin_fb_obj(obj); |
| 7360 | err: |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7361 | return ret; |
| 7362 | } |
| 7363 | |
| 7364 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 7365 | struct drm_crtc *crtc, |
| 7366 | struct drm_framebuffer *fb, |
| 7367 | struct drm_i915_gem_object *obj) |
| 7368 | { |
| 7369 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7370 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7371 | u32 flip_mask; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7372 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7373 | int ret; |
| 7374 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7375 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7376 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7377 | goto err; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7378 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7379 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7380 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7381 | goto err_unpin; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7382 | |
| 7383 | if (intel_crtc->plane) |
| 7384 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 7385 | else |
| 7386 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7387 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 7388 | intel_ring_emit(ring, MI_NOOP); |
| 7389 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
| 7390 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 7391 | intel_ring_emit(ring, fb->pitches[0]); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 7392 | intel_ring_emit(ring, i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7393 | intel_ring_emit(ring, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7394 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7395 | intel_mark_page_flip_active(intel_crtc); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7396 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7397 | return 0; |
| 7398 | |
| 7399 | err_unpin: |
| 7400 | intel_unpin_fb_obj(obj); |
| 7401 | err: |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7402 | return ret; |
| 7403 | } |
| 7404 | |
| 7405 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 7406 | struct drm_crtc *crtc, |
| 7407 | struct drm_framebuffer *fb, |
| 7408 | struct drm_i915_gem_object *obj) |
| 7409 | { |
| 7410 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7411 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7412 | uint32_t pf, pipesrc; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7413 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7414 | int ret; |
| 7415 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7416 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7417 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7418 | goto err; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7419 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7420 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7421 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7422 | goto err_unpin; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7423 | |
| 7424 | /* i965+ uses the linear or tiled offsets from the |
| 7425 | * Display Registers (which do not change across a page-flip) |
| 7426 | * so we need only reprogram the base address. |
| 7427 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7428 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 7429 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 7430 | intel_ring_emit(ring, fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 7431 | intel_ring_emit(ring, |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 7432 | (i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset) | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 7433 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7434 | |
| 7435 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 7436 | * untested on non-native modes, so ignore it for now. |
| 7437 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 7438 | */ |
| 7439 | pf = 0; |
| 7440 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7441 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7442 | |
| 7443 | intel_mark_page_flip_active(intel_crtc); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7444 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7445 | return 0; |
| 7446 | |
| 7447 | err_unpin: |
| 7448 | intel_unpin_fb_obj(obj); |
| 7449 | err: |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7450 | return ret; |
| 7451 | } |
| 7452 | |
| 7453 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 7454 | struct drm_crtc *crtc, |
| 7455 | struct drm_framebuffer *fb, |
| 7456 | struct drm_i915_gem_object *obj) |
| 7457 | { |
| 7458 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7459 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7460 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7461 | uint32_t pf, pipesrc; |
| 7462 | int ret; |
| 7463 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7464 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7465 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7466 | goto err; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7467 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7468 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7469 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7470 | goto err_unpin; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7471 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7472 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 7473 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 7474 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 7475 | intel_ring_emit(ring, i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7476 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 7477 | /* Contrary to the suggestions in the documentation, |
| 7478 | * "Enable Panel Fitter" does not seem to be required when page |
| 7479 | * flipping with a non-native mode, and worse causes a normal |
| 7480 | * modeset to fail. |
| 7481 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 7482 | */ |
| 7483 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7484 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7485 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7486 | |
| 7487 | intel_mark_page_flip_active(intel_crtc); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 7488 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7489 | return 0; |
| 7490 | |
| 7491 | err_unpin: |
| 7492 | intel_unpin_fb_obj(obj); |
| 7493 | err: |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7494 | return ret; |
| 7495 | } |
| 7496 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 7497 | /* |
| 7498 | * On gen7 we currently use the blit ring because (in early silicon at least) |
| 7499 | * the render ring doesn't give us interrpts for page flip completion, which |
| 7500 | * means clients will hang after the first flip is queued. Fortunately the |
| 7501 | * blit ring generates interrupts properly, so use it instead. |
| 7502 | */ |
| 7503 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 7504 | struct drm_crtc *crtc, |
| 7505 | struct drm_framebuffer *fb, |
| 7506 | struct drm_i915_gem_object *obj) |
| 7507 | { |
| 7508 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7509 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7510 | struct intel_ring_buffer *ring = &dev_priv->ring[BCS]; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 7511 | uint32_t plane_bit = 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 7512 | int ret; |
| 7513 | |
| 7514 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
| 7515 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7516 | goto err; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 7517 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 7518 | switch(intel_crtc->plane) { |
| 7519 | case PLANE_A: |
| 7520 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 7521 | break; |
| 7522 | case PLANE_B: |
| 7523 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 7524 | break; |
| 7525 | case PLANE_C: |
| 7526 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 7527 | break; |
| 7528 | default: |
| 7529 | WARN_ONCE(1, "unknown plane in flip command\n"); |
| 7530 | ret = -ENODEV; |
Eugeni Dodonov | ab3951e | 2012-06-18 19:03:38 -0300 | [diff] [blame] | 7531 | goto err_unpin; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 7532 | } |
| 7533 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 7534 | ret = intel_ring_begin(ring, 4); |
| 7535 | if (ret) |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7536 | goto err_unpin; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 7537 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 7538 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 7539 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 7540 | intel_ring_emit(ring, i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 7541 | intel_ring_emit(ring, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 7542 | |
| 7543 | intel_mark_page_flip_active(intel_crtc); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 7544 | intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 7545 | return 0; |
| 7546 | |
| 7547 | err_unpin: |
| 7548 | intel_unpin_fb_obj(obj); |
| 7549 | err: |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 7550 | return ret; |
| 7551 | } |
| 7552 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7553 | static int intel_default_queue_flip(struct drm_device *dev, |
| 7554 | struct drm_crtc *crtc, |
| 7555 | struct drm_framebuffer *fb, |
| 7556 | struct drm_i915_gem_object *obj) |
| 7557 | { |
| 7558 | return -ENODEV; |
| 7559 | } |
| 7560 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7561 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 7562 | struct drm_framebuffer *fb, |
| 7563 | struct drm_pending_vblank_event *event) |
| 7564 | { |
| 7565 | struct drm_device *dev = crtc->dev; |
| 7566 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 4a35f83 | 2013-02-22 16:53:38 +0200 | [diff] [blame] | 7567 | struct drm_framebuffer *old_fb = crtc->fb; |
| 7568 | struct drm_i915_gem_object *obj = to_intel_framebuffer(fb)->obj; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7569 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7570 | struct intel_unpin_work *work; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7571 | unsigned long flags; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 7572 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7573 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 7574 | /* Can't change pixel format via MI display flips. */ |
| 7575 | if (fb->pixel_format != crtc->fb->pixel_format) |
| 7576 | return -EINVAL; |
| 7577 | |
| 7578 | /* |
| 7579 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 7580 | * Note that pitch changes could also affect these register. |
| 7581 | */ |
| 7582 | if (INTEL_INFO(dev)->gen > 3 && |
| 7583 | (fb->offsets[0] != crtc->fb->offsets[0] || |
| 7584 | fb->pitches[0] != crtc->fb->pitches[0])) |
| 7585 | return -EINVAL; |
| 7586 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7587 | work = kzalloc(sizeof *work, GFP_KERNEL); |
| 7588 | if (work == NULL) |
| 7589 | return -ENOMEM; |
| 7590 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7591 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7592 | work->crtc = crtc; |
Ville Syrjälä | 4a35f83 | 2013-02-22 16:53:38 +0200 | [diff] [blame] | 7593 | work->old_fb_obj = to_intel_framebuffer(old_fb)->obj; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7594 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 7595 | |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 7596 | ret = drm_vblank_get(dev, intel_crtc->pipe); |
| 7597 | if (ret) |
| 7598 | goto free_work; |
| 7599 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7600 | /* We borrow the event spin lock for protecting unpin_work */ |
| 7601 | spin_lock_irqsave(&dev->event_lock, flags); |
| 7602 | if (intel_crtc->unpin_work) { |
| 7603 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 7604 | kfree(work); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 7605 | drm_vblank_put(dev, intel_crtc->pipe); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 7606 | |
| 7607 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7608 | return -EBUSY; |
| 7609 | } |
| 7610 | intel_crtc->unpin_work = work; |
| 7611 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 7612 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7613 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 7614 | flush_workqueue(dev_priv->wq); |
| 7615 | |
Chris Wilson | 7915810 | 2012-05-23 11:13:58 +0100 | [diff] [blame] | 7616 | ret = i915_mutex_lock_interruptible(dev); |
| 7617 | if (ret) |
| 7618 | goto cleanup; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7619 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 7620 | /* Reference the objects for the scheduled work. */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 7621 | drm_gem_object_reference(&work->old_fb_obj->base); |
| 7622 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7623 | |
| 7624 | crtc->fb = fb; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 7625 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 7626 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 7627 | |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 7628 | work->enable_stall_check = true; |
| 7629 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7630 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 7631 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 7632 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7633 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj); |
| 7634 | if (ret) |
| 7635 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7636 | |
Chris Wilson | 7782de3 | 2011-07-08 12:22:41 +0100 | [diff] [blame] | 7637 | intel_disable_fbc(dev); |
Chris Wilson | c65355b | 2013-06-06 16:53:41 -0300 | [diff] [blame] | 7638 | intel_mark_fb_busy(obj, NULL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7639 | mutex_unlock(&dev->struct_mutex); |
| 7640 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 7641 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 7642 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7643 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 7644 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 7645 | cleanup_pending: |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 7646 | atomic_dec(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 4a35f83 | 2013-02-22 16:53:38 +0200 | [diff] [blame] | 7647 | crtc->fb = old_fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 7648 | drm_gem_object_unreference(&work->old_fb_obj->base); |
| 7649 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 7650 | mutex_unlock(&dev->struct_mutex); |
| 7651 | |
Chris Wilson | 7915810 | 2012-05-23 11:13:58 +0100 | [diff] [blame] | 7652 | cleanup: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 7653 | spin_lock_irqsave(&dev->event_lock, flags); |
| 7654 | intel_crtc->unpin_work = NULL; |
| 7655 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 7656 | |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 7657 | drm_vblank_put(dev, intel_crtc->pipe); |
| 7658 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 7659 | kfree(work); |
| 7660 | |
| 7661 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 7662 | } |
| 7663 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 7664 | static struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 7665 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 7666 | .load_lut = intel_crtc_load_lut, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 7667 | }; |
| 7668 | |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 7669 | static bool intel_encoder_crtc_ok(struct drm_encoder *encoder, |
| 7670 | struct drm_crtc *crtc) |
| 7671 | { |
| 7672 | struct drm_device *dev; |
| 7673 | struct drm_crtc *tmp; |
| 7674 | int crtc_mask = 1; |
| 7675 | |
| 7676 | WARN(!crtc, "checking null crtc?\n"); |
| 7677 | |
| 7678 | dev = crtc->dev; |
| 7679 | |
| 7680 | list_for_each_entry(tmp, &dev->mode_config.crtc_list, head) { |
| 7681 | if (tmp == crtc) |
| 7682 | break; |
| 7683 | crtc_mask <<= 1; |
| 7684 | } |
| 7685 | |
| 7686 | if (encoder->possible_crtcs & crtc_mask) |
| 7687 | return true; |
| 7688 | return false; |
| 7689 | } |
| 7690 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 7691 | /** |
| 7692 | * intel_modeset_update_staged_output_state |
| 7693 | * |
| 7694 | * Updates the staged output configuration state, e.g. after we've read out the |
| 7695 | * current hw state. |
| 7696 | */ |
| 7697 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) |
| 7698 | { |
| 7699 | struct intel_encoder *encoder; |
| 7700 | struct intel_connector *connector; |
| 7701 | |
| 7702 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7703 | base.head) { |
| 7704 | connector->new_encoder = |
| 7705 | to_intel_encoder(connector->base.encoder); |
| 7706 | } |
| 7707 | |
| 7708 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7709 | base.head) { |
| 7710 | encoder->new_crtc = |
| 7711 | to_intel_crtc(encoder->base.crtc); |
| 7712 | } |
| 7713 | } |
| 7714 | |
| 7715 | /** |
| 7716 | * intel_modeset_commit_output_state |
| 7717 | * |
| 7718 | * This function copies the stage display pipe configuration to the real one. |
| 7719 | */ |
| 7720 | static void intel_modeset_commit_output_state(struct drm_device *dev) |
| 7721 | { |
| 7722 | struct intel_encoder *encoder; |
| 7723 | struct intel_connector *connector; |
| 7724 | |
| 7725 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7726 | base.head) { |
| 7727 | connector->base.encoder = &connector->new_encoder->base; |
| 7728 | } |
| 7729 | |
| 7730 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7731 | base.head) { |
| 7732 | encoder->base.crtc = &encoder->new_crtc->base; |
| 7733 | } |
| 7734 | } |
| 7735 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 7736 | static void |
| 7737 | connected_sink_compute_bpp(struct intel_connector * connector, |
| 7738 | struct intel_crtc_config *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7739 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 7740 | int bpp = pipe_config->pipe_bpp; |
| 7741 | |
| 7742 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 7743 | connector->base.base.id, |
| 7744 | drm_get_connector_name(&connector->base)); |
| 7745 | |
| 7746 | /* Don't use an invalid EDID bpc value */ |
| 7747 | if (connector->base.display_info.bpc && |
| 7748 | connector->base.display_info.bpc * 3 < bpp) { |
| 7749 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 7750 | bpp, connector->base.display_info.bpc*3); |
| 7751 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 7752 | } |
| 7753 | |
| 7754 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
| 7755 | if (connector->base.display_info.bpc == 0 && bpp > 24) { |
| 7756 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 7757 | bpp); |
| 7758 | pipe_config->pipe_bpp = 24; |
| 7759 | } |
| 7760 | } |
| 7761 | |
| 7762 | static int |
| 7763 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
| 7764 | struct drm_framebuffer *fb, |
| 7765 | struct intel_crtc_config *pipe_config) |
| 7766 | { |
| 7767 | struct drm_device *dev = crtc->base.dev; |
| 7768 | struct intel_connector *connector; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7769 | int bpp; |
| 7770 | |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 7771 | switch (fb->pixel_format) { |
| 7772 | case DRM_FORMAT_C8: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7773 | bpp = 8*3; /* since we go through a colormap */ |
| 7774 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 7775 | case DRM_FORMAT_XRGB1555: |
| 7776 | case DRM_FORMAT_ARGB1555: |
| 7777 | /* checked in intel_framebuffer_init already */ |
| 7778 | if (WARN_ON(INTEL_INFO(dev)->gen > 3)) |
| 7779 | return -EINVAL; |
| 7780 | case DRM_FORMAT_RGB565: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7781 | bpp = 6*3; /* min is 18bpp */ |
| 7782 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 7783 | case DRM_FORMAT_XBGR8888: |
| 7784 | case DRM_FORMAT_ABGR8888: |
| 7785 | /* checked in intel_framebuffer_init already */ |
| 7786 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
| 7787 | return -EINVAL; |
| 7788 | case DRM_FORMAT_XRGB8888: |
| 7789 | case DRM_FORMAT_ARGB8888: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7790 | bpp = 8*3; |
| 7791 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 7792 | case DRM_FORMAT_XRGB2101010: |
| 7793 | case DRM_FORMAT_ARGB2101010: |
| 7794 | case DRM_FORMAT_XBGR2101010: |
| 7795 | case DRM_FORMAT_ABGR2101010: |
| 7796 | /* checked in intel_framebuffer_init already */ |
| 7797 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 7798 | return -EINVAL; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7799 | bpp = 10*3; |
| 7800 | break; |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 7801 | /* TODO: gen4+ supports 16 bpc floating point, too. */ |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7802 | default: |
| 7803 | DRM_DEBUG_KMS("unsupported depth\n"); |
| 7804 | return -EINVAL; |
| 7805 | } |
| 7806 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7807 | pipe_config->pipe_bpp = bpp; |
| 7808 | |
| 7809 | /* Clamp display bpp to EDID value */ |
| 7810 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 7811 | base.head) { |
Daniel Vetter | 1b829e0 | 2013-06-02 13:26:24 +0200 | [diff] [blame] | 7812 | if (!connector->new_encoder || |
| 7813 | connector->new_encoder->new_crtc != crtc) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7814 | continue; |
| 7815 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 7816 | connected_sink_compute_bpp(connector, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7817 | } |
| 7818 | |
| 7819 | return bpp; |
| 7820 | } |
| 7821 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 7822 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
| 7823 | struct intel_crtc_config *pipe_config, |
| 7824 | const char *context) |
| 7825 | { |
| 7826 | DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id, |
| 7827 | context, pipe_name(crtc->pipe)); |
| 7828 | |
| 7829 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); |
| 7830 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 7831 | pipe_config->pipe_bpp, pipe_config->dither); |
| 7832 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 7833 | pipe_config->has_pch_encoder, |
| 7834 | pipe_config->fdi_lanes, |
| 7835 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 7836 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 7837 | pipe_config->fdi_m_n.tu); |
| 7838 | DRM_DEBUG_KMS("requested mode:\n"); |
| 7839 | drm_mode_debug_printmodeline(&pipe_config->requested_mode); |
| 7840 | DRM_DEBUG_KMS("adjusted mode:\n"); |
| 7841 | drm_mode_debug_printmodeline(&pipe_config->adjusted_mode); |
| 7842 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 7843 | pipe_config->gmch_pfit.control, |
| 7844 | pipe_config->gmch_pfit.pgm_ratios, |
| 7845 | pipe_config->gmch_pfit.lvds_border_bits); |
| 7846 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x\n", |
| 7847 | pipe_config->pch_pfit.pos, |
| 7848 | pipe_config->pch_pfit.size); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 7849 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 7850 | } |
| 7851 | |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 7852 | static bool check_encoder_cloning(struct drm_crtc *crtc) |
| 7853 | { |
| 7854 | int num_encoders = 0; |
| 7855 | bool uncloneable_encoders = false; |
| 7856 | struct intel_encoder *encoder; |
| 7857 | |
| 7858 | list_for_each_entry(encoder, &crtc->dev->mode_config.encoder_list, |
| 7859 | base.head) { |
| 7860 | if (&encoder->new_crtc->base != crtc) |
| 7861 | continue; |
| 7862 | |
| 7863 | num_encoders++; |
| 7864 | if (!encoder->cloneable) |
| 7865 | uncloneable_encoders = true; |
| 7866 | } |
| 7867 | |
| 7868 | return !(num_encoders > 1 && uncloneable_encoders); |
| 7869 | } |
| 7870 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 7871 | static struct intel_crtc_config * |
| 7872 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7873 | struct drm_framebuffer *fb, |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 7874 | struct drm_display_mode *mode) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7875 | { |
| 7876 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7877 | struct drm_encoder_helper_funcs *encoder_funcs; |
| 7878 | struct intel_encoder *encoder; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 7879 | struct intel_crtc_config *pipe_config; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 7880 | int plane_bpp, ret = -EINVAL; |
| 7881 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7882 | |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 7883 | if (!check_encoder_cloning(crtc)) { |
| 7884 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 7885 | return ERR_PTR(-EINVAL); |
| 7886 | } |
| 7887 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 7888 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 7889 | if (!pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7890 | return ERR_PTR(-ENOMEM); |
| 7891 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 7892 | drm_mode_copy(&pipe_config->adjusted_mode, mode); |
| 7893 | drm_mode_copy(&pipe_config->requested_mode, mode); |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7894 | pipe_config->cpu_transcoder = |
| 7895 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7896 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 7897 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 7898 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
| 7899 | * plane pixel format and any sink constraints into account. Returns the |
| 7900 | * source plane bpp so that dithering can be selected on mismatches |
| 7901 | * after encoders and crtc also have had their say. */ |
| 7902 | plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 7903 | fb, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7904 | if (plane_bpp < 0) |
| 7905 | goto fail; |
| 7906 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 7907 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7908 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 7909 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7910 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 7911 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7912 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 7913 | * adjust it according to limitations or connector properties, and also |
| 7914 | * a chance to reject the mode entirely. |
| 7915 | */ |
| 7916 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 7917 | base.head) { |
| 7918 | |
| 7919 | if (&encoder->new_crtc->base != crtc) |
| 7920 | continue; |
Daniel Vetter | 7ae8923 | 2013-03-27 00:44:52 +0100 | [diff] [blame] | 7921 | |
| 7922 | if (encoder->compute_config) { |
| 7923 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 7924 | DRM_DEBUG_KMS("Encoder config failure\n"); |
| 7925 | goto fail; |
| 7926 | } |
| 7927 | |
| 7928 | continue; |
| 7929 | } |
| 7930 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7931 | encoder_funcs = encoder->base.helper_private; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 7932 | if (!(encoder_funcs->mode_fixup(&encoder->base, |
| 7933 | &pipe_config->requested_mode, |
| 7934 | &pipe_config->adjusted_mode))) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7935 | DRM_DEBUG_KMS("Encoder fixup failed\n"); |
| 7936 | goto fail; |
| 7937 | } |
| 7938 | } |
| 7939 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 7940 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 7941 | * done afterwards in case the encoder adjusts the mode. */ |
| 7942 | if (!pipe_config->port_clock) |
| 7943 | pipe_config->port_clock = pipe_config->adjusted_mode.clock; |
| 7944 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 7945 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 7946 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7947 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 7948 | goto fail; |
| 7949 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 7950 | |
| 7951 | if (ret == RETRY) { |
| 7952 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 7953 | ret = -EINVAL; |
| 7954 | goto fail; |
| 7955 | } |
| 7956 | |
| 7957 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 7958 | retry = false; |
| 7959 | goto encoder_retry; |
| 7960 | } |
| 7961 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 7962 | pipe_config->dither = pipe_config->pipe_bpp != plane_bpp; |
| 7963 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
| 7964 | plane_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
| 7965 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 7966 | return pipe_config; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7967 | fail: |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 7968 | kfree(pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 7969 | return ERR_PTR(ret); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 7970 | } |
| 7971 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 7972 | /* Computes which crtcs are affected and sets the relevant bits in the mask. For |
| 7973 | * simplicity we use the crtc's pipe number (because it's easier to obtain). */ |
| 7974 | static void |
| 7975 | intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes, |
| 7976 | unsigned *prepare_pipes, unsigned *disable_pipes) |
| 7977 | { |
| 7978 | struct intel_crtc *intel_crtc; |
| 7979 | struct drm_device *dev = crtc->dev; |
| 7980 | struct intel_encoder *encoder; |
| 7981 | struct intel_connector *connector; |
| 7982 | struct drm_crtc *tmp_crtc; |
| 7983 | |
| 7984 | *disable_pipes = *modeset_pipes = *prepare_pipes = 0; |
| 7985 | |
| 7986 | /* Check which crtcs have changed outputs connected to them, these need |
| 7987 | * to be part of the prepare_pipes mask. We don't (yet) support global |
| 7988 | * modeset across multiple crtcs, so modeset_pipes will only have one |
| 7989 | * bit set at most. */ |
| 7990 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 7991 | base.head) { |
| 7992 | if (connector->base.encoder == &connector->new_encoder->base) |
| 7993 | continue; |
| 7994 | |
| 7995 | if (connector->base.encoder) { |
| 7996 | tmp_crtc = connector->base.encoder->crtc; |
| 7997 | |
| 7998 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 7999 | } |
| 8000 | |
| 8001 | if (connector->new_encoder) |
| 8002 | *prepare_pipes |= |
| 8003 | 1 << connector->new_encoder->new_crtc->pipe; |
| 8004 | } |
| 8005 | |
| 8006 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 8007 | base.head) { |
| 8008 | if (encoder->base.crtc == &encoder->new_crtc->base) |
| 8009 | continue; |
| 8010 | |
| 8011 | if (encoder->base.crtc) { |
| 8012 | tmp_crtc = encoder->base.crtc; |
| 8013 | |
| 8014 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 8015 | } |
| 8016 | |
| 8017 | if (encoder->new_crtc) |
| 8018 | *prepare_pipes |= 1 << encoder->new_crtc->pipe; |
| 8019 | } |
| 8020 | |
| 8021 | /* Check for any pipes that will be fully disabled ... */ |
| 8022 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 8023 | base.head) { |
| 8024 | bool used = false; |
| 8025 | |
| 8026 | /* Don't try to disable disabled crtcs. */ |
| 8027 | if (!intel_crtc->base.enabled) |
| 8028 | continue; |
| 8029 | |
| 8030 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 8031 | base.head) { |
| 8032 | if (encoder->new_crtc == intel_crtc) |
| 8033 | used = true; |
| 8034 | } |
| 8035 | |
| 8036 | if (!used) |
| 8037 | *disable_pipes |= 1 << intel_crtc->pipe; |
| 8038 | } |
| 8039 | |
| 8040 | |
| 8041 | /* set_mode is also used to update properties on life display pipes. */ |
| 8042 | intel_crtc = to_intel_crtc(crtc); |
| 8043 | if (crtc->enabled) |
| 8044 | *prepare_pipes |= 1 << intel_crtc->pipe; |
| 8045 | |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 8046 | /* |
| 8047 | * For simplicity do a full modeset on any pipe where the output routing |
| 8048 | * changed. We could be more clever, but that would require us to be |
| 8049 | * more careful with calling the relevant encoder->mode_set functions. |
| 8050 | */ |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 8051 | if (*prepare_pipes) |
| 8052 | *modeset_pipes = *prepare_pipes; |
| 8053 | |
| 8054 | /* ... and mask these out. */ |
| 8055 | *modeset_pipes &= ~(*disable_pipes); |
| 8056 | *prepare_pipes &= ~(*disable_pipes); |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 8057 | |
| 8058 | /* |
| 8059 | * HACK: We don't (yet) fully support global modesets. intel_set_config |
| 8060 | * obies this rule, but the modeset restore mode of |
| 8061 | * intel_modeset_setup_hw_state does not. |
| 8062 | */ |
| 8063 | *modeset_pipes &= 1 << intel_crtc->pipe; |
| 8064 | *prepare_pipes &= 1 << intel_crtc->pipe; |
Daniel Vetter | e3641d3 | 2013-04-11 19:49:07 +0200 | [diff] [blame] | 8065 | |
| 8066 | DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n", |
| 8067 | *modeset_pipes, *prepare_pipes, *disable_pipes); |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 8068 | } |
| 8069 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 8070 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
| 8071 | { |
| 8072 | struct drm_encoder *encoder; |
| 8073 | struct drm_device *dev = crtc->dev; |
| 8074 | |
| 8075 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 8076 | if (encoder->crtc == crtc) |
| 8077 | return true; |
| 8078 | |
| 8079 | return false; |
| 8080 | } |
| 8081 | |
| 8082 | static void |
| 8083 | intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes) |
| 8084 | { |
| 8085 | struct intel_encoder *intel_encoder; |
| 8086 | struct intel_crtc *intel_crtc; |
| 8087 | struct drm_connector *connector; |
| 8088 | |
| 8089 | list_for_each_entry(intel_encoder, &dev->mode_config.encoder_list, |
| 8090 | base.head) { |
| 8091 | if (!intel_encoder->base.crtc) |
| 8092 | continue; |
| 8093 | |
| 8094 | intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
| 8095 | |
| 8096 | if (prepare_pipes & (1 << intel_crtc->pipe)) |
| 8097 | intel_encoder->connectors_active = false; |
| 8098 | } |
| 8099 | |
| 8100 | intel_modeset_commit_output_state(dev); |
| 8101 | |
| 8102 | /* Update computed state. */ |
| 8103 | list_for_each_entry(intel_crtc, &dev->mode_config.crtc_list, |
| 8104 | base.head) { |
| 8105 | intel_crtc->base.enabled = intel_crtc_in_use(&intel_crtc->base); |
| 8106 | } |
| 8107 | |
| 8108 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 8109 | if (!connector->encoder || !connector->encoder->crtc) |
| 8110 | continue; |
| 8111 | |
| 8112 | intel_crtc = to_intel_crtc(connector->encoder->crtc); |
| 8113 | |
| 8114 | if (prepare_pipes & (1 << intel_crtc->pipe)) { |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 8115 | struct drm_property *dpms_property = |
| 8116 | dev->mode_config.dpms_property; |
| 8117 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 8118 | connector->dpms = DRM_MODE_DPMS_ON; |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 8119 | drm_object_property_set_value(&connector->base, |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 8120 | dpms_property, |
| 8121 | DRM_MODE_DPMS_ON); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 8122 | |
| 8123 | intel_encoder = to_intel_encoder(connector->encoder); |
| 8124 | intel_encoder->connectors_active = true; |
| 8125 | } |
| 8126 | } |
| 8127 | |
| 8128 | } |
| 8129 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8130 | static bool intel_fuzzy_clock_check(struct intel_crtc_config *cur, |
| 8131 | struct intel_crtc_config *new) |
| 8132 | { |
| 8133 | int clock1, clock2, diff; |
| 8134 | |
| 8135 | clock1 = cur->adjusted_mode.clock; |
| 8136 | clock2 = new->adjusted_mode.clock; |
| 8137 | |
| 8138 | if (clock1 == clock2) |
| 8139 | return true; |
| 8140 | |
| 8141 | if (!clock1 || !clock2) |
| 8142 | return false; |
| 8143 | |
| 8144 | diff = abs(clock1 - clock2); |
| 8145 | |
| 8146 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 8147 | return true; |
| 8148 | |
| 8149 | return false; |
| 8150 | } |
| 8151 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8152 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 8153 | list_for_each_entry((intel_crtc), \ |
| 8154 | &(dev)->mode_config.crtc_list, \ |
| 8155 | base.head) \ |
Daniel Vetter | 0973f18 | 2013-04-19 11:25:33 +0200 | [diff] [blame] | 8156 | if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8157 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8158 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8159 | intel_pipe_config_compare(struct drm_device *dev, |
| 8160 | struct intel_crtc_config *current_config, |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8161 | struct intel_crtc_config *pipe_config) |
| 8162 | { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8163 | #define PIPE_CONF_CHECK_X(name) \ |
| 8164 | if (current_config->name != pipe_config->name) { \ |
| 8165 | DRM_ERROR("mismatch in " #name " " \ |
| 8166 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 8167 | current_config->name, \ |
| 8168 | pipe_config->name); \ |
| 8169 | return false; \ |
| 8170 | } |
| 8171 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 8172 | #define PIPE_CONF_CHECK_I(name) \ |
| 8173 | if (current_config->name != pipe_config->name) { \ |
| 8174 | DRM_ERROR("mismatch in " #name " " \ |
| 8175 | "(expected %i, found %i)\n", \ |
| 8176 | current_config->name, \ |
| 8177 | pipe_config->name); \ |
| 8178 | return false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8179 | } |
| 8180 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8181 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 8182 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Jesse Barnes | 6f02488 | 2013-07-01 10:19:09 -0700 | [diff] [blame] | 8183 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8184 | "(expected %i, found %i)\n", \ |
| 8185 | current_config->name & (mask), \ |
| 8186 | pipe_config->name & (mask)); \ |
| 8187 | return false; \ |
| 8188 | } |
| 8189 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 8190 | #define PIPE_CONF_QUIRK(quirk) \ |
| 8191 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 8192 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8193 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 8194 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 8195 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 8196 | PIPE_CONF_CHECK_I(fdi_lanes); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8197 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
| 8198 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); |
| 8199 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); |
| 8200 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); |
| 8201 | PIPE_CONF_CHECK_I(fdi_m_n.tu); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 8202 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8203 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay); |
| 8204 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal); |
| 8205 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start); |
| 8206 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end); |
| 8207 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start); |
| 8208 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end); |
| 8209 | |
| 8210 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay); |
| 8211 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal); |
| 8212 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start); |
| 8213 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end); |
| 8214 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start); |
| 8215 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end); |
| 8216 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 8217 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8218 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8219 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 8220 | DRM_MODE_FLAG_INTERLACE); |
| 8221 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 8222 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
| 8223 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 8224 | DRM_MODE_FLAG_PHSYNC); |
| 8225 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 8226 | DRM_MODE_FLAG_NHSYNC); |
| 8227 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 8228 | DRM_MODE_FLAG_PVSYNC); |
| 8229 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 8230 | DRM_MODE_FLAG_NVSYNC); |
| 8231 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 8232 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8233 | PIPE_CONF_CHECK_I(requested_mode.hdisplay); |
| 8234 | PIPE_CONF_CHECK_I(requested_mode.vdisplay); |
| 8235 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8236 | PIPE_CONF_CHECK_I(gmch_pfit.control); |
| 8237 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 8238 | if (INTEL_INFO(dev)->gen < 4) |
| 8239 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
| 8240 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); |
| 8241 | PIPE_CONF_CHECK_I(pch_pfit.pos); |
| 8242 | PIPE_CONF_CHECK_I(pch_pfit.size); |
| 8243 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 8244 | PIPE_CONF_CHECK_I(ips_enabled); |
| 8245 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8246 | PIPE_CONF_CHECK_I(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8247 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 8248 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8249 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 8250 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8251 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8252 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 8253 | #undef PIPE_CONF_CHECK_I |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8254 | #undef PIPE_CONF_CHECK_FLAGS |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 8255 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8256 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8257 | if (!IS_HASWELL(dev)) { |
| 8258 | if (!intel_fuzzy_clock_check(current_config, pipe_config)) { |
Jesse Barnes | 6f02488 | 2013-07-01 10:19:09 -0700 | [diff] [blame] | 8259 | DRM_ERROR("mismatch in clock (expected %d, found %d)\n", |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8260 | current_config->adjusted_mode.clock, |
| 8261 | pipe_config->adjusted_mode.clock); |
| 8262 | return false; |
| 8263 | } |
| 8264 | } |
| 8265 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8266 | return true; |
| 8267 | } |
| 8268 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 8269 | static void |
| 8270 | check_connector_state(struct drm_device *dev) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 8271 | { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 8272 | struct intel_connector *connector; |
| 8273 | |
| 8274 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 8275 | base.head) { |
| 8276 | /* This also checks the encoder/connector hw state with the |
| 8277 | * ->get_hw_state callbacks. */ |
| 8278 | intel_connector_check_state(connector); |
| 8279 | |
| 8280 | WARN(&connector->new_encoder->base != connector->base.encoder, |
| 8281 | "connector's staged encoder doesn't match current encoder\n"); |
| 8282 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 8283 | } |
| 8284 | |
| 8285 | static void |
| 8286 | check_encoder_state(struct drm_device *dev) |
| 8287 | { |
| 8288 | struct intel_encoder *encoder; |
| 8289 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 8290 | |
| 8291 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 8292 | base.head) { |
| 8293 | bool enabled = false; |
| 8294 | bool active = false; |
| 8295 | enum pipe pipe, tracked_pipe; |
| 8296 | |
| 8297 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 8298 | encoder->base.base.id, |
| 8299 | drm_get_encoder_name(&encoder->base)); |
| 8300 | |
| 8301 | WARN(&encoder->new_crtc->base != encoder->base.crtc, |
| 8302 | "encoder's stage crtc doesn't match current crtc\n"); |
| 8303 | WARN(encoder->connectors_active && !encoder->base.crtc, |
| 8304 | "encoder's active_connectors set, but no crtc\n"); |
| 8305 | |
| 8306 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 8307 | base.head) { |
| 8308 | if (connector->base.encoder != &encoder->base) |
| 8309 | continue; |
| 8310 | enabled = true; |
| 8311 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) |
| 8312 | active = true; |
| 8313 | } |
| 8314 | WARN(!!encoder->base.crtc != enabled, |
| 8315 | "encoder's enabled state mismatch " |
| 8316 | "(expected %i, found %i)\n", |
| 8317 | !!encoder->base.crtc, enabled); |
| 8318 | WARN(active && !encoder->base.crtc, |
| 8319 | "active encoder with no crtc\n"); |
| 8320 | |
| 8321 | WARN(encoder->connectors_active != active, |
| 8322 | "encoder's computed active state doesn't match tracked active state " |
| 8323 | "(expected %i, found %i)\n", active, encoder->connectors_active); |
| 8324 | |
| 8325 | active = encoder->get_hw_state(encoder, &pipe); |
| 8326 | WARN(active != encoder->connectors_active, |
| 8327 | "encoder's hw state doesn't match sw tracking " |
| 8328 | "(expected %i, found %i)\n", |
| 8329 | encoder->connectors_active, active); |
| 8330 | |
| 8331 | if (!encoder->base.crtc) |
| 8332 | continue; |
| 8333 | |
| 8334 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; |
| 8335 | WARN(active && pipe != tracked_pipe, |
| 8336 | "active encoder's pipe doesn't match" |
| 8337 | "(expected %i, found %i)\n", |
| 8338 | tracked_pipe, pipe); |
| 8339 | |
| 8340 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 8341 | } |
| 8342 | |
| 8343 | static void |
| 8344 | check_crtc_state(struct drm_device *dev) |
| 8345 | { |
| 8346 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 8347 | struct intel_crtc *crtc; |
| 8348 | struct intel_encoder *encoder; |
| 8349 | struct intel_crtc_config pipe_config; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 8350 | |
| 8351 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, |
| 8352 | base.head) { |
| 8353 | bool enabled = false; |
| 8354 | bool active = false; |
| 8355 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 8356 | memset(&pipe_config, 0, sizeof(pipe_config)); |
| 8357 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 8358 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 8359 | crtc->base.base.id); |
| 8360 | |
| 8361 | WARN(crtc->active && !crtc->base.enabled, |
| 8362 | "active crtc, but not enabled in sw tracking\n"); |
| 8363 | |
| 8364 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 8365 | base.head) { |
| 8366 | if (encoder->base.crtc != &crtc->base) |
| 8367 | continue; |
| 8368 | enabled = true; |
| 8369 | if (encoder->connectors_active) |
| 8370 | active = true; |
| 8371 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8372 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 8373 | WARN(active != crtc->active, |
| 8374 | "crtc's computed active state doesn't match tracked active state " |
| 8375 | "(expected %i, found %i)\n", active, crtc->active); |
| 8376 | WARN(enabled != crtc->base.enabled, |
| 8377 | "crtc's computed enabled state doesn't match tracked enabled state " |
| 8378 | "(expected %i, found %i)\n", enabled, crtc->base.enabled); |
| 8379 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8380 | active = dev_priv->display.get_pipe_config(crtc, |
| 8381 | &pipe_config); |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 8382 | |
| 8383 | /* hw state is inconsistent with the pipe A quirk */ |
| 8384 | if (crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) |
| 8385 | active = crtc->active; |
| 8386 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8387 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 8388 | base.head) { |
| 8389 | if (encoder->base.crtc != &crtc->base) |
| 8390 | continue; |
Jesse Barnes | 510d5f2 | 2013-07-01 15:50:17 -0700 | [diff] [blame] | 8391 | if (encoder->get_config) |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8392 | encoder->get_config(encoder, &pipe_config); |
| 8393 | } |
| 8394 | |
Jesse Barnes | 510d5f2 | 2013-07-01 15:50:17 -0700 | [diff] [blame] | 8395 | if (dev_priv->display.get_clock) |
| 8396 | dev_priv->display.get_clock(crtc, &pipe_config); |
| 8397 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8398 | WARN(crtc->active != active, |
| 8399 | "crtc active state doesn't match with hw state " |
| 8400 | "(expected %i, found %i)\n", crtc->active, active); |
| 8401 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 8402 | if (active && |
| 8403 | !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) { |
| 8404 | WARN(1, "pipe state doesn't match!\n"); |
| 8405 | intel_dump_pipe_config(crtc, &pipe_config, |
| 8406 | "[hw state]"); |
| 8407 | intel_dump_pipe_config(crtc, &crtc->config, |
| 8408 | "[sw state]"); |
| 8409 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 8410 | } |
| 8411 | } |
| 8412 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 8413 | static void |
| 8414 | check_shared_dpll_state(struct drm_device *dev) |
| 8415 | { |
| 8416 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 8417 | struct intel_crtc *crtc; |
| 8418 | struct intel_dpll_hw_state dpll_hw_state; |
| 8419 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 8420 | |
| 8421 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 8422 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 8423 | int enabled_crtcs = 0, active_crtcs = 0; |
| 8424 | bool active; |
| 8425 | |
| 8426 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 8427 | |
| 8428 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 8429 | |
| 8430 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 8431 | |
| 8432 | WARN(pll->active > pll->refcount, |
| 8433 | "more active pll users than references: %i vs %i\n", |
| 8434 | pll->active, pll->refcount); |
| 8435 | WARN(pll->active && !pll->on, |
| 8436 | "pll in active use but not on in sw tracking\n"); |
| 8437 | WARN(pll->on != active, |
| 8438 | "pll on state mismatch (expected %i, found %i)\n", |
| 8439 | pll->on, active); |
| 8440 | |
| 8441 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, |
| 8442 | base.head) { |
| 8443 | if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll) |
| 8444 | enabled_crtcs++; |
| 8445 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 8446 | active_crtcs++; |
| 8447 | } |
| 8448 | WARN(pll->active != active_crtcs, |
| 8449 | "pll active crtcs mismatch (expected %i, found %i)\n", |
| 8450 | pll->active, active_crtcs); |
| 8451 | WARN(pll->refcount != enabled_crtcs, |
| 8452 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
| 8453 | pll->refcount, enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8454 | |
| 8455 | WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state, |
| 8456 | sizeof(dpll_hw_state)), |
| 8457 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 8458 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8459 | } |
| 8460 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 8461 | void |
| 8462 | intel_modeset_check_state(struct drm_device *dev) |
| 8463 | { |
| 8464 | check_connector_state(dev); |
| 8465 | check_encoder_state(dev); |
| 8466 | check_crtc_state(dev); |
| 8467 | check_shared_dpll_state(dev); |
| 8468 | } |
| 8469 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 8470 | static int __intel_set_mode(struct drm_crtc *crtc, |
| 8471 | struct drm_display_mode *mode, |
| 8472 | int x, int y, struct drm_framebuffer *fb) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8473 | { |
| 8474 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | dbf2b54e | 2012-07-02 11:18:29 +0200 | [diff] [blame] | 8475 | drm_i915_private_t *dev_priv = dev->dev_private; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 8476 | struct drm_display_mode *saved_mode, *saved_hwmode; |
| 8477 | struct intel_crtc_config *pipe_config = NULL; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8478 | struct intel_crtc *intel_crtc; |
| 8479 | unsigned disable_pipes, prepare_pipes, modeset_pipes; |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8480 | int ret = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8481 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 8482 | saved_mode = kmalloc(2 * sizeof(*saved_mode), GFP_KERNEL); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8483 | if (!saved_mode) |
| 8484 | return -ENOMEM; |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 8485 | saved_hwmode = saved_mode + 1; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8486 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 8487 | intel_modeset_affected_pipes(crtc, &modeset_pipes, |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8488 | &prepare_pipes, &disable_pipes); |
| 8489 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 8490 | *saved_hwmode = crtc->hwmode; |
| 8491 | *saved_mode = crtc->mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8492 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8493 | /* Hack: Because we don't (yet) support global modeset on multiple |
| 8494 | * crtcs, we don't keep track of the new mode for more than one crtc. |
| 8495 | * Hence simply check whether any bit is set in modeset_pipes in all the |
| 8496 | * pieces of code that are not yet converted to deal with mutliple crtcs |
| 8497 | * changing their mode at the same time. */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8498 | if (modeset_pipes) { |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 8499 | pipe_config = intel_modeset_pipe_config(crtc, fb, mode); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 8500 | if (IS_ERR(pipe_config)) { |
| 8501 | ret = PTR_ERR(pipe_config); |
| 8502 | pipe_config = NULL; |
| 8503 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 8504 | goto out; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8505 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 8506 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 8507 | "[modeset]"); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8508 | } |
| 8509 | |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 8510 | for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc) |
| 8511 | intel_crtc_disable(&intel_crtc->base); |
| 8512 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 8513 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
| 8514 | if (intel_crtc->base.enabled) |
| 8515 | dev_priv->display.crtc_disable(&intel_crtc->base); |
| 8516 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8517 | |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 8518 | /* crtc->mode is already used by the ->mode_set callbacks, hence we need |
| 8519 | * to set it here already despite that we pass it down the callchain. |
| 8520 | */ |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 8521 | if (modeset_pipes) { |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8522 | crtc->mode = *mode; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 8523 | /* mode_set/enable/disable functions rely on a correct pipe |
| 8524 | * config. */ |
| 8525 | to_intel_crtc(crtc)->config = *pipe_config; |
| 8526 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 8527 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 8528 | /* Only after disabling all output pipelines that will be changed can we |
| 8529 | * update the the output configuration. */ |
| 8530 | intel_modeset_update_state(dev, prepare_pipes); |
| 8531 | |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 8532 | if (dev_priv->display.modeset_global_resources) |
| 8533 | dev_priv->display.modeset_global_resources(dev); |
| 8534 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8535 | /* Set up the DPLL and any encoders state that needs to adjust or depend |
| 8536 | * on the DPLL. |
| 8537 | */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8538 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8539 | ret = intel_crtc_mode_set(&intel_crtc->base, |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8540 | x, y, fb); |
| 8541 | if (ret) |
| 8542 | goto done; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8543 | } |
| 8544 | |
| 8545 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8546 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) |
| 8547 | dev_priv->display.crtc_enable(&intel_crtc->base); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8548 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8549 | if (modeset_pipes) { |
| 8550 | /* Store real post-adjustment hardware mode. */ |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 8551 | crtc->hwmode = pipe_config->adjusted_mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8552 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8553 | /* Calculate and store various constants which |
| 8554 | * are later needed by vblank and swap-completion |
| 8555 | * timestamping. They are derived from true hwmode. |
| 8556 | */ |
| 8557 | drm_calc_timestamping_constants(crtc); |
| 8558 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8559 | |
| 8560 | /* FIXME: add subpixel order */ |
| 8561 | done: |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8562 | if (ret && crtc->enabled) { |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 8563 | crtc->hwmode = *saved_hwmode; |
| 8564 | crtc->mode = *saved_mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8565 | } |
| 8566 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 8567 | out: |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 8568 | kfree(pipe_config); |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 8569 | kfree(saved_mode); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 8570 | return ret; |
| 8571 | } |
| 8572 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 8573 | int intel_set_mode(struct drm_crtc *crtc, |
| 8574 | struct drm_display_mode *mode, |
| 8575 | int x, int y, struct drm_framebuffer *fb) |
| 8576 | { |
| 8577 | int ret; |
| 8578 | |
| 8579 | ret = __intel_set_mode(crtc, mode, x, y, fb); |
| 8580 | |
| 8581 | if (ret == 0) |
| 8582 | intel_modeset_check_state(crtc->dev); |
| 8583 | |
| 8584 | return ret; |
| 8585 | } |
| 8586 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8587 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 8588 | { |
| 8589 | intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->fb); |
| 8590 | } |
| 8591 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 8592 | #undef for_each_intel_crtc_masked |
| 8593 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 8594 | static void intel_set_config_free(struct intel_set_config *config) |
| 8595 | { |
| 8596 | if (!config) |
| 8597 | return; |
| 8598 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 8599 | kfree(config->save_connector_encoders); |
| 8600 | kfree(config->save_encoder_crtcs); |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 8601 | kfree(config); |
| 8602 | } |
| 8603 | |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8604 | static int intel_set_config_save_state(struct drm_device *dev, |
| 8605 | struct intel_set_config *config) |
| 8606 | { |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8607 | struct drm_encoder *encoder; |
| 8608 | struct drm_connector *connector; |
| 8609 | int count; |
| 8610 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 8611 | config->save_encoder_crtcs = |
| 8612 | kcalloc(dev->mode_config.num_encoder, |
| 8613 | sizeof(struct drm_crtc *), GFP_KERNEL); |
| 8614 | if (!config->save_encoder_crtcs) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8615 | return -ENOMEM; |
| 8616 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 8617 | config->save_connector_encoders = |
| 8618 | kcalloc(dev->mode_config.num_connector, |
| 8619 | sizeof(struct drm_encoder *), GFP_KERNEL); |
| 8620 | if (!config->save_connector_encoders) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8621 | return -ENOMEM; |
| 8622 | |
| 8623 | /* Copy data. Note that driver private data is not affected. |
| 8624 | * Should anything bad happen only the expected state is |
| 8625 | * restored, not the drivers personal bookkeeping. |
| 8626 | */ |
| 8627 | count = 0; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8628 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 8629 | config->save_encoder_crtcs[count++] = encoder->crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8630 | } |
| 8631 | |
| 8632 | count = 0; |
| 8633 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 8634 | config->save_connector_encoders[count++] = connector->encoder; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8635 | } |
| 8636 | |
| 8637 | return 0; |
| 8638 | } |
| 8639 | |
| 8640 | static void intel_set_config_restore_state(struct drm_device *dev, |
| 8641 | struct intel_set_config *config) |
| 8642 | { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8643 | struct intel_encoder *encoder; |
| 8644 | struct intel_connector *connector; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8645 | int count; |
| 8646 | |
| 8647 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8648 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) { |
| 8649 | encoder->new_crtc = |
| 8650 | to_intel_crtc(config->save_encoder_crtcs[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8651 | } |
| 8652 | |
| 8653 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8654 | list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) { |
| 8655 | connector->new_encoder = |
| 8656 | to_intel_encoder(config->save_connector_encoders[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8657 | } |
| 8658 | } |
| 8659 | |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 8660 | static bool |
| 8661 | is_crtc_connector_off(struct drm_crtc *crtc, struct drm_connector *connectors, |
| 8662 | int num_connectors) |
| 8663 | { |
| 8664 | int i; |
| 8665 | |
| 8666 | for (i = 0; i < num_connectors; i++) |
| 8667 | if (connectors[i].encoder && |
| 8668 | connectors[i].encoder->crtc == crtc && |
| 8669 | connectors[i].dpms != DRM_MODE_DPMS_ON) |
| 8670 | return true; |
| 8671 | |
| 8672 | return false; |
| 8673 | } |
| 8674 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8675 | static void |
| 8676 | intel_set_config_compute_mode_changes(struct drm_mode_set *set, |
| 8677 | struct intel_set_config *config) |
| 8678 | { |
| 8679 | |
| 8680 | /* We should be able to check here if the fb has the same properties |
| 8681 | * and then just flip_or_move it */ |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 8682 | if (set->connectors != NULL && |
| 8683 | is_crtc_connector_off(set->crtc, *set->connectors, |
| 8684 | set->num_connectors)) { |
| 8685 | config->mode_changed = true; |
| 8686 | } else if (set->crtc->fb != set->fb) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8687 | /* If we have no fb then treat it as a full mode set */ |
| 8688 | if (set->crtc->fb == NULL) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 8689 | struct intel_crtc *intel_crtc = |
| 8690 | to_intel_crtc(set->crtc); |
| 8691 | |
| 8692 | if (intel_crtc->active && i915_fastboot) { |
| 8693 | DRM_DEBUG_KMS("crtc has no fb, will flip\n"); |
| 8694 | config->fb_changed = true; |
| 8695 | } else { |
| 8696 | DRM_DEBUG_KMS("inactive crtc, full mode set\n"); |
| 8697 | config->mode_changed = true; |
| 8698 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8699 | } else if (set->fb == NULL) { |
| 8700 | config->mode_changed = true; |
Daniel Vetter | 72f4901 | 2013-03-28 16:01:35 +0100 | [diff] [blame] | 8701 | } else if (set->fb->pixel_format != |
| 8702 | set->crtc->fb->pixel_format) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8703 | config->mode_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 8704 | } else { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8705 | config->fb_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 8706 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8707 | } |
| 8708 | |
Daniel Vetter | 835c587 | 2012-07-10 18:11:08 +0200 | [diff] [blame] | 8709 | 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] | 8710 | config->fb_changed = true; |
| 8711 | |
| 8712 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
| 8713 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
| 8714 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 8715 | drm_mode_debug_printmodeline(set->mode); |
| 8716 | config->mode_changed = true; |
| 8717 | } |
| 8718 | } |
| 8719 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 8720 | static int |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8721 | intel_modeset_stage_output_state(struct drm_device *dev, |
| 8722 | struct drm_mode_set *set, |
| 8723 | struct intel_set_config *config) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8724 | { |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 8725 | struct drm_crtc *new_crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8726 | struct intel_connector *connector; |
| 8727 | struct intel_encoder *encoder; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 8728 | int count, ro; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8729 | |
Damien Lespiau | 9abdda7 | 2013-02-13 13:29:23 +0000 | [diff] [blame] | 8730 | /* The upper layers ensure that we either disable a crtc or have a list |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8731 | * of connectors. For paranoia, double-check this. */ |
| 8732 | WARN_ON(!set->fb && (set->num_connectors != 0)); |
| 8733 | WARN_ON(set->fb && (set->num_connectors == 0)); |
| 8734 | |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8735 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8736 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 8737 | base.head) { |
| 8738 | /* Otherwise traverse passed in connector list and get encoders |
| 8739 | * for them. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8740 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8741 | if (set->connectors[ro] == &connector->base) { |
| 8742 | connector->new_encoder = connector->encoder; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8743 | break; |
| 8744 | } |
| 8745 | } |
| 8746 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8747 | /* If we disable the crtc, disable all its connectors. Also, if |
| 8748 | * the connector is on the changing crtc but not on the new |
| 8749 | * connector list, disable it. */ |
| 8750 | if ((!set->fb || ro == set->num_connectors) && |
| 8751 | connector->base.encoder && |
| 8752 | connector->base.encoder->crtc == set->crtc) { |
| 8753 | connector->new_encoder = NULL; |
| 8754 | |
| 8755 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", |
| 8756 | connector->base.base.id, |
| 8757 | drm_get_connector_name(&connector->base)); |
| 8758 | } |
| 8759 | |
| 8760 | |
| 8761 | if (&connector->new_encoder->base != connector->base.encoder) { |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8762 | DRM_DEBUG_KMS("encoder changed, full mode switch\n"); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8763 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8764 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8765 | } |
| 8766 | /* connector->new_encoder is now updated for all connectors. */ |
| 8767 | |
| 8768 | /* Update crtc of enabled connectors. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8769 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8770 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 8771 | base.head) { |
| 8772 | if (!connector->new_encoder) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8773 | continue; |
| 8774 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8775 | new_crtc = connector->new_encoder->base.crtc; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8776 | |
| 8777 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8778 | if (set->connectors[ro] == &connector->base) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8779 | new_crtc = set->crtc; |
| 8780 | } |
| 8781 | |
| 8782 | /* Make sure the new CRTC will work with the encoder */ |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8783 | if (!intel_encoder_crtc_ok(&connector->new_encoder->base, |
| 8784 | new_crtc)) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8785 | return -EINVAL; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8786 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8787 | connector->encoder->new_crtc = to_intel_crtc(new_crtc); |
| 8788 | |
| 8789 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
| 8790 | connector->base.base.id, |
| 8791 | drm_get_connector_name(&connector->base), |
| 8792 | new_crtc->base.id); |
| 8793 | } |
| 8794 | |
| 8795 | /* Check for any encoders that needs to be disabled. */ |
| 8796 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 8797 | base.head) { |
| 8798 | list_for_each_entry(connector, |
| 8799 | &dev->mode_config.connector_list, |
| 8800 | base.head) { |
| 8801 | if (connector->new_encoder == encoder) { |
| 8802 | WARN_ON(!connector->new_encoder->new_crtc); |
| 8803 | |
| 8804 | goto next_encoder; |
| 8805 | } |
| 8806 | } |
| 8807 | encoder->new_crtc = NULL; |
| 8808 | next_encoder: |
| 8809 | /* Only now check for crtc changes so we don't miss encoders |
| 8810 | * that will be disabled. */ |
| 8811 | if (&encoder->new_crtc->base != encoder->base.crtc) { |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8812 | DRM_DEBUG_KMS("crtc changed, full mode switch\n"); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8813 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8814 | } |
| 8815 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8816 | /* Now we've also updated encoder->new_crtc for all encoders. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8817 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 8818 | return 0; |
| 8819 | } |
| 8820 | |
| 8821 | static int intel_crtc_set_config(struct drm_mode_set *set) |
| 8822 | { |
| 8823 | struct drm_device *dev; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 8824 | struct drm_mode_set save_set; |
| 8825 | struct intel_set_config *config; |
| 8826 | int ret; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 8827 | |
Daniel Vetter | 8d3e375 | 2012-07-05 16:09:09 +0200 | [diff] [blame] | 8828 | BUG_ON(!set); |
| 8829 | BUG_ON(!set->crtc); |
| 8830 | BUG_ON(!set->crtc->helper_private); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 8831 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 8832 | /* Enforce sane interface api - has been abused by the fb helper. */ |
| 8833 | BUG_ON(!set->mode && set->fb); |
| 8834 | BUG_ON(set->fb && set->num_connectors == 0); |
Daniel Vetter | 431e50f | 2012-07-10 17:53:42 +0200 | [diff] [blame] | 8835 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 8836 | if (set->fb) { |
| 8837 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", |
| 8838 | set->crtc->base.id, set->fb->base.id, |
| 8839 | (int)set->num_connectors, set->x, set->y); |
| 8840 | } else { |
| 8841 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 8842 | } |
| 8843 | |
| 8844 | dev = set->crtc->dev; |
| 8845 | |
| 8846 | ret = -ENOMEM; |
| 8847 | config = kzalloc(sizeof(*config), GFP_KERNEL); |
| 8848 | if (!config) |
| 8849 | goto out_config; |
| 8850 | |
| 8851 | ret = intel_set_config_save_state(dev, config); |
| 8852 | if (ret) |
| 8853 | goto out_config; |
| 8854 | |
| 8855 | save_set.crtc = set->crtc; |
| 8856 | save_set.mode = &set->crtc->mode; |
| 8857 | save_set.x = set->crtc->x; |
| 8858 | save_set.y = set->crtc->y; |
| 8859 | save_set.fb = set->crtc->fb; |
| 8860 | |
| 8861 | /* Compute whether we need a full modeset, only an fb base update or no |
| 8862 | * change at all. In the future we might also check whether only the |
| 8863 | * mode changed, e.g. for LVDS where we only change the panel fitter in |
| 8864 | * such cases. */ |
| 8865 | intel_set_config_compute_mode_changes(set, config); |
| 8866 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 8867 | ret = intel_modeset_stage_output_state(dev, set, config); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 8868 | if (ret) |
| 8869 | goto fail; |
| 8870 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8871 | if (config->mode_changed) { |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8872 | ret = intel_set_mode(set->crtc, set->mode, |
| 8873 | set->x, set->y, set->fb); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 8874 | } else if (config->fb_changed) { |
Ville Syrjälä | 4878cae | 2013-02-18 19:08:48 +0200 | [diff] [blame] | 8875 | intel_crtc_wait_for_pending_flips(set->crtc); |
| 8876 | |
Daniel Vetter | 4f660f4 | 2012-07-02 09:47:37 +0200 | [diff] [blame] | 8877 | ret = intel_pipe_set_base(set->crtc, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8878 | set->x, set->y, set->fb); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8879 | } |
| 8880 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 8881 | if (ret) { |
Daniel Vetter | bf67dfe | 2013-06-25 11:06:52 +0200 | [diff] [blame] | 8882 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
| 8883 | set->crtc->base.id, ret); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8884 | fail: |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 8885 | intel_set_config_restore_state(dev, config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8886 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 8887 | /* Try to restore the config */ |
| 8888 | if (config->mode_changed && |
| 8889 | intel_set_mode(save_set.crtc, save_set.mode, |
| 8890 | save_set.x, save_set.y, save_set.fb)) |
| 8891 | DRM_ERROR("failed to restore config after modeset failure\n"); |
| 8892 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8893 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 8894 | out_config: |
| 8895 | intel_set_config_free(config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8896 | return ret; |
| 8897 | } |
| 8898 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 8899 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 8900 | .cursor_set = intel_crtc_cursor_set, |
| 8901 | .cursor_move = intel_crtc_cursor_move, |
| 8902 | .gamma_set = intel_crtc_gamma_set, |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 8903 | .set_config = intel_crtc_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 8904 | .destroy = intel_crtc_destroy, |
| 8905 | .page_flip = intel_crtc_page_flip, |
| 8906 | }; |
| 8907 | |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 8908 | static void intel_cpu_pll_init(struct drm_device *dev) |
| 8909 | { |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 8910 | if (HAS_DDI(dev)) |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 8911 | intel_ddi_pll_init(dev); |
| 8912 | } |
| 8913 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 8914 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
| 8915 | struct intel_shared_dpll *pll, |
| 8916 | struct intel_dpll_hw_state *hw_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8917 | { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 8918 | uint32_t val; |
| 8919 | |
| 8920 | val = I915_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8921 | hw_state->dpll = val; |
| 8922 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); |
| 8923 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 8924 | |
| 8925 | return val & DPLL_VCO_ENABLE; |
| 8926 | } |
| 8927 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 8928 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
| 8929 | struct intel_shared_dpll *pll) |
| 8930 | { |
| 8931 | I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0); |
| 8932 | I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1); |
| 8933 | } |
| 8934 | |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 8935 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
| 8936 | struct intel_shared_dpll *pll) |
| 8937 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 8938 | /* PCH refclock must be enabled first */ |
| 8939 | assert_pch_refclk_enabled(dev_priv); |
| 8940 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 8941 | I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll); |
| 8942 | |
| 8943 | /* Wait for the clocks to stabilize. */ |
| 8944 | POSTING_READ(PCH_DPLL(pll->id)); |
| 8945 | udelay(150); |
| 8946 | |
| 8947 | /* The pixel multiplier can only be updated once the |
| 8948 | * DPLL is enabled and the clocks are stable. |
| 8949 | * |
| 8950 | * So write it again. |
| 8951 | */ |
| 8952 | I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll); |
| 8953 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 8954 | udelay(200); |
| 8955 | } |
| 8956 | |
| 8957 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, |
| 8958 | struct intel_shared_dpll *pll) |
| 8959 | { |
| 8960 | struct drm_device *dev = dev_priv->dev; |
| 8961 | struct intel_crtc *crtc; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 8962 | |
| 8963 | /* Make sure no transcoder isn't still depending on us. */ |
| 8964 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, base.head) { |
| 8965 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
| 8966 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); |
| 8967 | } |
| 8968 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 8969 | I915_WRITE(PCH_DPLL(pll->id), 0); |
| 8970 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 8971 | udelay(200); |
| 8972 | } |
| 8973 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 8974 | static char *ibx_pch_dpll_names[] = { |
| 8975 | "PCH DPLL A", |
| 8976 | "PCH DPLL B", |
| 8977 | }; |
| 8978 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 8979 | static void ibx_pch_dpll_init(struct drm_device *dev) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8980 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 8981 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8982 | int i; |
| 8983 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 8984 | dev_priv->num_shared_dpll = 2; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8985 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 8986 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 8987 | dev_priv->shared_dplls[i].id = i; |
| 8988 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 8989 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 8990 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
| 8991 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 8992 | dev_priv->shared_dplls[i].get_hw_state = |
| 8993 | ibx_pch_dpll_get_hw_state; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8994 | } |
| 8995 | } |
| 8996 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 8997 | static void intel_shared_dpll_init(struct drm_device *dev) |
| 8998 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 8999 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 9000 | |
| 9001 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 9002 | ibx_pch_dpll_init(dev); |
| 9003 | else |
| 9004 | dev_priv->num_shared_dpll = 0; |
| 9005 | |
| 9006 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); |
| 9007 | DRM_DEBUG_KMS("%i shared PLLs initialized\n", |
| 9008 | dev_priv->num_shared_dpll); |
| 9009 | } |
| 9010 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 9011 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9012 | { |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 9013 | drm_i915_private_t *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9014 | struct intel_crtc *intel_crtc; |
| 9015 | int i; |
| 9016 | |
| 9017 | intel_crtc = kzalloc(sizeof(struct intel_crtc) + (INTELFB_CONN_LIMIT * sizeof(struct drm_connector *)), GFP_KERNEL); |
| 9018 | if (intel_crtc == NULL) |
| 9019 | return; |
| 9020 | |
| 9021 | drm_crtc_init(dev, &intel_crtc->base, &intel_crtc_funcs); |
| 9022 | |
| 9023 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9024 | for (i = 0; i < 256; i++) { |
| 9025 | intel_crtc->lut_r[i] = i; |
| 9026 | intel_crtc->lut_g[i] = i; |
| 9027 | intel_crtc->lut_b[i] = i; |
| 9028 | } |
| 9029 | |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 9030 | /* Swap pipes & planes for FBC on pre-965 */ |
| 9031 | intel_crtc->pipe = pipe; |
| 9032 | intel_crtc->plane = pipe; |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 9033 | if (IS_MOBILE(dev) && IS_GEN3(dev)) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 9034 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 9035 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 9036 | } |
| 9037 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 9038 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 9039 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 9040 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 9041 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 9042 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9043 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9044 | } |
| 9045 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 9046 | 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] | 9047 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 9048 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 9049 | 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] | 9050 | struct drm_mode_object *drmmode_obj; |
| 9051 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 9052 | |
Daniel Vetter | 1cff8f6 | 2012-04-24 09:55:08 +0200 | [diff] [blame] | 9053 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 9054 | return -ENODEV; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 9055 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 9056 | drmmode_obj = drm_mode_object_find(dev, pipe_from_crtc_id->crtc_id, |
| 9057 | DRM_MODE_OBJECT_CRTC); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 9058 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 9059 | if (!drmmode_obj) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 9060 | DRM_ERROR("no such CRTC id\n"); |
| 9061 | return -EINVAL; |
| 9062 | } |
| 9063 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 9064 | crtc = to_intel_crtc(obj_to_crtc(drmmode_obj)); |
| 9065 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 9066 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 9067 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 9068 | } |
| 9069 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 9070 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9071 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 9072 | struct drm_device *dev = encoder->base.dev; |
| 9073 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9074 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9075 | int entry = 0; |
| 9076 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 9077 | list_for_each_entry(source_encoder, |
| 9078 | &dev->mode_config.encoder_list, base.head) { |
| 9079 | |
| 9080 | if (encoder == source_encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9081 | index_mask |= (1 << entry); |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 9082 | |
| 9083 | /* Intel hw has only one MUX where enocoders could be cloned. */ |
| 9084 | if (encoder->cloneable && source_encoder->cloneable) |
| 9085 | index_mask |= (1 << entry); |
| 9086 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9087 | entry++; |
| 9088 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 9089 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9090 | return index_mask; |
| 9091 | } |
| 9092 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 9093 | static bool has_edp_a(struct drm_device *dev) |
| 9094 | { |
| 9095 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9096 | |
| 9097 | if (!IS_MOBILE(dev)) |
| 9098 | return false; |
| 9099 | |
| 9100 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 9101 | return false; |
| 9102 | |
| 9103 | if (IS_GEN5(dev) && |
| 9104 | (I915_READ(ILK_DISPLAY_CHICKEN_FUSES) & ILK_eDP_A_DISABLE)) |
| 9105 | return false; |
| 9106 | |
| 9107 | return true; |
| 9108 | } |
| 9109 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9110 | static void intel_setup_outputs(struct drm_device *dev) |
| 9111 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 9112 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 9113 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 9114 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9115 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 9116 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9117 | |
Paulo Zanoni | c40c0f5 | 2013-04-12 18:16:53 -0300 | [diff] [blame] | 9118 | if (!IS_ULT(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 9119 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 9120 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 9121 | if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 9122 | int found; |
| 9123 | |
| 9124 | /* Haswell uses DDI functions to detect digital outputs */ |
| 9125 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
| 9126 | /* DDI A only supports eDP */ |
| 9127 | if (found) |
| 9128 | intel_ddi_init(dev, PORT_A); |
| 9129 | |
| 9130 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 9131 | * register */ |
| 9132 | found = I915_READ(SFUSE_STRAP); |
| 9133 | |
| 9134 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 9135 | intel_ddi_init(dev, PORT_B); |
| 9136 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 9137 | intel_ddi_init(dev, PORT_C); |
| 9138 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 9139 | intel_ddi_init(dev, PORT_D); |
| 9140 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 9141 | int found; |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 9142 | dpd_is_edp = intel_dpd_is_edp(dev); |
| 9143 | |
| 9144 | if (has_edp_a(dev)) |
| 9145 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 9146 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 9147 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 9148 | /* PCH SDVOB multiplex with HDMIB */ |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 9149 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 9150 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9151 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 9152 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 9153 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 9154 | } |
| 9155 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 9156 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9157 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 9158 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 9159 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9160 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 9161 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 9162 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 9163 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 9164 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 9165 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 9166 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 9167 | } else if (IS_VALLEYVIEW(dev)) { |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 9168 | /* Check for built-in panel first. Shares lanes with HDMI on SDVOC */ |
Ville Syrjälä | 67cfc20 | 2013-01-25 21:44:44 +0200 | [diff] [blame] | 9169 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED) |
| 9170 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 9171 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 9172 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) { |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9173 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
| 9174 | PORT_B); |
Ville Syrjälä | 67cfc20 | 2013-01-25 21:44:44 +0200 | [diff] [blame] | 9175 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED) |
| 9176 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 9177 | } |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 9178 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 9179 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 9180 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9181 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 9182 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9183 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 9184 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 9185 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9186 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 9187 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 9188 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 9189 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 9190 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 9191 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 9192 | |
| 9193 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 9194 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9195 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 9196 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9197 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 9198 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 9199 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9200 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 9201 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 9202 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 9203 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 9204 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 9205 | } |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 9206 | if (SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 9207 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 9208 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 9209 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 9210 | if (SUPPORTS_INTEGRATED_DP(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 9211 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 9212 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 9213 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9214 | intel_dvo_init(dev); |
| 9215 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 9216 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9217 | intel_tv_init(dev); |
| 9218 | |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 9219 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, base.head) { |
| 9220 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 9221 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 9222 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9223 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 9224 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 9225 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 9226 | |
| 9227 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9228 | } |
| 9229 | |
| 9230 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 9231 | { |
| 9232 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9233 | |
| 9234 | drm_framebuffer_cleanup(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9235 | drm_gem_object_unreference_unlocked(&intel_fb->obj->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9236 | |
| 9237 | kfree(intel_fb); |
| 9238 | } |
| 9239 | |
| 9240 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9241 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9242 | unsigned int *handle) |
| 9243 | { |
| 9244 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9245 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9246 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9247 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9248 | } |
| 9249 | |
| 9250 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 9251 | .destroy = intel_user_framebuffer_destroy, |
| 9252 | .create_handle = intel_user_framebuffer_create_handle, |
| 9253 | }; |
| 9254 | |
Dave Airlie | 3865167 | 2010-03-30 05:34:13 +0000 | [diff] [blame] | 9255 | int intel_framebuffer_init(struct drm_device *dev, |
| 9256 | struct intel_framebuffer *intel_fb, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 9257 | struct drm_mode_fb_cmd2 *mode_cmd, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9258 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9259 | { |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 9260 | int pitch_limit; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9261 | int ret; |
| 9262 | |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9263 | if (obj->tiling_mode == I915_TILING_Y) { |
| 9264 | DRM_DEBUG("hardware does not support tiling Y\n"); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 9265 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9266 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 9267 | |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9268 | if (mode_cmd->pitches[0] & 63) { |
| 9269 | DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n", |
| 9270 | mode_cmd->pitches[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 9271 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9272 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 9273 | |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 9274 | if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) { |
| 9275 | pitch_limit = 32*1024; |
| 9276 | } else if (INTEL_INFO(dev)->gen >= 4) { |
| 9277 | if (obj->tiling_mode) |
| 9278 | pitch_limit = 16*1024; |
| 9279 | else |
| 9280 | pitch_limit = 32*1024; |
| 9281 | } else if (INTEL_INFO(dev)->gen >= 3) { |
| 9282 | if (obj->tiling_mode) |
| 9283 | pitch_limit = 8*1024; |
| 9284 | else |
| 9285 | pitch_limit = 16*1024; |
| 9286 | } else |
| 9287 | /* XXX DSPC is limited to 4k tiled */ |
| 9288 | pitch_limit = 8*1024; |
| 9289 | |
| 9290 | if (mode_cmd->pitches[0] > pitch_limit) { |
| 9291 | DRM_DEBUG("%s pitch (%d) must be at less than %d\n", |
| 9292 | obj->tiling_mode ? "tiled" : "linear", |
| 9293 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 9294 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9295 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 9296 | |
| 9297 | if (obj->tiling_mode != I915_TILING_NONE && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9298 | mode_cmd->pitches[0] != obj->stride) { |
| 9299 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 9300 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 9301 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9302 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 9303 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 9304 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 9305 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 9306 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 9307 | case DRM_FORMAT_RGB565: |
| 9308 | case DRM_FORMAT_XRGB8888: |
| 9309 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 9310 | break; |
| 9311 | case DRM_FORMAT_XRGB1555: |
| 9312 | case DRM_FORMAT_ARGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9313 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 9314 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 9315 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 9316 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9317 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 9318 | break; |
| 9319 | case DRM_FORMAT_XBGR8888: |
| 9320 | case DRM_FORMAT_ABGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 9321 | case DRM_FORMAT_XRGB2101010: |
| 9322 | case DRM_FORMAT_ARGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 9323 | case DRM_FORMAT_XBGR2101010: |
| 9324 | case DRM_FORMAT_ABGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9325 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 9326 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 9327 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 9328 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9329 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 9330 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 9331 | case DRM_FORMAT_YUYV: |
| 9332 | case DRM_FORMAT_UYVY: |
| 9333 | case DRM_FORMAT_YVYU: |
| 9334 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9335 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 9336 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 9337 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 9338 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 9339 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 9340 | break; |
| 9341 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 9342 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 9343 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 9344 | return -EINVAL; |
| 9345 | } |
| 9346 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 9347 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 9348 | if (mode_cmd->offsets[0] != 0) |
| 9349 | return -EINVAL; |
| 9350 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 9351 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 9352 | intel_fb->obj = obj; |
| 9353 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9354 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 9355 | if (ret) { |
| 9356 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 9357 | return ret; |
| 9358 | } |
| 9359 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9360 | return 0; |
| 9361 | } |
| 9362 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9363 | static struct drm_framebuffer * |
| 9364 | intel_user_framebuffer_create(struct drm_device *dev, |
| 9365 | struct drm_file *filp, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 9366 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9367 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9368 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9369 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 9370 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
| 9371 | mode_cmd->handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 9372 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 9373 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9374 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9375 | return intel_framebuffer_create(dev, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9376 | } |
| 9377 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9378 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9379 | .fb_create = intel_user_framebuffer_create, |
Dave Airlie | eb1f8e4 | 2010-05-07 06:42:51 +0000 | [diff] [blame] | 9380 | .output_poll_changed = intel_fb_output_poll_changed, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9381 | }; |
| 9382 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 9383 | /* Set up chip specific display functions */ |
| 9384 | static void intel_init_display(struct drm_device *dev) |
| 9385 | { |
| 9386 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9387 | |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 9388 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
| 9389 | dev_priv->display.find_dpll = g4x_find_best_dpll; |
| 9390 | else if (IS_VALLEYVIEW(dev)) |
| 9391 | dev_priv->display.find_dpll = vlv_find_best_dpll; |
| 9392 | else if (IS_PINEVIEW(dev)) |
| 9393 | dev_priv->display.find_dpll = pnv_find_best_dpll; |
| 9394 | else |
| 9395 | dev_priv->display.find_dpll = i9xx_find_best_dpll; |
| 9396 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 9397 | if (HAS_DDI(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9398 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9399 | dev_priv->display.crtc_mode_set = haswell_crtc_mode_set; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 9400 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 9401 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 9402 | dev_priv->display.off = haswell_crtc_off; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 9403 | dev_priv->display.update_plane = ironlake_update_plane; |
| 9404 | } else if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9405 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9406 | dev_priv->display.get_clock = ironlake_crtc_clock_get; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 9407 | dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 9408 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 9409 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 9410 | dev_priv->display.off = ironlake_crtc_off; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 9411 | dev_priv->display.update_plane = ironlake_update_plane; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 9412 | } else if (IS_VALLEYVIEW(dev)) { |
| 9413 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9414 | dev_priv->display.get_clock = i9xx_crtc_clock_get; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 9415 | dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; |
| 9416 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 9417 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 9418 | dev_priv->display.off = i9xx_crtc_off; |
| 9419 | dev_priv->display.update_plane = i9xx_update_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 9420 | } else { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9421 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9422 | dev_priv->display.get_clock = i9xx_crtc_clock_get; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 9423 | dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 9424 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 9425 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 9426 | dev_priv->display.off = i9xx_crtc_off; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 9427 | dev_priv->display.update_plane = i9xx_update_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 9428 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 9429 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 9430 | /* Returns the core display clock speed */ |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 9431 | if (IS_VALLEYVIEW(dev)) |
| 9432 | dev_priv->display.get_display_clock_speed = |
| 9433 | valleyview_get_display_clock_speed; |
| 9434 | else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev))) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 9435 | dev_priv->display.get_display_clock_speed = |
| 9436 | i945_get_display_clock_speed; |
| 9437 | else if (IS_I915G(dev)) |
| 9438 | dev_priv->display.get_display_clock_speed = |
| 9439 | i915_get_display_clock_speed; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 9440 | else if (IS_I945GM(dev) || IS_845G(dev) || IS_PINEVIEW_M(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 9441 | dev_priv->display.get_display_clock_speed = |
| 9442 | i9xx_misc_get_display_clock_speed; |
| 9443 | else if (IS_I915GM(dev)) |
| 9444 | dev_priv->display.get_display_clock_speed = |
| 9445 | i915gm_get_display_clock_speed; |
| 9446 | else if (IS_I865G(dev)) |
| 9447 | dev_priv->display.get_display_clock_speed = |
| 9448 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 9449 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 9450 | dev_priv->display.get_display_clock_speed = |
| 9451 | i855_get_display_clock_speed; |
| 9452 | else /* 852, 830 */ |
| 9453 | dev_priv->display.get_display_clock_speed = |
| 9454 | i830_get_display_clock_speed; |
| 9455 | |
Zhenyu Wang | 7f8a856 | 2010-04-01 13:07:53 +0800 | [diff] [blame] | 9456 | if (HAS_PCH_SPLIT(dev)) { |
Chris Wilson | f00a3dd | 2010-10-21 14:57:17 +0100 | [diff] [blame] | 9457 | if (IS_GEN5(dev)) { |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 9458 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 9459 | dev_priv->display.write_eld = ironlake_write_eld; |
Yuanhan Liu | 1398261 | 2010-12-15 15:42:31 +0800 | [diff] [blame] | 9460 | } else if (IS_GEN6(dev)) { |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 9461 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 9462 | dev_priv->display.write_eld = ironlake_write_eld; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 9463 | } else if (IS_IVYBRIDGE(dev)) { |
| 9464 | /* FIXME: detect B0+ stepping and use auto training */ |
| 9465 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 9466 | dev_priv->display.write_eld = ironlake_write_eld; |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 9467 | dev_priv->display.modeset_global_resources = |
| 9468 | ivb_modeset_global_resources; |
Eugeni Dodonov | c82e4d2 | 2012-05-09 15:37:21 -0300 | [diff] [blame] | 9469 | } else if (IS_HASWELL(dev)) { |
| 9470 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 9471 | dev_priv->display.write_eld = haswell_write_eld; |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 9472 | dev_priv->display.modeset_global_resources = |
| 9473 | haswell_modeset_global_resources; |
Paulo Zanoni | a0e63c2 | 2012-12-06 11:12:39 -0200 | [diff] [blame] | 9474 | } |
Jesse Barnes | 6067aae | 2011-04-28 15:04:31 -0700 | [diff] [blame] | 9475 | } else if (IS_G4X(dev)) { |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 9476 | dev_priv->display.write_eld = g4x_write_eld; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 9477 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9478 | |
| 9479 | /* Default just returns -ENODEV to indicate unsupported */ |
| 9480 | dev_priv->display.queue_flip = intel_default_queue_flip; |
| 9481 | |
| 9482 | switch (INTEL_INFO(dev)->gen) { |
| 9483 | case 2: |
| 9484 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 9485 | break; |
| 9486 | |
| 9487 | case 3: |
| 9488 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 9489 | break; |
| 9490 | |
| 9491 | case 4: |
| 9492 | case 5: |
| 9493 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 9494 | break; |
| 9495 | |
| 9496 | case 6: |
| 9497 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 9498 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9499 | case 7: |
| 9500 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 9501 | break; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9502 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 9503 | } |
| 9504 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9505 | /* |
| 9506 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 9507 | * resume, or other times. This quirk makes sure that's the case for |
| 9508 | * affected systems. |
| 9509 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 9510 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9511 | { |
| 9512 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9513 | |
| 9514 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 9515 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9516 | } |
| 9517 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 9518 | /* |
| 9519 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 9520 | */ |
| 9521 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 9522 | { |
| 9523 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9524 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 9525 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 9526 | } |
| 9527 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 9528 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 9529 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 9530 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 9531 | */ |
| 9532 | static void quirk_invert_brightness(struct drm_device *dev) |
| 9533 | { |
| 9534 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9535 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 9536 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9537 | } |
| 9538 | |
| 9539 | struct intel_quirk { |
| 9540 | int device; |
| 9541 | int subsystem_vendor; |
| 9542 | int subsystem_device; |
| 9543 | void (*hook)(struct drm_device *dev); |
| 9544 | }; |
| 9545 | |
Egbert Eich | 5f85f176 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 9546 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 9547 | struct intel_dmi_quirk { |
| 9548 | void (*hook)(struct drm_device *dev); |
| 9549 | const struct dmi_system_id (*dmi_id_list)[]; |
| 9550 | }; |
| 9551 | |
| 9552 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 9553 | { |
| 9554 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 9555 | return 1; |
| 9556 | } |
| 9557 | |
| 9558 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 9559 | { |
| 9560 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 9561 | { |
| 9562 | .callback = intel_dmi_reverse_brightness, |
| 9563 | .ident = "NCR Corporation", |
| 9564 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 9565 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 9566 | }, |
| 9567 | }, |
| 9568 | { } /* terminating entry */ |
| 9569 | }, |
| 9570 | .hook = quirk_invert_brightness, |
| 9571 | }, |
| 9572 | }; |
| 9573 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 9574 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9575 | /* HP Mini needs pipe A force quirk (LP: #322104) */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 9576 | { 0x27ae, 0x103c, 0x361a, quirk_pipea_force }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9577 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9578 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 9579 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 9580 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9581 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 9582 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 9583 | |
Daniel Vetter | ccd0d36 | 2012-10-10 23:13:59 +0200 | [diff] [blame] | 9584 | /* 830/845 need to leave pipe A & dpll A up */ |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9585 | { 0x2562, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
Daniel Vetter | dcdaed6 | 2012-08-12 21:19:34 +0200 | [diff] [blame] | 9586 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 9587 | |
| 9588 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 9589 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 9590 | |
| 9591 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 9592 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 9593 | |
| 9594 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 9595 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
Jani Nikula | 1ffff60 | 2013-01-22 12:50:34 +0200 | [diff] [blame] | 9596 | |
| 9597 | /* Acer/eMachines G725 */ |
| 9598 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
Jani Nikula | 01e3a8f | 2013-01-22 12:50:35 +0200 | [diff] [blame] | 9599 | |
| 9600 | /* Acer/eMachines e725 */ |
| 9601 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
Jani Nikula | 5559eca | 2013-01-22 12:50:36 +0200 | [diff] [blame] | 9602 | |
| 9603 | /* Acer/Packard Bell NCL20 */ |
| 9604 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
Daniel Vetter | ac4199e | 2013-02-15 18:35:30 +0100 | [diff] [blame] | 9605 | |
| 9606 | /* Acer Aspire 4736Z */ |
| 9607 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9608 | }; |
| 9609 | |
| 9610 | static void intel_init_quirks(struct drm_device *dev) |
| 9611 | { |
| 9612 | struct pci_dev *d = dev->pdev; |
| 9613 | int i; |
| 9614 | |
| 9615 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 9616 | struct intel_quirk *q = &intel_quirks[i]; |
| 9617 | |
| 9618 | if (d->device == q->device && |
| 9619 | (d->subsystem_vendor == q->subsystem_vendor || |
| 9620 | q->subsystem_vendor == PCI_ANY_ID) && |
| 9621 | (d->subsystem_device == q->subsystem_device || |
| 9622 | q->subsystem_device == PCI_ANY_ID)) |
| 9623 | q->hook(dev); |
| 9624 | } |
Egbert Eich | 5f85f176 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 9625 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 9626 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 9627 | intel_dmi_quirks[i].hook(dev); |
| 9628 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9629 | } |
| 9630 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 9631 | /* Disable the VGA plane that we never use */ |
| 9632 | static void i915_disable_vga(struct drm_device *dev) |
| 9633 | { |
| 9634 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9635 | u8 sr1; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 9636 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 9637 | |
| 9638 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 9639 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 9640 | sr1 = inb(VGA_SR_DATA); |
| 9641 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 9642 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 9643 | udelay(300); |
| 9644 | |
| 9645 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
| 9646 | POSTING_READ(vga_reg); |
| 9647 | } |
| 9648 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 9649 | void intel_modeset_init_hw(struct drm_device *dev) |
| 9650 | { |
Paulo Zanoni | fa42e23 | 2013-01-25 16:59:11 -0200 | [diff] [blame] | 9651 | intel_init_power_well(dev); |
Eugeni Dodonov | 0232e92 | 2012-07-06 15:42:36 -0300 | [diff] [blame] | 9652 | |
Eugeni Dodonov | a8f78b5 | 2012-06-28 15:55:35 -0300 | [diff] [blame] | 9653 | intel_prepare_ddi(dev); |
| 9654 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 9655 | intel_init_clock_gating(dev); |
| 9656 | |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 9657 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 9658 | intel_enable_gt_powersave(dev); |
Daniel Vetter | 79f5b2c | 2012-06-24 16:42:33 +0200 | [diff] [blame] | 9659 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 9660 | } |
| 9661 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 9662 | void intel_modeset_suspend_hw(struct drm_device *dev) |
| 9663 | { |
| 9664 | intel_suspend_hw(dev); |
| 9665 | } |
| 9666 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9667 | void intel_modeset_init(struct drm_device *dev) |
| 9668 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9669 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 9670 | int i, j, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9671 | |
| 9672 | drm_mode_config_init(dev); |
| 9673 | |
| 9674 | dev->mode_config.min_width = 0; |
| 9675 | dev->mode_config.min_height = 0; |
| 9676 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 9677 | dev->mode_config.preferred_depth = 24; |
| 9678 | dev->mode_config.prefer_shadow = 1; |
| 9679 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 9680 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9681 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 9682 | intel_init_quirks(dev); |
| 9683 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 9684 | intel_init_pm(dev); |
| 9685 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 9686 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 9687 | return; |
| 9688 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 9689 | intel_init_display(dev); |
| 9690 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 9691 | if (IS_GEN2(dev)) { |
| 9692 | dev->mode_config.max_width = 2048; |
| 9693 | dev->mode_config.max_height = 2048; |
| 9694 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 9695 | dev->mode_config.max_width = 4096; |
| 9696 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9697 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 9698 | dev->mode_config.max_width = 8192; |
| 9699 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9700 | } |
Ben Widawsky | 5d4545a | 2013-01-17 12:45:15 -0800 | [diff] [blame] | 9701 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9702 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 9703 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 9704 | INTEL_INFO(dev)->num_pipes, |
| 9705 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9706 | |
Damien Lespiau | 08e2a7d | 2013-07-11 20:10:54 +0100 | [diff] [blame] | 9707 | for_each_pipe(i) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9708 | intel_crtc_init(dev, i); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 9709 | for (j = 0; j < dev_priv->num_plane; j++) { |
| 9710 | ret = intel_plane_init(dev, i, j); |
| 9711 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 9712 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
| 9713 | pipe_name(i), sprite_name(i, j), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 9714 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9715 | } |
| 9716 | |
Paulo Zanoni | 79f689a | 2012-10-05 12:05:52 -0300 | [diff] [blame] | 9717 | intel_cpu_pll_init(dev); |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 9718 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 9719 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 9720 | /* Just disable it once at startup */ |
| 9721 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9722 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 9723 | |
| 9724 | /* Just in case the BIOS is doing something questionable. */ |
| 9725 | intel_disable_fbc(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 9726 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 9727 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9728 | static void |
| 9729 | intel_connector_break_all_links(struct intel_connector *connector) |
| 9730 | { |
| 9731 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 9732 | connector->base.encoder = NULL; |
| 9733 | connector->encoder->connectors_active = false; |
| 9734 | connector->encoder->base.crtc = NULL; |
| 9735 | } |
| 9736 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 9737 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 9738 | { |
| 9739 | struct intel_connector *connector; |
| 9740 | struct drm_connector *crt = NULL; |
| 9741 | struct intel_load_detect_pipe load_detect_temp; |
| 9742 | |
| 9743 | /* We can't just switch on the pipe A, we need to set things up with a |
| 9744 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 9745 | * by enabling the load detect pipe once. */ |
| 9746 | list_for_each_entry(connector, |
| 9747 | &dev->mode_config.connector_list, |
| 9748 | base.head) { |
| 9749 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 9750 | crt = &connector->base; |
| 9751 | break; |
| 9752 | } |
| 9753 | } |
| 9754 | |
| 9755 | if (!crt) |
| 9756 | return; |
| 9757 | |
| 9758 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp)) |
| 9759 | intel_release_load_detect_pipe(crt, &load_detect_temp); |
| 9760 | |
| 9761 | |
| 9762 | } |
| 9763 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 9764 | static bool |
| 9765 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 9766 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 9767 | struct drm_device *dev = crtc->base.dev; |
| 9768 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 9769 | u32 reg, val; |
| 9770 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 9771 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 9772 | return true; |
| 9773 | |
| 9774 | reg = DSPCNTR(!crtc->plane); |
| 9775 | val = I915_READ(reg); |
| 9776 | |
| 9777 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 9778 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 9779 | return false; |
| 9780 | |
| 9781 | return true; |
| 9782 | } |
| 9783 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9784 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 9785 | { |
| 9786 | struct drm_device *dev = crtc->base.dev; |
| 9787 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 9788 | u32 reg; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9789 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9790 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 9791 | reg = PIPECONF(crtc->config.cpu_transcoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9792 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 9793 | |
| 9794 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 9795 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 9796 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 9797 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9798 | struct intel_connector *connector; |
| 9799 | bool plane; |
| 9800 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9801 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 9802 | crtc->base.base.id); |
| 9803 | |
| 9804 | /* Pipe has the wrong plane attached and the plane is active. |
| 9805 | * Temporarily change the plane mapping and disable everything |
| 9806 | * ... */ |
| 9807 | plane = crtc->plane; |
| 9808 | crtc->plane = !plane; |
| 9809 | dev_priv->display.crtc_disable(&crtc->base); |
| 9810 | crtc->plane = plane; |
| 9811 | |
| 9812 | /* ... and break all links. */ |
| 9813 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 9814 | base.head) { |
| 9815 | if (connector->encoder->base.crtc != &crtc->base) |
| 9816 | continue; |
| 9817 | |
| 9818 | intel_connector_break_all_links(connector); |
| 9819 | } |
| 9820 | |
| 9821 | WARN_ON(crtc->active); |
| 9822 | crtc->base.enabled = false; |
| 9823 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9824 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 9825 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 9826 | crtc->pipe == PIPE_A && !crtc->active) { |
| 9827 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 9828 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 9829 | * call below we restore the pipe to the right state, but leave |
| 9830 | * the required bits on. */ |
| 9831 | intel_enable_pipe_a(dev); |
| 9832 | } |
| 9833 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9834 | /* Adjust the state of the output pipe according to whether we |
| 9835 | * have active connectors/encoders. */ |
| 9836 | intel_crtc_update_dpms(&crtc->base); |
| 9837 | |
| 9838 | if (crtc->active != crtc->base.enabled) { |
| 9839 | struct intel_encoder *encoder; |
| 9840 | |
| 9841 | /* This can happen either due to bugs in the get_hw_state |
| 9842 | * functions or because the pipe is force-enabled due to the |
| 9843 | * pipe A quirk. */ |
| 9844 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", |
| 9845 | crtc->base.base.id, |
| 9846 | crtc->base.enabled ? "enabled" : "disabled", |
| 9847 | crtc->active ? "enabled" : "disabled"); |
| 9848 | |
| 9849 | crtc->base.enabled = crtc->active; |
| 9850 | |
| 9851 | /* Because we only establish the connector -> encoder -> |
| 9852 | * crtc links if something is active, this means the |
| 9853 | * crtc is now deactivated. Break the links. connector |
| 9854 | * -> encoder links are only establish when things are |
| 9855 | * actually up, hence no need to break them. */ |
| 9856 | WARN_ON(crtc->active); |
| 9857 | |
| 9858 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
| 9859 | WARN_ON(encoder->connectors_active); |
| 9860 | encoder->base.crtc = NULL; |
| 9861 | } |
| 9862 | } |
| 9863 | } |
| 9864 | |
| 9865 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 9866 | { |
| 9867 | struct intel_connector *connector; |
| 9868 | struct drm_device *dev = encoder->base.dev; |
| 9869 | |
| 9870 | /* We need to check both for a crtc link (meaning that the |
| 9871 | * encoder is active and trying to read from a pipe) and the |
| 9872 | * pipe itself being active. */ |
| 9873 | bool has_active_crtc = encoder->base.crtc && |
| 9874 | to_intel_crtc(encoder->base.crtc)->active; |
| 9875 | |
| 9876 | if (encoder->connectors_active && !has_active_crtc) { |
| 9877 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 9878 | encoder->base.base.id, |
| 9879 | drm_get_encoder_name(&encoder->base)); |
| 9880 | |
| 9881 | /* Connector is active, but has no active pipe. This is |
| 9882 | * fallout from our resume register restoring. Disable |
| 9883 | * the encoder manually again. */ |
| 9884 | if (encoder->base.crtc) { |
| 9885 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 9886 | encoder->base.base.id, |
| 9887 | drm_get_encoder_name(&encoder->base)); |
| 9888 | encoder->disable(encoder); |
| 9889 | } |
| 9890 | |
| 9891 | /* Inconsistent output/port/pipe state happens presumably due to |
| 9892 | * a bug in one of the get_hw_state functions. Or someplace else |
| 9893 | * in our code, like the register restore mess on resume. Clamp |
| 9894 | * things to off as a safer default. */ |
| 9895 | list_for_each_entry(connector, |
| 9896 | &dev->mode_config.connector_list, |
| 9897 | base.head) { |
| 9898 | if (connector->encoder != encoder) |
| 9899 | continue; |
| 9900 | |
| 9901 | intel_connector_break_all_links(connector); |
| 9902 | } |
| 9903 | } |
| 9904 | /* Enabled encoders without active connectors will be fixed in |
| 9905 | * the crtc fixup. */ |
| 9906 | } |
| 9907 | |
Daniel Vetter | 44cec74 | 2013-01-25 17:53:21 +0100 | [diff] [blame] | 9908 | void i915_redisable_vga(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 9909 | { |
| 9910 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 9911 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 9912 | |
| 9913 | if (I915_READ(vga_reg) != VGA_DISP_DISABLE) { |
| 9914 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
Ville Syrjälä | 209d521 | 2013-01-25 21:44:48 +0200 | [diff] [blame] | 9915 | i915_disable_vga(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 9916 | } |
| 9917 | } |
| 9918 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 9919 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9920 | { |
| 9921 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9922 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9923 | struct intel_crtc *crtc; |
| 9924 | struct intel_encoder *encoder; |
| 9925 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 9926 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9927 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9928 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, |
| 9929 | base.head) { |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 9930 | memset(&crtc->config, 0, sizeof(crtc->config)); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 9931 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 9932 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
| 9933 | &crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9934 | |
| 9935 | crtc->base.enabled = crtc->active; |
| 9936 | |
| 9937 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 9938 | crtc->base.base.id, |
| 9939 | crtc->active ? "enabled" : "disabled"); |
| 9940 | } |
| 9941 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 9942 | /* FIXME: Smash this into the new shared dpll infrastructure. */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 9943 | if (HAS_DDI(dev)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 9944 | intel_ddi_setup_hw_pll_state(dev); |
| 9945 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 9946 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 9947 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 9948 | |
| 9949 | pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state); |
| 9950 | pll->active = 0; |
| 9951 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, |
| 9952 | base.head) { |
| 9953 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 9954 | pll->active++; |
| 9955 | } |
| 9956 | pll->refcount = pll->active; |
| 9957 | |
| 9958 | DRM_DEBUG_KMS("%s hw state readout: refcount %i\n", |
| 9959 | pll->name, pll->refcount); |
| 9960 | } |
| 9961 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9962 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 9963 | base.head) { |
| 9964 | pipe = 0; |
| 9965 | |
| 9966 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 9967 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 9968 | encoder->base.crtc = &crtc->base; |
Jesse Barnes | 510d5f2 | 2013-07-01 15:50:17 -0700 | [diff] [blame] | 9969 | if (encoder->get_config) |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 9970 | encoder->get_config(encoder, &crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9971 | } else { |
| 9972 | encoder->base.crtc = NULL; |
| 9973 | } |
| 9974 | |
| 9975 | encoder->connectors_active = false; |
| 9976 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe=%i\n", |
| 9977 | encoder->base.base.id, |
| 9978 | drm_get_encoder_name(&encoder->base), |
| 9979 | encoder->base.crtc ? "enabled" : "disabled", |
| 9980 | pipe); |
| 9981 | } |
| 9982 | |
Jesse Barnes | 510d5f2 | 2013-07-01 15:50:17 -0700 | [diff] [blame] | 9983 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, |
| 9984 | base.head) { |
| 9985 | if (!crtc->active) |
| 9986 | continue; |
| 9987 | if (dev_priv->display.get_clock) |
| 9988 | dev_priv->display.get_clock(crtc, |
| 9989 | &crtc->config); |
| 9990 | } |
| 9991 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 9992 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 9993 | base.head) { |
| 9994 | if (connector->get_hw_state(connector)) { |
| 9995 | connector->base.dpms = DRM_MODE_DPMS_ON; |
| 9996 | connector->encoder->connectors_active = true; |
| 9997 | connector->base.encoder = &connector->encoder->base; |
| 9998 | } else { |
| 9999 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 10000 | connector->base.encoder = NULL; |
| 10001 | } |
| 10002 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 10003 | connector->base.base.id, |
| 10004 | drm_get_connector_name(&connector->base), |
| 10005 | connector->base.encoder ? "enabled" : "disabled"); |
| 10006 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 10007 | } |
| 10008 | |
| 10009 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm |
| 10010 | * and i915 state tracking structures. */ |
| 10011 | void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 10012 | bool force_restore) |
| 10013 | { |
| 10014 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10015 | enum pipe pipe; |
| 10016 | struct drm_plane *plane; |
| 10017 | struct intel_crtc *crtc; |
| 10018 | struct intel_encoder *encoder; |
| 10019 | |
| 10020 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 10021 | |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 10022 | /* |
| 10023 | * Now that we have the config, copy it to each CRTC struct |
| 10024 | * Note that this could go away if we move to using crtc_config |
| 10025 | * checking everywhere. |
| 10026 | */ |
| 10027 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, |
| 10028 | base.head) { |
| 10029 | if (crtc->active && i915_fastboot) { |
| 10030 | intel_crtc_mode_from_pipe_config(crtc, &crtc->config); |
| 10031 | |
| 10032 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
| 10033 | crtc->base.base.id); |
| 10034 | drm_mode_debug_printmodeline(&crtc->base.mode); |
| 10035 | } |
| 10036 | } |
| 10037 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 10038 | /* HW state is read out, now we need to sanitize this mess. */ |
| 10039 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, |
| 10040 | base.head) { |
| 10041 | intel_sanitize_encoder(encoder); |
| 10042 | } |
| 10043 | |
| 10044 | for_each_pipe(pipe) { |
| 10045 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 10046 | intel_sanitize_crtc(crtc); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10047 | intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 10048 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10049 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 10050 | if (force_restore) { |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 10051 | /* |
| 10052 | * We need to use raw interfaces for restoring state to avoid |
| 10053 | * checking (bogus) intermediate states. |
| 10054 | */ |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 10055 | for_each_pipe(pipe) { |
Jesse Barnes | b5644d0 | 2013-03-26 13:25:27 -0700 | [diff] [blame] | 10056 | struct drm_crtc *crtc = |
| 10057 | dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 10058 | |
| 10059 | __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, |
| 10060 | crtc->fb); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 10061 | } |
Jesse Barnes | b5644d0 | 2013-03-26 13:25:27 -0700 | [diff] [blame] | 10062 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) |
| 10063 | intel_plane_restore(plane); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 10064 | |
| 10065 | i915_redisable_vga(dev); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 10066 | } else { |
| 10067 | intel_modeset_update_staged_output_state(dev); |
| 10068 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10069 | |
| 10070 | intel_modeset_check_state(dev); |
Daniel Vetter | 2e93889 | 2012-10-11 20:08:24 +0200 | [diff] [blame] | 10071 | |
| 10072 | drm_mode_config_reset(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 10073 | } |
| 10074 | |
| 10075 | void intel_modeset_gem_init(struct drm_device *dev) |
| 10076 | { |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 10077 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 10078 | |
| 10079 | intel_setup_overlay(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 10080 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 10081 | intel_modeset_setup_hw_state(dev, false); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10082 | } |
| 10083 | |
| 10084 | void intel_modeset_cleanup(struct drm_device *dev) |
| 10085 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10086 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10087 | struct drm_crtc *crtc; |
| 10088 | struct intel_crtc *intel_crtc; |
| 10089 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 10090 | /* |
| 10091 | * Interrupts and polling as the first thing to avoid creating havoc. |
| 10092 | * Too much stuff here (turning of rps, connectors, ...) would |
| 10093 | * experience fancy races otherwise. |
| 10094 | */ |
| 10095 | drm_irq_uninstall(dev); |
| 10096 | cancel_work_sync(&dev_priv->hotplug_work); |
| 10097 | /* |
| 10098 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 10099 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 10100 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 10101 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 10102 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10103 | mutex_lock(&dev->struct_mutex); |
| 10104 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 10105 | intel_unregister_dsm_handler(); |
| 10106 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10107 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 10108 | /* Skip inactive CRTCs */ |
| 10109 | if (!crtc->fb) |
| 10110 | continue; |
| 10111 | |
| 10112 | intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3dec009 | 2010-08-20 21:40:52 +0200 | [diff] [blame] | 10113 | intel_increase_pllclock(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 10114 | } |
| 10115 | |
Chris Wilson | 973d04f | 2011-07-08 12:22:37 +0100 | [diff] [blame] | 10116 | intel_disable_fbc(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 10117 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 10118 | intel_disable_gt_powersave(dev); |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 10119 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 10120 | ironlake_teardown_rc6(dev); |
| 10121 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 10122 | mutex_unlock(&dev->struct_mutex); |
| 10123 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 10124 | /* flush any delayed tasks or pending work */ |
| 10125 | flush_scheduled_work(); |
| 10126 | |
Jani Nikula | dc652f9 | 2013-04-12 15:18:38 +0300 | [diff] [blame] | 10127 | /* destroy backlight, if any, before the connectors */ |
| 10128 | intel_panel_destroy_backlight(dev); |
| 10129 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10130 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 10131 | |
| 10132 | intel_cleanup_overlay(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10133 | } |
| 10134 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 10135 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 10136 | * Return which encoder is currently attached for connector. |
| 10137 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 10138 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10139 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 10140 | return &intel_attached_encoder(connector)->base; |
| 10141 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10142 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 10143 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 10144 | struct intel_encoder *encoder) |
| 10145 | { |
| 10146 | connector->encoder = encoder; |
| 10147 | drm_mode_connector_attach_encoder(&connector->base, |
| 10148 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 10149 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 10150 | |
| 10151 | /* |
| 10152 | * set vga decode state - true == enable VGA decode |
| 10153 | */ |
| 10154 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 10155 | { |
| 10156 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10157 | u16 gmch_ctrl; |
| 10158 | |
| 10159 | pci_read_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, &gmch_ctrl); |
| 10160 | if (state) |
| 10161 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 10162 | else |
| 10163 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
| 10164 | pci_write_config_word(dev_priv->bridge_dev, INTEL_GMCH_CTRL, gmch_ctrl); |
| 10165 | return 0; |
| 10166 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10167 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10168 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 10169 | |
| 10170 | u32 power_well_driver; |
| 10171 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10172 | struct intel_cursor_error_state { |
| 10173 | u32 control; |
| 10174 | u32 position; |
| 10175 | u32 base; |
| 10176 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 10177 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10178 | |
| 10179 | struct intel_pipe_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 10180 | enum transcoder cpu_transcoder; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10181 | u32 conf; |
| 10182 | u32 source; |
| 10183 | |
| 10184 | u32 htotal; |
| 10185 | u32 hblank; |
| 10186 | u32 hsync; |
| 10187 | u32 vtotal; |
| 10188 | u32 vblank; |
| 10189 | u32 vsync; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 10190 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10191 | |
| 10192 | struct intel_plane_error_state { |
| 10193 | u32 control; |
| 10194 | u32 stride; |
| 10195 | u32 size; |
| 10196 | u32 pos; |
| 10197 | u32 addr; |
| 10198 | u32 surface; |
| 10199 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 10200 | } plane[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10201 | }; |
| 10202 | |
| 10203 | struct intel_display_error_state * |
| 10204 | intel_display_capture_error_state(struct drm_device *dev) |
| 10205 | { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 10206 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10207 | struct intel_display_error_state *error; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 10208 | enum transcoder cpu_transcoder; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10209 | int i; |
| 10210 | |
| 10211 | error = kmalloc(sizeof(*error), GFP_ATOMIC); |
| 10212 | if (error == NULL) |
| 10213 | return NULL; |
| 10214 | |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 10215 | if (HAS_POWER_WELL(dev)) |
| 10216 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 10217 | |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 10218 | for_each_pipe(i) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 10219 | cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, i); |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 10220 | error->pipe[i].cpu_transcoder = cpu_transcoder; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 10221 | |
Paulo Zanoni | a18c4c3 | 2013-03-06 20:03:12 -0300 | [diff] [blame] | 10222 | if (INTEL_INFO(dev)->gen <= 6 || IS_VALLEYVIEW(dev)) { |
| 10223 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 10224 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 10225 | error->cursor[i].base = I915_READ(CURBASE(i)); |
| 10226 | } else { |
| 10227 | error->cursor[i].control = I915_READ(CURCNTR_IVB(i)); |
| 10228 | error->cursor[i].position = I915_READ(CURPOS_IVB(i)); |
| 10229 | error->cursor[i].base = I915_READ(CURBASE_IVB(i)); |
| 10230 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10231 | |
| 10232 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 10233 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 10234 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 10235 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 10236 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 10237 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 10238 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 10239 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10240 | if (INTEL_INFO(dev)->gen >= 4) { |
| 10241 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 10242 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 10243 | } |
| 10244 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 10245 | error->pipe[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10246 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 10247 | error->pipe[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 10248 | error->pipe[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 10249 | error->pipe[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 10250 | error->pipe[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 10251 | error->pipe[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 10252 | error->pipe[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10253 | } |
| 10254 | |
Paulo Zanoni | 12d217c | 2013-05-03 12:15:38 -0300 | [diff] [blame] | 10255 | /* In the code above we read the registers without checking if the power |
| 10256 | * well was on, so here we have to clear the FPGA_DBG_RM_NOCLAIM bit to |
| 10257 | * prevent the next I915_WRITE from detecting it and printing an error |
| 10258 | * message. */ |
| 10259 | if (HAS_POWER_WELL(dev)) |
| 10260 | I915_WRITE_NOTRACE(FPGA_DBG, FPGA_DBG_RM_NOCLAIM); |
| 10261 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10262 | return error; |
| 10263 | } |
| 10264 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10265 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 10266 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10267 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10268 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10269 | struct drm_device *dev, |
| 10270 | struct intel_display_error_state *error) |
| 10271 | { |
| 10272 | int i; |
| 10273 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10274 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 10275 | if (HAS_POWER_WELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10276 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 10277 | error->power_well_driver); |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 10278 | for_each_pipe(i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10279 | err_printf(m, "Pipe [%d]:\n", i); |
| 10280 | err_printf(m, " CPU transcoder: %c\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 10281 | transcoder_name(error->pipe[i].cpu_transcoder)); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10282 | err_printf(m, " CONF: %08x\n", error->pipe[i].conf); |
| 10283 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
| 10284 | err_printf(m, " HTOTAL: %08x\n", error->pipe[i].htotal); |
| 10285 | err_printf(m, " HBLANK: %08x\n", error->pipe[i].hblank); |
| 10286 | err_printf(m, " HSYNC: %08x\n", error->pipe[i].hsync); |
| 10287 | err_printf(m, " VTOTAL: %08x\n", error->pipe[i].vtotal); |
| 10288 | err_printf(m, " VBLANK: %08x\n", error->pipe[i].vblank); |
| 10289 | err_printf(m, " VSYNC: %08x\n", error->pipe[i].vsync); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10290 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10291 | err_printf(m, "Plane [%d]:\n", i); |
| 10292 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 10293 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 10294 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10295 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 10296 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 10297 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 10298 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10299 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10300 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10301 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 10302 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10303 | } |
| 10304 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 10305 | err_printf(m, "Cursor [%d]:\n", i); |
| 10306 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 10307 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 10308 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 10309 | } |
| 10310 | } |