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> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 42 | #include <drm/drm_plane_helper.h> |
| 43 | #include <drm/drm_rect.h> |
Keith Packard | c0f372b3 | 2011-11-16 22:24:52 -0800 | [diff] [blame] | 44 | #include <linux/dma_remapping.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 45 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 46 | /* Primary plane formats supported by all gen */ |
| 47 | #define COMMON_PRIMARY_FORMATS \ |
| 48 | DRM_FORMAT_C8, \ |
| 49 | DRM_FORMAT_RGB565, \ |
| 50 | DRM_FORMAT_XRGB8888, \ |
| 51 | DRM_FORMAT_ARGB8888 |
| 52 | |
| 53 | /* Primary plane formats for gen <= 3 */ |
| 54 | static const uint32_t intel_primary_formats_gen2[] = { |
| 55 | COMMON_PRIMARY_FORMATS, |
| 56 | DRM_FORMAT_XRGB1555, |
| 57 | DRM_FORMAT_ARGB1555, |
| 58 | }; |
| 59 | |
| 60 | /* Primary plane formats for gen >= 4 */ |
| 61 | static const uint32_t intel_primary_formats_gen4[] = { |
| 62 | COMMON_PRIMARY_FORMATS, \ |
| 63 | DRM_FORMAT_XBGR8888, |
| 64 | DRM_FORMAT_ABGR8888, |
| 65 | DRM_FORMAT_XRGB2101010, |
| 66 | DRM_FORMAT_ARGB2101010, |
| 67 | DRM_FORMAT_XBGR2101010, |
| 68 | DRM_FORMAT_ABGR2101010, |
| 69 | }; |
| 70 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 71 | /* Cursor formats */ |
| 72 | static const uint32_t intel_cursor_formats[] = { |
| 73 | DRM_FORMAT_ARGB8888, |
| 74 | }; |
| 75 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 76 | #define DIV_ROUND_CLOSEST_ULL(ll, d) \ |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 77 | ({ unsigned long long _tmp = (ll)+(d)/2; do_div(_tmp, d); _tmp; }) |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 78 | |
Daniel Vetter | cc36513 | 2014-06-18 13:59:13 +0200 | [diff] [blame] | 79 | static void intel_increase_pllclock(struct drm_device *dev, |
| 80 | enum pipe pipe); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 81 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 82 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 83 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
| 84 | struct intel_crtc_config *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 85 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
| 86 | struct intel_crtc_config *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 87 | |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 88 | static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 89 | int x, int y, struct drm_framebuffer *old_fb); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 90 | static int intel_framebuffer_init(struct drm_device *dev, |
| 91 | struct intel_framebuffer *ifb, |
| 92 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 93 | struct drm_i915_gem_object *obj); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 94 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 95 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 96 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 97 | struct intel_link_m_n *m_n, |
| 98 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 99 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 100 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
| 101 | static void intel_set_pipe_csc(struct drm_crtc *crtc); |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 102 | static void vlv_prepare_pll(struct intel_crtc *crtc); |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 103 | static void chv_prepare_pll(struct intel_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 104 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 105 | static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe) |
| 106 | { |
| 107 | if (!connector->mst_port) |
| 108 | return connector->encoder; |
| 109 | else |
| 110 | return &connector->mst_port->mst_encoders[pipe]->base; |
| 111 | } |
| 112 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 113 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 114 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 115 | } intel_range_t; |
| 116 | |
| 117 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 118 | int dot_limit; |
| 119 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 120 | } intel_p2_t; |
| 121 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 122 | typedef struct intel_limit intel_limit_t; |
| 123 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 124 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 125 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 126 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 127 | |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 128 | int |
| 129 | intel_pch_rawclk(struct drm_device *dev) |
| 130 | { |
| 131 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 132 | |
| 133 | WARN_ON(!HAS_PCH_SPLIT(dev)); |
| 134 | |
| 135 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; |
| 136 | } |
| 137 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 138 | static inline u32 /* units of 100MHz */ |
| 139 | intel_fdi_link_freq(struct drm_device *dev) |
| 140 | { |
Chris Wilson | 8b99e68 | 2010-10-13 09:59:17 +0100 | [diff] [blame] | 141 | if (IS_GEN5(dev)) { |
| 142 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 143 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; |
| 144 | } else |
| 145 | return 27; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 146 | } |
| 147 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 148 | static const intel_limit_t intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 149 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 150 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 151 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 152 | .m = { .min = 96, .max = 140 }, |
| 153 | .m1 = { .min = 18, .max = 26 }, |
| 154 | .m2 = { .min = 6, .max = 16 }, |
| 155 | .p = { .min = 4, .max = 128 }, |
| 156 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 157 | .p2 = { .dot_limit = 165000, |
| 158 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 161 | static const intel_limit_t intel_limits_i8xx_dvo = { |
| 162 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 163 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 164 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 165 | .m = { .min = 96, .max = 140 }, |
| 166 | .m1 = { .min = 18, .max = 26 }, |
| 167 | .m2 = { .min = 6, .max = 16 }, |
| 168 | .p = { .min = 4, .max = 128 }, |
| 169 | .p1 = { .min = 2, .max = 33 }, |
| 170 | .p2 = { .dot_limit = 165000, |
| 171 | .p2_slow = 4, .p2_fast = 4 }, |
| 172 | }; |
| 173 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 174 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 175 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 176 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 177 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 178 | .m = { .min = 96, .max = 140 }, |
| 179 | .m1 = { .min = 18, .max = 26 }, |
| 180 | .m2 = { .min = 6, .max = 16 }, |
| 181 | .p = { .min = 4, .max = 128 }, |
| 182 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 183 | .p2 = { .dot_limit = 165000, |
| 184 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 185 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 186 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 187 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 188 | .dot = { .min = 20000, .max = 400000 }, |
| 189 | .vco = { .min = 1400000, .max = 2800000 }, |
| 190 | .n = { .min = 1, .max = 6 }, |
| 191 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 192 | .m1 = { .min = 8, .max = 18 }, |
| 193 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 194 | .p = { .min = 5, .max = 80 }, |
| 195 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 196 | .p2 = { .dot_limit = 200000, |
| 197 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 201 | .dot = { .min = 20000, .max = 400000 }, |
| 202 | .vco = { .min = 1400000, .max = 2800000 }, |
| 203 | .n = { .min = 1, .max = 6 }, |
| 204 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 205 | .m1 = { .min = 8, .max = 18 }, |
| 206 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 207 | .p = { .min = 7, .max = 98 }, |
| 208 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 209 | .p2 = { .dot_limit = 112000, |
| 210 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 211 | }; |
| 212 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 213 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 214 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 215 | .dot = { .min = 25000, .max = 270000 }, |
| 216 | .vco = { .min = 1750000, .max = 3500000}, |
| 217 | .n = { .min = 1, .max = 4 }, |
| 218 | .m = { .min = 104, .max = 138 }, |
| 219 | .m1 = { .min = 17, .max = 23 }, |
| 220 | .m2 = { .min = 5, .max = 11 }, |
| 221 | .p = { .min = 10, .max = 30 }, |
| 222 | .p1 = { .min = 1, .max = 3}, |
| 223 | .p2 = { .dot_limit = 270000, |
| 224 | .p2_slow = 10, |
| 225 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 226 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 230 | .dot = { .min = 22000, .max = 400000 }, |
| 231 | .vco = { .min = 1750000, .max = 3500000}, |
| 232 | .n = { .min = 1, .max = 4 }, |
| 233 | .m = { .min = 104, .max = 138 }, |
| 234 | .m1 = { .min = 16, .max = 23 }, |
| 235 | .m2 = { .min = 5, .max = 11 }, |
| 236 | .p = { .min = 5, .max = 80 }, |
| 237 | .p1 = { .min = 1, .max = 8}, |
| 238 | .p2 = { .dot_limit = 165000, |
| 239 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 240 | }; |
| 241 | |
| 242 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 243 | .dot = { .min = 20000, .max = 115000 }, |
| 244 | .vco = { .min = 1750000, .max = 3500000 }, |
| 245 | .n = { .min = 1, .max = 3 }, |
| 246 | .m = { .min = 104, .max = 138 }, |
| 247 | .m1 = { .min = 17, .max = 23 }, |
| 248 | .m2 = { .min = 5, .max = 11 }, |
| 249 | .p = { .min = 28, .max = 112 }, |
| 250 | .p1 = { .min = 2, .max = 8 }, |
| 251 | .p2 = { .dot_limit = 0, |
| 252 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 253 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
| 256 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 257 | .dot = { .min = 80000, .max = 224000 }, |
| 258 | .vco = { .min = 1750000, .max = 3500000 }, |
| 259 | .n = { .min = 1, .max = 3 }, |
| 260 | .m = { .min = 104, .max = 138 }, |
| 261 | .m1 = { .min = 17, .max = 23 }, |
| 262 | .m2 = { .min = 5, .max = 11 }, |
| 263 | .p = { .min = 14, .max = 42 }, |
| 264 | .p1 = { .min = 2, .max = 6 }, |
| 265 | .p2 = { .dot_limit = 0, |
| 266 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 267 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 268 | }; |
| 269 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 270 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 271 | .dot = { .min = 20000, .max = 400000}, |
| 272 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 273 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 274 | .n = { .min = 3, .max = 6 }, |
| 275 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 276 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 277 | .m1 = { .min = 0, .max = 0 }, |
| 278 | .m2 = { .min = 0, .max = 254 }, |
| 279 | .p = { .min = 5, .max = 80 }, |
| 280 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 281 | .p2 = { .dot_limit = 200000, |
| 282 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 283 | }; |
| 284 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 285 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 286 | .dot = { .min = 20000, .max = 400000 }, |
| 287 | .vco = { .min = 1700000, .max = 3500000 }, |
| 288 | .n = { .min = 3, .max = 6 }, |
| 289 | .m = { .min = 2, .max = 256 }, |
| 290 | .m1 = { .min = 0, .max = 0 }, |
| 291 | .m2 = { .min = 0, .max = 254 }, |
| 292 | .p = { .min = 7, .max = 112 }, |
| 293 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 294 | .p2 = { .dot_limit = 112000, |
| 295 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 296 | }; |
| 297 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 298 | /* Ironlake / Sandybridge |
| 299 | * |
| 300 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 301 | * the range value for them is (actual_value - 2). |
| 302 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 303 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 304 | .dot = { .min = 25000, .max = 350000 }, |
| 305 | .vco = { .min = 1760000, .max = 3510000 }, |
| 306 | .n = { .min = 1, .max = 5 }, |
| 307 | .m = { .min = 79, .max = 127 }, |
| 308 | .m1 = { .min = 12, .max = 22 }, |
| 309 | .m2 = { .min = 5, .max = 9 }, |
| 310 | .p = { .min = 5, .max = 80 }, |
| 311 | .p1 = { .min = 1, .max = 8 }, |
| 312 | .p2 = { .dot_limit = 225000, |
| 313 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 314 | }; |
| 315 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 316 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 317 | .dot = { .min = 25000, .max = 350000 }, |
| 318 | .vco = { .min = 1760000, .max = 3510000 }, |
| 319 | .n = { .min = 1, .max = 3 }, |
| 320 | .m = { .min = 79, .max = 118 }, |
| 321 | .m1 = { .min = 12, .max = 22 }, |
| 322 | .m2 = { .min = 5, .max = 9 }, |
| 323 | .p = { .min = 28, .max = 112 }, |
| 324 | .p1 = { .min = 2, .max = 8 }, |
| 325 | .p2 = { .dot_limit = 225000, |
| 326 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 330 | .dot = { .min = 25000, .max = 350000 }, |
| 331 | .vco = { .min = 1760000, .max = 3510000 }, |
| 332 | .n = { .min = 1, .max = 3 }, |
| 333 | .m = { .min = 79, .max = 127 }, |
| 334 | .m1 = { .min = 12, .max = 22 }, |
| 335 | .m2 = { .min = 5, .max = 9 }, |
| 336 | .p = { .min = 14, .max = 56 }, |
| 337 | .p1 = { .min = 2, .max = 8 }, |
| 338 | .p2 = { .dot_limit = 225000, |
| 339 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 340 | }; |
| 341 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 342 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 343 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 344 | .dot = { .min = 25000, .max = 350000 }, |
| 345 | .vco = { .min = 1760000, .max = 3510000 }, |
| 346 | .n = { .min = 1, .max = 2 }, |
| 347 | .m = { .min = 79, .max = 126 }, |
| 348 | .m1 = { .min = 12, .max = 22 }, |
| 349 | .m2 = { .min = 5, .max = 9 }, |
| 350 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 351 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 352 | .p2 = { .dot_limit = 225000, |
| 353 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 354 | }; |
| 355 | |
| 356 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 357 | .dot = { .min = 25000, .max = 350000 }, |
| 358 | .vco = { .min = 1760000, .max = 3510000 }, |
| 359 | .n = { .min = 1, .max = 3 }, |
| 360 | .m = { .min = 79, .max = 126 }, |
| 361 | .m1 = { .min = 12, .max = 22 }, |
| 362 | .m2 = { .min = 5, .max = 9 }, |
| 363 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 364 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 365 | .p2 = { .dot_limit = 225000, |
| 366 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 367 | }; |
| 368 | |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 369 | static const intel_limit_t intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 370 | /* |
| 371 | * These are the data rate limits (measured in fast clocks) |
| 372 | * since those are the strictest limits we have. The fast |
| 373 | * clock and actual rate limits are more relaxed, so checking |
| 374 | * them would make no difference. |
| 375 | */ |
| 376 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 377 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 378 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 379 | .m1 = { .min = 2, .max = 3 }, |
| 380 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 381 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 382 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 383 | }; |
| 384 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 385 | static const intel_limit_t intel_limits_chv = { |
| 386 | /* |
| 387 | * These are the data rate limits (measured in fast clocks) |
| 388 | * since those are the strictest limits we have. The fast |
| 389 | * clock and actual rate limits are more relaxed, so checking |
| 390 | * them would make no difference. |
| 391 | */ |
| 392 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
| 393 | .vco = { .min = 4860000, .max = 6700000 }, |
| 394 | .n = { .min = 1, .max = 1 }, |
| 395 | .m1 = { .min = 2, .max = 2 }, |
| 396 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 397 | .p1 = { .min = 2, .max = 4 }, |
| 398 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 399 | }; |
| 400 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 401 | static void vlv_clock(int refclk, intel_clock_t *clock) |
| 402 | { |
| 403 | clock->m = clock->m1 * clock->m2; |
| 404 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 405 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 406 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 407 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 408 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 409 | } |
| 410 | |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 411 | /** |
| 412 | * Returns whether any output on the specified pipe is of the specified type |
| 413 | */ |
| 414 | static bool intel_pipe_has_type(struct drm_crtc *crtc, int type) |
| 415 | { |
| 416 | struct drm_device *dev = crtc->dev; |
| 417 | struct intel_encoder *encoder; |
| 418 | |
| 419 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 420 | if (encoder->type == type) |
| 421 | return true; |
| 422 | |
| 423 | return false; |
| 424 | } |
| 425 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 426 | static const intel_limit_t *intel_ironlake_limit(struct drm_crtc *crtc, |
| 427 | int refclk) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 428 | { |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 429 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 430 | const intel_limit_t *limit; |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 431 | |
| 432 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 433 | if (intel_is_dual_link_lvds(dev)) { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 434 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 435 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 436 | else |
| 437 | limit = &intel_limits_ironlake_dual_lvds; |
| 438 | } else { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 439 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 440 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 441 | else |
| 442 | limit = &intel_limits_ironlake_single_lvds; |
| 443 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 444 | } else |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 445 | limit = &intel_limits_ironlake_dac; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 446 | |
| 447 | return limit; |
| 448 | } |
| 449 | |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 450 | static const intel_limit_t *intel_g4x_limit(struct drm_crtc *crtc) |
| 451 | { |
| 452 | struct drm_device *dev = crtc->dev; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 453 | const intel_limit_t *limit; |
| 454 | |
| 455 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 456 | if (intel_is_dual_link_lvds(dev)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 457 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 458 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 459 | limit = &intel_limits_g4x_single_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 460 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI) || |
| 461 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 462 | limit = &intel_limits_g4x_hdmi; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 463 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 464 | limit = &intel_limits_g4x_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 465 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 466 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 467 | |
| 468 | return limit; |
| 469 | } |
| 470 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 471 | 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] | 472 | { |
| 473 | struct drm_device *dev = crtc->dev; |
| 474 | const intel_limit_t *limit; |
| 475 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 476 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 477 | limit = intel_ironlake_limit(crtc, refclk); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 478 | else if (IS_G4X(dev)) { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 479 | limit = intel_g4x_limit(crtc); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 480 | } else if (IS_PINEVIEW(dev)) { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 481 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 482 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 483 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 484 | limit = &intel_limits_pineview_sdvo; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 485 | } else if (IS_CHERRYVIEW(dev)) { |
| 486 | limit = &intel_limits_chv; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 487 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 488 | limit = &intel_limits_vlv; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 489 | } else if (!IS_GEN2(dev)) { |
| 490 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
| 491 | limit = &intel_limits_i9xx_lvds; |
| 492 | else |
| 493 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 494 | } else { |
| 495 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 496 | limit = &intel_limits_i8xx_lvds; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 497 | else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 498 | limit = &intel_limits_i8xx_dvo; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 499 | else |
| 500 | limit = &intel_limits_i8xx_dac; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 501 | } |
| 502 | return limit; |
| 503 | } |
| 504 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 505 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
| 506 | static void pineview_clock(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 507 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 508 | clock->m = clock->m2 + 2; |
| 509 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 510 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 511 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 512 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 513 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 514 | } |
| 515 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 516 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 517 | { |
| 518 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 519 | } |
| 520 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 521 | static void i9xx_clock(int refclk, intel_clock_t *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 522 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 523 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 524 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 525 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
| 526 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 527 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 528 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 529 | } |
| 530 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 531 | static void chv_clock(int refclk, intel_clock_t *clock) |
| 532 | { |
| 533 | clock->m = clock->m1 * clock->m2; |
| 534 | clock->p = clock->p1 * clock->p2; |
| 535 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 536 | return; |
| 537 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 538 | clock->n << 22); |
| 539 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
| 540 | } |
| 541 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 542 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 543 | /** |
| 544 | * Returns whether the given set of divisors are valid for a given refclk with |
| 545 | * the given connectors. |
| 546 | */ |
| 547 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 548 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 549 | const intel_limit_t *limit, |
| 550 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 551 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 552 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 553 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 554 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 555 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 556 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 557 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 558 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 559 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 560 | |
| 561 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev)) |
| 562 | if (clock->m1 <= clock->m2) |
| 563 | INTELPllInvalid("m1 <= m2\n"); |
| 564 | |
| 565 | if (!IS_VALLEYVIEW(dev)) { |
| 566 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 567 | INTELPllInvalid("p out of range\n"); |
| 568 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 569 | INTELPllInvalid("m out of range\n"); |
| 570 | } |
| 571 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 572 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 573 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 574 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 575 | * connector, etc., rather than just a single range. |
| 576 | */ |
| 577 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 578 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 579 | |
| 580 | return true; |
| 581 | } |
| 582 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 583 | static bool |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 584 | 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] | 585 | int target, int refclk, intel_clock_t *match_clock, |
| 586 | intel_clock_t *best_clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 587 | { |
| 588 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 589 | intel_clock_t clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 590 | int err = target; |
| 591 | |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 592 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 593 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 594 | * For LVDS just rely on its current settings for dual-channel. |
| 595 | * We haven't figured out how to reliably set up different |
| 596 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 597 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 598 | if (intel_is_dual_link_lvds(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 599 | clock.p2 = limit->p2.p2_fast; |
| 600 | else |
| 601 | clock.p2 = limit->p2.p2_slow; |
| 602 | } else { |
| 603 | if (target < limit->p2.dot_limit) |
| 604 | clock.p2 = limit->p2.p2_slow; |
| 605 | else |
| 606 | clock.p2 = limit->p2.p2_fast; |
| 607 | } |
| 608 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 609 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 610 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 611 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 612 | clock.m1++) { |
| 613 | for (clock.m2 = limit->m2.min; |
| 614 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 615 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 616 | break; |
| 617 | for (clock.n = limit->n.min; |
| 618 | clock.n <= limit->n.max; clock.n++) { |
| 619 | for (clock.p1 = limit->p1.min; |
| 620 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 621 | int this_err; |
| 622 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 623 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 624 | if (!intel_PLL_is_valid(dev, limit, |
| 625 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 626 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 627 | if (match_clock && |
| 628 | clock.p != match_clock->p) |
| 629 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 630 | |
| 631 | this_err = abs(clock.dot - target); |
| 632 | if (this_err < err) { |
| 633 | *best_clock = clock; |
| 634 | err = this_err; |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | } |
| 639 | } |
| 640 | |
| 641 | return (err != target); |
| 642 | } |
| 643 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 644 | static bool |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 645 | pnv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 646 | int target, int refclk, intel_clock_t *match_clock, |
| 647 | intel_clock_t *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 648 | { |
| 649 | struct drm_device *dev = crtc->dev; |
| 650 | intel_clock_t clock; |
| 651 | int err = target; |
| 652 | |
| 653 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
| 654 | /* |
| 655 | * For LVDS just rely on its current settings for dual-channel. |
| 656 | * We haven't figured out how to reliably set up different |
| 657 | * single/dual channel state, if we even can. |
| 658 | */ |
| 659 | if (intel_is_dual_link_lvds(dev)) |
| 660 | clock.p2 = limit->p2.p2_fast; |
| 661 | else |
| 662 | clock.p2 = limit->p2.p2_slow; |
| 663 | } else { |
| 664 | if (target < limit->p2.dot_limit) |
| 665 | clock.p2 = limit->p2.p2_slow; |
| 666 | else |
| 667 | clock.p2 = limit->p2.p2_fast; |
| 668 | } |
| 669 | |
| 670 | memset(best_clock, 0, sizeof(*best_clock)); |
| 671 | |
| 672 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 673 | clock.m1++) { |
| 674 | for (clock.m2 = limit->m2.min; |
| 675 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 676 | for (clock.n = limit->n.min; |
| 677 | clock.n <= limit->n.max; clock.n++) { |
| 678 | for (clock.p1 = limit->p1.min; |
| 679 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 680 | int this_err; |
| 681 | |
| 682 | pineview_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 683 | if (!intel_PLL_is_valid(dev, limit, |
| 684 | &clock)) |
| 685 | continue; |
| 686 | if (match_clock && |
| 687 | clock.p != match_clock->p) |
| 688 | continue; |
| 689 | |
| 690 | this_err = abs(clock.dot - target); |
| 691 | if (this_err < err) { |
| 692 | *best_clock = clock; |
| 693 | err = this_err; |
| 694 | } |
| 695 | } |
| 696 | } |
| 697 | } |
| 698 | } |
| 699 | |
| 700 | return (err != target); |
| 701 | } |
| 702 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 703 | static bool |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 704 | g4x_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 705 | int target, int refclk, intel_clock_t *match_clock, |
| 706 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 707 | { |
| 708 | struct drm_device *dev = crtc->dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 709 | intel_clock_t clock; |
| 710 | int max_n; |
| 711 | bool found; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 712 | /* approximately equals target * 0.00585 */ |
| 713 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 714 | found = false; |
| 715 | |
| 716 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 717 | if (intel_is_dual_link_lvds(dev)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 718 | clock.p2 = limit->p2.p2_fast; |
| 719 | else |
| 720 | clock.p2 = limit->p2.p2_slow; |
| 721 | } else { |
| 722 | if (target < limit->p2.dot_limit) |
| 723 | clock.p2 = limit->p2.p2_slow; |
| 724 | else |
| 725 | clock.p2 = limit->p2.p2_fast; |
| 726 | } |
| 727 | |
| 728 | memset(best_clock, 0, sizeof(*best_clock)); |
| 729 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 730 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 731 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 732 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 733 | for (clock.m1 = limit->m1.max; |
| 734 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 735 | for (clock.m2 = limit->m2.max; |
| 736 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 737 | for (clock.p1 = limit->p1.max; |
| 738 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 739 | int this_err; |
| 740 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 741 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 742 | if (!intel_PLL_is_valid(dev, limit, |
| 743 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 744 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 745 | |
| 746 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 747 | if (this_err < err_most) { |
| 748 | *best_clock = clock; |
| 749 | err_most = this_err; |
| 750 | max_n = clock.n; |
| 751 | found = true; |
| 752 | } |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 757 | return found; |
| 758 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 759 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 760 | static bool |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 761 | vlv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 762 | int target, int refclk, intel_clock_t *match_clock, |
| 763 | intel_clock_t *best_clock) |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 764 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 765 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 766 | intel_clock_t clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 767 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 768 | /* min update 19.2 MHz */ |
| 769 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 770 | bool found = false; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 771 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 772 | target *= 5; /* fast clock */ |
| 773 | |
| 774 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 775 | |
| 776 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 777 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Ville Syrjälä | 811bbf0 | 2013-09-24 21:26:25 +0300 | [diff] [blame] | 778 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
Ville Syrjälä | 889059d | 2013-09-24 21:26:27 +0300 | [diff] [blame] | 779 | for (clock.p2 = limit->p2.p2_fast; clock.p2 >= limit->p2.p2_slow; |
Ville Syrjälä | c1a9ae4 | 2013-09-24 21:26:23 +0300 | [diff] [blame] | 780 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 781 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 782 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 783 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 784 | unsigned int ppm, diff; |
| 785 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 786 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 787 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 788 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 789 | vlv_clock(refclk, &clock); |
| 790 | |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 791 | if (!intel_PLL_is_valid(dev, limit, |
| 792 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 793 | continue; |
| 794 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 795 | diff = abs(clock.dot - target); |
| 796 | ppm = div_u64(1000000ULL * diff, target); |
| 797 | |
| 798 | if (ppm < 100 && clock.p > best_clock->p) { |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 799 | bestppm = 0; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 800 | *best_clock = clock; |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 801 | found = true; |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 802 | } |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 803 | |
Ville Syrjälä | c686122 | 2013-09-24 21:26:21 +0300 | [diff] [blame] | 804 | if (bestppm >= 10 && ppm < bestppm - 10) { |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 805 | bestppm = ppm; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 806 | *best_clock = clock; |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 807 | found = true; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 808 | } |
| 809 | } |
| 810 | } |
| 811 | } |
| 812 | } |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 813 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 814 | return found; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 815 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 816 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 817 | static bool |
| 818 | chv_find_best_dpll(const intel_limit_t *limit, struct drm_crtc *crtc, |
| 819 | int target, int refclk, intel_clock_t *match_clock, |
| 820 | intel_clock_t *best_clock) |
| 821 | { |
| 822 | struct drm_device *dev = crtc->dev; |
| 823 | intel_clock_t clock; |
| 824 | uint64_t m2; |
| 825 | int found = false; |
| 826 | |
| 827 | memset(best_clock, 0, sizeof(*best_clock)); |
| 828 | |
| 829 | /* |
| 830 | * Based on hardware doc, the n always set to 1, and m1 always |
| 831 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 832 | * revisit this because n may not 1 anymore. |
| 833 | */ |
| 834 | clock.n = 1, clock.m1 = 2; |
| 835 | target *= 5; /* fast clock */ |
| 836 | |
| 837 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 838 | for (clock.p2 = limit->p2.p2_fast; |
| 839 | clock.p2 >= limit->p2.p2_slow; |
| 840 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
| 841 | |
| 842 | clock.p = clock.p1 * clock.p2; |
| 843 | |
| 844 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 845 | clock.n) << 22, refclk * clock.m1); |
| 846 | |
| 847 | if (m2 > INT_MAX/clock.m1) |
| 848 | continue; |
| 849 | |
| 850 | clock.m2 = m2; |
| 851 | |
| 852 | chv_clock(refclk, &clock); |
| 853 | |
| 854 | if (!intel_PLL_is_valid(dev, limit, &clock)) |
| 855 | continue; |
| 856 | |
| 857 | /* based on hardware requirement, prefer bigger p |
| 858 | */ |
| 859 | if (clock.p > best_clock->p) { |
| 860 | *best_clock = clock; |
| 861 | found = true; |
| 862 | } |
| 863 | } |
| 864 | } |
| 865 | |
| 866 | return found; |
| 867 | } |
| 868 | |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 869 | bool intel_crtc_active(struct drm_crtc *crtc) |
| 870 | { |
| 871 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 872 | |
| 873 | /* Be paranoid as we can arrive here with only partial |
| 874 | * state retrieved from the hardware during setup. |
| 875 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 876 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 877 | * as Haswell has gained clock readout/fastboot support. |
| 878 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 879 | * We can ditch the crtc->primary->fb check as soon as we can |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 880 | * properly reconstruct framebuffers. |
| 881 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 882 | return intel_crtc->active && crtc->primary->fb && |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 883 | intel_crtc->config.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 884 | } |
| 885 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 886 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 887 | enum pipe pipe) |
| 888 | { |
| 889 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 890 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 891 | |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 892 | return intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 893 | } |
| 894 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 895 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 896 | { |
| 897 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 898 | u32 reg = PIPEDSL(pipe); |
| 899 | u32 line1, line2; |
| 900 | u32 line_mask; |
| 901 | |
| 902 | if (IS_GEN2(dev)) |
| 903 | line_mask = DSL_LINEMASK_GEN2; |
| 904 | else |
| 905 | line_mask = DSL_LINEMASK_GEN3; |
| 906 | |
| 907 | line1 = I915_READ(reg) & line_mask; |
| 908 | mdelay(5); |
| 909 | line2 = I915_READ(reg) & line_mask; |
| 910 | |
| 911 | return line1 == line2; |
| 912 | } |
| 913 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 914 | /* |
| 915 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 916 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 917 | * |
| 918 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 919 | * spinning on the vblank interrupt status bit, since we won't actually |
| 920 | * see an interrupt when the pipe is disabled. |
| 921 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 922 | * On Gen4 and above: |
| 923 | * wait for the pipe register state bit to turn off |
| 924 | * |
| 925 | * Otherwise: |
| 926 | * wait for the display line value to settle (it usually |
| 927 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 928 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 929 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 930 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 931 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 932 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 933 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 934 | enum transcoder cpu_transcoder = crtc->config.cpu_transcoder; |
| 935 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 936 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 937 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 938 | int reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 939 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 940 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 941 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 942 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 943 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 944 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 945 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 946 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 947 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 948 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 949 | } |
| 950 | |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 951 | /* |
| 952 | * ibx_digital_port_connected - is the specified port connected? |
| 953 | * @dev_priv: i915 private structure |
| 954 | * @port: the port to test |
| 955 | * |
| 956 | * Returns true if @port is connected, false otherwise. |
| 957 | */ |
| 958 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 959 | struct intel_digital_port *port) |
| 960 | { |
| 961 | u32 bit; |
| 962 | |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 963 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 964 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 965 | case PORT_B: |
| 966 | bit = SDE_PORTB_HOTPLUG; |
| 967 | break; |
| 968 | case PORT_C: |
| 969 | bit = SDE_PORTC_HOTPLUG; |
| 970 | break; |
| 971 | case PORT_D: |
| 972 | bit = SDE_PORTD_HOTPLUG; |
| 973 | break; |
| 974 | default: |
| 975 | return true; |
| 976 | } |
| 977 | } else { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 978 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 979 | case PORT_B: |
| 980 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 981 | break; |
| 982 | case PORT_C: |
| 983 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 984 | break; |
| 985 | case PORT_D: |
| 986 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 987 | break; |
| 988 | default: |
| 989 | return true; |
| 990 | } |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 991 | } |
| 992 | |
| 993 | return I915_READ(SDEISR) & bit; |
| 994 | } |
| 995 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 996 | static const char *state_string(bool enabled) |
| 997 | { |
| 998 | return enabled ? "on" : "off"; |
| 999 | } |
| 1000 | |
| 1001 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1002 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1003 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1004 | { |
| 1005 | int reg; |
| 1006 | u32 val; |
| 1007 | bool cur_state; |
| 1008 | |
| 1009 | reg = DPLL(pipe); |
| 1010 | val = I915_READ(reg); |
| 1011 | cur_state = !!(val & DPLL_VCO_ENABLE); |
| 1012 | WARN(cur_state != state, |
| 1013 | "PLL state assertion failure (expected %s, current %s)\n", |
| 1014 | state_string(state), state_string(cur_state)); |
| 1015 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1016 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1017 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
| 1018 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
| 1019 | { |
| 1020 | u32 val; |
| 1021 | bool cur_state; |
| 1022 | |
| 1023 | mutex_lock(&dev_priv->dpio_lock); |
| 1024 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
| 1025 | mutex_unlock(&dev_priv->dpio_lock); |
| 1026 | |
| 1027 | cur_state = val & DSI_PLL_VCO_EN; |
| 1028 | WARN(cur_state != state, |
| 1029 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
| 1030 | state_string(state), state_string(cur_state)); |
| 1031 | } |
| 1032 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) |
| 1033 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) |
| 1034 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1035 | struct intel_shared_dpll * |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1036 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1037 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1038 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 1039 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 1040 | if (crtc->config.shared_dpll < 0) |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1041 | return NULL; |
| 1042 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 1043 | return &dev_priv->shared_dplls[crtc->config.shared_dpll]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1044 | } |
| 1045 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1046 | /* For ILK+ */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1047 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
| 1048 | struct intel_shared_dpll *pll, |
| 1049 | bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1050 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1051 | bool cur_state; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1052 | struct intel_dpll_hw_state hw_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1053 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1054 | if (WARN (!pll, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1055 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1056 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1057 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1058 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1059 | WARN(cur_state != state, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1060 | "%s assertion failure (expected %s, current %s)\n", |
| 1061 | pll->name, state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1062 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1063 | |
| 1064 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1065 | enum pipe pipe, bool state) |
| 1066 | { |
| 1067 | int reg; |
| 1068 | u32 val; |
| 1069 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1070 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1071 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1072 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1073 | if (HAS_DDI(dev_priv->dev)) { |
| 1074 | /* DDI does not have a specific FDI_TX register */ |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1075 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1076 | val = I915_READ(reg); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1077 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1078 | } else { |
| 1079 | reg = FDI_TX_CTL(pipe); |
| 1080 | val = I915_READ(reg); |
| 1081 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1082 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1083 | WARN(cur_state != state, |
| 1084 | "FDI TX state assertion failure (expected %s, current %s)\n", |
| 1085 | state_string(state), state_string(cur_state)); |
| 1086 | } |
| 1087 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1088 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1089 | |
| 1090 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1091 | enum pipe pipe, bool state) |
| 1092 | { |
| 1093 | int reg; |
| 1094 | u32 val; |
| 1095 | bool cur_state; |
| 1096 | |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1097 | reg = FDI_RX_CTL(pipe); |
| 1098 | val = I915_READ(reg); |
| 1099 | cur_state = !!(val & FDI_RX_ENABLE); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1100 | WARN(cur_state != state, |
| 1101 | "FDI RX state assertion failure (expected %s, current %s)\n", |
| 1102 | state_string(state), state_string(cur_state)); |
| 1103 | } |
| 1104 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1105 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1106 | |
| 1107 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1108 | enum pipe pipe) |
| 1109 | { |
| 1110 | int reg; |
| 1111 | u32 val; |
| 1112 | |
| 1113 | /* ILK FDI PLL is always enabled */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1114 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1115 | return; |
| 1116 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1117 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1118 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1119 | return; |
| 1120 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1121 | reg = FDI_TX_CTL(pipe); |
| 1122 | val = I915_READ(reg); |
| 1123 | WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
| 1124 | } |
| 1125 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1126 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1127 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1128 | { |
| 1129 | int reg; |
| 1130 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1131 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1132 | |
| 1133 | reg = FDI_RX_CTL(pipe); |
| 1134 | val = I915_READ(reg); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1135 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
| 1136 | WARN(cur_state != state, |
| 1137 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
| 1138 | state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1139 | } |
| 1140 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1141 | static void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1142 | enum pipe pipe) |
| 1143 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1144 | struct drm_device *dev = dev_priv->dev; |
| 1145 | int pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1146 | u32 val; |
| 1147 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1148 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1149 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1150 | if (WARN_ON(HAS_DDI(dev))) |
| 1151 | return; |
| 1152 | |
| 1153 | if (HAS_PCH_SPLIT(dev)) { |
| 1154 | u32 port_sel; |
| 1155 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1156 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1157 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1158 | |
| 1159 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1160 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1161 | panel_pipe = PIPE_B; |
| 1162 | /* XXX: else fix for eDP */ |
| 1163 | } else if (IS_VALLEYVIEW(dev)) { |
| 1164 | /* presumably write lock depends on pipe, not port select */ |
| 1165 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1166 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1167 | } else { |
| 1168 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1169 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1170 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1171 | } |
| 1172 | |
| 1173 | val = I915_READ(pp_reg); |
| 1174 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1175 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1176 | locked = false; |
| 1177 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1178 | WARN(panel_pipe == pipe && locked, |
| 1179 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1180 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1181 | } |
| 1182 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1183 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1184 | enum pipe pipe, bool state) |
| 1185 | { |
| 1186 | struct drm_device *dev = dev_priv->dev; |
| 1187 | bool cur_state; |
| 1188 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1189 | if (IS_845G(dev) || IS_I865G(dev)) |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1190 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1191 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1192 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1193 | |
| 1194 | WARN(cur_state != state, |
| 1195 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
| 1196 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
| 1197 | } |
| 1198 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1199 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1200 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1201 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1202 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1203 | { |
| 1204 | int reg; |
| 1205 | u32 val; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1206 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1207 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1208 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1209 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1210 | /* if we need the pipe quirk it must be always on */ |
| 1211 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1212 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1213 | state = true; |
| 1214 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 1215 | if (!intel_display_power_enabled(dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 1216 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1217 | cur_state = false; |
| 1218 | } else { |
| 1219 | reg = PIPECONF(cpu_transcoder); |
| 1220 | val = I915_READ(reg); |
| 1221 | cur_state = !!(val & PIPECONF_ENABLE); |
| 1222 | } |
| 1223 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1224 | WARN(cur_state != state, |
| 1225 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1226 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1227 | } |
| 1228 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1229 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1230 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1231 | { |
| 1232 | int reg; |
| 1233 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1234 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1235 | |
| 1236 | reg = DSPCNTR(plane); |
| 1237 | val = I915_READ(reg); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1238 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
| 1239 | WARN(cur_state != state, |
| 1240 | "plane %c assertion failure (expected %s, current %s)\n", |
| 1241 | plane_name(plane), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1242 | } |
| 1243 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1244 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1245 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1246 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1247 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1248 | enum pipe pipe) |
| 1249 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1250 | struct drm_device *dev = dev_priv->dev; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1251 | int reg, i; |
| 1252 | u32 val; |
| 1253 | int cur_pipe; |
| 1254 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1255 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1256 | if (INTEL_INFO(dev)->gen >= 4) { |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1257 | reg = DSPCNTR(pipe); |
| 1258 | val = I915_READ(reg); |
Damien Lespiau | 83f26f1 | 2014-03-17 17:59:48 +0000 | [diff] [blame] | 1259 | WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1260 | "plane %c assertion failure, should be disabled but not\n", |
| 1261 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1262 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1263 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1264 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1265 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1266 | for_each_pipe(dev_priv, i) { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1267 | reg = DSPCNTR(i); |
| 1268 | val = I915_READ(reg); |
| 1269 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 1270 | DISPPLANE_SEL_PIPE_SHIFT; |
| 1271 | WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1272 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1273 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1274 | } |
| 1275 | } |
| 1276 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1277 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1278 | enum pipe pipe) |
| 1279 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1280 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1281 | int reg, sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1282 | u32 val; |
| 1283 | |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1284 | if (IS_VALLEYVIEW(dev)) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1285 | for_each_sprite(pipe, sprite) { |
| 1286 | reg = SPCNTR(pipe, sprite); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1287 | val = I915_READ(reg); |
Damien Lespiau | 83f26f1 | 2014-03-17 17:59:48 +0000 | [diff] [blame] | 1288 | WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1289 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1290 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1291 | } |
| 1292 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 1293 | reg = SPRCTL(pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1294 | val = I915_READ(reg); |
Damien Lespiau | 83f26f1 | 2014-03-17 17:59:48 +0000 | [diff] [blame] | 1295 | WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1296 | "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] | 1297 | plane_name(pipe), pipe_name(pipe)); |
| 1298 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1299 | reg = DVSCNTR(pipe); |
| 1300 | val = I915_READ(reg); |
Damien Lespiau | 83f26f1 | 2014-03-17 17:59:48 +0000 | [diff] [blame] | 1301 | WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1302 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1303 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1304 | } |
| 1305 | } |
| 1306 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1307 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1308 | { |
| 1309 | if (WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
| 1310 | drm_crtc_vblank_put(crtc); |
| 1311 | } |
| 1312 | |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 1313 | static void ibx_assert_pch_refclk_enabled(struct drm_i915_private *dev_priv) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1314 | { |
| 1315 | u32 val; |
| 1316 | bool enabled; |
| 1317 | |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 1318 | WARN_ON(!(HAS_PCH_IBX(dev_priv->dev) || HAS_PCH_CPT(dev_priv->dev))); |
Eugeni Dodonov | 9d82aa1 | 2012-05-09 15:37:17 -0300 | [diff] [blame] | 1319 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1320 | val = I915_READ(PCH_DREF_CONTROL); |
| 1321 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | |
| 1322 | DREF_SUPERSPREAD_SOURCE_MASK)); |
| 1323 | WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
| 1324 | } |
| 1325 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1326 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1327 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1328 | { |
| 1329 | int reg; |
| 1330 | u32 val; |
| 1331 | bool enabled; |
| 1332 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1333 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1334 | val = I915_READ(reg); |
| 1335 | enabled = !!(val & TRANS_ENABLE); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1336 | WARN(enabled, |
| 1337 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1338 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1339 | } |
| 1340 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1341 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1342 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1343 | { |
| 1344 | if ((val & DP_PORT_EN) == 0) |
| 1345 | return false; |
| 1346 | |
| 1347 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1348 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); |
| 1349 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); |
| 1350 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1351 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1352 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1353 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1354 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1355 | } else { |
| 1356 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1357 | return false; |
| 1358 | } |
| 1359 | return true; |
| 1360 | } |
| 1361 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1362 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1363 | enum pipe pipe, u32 val) |
| 1364 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1365 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1366 | return false; |
| 1367 | |
| 1368 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1369 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1370 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1371 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1372 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1373 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1374 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1375 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1376 | return false; |
| 1377 | } |
| 1378 | return true; |
| 1379 | } |
| 1380 | |
| 1381 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1382 | enum pipe pipe, u32 val) |
| 1383 | { |
| 1384 | if ((val & LVDS_PORT_EN) == 0) |
| 1385 | return false; |
| 1386 | |
| 1387 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1388 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1389 | return false; |
| 1390 | } else { |
| 1391 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1392 | return false; |
| 1393 | } |
| 1394 | return true; |
| 1395 | } |
| 1396 | |
| 1397 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1398 | enum pipe pipe, u32 val) |
| 1399 | { |
| 1400 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1401 | return false; |
| 1402 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1403 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1404 | return false; |
| 1405 | } else { |
| 1406 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1407 | return false; |
| 1408 | } |
| 1409 | return true; |
| 1410 | } |
| 1411 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1412 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1413 | enum pipe pipe, int reg, u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1414 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1415 | u32 val = I915_READ(reg); |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1416 | WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1417 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1418 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1419 | |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1420 | WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
| 1421 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1422 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1423 | } |
| 1424 | |
| 1425 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
| 1426 | enum pipe pipe, int reg) |
| 1427 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1428 | u32 val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1429 | WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1430 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1431 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1432 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1433 | WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1434 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1435 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1436 | } |
| 1437 | |
| 1438 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1439 | enum pipe pipe) |
| 1440 | { |
| 1441 | int reg; |
| 1442 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1443 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1444 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1445 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1446 | 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] | 1447 | |
| 1448 | reg = PCH_ADPA; |
| 1449 | val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1450 | WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1451 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1452 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1453 | |
| 1454 | reg = PCH_LVDS; |
| 1455 | val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1456 | WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1457 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1458 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1459 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1460 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1461 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1462 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1463 | } |
| 1464 | |
Jesse Barnes | 40e9cf6 | 2013-10-03 11:35:46 -0700 | [diff] [blame] | 1465 | static void intel_init_dpio(struct drm_device *dev) |
| 1466 | { |
| 1467 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1468 | |
| 1469 | if (!IS_VALLEYVIEW(dev)) |
| 1470 | return; |
| 1471 | |
Chon Ming Lee | a09cadd | 2014-04-09 13:28:14 +0300 | [diff] [blame] | 1472 | /* |
| 1473 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), |
| 1474 | * CHV x1 PHY (DP/HDMI D) |
| 1475 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) |
| 1476 | */ |
| 1477 | if (IS_CHERRYVIEW(dev)) { |
| 1478 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; |
| 1479 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; |
| 1480 | } else { |
| 1481 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; |
| 1482 | } |
Jesse Barnes | 5382f5f35 | 2013-12-16 16:34:24 -0800 | [diff] [blame] | 1483 | } |
| 1484 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1485 | static void vlv_enable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1486 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1487 | struct drm_device *dev = crtc->base.dev; |
| 1488 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1489 | int reg = DPLL(crtc->pipe); |
| 1490 | u32 dpll = crtc->config.dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1491 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1492 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1493 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1494 | /* No really, not for ILK+ */ |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1495 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); |
| 1496 | |
| 1497 | /* PLL is protected by panel, make sure we can write it */ |
Jani Nikula | 6a9e736 | 2014-08-22 15:06:35 +0300 | [diff] [blame] | 1498 | if (IS_MOBILE(dev_priv->dev)) |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1499 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1500 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1501 | I915_WRITE(reg, dpll); |
| 1502 | POSTING_READ(reg); |
| 1503 | udelay(150); |
| 1504 | |
| 1505 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1506 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); |
| 1507 | |
| 1508 | I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md); |
| 1509 | POSTING_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1510 | |
| 1511 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1512 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1513 | POSTING_READ(reg); |
| 1514 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1515 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1516 | POSTING_READ(reg); |
| 1517 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1518 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1519 | POSTING_READ(reg); |
| 1520 | udelay(150); /* wait for warmup */ |
| 1521 | } |
| 1522 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1523 | static void chv_enable_pll(struct intel_crtc *crtc) |
| 1524 | { |
| 1525 | struct drm_device *dev = crtc->base.dev; |
| 1526 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1527 | int pipe = crtc->pipe; |
| 1528 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1529 | u32 tmp; |
| 1530 | |
| 1531 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 1532 | |
| 1533 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); |
| 1534 | |
| 1535 | mutex_lock(&dev_priv->dpio_lock); |
| 1536 | |
| 1537 | /* Enable back the 10bit clock to display controller */ |
| 1538 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1539 | tmp |= DPIO_DCLKP_EN; |
| 1540 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1541 | |
| 1542 | /* |
| 1543 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1544 | */ |
| 1545 | udelay(1); |
| 1546 | |
| 1547 | /* Enable PLL */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1548 | I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1549 | |
| 1550 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1551 | if (wait_for(((I915_READ(DPLL(pipe)) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1552 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
| 1553 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1554 | /* not sure when this should be written */ |
| 1555 | I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md); |
| 1556 | POSTING_READ(DPLL_MD(pipe)); |
| 1557 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1558 | mutex_unlock(&dev_priv->dpio_lock); |
| 1559 | } |
| 1560 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1561 | static int intel_num_dvo_pipes(struct drm_device *dev) |
| 1562 | { |
| 1563 | struct intel_crtc *crtc; |
| 1564 | int count = 0; |
| 1565 | |
| 1566 | for_each_intel_crtc(dev, crtc) |
| 1567 | count += crtc->active && |
| 1568 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO); |
| 1569 | |
| 1570 | return count; |
| 1571 | } |
| 1572 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1573 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1574 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1575 | struct drm_device *dev = crtc->base.dev; |
| 1576 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1577 | int reg = DPLL(crtc->pipe); |
| 1578 | u32 dpll = crtc->config.dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1579 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1580 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1581 | |
| 1582 | /* No really, not for ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1583 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1584 | |
| 1585 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1586 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1587 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1588 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1589 | /* Enable DVO 2x clock on both PLLs if necessary */ |
| 1590 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { |
| 1591 | /* |
| 1592 | * It appears to be important that we don't enable this |
| 1593 | * for the current pipe before otherwise configuring the |
| 1594 | * PLL. No idea how this should be handled if multiple |
| 1595 | * DVO outputs are enabled simultaneosly. |
| 1596 | */ |
| 1597 | dpll |= DPLL_DVO_2X_MODE; |
| 1598 | I915_WRITE(DPLL(!crtc->pipe), |
| 1599 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1600 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1601 | |
| 1602 | /* Wait for the clocks to stabilize. */ |
| 1603 | POSTING_READ(reg); |
| 1604 | udelay(150); |
| 1605 | |
| 1606 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1607 | I915_WRITE(DPLL_MD(crtc->pipe), |
| 1608 | crtc->config.dpll_hw_state.dpll_md); |
| 1609 | } else { |
| 1610 | /* The pixel multiplier can only be updated once the |
| 1611 | * DPLL is enabled and the clocks are stable. |
| 1612 | * |
| 1613 | * So write it again. |
| 1614 | */ |
| 1615 | I915_WRITE(reg, dpll); |
| 1616 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1617 | |
| 1618 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1619 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1620 | POSTING_READ(reg); |
| 1621 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1622 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1623 | POSTING_READ(reg); |
| 1624 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1625 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1626 | POSTING_READ(reg); |
| 1627 | udelay(150); /* wait for warmup */ |
| 1628 | } |
| 1629 | |
| 1630 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1631 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1632 | * @dev_priv: i915 private structure |
| 1633 | * @pipe: pipe PLL to disable |
| 1634 | * |
| 1635 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1636 | * |
| 1637 | * Note! This is for pre-ILK only. |
| 1638 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1639 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1640 | { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1641 | struct drm_device *dev = crtc->base.dev; |
| 1642 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1643 | enum pipe pipe = crtc->pipe; |
| 1644 | |
| 1645 | /* Disable DVO 2x clock on both PLLs if necessary */ |
| 1646 | if (IS_I830(dev) && |
| 1647 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO) && |
| 1648 | intel_num_dvo_pipes(dev) == 1) { |
| 1649 | I915_WRITE(DPLL(PIPE_B), |
| 1650 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1651 | I915_WRITE(DPLL(PIPE_A), |
| 1652 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1653 | } |
| 1654 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1655 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1656 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1657 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1658 | return; |
| 1659 | |
| 1660 | /* Make sure the pipe isn't still relying on us */ |
| 1661 | assert_pipe_disabled(dev_priv, pipe); |
| 1662 | |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1663 | I915_WRITE(DPLL(pipe), 0); |
| 1664 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1665 | } |
| 1666 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1667 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1668 | { |
| 1669 | u32 val = 0; |
| 1670 | |
| 1671 | /* Make sure the pipe isn't still relying on us */ |
| 1672 | assert_pipe_disabled(dev_priv, pipe); |
| 1673 | |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1674 | /* |
| 1675 | * Leave integrated clock source and reference clock enabled for pipe B. |
| 1676 | * The latter is needed for VGA hotplug / manual detection. |
| 1677 | */ |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1678 | if (pipe == PIPE_B) |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1679 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1680 | I915_WRITE(DPLL(pipe), val); |
| 1681 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1682 | |
| 1683 | } |
| 1684 | |
| 1685 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1686 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1687 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1688 | u32 val; |
| 1689 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1690 | /* Make sure the pipe isn't still relying on us */ |
| 1691 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1692 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1693 | /* Set PLL en = 0 */ |
Ville Syrjälä | d17ec4c | 2014-06-28 02:03:59 +0300 | [diff] [blame] | 1694 | val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1695 | if (pipe != PIPE_A) |
| 1696 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1697 | I915_WRITE(DPLL(pipe), val); |
| 1698 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1699 | |
| 1700 | mutex_lock(&dev_priv->dpio_lock); |
| 1701 | |
| 1702 | /* Disable 10bit clock to display controller */ |
| 1703 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1704 | val &= ~DPIO_DCLKP_EN; |
| 1705 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1706 | |
Ville Syrjälä | 61407f6 | 2014-05-27 16:32:55 +0300 | [diff] [blame] | 1707 | /* disable left/right clock distribution */ |
| 1708 | if (pipe != PIPE_B) { |
| 1709 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); |
| 1710 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); |
| 1711 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); |
| 1712 | } else { |
| 1713 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); |
| 1714 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); |
| 1715 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); |
| 1716 | } |
| 1717 | |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1718 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1719 | } |
| 1720 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1721 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
| 1722 | struct intel_digital_port *dport) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1723 | { |
| 1724 | u32 port_mask; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1725 | int dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1726 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1727 | switch (dport->port) { |
| 1728 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1729 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1730 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1731 | break; |
| 1732 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1733 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1734 | dpll_reg = DPLL(0); |
| 1735 | break; |
| 1736 | case PORT_D: |
| 1737 | port_mask = DPLL_PORTD_READY_MASK; |
| 1738 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1739 | break; |
| 1740 | default: |
| 1741 | BUG(); |
| 1742 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1743 | |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1744 | if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1745 | WARN(1, "timed out waiting for port %c ready: 0x%08x\n", |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1746 | port_name(dport->port), I915_READ(dpll_reg)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1747 | } |
| 1748 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1749 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
| 1750 | { |
| 1751 | struct drm_device *dev = crtc->base.dev; |
| 1752 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1753 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 1754 | |
Chris Wilson | be19f0f | 2014-05-28 16:16:42 +0100 | [diff] [blame] | 1755 | if (WARN_ON(pll == NULL)) |
| 1756 | return; |
| 1757 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1758 | WARN_ON(!pll->refcount); |
| 1759 | if (pll->active == 0) { |
| 1760 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); |
| 1761 | WARN_ON(pll->on); |
| 1762 | assert_shared_dpll_disabled(dev_priv, pll); |
| 1763 | |
| 1764 | pll->mode_set(dev_priv, pll); |
| 1765 | } |
| 1766 | } |
| 1767 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1768 | /** |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1769 | * intel_enable_shared_dpll - enable PCH PLL |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1770 | * @dev_priv: i915 private structure |
| 1771 | * @pipe: pipe PLL to enable |
| 1772 | * |
| 1773 | * The PCH PLL needs to be enabled before the PCH transcoder, since it |
| 1774 | * drives the transcoder clock. |
| 1775 | */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1776 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1777 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1778 | struct drm_device *dev = crtc->base.dev; |
| 1779 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1780 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1781 | |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1782 | if (WARN_ON(pll == NULL)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1783 | return; |
| 1784 | |
| 1785 | if (WARN_ON(pll->refcount == 0)) |
| 1786 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1787 | |
Damien Lespiau | 74dd692 | 2014-07-29 18:06:17 +0100 | [diff] [blame] | 1788 | DRM_DEBUG_KMS("enable %s (active %d, on? %d) for crtc %d\n", |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1789 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1790 | crtc->base.base.id); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1791 | |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1792 | if (pll->active++) { |
| 1793 | WARN_ON(!pll->on); |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1794 | assert_shared_dpll_enabled(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1795 | return; |
| 1796 | } |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1797 | WARN_ON(pll->on); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1798 | |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1799 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 1800 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1801 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1802 | pll->enable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1803 | pll->on = true; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1804 | } |
| 1805 | |
Damien Lespiau | f6daaec | 2014-08-09 23:00:56 +0100 | [diff] [blame] | 1806 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1807 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1808 | struct drm_device *dev = crtc->base.dev; |
| 1809 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1810 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 4c609cb | 2011-09-02 12:52:11 -0700 | [diff] [blame] | 1811 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1812 | /* PCH only available on ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1813 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1814 | if (WARN_ON(pll == NULL)) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1815 | return; |
| 1816 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1817 | if (WARN_ON(pll->refcount == 0)) |
| 1818 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1819 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1820 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
| 1821 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1822 | crtc->base.base.id); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1823 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1824 | if (WARN_ON(pll->active == 0)) { |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1825 | assert_shared_dpll_disabled(dev_priv, pll); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1826 | return; |
| 1827 | } |
| 1828 | |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1829 | assert_shared_dpll_enabled(dev_priv, pll); |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1830 | WARN_ON(!pll->on); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1831 | if (--pll->active) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1832 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1833 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1834 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1835 | pll->disable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1836 | pll->on = false; |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1837 | |
| 1838 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1839 | } |
| 1840 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1841 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1842 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1843 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1844 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1845 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1846 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1847 | uint32_t reg, val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1848 | |
| 1849 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1850 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1851 | |
| 1852 | /* Make sure PCH DPLL is enabled */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 1853 | assert_shared_dpll_enabled(dev_priv, |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1854 | intel_crtc_to_shared_dpll(intel_crtc)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1855 | |
| 1856 | /* FDI must be feeding us bits for PCH ports */ |
| 1857 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1858 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1859 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1860 | if (HAS_PCH_CPT(dev)) { |
| 1861 | /* Workaround: Set the timing override bit before enabling the |
| 1862 | * pch transcoder. */ |
| 1863 | reg = TRANS_CHICKEN2(pipe); |
| 1864 | val = I915_READ(reg); |
| 1865 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1866 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1867 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1868 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1869 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1870 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1871 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1872 | |
| 1873 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1874 | /* |
| 1875 | * make the BPC in transcoder be consistent with |
| 1876 | * that in pipeconf reg. |
| 1877 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1878 | val &= ~PIPECONF_BPC_MASK; |
| 1879 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1880 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1881 | |
| 1882 | val &= ~TRANS_INTERLACE_MASK; |
| 1883 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1884 | if (HAS_PCH_IBX(dev_priv->dev) && |
| 1885 | intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) |
| 1886 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1887 | else |
| 1888 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1889 | else |
| 1890 | val |= TRANS_PROGRESSIVE; |
| 1891 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1892 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1893 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1894 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1895 | } |
| 1896 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1897 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1898 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1899 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1900 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1901 | |
| 1902 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1903 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1904 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1905 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1906 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1907 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1908 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1909 | /* Workaround: set timing override bit. */ |
| 1910 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1911 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1912 | I915_WRITE(_TRANSA_CHICKEN2, val); |
| 1913 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1914 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1915 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1916 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1917 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1918 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1919 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1920 | else |
| 1921 | val |= TRANS_PROGRESSIVE; |
| 1922 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1923 | I915_WRITE(LPT_TRANSCONF, val); |
| 1924 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1925 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1926 | } |
| 1927 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1928 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1929 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1930 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1931 | struct drm_device *dev = dev_priv->dev; |
| 1932 | uint32_t reg, val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1933 | |
| 1934 | /* FDI relies on the transcoder */ |
| 1935 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1936 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1937 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1938 | /* Ports must be off as well */ |
| 1939 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1940 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1941 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1942 | val = I915_READ(reg); |
| 1943 | val &= ~TRANS_ENABLE; |
| 1944 | I915_WRITE(reg, val); |
| 1945 | /* wait for PCH transcoder off, transcoder state */ |
| 1946 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1947 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1948 | |
| 1949 | if (!HAS_PCH_IBX(dev)) { |
| 1950 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1951 | reg = TRANS_CHICKEN2(pipe); |
| 1952 | val = I915_READ(reg); |
| 1953 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1954 | I915_WRITE(reg, val); |
| 1955 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1956 | } |
| 1957 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 1958 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1959 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1960 | u32 val; |
| 1961 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1962 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1963 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1964 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1965 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1966 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1967 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1968 | |
| 1969 | /* Workaround: clear timing override bit. */ |
| 1970 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1971 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1972 | I915_WRITE(_TRANSA_CHICKEN2, val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1973 | } |
| 1974 | |
| 1975 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1976 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1977 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1978 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1979 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1980 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1981 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 1982 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1983 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1984 | struct drm_device *dev = crtc->base.dev; |
| 1985 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1986 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1987 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1988 | pipe); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1989 | enum pipe pch_transcoder; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1990 | int reg; |
| 1991 | u32 val; |
| 1992 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1993 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1994 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1995 | assert_sprites_disabled(dev_priv, pipe); |
| 1996 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 1997 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 1998 | pch_transcoder = TRANSCODER_A; |
| 1999 | else |
| 2000 | pch_transcoder = pipe; |
| 2001 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2002 | /* |
| 2003 | * A pipe without a PLL won't actually be able to drive bits from |
| 2004 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 2005 | * need the check. |
| 2006 | */ |
| 2007 | if (!HAS_PCH_SPLIT(dev_priv->dev)) |
Paulo Zanoni | fbf3218 | 2014-01-17 13:51:11 -0200 | [diff] [blame] | 2008 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 2009 | assert_dsi_pll_enabled(dev_priv); |
| 2010 | else |
| 2011 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2012 | else { |
Paulo Zanoni | 30421c4 | 2014-01-17 13:51:10 -0200 | [diff] [blame] | 2013 | if (crtc->config.has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2014 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2015 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2016 | assert_fdi_tx_pll_enabled(dev_priv, |
| 2017 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2018 | } |
| 2019 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 2020 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2021 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2022 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2023 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2024 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2025 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 2026 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2027 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2028 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2029 | |
| 2030 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 2031 | POSTING_READ(reg); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2035 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2036 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2037 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2038 | * Disable the pipe of @crtc, making sure that various hardware |
| 2039 | * specific requirements are met, if applicable, e.g. plane |
| 2040 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2041 | * |
| 2042 | * Will wait until the pipe has shut down before returning. |
| 2043 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2044 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2045 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2046 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 2047 | enum transcoder cpu_transcoder = crtc->config.cpu_transcoder; |
| 2048 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2049 | int reg; |
| 2050 | u32 val; |
| 2051 | |
| 2052 | /* |
| 2053 | * Make sure planes won't keep trying to pump pixels to us, |
| 2054 | * or we might hang the display. |
| 2055 | */ |
| 2056 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2057 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2058 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2059 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2060 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2061 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2062 | if ((val & PIPECONF_ENABLE) == 0) |
| 2063 | return; |
| 2064 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2065 | /* |
| 2066 | * Double wide has implications for planes |
| 2067 | * so best keep it disabled when not needed. |
| 2068 | */ |
| 2069 | if (crtc->config.double_wide) |
| 2070 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2071 | |
| 2072 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2073 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2074 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2075 | val &= ~PIPECONF_ENABLE; |
| 2076 | |
| 2077 | I915_WRITE(reg, val); |
| 2078 | if ((val & PIPECONF_ENABLE) == 0) |
| 2079 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2080 | } |
| 2081 | |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2082 | /* |
| 2083 | * Plane regs are double buffered, going from enabled->disabled needs a |
| 2084 | * trigger in order to latch. The display address reg provides this. |
| 2085 | */ |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2086 | void intel_flush_primary_plane(struct drm_i915_private *dev_priv, |
| 2087 | enum plane plane) |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2088 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 2089 | struct drm_device *dev = dev_priv->dev; |
| 2090 | u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2091 | |
| 2092 | I915_WRITE(reg, I915_READ(reg)); |
| 2093 | POSTING_READ(reg); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2094 | } |
| 2095 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2096 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2097 | * intel_enable_primary_hw_plane - enable the primary plane on a given pipe |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2098 | * @plane: plane to be enabled |
| 2099 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2100 | * |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2101 | * Enable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2102 | */ |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2103 | static void intel_enable_primary_hw_plane(struct drm_plane *plane, |
| 2104 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2105 | { |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2106 | struct drm_device *dev = plane->dev; |
| 2107 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2108 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2109 | |
| 2110 | /* If the pipe isn't enabled, we can't pump pixels and may hang */ |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2111 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2112 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2113 | if (intel_crtc->primary_enabled) |
| 2114 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2115 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2116 | intel_crtc->primary_enabled = true; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2117 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2118 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2119 | crtc->x, crtc->y); |
Ville Syrjälä | 33c3b0d | 2014-06-24 13:59:28 +0300 | [diff] [blame] | 2120 | |
| 2121 | /* |
| 2122 | * BDW signals flip done immediately if the plane |
| 2123 | * is disabled, even if the plane enable is already |
| 2124 | * armed to occur at the next vblank :( |
| 2125 | */ |
| 2126 | if (IS_BROADWELL(dev)) |
| 2127 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2128 | } |
| 2129 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2130 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2131 | * intel_disable_primary_hw_plane - disable the primary hardware plane |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2132 | * @plane: plane to be disabled |
| 2133 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2134 | * |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2135 | * Disable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2136 | */ |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2137 | static void intel_disable_primary_hw_plane(struct drm_plane *plane, |
| 2138 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2139 | { |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2140 | struct drm_device *dev = plane->dev; |
| 2141 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2142 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2143 | |
| 2144 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2145 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2146 | if (!intel_crtc->primary_enabled) |
| 2147 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2148 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2149 | intel_crtc->primary_enabled = false; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2150 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2151 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2152 | crtc->x, crtc->y); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2153 | } |
| 2154 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2155 | static bool need_vtd_wa(struct drm_device *dev) |
| 2156 | { |
| 2157 | #ifdef CONFIG_INTEL_IOMMU |
| 2158 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2159 | return true; |
| 2160 | #endif |
| 2161 | return false; |
| 2162 | } |
| 2163 | |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2164 | static int intel_align_height(struct drm_device *dev, int height, bool tiled) |
| 2165 | { |
| 2166 | int tile_height; |
| 2167 | |
| 2168 | tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1; |
| 2169 | return ALIGN(height, tile_height); |
| 2170 | } |
| 2171 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2172 | int |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2173 | intel_pin_and_fence_fb_obj(struct drm_device *dev, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2174 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2175 | struct intel_engine_cs *pipelined) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2176 | { |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2177 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2178 | u32 alignment; |
| 2179 | int ret; |
| 2180 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2181 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2182 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2183 | switch (obj->tiling_mode) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2184 | case I915_TILING_NONE: |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2185 | if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
| 2186 | alignment = 128 * 1024; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2187 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2188 | alignment = 4 * 1024; |
| 2189 | else |
| 2190 | alignment = 64 * 1024; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2191 | break; |
| 2192 | case I915_TILING_X: |
| 2193 | /* pin() will align the object as required by fence */ |
| 2194 | alignment = 0; |
| 2195 | break; |
| 2196 | case I915_TILING_Y: |
Daniel Vetter | 80075d4 | 2013-10-09 21:23:52 +0200 | [diff] [blame] | 2197 | WARN(1, "Y tiled bo slipped through, driver bug!\n"); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2198 | return -EINVAL; |
| 2199 | default: |
| 2200 | BUG(); |
| 2201 | } |
| 2202 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2203 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2204 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2205 | * we should always have valid PTE following the scanout preventing |
| 2206 | * the VT-d warning. |
| 2207 | */ |
| 2208 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2209 | alignment = 256 * 1024; |
| 2210 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2211 | /* |
| 2212 | * Global gtt pte registers are special registers which actually forward |
| 2213 | * writes to a chunk of system memory. Which means that there is no risk |
| 2214 | * that the register values disappear as soon as we call |
| 2215 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2216 | * pin/unpin/fence and not more. |
| 2217 | */ |
| 2218 | intel_runtime_pm_get(dev_priv); |
| 2219 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2220 | dev_priv->mm.interruptible = false; |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 2221 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2222 | if (ret) |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2223 | goto err_interruptible; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2224 | |
| 2225 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2226 | * fence, whereas 965+ only requires a fence if using |
| 2227 | * framebuffer compression. For simplicity, we always install |
| 2228 | * a fence as the cost is not that onerous. |
| 2229 | */ |
Chris Wilson | 06d9813 | 2012-04-17 15:31:24 +0100 | [diff] [blame] | 2230 | ret = i915_gem_object_get_fence(obj); |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2231 | if (ret) |
| 2232 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2233 | |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2234 | i915_gem_object_pin_fence(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2235 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2236 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2237 | intel_runtime_pm_put(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2238 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2239 | |
| 2240 | err_unpin: |
Chris Wilson | cc98b41 | 2013-08-09 12:25:09 +0100 | [diff] [blame] | 2241 | i915_gem_object_unpin_from_display_plane(obj); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2242 | err_interruptible: |
| 2243 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2244 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2245 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2246 | } |
| 2247 | |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2248 | void intel_unpin_fb_obj(struct drm_i915_gem_object *obj) |
| 2249 | { |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2250 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2251 | |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2252 | i915_gem_object_unpin_fence(obj); |
Chris Wilson | cc98b41 | 2013-08-09 12:25:09 +0100 | [diff] [blame] | 2253 | i915_gem_object_unpin_from_display_plane(obj); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2254 | } |
| 2255 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2256 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
| 2257 | * is assumed to be a power-of-two. */ |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2258 | unsigned long intel_gen4_compute_page_offset(int *x, int *y, |
| 2259 | unsigned int tiling_mode, |
| 2260 | unsigned int cpp, |
| 2261 | unsigned int pitch) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2262 | { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2263 | if (tiling_mode != I915_TILING_NONE) { |
| 2264 | unsigned int tile_rows, tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2265 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2266 | tile_rows = *y / 8; |
| 2267 | *y %= 8; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2268 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2269 | tiles = *x / (512/cpp); |
| 2270 | *x %= 512/cpp; |
| 2271 | |
| 2272 | return tile_rows * pitch * 8 + tiles * 4096; |
| 2273 | } else { |
| 2274 | unsigned int offset; |
| 2275 | |
| 2276 | offset = *y * pitch + *x * cpp; |
| 2277 | *y = 0; |
| 2278 | *x = (offset & 4095) / cpp; |
| 2279 | return offset & -4096; |
| 2280 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2281 | } |
| 2282 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2283 | int intel_format_to_fourcc(int format) |
| 2284 | { |
| 2285 | switch (format) { |
| 2286 | case DISPPLANE_8BPP: |
| 2287 | return DRM_FORMAT_C8; |
| 2288 | case DISPPLANE_BGRX555: |
| 2289 | return DRM_FORMAT_XRGB1555; |
| 2290 | case DISPPLANE_BGRX565: |
| 2291 | return DRM_FORMAT_RGB565; |
| 2292 | default: |
| 2293 | case DISPPLANE_BGRX888: |
| 2294 | return DRM_FORMAT_XRGB8888; |
| 2295 | case DISPPLANE_RGBX888: |
| 2296 | return DRM_FORMAT_XBGR8888; |
| 2297 | case DISPPLANE_BGRX101010: |
| 2298 | return DRM_FORMAT_XRGB2101010; |
| 2299 | case DISPPLANE_RGBX101010: |
| 2300 | return DRM_FORMAT_XBGR2101010; |
| 2301 | } |
| 2302 | } |
| 2303 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2304 | static bool intel_alloc_plane_obj(struct intel_crtc *crtc, |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2305 | struct intel_plane_config *plane_config) |
| 2306 | { |
| 2307 | struct drm_device *dev = crtc->base.dev; |
| 2308 | struct drm_i915_gem_object *obj = NULL; |
| 2309 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
| 2310 | u32 base = plane_config->base; |
| 2311 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2312 | if (plane_config->size == 0) |
| 2313 | return false; |
| 2314 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2315 | obj = i915_gem_object_create_stolen_for_preallocated(dev, base, base, |
| 2316 | plane_config->size); |
| 2317 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2318 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2319 | |
| 2320 | if (plane_config->tiled) { |
| 2321 | obj->tiling_mode = I915_TILING_X; |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2322 | obj->stride = crtc->base.primary->fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2323 | } |
| 2324 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2325 | mode_cmd.pixel_format = crtc->base.primary->fb->pixel_format; |
| 2326 | mode_cmd.width = crtc->base.primary->fb->width; |
| 2327 | mode_cmd.height = crtc->base.primary->fb->height; |
| 2328 | mode_cmd.pitches[0] = crtc->base.primary->fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2329 | |
| 2330 | mutex_lock(&dev->struct_mutex); |
| 2331 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2332 | if (intel_framebuffer_init(dev, to_intel_framebuffer(crtc->base.primary->fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2333 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2334 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2335 | goto out_unref_obj; |
| 2336 | } |
| 2337 | |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 2338 | obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2339 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2340 | |
| 2341 | DRM_DEBUG_KMS("plane fb obj %p\n", obj); |
| 2342 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2343 | |
| 2344 | out_unref_obj: |
| 2345 | drm_gem_object_unreference(&obj->base); |
| 2346 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2347 | return false; |
| 2348 | } |
| 2349 | |
| 2350 | static void intel_find_plane_obj(struct intel_crtc *intel_crtc, |
| 2351 | struct intel_plane_config *plane_config) |
| 2352 | { |
| 2353 | struct drm_device *dev = intel_crtc->base.dev; |
| 2354 | struct drm_crtc *c; |
| 2355 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2356 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2357 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2358 | if (!intel_crtc->base.primary->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2359 | return; |
| 2360 | |
| 2361 | if (intel_alloc_plane_obj(intel_crtc, plane_config)) |
| 2362 | return; |
| 2363 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2364 | kfree(intel_crtc->base.primary->fb); |
| 2365 | intel_crtc->base.primary->fb = NULL; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2366 | |
| 2367 | /* |
| 2368 | * Failed to alloc the obj, check to see if we should share |
| 2369 | * an fb with another CRTC instead |
| 2370 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2371 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2372 | i = to_intel_crtc(c); |
| 2373 | |
| 2374 | if (c == &intel_crtc->base) |
| 2375 | continue; |
| 2376 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2377 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2378 | continue; |
| 2379 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2380 | obj = intel_fb_obj(c->primary->fb); |
| 2381 | if (obj == NULL) |
| 2382 | continue; |
| 2383 | |
| 2384 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2385 | drm_framebuffer_reference(c->primary->fb); |
| 2386 | intel_crtc->base.primary->fb = c->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2387 | obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2388 | break; |
| 2389 | } |
| 2390 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2391 | } |
| 2392 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2393 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
| 2394 | struct drm_framebuffer *fb, |
| 2395 | int x, int y) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2396 | { |
| 2397 | struct drm_device *dev = crtc->dev; |
| 2398 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2399 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2400 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2401 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2402 | unsigned long linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2403 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2404 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2405 | int pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2406 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2407 | if (!intel_crtc->primary_enabled) { |
| 2408 | I915_WRITE(reg, 0); |
| 2409 | if (INTEL_INFO(dev)->gen >= 4) |
| 2410 | I915_WRITE(DSPSURF(plane), 0); |
| 2411 | else |
| 2412 | I915_WRITE(DSPADDR(plane), 0); |
| 2413 | POSTING_READ(reg); |
| 2414 | return; |
| 2415 | } |
| 2416 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2417 | obj = intel_fb_obj(fb); |
| 2418 | if (WARN_ON(obj == NULL)) |
| 2419 | return; |
| 2420 | |
| 2421 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2422 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2423 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2424 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2425 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2426 | |
| 2427 | if (INTEL_INFO(dev)->gen < 4) { |
| 2428 | if (intel_crtc->pipe == PIPE_B) |
| 2429 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 2430 | |
| 2431 | /* pipesrc and dspsize control the size that is scaled from, |
| 2432 | * which should always be the user's requested size. |
| 2433 | */ |
| 2434 | I915_WRITE(DSPSIZE(plane), |
| 2435 | ((intel_crtc->config.pipe_src_h - 1) << 16) | |
| 2436 | (intel_crtc->config.pipe_src_w - 1)); |
| 2437 | I915_WRITE(DSPPOS(plane), 0); |
| 2438 | } |
| 2439 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2440 | switch (fb->pixel_format) { |
| 2441 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2442 | dspcntr |= DISPPLANE_8BPP; |
| 2443 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2444 | case DRM_FORMAT_XRGB1555: |
| 2445 | case DRM_FORMAT_ARGB1555: |
| 2446 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2447 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2448 | case DRM_FORMAT_RGB565: |
| 2449 | dspcntr |= DISPPLANE_BGRX565; |
| 2450 | break; |
| 2451 | case DRM_FORMAT_XRGB8888: |
| 2452 | case DRM_FORMAT_ARGB8888: |
| 2453 | dspcntr |= DISPPLANE_BGRX888; |
| 2454 | break; |
| 2455 | case DRM_FORMAT_XBGR8888: |
| 2456 | case DRM_FORMAT_ABGR8888: |
| 2457 | dspcntr |= DISPPLANE_RGBX888; |
| 2458 | break; |
| 2459 | case DRM_FORMAT_XRGB2101010: |
| 2460 | case DRM_FORMAT_ARGB2101010: |
| 2461 | dspcntr |= DISPPLANE_BGRX101010; |
| 2462 | break; |
| 2463 | case DRM_FORMAT_XBGR2101010: |
| 2464 | case DRM_FORMAT_ABGR2101010: |
| 2465 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2466 | break; |
| 2467 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2468 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2469 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2470 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2471 | if (INTEL_INFO(dev)->gen >= 4 && |
| 2472 | obj->tiling_mode != I915_TILING_NONE) |
| 2473 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2474 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 2475 | if (IS_G4X(dev)) |
| 2476 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2477 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2478 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2479 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2480 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2481 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2482 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2483 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2484 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2485 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2486 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2487 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2488 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2489 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2490 | if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) { |
| 2491 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2492 | |
| 2493 | x += (intel_crtc->config.pipe_src_w - 1); |
| 2494 | y += (intel_crtc->config.pipe_src_h - 1); |
| 2495 | |
| 2496 | /* Finding the last pixel of the last line of the display |
| 2497 | data and adding to linear_offset*/ |
| 2498 | linear_offset += |
| 2499 | (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] + |
| 2500 | (intel_crtc->config.pipe_src_w - 1) * pixel_size; |
| 2501 | } |
| 2502 | |
| 2503 | I915_WRITE(reg, dspcntr); |
| 2504 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2505 | DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n", |
| 2506 | i915_gem_obj_ggtt_offset(obj), linear_offset, x, y, |
| 2507 | fb->pitches[0]); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2508 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2509 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2510 | I915_WRITE(DSPSURF(plane), |
| 2511 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2512 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2513 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2514 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2515 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2516 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2517 | } |
| 2518 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2519 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
| 2520 | struct drm_framebuffer *fb, |
| 2521 | int x, int y) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2522 | { |
| 2523 | struct drm_device *dev = crtc->dev; |
| 2524 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2525 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2526 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2527 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2528 | unsigned long linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2529 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2530 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2531 | int pixel_size; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2532 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2533 | if (!intel_crtc->primary_enabled) { |
| 2534 | I915_WRITE(reg, 0); |
| 2535 | I915_WRITE(DSPSURF(plane), 0); |
| 2536 | POSTING_READ(reg); |
| 2537 | return; |
| 2538 | } |
| 2539 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2540 | obj = intel_fb_obj(fb); |
| 2541 | if (WARN_ON(obj == NULL)) |
| 2542 | return; |
| 2543 | |
| 2544 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2545 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2546 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2547 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2548 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2549 | |
| 2550 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 2551 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 2552 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2553 | switch (fb->pixel_format) { |
| 2554 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2555 | dspcntr |= DISPPLANE_8BPP; |
| 2556 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2557 | case DRM_FORMAT_RGB565: |
| 2558 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2559 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2560 | case DRM_FORMAT_XRGB8888: |
| 2561 | case DRM_FORMAT_ARGB8888: |
| 2562 | dspcntr |= DISPPLANE_BGRX888; |
| 2563 | break; |
| 2564 | case DRM_FORMAT_XBGR8888: |
| 2565 | case DRM_FORMAT_ABGR8888: |
| 2566 | dspcntr |= DISPPLANE_RGBX888; |
| 2567 | break; |
| 2568 | case DRM_FORMAT_XRGB2101010: |
| 2569 | case DRM_FORMAT_ARGB2101010: |
| 2570 | dspcntr |= DISPPLANE_BGRX101010; |
| 2571 | break; |
| 2572 | case DRM_FORMAT_XBGR2101010: |
| 2573 | case DRM_FORMAT_ABGR2101010: |
| 2574 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2575 | break; |
| 2576 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2577 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
| 2580 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2581 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2582 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2583 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 2584 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2585 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2586 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2587 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2588 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2589 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2590 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2591 | linear_offset -= intel_crtc->dspaddr_offset; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2592 | if (to_intel_plane(crtc->primary)->rotation == BIT(DRM_ROTATE_180)) { |
| 2593 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2594 | |
| 2595 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
| 2596 | x += (intel_crtc->config.pipe_src_w - 1); |
| 2597 | y += (intel_crtc->config.pipe_src_h - 1); |
| 2598 | |
| 2599 | /* Finding the last pixel of the last line of the display |
| 2600 | data and adding to linear_offset*/ |
| 2601 | linear_offset += |
| 2602 | (intel_crtc->config.pipe_src_h - 1) * fb->pitches[0] + |
| 2603 | (intel_crtc->config.pipe_src_w - 1) * pixel_size; |
| 2604 | } |
| 2605 | } |
| 2606 | |
| 2607 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2608 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2609 | DRM_DEBUG_KMS("Writing base %08lX %08lX %d %d %d\n", |
| 2610 | i915_gem_obj_ggtt_offset(obj), linear_offset, x, y, |
| 2611 | fb->pitches[0]); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2612 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2613 | I915_WRITE(DSPSURF(plane), |
| 2614 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 2615 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2616 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2617 | } else { |
| 2618 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2619 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2620 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2621 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
| 2624 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 2625 | static int |
| 2626 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 2627 | int x, int y, enum mode_set_atomic state) |
| 2628 | { |
| 2629 | struct drm_device *dev = crtc->dev; |
| 2630 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2631 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2632 | if (dev_priv->display.disable_fbc) |
| 2633 | dev_priv->display.disable_fbc(dev); |
Daniel Vetter | cc36513 | 2014-06-18 13:59:13 +0200 | [diff] [blame] | 2634 | intel_increase_pllclock(dev, to_intel_crtc(crtc)->pipe); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2635 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2636 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
| 2637 | |
| 2638 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2639 | } |
| 2640 | |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2641 | void intel_display_handle_reset(struct drm_device *dev) |
| 2642 | { |
| 2643 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2644 | struct drm_crtc *crtc; |
| 2645 | |
| 2646 | /* |
| 2647 | * Flips in the rings have been nuked by the reset, |
| 2648 | * so complete all pending flips so that user space |
| 2649 | * will get its events and not get stuck. |
| 2650 | * |
| 2651 | * Also update the base address of all primary |
| 2652 | * planes to the the last fb to make sure we're |
| 2653 | * showing the correct fb after a reset. |
| 2654 | * |
| 2655 | * Need to make two loops over the crtcs so that we |
| 2656 | * don't try to grab a crtc mutex before the |
| 2657 | * pending_flip_queue really got woken up. |
| 2658 | */ |
| 2659 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2660 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2661 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2662 | enum plane plane = intel_crtc->plane; |
| 2663 | |
| 2664 | intel_prepare_page_flip(dev, plane); |
| 2665 | intel_finish_page_flip_plane(dev, plane); |
| 2666 | } |
| 2667 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2668 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2669 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2670 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 2671 | drm_modeset_lock(&crtc->mutex, NULL); |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 2672 | /* |
| 2673 | * FIXME: Once we have proper support for primary planes (and |
| 2674 | * disabling them without disabling the entire crtc) allow again |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2675 | * a NULL crtc->primary->fb. |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 2676 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2677 | if (intel_crtc->active && crtc->primary->fb) |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2678 | dev_priv->display.update_primary_plane(crtc, |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2679 | crtc->primary->fb, |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2680 | crtc->x, |
| 2681 | crtc->y); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 2682 | drm_modeset_unlock(&crtc->mutex); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2683 | } |
| 2684 | } |
| 2685 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2686 | static int |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2687 | intel_finish_fb(struct drm_framebuffer *old_fb) |
| 2688 | { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2689 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2690 | struct drm_i915_private *dev_priv = obj->base.dev->dev_private; |
| 2691 | bool was_interruptible = dev_priv->mm.interruptible; |
| 2692 | int ret; |
| 2693 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2694 | /* Big Hammer, we also need to ensure that any pending |
| 2695 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 2696 | * current scanout is retired before unpinning the old |
| 2697 | * framebuffer. |
| 2698 | * |
| 2699 | * This should only fail upon a hung GPU, in which case we |
| 2700 | * can safely continue. |
| 2701 | */ |
| 2702 | dev_priv->mm.interruptible = false; |
| 2703 | ret = i915_gem_object_finish_gpu(obj); |
| 2704 | dev_priv->mm.interruptible = was_interruptible; |
| 2705 | |
| 2706 | return ret; |
| 2707 | } |
| 2708 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 2709 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 2710 | { |
| 2711 | struct drm_device *dev = crtc->dev; |
| 2712 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2713 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2714 | unsigned long flags; |
| 2715 | bool pending; |
| 2716 | |
| 2717 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 2718 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 2719 | return false; |
| 2720 | |
| 2721 | spin_lock_irqsave(&dev->event_lock, flags); |
| 2722 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
| 2723 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 2724 | |
| 2725 | return pending; |
| 2726 | } |
| 2727 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 2728 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
| 2729 | { |
| 2730 | struct drm_device *dev = crtc->base.dev; |
| 2731 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2732 | const struct drm_display_mode *adjusted_mode; |
| 2733 | |
| 2734 | if (!i915.fastboot) |
| 2735 | return; |
| 2736 | |
| 2737 | /* |
| 2738 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 2739 | * that in compute_mode_changes we check the native mode (not the pfit |
| 2740 | * mode) to see if we can flip rather than do a full mode set. In the |
| 2741 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 2742 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 2743 | * sized surface. |
| 2744 | * |
| 2745 | * To fix this properly, we need to hoist the checks up into |
| 2746 | * compute_mode_changes (or above), check the actual pfit state and |
| 2747 | * whether the platform allows pfit disable with pipe active, and only |
| 2748 | * then update the pipesrc and pfit state, even on the flip path. |
| 2749 | */ |
| 2750 | |
| 2751 | adjusted_mode = &crtc->config.adjusted_mode; |
| 2752 | |
| 2753 | I915_WRITE(PIPESRC(crtc->pipe), |
| 2754 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | |
| 2755 | (adjusted_mode->crtc_vdisplay - 1)); |
| 2756 | if (!crtc->config.pch_pfit.enabled && |
| 2757 | (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) || |
| 2758 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP))) { |
| 2759 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
| 2760 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); |
| 2761 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); |
| 2762 | } |
| 2763 | crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay; |
| 2764 | crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay; |
| 2765 | } |
| 2766 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2767 | static int |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2768 | intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2769 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2770 | { |
| 2771 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2772 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2773 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 2774 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2775 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
| 2776 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 2777 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2778 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2779 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 2780 | if (intel_crtc_has_pending_flip(crtc)) { |
| 2781 | DRM_ERROR("pipe is still busy with an old pageflip\n"); |
| 2782 | return -EBUSY; |
| 2783 | } |
| 2784 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2785 | /* no fb bound */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2786 | if (!fb) { |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2787 | DRM_ERROR("No FB bound\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2788 | return 0; |
| 2789 | } |
| 2790 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 2791 | if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 2792 | DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n", |
| 2793 | plane_name(intel_crtc->plane), |
| 2794 | INTEL_INFO(dev)->num_pipes); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2795 | return -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2796 | } |
| 2797 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2798 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 2799 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
| 2800 | if (ret == 0) |
Matt Roper | 91565c8 | 2014-06-24 17:05:02 -0700 | [diff] [blame] | 2801 | i915_gem_track_fb(old_obj, obj, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 2802 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Ville Syrjälä | 8ac36ec | 2014-03-11 19:37:33 +0200 | [diff] [blame] | 2803 | mutex_unlock(&dev->struct_mutex); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2804 | if (ret != 0) { |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2805 | DRM_ERROR("pin & fence failed\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2806 | return ret; |
| 2807 | } |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2808 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 2809 | intel_update_pipe_size(intel_crtc); |
Jesse Barnes | 4d6a3e6 | 2013-06-26 01:38:18 +0300 | [diff] [blame] | 2810 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2811 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2812 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 2813 | if (intel_crtc->active) |
| 2814 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 2815 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2816 | crtc->primary->fb = fb; |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 2817 | crtc->x = x; |
| 2818 | crtc->y = y; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2819 | |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 2820 | if (old_fb) { |
Daniel Vetter | d7697ee | 2013-06-02 17:23:01 +0200 | [diff] [blame] | 2821 | if (intel_crtc->active && old_fb != fb) |
| 2822 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Ville Syrjälä | 8ac36ec | 2014-03-11 19:37:33 +0200 | [diff] [blame] | 2823 | mutex_lock(&dev->struct_mutex); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2824 | intel_unpin_fb_obj(old_obj); |
Ville Syrjälä | 8ac36ec | 2014-03-11 19:37:33 +0200 | [diff] [blame] | 2825 | mutex_unlock(&dev->struct_mutex); |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 2826 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2827 | |
Ville Syrjälä | 8ac36ec | 2014-03-11 19:37:33 +0200 | [diff] [blame] | 2828 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2829 | intel_update_fbc(dev); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2830 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2831 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2832 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2833 | } |
| 2834 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2835 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 2836 | { |
| 2837 | struct drm_device *dev = crtc->dev; |
| 2838 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2839 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2840 | int pipe = intel_crtc->pipe; |
| 2841 | u32 reg, temp; |
| 2842 | |
| 2843 | /* enable normal train */ |
| 2844 | reg = FDI_TX_CTL(pipe); |
| 2845 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 2846 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2847 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 2848 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 2849 | } else { |
| 2850 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2851 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2852 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2853 | I915_WRITE(reg, temp); |
| 2854 | |
| 2855 | reg = FDI_RX_CTL(pipe); |
| 2856 | temp = I915_READ(reg); |
| 2857 | if (HAS_PCH_CPT(dev)) { |
| 2858 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2859 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 2860 | } else { |
| 2861 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2862 | temp |= FDI_LINK_TRAIN_NONE; |
| 2863 | } |
| 2864 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 2865 | |
| 2866 | /* wait one idle pattern time */ |
| 2867 | POSTING_READ(reg); |
| 2868 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2869 | |
| 2870 | /* IVB wants error correction enabled */ |
| 2871 | if (IS_IVYBRIDGE(dev)) |
| 2872 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 2873 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2874 | } |
| 2875 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 2876 | static bool pipe_has_enabled_pch(struct intel_crtc *crtc) |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 2877 | { |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 2878 | return crtc->base.enabled && crtc->active && |
| 2879 | crtc->config.has_pch_encoder; |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 2880 | } |
| 2881 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2882 | static void ivb_modeset_global_resources(struct drm_device *dev) |
| 2883 | { |
| 2884 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2885 | struct intel_crtc *pipe_B_crtc = |
| 2886 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]); |
| 2887 | struct intel_crtc *pipe_C_crtc = |
| 2888 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]); |
| 2889 | uint32_t temp; |
| 2890 | |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 2891 | /* |
| 2892 | * When everything is off disable fdi C so that we could enable fdi B |
| 2893 | * with all lanes. Note that we don't care about enabled pipes without |
| 2894 | * an enabled pch encoder. |
| 2895 | */ |
| 2896 | if (!pipe_has_enabled_pch(pipe_B_crtc) && |
| 2897 | !pipe_has_enabled_pch(pipe_C_crtc)) { |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2898 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 2899 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 2900 | |
| 2901 | temp = I915_READ(SOUTH_CHICKEN1); |
| 2902 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 2903 | DRM_DEBUG_KMS("disabling fdi C rx\n"); |
| 2904 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 2905 | } |
| 2906 | } |
| 2907 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2908 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 2909 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 2910 | { |
| 2911 | struct drm_device *dev = crtc->dev; |
| 2912 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2913 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2914 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2915 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2916 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 2917 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2918 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2919 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2920 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 2921 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2922 | reg = FDI_RX_IMR(pipe); |
| 2923 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2924 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 2925 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2926 | I915_WRITE(reg, temp); |
| 2927 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2928 | udelay(150); |
| 2929 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2930 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2931 | reg = FDI_TX_CTL(pipe); |
| 2932 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 2933 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
| 2934 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2935 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2936 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2937 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2938 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2939 | reg = FDI_RX_CTL(pipe); |
| 2940 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2941 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2942 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2943 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 2944 | |
| 2945 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2946 | udelay(150); |
| 2947 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2948 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 2949 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 2950 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 2951 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2952 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2953 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2954 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2955 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2956 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2957 | |
| 2958 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 2959 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2960 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2961 | break; |
| 2962 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2963 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2964 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2965 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2966 | |
| 2967 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2968 | reg = FDI_TX_CTL(pipe); |
| 2969 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2970 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2971 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2972 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2973 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2974 | reg = FDI_RX_CTL(pipe); |
| 2975 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2976 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2977 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2978 | I915_WRITE(reg, temp); |
| 2979 | |
| 2980 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2981 | udelay(150); |
| 2982 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2983 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2984 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2985 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2986 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2987 | |
| 2988 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2989 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2990 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 2991 | break; |
| 2992 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2993 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2994 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2995 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2996 | |
| 2997 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 2998 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2999 | } |
| 3000 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3001 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3002 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3003 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3004 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3005 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3006 | }; |
| 3007 | |
| 3008 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3009 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3010 | { |
| 3011 | struct drm_device *dev = crtc->dev; |
| 3012 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3013 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3014 | int pipe = intel_crtc->pipe; |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3015 | u32 reg, temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3016 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3017 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3018 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3019 | reg = FDI_RX_IMR(pipe); |
| 3020 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3021 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3022 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3023 | I915_WRITE(reg, temp); |
| 3024 | |
| 3025 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3026 | udelay(150); |
| 3027 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3028 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3029 | reg = FDI_TX_CTL(pipe); |
| 3030 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3031 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
| 3032 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3033 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3034 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3035 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3036 | /* SNB-B */ |
| 3037 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3038 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3039 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3040 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3041 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3042 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3043 | reg = FDI_RX_CTL(pipe); |
| 3044 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3045 | if (HAS_PCH_CPT(dev)) { |
| 3046 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3047 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3048 | } else { |
| 3049 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3050 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3051 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3052 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3053 | |
| 3054 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3055 | udelay(150); |
| 3056 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3057 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3058 | reg = FDI_TX_CTL(pipe); |
| 3059 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3060 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3061 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3062 | I915_WRITE(reg, temp); |
| 3063 | |
| 3064 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3065 | udelay(500); |
| 3066 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3067 | for (retry = 0; retry < 5; retry++) { |
| 3068 | reg = FDI_RX_IIR(pipe); |
| 3069 | temp = I915_READ(reg); |
| 3070 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3071 | if (temp & FDI_RX_BIT_LOCK) { |
| 3072 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3073 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3074 | break; |
| 3075 | } |
| 3076 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3077 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3078 | if (retry < 5) |
| 3079 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3080 | } |
| 3081 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3082 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3083 | |
| 3084 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3085 | reg = FDI_TX_CTL(pipe); |
| 3086 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3087 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3088 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3089 | if (IS_GEN6(dev)) { |
| 3090 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3091 | /* SNB-B */ |
| 3092 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3093 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3094 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3095 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3096 | reg = FDI_RX_CTL(pipe); |
| 3097 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3098 | if (HAS_PCH_CPT(dev)) { |
| 3099 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3100 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3101 | } else { |
| 3102 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3103 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3104 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3105 | I915_WRITE(reg, temp); |
| 3106 | |
| 3107 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3108 | udelay(150); |
| 3109 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3110 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3111 | reg = FDI_TX_CTL(pipe); |
| 3112 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3113 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3114 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3115 | I915_WRITE(reg, temp); |
| 3116 | |
| 3117 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3118 | udelay(500); |
| 3119 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3120 | for (retry = 0; retry < 5; retry++) { |
| 3121 | reg = FDI_RX_IIR(pipe); |
| 3122 | temp = I915_READ(reg); |
| 3123 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3124 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3125 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3126 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3127 | break; |
| 3128 | } |
| 3129 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3130 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3131 | if (retry < 5) |
| 3132 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3133 | } |
| 3134 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3135 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3136 | |
| 3137 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3138 | } |
| 3139 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3140 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3141 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3142 | { |
| 3143 | struct drm_device *dev = crtc->dev; |
| 3144 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3145 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3146 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3147 | u32 reg, temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3148 | |
| 3149 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3150 | for train result */ |
| 3151 | reg = FDI_RX_IMR(pipe); |
| 3152 | temp = I915_READ(reg); |
| 3153 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3154 | temp &= ~FDI_RX_BIT_LOCK; |
| 3155 | I915_WRITE(reg, temp); |
| 3156 | |
| 3157 | POSTING_READ(reg); |
| 3158 | udelay(150); |
| 3159 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3160 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3161 | I915_READ(FDI_RX_IIR(pipe))); |
| 3162 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3163 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3164 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3165 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3166 | reg = FDI_TX_CTL(pipe); |
| 3167 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3168 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3169 | temp &= ~FDI_TX_ENABLE; |
| 3170 | I915_WRITE(reg, temp); |
| 3171 | |
| 3172 | reg = FDI_RX_CTL(pipe); |
| 3173 | temp = I915_READ(reg); |
| 3174 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3175 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3176 | temp &= ~FDI_RX_ENABLE; |
| 3177 | I915_WRITE(reg, temp); |
| 3178 | |
| 3179 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3180 | reg = FDI_TX_CTL(pipe); |
| 3181 | temp = I915_READ(reg); |
| 3182 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
| 3183 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
| 3184 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3185 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3186 | temp |= snb_b_fdi_train_param[j/2]; |
| 3187 | temp |= FDI_COMPOSITE_SYNC; |
| 3188 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3189 | |
| 3190 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3191 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3192 | |
| 3193 | reg = FDI_RX_CTL(pipe); |
| 3194 | temp = I915_READ(reg); |
| 3195 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3196 | temp |= FDI_COMPOSITE_SYNC; |
| 3197 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3198 | |
| 3199 | POSTING_READ(reg); |
| 3200 | udelay(1); /* should be 0.5us */ |
| 3201 | |
| 3202 | for (i = 0; i < 4; i++) { |
| 3203 | reg = FDI_RX_IIR(pipe); |
| 3204 | temp = I915_READ(reg); |
| 3205 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3206 | |
| 3207 | if (temp & FDI_RX_BIT_LOCK || |
| 3208 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3209 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3210 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3211 | i); |
| 3212 | break; |
| 3213 | } |
| 3214 | udelay(1); /* should be 0.5us */ |
| 3215 | } |
| 3216 | if (i == 4) { |
| 3217 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3218 | continue; |
| 3219 | } |
| 3220 | |
| 3221 | /* Train 2 */ |
| 3222 | reg = FDI_TX_CTL(pipe); |
| 3223 | temp = I915_READ(reg); |
| 3224 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3225 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3226 | I915_WRITE(reg, temp); |
| 3227 | |
| 3228 | reg = FDI_RX_CTL(pipe); |
| 3229 | temp = I915_READ(reg); |
| 3230 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3231 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3232 | I915_WRITE(reg, temp); |
| 3233 | |
| 3234 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3235 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3236 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3237 | for (i = 0; i < 4; i++) { |
| 3238 | reg = FDI_RX_IIR(pipe); |
| 3239 | temp = I915_READ(reg); |
| 3240 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3241 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3242 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3243 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3244 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3245 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3246 | i); |
| 3247 | goto train_done; |
| 3248 | } |
| 3249 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3250 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3251 | if (i == 4) |
| 3252 | DRM_DEBUG_KMS("FDI train 2 fail on vswing %d\n", j / 2); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3253 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3254 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3255 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3256 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3257 | } |
| 3258 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3259 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3260 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3261 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3262 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3263 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3264 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3265 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3266 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3267 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3268 | reg = FDI_RX_CTL(pipe); |
| 3269 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3270 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
| 3271 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3272 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3273 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3274 | |
| 3275 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3276 | udelay(200); |
| 3277 | |
| 3278 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3279 | temp = I915_READ(reg); |
| 3280 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3281 | |
| 3282 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3283 | udelay(200); |
| 3284 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3285 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3286 | reg = FDI_TX_CTL(pipe); |
| 3287 | temp = I915_READ(reg); |
| 3288 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3289 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3290 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3291 | POSTING_READ(reg); |
| 3292 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3293 | } |
| 3294 | } |
| 3295 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3296 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3297 | { |
| 3298 | struct drm_device *dev = intel_crtc->base.dev; |
| 3299 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3300 | int pipe = intel_crtc->pipe; |
| 3301 | u32 reg, temp; |
| 3302 | |
| 3303 | /* Switch from PCDclk to Rawclk */ |
| 3304 | reg = FDI_RX_CTL(pipe); |
| 3305 | temp = I915_READ(reg); |
| 3306 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3307 | |
| 3308 | /* Disable CPU FDI TX PLL */ |
| 3309 | reg = FDI_TX_CTL(pipe); |
| 3310 | temp = I915_READ(reg); |
| 3311 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3312 | |
| 3313 | POSTING_READ(reg); |
| 3314 | udelay(100); |
| 3315 | |
| 3316 | reg = FDI_RX_CTL(pipe); |
| 3317 | temp = I915_READ(reg); |
| 3318 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3319 | |
| 3320 | /* Wait for the clocks to turn off. */ |
| 3321 | POSTING_READ(reg); |
| 3322 | udelay(100); |
| 3323 | } |
| 3324 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3325 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3326 | { |
| 3327 | struct drm_device *dev = crtc->dev; |
| 3328 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3329 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3330 | int pipe = intel_crtc->pipe; |
| 3331 | u32 reg, temp; |
| 3332 | |
| 3333 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3334 | reg = FDI_TX_CTL(pipe); |
| 3335 | temp = I915_READ(reg); |
| 3336 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3337 | POSTING_READ(reg); |
| 3338 | |
| 3339 | reg = FDI_RX_CTL(pipe); |
| 3340 | temp = I915_READ(reg); |
| 3341 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3342 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3343 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3344 | |
| 3345 | POSTING_READ(reg); |
| 3346 | udelay(100); |
| 3347 | |
| 3348 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3349 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3350 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3351 | |
| 3352 | /* still set train pattern 1 */ |
| 3353 | reg = FDI_TX_CTL(pipe); |
| 3354 | temp = I915_READ(reg); |
| 3355 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3356 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3357 | I915_WRITE(reg, temp); |
| 3358 | |
| 3359 | reg = FDI_RX_CTL(pipe); |
| 3360 | temp = I915_READ(reg); |
| 3361 | if (HAS_PCH_CPT(dev)) { |
| 3362 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3363 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3364 | } else { |
| 3365 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3366 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3367 | } |
| 3368 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3369 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3370 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3371 | I915_WRITE(reg, temp); |
| 3372 | |
| 3373 | POSTING_READ(reg); |
| 3374 | udelay(100); |
| 3375 | } |
| 3376 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3377 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3378 | { |
| 3379 | struct intel_crtc *crtc; |
| 3380 | |
| 3381 | /* Note that we don't need to be called with mode_config.lock here |
| 3382 | * as our list of CRTC objects is static for the lifetime of the |
| 3383 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3384 | * happily treat the predicates as racy, atomic checks as userspace |
| 3385 | * cannot claim and pin a new fb without at least acquring the |
| 3386 | * struct_mutex and so serialising with us. |
| 3387 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3388 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3389 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3390 | continue; |
| 3391 | |
| 3392 | if (crtc->unpin_work) |
| 3393 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3394 | |
| 3395 | return true; |
| 3396 | } |
| 3397 | |
| 3398 | return false; |
| 3399 | } |
| 3400 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3401 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
| 3402 | { |
| 3403 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 3404 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 3405 | |
| 3406 | /* ensure that the unpin work is consistent wrt ->pending. */ |
| 3407 | smp_rmb(); |
| 3408 | intel_crtc->unpin_work = NULL; |
| 3409 | |
| 3410 | if (work->event) |
| 3411 | drm_send_vblank_event(intel_crtc->base.dev, |
| 3412 | intel_crtc->pipe, |
| 3413 | work->event); |
| 3414 | |
| 3415 | drm_crtc_vblank_put(&intel_crtc->base); |
| 3416 | |
| 3417 | wake_up_all(&dev_priv->pending_flip_queue); |
| 3418 | queue_work(dev_priv->wq, &work->work); |
| 3419 | |
| 3420 | trace_i915_flip_complete(intel_crtc->plane, |
| 3421 | work->pending_flip_obj); |
| 3422 | } |
| 3423 | |
Ville Syrjälä | 46a55d3 | 2014-05-21 14:04:46 +0300 | [diff] [blame] | 3424 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3425 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3426 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3427 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3428 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3429 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3430 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
| 3431 | !intel_crtc_has_pending_flip(crtc), |
| 3432 | 60*HZ) == 0)) { |
| 3433 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3434 | unsigned long flags; |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3435 | |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3436 | spin_lock_irqsave(&dev->event_lock, flags); |
| 3437 | if (intel_crtc->unpin_work) { |
| 3438 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 3439 | page_flip_completed(intel_crtc); |
| 3440 | } |
| 3441 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 3442 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3443 | |
Chris Wilson | 975d568 | 2014-08-20 13:13:34 +0100 | [diff] [blame] | 3444 | if (crtc->primary->fb) { |
| 3445 | mutex_lock(&dev->struct_mutex); |
| 3446 | intel_finish_fb(crtc->primary->fb); |
| 3447 | mutex_unlock(&dev->struct_mutex); |
| 3448 | } |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3449 | } |
| 3450 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3451 | /* Program iCLKIP clock to the desired frequency */ |
| 3452 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3453 | { |
| 3454 | struct drm_device *dev = crtc->dev; |
| 3455 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 3456 | int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3457 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3458 | u32 temp; |
| 3459 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3460 | mutex_lock(&dev_priv->dpio_lock); |
| 3461 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3462 | /* It is necessary to ungate the pixclk gate prior to programming |
| 3463 | * the divisors, and gate it back when it is done. |
| 3464 | */ |
| 3465 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3466 | |
| 3467 | /* Disable SSCCTL */ |
| 3468 | intel_sbi_write(dev_priv, SBI_SSCCTL6, |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3469 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
| 3470 | SBI_SSCCTL_DISABLE, |
| 3471 | SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3472 | |
| 3473 | /* 20MHz is a corner case which is out of range for the 7-bit divisor */ |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 3474 | if (clock == 20000) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3475 | auxdiv = 1; |
| 3476 | divsel = 0x41; |
| 3477 | phaseinc = 0x20; |
| 3478 | } else { |
| 3479 | /* The iCLK virtual clock root frequency is in MHz, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 3480 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3481 | * divisors, it is necessary to divide one by another, so we |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3482 | * convert the virtual clock precision to KHz here for higher |
| 3483 | * precision. |
| 3484 | */ |
| 3485 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3486 | u32 iclk_pi_range = 64; |
| 3487 | u32 desired_divisor, msb_divisor_value, pi_value; |
| 3488 | |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 3489 | desired_divisor = (iclk_virtual_root_freq / clock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3490 | msb_divisor_value = desired_divisor / iclk_pi_range; |
| 3491 | pi_value = desired_divisor % iclk_pi_range; |
| 3492 | |
| 3493 | auxdiv = 0; |
| 3494 | divsel = msb_divisor_value - 2; |
| 3495 | phaseinc = pi_value; |
| 3496 | } |
| 3497 | |
| 3498 | /* This should not happen with any sane values */ |
| 3499 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 3500 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 3501 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 3502 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 3503 | |
| 3504 | DRM_DEBUG_KMS("iCLKIP clock: found settings for %dKHz refresh rate: auxdiv=%x, divsel=%x, phasedir=%x, phaseinc=%x\n", |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 3505 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3506 | auxdiv, |
| 3507 | divsel, |
| 3508 | phasedir, |
| 3509 | phaseinc); |
| 3510 | |
| 3511 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3512 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3513 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3514 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3515 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3516 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3517 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3518 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3519 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3520 | |
| 3521 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3522 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3523 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3524 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3525 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3526 | |
| 3527 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3528 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3529 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3530 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3531 | |
| 3532 | /* Wait for initialization time */ |
| 3533 | udelay(24); |
| 3534 | |
| 3535 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3536 | |
| 3537 | mutex_unlock(&dev_priv->dpio_lock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3538 | } |
| 3539 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3540 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 3541 | enum pipe pch_transcoder) |
| 3542 | { |
| 3543 | struct drm_device *dev = crtc->base.dev; |
| 3544 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3545 | enum transcoder cpu_transcoder = crtc->config.cpu_transcoder; |
| 3546 | |
| 3547 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 3548 | I915_READ(HTOTAL(cpu_transcoder))); |
| 3549 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 3550 | I915_READ(HBLANK(cpu_transcoder))); |
| 3551 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 3552 | I915_READ(HSYNC(cpu_transcoder))); |
| 3553 | |
| 3554 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 3555 | I915_READ(VTOTAL(cpu_transcoder))); |
| 3556 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 3557 | I915_READ(VBLANK(cpu_transcoder))); |
| 3558 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 3559 | I915_READ(VSYNC(cpu_transcoder))); |
| 3560 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 3561 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 3562 | } |
| 3563 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3564 | static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev) |
| 3565 | { |
| 3566 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3567 | uint32_t temp; |
| 3568 | |
| 3569 | temp = I915_READ(SOUTH_CHICKEN1); |
| 3570 | if (temp & FDI_BC_BIFURCATION_SELECT) |
| 3571 | return; |
| 3572 | |
| 3573 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 3574 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 3575 | |
| 3576 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 3577 | DRM_DEBUG_KMS("enabling fdi C rx\n"); |
| 3578 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 3579 | POSTING_READ(SOUTH_CHICKEN1); |
| 3580 | } |
| 3581 | |
| 3582 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 3583 | { |
| 3584 | struct drm_device *dev = intel_crtc->base.dev; |
| 3585 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3586 | |
| 3587 | switch (intel_crtc->pipe) { |
| 3588 | case PIPE_A: |
| 3589 | break; |
| 3590 | case PIPE_B: |
| 3591 | if (intel_crtc->config.fdi_lanes > 2) |
| 3592 | WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT); |
| 3593 | else |
| 3594 | cpt_enable_fdi_bc_bifurcation(dev); |
| 3595 | |
| 3596 | break; |
| 3597 | case PIPE_C: |
| 3598 | cpt_enable_fdi_bc_bifurcation(dev); |
| 3599 | |
| 3600 | break; |
| 3601 | default: |
| 3602 | BUG(); |
| 3603 | } |
| 3604 | } |
| 3605 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3606 | /* |
| 3607 | * Enable PCH resources required for PCH ports: |
| 3608 | * - PCH PLLs |
| 3609 | * - FDI training & RX/TX |
| 3610 | * - update transcoder timings |
| 3611 | * - DP transcoding bits |
| 3612 | * - transcoder |
| 3613 | */ |
| 3614 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3615 | { |
| 3616 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3617 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3618 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3619 | int pipe = intel_crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3620 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3621 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 3622 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 3623 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3624 | if (IS_IVYBRIDGE(dev)) |
| 3625 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 3626 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 3627 | /* Write the TU size bits before fdi link training, so that error |
| 3628 | * detection works. */ |
| 3629 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 3630 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 3631 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3632 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 3633 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3634 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3635 | /* We need to program the right clock selection before writing the pixel |
| 3636 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3637 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3638 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 3639 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3640 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 3641 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 3642 | sel = TRANS_DPLLB_SEL(pipe); |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 3643 | if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3644 | temp |= sel; |
| 3645 | else |
| 3646 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3647 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3648 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3649 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3650 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 3651 | * transcoder, and we actually should do this to not upset any PCH |
| 3652 | * transcoder that already use the clock when we share it. |
| 3653 | * |
| 3654 | * Note that enable_shared_dpll tries to do the right thing, but |
| 3655 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 3656 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 3657 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3658 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 3659 | /* set transcoder timing, panel must allow it */ |
| 3660 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3661 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3662 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3663 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3664 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3665 | /* For PCH DP, enable TRANS_DP_CTL */ |
| 3666 | if (HAS_PCH_CPT(dev) && |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 3667 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 3668 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3669 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3670 | reg = TRANS_DP_CTL(pipe); |
| 3671 | temp = I915_READ(reg); |
| 3672 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 3673 | TRANS_DP_SYNC_MASK | |
| 3674 | TRANS_DP_BPC_MASK); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3675 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
| 3676 | TRANS_DP_ENH_FRAMING); |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 3677 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3678 | |
| 3679 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3680 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3681 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3682 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3683 | |
| 3684 | switch (intel_trans_dp_port_sel(crtc)) { |
| 3685 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3686 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3687 | break; |
| 3688 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3689 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3690 | break; |
| 3691 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3692 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3693 | break; |
| 3694 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 3695 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3696 | } |
| 3697 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3698 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3699 | } |
| 3700 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 3701 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3702 | } |
| 3703 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3704 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 3705 | { |
| 3706 | struct drm_device *dev = crtc->dev; |
| 3707 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3708 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 3709 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3710 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 3711 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3712 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 3713 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3714 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 3715 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3716 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3717 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 3718 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3719 | } |
| 3720 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 3721 | void intel_put_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3722 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3723 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3724 | |
| 3725 | if (pll == NULL) |
| 3726 | return; |
| 3727 | |
| 3728 | if (pll->refcount == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3729 | WARN(1, "bad %s refcount\n", pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3730 | return; |
| 3731 | } |
| 3732 | |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 3733 | if (--pll->refcount == 0) { |
| 3734 | WARN_ON(pll->on); |
| 3735 | WARN_ON(pll->active); |
| 3736 | } |
| 3737 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 3738 | crtc->config.shared_dpll = DPLL_ID_PRIVATE; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3739 | } |
| 3740 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 3741 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3742 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3743 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 3744 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 3745 | enum intel_dpll_id i; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3746 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3747 | if (pll) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3748 | DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n", |
| 3749 | crtc->base.base.id, pll->name); |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3750 | intel_put_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3751 | } |
| 3752 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3753 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 3754 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 3755 | i = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3756 | pll = &dev_priv->shared_dplls[i]; |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3757 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3758 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 3759 | crtc->base.base.id, pll->name); |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3760 | |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 3761 | WARN_ON(pll->refcount); |
| 3762 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3763 | goto found; |
| 3764 | } |
| 3765 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3766 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 3767 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3768 | |
| 3769 | /* Only want to check enabled timings first */ |
| 3770 | if (pll->refcount == 0) |
| 3771 | continue; |
| 3772 | |
Daniel Vetter | b89a1d3 | 2013-06-05 13:34:24 +0200 | [diff] [blame] | 3773 | if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state, |
| 3774 | sizeof(pll->hw_state)) == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3775 | 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] | 3776 | crtc->base.base.id, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3777 | pll->name, pll->refcount, pll->active); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3778 | |
| 3779 | goto found; |
| 3780 | } |
| 3781 | } |
| 3782 | |
| 3783 | /* Ok no matching timings, maybe there's a free one? */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3784 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 3785 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3786 | if (pll->refcount == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3787 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
| 3788 | crtc->base.base.id, pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3789 | goto found; |
| 3790 | } |
| 3791 | } |
| 3792 | |
| 3793 | return NULL; |
| 3794 | |
| 3795 | found: |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 3796 | if (pll->refcount == 0) |
| 3797 | pll->hw_state = crtc->config.dpll_hw_state; |
| 3798 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 3799 | crtc->config.shared_dpll = i; |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3800 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
| 3801 | pipe_name(crtc->pipe)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 3802 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3803 | pll->refcount++; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3804 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3805 | return pll; |
| 3806 | } |
| 3807 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 3808 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3809 | { |
| 3810 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 3811 | int dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3812 | u32 temp; |
| 3813 | |
| 3814 | temp = I915_READ(dslreg); |
| 3815 | udelay(500); |
| 3816 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3817 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 3818 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3819 | } |
| 3820 | } |
| 3821 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 3822 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 3823 | { |
| 3824 | struct drm_device *dev = crtc->base.dev; |
| 3825 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3826 | int pipe = crtc->pipe; |
| 3827 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 3828 | if (crtc->config.pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 3829 | /* Force use of hard-coded filter coefficients |
| 3830 | * as some pre-programmed values are broken, |
| 3831 | * e.g. x201. |
| 3832 | */ |
| 3833 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 3834 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 3835 | PF_PIPE_SEL_IVB(pipe)); |
| 3836 | else |
| 3837 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
| 3838 | I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos); |
| 3839 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 3840 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3841 | } |
| 3842 | |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3843 | static void intel_enable_planes(struct drm_crtc *crtc) |
| 3844 | { |
| 3845 | struct drm_device *dev = crtc->dev; |
| 3846 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3847 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3848 | struct intel_plane *intel_plane; |
| 3849 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3850 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 3851 | intel_plane = to_intel_plane(plane); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3852 | if (intel_plane->pipe == pipe) |
| 3853 | intel_plane_restore(&intel_plane->base); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3854 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3855 | } |
| 3856 | |
| 3857 | static void intel_disable_planes(struct drm_crtc *crtc) |
| 3858 | { |
| 3859 | struct drm_device *dev = crtc->dev; |
| 3860 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3861 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3862 | struct intel_plane *intel_plane; |
| 3863 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3864 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 3865 | intel_plane = to_intel_plane(plane); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3866 | if (intel_plane->pipe == pipe) |
| 3867 | intel_plane_disable(&intel_plane->base); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3868 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3869 | } |
| 3870 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 3871 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3872 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 3873 | struct drm_device *dev = crtc->base.dev; |
| 3874 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3875 | |
| 3876 | if (!crtc->config.ips_enabled) |
| 3877 | return; |
| 3878 | |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 3879 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
| 3880 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3881 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3882 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 3883 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 3884 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3885 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 3886 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3887 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 3888 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 3889 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 3890 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 3891 | */ |
| 3892 | } else { |
| 3893 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 3894 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 3895 | * is essentially intel_wait_for_vblank. If we don't have this |
| 3896 | * and don't wait for vblanks until the end of crtc_enable, then |
| 3897 | * the HW state readout code will complain that the expected |
| 3898 | * IPS_CTL value is not the one we read. */ |
| 3899 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 3900 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 3901 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3902 | } |
| 3903 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 3904 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3905 | { |
| 3906 | struct drm_device *dev = crtc->base.dev; |
| 3907 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3908 | |
| 3909 | if (!crtc->config.ips_enabled) |
| 3910 | return; |
| 3911 | |
| 3912 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 3913 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 3914 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3915 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 3916 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 3917 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 3918 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 3919 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 3920 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 3921 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 3922 | POSTING_READ(IPS_CTL); |
| 3923 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3924 | |
| 3925 | /* We need to wait for a vblank before we can disable the plane. */ |
| 3926 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3927 | } |
| 3928 | |
| 3929 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 3930 | static void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 3931 | { |
| 3932 | struct drm_device *dev = crtc->dev; |
| 3933 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3934 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3935 | enum pipe pipe = intel_crtc->pipe; |
| 3936 | int palreg = PALETTE(pipe); |
| 3937 | int i; |
| 3938 | bool reenable_ips = false; |
| 3939 | |
| 3940 | /* The clocks have to be on to load the palette. */ |
| 3941 | if (!crtc->enabled || !intel_crtc->active) |
| 3942 | return; |
| 3943 | |
| 3944 | if (!HAS_PCH_SPLIT(dev_priv->dev)) { |
| 3945 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
| 3946 | assert_dsi_pll_enabled(dev_priv); |
| 3947 | else |
| 3948 | assert_pll_enabled(dev_priv, pipe); |
| 3949 | } |
| 3950 | |
| 3951 | /* use legacy palette for Ironlake */ |
Sonika Jindal | 7a1db49 | 2014-07-22 11:18:27 +0530 | [diff] [blame] | 3952 | if (!HAS_GMCH_DISPLAY(dev)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3953 | palreg = LGC_PALETTE(pipe); |
| 3954 | |
| 3955 | /* Workaround : Do not read or write the pipe palette/gamma data while |
| 3956 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 3957 | */ |
Paulo Zanoni | 41e6fc4 | 2014-01-08 17:26:31 -0200 | [diff] [blame] | 3958 | if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled && |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3959 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
| 3960 | GAMMA_MODE_MODE_SPLIT)) { |
| 3961 | hsw_disable_ips(intel_crtc); |
| 3962 | reenable_ips = true; |
| 3963 | } |
| 3964 | |
| 3965 | for (i = 0; i < 256; i++) { |
| 3966 | I915_WRITE(palreg + 4 * i, |
| 3967 | (intel_crtc->lut_r[i] << 16) | |
| 3968 | (intel_crtc->lut_g[i] << 8) | |
| 3969 | intel_crtc->lut_b[i]); |
| 3970 | } |
| 3971 | |
| 3972 | if (reenable_ips) |
| 3973 | hsw_enable_ips(intel_crtc); |
| 3974 | } |
| 3975 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 3976 | static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable) |
| 3977 | { |
| 3978 | if (!enable && intel_crtc->overlay) { |
| 3979 | struct drm_device *dev = intel_crtc->base.dev; |
| 3980 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3981 | |
| 3982 | mutex_lock(&dev->struct_mutex); |
| 3983 | dev_priv->mm.interruptible = false; |
| 3984 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 3985 | dev_priv->mm.interruptible = true; |
| 3986 | mutex_unlock(&dev->struct_mutex); |
| 3987 | } |
| 3988 | |
| 3989 | /* Let userspace switch the overlay on again. In most cases userspace |
| 3990 | * has to recompute where to put it anyway. |
| 3991 | */ |
| 3992 | } |
| 3993 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 3994 | static void intel_crtc_enable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3995 | { |
| 3996 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3997 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3998 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3999 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 4000 | intel_enable_primary_hw_plane(crtc->primary, crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4001 | intel_enable_planes(crtc); |
| 4002 | intel_crtc_update_cursor(crtc, true); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4003 | intel_crtc_dpms_overlay(intel_crtc, true); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4004 | |
| 4005 | hsw_enable_ips(intel_crtc); |
| 4006 | |
| 4007 | mutex_lock(&dev->struct_mutex); |
| 4008 | intel_update_fbc(dev); |
| 4009 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4010 | |
| 4011 | /* |
| 4012 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4013 | * to compute the mask of flip planes precisely. For the time being |
| 4014 | * consider this a flip from a NULL plane. |
| 4015 | */ |
| 4016 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4017 | } |
| 4018 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4019 | static void intel_crtc_disable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4020 | { |
| 4021 | struct drm_device *dev = crtc->dev; |
| 4022 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4023 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4024 | int pipe = intel_crtc->pipe; |
| 4025 | int plane = intel_crtc->plane; |
| 4026 | |
| 4027 | intel_crtc_wait_for_pending_flips(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4028 | |
| 4029 | if (dev_priv->fbc.plane == plane) |
| 4030 | intel_disable_fbc(dev); |
| 4031 | |
| 4032 | hsw_disable_ips(intel_crtc); |
| 4033 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4034 | intel_crtc_dpms_overlay(intel_crtc, false); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4035 | intel_crtc_update_cursor(crtc, false); |
| 4036 | intel_disable_planes(crtc); |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 4037 | intel_disable_primary_hw_plane(crtc->primary, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4038 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4039 | /* |
| 4040 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4041 | * to compute the mask of flip planes precisely. For the time being |
| 4042 | * consider this a flip to a NULL plane. |
| 4043 | */ |
| 4044 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4045 | } |
| 4046 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4047 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4048 | { |
| 4049 | struct drm_device *dev = crtc->dev; |
| 4050 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4051 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4052 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4053 | int pipe = intel_crtc->pipe; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4054 | |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 4055 | WARN_ON(!crtc->enabled); |
| 4056 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4057 | if (intel_crtc->active) |
| 4058 | return; |
| 4059 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4060 | if (intel_crtc->config.has_pch_encoder) |
| 4061 | intel_prepare_shared_dpll(intel_crtc); |
| 4062 | |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4063 | if (intel_crtc->config.has_dp_encoder) |
| 4064 | intel_dp_set_m_n(intel_crtc); |
| 4065 | |
| 4066 | intel_set_pipe_timings(intel_crtc); |
| 4067 | |
| 4068 | if (intel_crtc->config.has_pch_encoder) { |
| 4069 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 4070 | &intel_crtc->config.fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4071 | } |
| 4072 | |
| 4073 | ironlake_set_pipeconf(crtc); |
| 4074 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4075 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4076 | |
| 4077 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 4078 | intel_set_pch_fifo_underrun_reporting(dev, pipe, true); |
| 4079 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4080 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4081 | if (encoder->pre_enable) |
| 4082 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4083 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 4084 | if (intel_crtc->config.has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4085 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4086 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4087 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4088 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4089 | } else { |
| 4090 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4091 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4092 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4093 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4094 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4095 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4096 | /* |
| 4097 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4098 | * clocks enabled |
| 4099 | */ |
| 4100 | intel_crtc_load_lut(crtc); |
| 4101 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4102 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4103 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4104 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 4105 | if (intel_crtc->config.has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4106 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4107 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4108 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4109 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4110 | |
| 4111 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4112 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Daniel Vetter | 6ce9410 | 2012-10-04 19:20:03 +0200 | [diff] [blame] | 4113 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame^] | 4114 | assert_vblank_disabled(crtc); |
| 4115 | drm_crtc_vblank_on(crtc); |
| 4116 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4117 | intel_crtc_enable_planes(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4118 | } |
| 4119 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4120 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4121 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4122 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4123 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4124 | } |
| 4125 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4126 | /* |
| 4127 | * This implements the workaround described in the "notes" section of the mode |
| 4128 | * set sequence documentation. When going from no pipes or single pipe to |
| 4129 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 4130 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 4131 | */ |
| 4132 | static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc) |
| 4133 | { |
| 4134 | struct drm_device *dev = crtc->base.dev; |
| 4135 | struct intel_crtc *crtc_it, *other_active_crtc = NULL; |
| 4136 | |
| 4137 | /* We want to get the other_active_crtc only if there's only 1 other |
| 4138 | * active crtc. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4139 | for_each_intel_crtc(dev, crtc_it) { |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4140 | if (!crtc_it->active || crtc_it == crtc) |
| 4141 | continue; |
| 4142 | |
| 4143 | if (other_active_crtc) |
| 4144 | return; |
| 4145 | |
| 4146 | other_active_crtc = crtc_it; |
| 4147 | } |
| 4148 | if (!other_active_crtc) |
| 4149 | return; |
| 4150 | |
| 4151 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4152 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4153 | } |
| 4154 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4155 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 4156 | { |
| 4157 | struct drm_device *dev = crtc->dev; |
| 4158 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4159 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4160 | struct intel_encoder *encoder; |
| 4161 | int pipe = intel_crtc->pipe; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4162 | |
| 4163 | WARN_ON(!crtc->enabled); |
| 4164 | |
| 4165 | if (intel_crtc->active) |
| 4166 | return; |
| 4167 | |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4168 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4169 | intel_enable_shared_dpll(intel_crtc); |
| 4170 | |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4171 | if (intel_crtc->config.has_dp_encoder) |
| 4172 | intel_dp_set_m_n(intel_crtc); |
| 4173 | |
| 4174 | intel_set_pipe_timings(intel_crtc); |
| 4175 | |
| 4176 | if (intel_crtc->config.has_pch_encoder) { |
| 4177 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 4178 | &intel_crtc->config.fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4179 | } |
| 4180 | |
| 4181 | haswell_set_pipeconf(crtc); |
| 4182 | |
| 4183 | intel_set_pipe_csc(crtc); |
| 4184 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4185 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4186 | |
| 4187 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4188 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4189 | if (encoder->pre_enable) |
| 4190 | encoder->pre_enable(encoder); |
| 4191 | |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4192 | if (intel_crtc->config.has_pch_encoder) { |
| 4193 | intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true); |
| 4194 | dev_priv->display.fdi_link_train(crtc); |
| 4195 | } |
| 4196 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4197 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4198 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4199 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4200 | |
| 4201 | /* |
| 4202 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4203 | * clocks enabled |
| 4204 | */ |
| 4205 | intel_crtc_load_lut(crtc); |
| 4206 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4207 | intel_ddi_set_pipe_settings(crtc); |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 4208 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4209 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4210 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4211 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4212 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 4213 | if (intel_crtc->config.has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4214 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4215 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4216 | if (intel_crtc->config.dp_encoder_is_mst) |
| 4217 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 4218 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4219 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4220 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4221 | intel_opregion_notify_encoder(encoder, true); |
| 4222 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4223 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame^] | 4224 | assert_vblank_disabled(crtc); |
| 4225 | drm_crtc_vblank_on(crtc); |
| 4226 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4227 | /* If we change the relative order between pipe/planes enabling, we need |
| 4228 | * to change the workaround. */ |
| 4229 | haswell_mode_set_planes_workaround(intel_crtc); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4230 | intel_crtc_enable_planes(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4231 | } |
| 4232 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4233 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
| 4234 | { |
| 4235 | struct drm_device *dev = crtc->base.dev; |
| 4236 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4237 | int pipe = crtc->pipe; |
| 4238 | |
| 4239 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4240 | * it's in use. The hw state code will make sure we get this right. */ |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 4241 | if (crtc->config.pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4242 | I915_WRITE(PF_CTL(pipe), 0); |
| 4243 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 4244 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 4245 | } |
| 4246 | } |
| 4247 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4248 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 4249 | { |
| 4250 | struct drm_device *dev = crtc->dev; |
| 4251 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4252 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4253 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4254 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4255 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4256 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4257 | if (!intel_crtc->active) |
| 4258 | return; |
| 4259 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4260 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4261 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame^] | 4262 | drm_crtc_vblank_off(crtc); |
| 4263 | assert_vblank_disabled(crtc); |
| 4264 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4265 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4266 | encoder->disable(encoder); |
| 4267 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4268 | if (intel_crtc->config.has_pch_encoder) |
| 4269 | intel_set_pch_fifo_underrun_reporting(dev, pipe, false); |
| 4270 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4271 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4272 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4273 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4274 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 4275 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4276 | if (encoder->post_disable) |
| 4277 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4278 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4279 | if (intel_crtc->config.has_pch_encoder) { |
| 4280 | ironlake_fdi_disable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4281 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4282 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
| 4283 | intel_set_pch_fifo_underrun_reporting(dev, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4284 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4285 | if (HAS_PCH_CPT(dev)) { |
| 4286 | /* disable TRANS_DP_CTL */ |
| 4287 | reg = TRANS_DP_CTL(pipe); |
| 4288 | temp = I915_READ(reg); |
| 4289 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 4290 | TRANS_DP_PORT_SEL_MASK); |
| 4291 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 4292 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4293 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4294 | /* disable DPLL_SEL */ |
| 4295 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4296 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4297 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 4298 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4299 | |
| 4300 | /* disable PCH DPLL */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4301 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4302 | |
| 4303 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4304 | } |
| 4305 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4306 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4307 | intel_update_watermarks(crtc); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4308 | |
| 4309 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4310 | intel_update_fbc(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4311 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4312 | } |
| 4313 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4314 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 4315 | { |
| 4316 | struct drm_device *dev = crtc->dev; |
| 4317 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4318 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4319 | struct intel_encoder *encoder; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 4320 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4321 | |
| 4322 | if (!intel_crtc->active) |
| 4323 | return; |
| 4324 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4325 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | dda9a66 | 2013-09-19 17:00:37 -0300 | [diff] [blame] | 4326 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame^] | 4327 | drm_crtc_vblank_off(crtc); |
| 4328 | assert_vblank_disabled(crtc); |
| 4329 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4330 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 4331 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4332 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4333 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4334 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4335 | if (intel_crtc->config.has_pch_encoder) |
| 4336 | intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false); |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4337 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4338 | |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 4339 | if (intel_crtc->config.dp_encoder_is_mst) |
| 4340 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 4341 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 4342 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4343 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4344 | ironlake_pfit_disable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4345 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4346 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4347 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 4348 | if (intel_crtc->config.has_pch_encoder) { |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 4349 | lpt_disable_pch_transcoder(dev_priv); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4350 | intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 4351 | intel_ddi_fdi_disable(crtc); |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 4352 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4353 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 4354 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4355 | if (encoder->post_disable) |
| 4356 | encoder->post_disable(encoder); |
| 4357 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4358 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4359 | intel_update_watermarks(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4360 | |
| 4361 | mutex_lock(&dev->struct_mutex); |
| 4362 | intel_update_fbc(dev); |
| 4363 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4364 | |
| 4365 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4366 | intel_disable_shared_dpll(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4367 | } |
| 4368 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4369 | static void ironlake_crtc_off(struct drm_crtc *crtc) |
| 4370 | { |
| 4371 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4372 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4373 | } |
| 4374 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 4375 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4376 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 4377 | { |
| 4378 | struct drm_device *dev = crtc->base.dev; |
| 4379 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4380 | struct intel_crtc_config *pipe_config = &crtc->config; |
| 4381 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 4382 | if (!crtc->config.gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4383 | return; |
| 4384 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 4385 | /* |
| 4386 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 4387 | * according to register description and PRM. |
| 4388 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4389 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 4390 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 4391 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4392 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 4393 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 4394 | |
| 4395 | /* Border color in case we don't scale up to the full screen. Black by |
| 4396 | * default, change to something else for debugging. */ |
| 4397 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4398 | } |
| 4399 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4400 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 4401 | { |
| 4402 | switch (port) { |
| 4403 | case PORT_A: |
| 4404 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; |
| 4405 | case PORT_B: |
| 4406 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; |
| 4407 | case PORT_C: |
| 4408 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; |
| 4409 | case PORT_D: |
| 4410 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; |
| 4411 | default: |
| 4412 | WARN_ON_ONCE(1); |
| 4413 | return POWER_DOMAIN_PORT_OTHER; |
| 4414 | } |
| 4415 | } |
| 4416 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4417 | #define for_each_power_domain(domain, mask) \ |
| 4418 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ |
| 4419 | if ((1 << (domain)) & (mask)) |
| 4420 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4421 | enum intel_display_power_domain |
| 4422 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4423 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4424 | struct drm_device *dev = intel_encoder->base.dev; |
| 4425 | struct intel_digital_port *intel_dig_port; |
| 4426 | |
| 4427 | switch (intel_encoder->type) { |
| 4428 | case INTEL_OUTPUT_UNKNOWN: |
| 4429 | /* Only DDI platforms should ever use this output type */ |
| 4430 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 4431 | case INTEL_OUTPUT_DISPLAYPORT: |
| 4432 | case INTEL_OUTPUT_HDMI: |
| 4433 | case INTEL_OUTPUT_EDP: |
| 4434 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4435 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4436 | case INTEL_OUTPUT_DP_MST: |
| 4437 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 4438 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4439 | case INTEL_OUTPUT_ANALOG: |
| 4440 | return POWER_DOMAIN_PORT_CRT; |
| 4441 | case INTEL_OUTPUT_DSI: |
| 4442 | return POWER_DOMAIN_PORT_DSI; |
| 4443 | default: |
| 4444 | return POWER_DOMAIN_PORT_OTHER; |
| 4445 | } |
| 4446 | } |
| 4447 | |
| 4448 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) |
| 4449 | { |
| 4450 | struct drm_device *dev = crtc->dev; |
| 4451 | struct intel_encoder *intel_encoder; |
| 4452 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4453 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4454 | unsigned long mask; |
| 4455 | enum transcoder transcoder; |
| 4456 | |
| 4457 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); |
| 4458 | |
| 4459 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 4460 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Daniel Vetter | fabf6e5 | 2014-05-29 14:10:22 +0200 | [diff] [blame] | 4461 | if (intel_crtc->config.pch_pfit.enabled || |
| 4462 | intel_crtc->config.pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4463 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 4464 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4465 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 4466 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
| 4467 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4468 | return mask; |
| 4469 | } |
| 4470 | |
| 4471 | void intel_display_set_init_power(struct drm_i915_private *dev_priv, |
| 4472 | bool enable) |
| 4473 | { |
| 4474 | if (dev_priv->power_domains.init_power_on == enable) |
| 4475 | return; |
| 4476 | |
| 4477 | if (enable) |
| 4478 | intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
| 4479 | else |
| 4480 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT); |
| 4481 | |
| 4482 | dev_priv->power_domains.init_power_on = enable; |
| 4483 | } |
| 4484 | |
| 4485 | static void modeset_update_crtc_power_domains(struct drm_device *dev) |
| 4486 | { |
| 4487 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4488 | unsigned long pipe_domains[I915_MAX_PIPES] = { 0, }; |
| 4489 | struct intel_crtc *crtc; |
| 4490 | |
| 4491 | /* |
| 4492 | * First get all needed power domains, then put all unneeded, to avoid |
| 4493 | * any unnecessary toggling of the power wells. |
| 4494 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4495 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4496 | enum intel_display_power_domain domain; |
| 4497 | |
| 4498 | if (!crtc->base.enabled) |
| 4499 | continue; |
| 4500 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4501 | pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4502 | |
| 4503 | for_each_power_domain(domain, pipe_domains[crtc->pipe]) |
| 4504 | intel_display_power_get(dev_priv, domain); |
| 4505 | } |
| 4506 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4507 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4508 | enum intel_display_power_domain domain; |
| 4509 | |
| 4510 | for_each_power_domain(domain, crtc->enabled_power_domains) |
| 4511 | intel_display_power_put(dev_priv, domain); |
| 4512 | |
| 4513 | crtc->enabled_power_domains = pipe_domains[crtc->pipe]; |
| 4514 | } |
| 4515 | |
| 4516 | intel_display_set_init_power(dev_priv, false); |
| 4517 | } |
| 4518 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4519 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4520 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4521 | { |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 4522 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4523 | |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 4524 | /* Obtain SKU information */ |
| 4525 | mutex_lock(&dev_priv->dpio_lock); |
| 4526 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 4527 | CCK_FUSE_HPLL_FREQ_MASK; |
| 4528 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4529 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4530 | return vco_freq[hpll_freq] * 1000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4531 | } |
| 4532 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4533 | static void vlv_update_cdclk(struct drm_device *dev) |
| 4534 | { |
| 4535 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4536 | |
| 4537 | dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev); |
| 4538 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz", |
| 4539 | dev_priv->vlv_cdclk_freq); |
| 4540 | |
| 4541 | /* |
| 4542 | * Program the gmbus_freq based on the cdclk frequency. |
| 4543 | * BSpec erroneously claims we should aim for 4MHz, but |
| 4544 | * in fact 1MHz is the correct frequency. |
| 4545 | */ |
| 4546 | I915_WRITE(GMBUSFREQ_VLV, dev_priv->vlv_cdclk_freq); |
| 4547 | } |
| 4548 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4549 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 4550 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 4551 | { |
| 4552 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4553 | u32 val, cmd; |
| 4554 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 4555 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq); |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 4556 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4557 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4558 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4559 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4560 | cmd = 1; |
| 4561 | else |
| 4562 | cmd = 0; |
| 4563 | |
| 4564 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4565 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 4566 | val &= ~DSPFREQGUAR_MASK; |
| 4567 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 4568 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 4569 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 4570 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 4571 | 50)) { |
| 4572 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 4573 | } |
| 4574 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4575 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4576 | if (cdclk == 400000) { |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4577 | u32 divider, vco; |
| 4578 | |
| 4579 | vco = valleyview_get_vco(dev_priv); |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4580 | divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4581 | |
| 4582 | mutex_lock(&dev_priv->dpio_lock); |
| 4583 | /* adjust cdclk divider */ |
| 4584 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Ville Syrjälä | 9cf33db | 2014-06-13 13:37:48 +0300 | [diff] [blame] | 4585 | val &= ~DISPLAY_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4586 | val |= divider; |
| 4587 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 4588 | |
| 4589 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
| 4590 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 4591 | 50)) |
| 4592 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4593 | mutex_unlock(&dev_priv->dpio_lock); |
| 4594 | } |
| 4595 | |
| 4596 | mutex_lock(&dev_priv->dpio_lock); |
| 4597 | /* adjust self-refresh exit latency value */ |
| 4598 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 4599 | val &= ~0x7f; |
| 4600 | |
| 4601 | /* |
| 4602 | * For high bandwidth configs, we set a higher latency in the bunit |
| 4603 | * so that the core display fetch happens in time to avoid underruns. |
| 4604 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4605 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4606 | val |= 4500 / 250; /* 4.5 usec */ |
| 4607 | else |
| 4608 | val |= 3000 / 250; /* 3.0 usec */ |
| 4609 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
| 4610 | mutex_unlock(&dev_priv->dpio_lock); |
| 4611 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4612 | vlv_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4613 | } |
| 4614 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 4615 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 4616 | { |
| 4617 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4618 | u32 val, cmd; |
| 4619 | |
| 4620 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq); |
| 4621 | |
| 4622 | switch (cdclk) { |
| 4623 | case 400000: |
| 4624 | cmd = 3; |
| 4625 | break; |
| 4626 | case 333333: |
| 4627 | case 320000: |
| 4628 | cmd = 2; |
| 4629 | break; |
| 4630 | case 266667: |
| 4631 | cmd = 1; |
| 4632 | break; |
| 4633 | case 200000: |
| 4634 | cmd = 0; |
| 4635 | break; |
| 4636 | default: |
| 4637 | WARN_ON(1); |
| 4638 | return; |
| 4639 | } |
| 4640 | |
| 4641 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4642 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 4643 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 4644 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 4645 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 4646 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 4647 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 4648 | 50)) { |
| 4649 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 4650 | } |
| 4651 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4652 | |
| 4653 | vlv_update_cdclk(dev); |
| 4654 | } |
| 4655 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4656 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 4657 | int max_pixclk) |
| 4658 | { |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 4659 | int vco = valleyview_get_vco(dev_priv); |
| 4660 | int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000; |
| 4661 | |
Ville Syrjälä | d49a340 | 2014-06-28 02:03:58 +0300 | [diff] [blame] | 4662 | /* FIXME: Punit isn't quite ready yet */ |
| 4663 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 4664 | return 400000; |
| 4665 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4666 | /* |
| 4667 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 4668 | * 200MHz |
| 4669 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 4670 | * 320/333MHz (depends on HPLL freq) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4671 | * 400MHz |
| 4672 | * So we check to see whether we're above 90% of the lower bin and |
| 4673 | * adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 4674 | * |
| 4675 | * We seem to get an unstable or solid color picture at 200MHz. |
| 4676 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 4677 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4678 | */ |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 4679 | if (max_pixclk > freq_320*9/10) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4680 | return 400000; |
| 4681 | else if (max_pixclk > 266667*9/10) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 4682 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 4683 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4684 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 4685 | else |
| 4686 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4687 | } |
| 4688 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4689 | /* compute the max pixel clock for new configuration */ |
| 4690 | static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4691 | { |
| 4692 | struct drm_device *dev = dev_priv->dev; |
| 4693 | struct intel_crtc *intel_crtc; |
| 4694 | int max_pixclk = 0; |
| 4695 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4696 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4697 | if (intel_crtc->new_enabled) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4698 | max_pixclk = max(max_pixclk, |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4699 | intel_crtc->new_config->adjusted_mode.crtc_clock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4700 | } |
| 4701 | |
| 4702 | return max_pixclk; |
| 4703 | } |
| 4704 | |
| 4705 | static void valleyview_modeset_global_pipes(struct drm_device *dev, |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4706 | unsigned *prepare_pipes) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4707 | { |
| 4708 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4709 | struct intel_crtc *intel_crtc; |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4710 | int max_pixclk = intel_mode_max_pixclk(dev_priv); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4711 | |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 4712 | if (valleyview_calc_cdclk(dev_priv, max_pixclk) == |
| 4713 | dev_priv->vlv_cdclk_freq) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4714 | return; |
| 4715 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4716 | /* disable/enable all currently active pipes while we change cdclk */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4717 | for_each_intel_crtc(dev, intel_crtc) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4718 | if (intel_crtc->base.enabled) |
| 4719 | *prepare_pipes |= (1 << intel_crtc->pipe); |
| 4720 | } |
| 4721 | |
| 4722 | static void valleyview_modeset_global_resources(struct drm_device *dev) |
| 4723 | { |
| 4724 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4725 | int max_pixclk = intel_mode_max_pixclk(dev_priv); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4726 | int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
| 4727 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 4728 | if (req_cdclk != dev_priv->vlv_cdclk_freq) { |
| 4729 | if (IS_CHERRYVIEW(dev)) |
| 4730 | cherryview_set_cdclk(dev, req_cdclk); |
| 4731 | else |
| 4732 | valleyview_set_cdclk(dev, req_cdclk); |
| 4733 | } |
| 4734 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 4735 | modeset_update_crtc_power_domains(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4736 | } |
| 4737 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4738 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 4739 | { |
| 4740 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4741 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4742 | struct intel_encoder *encoder; |
| 4743 | int pipe = intel_crtc->pipe; |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 4744 | bool is_dsi; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4745 | |
| 4746 | WARN_ON(!crtc->enabled); |
| 4747 | |
| 4748 | if (intel_crtc->active) |
| 4749 | return; |
| 4750 | |
Shobhit Kumar | 8525a23 | 2014-06-25 12:20:39 +0530 | [diff] [blame] | 4751 | is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI); |
| 4752 | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 4753 | if (!is_dsi) { |
| 4754 | if (IS_CHERRYVIEW(dev)) |
| 4755 | chv_prepare_pll(intel_crtc); |
| 4756 | else |
| 4757 | vlv_prepare_pll(intel_crtc); |
| 4758 | } |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 4759 | |
| 4760 | if (intel_crtc->config.has_dp_encoder) |
| 4761 | intel_dp_set_m_n(intel_crtc); |
| 4762 | |
| 4763 | intel_set_pipe_timings(intel_crtc); |
| 4764 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 4765 | i9xx_set_pipeconf(intel_crtc); |
| 4766 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4767 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4768 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4769 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 4770 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4771 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4772 | if (encoder->pre_pll_enable) |
| 4773 | encoder->pre_pll_enable(encoder); |
| 4774 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 4775 | if (!is_dsi) { |
| 4776 | if (IS_CHERRYVIEW(dev)) |
| 4777 | chv_enable_pll(intel_crtc); |
| 4778 | else |
| 4779 | vlv_enable_pll(intel_crtc); |
| 4780 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4781 | |
| 4782 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4783 | if (encoder->pre_enable) |
| 4784 | encoder->pre_enable(encoder); |
| 4785 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4786 | i9xx_pfit_enable(intel_crtc); |
| 4787 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 4788 | intel_crtc_load_lut(crtc); |
| 4789 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4790 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4791 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 4792 | |
Jani Nikula | 5004945 | 2013-07-30 12:20:32 +0300 | [diff] [blame] | 4793 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4794 | encoder->enable(encoder); |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 4795 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame^] | 4796 | assert_vblank_disabled(crtc); |
| 4797 | drm_crtc_vblank_on(crtc); |
| 4798 | |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 4799 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 4800 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 4801 | /* Underruns don't raise interrupts, so check manually. */ |
| 4802 | i9xx_check_fifo_underruns(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4803 | } |
| 4804 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 4805 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 4806 | { |
| 4807 | struct drm_device *dev = crtc->base.dev; |
| 4808 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4809 | |
| 4810 | I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0); |
| 4811 | I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1); |
| 4812 | } |
| 4813 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4814 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4815 | { |
| 4816 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4817 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4818 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4819 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4820 | |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 4821 | WARN_ON(!crtc->enabled); |
| 4822 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4823 | if (intel_crtc->active) |
| 4824 | return; |
| 4825 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 4826 | i9xx_set_pll_dividers(intel_crtc); |
| 4827 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 4828 | if (intel_crtc->config.has_dp_encoder) |
| 4829 | intel_dp_set_m_n(intel_crtc); |
| 4830 | |
| 4831 | intel_set_pipe_timings(intel_crtc); |
| 4832 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 4833 | i9xx_set_pipeconf(intel_crtc); |
| 4834 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4835 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4836 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4837 | if (!IS_GEN2(dev)) |
| 4838 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 4839 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 4840 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 4841 | if (encoder->pre_enable) |
| 4842 | encoder->pre_enable(encoder); |
| 4843 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4844 | i9xx_enable_pll(intel_crtc); |
| 4845 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4846 | i9xx_pfit_enable(intel_crtc); |
| 4847 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 4848 | intel_crtc_load_lut(crtc); |
| 4849 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4850 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4851 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 4852 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4853 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4854 | encoder->enable(encoder); |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 4855 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame^] | 4856 | assert_vblank_disabled(crtc); |
| 4857 | drm_crtc_vblank_on(crtc); |
| 4858 | |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 4859 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 4860 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4861 | /* |
| 4862 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4863 | * So don't enable underrun reporting before at least some planes |
| 4864 | * are enabled. |
| 4865 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4866 | * but leave the pipe running. |
| 4867 | */ |
| 4868 | if (IS_GEN2(dev)) |
| 4869 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 4870 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 4871 | /* Underruns don't raise interrupts, so check manually. */ |
| 4872 | i9xx_check_fifo_underruns(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4873 | } |
| 4874 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 4875 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 4876 | { |
| 4877 | struct drm_device *dev = crtc->base.dev; |
| 4878 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 4879 | |
| 4880 | if (!crtc->config.gmch_pfit.control) |
| 4881 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 4882 | |
| 4883 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 4884 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 4885 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 4886 | I915_READ(PFIT_CONTROL)); |
| 4887 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 4888 | } |
| 4889 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4890 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 4891 | { |
| 4892 | struct drm_device *dev = crtc->dev; |
| 4893 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4894 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4895 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4896 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4897 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4898 | if (!intel_crtc->active) |
| 4899 | return; |
| 4900 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4901 | /* |
| 4902 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4903 | * So diasble underrun reporting before all the planes get disabled. |
| 4904 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4905 | * but leave the pipe running. |
| 4906 | */ |
| 4907 | if (IS_GEN2(dev)) |
| 4908 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, false); |
| 4909 | |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 4910 | /* |
| 4911 | * Vblank time updates from the shadow to live plane control register |
| 4912 | * are blocked if the memory self-refresh mode is active at that |
| 4913 | * moment. So to make sure the plane gets truly disabled, disable |
| 4914 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4915 | * will be checked/applied by the HW only at the next frame start |
| 4916 | * event which is after the vblank start event, so we need to have a |
| 4917 | * wait-for-vblank between disabling the plane and the pipe. |
| 4918 | */ |
| 4919 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 4920 | intel_crtc_disable_planes(crtc); |
| 4921 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 4922 | /* |
| 4923 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 4924 | * wait for planes to fully turn off before disabling the pipe. |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 4925 | * We also need to wait on all gmch platforms because of the |
| 4926 | * self-refresh mode constraint explained above. |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 4927 | */ |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 4928 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 4929 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame^] | 4930 | drm_crtc_vblank_off(crtc); |
| 4931 | assert_vblank_disabled(crtc); |
| 4932 | |
| 4933 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4934 | encoder->disable(encoder); |
| 4935 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4936 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 4937 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 4938 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 4939 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4940 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4941 | if (encoder->post_disable) |
| 4942 | encoder->post_disable(encoder); |
| 4943 | |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 4944 | if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) { |
| 4945 | if (IS_CHERRYVIEW(dev)) |
| 4946 | chv_disable_pll(dev_priv, pipe); |
| 4947 | else if (IS_VALLEYVIEW(dev)) |
| 4948 | vlv_disable_pll(dev_priv, pipe); |
| 4949 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 4950 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 4951 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4952 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4953 | if (!IS_GEN2(dev)) |
| 4954 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, false); |
| 4955 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4956 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4957 | intel_update_watermarks(crtc); |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4958 | |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 4959 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4960 | intel_update_fbc(dev); |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 4961 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4962 | } |
| 4963 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4964 | static void i9xx_crtc_off(struct drm_crtc *crtc) |
| 4965 | { |
| 4966 | } |
| 4967 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 4968 | static void intel_crtc_update_sarea(struct drm_crtc *crtc, |
| 4969 | bool enabled) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4970 | { |
| 4971 | struct drm_device *dev = crtc->dev; |
| 4972 | struct drm_i915_master_private *master_priv; |
| 4973 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4974 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4975 | |
| 4976 | if (!dev->primary->master) |
| 4977 | return; |
| 4978 | |
| 4979 | master_priv = dev->primary->master->driver_priv; |
| 4980 | if (!master_priv->sarea_priv) |
| 4981 | return; |
| 4982 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4983 | switch (pipe) { |
| 4984 | case 0: |
| 4985 | master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0; |
| 4986 | master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0; |
| 4987 | break; |
| 4988 | case 1: |
| 4989 | master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0; |
| 4990 | master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0; |
| 4991 | break; |
| 4992 | default: |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 4993 | 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] | 4994 | break; |
| 4995 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4996 | } |
| 4997 | |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 4998 | /* Master function to enable/disable CRTC and corresponding power wells */ |
| 4999 | void intel_crtc_control(struct drm_crtc *crtc, bool enable) |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5000 | { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5001 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5002 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5003 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5004 | enum intel_display_power_domain domain; |
| 5005 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5006 | |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5007 | if (enable) { |
| 5008 | if (!intel_crtc->active) { |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 5009 | domains = get_crtc_power_domains(crtc); |
| 5010 | for_each_power_domain(domain, domains) |
| 5011 | intel_display_power_get(dev_priv, domain); |
| 5012 | intel_crtc->enabled_power_domains = domains; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5013 | |
| 5014 | dev_priv->display.crtc_enable(crtc); |
| 5015 | } |
| 5016 | } else { |
| 5017 | if (intel_crtc->active) { |
| 5018 | dev_priv->display.crtc_disable(crtc); |
| 5019 | |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 5020 | domains = intel_crtc->enabled_power_domains; |
| 5021 | for_each_power_domain(domain, domains) |
| 5022 | intel_display_power_put(dev_priv, domain); |
| 5023 | intel_crtc->enabled_power_domains = 0; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5024 | } |
| 5025 | } |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 5026 | } |
| 5027 | |
| 5028 | /** |
| 5029 | * Sets the power management mode of the pipe and plane. |
| 5030 | */ |
| 5031 | void intel_crtc_update_dpms(struct drm_crtc *crtc) |
| 5032 | { |
| 5033 | struct drm_device *dev = crtc->dev; |
| 5034 | struct intel_encoder *intel_encoder; |
| 5035 | bool enable = false; |
| 5036 | |
| 5037 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 5038 | enable |= intel_encoder->connectors_active; |
| 5039 | |
| 5040 | intel_crtc_control(crtc, enable); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5041 | |
| 5042 | intel_crtc_update_sarea(crtc, enable); |
| 5043 | } |
| 5044 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5045 | static void intel_crtc_disable(struct drm_crtc *crtc) |
| 5046 | { |
| 5047 | struct drm_device *dev = crtc->dev; |
| 5048 | struct drm_connector *connector; |
| 5049 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 5050 | struct drm_i915_gem_object *old_obj = intel_fb_obj(crtc->primary->fb); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 5051 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5052 | |
| 5053 | /* crtc should still be enabled when we disable it. */ |
| 5054 | WARN_ON(!crtc->enabled); |
| 5055 | |
| 5056 | dev_priv->display.crtc_disable(crtc); |
| 5057 | intel_crtc_update_sarea(crtc, false); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5058 | dev_priv->display.off(crtc); |
| 5059 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 5060 | if (crtc->primary->fb) { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5061 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 5062 | intel_unpin_fb_obj(old_obj); |
| 5063 | i915_gem_track_fb(old_obj, NULL, |
| 5064 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5065 | mutex_unlock(&dev->struct_mutex); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 5066 | crtc->primary->fb = NULL; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5067 | } |
| 5068 | |
| 5069 | /* Update computed state. */ |
| 5070 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 5071 | if (!connector->encoder || !connector->encoder->crtc) |
| 5072 | continue; |
| 5073 | |
| 5074 | if (connector->encoder->crtc != crtc) |
| 5075 | continue; |
| 5076 | |
| 5077 | connector->dpms = DRM_MODE_DPMS_OFF; |
| 5078 | to_intel_encoder(connector->encoder)->connectors_active = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5079 | } |
| 5080 | } |
| 5081 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5082 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 5083 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5084 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5085 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5086 | drm_encoder_cleanup(encoder); |
| 5087 | kfree(intel_encoder); |
| 5088 | } |
| 5089 | |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5090 | /* Simple dpms helper for encoders with just one connector, no cloning and only |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5091 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
| 5092 | * state of the entire output pipe. */ |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5093 | static void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5094 | { |
| 5095 | if (mode == DRM_MODE_DPMS_ON) { |
| 5096 | encoder->connectors_active = true; |
| 5097 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5098 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5099 | } else { |
| 5100 | encoder->connectors_active = false; |
| 5101 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5102 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5103 | } |
| 5104 | } |
| 5105 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5106 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 5107 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5108 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5109 | { |
| 5110 | if (connector->get_hw_state(connector)) { |
| 5111 | struct intel_encoder *encoder = connector->encoder; |
| 5112 | struct drm_crtc *crtc; |
| 5113 | bool encoder_enabled; |
| 5114 | enum pipe pipe; |
| 5115 | |
| 5116 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 5117 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 5118 | connector->base.name); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5119 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5120 | /* there is no real hw state for MST connectors */ |
| 5121 | if (connector->mst_port) |
| 5122 | return; |
| 5123 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5124 | WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
| 5125 | "wrong connector dpms state\n"); |
| 5126 | WARN(connector->base.encoder != &encoder->base, |
| 5127 | "active connector not linked to encoder\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5128 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5129 | if (encoder) { |
| 5130 | WARN(!encoder->connectors_active, |
| 5131 | "encoder->connectors_active not set\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5132 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5133 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); |
| 5134 | WARN(!encoder_enabled, "encoder not enabled\n"); |
| 5135 | if (WARN_ON(!encoder->base.crtc)) |
| 5136 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5137 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5138 | crtc = encoder->base.crtc; |
| 5139 | |
| 5140 | WARN(!crtc->enabled, "crtc not enabled\n"); |
| 5141 | WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
| 5142 | WARN(pipe != to_intel_crtc(crtc)->pipe, |
| 5143 | "encoder active on the wrong pipe\n"); |
| 5144 | } |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5145 | } |
| 5146 | } |
| 5147 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5148 | /* Even simpler default implementation, if there's really no special case to |
| 5149 | * consider. */ |
| 5150 | void intel_connector_dpms(struct drm_connector *connector, int mode) |
| 5151 | { |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5152 | /* All the simple cases only support two dpms states. */ |
| 5153 | if (mode != DRM_MODE_DPMS_ON) |
| 5154 | mode = DRM_MODE_DPMS_OFF; |
| 5155 | |
| 5156 | if (mode == connector->dpms) |
| 5157 | return; |
| 5158 | |
| 5159 | connector->dpms = mode; |
| 5160 | |
| 5161 | /* Only need to change hw state when actually enabled */ |
Chris Wilson | c9976dc | 2013-09-29 19:15:07 +0100 | [diff] [blame] | 5162 | if (connector->encoder) |
| 5163 | intel_encoder_dpms(to_intel_encoder(connector->encoder), mode); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5164 | |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5165 | intel_modeset_check_state(connector->dev); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5166 | } |
| 5167 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5168 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 5169 | * one connector and no cloning and hence the encoder state determines the state |
| 5170 | * of the connector. */ |
| 5171 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 5172 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 5173 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5174 | struct intel_encoder *encoder = connector->encoder; |
| 5175 | |
| 5176 | return encoder->get_hw_state(encoder, &pipe); |
| 5177 | } |
| 5178 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5179 | static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
| 5180 | struct intel_crtc_config *pipe_config) |
| 5181 | { |
| 5182 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5183 | struct intel_crtc *pipe_B_crtc = |
| 5184 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]); |
| 5185 | |
| 5186 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 5187 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5188 | if (pipe_config->fdi_lanes > 4) { |
| 5189 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 5190 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5191 | return false; |
| 5192 | } |
| 5193 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 5194 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5195 | if (pipe_config->fdi_lanes > 2) { |
| 5196 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 5197 | pipe_config->fdi_lanes); |
| 5198 | return false; |
| 5199 | } else { |
| 5200 | return true; |
| 5201 | } |
| 5202 | } |
| 5203 | |
| 5204 | if (INTEL_INFO(dev)->num_pipes == 2) |
| 5205 | return true; |
| 5206 | |
| 5207 | /* Ivybridge 3 pipe is really complicated */ |
| 5208 | switch (pipe) { |
| 5209 | case PIPE_A: |
| 5210 | return true; |
| 5211 | case PIPE_B: |
| 5212 | if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled && |
| 5213 | pipe_config->fdi_lanes > 2) { |
| 5214 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 5215 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5216 | return false; |
| 5217 | } |
| 5218 | return true; |
| 5219 | case PIPE_C: |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 5220 | if (!pipe_has_enabled_pch(pipe_B_crtc) || |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5221 | pipe_B_crtc->config.fdi_lanes <= 2) { |
| 5222 | if (pipe_config->fdi_lanes > 2) { |
| 5223 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 5224 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5225 | return false; |
| 5226 | } |
| 5227 | } else { |
| 5228 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
| 5229 | return false; |
| 5230 | } |
| 5231 | return true; |
| 5232 | default: |
| 5233 | BUG(); |
| 5234 | } |
| 5235 | } |
| 5236 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5237 | #define RETRY 1 |
| 5238 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, |
| 5239 | struct intel_crtc_config *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5240 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5241 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5242 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 5243 | int lane, link_bw, fdi_dotclock; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5244 | bool setup_ok, needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5245 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5246 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5247 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 5248 | * each output octet as 10 bits. The actual frequency |
| 5249 | * is stored as a divider into a 100MHz clock, and the |
| 5250 | * mode pixel clock is stored in units of 1KHz. |
| 5251 | * Hence the bw of each lane in terms of the mode signal |
| 5252 | * is: |
| 5253 | */ |
| 5254 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
| 5255 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5256 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5257 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5258 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5259 | pipe_config->pipe_bpp); |
| 5260 | |
| 5261 | pipe_config->fdi_lanes = lane; |
| 5262 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5263 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5264 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5265 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5266 | setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
| 5267 | intel_crtc->pipe, pipe_config); |
| 5268 | if (!setup_ok && pipe_config->pipe_bpp > 6*3) { |
| 5269 | pipe_config->pipe_bpp -= 2*3; |
| 5270 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 5271 | pipe_config->pipe_bpp); |
| 5272 | needs_recompute = true; |
| 5273 | pipe_config->bw_constrained = true; |
| 5274 | |
| 5275 | goto retry; |
| 5276 | } |
| 5277 | |
| 5278 | if (needs_recompute) |
| 5279 | return RETRY; |
| 5280 | |
| 5281 | return setup_ok ? 0 : -EINVAL; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5282 | } |
| 5283 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5284 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
| 5285 | struct intel_crtc_config *pipe_config) |
| 5286 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5287 | pipe_config->ips_enabled = i915.enable_ips && |
Paulo Zanoni | 3c4ca58 | 2013-05-31 16:33:23 -0300 | [diff] [blame] | 5288 | hsw_crtc_supports_ips(crtc) && |
Jesse Barnes | b6dfdc9 | 2013-07-25 10:06:50 -0700 | [diff] [blame] | 5289 | pipe_config->pipe_bpp <= 24; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5290 | } |
| 5291 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5292 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5293 | struct intel_crtc_config *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5294 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5295 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 5296 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5297 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5298 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5299 | if (INTEL_INFO(dev)->gen < 4) { |
| 5300 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5301 | int clock_limit = |
| 5302 | dev_priv->display.get_display_clock_speed(dev); |
| 5303 | |
| 5304 | /* |
| 5305 | * Enable pixel doubling when the dot clock |
| 5306 | * is > 90% of the (display) core speed. |
| 5307 | * |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5308 | * GDG double wide on either pipe, |
| 5309 | * otherwise pipe A only. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5310 | */ |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5311 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5312 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5313 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5314 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5315 | } |
| 5316 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5317 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5318 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5319 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5320 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 5321 | /* |
| 5322 | * Pipe horizontal size must be even in: |
| 5323 | * - DVO ganged mode |
| 5324 | * - LVDS dual channel mode |
| 5325 | * - Double wide pipe |
| 5326 | */ |
| 5327 | if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
| 5328 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 5329 | pipe_config->pipe_src_w &= ~1; |
| 5330 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 5331 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 5332 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5333 | */ |
| 5334 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
| 5335 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5336 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5337 | |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5338 | 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] | 5339 | pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */ |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5340 | } 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] | 5341 | /* only a 8bpc pipe, with 6bpc dither through the panel fitter |
| 5342 | * for lvds. */ |
| 5343 | pipe_config->pipe_bpp = 8*3; |
| 5344 | } |
| 5345 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 5346 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5347 | hsw_compute_ips_config(crtc, pipe_config); |
| 5348 | |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame] | 5349 | /* |
| 5350 | * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the |
| 5351 | * old clock survives for now. |
| 5352 | */ |
| 5353 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev) || HAS_DDI(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5354 | pipe_config->shared_dpll = crtc->config.shared_dpll; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5355 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5356 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5357 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5358 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5359 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5360 | } |
| 5361 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 5362 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 5363 | { |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5364 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5365 | int vco = valleyview_get_vco(dev_priv); |
| 5366 | u32 val; |
| 5367 | int divider; |
| 5368 | |
Ville Syrjälä | d49a340 | 2014-06-28 02:03:58 +0300 | [diff] [blame] | 5369 | /* FIXME: Punit isn't quite ready yet */ |
| 5370 | if (IS_CHERRYVIEW(dev)) |
| 5371 | return 400000; |
| 5372 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5373 | mutex_lock(&dev_priv->dpio_lock); |
| 5374 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
| 5375 | mutex_unlock(&dev_priv->dpio_lock); |
| 5376 | |
| 5377 | divider = val & DISPLAY_FREQUENCY_VALUES; |
| 5378 | |
Ville Syrjälä | 7d007f4 | 2014-06-13 13:37:53 +0300 | [diff] [blame] | 5379 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
| 5380 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 5381 | "cdclk change in progress\n"); |
| 5382 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5383 | return DIV_ROUND_CLOSEST(vco << 1, divider + 1); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 5384 | } |
| 5385 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5386 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5387 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5388 | return 400000; |
| 5389 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5390 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5391 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 5392 | { |
| 5393 | return 333000; |
| 5394 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5395 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5396 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 5397 | { |
| 5398 | return 200000; |
| 5399 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5400 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 5401 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 5402 | { |
| 5403 | u16 gcfgc = 0; |
| 5404 | |
| 5405 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 5406 | |
| 5407 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 5408 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
| 5409 | return 267000; |
| 5410 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
| 5411 | return 333000; |
| 5412 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
| 5413 | return 444000; |
| 5414 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 5415 | return 200000; |
| 5416 | default: |
| 5417 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 5418 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
| 5419 | return 133000; |
| 5420 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
| 5421 | return 167000; |
| 5422 | } |
| 5423 | } |
| 5424 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5425 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 5426 | { |
| 5427 | u16 gcfgc = 0; |
| 5428 | |
| 5429 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 5430 | |
| 5431 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5432 | return 133000; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5433 | else { |
| 5434 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 5435 | case GC_DISPLAY_CLOCK_333_MHZ: |
| 5436 | return 333000; |
| 5437 | default: |
| 5438 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 5439 | return 190000; |
| 5440 | } |
| 5441 | } |
| 5442 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5443 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5444 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 5445 | { |
| 5446 | return 266000; |
| 5447 | } |
| 5448 | |
| 5449 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 5450 | { |
| 5451 | u16 hpllcc = 0; |
| 5452 | /* Assume that the hardware is in the high speed state. This |
| 5453 | * should be the default. |
| 5454 | */ |
| 5455 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 5456 | case GC_CLOCK_133_200: |
| 5457 | case GC_CLOCK_100_200: |
| 5458 | return 200000; |
| 5459 | case GC_CLOCK_166_250: |
| 5460 | return 250000; |
| 5461 | case GC_CLOCK_100_133: |
| 5462 | return 133000; |
| 5463 | } |
| 5464 | |
| 5465 | /* Shouldn't happen */ |
| 5466 | return 0; |
| 5467 | } |
| 5468 | |
| 5469 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 5470 | { |
| 5471 | return 133000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5472 | } |
| 5473 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5474 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5475 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5476 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5477 | while (*num > DATA_LINK_M_N_MASK || |
| 5478 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5479 | *num >>= 1; |
| 5480 | *den >>= 1; |
| 5481 | } |
| 5482 | } |
| 5483 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5484 | static void compute_m_n(unsigned int m, unsigned int n, |
| 5485 | uint32_t *ret_m, uint32_t *ret_n) |
| 5486 | { |
| 5487 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 5488 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 5489 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 5490 | } |
| 5491 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5492 | void |
| 5493 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 5494 | int pixel_clock, int link_clock, |
| 5495 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5496 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5497 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5498 | |
| 5499 | compute_m_n(bits_per_pixel * pixel_clock, |
| 5500 | link_clock * nlanes * 8, |
| 5501 | &m_n->gmch_m, &m_n->gmch_n); |
| 5502 | |
| 5503 | compute_m_n(pixel_clock, link_clock, |
| 5504 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5505 | } |
| 5506 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 5507 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 5508 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5509 | if (i915.panel_use_ssc >= 0) |
| 5510 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5511 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 5512 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 5513 | } |
| 5514 | |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5515 | static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors) |
| 5516 | { |
| 5517 | struct drm_device *dev = crtc->dev; |
| 5518 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5519 | int refclk; |
| 5520 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5521 | if (IS_VALLEYVIEW(dev)) { |
Daniel Vetter | 9a0ea49 | 2013-09-16 11:29:34 +0200 | [diff] [blame] | 5522 | refclk = 100000; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5523 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5524 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 5525 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 5526 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5527 | } else if (!IS_GEN2(dev)) { |
| 5528 | refclk = 96000; |
| 5529 | } else { |
| 5530 | refclk = 48000; |
| 5531 | } |
| 5532 | |
| 5533 | return refclk; |
| 5534 | } |
| 5535 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5536 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5537 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 5538 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5539 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5540 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5541 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 5542 | { |
| 5543 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5544 | } |
| 5545 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5546 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5547 | intel_clock_t *reduced_clock) |
| 5548 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5549 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5550 | u32 fp, fp2 = 0; |
| 5551 | |
| 5552 | if (IS_PINEVIEW(dev)) { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5553 | fp = pnv_dpll_compute_fp(&crtc->config.dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5554 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5555 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5556 | } else { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5557 | fp = i9xx_dpll_compute_fp(&crtc->config.dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5558 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5559 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5560 | } |
| 5561 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5562 | crtc->config.dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5563 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5564 | crtc->lowfreq_avail = false; |
| 5565 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5566 | reduced_clock && i915.powersave) { |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5567 | crtc->config.dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5568 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5569 | } else { |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5570 | crtc->config.dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5571 | } |
| 5572 | } |
| 5573 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 5574 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 5575 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5576 | { |
| 5577 | u32 reg_val; |
| 5578 | |
| 5579 | /* |
| 5580 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 5581 | * and set it to a reasonable value instead. |
| 5582 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5583 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5584 | reg_val &= 0xffffff00; |
| 5585 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5586 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5587 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5588 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5589 | reg_val &= 0x8cffffff; |
| 5590 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5591 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5592 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5593 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5594 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5595 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5596 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5597 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5598 | reg_val &= 0x00ffffff; |
| 5599 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5600 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5601 | } |
| 5602 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5603 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 5604 | struct intel_link_m_n *m_n) |
| 5605 | { |
| 5606 | struct drm_device *dev = crtc->base.dev; |
| 5607 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5608 | int pipe = crtc->pipe; |
| 5609 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 5610 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 5611 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 5612 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 5613 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5614 | } |
| 5615 | |
| 5616 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 5617 | struct intel_link_m_n *m_n, |
| 5618 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5619 | { |
| 5620 | struct drm_device *dev = crtc->base.dev; |
| 5621 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5622 | int pipe = crtc->pipe; |
| 5623 | enum transcoder transcoder = crtc->config.cpu_transcoder; |
| 5624 | |
| 5625 | if (INTEL_INFO(dev)->gen >= 5) { |
| 5626 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 5627 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 5628 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 5629 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 5630 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 5631 | * for gen < 8) and if DRRS is supported (to make sure the |
| 5632 | * registers are not unnecessarily accessed). |
| 5633 | */ |
| 5634 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
| 5635 | crtc->config.has_drrs) { |
| 5636 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 5637 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 5638 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 5639 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 5640 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 5641 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5642 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 5643 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 5644 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 5645 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 5646 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5647 | } |
| 5648 | } |
| 5649 | |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 5650 | void intel_dp_set_m_n(struct intel_crtc *crtc) |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 5651 | { |
| 5652 | if (crtc->config.has_pch_encoder) |
| 5653 | intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n); |
| 5654 | else |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 5655 | intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n, |
| 5656 | &crtc->config.dp_m2_n2); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 5657 | } |
| 5658 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5659 | static void vlv_update_pll(struct intel_crtc *crtc) |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5660 | { |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5661 | u32 dpll, dpll_md; |
| 5662 | |
| 5663 | /* |
| 5664 | * Enable DPIO clock input. We should never disable the reference |
| 5665 | * clock for pipe B, since VGA hotplug / manual detection depends |
| 5666 | * on it. |
| 5667 | */ |
| 5668 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | |
| 5669 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; |
| 5670 | /* We should never disable this, set it here for state tracking */ |
| 5671 | if (crtc->pipe == PIPE_B) |
| 5672 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 5673 | dpll |= DPLL_VCO_ENABLE; |
| 5674 | crtc->config.dpll_hw_state.dpll = dpll; |
| 5675 | |
| 5676 | dpll_md = (crtc->config.pixel_multiplier - 1) |
| 5677 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 5678 | crtc->config.dpll_hw_state.dpll_md = dpll_md; |
| 5679 | } |
| 5680 | |
| 5681 | static void vlv_prepare_pll(struct intel_crtc *crtc) |
| 5682 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5683 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5684 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5685 | int pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5686 | u32 mdiv; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5687 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5688 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5689 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 5690 | mutex_lock(&dev_priv->dpio_lock); |
| 5691 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5692 | bestn = crtc->config.dpll.n; |
| 5693 | bestm1 = crtc->config.dpll.m1; |
| 5694 | bestm2 = crtc->config.dpll.m2; |
| 5695 | bestp1 = crtc->config.dpll.p1; |
| 5696 | bestp2 = crtc->config.dpll.p2; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5697 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5698 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 5699 | |
| 5700 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5701 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 5702 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5703 | |
| 5704 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5705 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5706 | |
| 5707 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5708 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5709 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5710 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5711 | |
| 5712 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5713 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5714 | |
| 5715 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5716 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 5717 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 5718 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5719 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 5720 | |
| 5721 | /* |
| 5722 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 5723 | * but we don't support that). |
| 5724 | * Note: don't use the DAC post divider as it seems unstable. |
| 5725 | */ |
| 5726 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5727 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5728 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5729 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5730 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5731 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5732 | /* Set HBR and RBR LPF coefficients */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 5733 | if (crtc->config.port_clock == 162000 || |
Ville Syrjälä | 99750bd | 2013-06-14 14:02:52 +0300 | [diff] [blame] | 5734 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) || |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5735 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5736 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b012 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 5737 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5738 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5739 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5740 | 0x00d0000f); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5741 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5742 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) || |
| 5743 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) { |
| 5744 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5745 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5746 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5747 | 0x0df40000); |
| 5748 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5749 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5750 | 0x0df70000); |
| 5751 | } else { /* HDMI or VGA */ |
| 5752 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5753 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5754 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5755 | 0x0df70000); |
| 5756 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5757 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5758 | 0x0df40000); |
| 5759 | } |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5760 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5761 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5762 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
| 5763 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) || |
| 5764 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP)) |
| 5765 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5766 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5767 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5768 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 5769 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5770 | } |
| 5771 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5772 | static void chv_update_pll(struct intel_crtc *crtc) |
| 5773 | { |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5774 | crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV | |
| 5775 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
| 5776 | DPLL_VCO_ENABLE; |
| 5777 | if (crtc->pipe != PIPE_A) |
| 5778 | crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 5779 | |
| 5780 | crtc->config.dpll_hw_state.dpll_md = |
| 5781 | (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 5782 | } |
| 5783 | |
| 5784 | static void chv_prepare_pll(struct intel_crtc *crtc) |
| 5785 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5786 | struct drm_device *dev = crtc->base.dev; |
| 5787 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5788 | int pipe = crtc->pipe; |
| 5789 | int dpll_reg = DPLL(crtc->pipe); |
| 5790 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 5791 | u32 loopfilter, intcoeff; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5792 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
| 5793 | int refclk; |
| 5794 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5795 | bestn = crtc->config.dpll.n; |
| 5796 | bestm2_frac = crtc->config.dpll.m2 & 0x3fffff; |
| 5797 | bestm1 = crtc->config.dpll.m1; |
| 5798 | bestm2 = crtc->config.dpll.m2 >> 22; |
| 5799 | bestp1 = crtc->config.dpll.p1; |
| 5800 | bestp2 = crtc->config.dpll.p2; |
| 5801 | |
| 5802 | /* |
| 5803 | * Enable Refclk and SSC |
| 5804 | */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 5805 | I915_WRITE(dpll_reg, |
| 5806 | crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 5807 | |
| 5808 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5809 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5810 | /* p1 and p2 divider */ |
| 5811 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 5812 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 5813 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 5814 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 5815 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 5816 | |
| 5817 | /* Feedback post-divider - m2 */ |
| 5818 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 5819 | |
| 5820 | /* Feedback refclk divider - n and m1 */ |
| 5821 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 5822 | DPIO_CHV_M1_DIV_BY_2 | |
| 5823 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 5824 | |
| 5825 | /* M2 fraction division */ |
| 5826 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
| 5827 | |
| 5828 | /* M2 fraction division enable */ |
| 5829 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), |
| 5830 | DPIO_CHV_FRAC_DIV_EN | |
| 5831 | (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT)); |
| 5832 | |
| 5833 | /* Loop filter */ |
| 5834 | refclk = i9xx_get_refclk(&crtc->base, 0); |
| 5835 | loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT | |
| 5836 | 2 << DPIO_CHV_GAIN_CTRL_SHIFT; |
| 5837 | if (refclk == 100000) |
| 5838 | intcoeff = 11; |
| 5839 | else if (refclk == 38400) |
| 5840 | intcoeff = 10; |
| 5841 | else |
| 5842 | intcoeff = 9; |
| 5843 | loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT; |
| 5844 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 5845 | |
| 5846 | /* AFC Recal */ |
| 5847 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 5848 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 5849 | DPIO_AFC_RECAL); |
| 5850 | |
| 5851 | mutex_unlock(&dev_priv->dpio_lock); |
| 5852 | } |
| 5853 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5854 | static void i9xx_update_pll(struct intel_crtc *crtc, |
| 5855 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5856 | int num_connectors) |
| 5857 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5858 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5859 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5860 | u32 dpll; |
| 5861 | bool is_sdvo; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5862 | struct dpll *clock = &crtc->config.dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5863 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5864 | i9xx_update_pll_dividers(crtc, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 5865 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5866 | is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) || |
| 5867 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5868 | |
| 5869 | dpll = DPLL_VGA_MODE_DIS; |
| 5870 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5871 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5872 | dpll |= DPLLB_MODE_LVDS; |
| 5873 | else |
| 5874 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 5875 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 5876 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 5877 | dpll |= (crtc->config.pixel_multiplier - 1) |
| 5878 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5879 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 5880 | |
| 5881 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 5882 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 5883 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5884 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 5885 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5886 | |
| 5887 | /* compute bitmask from p1 value */ |
| 5888 | if (IS_PINEVIEW(dev)) |
| 5889 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 5890 | else { |
| 5891 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 5892 | if (IS_G4X(dev) && reduced_clock) |
| 5893 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 5894 | } |
| 5895 | switch (clock->p2) { |
| 5896 | case 5: |
| 5897 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 5898 | break; |
| 5899 | case 7: |
| 5900 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 5901 | break; |
| 5902 | case 10: |
| 5903 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 5904 | break; |
| 5905 | case 14: |
| 5906 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 5907 | break; |
| 5908 | } |
| 5909 | if (INTEL_INFO(dev)->gen >= 4) |
| 5910 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 5911 | |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 5912 | if (crtc->config.sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5913 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5914 | else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5915 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 5916 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 5917 | else |
| 5918 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 5919 | |
| 5920 | dpll |= DPLL_VCO_ENABLE; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5921 | crtc->config.dpll_hw_state.dpll = dpll; |
| 5922 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5923 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 5924 | u32 dpll_md = (crtc->config.pixel_multiplier - 1) |
| 5925 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5926 | crtc->config.dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5927 | } |
| 5928 | } |
| 5929 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5930 | static void i8xx_update_pll(struct intel_crtc *crtc, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5931 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5932 | int num_connectors) |
| 5933 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5934 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5935 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5936 | u32 dpll; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5937 | struct dpll *clock = &crtc->config.dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5938 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5939 | i9xx_update_pll_dividers(crtc, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 5940 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5941 | dpll = DPLL_VGA_MODE_DIS; |
| 5942 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5943 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5944 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 5945 | } else { |
| 5946 | if (clock->p1 == 2) |
| 5947 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 5948 | else |
| 5949 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 5950 | if (clock->p2 == 4) |
| 5951 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 5952 | } |
| 5953 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 5954 | if (!IS_I830(dev) && intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 5955 | dpll |= DPLL_DVO_2X_MODE; |
| 5956 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5957 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5958 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 5959 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 5960 | else |
| 5961 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 5962 | |
| 5963 | dpll |= DPLL_VCO_ENABLE; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5964 | crtc->config.dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5965 | } |
| 5966 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 5967 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5968 | { |
| 5969 | struct drm_device *dev = intel_crtc->base.dev; |
| 5970 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5971 | enum pipe pipe = intel_crtc->pipe; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 5972 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 5973 | struct drm_display_mode *adjusted_mode = |
| 5974 | &intel_crtc->config.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 5975 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 5976 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 5977 | |
| 5978 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 5979 | * the hw state checker will get angry at the mismatch. */ |
| 5980 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 5981 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5982 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 5983 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5984 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 5985 | crtc_vtotal -= 1; |
| 5986 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 5987 | |
| 5988 | if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO)) |
| 5989 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 5990 | else |
| 5991 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 5992 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 5993 | if (vsyncshift < 0) |
| 5994 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5995 | } |
| 5996 | |
| 5997 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 5998 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5999 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6000 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6001 | (adjusted_mode->crtc_hdisplay - 1) | |
| 6002 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6003 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6004 | (adjusted_mode->crtc_hblank_start - 1) | |
| 6005 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6006 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6007 | (adjusted_mode->crtc_hsync_start - 1) | |
| 6008 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 6009 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6010 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6011 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6012 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6013 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6014 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6015 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6016 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6017 | (adjusted_mode->crtc_vsync_start - 1) | |
| 6018 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 6019 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 6020 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 6021 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 6022 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 6023 | * bits. */ |
| 6024 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 6025 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 6026 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 6027 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6028 | /* pipesrc controls the size that is scaled from, which should |
| 6029 | * always be the user's requested size. |
| 6030 | */ |
| 6031 | I915_WRITE(PIPESRC(pipe), |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 6032 | ((intel_crtc->config.pipe_src_w - 1) << 16) | |
| 6033 | (intel_crtc->config.pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6034 | } |
| 6035 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6036 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
| 6037 | struct intel_crtc_config *pipe_config) |
| 6038 | { |
| 6039 | struct drm_device *dev = crtc->base.dev; |
| 6040 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6041 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 6042 | uint32_t tmp; |
| 6043 | |
| 6044 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
| 6045 | pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 6046 | pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
| 6047 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
| 6048 | pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 6049 | pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
| 6050 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
| 6051 | pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 6052 | pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
| 6053 | |
| 6054 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
| 6055 | pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 6056 | pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
| 6057 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
| 6058 | pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 6059 | pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
| 6060 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
| 6061 | pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 6062 | pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
| 6063 | |
| 6064 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
| 6065 | pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 6066 | pipe_config->adjusted_mode.crtc_vtotal += 1; |
| 6067 | pipe_config->adjusted_mode.crtc_vblank_end += 1; |
| 6068 | } |
| 6069 | |
| 6070 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 6071 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 6072 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 6073 | |
| 6074 | pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h; |
| 6075 | pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6076 | } |
| 6077 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6078 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
| 6079 | struct intel_crtc_config *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6080 | { |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6081 | mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay; |
| 6082 | mode->htotal = pipe_config->adjusted_mode.crtc_htotal; |
| 6083 | mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start; |
| 6084 | mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6085 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6086 | mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay; |
| 6087 | mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal; |
| 6088 | mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start; |
| 6089 | mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6090 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6091 | mode->flags = pipe_config->adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6092 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6093 | mode->clock = pipe_config->adjusted_mode.crtc_clock; |
| 6094 | mode->flags |= pipe_config->adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6095 | } |
| 6096 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6097 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 6098 | { |
| 6099 | struct drm_device *dev = intel_crtc->base.dev; |
| 6100 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6101 | uint32_t pipeconf; |
| 6102 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6103 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6104 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 6105 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 6106 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 6107 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 6108 | |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6109 | if (intel_crtc->config.double_wide) |
| 6110 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6111 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6112 | /* only g4x and later have fancy bpc/dither controls */ |
| 6113 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6114 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
| 6115 | if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30) |
| 6116 | pipeconf |= PIPECONF_DITHER_EN | |
| 6117 | PIPECONF_DITHER_TYPE_SP; |
| 6118 | |
| 6119 | switch (intel_crtc->config.pipe_bpp) { |
| 6120 | case 18: |
| 6121 | pipeconf |= PIPECONF_6BPC; |
| 6122 | break; |
| 6123 | case 24: |
| 6124 | pipeconf |= PIPECONF_8BPC; |
| 6125 | break; |
| 6126 | case 30: |
| 6127 | pipeconf |= PIPECONF_10BPC; |
| 6128 | break; |
| 6129 | default: |
| 6130 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 6131 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6132 | } |
| 6133 | } |
| 6134 | |
| 6135 | if (HAS_PIPE_CXSR(dev)) { |
| 6136 | if (intel_crtc->lowfreq_avail) { |
| 6137 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 6138 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 6139 | } else { |
| 6140 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6141 | } |
| 6142 | } |
| 6143 | |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 6144 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
| 6145 | if (INTEL_INFO(dev)->gen < 4 || |
| 6146 | intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO)) |
| 6147 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 6148 | else |
| 6149 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 6150 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6151 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 6152 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6153 | if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range) |
| 6154 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 6155 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6156 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 6157 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 6158 | } |
| 6159 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6160 | static int i9xx_crtc_mode_set(struct drm_crtc *crtc, |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6161 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6162 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6163 | { |
| 6164 | struct drm_device *dev = crtc->dev; |
| 6165 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6166 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6167 | int refclk, num_connectors = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6168 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | a16af721 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 6169 | bool ok, has_reduced_clock = false; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6170 | bool is_lvds = false, is_dsi = false; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6171 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 6172 | const intel_limit_t *limit; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6173 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 6174 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6175 | switch (encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6176 | case INTEL_OUTPUT_LVDS: |
| 6177 | is_lvds = true; |
| 6178 | break; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6179 | case INTEL_OUTPUT_DSI: |
| 6180 | is_dsi = true; |
| 6181 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6182 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 6183 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6184 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6185 | } |
| 6186 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6187 | if (is_dsi) |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6188 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6189 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6190 | if (!intel_crtc->config.clock_set) { |
| 6191 | refclk = i9xx_get_refclk(crtc, num_connectors); |
| 6192 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6193 | /* |
| 6194 | * Returns a set of divisors for the desired target clock with |
| 6195 | * the given refclk, or FALSE. The returned values represent |
| 6196 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + |
| 6197 | * 2) / p1 / p2. |
| 6198 | */ |
| 6199 | limit = intel_limit(crtc, refclk); |
| 6200 | ok = dev_priv->display.find_dpll(limit, crtc, |
| 6201 | intel_crtc->config.port_clock, |
| 6202 | refclk, NULL, &clock); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6203 | if (!ok) { |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6204 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 6205 | return -EINVAL; |
| 6206 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6207 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6208 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 6209 | /* |
| 6210 | * Ensure we match the reduced clock's P to the target |
| 6211 | * clock. If the clocks don't match, we can't switch |
| 6212 | * the display clock by using the FP0/FP1. In such case |
| 6213 | * we will disable the LVDS downclock feature. |
| 6214 | */ |
| 6215 | has_reduced_clock = |
| 6216 | dev_priv->display.find_dpll(limit, crtc, |
| 6217 | dev_priv->lvds_downclock, |
| 6218 | refclk, &clock, |
| 6219 | &reduced_clock); |
| 6220 | } |
| 6221 | /* Compat-code for transition, will disappear. */ |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6222 | intel_crtc->config.dpll.n = clock.n; |
| 6223 | intel_crtc->config.dpll.m1 = clock.m1; |
| 6224 | intel_crtc->config.dpll.m2 = clock.m2; |
| 6225 | intel_crtc->config.dpll.p1 = clock.p1; |
| 6226 | intel_crtc->config.dpll.p2 = clock.p2; |
| 6227 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6228 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6229 | if (IS_GEN2(dev)) { |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 6230 | i8xx_update_pll(intel_crtc, |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6231 | has_reduced_clock ? &reduced_clock : NULL, |
| 6232 | num_connectors); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6233 | } else if (IS_CHERRYVIEW(dev)) { |
| 6234 | chv_update_pll(intel_crtc); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6235 | } else if (IS_VALLEYVIEW(dev)) { |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6236 | vlv_update_pll(intel_crtc); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6237 | } else { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6238 | i9xx_update_pll(intel_crtc, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6239 | has_reduced_clock ? &reduced_clock : NULL, |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 6240 | num_connectors); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6241 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6242 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 6243 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6244 | } |
| 6245 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6246 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
| 6247 | struct intel_crtc_config *pipe_config) |
| 6248 | { |
| 6249 | struct drm_device *dev = crtc->base.dev; |
| 6250 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6251 | uint32_t tmp; |
| 6252 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 6253 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 6254 | return; |
| 6255 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6256 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6257 | if (!(tmp & PFIT_ENABLE)) |
| 6258 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6259 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6260 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6261 | if (INTEL_INFO(dev)->gen < 4) { |
| 6262 | if (crtc->pipe != PIPE_B) |
| 6263 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6264 | } else { |
| 6265 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 6266 | return; |
| 6267 | } |
| 6268 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6269 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6270 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 6271 | if (INTEL_INFO(dev)->gen < 5) |
| 6272 | pipe_config->gmch_pfit.lvds_border_bits = |
| 6273 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 6274 | } |
| 6275 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6276 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
| 6277 | struct intel_crtc_config *pipe_config) |
| 6278 | { |
| 6279 | struct drm_device *dev = crtc->base.dev; |
| 6280 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6281 | int pipe = pipe_config->cpu_transcoder; |
| 6282 | intel_clock_t clock; |
| 6283 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 6284 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6285 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 6286 | /* In case of MIPI DPLL will not even be used */ |
| 6287 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) |
| 6288 | return; |
| 6289 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6290 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6291 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6292 | mutex_unlock(&dev_priv->dpio_lock); |
| 6293 | |
| 6294 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 6295 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 6296 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 6297 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 6298 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 6299 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 6300 | vlv_clock(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6301 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 6302 | /* clock.dot is the fast clock */ |
| 6303 | pipe_config->port_clock = clock.dot / 5; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6304 | } |
| 6305 | |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6306 | static void i9xx_get_plane_config(struct intel_crtc *crtc, |
| 6307 | struct intel_plane_config *plane_config) |
| 6308 | { |
| 6309 | struct drm_device *dev = crtc->base.dev; |
| 6310 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6311 | u32 val, base, offset; |
| 6312 | int pipe = crtc->pipe, plane = crtc->plane; |
| 6313 | int fourcc, pixel_format; |
| 6314 | int aligned_height; |
| 6315 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 6316 | crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL); |
| 6317 | if (!crtc->base.primary->fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6318 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 6319 | return; |
| 6320 | } |
| 6321 | |
| 6322 | val = I915_READ(DSPCNTR(plane)); |
| 6323 | |
| 6324 | if (INTEL_INFO(dev)->gen >= 4) |
| 6325 | if (val & DISPPLANE_TILED) |
| 6326 | plane_config->tiled = true; |
| 6327 | |
| 6328 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
| 6329 | fourcc = intel_format_to_fourcc(pixel_format); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 6330 | crtc->base.primary->fb->pixel_format = fourcc; |
| 6331 | crtc->base.primary->fb->bits_per_pixel = |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6332 | drm_format_plane_cpp(fourcc, 0) * 8; |
| 6333 | |
| 6334 | if (INTEL_INFO(dev)->gen >= 4) { |
| 6335 | if (plane_config->tiled) |
| 6336 | offset = I915_READ(DSPTILEOFF(plane)); |
| 6337 | else |
| 6338 | offset = I915_READ(DSPLINOFF(plane)); |
| 6339 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 6340 | } else { |
| 6341 | base = I915_READ(DSPADDR(plane)); |
| 6342 | } |
| 6343 | plane_config->base = base; |
| 6344 | |
| 6345 | val = I915_READ(PIPESRC(pipe)); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 6346 | crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1; |
| 6347 | crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6348 | |
| 6349 | val = I915_READ(DSPSTRIDE(pipe)); |
Rafael Barbalho | 026b96e | 2014-07-28 19:56:27 +0100 | [diff] [blame] | 6350 | crtc->base.primary->fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6351 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 6352 | aligned_height = intel_align_height(dev, crtc->base.primary->fb->height, |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6353 | plane_config->tiled); |
| 6354 | |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 6355 | plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] * |
| 6356 | aligned_height); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6357 | |
| 6358 | DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 6359 | pipe, plane, crtc->base.primary->fb->width, |
| 6360 | crtc->base.primary->fb->height, |
| 6361 | crtc->base.primary->fb->bits_per_pixel, base, |
| 6362 | crtc->base.primary->fb->pitches[0], |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6363 | plane_config->size); |
| 6364 | |
| 6365 | } |
| 6366 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 6367 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
| 6368 | struct intel_crtc_config *pipe_config) |
| 6369 | { |
| 6370 | struct drm_device *dev = crtc->base.dev; |
| 6371 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6372 | int pipe = pipe_config->cpu_transcoder; |
| 6373 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
| 6374 | intel_clock_t clock; |
| 6375 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2; |
| 6376 | int refclk = 100000; |
| 6377 | |
| 6378 | mutex_lock(&dev_priv->dpio_lock); |
| 6379 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 6380 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 6381 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 6382 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
| 6383 | mutex_unlock(&dev_priv->dpio_lock); |
| 6384 | |
| 6385 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; |
| 6386 | clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff); |
| 6387 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 6388 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 6389 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 6390 | |
| 6391 | chv_clock(refclk, &clock); |
| 6392 | |
| 6393 | /* clock.dot is the fast clock */ |
| 6394 | pipe_config->port_clock = clock.dot / 5; |
| 6395 | } |
| 6396 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6397 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
| 6398 | struct intel_crtc_config *pipe_config) |
| 6399 | { |
| 6400 | struct drm_device *dev = crtc->base.dev; |
| 6401 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6402 | uint32_t tmp; |
| 6403 | |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 6404 | if (!intel_display_power_enabled(dev_priv, |
| 6405 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 6406 | return false; |
| 6407 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 6408 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 6409 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 6410 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6411 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 6412 | if (!(tmp & PIPECONF_ENABLE)) |
| 6413 | return false; |
| 6414 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 6415 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
| 6416 | switch (tmp & PIPECONF_BPC_MASK) { |
| 6417 | case PIPECONF_6BPC: |
| 6418 | pipe_config->pipe_bpp = 18; |
| 6419 | break; |
| 6420 | case PIPECONF_8BPC: |
| 6421 | pipe_config->pipe_bpp = 24; |
| 6422 | break; |
| 6423 | case PIPECONF_10BPC: |
| 6424 | pipe_config->pipe_bpp = 30; |
| 6425 | break; |
| 6426 | default: |
| 6427 | break; |
| 6428 | } |
| 6429 | } |
| 6430 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 6431 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
| 6432 | pipe_config->limited_color_range = true; |
| 6433 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 6434 | if (INTEL_INFO(dev)->gen < 4) |
| 6435 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 6436 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6437 | intel_get_pipe_timings(crtc, pipe_config); |
| 6438 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6439 | i9xx_get_pfit_config(crtc, pipe_config); |
| 6440 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6441 | if (INTEL_INFO(dev)->gen >= 4) { |
| 6442 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
| 6443 | pipe_config->pixel_multiplier = |
| 6444 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 6445 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6446 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6447 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 6448 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 6449 | pipe_config->pixel_multiplier = |
| 6450 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 6451 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 6452 | } else { |
| 6453 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 6454 | * port and will be fixed up in the encoder->get_config |
| 6455 | * function. */ |
| 6456 | pipe_config->pixel_multiplier = 1; |
| 6457 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6458 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
| 6459 | if (!IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 6460 | /* |
| 6461 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 6462 | * on 830. Filter it out here so that we don't |
| 6463 | * report errors due to that. |
| 6464 | */ |
| 6465 | if (IS_I830(dev)) |
| 6466 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 6467 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6468 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 6469 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 6470 | } else { |
| 6471 | /* Mask out read-only status bits. */ |
| 6472 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 6473 | DPLL_PORTC_READY_MASK | |
| 6474 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6475 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6476 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 6477 | if (IS_CHERRYVIEW(dev)) |
| 6478 | chv_crtc_clock_get(crtc, pipe_config); |
| 6479 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6480 | vlv_crtc_clock_get(crtc, pipe_config); |
| 6481 | else |
| 6482 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 6483 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6484 | return true; |
| 6485 | } |
| 6486 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6487 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6488 | { |
| 6489 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6490 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6491 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6492 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6493 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6494 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6495 | bool has_ck505 = false; |
| 6496 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6497 | |
| 6498 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 6499 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6500 | switch (encoder->type) { |
| 6501 | case INTEL_OUTPUT_LVDS: |
| 6502 | has_panel = true; |
| 6503 | has_lvds = true; |
| 6504 | break; |
| 6505 | case INTEL_OUTPUT_EDP: |
| 6506 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 6507 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6508 | has_cpu_edp = true; |
| 6509 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6510 | } |
| 6511 | } |
| 6512 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6513 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6514 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6515 | can_ssc = has_ck505; |
| 6516 | } else { |
| 6517 | has_ck505 = false; |
| 6518 | can_ssc = true; |
| 6519 | } |
| 6520 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 6521 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 6522 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6523 | |
| 6524 | /* Ironlake: try to setup display ref clock before DPLL |
| 6525 | * enabling. This is only under driver's control after |
| 6526 | * PCH B stepping, previous chipset stepping should be |
| 6527 | * ignoring this setting. |
| 6528 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6529 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6530 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6531 | /* As we must carefully and slowly disable/enable each source in turn, |
| 6532 | * compute the final state we want first and check if we need to |
| 6533 | * make any changes at all. |
| 6534 | */ |
| 6535 | final = val; |
| 6536 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6537 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6538 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6539 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6540 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 6541 | |
| 6542 | final &= ~DREF_SSC_SOURCE_MASK; |
| 6543 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 6544 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6545 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6546 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6547 | final |= DREF_SSC_SOURCE_ENABLE; |
| 6548 | |
| 6549 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 6550 | final |= DREF_SSC1_ENABLE; |
| 6551 | |
| 6552 | if (has_cpu_edp) { |
| 6553 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 6554 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 6555 | else |
| 6556 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 6557 | } else |
| 6558 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 6559 | } else { |
| 6560 | final |= DREF_SSC_SOURCE_DISABLE; |
| 6561 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 6562 | } |
| 6563 | |
| 6564 | if (final == val) |
| 6565 | return; |
| 6566 | |
| 6567 | /* Always enable nonspread source */ |
| 6568 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 6569 | |
| 6570 | if (has_ck505) |
| 6571 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 6572 | else |
| 6573 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 6574 | |
| 6575 | if (has_panel) { |
| 6576 | val &= ~DREF_SSC_SOURCE_MASK; |
| 6577 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6578 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6579 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6580 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6581 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6582 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 6583 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6584 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6585 | |
| 6586 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6587 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6588 | POSTING_READ(PCH_DREF_CONTROL); |
| 6589 | udelay(200); |
| 6590 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6591 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6592 | |
| 6593 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6594 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6595 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6596 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6597 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 6598 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6599 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6600 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6601 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6602 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6603 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6604 | POSTING_READ(PCH_DREF_CONTROL); |
| 6605 | udelay(200); |
| 6606 | } else { |
| 6607 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 6608 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6609 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6610 | |
| 6611 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6612 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6613 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6614 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6615 | POSTING_READ(PCH_DREF_CONTROL); |
| 6616 | udelay(200); |
| 6617 | |
| 6618 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6619 | val &= ~DREF_SSC_SOURCE_MASK; |
| 6620 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6621 | |
| 6622 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6623 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6624 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6625 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6626 | POSTING_READ(PCH_DREF_CONTROL); |
| 6627 | udelay(200); |
| 6628 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6629 | |
| 6630 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6631 | } |
| 6632 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6633 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6634 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6635 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6636 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6637 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 6638 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 6639 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6640 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6641 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 6642 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 6643 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6644 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6645 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 6646 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 6647 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6648 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6649 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 6650 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 6651 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6652 | } |
| 6653 | |
| 6654 | /* WaMPhyProgramming:hsw */ |
| 6655 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 6656 | { |
| 6657 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6658 | |
| 6659 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 6660 | tmp &= ~(0xFF << 24); |
| 6661 | tmp |= (0x12 << 24); |
| 6662 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 6663 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6664 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 6665 | tmp |= (1 << 11); |
| 6666 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 6667 | |
| 6668 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 6669 | tmp |= (1 << 11); |
| 6670 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 6671 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6672 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 6673 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 6674 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 6675 | |
| 6676 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 6677 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 6678 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 6679 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6680 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 6681 | tmp &= ~(7 << 13); |
| 6682 | tmp |= (5 << 13); |
| 6683 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6684 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6685 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 6686 | tmp &= ~(7 << 13); |
| 6687 | tmp |= (5 << 13); |
| 6688 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6689 | |
| 6690 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 6691 | tmp &= ~0xFF; |
| 6692 | tmp |= 0x1C; |
| 6693 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 6694 | |
| 6695 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 6696 | tmp &= ~0xFF; |
| 6697 | tmp |= 0x1C; |
| 6698 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 6699 | |
| 6700 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 6701 | tmp &= ~(0xFF << 16); |
| 6702 | tmp |= (0x1C << 16); |
| 6703 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 6704 | |
| 6705 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 6706 | tmp &= ~(0xFF << 16); |
| 6707 | tmp |= (0x1C << 16); |
| 6708 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 6709 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6710 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 6711 | tmp |= (1 << 27); |
| 6712 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6713 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6714 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 6715 | tmp |= (1 << 27); |
| 6716 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6717 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6718 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 6719 | tmp &= ~(0xF << 28); |
| 6720 | tmp |= (4 << 28); |
| 6721 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6722 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6723 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 6724 | tmp &= ~(0xF << 28); |
| 6725 | tmp |= (4 << 28); |
| 6726 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6727 | } |
| 6728 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6729 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 6730 | * Programming" based on the parameters passed: |
| 6731 | * - Sequence to enable CLKOUT_DP |
| 6732 | * - Sequence to enable CLKOUT_DP without spread |
| 6733 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 6734 | */ |
| 6735 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 6736 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6737 | { |
| 6738 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6739 | uint32_t reg, tmp; |
| 6740 | |
| 6741 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 6742 | with_spread = true; |
| 6743 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && |
| 6744 | with_fdi, "LP PCH doesn't have FDI\n")) |
| 6745 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6746 | |
| 6747 | mutex_lock(&dev_priv->dpio_lock); |
| 6748 | |
| 6749 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 6750 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 6751 | tmp |= SBI_SSCCTL_PATHALT; |
| 6752 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 6753 | |
| 6754 | udelay(24); |
| 6755 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6756 | if (with_spread) { |
| 6757 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 6758 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 6759 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6760 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6761 | if (with_fdi) { |
| 6762 | lpt_reset_fdi_mphy(dev_priv); |
| 6763 | lpt_program_fdi_mphy(dev_priv); |
| 6764 | } |
| 6765 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6766 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6767 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 6768 | SBI_GEN0 : SBI_DBUFF0; |
| 6769 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 6770 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 6771 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 6772 | |
| 6773 | mutex_unlock(&dev_priv->dpio_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6774 | } |
| 6775 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 6776 | /* Sequence to disable CLKOUT_DP */ |
| 6777 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 6778 | { |
| 6779 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6780 | uint32_t reg, tmp; |
| 6781 | |
| 6782 | mutex_lock(&dev_priv->dpio_lock); |
| 6783 | |
| 6784 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 6785 | SBI_GEN0 : SBI_DBUFF0; |
| 6786 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 6787 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 6788 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 6789 | |
| 6790 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 6791 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 6792 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 6793 | tmp |= SBI_SSCCTL_PATHALT; |
| 6794 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 6795 | udelay(32); |
| 6796 | } |
| 6797 | tmp |= SBI_SSCCTL_DISABLE; |
| 6798 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 6799 | } |
| 6800 | |
| 6801 | mutex_unlock(&dev_priv->dpio_lock); |
| 6802 | } |
| 6803 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 6804 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 6805 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 6806 | struct intel_encoder *encoder; |
| 6807 | bool has_vga = false; |
| 6808 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 6809 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 6810 | switch (encoder->type) { |
| 6811 | case INTEL_OUTPUT_ANALOG: |
| 6812 | has_vga = true; |
| 6813 | break; |
| 6814 | } |
| 6815 | } |
| 6816 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 6817 | if (has_vga) |
| 6818 | lpt_enable_clkout_dp(dev, true, true); |
| 6819 | else |
| 6820 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 6821 | } |
| 6822 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6823 | /* |
| 6824 | * Initialize reference clocks when the driver loads |
| 6825 | */ |
| 6826 | void intel_init_pch_refclk(struct drm_device *dev) |
| 6827 | { |
| 6828 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 6829 | ironlake_init_pch_refclk(dev); |
| 6830 | else if (HAS_PCH_LPT(dev)) |
| 6831 | lpt_init_pch_refclk(dev); |
| 6832 | } |
| 6833 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6834 | static int ironlake_get_refclk(struct drm_crtc *crtc) |
| 6835 | { |
| 6836 | struct drm_device *dev = crtc->dev; |
| 6837 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6838 | struct intel_encoder *encoder; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6839 | int num_connectors = 0; |
| 6840 | bool is_lvds = false; |
| 6841 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 6842 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6843 | switch (encoder->type) { |
| 6844 | case INTEL_OUTPUT_LVDS: |
| 6845 | is_lvds = true; |
| 6846 | break; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6847 | } |
| 6848 | num_connectors++; |
| 6849 | } |
| 6850 | |
| 6851 | if (is_lvds && intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 6852 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6853 | dev_priv->vbt.lvds_ssc_freq); |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 6854 | return dev_priv->vbt.lvds_ssc_freq; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6855 | } |
| 6856 | |
| 6857 | return 120000; |
| 6858 | } |
| 6859 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 6860 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6861 | { |
| 6862 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 6863 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6864 | int pipe = intel_crtc->pipe; |
| 6865 | uint32_t val; |
| 6866 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 6867 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6868 | |
Daniel Vetter | 965e0c4 | 2013-03-27 00:44:57 +0100 | [diff] [blame] | 6869 | switch (intel_crtc->config.pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6870 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 6871 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6872 | break; |
| 6873 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 6874 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6875 | break; |
| 6876 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 6877 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6878 | break; |
| 6879 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 6880 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6881 | break; |
| 6882 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 6883 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 6884 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6885 | } |
| 6886 | |
Daniel Vetter | d8b3224 | 2013-04-25 17:54:44 +0200 | [diff] [blame] | 6887 | if (intel_crtc->config.dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6888 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 6889 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 6890 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6891 | val |= PIPECONF_INTERLACED_ILK; |
| 6892 | else |
| 6893 | val |= PIPECONF_PROGRESSIVE; |
| 6894 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6895 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 6896 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 6897 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6898 | I915_WRITE(PIPECONF(pipe), val); |
| 6899 | POSTING_READ(PIPECONF(pipe)); |
| 6900 | } |
| 6901 | |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6902 | /* |
| 6903 | * Set up the pipe CSC unit. |
| 6904 | * |
| 6905 | * Currently only full range RGB to limited range RGB conversion |
| 6906 | * is supported, but eventually this should handle various |
| 6907 | * RGB<->YCbCr scenarios as well. |
| 6908 | */ |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6909 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6910 | { |
| 6911 | struct drm_device *dev = crtc->dev; |
| 6912 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6913 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6914 | int pipe = intel_crtc->pipe; |
| 6915 | uint16_t coeff = 0x7800; /* 1.0 */ |
| 6916 | |
| 6917 | /* |
| 6918 | * TODO: Check what kind of values actually come out of the pipe |
| 6919 | * with these coeff/postoff values and adjust to get the best |
| 6920 | * accuracy. Perhaps we even need to take the bpc value into |
| 6921 | * consideration. |
| 6922 | */ |
| 6923 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6924 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6925 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
| 6926 | |
| 6927 | /* |
| 6928 | * GY/GU and RY/RU should be the other way around according |
| 6929 | * to BSpec, but reality doesn't agree. Just set them up in |
| 6930 | * a way that results in the correct picture. |
| 6931 | */ |
| 6932 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); |
| 6933 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); |
| 6934 | |
| 6935 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); |
| 6936 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); |
| 6937 | |
| 6938 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); |
| 6939 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); |
| 6940 | |
| 6941 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); |
| 6942 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); |
| 6943 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); |
| 6944 | |
| 6945 | if (INTEL_INFO(dev)->gen > 6) { |
| 6946 | uint16_t postoff = 0; |
| 6947 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6948 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 32cf0cb | 2013-11-28 22:10:38 +0200 | [diff] [blame] | 6949 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6950 | |
| 6951 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); |
| 6952 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); |
| 6953 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); |
| 6954 | |
| 6955 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); |
| 6956 | } else { |
| 6957 | uint32_t mode = CSC_MODE_YUV_TO_RGB; |
| 6958 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6959 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6960 | mode |= CSC_BLACK_SCREEN_OFFSET; |
| 6961 | |
| 6962 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); |
| 6963 | } |
| 6964 | } |
| 6965 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 6966 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6967 | { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 6968 | struct drm_device *dev = crtc->dev; |
| 6969 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6970 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 6971 | enum pipe pipe = intel_crtc->pipe; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 6972 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6973 | uint32_t val; |
| 6974 | |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 6975 | val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6976 | |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 6977 | if (IS_HASWELL(dev) && intel_crtc->config.dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6978 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 6979 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 6980 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6981 | val |= PIPECONF_INTERLACED_ILK; |
| 6982 | else |
| 6983 | val |= PIPECONF_PROGRESSIVE; |
| 6984 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 6985 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 6986 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 6987 | |
| 6988 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); |
| 6989 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 6990 | |
| 6991 | if (IS_BROADWELL(dev)) { |
| 6992 | val = 0; |
| 6993 | |
| 6994 | switch (intel_crtc->config.pipe_bpp) { |
| 6995 | case 18: |
| 6996 | val |= PIPEMISC_DITHER_6_BPC; |
| 6997 | break; |
| 6998 | case 24: |
| 6999 | val |= PIPEMISC_DITHER_8_BPC; |
| 7000 | break; |
| 7001 | case 30: |
| 7002 | val |= PIPEMISC_DITHER_10_BPC; |
| 7003 | break; |
| 7004 | case 36: |
| 7005 | val |= PIPEMISC_DITHER_12_BPC; |
| 7006 | break; |
| 7007 | default: |
| 7008 | /* Case prevented by pipe_config_set_bpp. */ |
| 7009 | BUG(); |
| 7010 | } |
| 7011 | |
| 7012 | if (intel_crtc->config.dither) |
| 7013 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 7014 | |
| 7015 | I915_WRITE(PIPEMISC(pipe), val); |
| 7016 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7017 | } |
| 7018 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7019 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7020 | intel_clock_t *clock, |
| 7021 | bool *has_reduced_clock, |
| 7022 | intel_clock_t *reduced_clock) |
| 7023 | { |
| 7024 | struct drm_device *dev = crtc->dev; |
| 7025 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7026 | struct intel_encoder *intel_encoder; |
| 7027 | int refclk; |
| 7028 | const intel_limit_t *limit; |
Daniel Vetter | a16af721 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 7029 | bool ret, is_lvds = false; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7030 | |
| 7031 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 7032 | switch (intel_encoder->type) { |
| 7033 | case INTEL_OUTPUT_LVDS: |
| 7034 | is_lvds = true; |
| 7035 | break; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7036 | } |
| 7037 | } |
| 7038 | |
| 7039 | refclk = ironlake_get_refclk(crtc); |
| 7040 | |
| 7041 | /* |
| 7042 | * Returns a set of divisors for the desired target clock with the given |
| 7043 | * refclk, or FALSE. The returned values represent the clock equation: |
| 7044 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 7045 | */ |
| 7046 | limit = intel_limit(crtc, refclk); |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 7047 | ret = dev_priv->display.find_dpll(limit, crtc, |
| 7048 | to_intel_crtc(crtc)->config.port_clock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7049 | refclk, NULL, clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7050 | if (!ret) |
| 7051 | return false; |
| 7052 | |
| 7053 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 7054 | /* |
| 7055 | * Ensure we match the reduced clock's P to the target clock. |
| 7056 | * If the clocks don't match, we can't switch the display clock |
| 7057 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 7058 | * downclock feature. |
| 7059 | */ |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7060 | *has_reduced_clock = |
| 7061 | dev_priv->display.find_dpll(limit, crtc, |
| 7062 | dev_priv->lvds_downclock, |
| 7063 | refclk, clock, |
| 7064 | reduced_clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7065 | } |
| 7066 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7067 | return true; |
| 7068 | } |
| 7069 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7070 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 7071 | { |
| 7072 | /* |
| 7073 | * Account for spread spectrum to avoid |
| 7074 | * oversubscribing the link. Max center spread |
| 7075 | * is 2.5%; use 5% for safety's sake. |
| 7076 | */ |
| 7077 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 7078 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7079 | } |
| 7080 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7081 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 7082 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7083 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 7084 | } |
| 7085 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7086 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7087 | u32 *fp, |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7088 | intel_clock_t *reduced_clock, u32 *fp2) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7089 | { |
| 7090 | struct drm_crtc *crtc = &intel_crtc->base; |
| 7091 | struct drm_device *dev = crtc->dev; |
| 7092 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7093 | struct intel_encoder *intel_encoder; |
| 7094 | uint32_t dpll; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7095 | int factor, num_connectors = 0; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 7096 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7097 | |
| 7098 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 7099 | switch (intel_encoder->type) { |
| 7100 | case INTEL_OUTPUT_LVDS: |
| 7101 | is_lvds = true; |
| 7102 | break; |
| 7103 | case INTEL_OUTPUT_SDVO: |
| 7104 | case INTEL_OUTPUT_HDMI: |
| 7105 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7106 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7107 | } |
| 7108 | |
| 7109 | num_connectors++; |
| 7110 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7111 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7112 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7113 | factor = 21; |
| 7114 | if (is_lvds) { |
| 7115 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 7116 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 7117 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7118 | factor = 25; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 7119 | } else if (intel_crtc->config.sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7120 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7121 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7122 | if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor)) |
Daniel Vetter | 7d0ac5b | 2013-04-04 22:20:32 +0200 | [diff] [blame] | 7123 | *fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7124 | |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7125 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
| 7126 | *fp2 |= FP_CB_TUNE; |
| 7127 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 7128 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7129 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7130 | if (is_lvds) |
| 7131 | dpll |= DPLLB_MODE_LVDS; |
| 7132 | else |
| 7133 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7134 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7135 | dpll |= (intel_crtc->config.pixel_multiplier - 1) |
| 7136 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7137 | |
| 7138 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7139 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 9566e9a | 2013-04-19 11:14:36 +0200 | [diff] [blame] | 7140 | if (intel_crtc->config.has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7141 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7142 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7143 | /* compute bitmask from p1 value */ |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7144 | 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] | 7145 | /* also FPA1 */ |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7146 | 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] | 7147 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7148 | switch (intel_crtc->config.dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7149 | case 5: |
| 7150 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7151 | break; |
| 7152 | case 7: |
| 7153 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7154 | break; |
| 7155 | case 10: |
| 7156 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7157 | break; |
| 7158 | case 14: |
| 7159 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7160 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7161 | } |
| 7162 | |
Daniel Vetter | b4c09f3 | 2013-04-30 14:01:42 +0200 | [diff] [blame] | 7163 | 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] | 7164 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7165 | else |
| 7166 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7167 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 7168 | return dpll | DPLL_VCO_ENABLE; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7169 | } |
| 7170 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7171 | static int ironlake_crtc_mode_set(struct drm_crtc *crtc, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7172 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 7173 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7174 | { |
| 7175 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7176 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7177 | int num_connectors = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7178 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7179 | u32 dpll = 0, fp = 0, fp2 = 0; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 7180 | bool ok, has_reduced_clock = false; |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 7181 | bool is_lvds = false; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 7182 | struct intel_encoder *encoder; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 7183 | struct intel_shared_dpll *pll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7184 | |
| 7185 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 7186 | switch (encoder->type) { |
| 7187 | case INTEL_OUTPUT_LVDS: |
| 7188 | is_lvds = true; |
| 7189 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7190 | } |
| 7191 | |
| 7192 | num_connectors++; |
| 7193 | } |
| 7194 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 7195 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 7196 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 7197 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 7198 | ok = ironlake_compute_clocks(crtc, &clock, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7199 | &has_reduced_clock, &reduced_clock); |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7200 | if (!ok && !intel_crtc->config.clock_set) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7201 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7202 | return -EINVAL; |
| 7203 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7204 | /* Compat-code for transition, will disappear. */ |
| 7205 | if (!intel_crtc->config.clock_set) { |
| 7206 | intel_crtc->config.dpll.n = clock.n; |
| 7207 | intel_crtc->config.dpll.m1 = clock.m1; |
| 7208 | intel_crtc->config.dpll.m2 = clock.m2; |
| 7209 | intel_crtc->config.dpll.p1 = clock.p1; |
| 7210 | intel_crtc->config.dpll.p2 = clock.p2; |
| 7211 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7212 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 7213 | /* 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] | 7214 | if (intel_crtc->config.has_pch_encoder) { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7215 | fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7216 | if (has_reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7217 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7218 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7219 | dpll = ironlake_compute_dpll(intel_crtc, |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7220 | &fp, &reduced_clock, |
| 7221 | has_reduced_clock ? &fp2 : NULL); |
| 7222 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 7223 | intel_crtc->config.dpll_hw_state.dpll = dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7224 | intel_crtc->config.dpll_hw_state.fp0 = fp; |
| 7225 | if (has_reduced_clock) |
| 7226 | intel_crtc->config.dpll_hw_state.fp1 = fp2; |
| 7227 | else |
| 7228 | intel_crtc->config.dpll_hw_state.fp1 = fp; |
| 7229 | |
Daniel Vetter | b89a1d3 | 2013-06-05 13:34:24 +0200 | [diff] [blame] | 7230 | pll = intel_get_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 7231 | if (pll == NULL) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 7232 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 7233 | pipe_name(intel_crtc->pipe)); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 7234 | return -EINVAL; |
| 7235 | } |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 7236 | } else |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 7237 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7238 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 7239 | if (is_lvds && has_reduced_clock && i915.powersave) |
Daniel Vetter | bcd644e | 2013-06-05 13:34:22 +0200 | [diff] [blame] | 7240 | intel_crtc->lowfreq_avail = true; |
| 7241 | else |
| 7242 | intel_crtc->lowfreq_avail = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 7243 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7244 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7245 | } |
| 7246 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7247 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 7248 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7249 | { |
| 7250 | struct drm_device *dev = crtc->base.dev; |
| 7251 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7252 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7253 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7254 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 7255 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 7256 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 7257 | & ~TU_SIZE_MASK; |
| 7258 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 7259 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 7260 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7261 | } |
| 7262 | |
| 7263 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 7264 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7265 | struct intel_link_m_n *m_n, |
| 7266 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7267 | { |
| 7268 | struct drm_device *dev = crtc->base.dev; |
| 7269 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7270 | enum pipe pipe = crtc->pipe; |
| 7271 | |
| 7272 | if (INTEL_INFO(dev)->gen >= 5) { |
| 7273 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 7274 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 7275 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 7276 | & ~TU_SIZE_MASK; |
| 7277 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 7278 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 7279 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7280 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 7281 | * gen < 8) and if DRRS is supported (to make sure the |
| 7282 | * registers are not unnecessarily read). |
| 7283 | */ |
| 7284 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
| 7285 | crtc->config.has_drrs) { |
| 7286 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 7287 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 7288 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 7289 | & ~TU_SIZE_MASK; |
| 7290 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 7291 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 7292 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7293 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7294 | } else { |
| 7295 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 7296 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 7297 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 7298 | & ~TU_SIZE_MASK; |
| 7299 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 7300 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 7301 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7302 | } |
| 7303 | } |
| 7304 | |
| 7305 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
| 7306 | struct intel_crtc_config *pipe_config) |
| 7307 | { |
| 7308 | if (crtc->config.has_pch_encoder) |
| 7309 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 7310 | else |
| 7311 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7312 | &pipe_config->dp_m_n, |
| 7313 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7314 | } |
| 7315 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7316 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
| 7317 | struct intel_crtc_config *pipe_config) |
| 7318 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7319 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7320 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7321 | } |
| 7322 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7323 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
| 7324 | struct intel_crtc_config *pipe_config) |
| 7325 | { |
| 7326 | struct drm_device *dev = crtc->base.dev; |
| 7327 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7328 | uint32_t tmp; |
| 7329 | |
| 7330 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 7331 | |
| 7332 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 7333 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7334 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 7335 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 7336 | |
| 7337 | /* We currently do not free assignements of panel fitters on |
| 7338 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 7339 | * differentiates them) so just WARN about this case for now. */ |
| 7340 | if (IS_GEN7(dev)) { |
| 7341 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 7342 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 7343 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7344 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7345 | } |
| 7346 | |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7347 | static void ironlake_get_plane_config(struct intel_crtc *crtc, |
| 7348 | struct intel_plane_config *plane_config) |
| 7349 | { |
| 7350 | struct drm_device *dev = crtc->base.dev; |
| 7351 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7352 | u32 val, base, offset; |
| 7353 | int pipe = crtc->pipe, plane = crtc->plane; |
| 7354 | int fourcc, pixel_format; |
| 7355 | int aligned_height; |
| 7356 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 7357 | crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL); |
| 7358 | if (!crtc->base.primary->fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7359 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7360 | return; |
| 7361 | } |
| 7362 | |
| 7363 | val = I915_READ(DSPCNTR(plane)); |
| 7364 | |
| 7365 | if (INTEL_INFO(dev)->gen >= 4) |
| 7366 | if (val & DISPPLANE_TILED) |
| 7367 | plane_config->tiled = true; |
| 7368 | |
| 7369 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
| 7370 | fourcc = intel_format_to_fourcc(pixel_format); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 7371 | crtc->base.primary->fb->pixel_format = fourcc; |
| 7372 | crtc->base.primary->fb->bits_per_pixel = |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7373 | drm_format_plane_cpp(fourcc, 0) * 8; |
| 7374 | |
| 7375 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 7376 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
| 7377 | offset = I915_READ(DSPOFFSET(plane)); |
| 7378 | } else { |
| 7379 | if (plane_config->tiled) |
| 7380 | offset = I915_READ(DSPTILEOFF(plane)); |
| 7381 | else |
| 7382 | offset = I915_READ(DSPLINOFF(plane)); |
| 7383 | } |
| 7384 | plane_config->base = base; |
| 7385 | |
| 7386 | val = I915_READ(PIPESRC(pipe)); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 7387 | crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1; |
| 7388 | crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7389 | |
| 7390 | val = I915_READ(DSPSTRIDE(pipe)); |
Rafael Barbalho | 026b96e | 2014-07-28 19:56:27 +0100 | [diff] [blame] | 7391 | crtc->base.primary->fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7392 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 7393 | aligned_height = intel_align_height(dev, crtc->base.primary->fb->height, |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7394 | plane_config->tiled); |
| 7395 | |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 7396 | plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] * |
| 7397 | aligned_height); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7398 | |
| 7399 | DRM_DEBUG_KMS("pipe/plane %d/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 7400 | pipe, plane, crtc->base.primary->fb->width, |
| 7401 | crtc->base.primary->fb->height, |
| 7402 | crtc->base.primary->fb->bits_per_pixel, base, |
| 7403 | crtc->base.primary->fb->pitches[0], |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7404 | plane_config->size); |
| 7405 | } |
| 7406 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7407 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
| 7408 | struct intel_crtc_config *pipe_config) |
| 7409 | { |
| 7410 | struct drm_device *dev = crtc->base.dev; |
| 7411 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7412 | uint32_t tmp; |
| 7413 | |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 7414 | if (!intel_display_power_enabled(dev_priv, |
| 7415 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 7416 | return false; |
| 7417 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7418 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7419 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7420 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7421 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7422 | if (!(tmp & PIPECONF_ENABLE)) |
| 7423 | return false; |
| 7424 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7425 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7426 | case PIPECONF_6BPC: |
| 7427 | pipe_config->pipe_bpp = 18; |
| 7428 | break; |
| 7429 | case PIPECONF_8BPC: |
| 7430 | pipe_config->pipe_bpp = 24; |
| 7431 | break; |
| 7432 | case PIPECONF_10BPC: |
| 7433 | pipe_config->pipe_bpp = 30; |
| 7434 | break; |
| 7435 | case PIPECONF_12BPC: |
| 7436 | pipe_config->pipe_bpp = 36; |
| 7437 | break; |
| 7438 | default: |
| 7439 | break; |
| 7440 | } |
| 7441 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 7442 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 7443 | pipe_config->limited_color_range = true; |
| 7444 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 7445 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7446 | struct intel_shared_dpll *pll; |
| 7447 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 7448 | pipe_config->has_pch_encoder = true; |
| 7449 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 7450 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 7451 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 7452 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7453 | |
| 7454 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7455 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7456 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 7457 | pipe_config->shared_dpll = |
| 7458 | (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7459 | } else { |
| 7460 | tmp = I915_READ(PCH_DPLL_SEL); |
| 7461 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
| 7462 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; |
| 7463 | else |
| 7464 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; |
| 7465 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7466 | |
| 7467 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 7468 | |
| 7469 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 7470 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 7471 | |
| 7472 | tmp = pipe_config->dpll_hw_state.dpll; |
| 7473 | pipe_config->pixel_multiplier = |
| 7474 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 7475 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 7476 | |
| 7477 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7478 | } else { |
| 7479 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 7480 | } |
| 7481 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7482 | intel_get_pipe_timings(crtc, pipe_config); |
| 7483 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7484 | ironlake_get_pfit_config(crtc, pipe_config); |
| 7485 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7486 | return true; |
| 7487 | } |
| 7488 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7489 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 7490 | { |
| 7491 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7492 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7493 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 7494 | for_each_intel_crtc(dev, crtc) |
Paulo Zanoni | 798183c | 2013-12-06 20:29:01 -0200 | [diff] [blame] | 7495 | WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7496 | pipe_name(crtc->pipe)); |
| 7497 | |
| 7498 | WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
Daniel Vetter | 8cc3e16 | 2014-06-25 22:01:46 +0300 | [diff] [blame] | 7499 | WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
| 7500 | WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 7501 | WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7502 | WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 7503 | WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
| 7504 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 7505 | if (IS_HASWELL(dev)) |
| 7506 | WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
| 7507 | "CPU PWM2 enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7508 | WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
| 7509 | "PCH PWM1 enabled\n"); |
| 7510 | WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
| 7511 | "Utility pin enabled\n"); |
| 7512 | WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
| 7513 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 7514 | /* |
| 7515 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 7516 | * interrupts remain enabled. We used to check for that, but since it's |
| 7517 | * gen-specific and since we only disable LCPLL after we fully disable |
| 7518 | * the interrupts, the check below should be enough. |
| 7519 | */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 7520 | WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7521 | } |
| 7522 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7523 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 7524 | { |
| 7525 | struct drm_device *dev = dev_priv->dev; |
| 7526 | |
| 7527 | if (IS_HASWELL(dev)) |
| 7528 | return I915_READ(D_COMP_HSW); |
| 7529 | else |
| 7530 | return I915_READ(D_COMP_BDW); |
| 7531 | } |
| 7532 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7533 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 7534 | { |
| 7535 | struct drm_device *dev = dev_priv->dev; |
| 7536 | |
| 7537 | if (IS_HASWELL(dev)) { |
| 7538 | mutex_lock(&dev_priv->rps.hw_lock); |
| 7539 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 7540 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 7541 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7542 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 7543 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7544 | I915_WRITE(D_COMP_BDW, val); |
| 7545 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7546 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7547 | } |
| 7548 | |
| 7549 | /* |
| 7550 | * This function implements pieces of two sequences from BSpec: |
| 7551 | * - Sequence for display software to disable LCPLL |
| 7552 | * - Sequence for display software to allow package C8+ |
| 7553 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 7554 | * register. Callers should take care of disabling all the display engine |
| 7555 | * functions, doing the mode unset, fixing interrupts, etc. |
| 7556 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 7557 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 7558 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7559 | { |
| 7560 | uint32_t val; |
| 7561 | |
| 7562 | assert_can_disable_lcpll(dev_priv); |
| 7563 | |
| 7564 | val = I915_READ(LCPLL_CTL); |
| 7565 | |
| 7566 | if (switch_to_fclk) { |
| 7567 | val |= LCPLL_CD_SOURCE_FCLK; |
| 7568 | I915_WRITE(LCPLL_CTL, val); |
| 7569 | |
| 7570 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 7571 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 7572 | DRM_ERROR("Switching to FCLK failed\n"); |
| 7573 | |
| 7574 | val = I915_READ(LCPLL_CTL); |
| 7575 | } |
| 7576 | |
| 7577 | val |= LCPLL_PLL_DISABLE; |
| 7578 | I915_WRITE(LCPLL_CTL, val); |
| 7579 | POSTING_READ(LCPLL_CTL); |
| 7580 | |
| 7581 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 7582 | DRM_ERROR("LCPLL still locked\n"); |
| 7583 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7584 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7585 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7586 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7587 | ndelay(100); |
| 7588 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7589 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 7590 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7591 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 7592 | |
| 7593 | if (allow_power_down) { |
| 7594 | val = I915_READ(LCPLL_CTL); |
| 7595 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 7596 | I915_WRITE(LCPLL_CTL, val); |
| 7597 | POSTING_READ(LCPLL_CTL); |
| 7598 | } |
| 7599 | } |
| 7600 | |
| 7601 | /* |
| 7602 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 7603 | * source. |
| 7604 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 7605 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7606 | { |
| 7607 | uint32_t val; |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 7608 | unsigned long irqflags; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7609 | |
| 7610 | val = I915_READ(LCPLL_CTL); |
| 7611 | |
| 7612 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 7613 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 7614 | return; |
| 7615 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 7616 | /* |
| 7617 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 7618 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. |
| 7619 | * |
| 7620 | * The other problem is that hsw_restore_lcpll() is called as part of |
| 7621 | * the runtime PM resume sequence, so we can't just call |
| 7622 | * gen6_gt_force_wake_get() because that function calls |
| 7623 | * intel_runtime_pm_get(), and we can't change the runtime PM refcount |
| 7624 | * while we are on the resume sequence. So to solve this problem we have |
| 7625 | * to call special forcewake code that doesn't touch runtime PM and |
| 7626 | * doesn't enable the forcewake delayed work. |
| 7627 | */ |
| 7628 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 7629 | if (dev_priv->uncore.forcewake_count++ == 0) |
| 7630 | dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 7631 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 7632 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7633 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 7634 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 7635 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 7636 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7637 | } |
| 7638 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7639 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7640 | val |= D_COMP_COMP_FORCE; |
| 7641 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7642 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7643 | |
| 7644 | val = I915_READ(LCPLL_CTL); |
| 7645 | val &= ~LCPLL_PLL_DISABLE; |
| 7646 | I915_WRITE(LCPLL_CTL, val); |
| 7647 | |
| 7648 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 7649 | DRM_ERROR("LCPLL not locked yet\n"); |
| 7650 | |
| 7651 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 7652 | val = I915_READ(LCPLL_CTL); |
| 7653 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 7654 | I915_WRITE(LCPLL_CTL, val); |
| 7655 | |
| 7656 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 7657 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 7658 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 7659 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 7660 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 7661 | /* See the big comment above. */ |
| 7662 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 7663 | if (--dev_priv->uncore.forcewake_count == 0) |
| 7664 | dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 7665 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7666 | } |
| 7667 | |
Paulo Zanoni | 765dab6 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 7668 | /* |
| 7669 | * Package states C8 and deeper are really deep PC states that can only be |
| 7670 | * reached when all the devices on the system allow it, so even if the graphics |
| 7671 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 7672 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 7673 | * |
| 7674 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 7675 | * well is disabled and most interrupts are disabled, and these are also |
| 7676 | * requirements for runtime PM. When these conditions are met, we manually do |
| 7677 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 7678 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 7679 | * hang the machine. |
| 7680 | * |
| 7681 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 7682 | * the state of some registers, so when we come back from PC8+ we need to |
| 7683 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 7684 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 7685 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 7686 | * because of the runtime PM support). |
| 7687 | * |
| 7688 | * For more, read "Display Sequences for Package C8" on the hardware |
| 7689 | * documentation. |
| 7690 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 7691 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7692 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7693 | struct drm_device *dev = dev_priv->dev; |
| 7694 | uint32_t val; |
| 7695 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7696 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 7697 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7698 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 7699 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 7700 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 7701 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 7702 | } |
| 7703 | |
| 7704 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7705 | hsw_disable_lcpll(dev_priv, true, true); |
| 7706 | } |
| 7707 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 7708 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7709 | { |
| 7710 | struct drm_device *dev = dev_priv->dev; |
| 7711 | uint32_t val; |
| 7712 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7713 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 7714 | |
| 7715 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7716 | lpt_init_pch_refclk(dev); |
| 7717 | |
| 7718 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 7719 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 7720 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 7721 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 7722 | } |
| 7723 | |
| 7724 | intel_prepare_ddi(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7725 | } |
| 7726 | |
Paulo Zanoni | 9a952a0 | 2014-03-07 20:12:34 -0300 | [diff] [blame] | 7727 | static void snb_modeset_global_resources(struct drm_device *dev) |
| 7728 | { |
| 7729 | modeset_update_crtc_power_domains(dev); |
| 7730 | } |
| 7731 | |
Imre Deak | 4f07412 | 2013-10-16 17:25:51 +0300 | [diff] [blame] | 7732 | static void haswell_modeset_global_resources(struct drm_device *dev) |
| 7733 | { |
Paulo Zanoni | da72356 | 2013-12-19 11:54:51 -0200 | [diff] [blame] | 7734 | modeset_update_crtc_power_domains(dev); |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 7735 | } |
| 7736 | |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 7737 | static int haswell_crtc_mode_set(struct drm_crtc *crtc, |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 7738 | int x, int y, |
| 7739 | struct drm_framebuffer *fb) |
| 7740 | { |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 7741 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 7742 | |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 7743 | if (!intel_ddi_pll_select(intel_crtc)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 7744 | return -EINVAL; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 7745 | |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 7746 | intel_crtc->lowfreq_avail = false; |
| 7747 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7748 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7749 | } |
| 7750 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 7751 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 7752 | enum port port, |
| 7753 | struct intel_crtc_config *pipe_config) |
| 7754 | { |
| 7755 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 7756 | |
| 7757 | switch (pipe_config->ddi_pll_sel) { |
| 7758 | case PORT_CLK_SEL_WRPLL1: |
| 7759 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; |
| 7760 | break; |
| 7761 | case PORT_CLK_SEL_WRPLL2: |
| 7762 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; |
| 7763 | break; |
| 7764 | } |
| 7765 | } |
| 7766 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 7767 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
| 7768 | struct intel_crtc_config *pipe_config) |
| 7769 | { |
| 7770 | struct drm_device *dev = crtc->base.dev; |
| 7771 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 7772 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 7773 | enum port port; |
| 7774 | uint32_t tmp; |
| 7775 | |
| 7776 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 7777 | |
| 7778 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 7779 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 7780 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 7781 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 7782 | if (pipe_config->shared_dpll >= 0) { |
| 7783 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 7784 | |
| 7785 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 7786 | &pipe_config->dpll_hw_state)); |
| 7787 | } |
| 7788 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 7789 | /* |
| 7790 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 7791 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 7792 | * the PCH transcoder is on. |
| 7793 | */ |
| 7794 | if ((port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
| 7795 | pipe_config->has_pch_encoder = true; |
| 7796 | |
| 7797 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 7798 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 7799 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 7800 | |
| 7801 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 7802 | } |
| 7803 | } |
| 7804 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7805 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
| 7806 | struct intel_crtc_config *pipe_config) |
| 7807 | { |
| 7808 | struct drm_device *dev = crtc->base.dev; |
| 7809 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7810 | enum intel_display_power_domain pfit_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7811 | uint32_t tmp; |
| 7812 | |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7813 | if (!intel_display_power_enabled(dev_priv, |
| 7814 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 7815 | return false; |
| 7816 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7817 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7818 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
| 7819 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7820 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 7821 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 7822 | enum pipe trans_edp_pipe; |
| 7823 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 7824 | default: |
| 7825 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 7826 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 7827 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 7828 | trans_edp_pipe = PIPE_A; |
| 7829 | break; |
| 7830 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 7831 | trans_edp_pipe = PIPE_B; |
| 7832 | break; |
| 7833 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 7834 | trans_edp_pipe = PIPE_C; |
| 7835 | break; |
| 7836 | } |
| 7837 | |
| 7838 | if (trans_edp_pipe == crtc->pipe) |
| 7839 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 7840 | } |
| 7841 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7842 | if (!intel_display_power_enabled(dev_priv, |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7843 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
Paulo Zanoni | 2bfce95 | 2013-04-18 16:35:40 -0300 | [diff] [blame] | 7844 | return false; |
| 7845 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7846 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7847 | if (!(tmp & PIPECONF_ENABLE)) |
| 7848 | return false; |
| 7849 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 7850 | haswell_get_ddi_port_state(crtc, pipe_config); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 7851 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7852 | intel_get_pipe_timings(crtc, pipe_config); |
| 7853 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7854 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7855 | if (intel_display_power_enabled(dev_priv, pfit_domain)) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7856 | ironlake_get_pfit_config(crtc, pipe_config); |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 7857 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 7858 | if (IS_HASWELL(dev)) |
| 7859 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 7860 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 7861 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7862 | pipe_config->pixel_multiplier = 1; |
| 7863 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7864 | return true; |
| 7865 | } |
| 7866 | |
Jani Nikula | 1a91510 | 2013-10-16 12:34:48 +0300 | [diff] [blame] | 7867 | static struct { |
| 7868 | int clock; |
| 7869 | u32 config; |
| 7870 | } hdmi_audio_clock[] = { |
| 7871 | { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 }, |
| 7872 | { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */ |
| 7873 | { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 }, |
| 7874 | { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 }, |
| 7875 | { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 }, |
| 7876 | { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 }, |
| 7877 | { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 }, |
| 7878 | { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 }, |
| 7879 | { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 }, |
| 7880 | { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 }, |
| 7881 | }; |
| 7882 | |
| 7883 | /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */ |
| 7884 | static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode) |
| 7885 | { |
| 7886 | int i; |
| 7887 | |
| 7888 | for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) { |
| 7889 | if (mode->clock == hdmi_audio_clock[i].clock) |
| 7890 | break; |
| 7891 | } |
| 7892 | |
| 7893 | if (i == ARRAY_SIZE(hdmi_audio_clock)) { |
| 7894 | DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock); |
| 7895 | i = 1; |
| 7896 | } |
| 7897 | |
| 7898 | DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n", |
| 7899 | hdmi_audio_clock[i].clock, |
| 7900 | hdmi_audio_clock[i].config); |
| 7901 | |
| 7902 | return hdmi_audio_clock[i].config; |
| 7903 | } |
| 7904 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 7905 | static bool intel_eld_uptodate(struct drm_connector *connector, |
| 7906 | int reg_eldv, uint32_t bits_eldv, |
| 7907 | int reg_elda, uint32_t bits_elda, |
| 7908 | int reg_edid) |
| 7909 | { |
| 7910 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 7911 | uint8_t *eld = connector->eld; |
| 7912 | uint32_t i; |
| 7913 | |
| 7914 | i = I915_READ(reg_eldv); |
| 7915 | i &= bits_eldv; |
| 7916 | |
| 7917 | if (!eld[0]) |
| 7918 | return !i; |
| 7919 | |
| 7920 | if (!i) |
| 7921 | return false; |
| 7922 | |
| 7923 | i = I915_READ(reg_elda); |
| 7924 | i &= ~bits_elda; |
| 7925 | I915_WRITE(reg_elda, i); |
| 7926 | |
| 7927 | for (i = 0; i < eld[2]; i++) |
| 7928 | if (I915_READ(reg_edid) != *((uint32_t *)eld + i)) |
| 7929 | return false; |
| 7930 | |
| 7931 | return true; |
| 7932 | } |
| 7933 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 7934 | static void g4x_write_eld(struct drm_connector *connector, |
Jani Nikula | 3442705 | 2013-10-16 12:34:47 +0300 | [diff] [blame] | 7935 | struct drm_crtc *crtc, |
| 7936 | struct drm_display_mode *mode) |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 7937 | { |
| 7938 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 7939 | uint8_t *eld = connector->eld; |
| 7940 | uint32_t eldv; |
| 7941 | uint32_t len; |
| 7942 | uint32_t i; |
| 7943 | |
| 7944 | i = I915_READ(G4X_AUD_VID_DID); |
| 7945 | |
| 7946 | if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL) |
| 7947 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 7948 | else |
| 7949 | eldv = G4X_ELDV_DEVCTG; |
| 7950 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 7951 | if (intel_eld_uptodate(connector, |
| 7952 | G4X_AUD_CNTL_ST, eldv, |
| 7953 | G4X_AUD_CNTL_ST, G4X_ELD_ADDR, |
| 7954 | G4X_HDMIW_HDMIEDID)) |
| 7955 | return; |
| 7956 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 7957 | i = I915_READ(G4X_AUD_CNTL_ST); |
| 7958 | i &= ~(eldv | G4X_ELD_ADDR); |
| 7959 | len = (i >> 9) & 0x1f; /* ELD buffer size */ |
| 7960 | I915_WRITE(G4X_AUD_CNTL_ST, i); |
| 7961 | |
| 7962 | if (!eld[0]) |
| 7963 | return; |
| 7964 | |
| 7965 | len = min_t(uint8_t, eld[2], len); |
| 7966 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 7967 | for (i = 0; i < len; i++) |
| 7968 | I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i)); |
| 7969 | |
| 7970 | i = I915_READ(G4X_AUD_CNTL_ST); |
| 7971 | i |= eldv; |
| 7972 | I915_WRITE(G4X_AUD_CNTL_ST, i); |
| 7973 | } |
| 7974 | |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7975 | static void haswell_write_eld(struct drm_connector *connector, |
Jani Nikula | 3442705 | 2013-10-16 12:34:47 +0300 | [diff] [blame] | 7976 | struct drm_crtc *crtc, |
| 7977 | struct drm_display_mode *mode) |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7978 | { |
| 7979 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 7980 | uint8_t *eld = connector->eld; |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7981 | uint32_t eldv; |
| 7982 | uint32_t i; |
| 7983 | int len; |
| 7984 | int pipe = to_intel_crtc(crtc)->pipe; |
| 7985 | int tmp; |
| 7986 | |
| 7987 | int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe); |
| 7988 | int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe); |
| 7989 | int aud_config = HSW_AUD_CFG(pipe); |
| 7990 | int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD; |
| 7991 | |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7992 | /* Audio output enable */ |
| 7993 | DRM_DEBUG_DRIVER("HDMI audio: enable codec\n"); |
| 7994 | tmp = I915_READ(aud_cntrl_st2); |
| 7995 | tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4)); |
| 7996 | I915_WRITE(aud_cntrl_st2, tmp); |
Daniel Vetter | c790579 | 2014-04-16 16:56:09 +0200 | [diff] [blame] | 7997 | POSTING_READ(aud_cntrl_st2); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7998 | |
Daniel Vetter | c790579 | 2014-04-16 16:56:09 +0200 | [diff] [blame] | 7999 | assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 8000 | |
| 8001 | /* Set ELD valid state */ |
| 8002 | tmp = I915_READ(aud_cntrl_st2); |
Takashi Iwai | 7e7cb34 | 2013-09-10 07:30:36 +0200 | [diff] [blame] | 8003 | DRM_DEBUG_DRIVER("HDMI audio: pin eld vld status=0x%08x\n", tmp); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 8004 | tmp |= (AUDIO_ELD_VALID_A << (pipe * 4)); |
| 8005 | I915_WRITE(aud_cntrl_st2, tmp); |
| 8006 | tmp = I915_READ(aud_cntrl_st2); |
Takashi Iwai | 7e7cb34 | 2013-09-10 07:30:36 +0200 | [diff] [blame] | 8007 | DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 8008 | |
| 8009 | /* Enable HDMI mode */ |
| 8010 | tmp = I915_READ(aud_config); |
Takashi Iwai | 7e7cb34 | 2013-09-10 07:30:36 +0200 | [diff] [blame] | 8011 | DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 8012 | /* clear N_programing_enable and N_value_index */ |
| 8013 | tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE); |
| 8014 | I915_WRITE(aud_config, tmp); |
| 8015 | |
| 8016 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
| 8017 | |
| 8018 | eldv = AUDIO_ELD_VALID_A << (pipe * 4); |
| 8019 | |
| 8020 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
| 8021 | DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n"); |
| 8022 | eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */ |
| 8023 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
Jani Nikula | 1a91510 | 2013-10-16 12:34:48 +0300 | [diff] [blame] | 8024 | } else { |
| 8025 | I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode)); |
| 8026 | } |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 8027 | |
| 8028 | if (intel_eld_uptodate(connector, |
| 8029 | aud_cntrl_st2, eldv, |
| 8030 | aud_cntl_st, IBX_ELD_ADDRESS, |
| 8031 | hdmiw_hdmiedid)) |
| 8032 | return; |
| 8033 | |
| 8034 | i = I915_READ(aud_cntrl_st2); |
| 8035 | i &= ~eldv; |
| 8036 | I915_WRITE(aud_cntrl_st2, i); |
| 8037 | |
| 8038 | if (!eld[0]) |
| 8039 | return; |
| 8040 | |
| 8041 | i = I915_READ(aud_cntl_st); |
| 8042 | i &= ~IBX_ELD_ADDRESS; |
| 8043 | I915_WRITE(aud_cntl_st, i); |
| 8044 | i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */ |
| 8045 | DRM_DEBUG_DRIVER("port num:%d\n", i); |
| 8046 | |
| 8047 | len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
| 8048 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 8049 | for (i = 0; i < len; i++) |
| 8050 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 8051 | |
| 8052 | i = I915_READ(aud_cntrl_st2); |
| 8053 | i |= eldv; |
| 8054 | I915_WRITE(aud_cntrl_st2, i); |
| 8055 | |
| 8056 | } |
| 8057 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8058 | static void ironlake_write_eld(struct drm_connector *connector, |
Jani Nikula | 3442705 | 2013-10-16 12:34:47 +0300 | [diff] [blame] | 8059 | struct drm_crtc *crtc, |
| 8060 | struct drm_display_mode *mode) |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8061 | { |
| 8062 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 8063 | uint8_t *eld = connector->eld; |
| 8064 | uint32_t eldv; |
| 8065 | uint32_t i; |
| 8066 | int len; |
| 8067 | int hdmiw_hdmiedid; |
Wu Fengguang | b6daa02 | 2012-01-06 14:41:31 -0600 | [diff] [blame] | 8068 | int aud_config; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8069 | int aud_cntl_st; |
| 8070 | int aud_cntrl_st2; |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 8071 | int pipe = to_intel_crtc(crtc)->pipe; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8072 | |
Wu Fengguang | b3f33cb | 2011-12-09 20:42:17 +0800 | [diff] [blame] | 8073 | if (HAS_PCH_IBX(connector->dev)) { |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 8074 | hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe); |
| 8075 | aud_config = IBX_AUD_CFG(pipe); |
| 8076 | aud_cntl_st = IBX_AUD_CNTL_ST(pipe); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8077 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
Mengdong Lin | 9ca2fe7 | 2013-11-01 00:17:03 -0400 | [diff] [blame] | 8078 | } else if (IS_VALLEYVIEW(connector->dev)) { |
| 8079 | hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe); |
| 8080 | aud_config = VLV_AUD_CFG(pipe); |
| 8081 | aud_cntl_st = VLV_AUD_CNTL_ST(pipe); |
| 8082 | aud_cntrl_st2 = VLV_AUD_CNTL_ST2; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8083 | } else { |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 8084 | hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe); |
| 8085 | aud_config = CPT_AUD_CFG(pipe); |
| 8086 | aud_cntl_st = CPT_AUD_CNTL_ST(pipe); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8087 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8088 | } |
| 8089 | |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 8090 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8091 | |
Mengdong Lin | 9ca2fe7 | 2013-11-01 00:17:03 -0400 | [diff] [blame] | 8092 | if (IS_VALLEYVIEW(connector->dev)) { |
| 8093 | struct intel_encoder *intel_encoder; |
| 8094 | struct intel_digital_port *intel_dig_port; |
| 8095 | |
| 8096 | intel_encoder = intel_attached_encoder(connector); |
| 8097 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
| 8098 | i = intel_dig_port->port; |
| 8099 | } else { |
| 8100 | i = I915_READ(aud_cntl_st); |
| 8101 | i = (i >> 29) & DIP_PORT_SEL_MASK; |
| 8102 | /* DIP_Port_Select, 0x1 = PortB */ |
| 8103 | } |
| 8104 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8105 | if (!i) { |
| 8106 | DRM_DEBUG_DRIVER("Audio directed to unknown port\n"); |
| 8107 | /* operate blindly on all ports */ |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8108 | eldv = IBX_ELD_VALIDB; |
| 8109 | eldv |= IBX_ELD_VALIDB << 4; |
| 8110 | eldv |= IBX_ELD_VALIDB << 8; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8111 | } else { |
Ville Syrjälä | 2582a85 | 2013-04-17 17:48:47 +0300 | [diff] [blame] | 8112 | DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i)); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8113 | eldv = IBX_ELD_VALIDB << ((i - 1) * 4); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8114 | } |
| 8115 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 8116 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
| 8117 | DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n"); |
| 8118 | eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */ |
Wu Fengguang | b6daa02 | 2012-01-06 14:41:31 -0600 | [diff] [blame] | 8119 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
Jani Nikula | 1a91510 | 2013-10-16 12:34:48 +0300 | [diff] [blame] | 8120 | } else { |
| 8121 | I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode)); |
| 8122 | } |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 8123 | |
| 8124 | if (intel_eld_uptodate(connector, |
| 8125 | aud_cntrl_st2, eldv, |
| 8126 | aud_cntl_st, IBX_ELD_ADDRESS, |
| 8127 | hdmiw_hdmiedid)) |
| 8128 | return; |
| 8129 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8130 | i = I915_READ(aud_cntrl_st2); |
| 8131 | i &= ~eldv; |
| 8132 | I915_WRITE(aud_cntrl_st2, i); |
| 8133 | |
| 8134 | if (!eld[0]) |
| 8135 | return; |
| 8136 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8137 | i = I915_READ(aud_cntl_st); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8138 | i &= ~IBX_ELD_ADDRESS; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8139 | I915_WRITE(aud_cntl_st, i); |
| 8140 | |
| 8141 | len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
| 8142 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 8143 | for (i = 0; i < len; i++) |
| 8144 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 8145 | |
| 8146 | i = I915_READ(aud_cntrl_st2); |
| 8147 | i |= eldv; |
| 8148 | I915_WRITE(aud_cntrl_st2, i); |
| 8149 | } |
| 8150 | |
| 8151 | void intel_write_eld(struct drm_encoder *encoder, |
| 8152 | struct drm_display_mode *mode) |
| 8153 | { |
| 8154 | struct drm_crtc *crtc = encoder->crtc; |
| 8155 | struct drm_connector *connector; |
| 8156 | struct drm_device *dev = encoder->dev; |
| 8157 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8158 | |
| 8159 | connector = drm_select_eld(encoder, mode); |
| 8160 | if (!connector) |
| 8161 | return; |
| 8162 | |
| 8163 | DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 8164 | connector->base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 8165 | connector->name, |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8166 | connector->encoder->base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 8167 | connector->encoder->name); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8168 | |
| 8169 | connector->eld[6] = drm_av_sync_delay(connector, mode) / 2; |
| 8170 | |
| 8171 | if (dev_priv->display.write_eld) |
Jani Nikula | 3442705 | 2013-10-16 12:34:47 +0300 | [diff] [blame] | 8172 | dev_priv->display.write_eld(connector, crtc, mode); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8173 | } |
| 8174 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8175 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8176 | { |
| 8177 | struct drm_device *dev = crtc->dev; |
| 8178 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8179 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8180 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8181 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8182 | if (base) { |
| 8183 | unsigned int width = intel_crtc->cursor_width; |
| 8184 | unsigned int height = intel_crtc->cursor_height; |
| 8185 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 8186 | |
| 8187 | switch (stride) { |
| 8188 | default: |
| 8189 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 8190 | width, stride); |
| 8191 | stride = 256; |
| 8192 | /* fallthrough */ |
| 8193 | case 256: |
| 8194 | case 512: |
| 8195 | case 1024: |
| 8196 | case 2048: |
| 8197 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8198 | } |
| 8199 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8200 | cntl |= CURSOR_ENABLE | |
| 8201 | CURSOR_GAMMA_ENABLE | |
| 8202 | CURSOR_FORMAT_ARGB | |
| 8203 | CURSOR_STRIDE(stride); |
| 8204 | |
| 8205 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8206 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8207 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8208 | if (intel_crtc->cursor_cntl != 0 && |
| 8209 | (intel_crtc->cursor_base != base || |
| 8210 | intel_crtc->cursor_size != size || |
| 8211 | intel_crtc->cursor_cntl != cntl)) { |
| 8212 | /* On these chipsets we can only modify the base/size/stride |
| 8213 | * whilst the cursor is disabled. |
| 8214 | */ |
| 8215 | I915_WRITE(_CURACNTR, 0); |
| 8216 | POSTING_READ(_CURACNTR); |
| 8217 | intel_crtc->cursor_cntl = 0; |
| 8218 | } |
| 8219 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8220 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8221 | I915_WRITE(_CURABASE, base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8222 | intel_crtc->cursor_base = base; |
| 8223 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8224 | |
| 8225 | if (intel_crtc->cursor_size != size) { |
| 8226 | I915_WRITE(CURSIZE, size); |
| 8227 | intel_crtc->cursor_size = size; |
| 8228 | } |
| 8229 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8230 | if (intel_crtc->cursor_cntl != cntl) { |
| 8231 | I915_WRITE(_CURACNTR, cntl); |
| 8232 | POSTING_READ(_CURACNTR); |
| 8233 | intel_crtc->cursor_cntl = cntl; |
| 8234 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8235 | } |
| 8236 | |
| 8237 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8238 | { |
| 8239 | struct drm_device *dev = crtc->dev; |
| 8240 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8241 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8242 | int pipe = intel_crtc->pipe; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8243 | uint32_t cntl; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8244 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8245 | cntl = 0; |
| 8246 | if (base) { |
| 8247 | cntl = MCURSOR_GAMMA_ENABLE; |
| 8248 | switch (intel_crtc->cursor_width) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8249 | case 64: |
| 8250 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 8251 | break; |
| 8252 | case 128: |
| 8253 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 8254 | break; |
| 8255 | case 256: |
| 8256 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 8257 | break; |
| 8258 | default: |
| 8259 | WARN_ON(1); |
| 8260 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8261 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8262 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 8263 | |
| 8264 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 8265 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8266 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8267 | |
| 8268 | if (intel_crtc->cursor_cntl != cntl) { |
| 8269 | I915_WRITE(CURCNTR(pipe), cntl); |
| 8270 | POSTING_READ(CURCNTR(pipe)); |
| 8271 | intel_crtc->cursor_cntl = cntl; |
| 8272 | } |
| 8273 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8274 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8275 | I915_WRITE(CURBASE(pipe), base); |
| 8276 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8277 | |
| 8278 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8279 | } |
| 8280 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8281 | /* 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] | 8282 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 8283 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8284 | { |
| 8285 | struct drm_device *dev = crtc->dev; |
| 8286 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8287 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8288 | int pipe = intel_crtc->pipe; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 8289 | int x = crtc->cursor_x; |
| 8290 | int y = crtc->cursor_y; |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8291 | u32 base = 0, pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8292 | |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8293 | if (on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8294 | base = intel_crtc->cursor_addr; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8295 | |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8296 | if (x >= intel_crtc->config.pipe_src_w) |
| 8297 | base = 0; |
| 8298 | |
| 8299 | if (y >= intel_crtc->config.pipe_src_h) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8300 | base = 0; |
| 8301 | |
| 8302 | if (x < 0) { |
Ville Syrjälä | efc9064 | 2013-09-04 18:25:30 +0300 | [diff] [blame] | 8303 | if (x + intel_crtc->cursor_width <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8304 | base = 0; |
| 8305 | |
| 8306 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 8307 | x = -x; |
| 8308 | } |
| 8309 | pos |= x << CURSOR_X_SHIFT; |
| 8310 | |
| 8311 | if (y < 0) { |
Ville Syrjälä | efc9064 | 2013-09-04 18:25:30 +0300 | [diff] [blame] | 8312 | if (y + intel_crtc->cursor_height <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8313 | base = 0; |
| 8314 | |
| 8315 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 8316 | y = -y; |
| 8317 | } |
| 8318 | pos |= y << CURSOR_Y_SHIFT; |
| 8319 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8320 | if (base == 0 && intel_crtc->cursor_base == 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8321 | return; |
| 8322 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8323 | I915_WRITE(CURPOS(pipe), pos); |
| 8324 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 8325 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8326 | i845_update_cursor(crtc, base); |
| 8327 | else |
| 8328 | i9xx_update_cursor(crtc, base); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8329 | } |
| 8330 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8331 | static bool cursor_size_ok(struct drm_device *dev, |
| 8332 | uint32_t width, uint32_t height) |
| 8333 | { |
| 8334 | if (width == 0 || height == 0) |
| 8335 | return false; |
| 8336 | |
| 8337 | /* |
| 8338 | * 845g/865g are special in that they are only limited by |
| 8339 | * the width of their cursors, the height is arbitrary up to |
| 8340 | * the precision of the register. Everything else requires |
| 8341 | * square cursors, limited to a few power-of-two sizes. |
| 8342 | */ |
| 8343 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 8344 | if ((width & 63) != 0) |
| 8345 | return false; |
| 8346 | |
| 8347 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 8348 | return false; |
| 8349 | |
| 8350 | if (height > 1023) |
| 8351 | return false; |
| 8352 | } else { |
| 8353 | switch (width | height) { |
| 8354 | case 256: |
| 8355 | case 128: |
| 8356 | if (IS_GEN2(dev)) |
| 8357 | return false; |
| 8358 | case 64: |
| 8359 | break; |
| 8360 | default: |
| 8361 | return false; |
| 8362 | } |
| 8363 | } |
| 8364 | |
| 8365 | return true; |
| 8366 | } |
| 8367 | |
Matt Roper | e328795 | 2014-06-10 08:28:12 -0700 | [diff] [blame] | 8368 | /* |
| 8369 | * intel_crtc_cursor_set_obj - Set cursor to specified GEM object |
| 8370 | * |
| 8371 | * Note that the object's reference will be consumed if the update fails. If |
| 8372 | * the update succeeds, the reference of the old object (if any) will be |
| 8373 | * consumed. |
| 8374 | */ |
| 8375 | static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc, |
| 8376 | struct drm_i915_gem_object *obj, |
| 8377 | uint32_t width, uint32_t height) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8378 | { |
| 8379 | struct drm_device *dev = crtc->dev; |
| 8380 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8381 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 8382 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8383 | unsigned old_width, stride; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8384 | uint32_t addr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8385 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8386 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8387 | /* if we want to turn off the cursor ignore width and height */ |
Matt Roper | e328795 | 2014-06-10 08:28:12 -0700 | [diff] [blame] | 8388 | if (!obj) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 8389 | DRM_DEBUG_KMS("cursor off\n"); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8390 | addr = 0; |
Pierre Willenbrock | 5004417 | 2009-02-23 10:12:15 +1000 | [diff] [blame] | 8391 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8392 | goto finish; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8393 | } |
| 8394 | |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8395 | /* Check for which cursor types we support */ |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8396 | if (!cursor_size_ok(dev, width, height)) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8397 | DRM_DEBUG("Cursor dimension not supported\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8398 | return -EINVAL; |
| 8399 | } |
| 8400 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8401 | stride = roundup_pow_of_two(width) * 4; |
| 8402 | if (obj->base.size < stride * height) { |
Matt Roper | e328795 | 2014-06-10 08:28:12 -0700 | [diff] [blame] | 8403 | DRM_DEBUG_KMS("buffer is too small\n"); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 8404 | ret = -ENOMEM; |
| 8405 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8406 | } |
| 8407 | |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 8408 | /* 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] | 8409 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 8410 | if (!INTEL_INFO(dev)->cursor_needs_physical) { |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 8411 | unsigned alignment; |
| 8412 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 8413 | if (obj->tiling_mode) { |
Daniel Vetter | 3b25b31 | 2014-02-14 14:06:06 +0100 | [diff] [blame] | 8414 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 8415 | ret = -EINVAL; |
| 8416 | goto fail_locked; |
| 8417 | } |
| 8418 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 8419 | /* |
| 8420 | * Global gtt pte registers are special registers which actually |
| 8421 | * forward writes to a chunk of system memory. Which means that |
| 8422 | * there is no risk that the register values disappear as soon |
| 8423 | * as we call intel_runtime_pm_put(), so it is correct to wrap |
| 8424 | * only the pin/unpin/fence and not more. |
| 8425 | */ |
| 8426 | intel_runtime_pm_get(dev_priv); |
| 8427 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 8428 | /* Note that the w/a also requires 2 PTE of padding following |
| 8429 | * the bo. We currently fill all unused PTE with the shadow |
| 8430 | * page and so we should always have valid PTE following the |
| 8431 | * cursor preventing the VT-d warning. |
| 8432 | */ |
| 8433 | alignment = 0; |
| 8434 | if (need_vtd_wa(dev)) |
| 8435 | alignment = 64*1024; |
| 8436 | |
| 8437 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL); |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 8438 | if (ret) { |
Daniel Vetter | 3b25b31 | 2014-02-14 14:06:06 +0100 | [diff] [blame] | 8439 | DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n"); |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 8440 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 8441 | goto fail_locked; |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 8442 | } |
| 8443 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 8444 | ret = i915_gem_object_put_fence(obj); |
| 8445 | if (ret) { |
Daniel Vetter | 3b25b31 | 2014-02-14 14:06:06 +0100 | [diff] [blame] | 8446 | DRM_DEBUG_KMS("failed to release fence for cursor"); |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 8447 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 8448 | goto fail_unpin; |
| 8449 | } |
| 8450 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 8451 | addr = i915_gem_obj_ggtt_offset(obj); |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 8452 | |
| 8453 | intel_runtime_pm_put(dev_priv); |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 8454 | } else { |
Chris Wilson | 6eeefaf | 2010-08-07 11:01:39 +0100 | [diff] [blame] | 8455 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
Chris Wilson | 0073115 | 2014-05-21 12:42:56 +0100 | [diff] [blame] | 8456 | ret = i915_gem_object_attach_phys(obj, align); |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 8457 | if (ret) { |
Daniel Vetter | 3b25b31 | 2014-02-14 14:06:06 +0100 | [diff] [blame] | 8458 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 8459 | goto fail_locked; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 8460 | } |
Chris Wilson | 0073115 | 2014-05-21 12:42:56 +0100 | [diff] [blame] | 8461 | addr = obj->phys_handle->busaddr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8462 | } |
| 8463 | |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8464 | finish: |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8465 | if (intel_crtc->cursor_bo) { |
Chris Wilson | 0073115 | 2014-05-21 12:42:56 +0100 | [diff] [blame] | 8466 | if (!INTEL_INFO(dev)->cursor_needs_physical) |
Chris Wilson | cc98b41 | 2013-08-09 12:25:09 +0100 | [diff] [blame] | 8467 | i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8468 | } |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 8469 | |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 8470 | i915_gem_track_fb(intel_crtc->cursor_bo, obj, |
| 8471 | INTEL_FRONTBUFFER_CURSOR(pipe)); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 8472 | mutex_unlock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8473 | |
Chris Wilson | 64f962e | 2014-03-26 12:38:15 +0000 | [diff] [blame] | 8474 | old_width = intel_crtc->cursor_width; |
| 8475 | |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8476 | intel_crtc->cursor_addr = addr; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8477 | intel_crtc->cursor_bo = obj; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8478 | intel_crtc->cursor_width = width; |
| 8479 | intel_crtc->cursor_height = height; |
| 8480 | |
Chris Wilson | 64f962e | 2014-03-26 12:38:15 +0000 | [diff] [blame] | 8481 | if (intel_crtc->active) { |
| 8482 | if (old_width != width) |
| 8483 | intel_update_watermarks(crtc); |
Ville Syrjälä | f2f5f77 | 2013-09-17 18:33:44 +0300 | [diff] [blame] | 8484 | intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL); |
Chris Wilson | 64f962e | 2014-03-26 12:38:15 +0000 | [diff] [blame] | 8485 | } |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8486 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 8487 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe)); |
| 8488 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8489 | return 0; |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 8490 | fail_unpin: |
Chris Wilson | cc98b41 | 2013-08-09 12:25:09 +0100 | [diff] [blame] | 8491 | i915_gem_object_unpin_from_display_plane(obj); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 8492 | fail_locked: |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 8493 | mutex_unlock(&dev->struct_mutex); |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 8494 | fail: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8495 | drm_gem_object_unreference_unlocked(&obj->base); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 8496 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8497 | } |
| 8498 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8499 | 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] | 8500 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8501 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 8502 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8503 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8504 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 8505 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8506 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 8507 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 8508 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 8509 | } |
| 8510 | |
| 8511 | intel_crtc_load_lut(crtc); |
| 8512 | } |
| 8513 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8514 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 8515 | static struct drm_display_mode load_detect_mode = { |
| 8516 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 8517 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 8518 | }; |
| 8519 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 8520 | struct drm_framebuffer * |
| 8521 | __intel_framebuffer_create(struct drm_device *dev, |
| 8522 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 8523 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8524 | { |
| 8525 | struct intel_framebuffer *intel_fb; |
| 8526 | int ret; |
| 8527 | |
| 8528 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 8529 | if (!intel_fb) { |
| 8530 | drm_gem_object_unreference_unlocked(&obj->base); |
| 8531 | return ERR_PTR(-ENOMEM); |
| 8532 | } |
| 8533 | |
| 8534 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8535 | if (ret) |
| 8536 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8537 | |
| 8538 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8539 | err: |
| 8540 | drm_gem_object_unreference_unlocked(&obj->base); |
| 8541 | kfree(intel_fb); |
| 8542 | |
| 8543 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8544 | } |
| 8545 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 8546 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 8547 | intel_framebuffer_create(struct drm_device *dev, |
| 8548 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 8549 | struct drm_i915_gem_object *obj) |
| 8550 | { |
| 8551 | struct drm_framebuffer *fb; |
| 8552 | int ret; |
| 8553 | |
| 8554 | ret = i915_mutex_lock_interruptible(dev); |
| 8555 | if (ret) |
| 8556 | return ERR_PTR(ret); |
| 8557 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 8558 | mutex_unlock(&dev->struct_mutex); |
| 8559 | |
| 8560 | return fb; |
| 8561 | } |
| 8562 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8563 | static u32 |
| 8564 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 8565 | { |
| 8566 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 8567 | return ALIGN(pitch, 64); |
| 8568 | } |
| 8569 | |
| 8570 | static u32 |
| 8571 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 8572 | { |
| 8573 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 8574 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8575 | } |
| 8576 | |
| 8577 | static struct drm_framebuffer * |
| 8578 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 8579 | struct drm_display_mode *mode, |
| 8580 | int depth, int bpp) |
| 8581 | { |
| 8582 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 8583 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8584 | |
| 8585 | obj = i915_gem_alloc_object(dev, |
| 8586 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 8587 | if (obj == NULL) |
| 8588 | return ERR_PTR(-ENOMEM); |
| 8589 | |
| 8590 | mode_cmd.width = mode->hdisplay; |
| 8591 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 8592 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 8593 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 8594 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8595 | |
| 8596 | return intel_framebuffer_create(dev, &mode_cmd, obj); |
| 8597 | } |
| 8598 | |
| 8599 | static struct drm_framebuffer * |
| 8600 | mode_fits_in_fbdev(struct drm_device *dev, |
| 8601 | struct drm_display_mode *mode) |
| 8602 | { |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 8603 | #ifdef CONFIG_DRM_I915_FBDEV |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8604 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8605 | struct drm_i915_gem_object *obj; |
| 8606 | struct drm_framebuffer *fb; |
| 8607 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 8608 | if (!dev_priv->fbdev) |
| 8609 | return NULL; |
| 8610 | |
| 8611 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8612 | return NULL; |
| 8613 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 8614 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 8615 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8616 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 8617 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 8618 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 8619 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8620 | return NULL; |
| 8621 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 8622 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8623 | return NULL; |
| 8624 | |
| 8625 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 8626 | #else |
| 8627 | return NULL; |
| 8628 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8629 | } |
| 8630 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8631 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8632 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8633 | struct intel_load_detect_pipe *old, |
| 8634 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8635 | { |
| 8636 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8637 | struct intel_encoder *intel_encoder = |
| 8638 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8639 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 8640 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8641 | struct drm_crtc *crtc = NULL; |
| 8642 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8643 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8644 | struct drm_mode_config *config = &dev->mode_config; |
| 8645 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8646 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8647 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 8648 | connector->base.id, connector->name, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 8649 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8650 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8651 | retry: |
| 8652 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 8653 | if (ret) |
| 8654 | goto fail_unlock; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 8655 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8656 | /* |
| 8657 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 8658 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8659 | * - if the connector already has an assigned crtc, use it (but make |
| 8660 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 8661 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8662 | * - try to find the first unused crtc that can drive this connector, |
| 8663 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8664 | */ |
| 8665 | |
| 8666 | /* See if we already have a CRTC for this connector */ |
| 8667 | if (encoder->crtc) { |
| 8668 | crtc = encoder->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8669 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8670 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 8671 | if (ret) |
| 8672 | goto fail_unlock; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 8673 | |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8674 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8675 | old->load_detect_temp = false; |
| 8676 | |
| 8677 | /* Make sure the crtc and connector are running */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8678 | if (connector->dpms != DRM_MODE_DPMS_ON) |
| 8679 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8680 | |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8681 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8682 | } |
| 8683 | |
| 8684 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 8685 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8686 | i++; |
| 8687 | if (!(encoder->possible_crtcs & (1 << i))) |
| 8688 | continue; |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 8689 | if (possible_crtc->enabled) |
| 8690 | continue; |
| 8691 | /* This can occur when applying the pipe A quirk on resume. */ |
| 8692 | if (to_intel_crtc(possible_crtc)->new_enabled) |
| 8693 | continue; |
| 8694 | |
| 8695 | crtc = possible_crtc; |
| 8696 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8697 | } |
| 8698 | |
| 8699 | /* |
| 8700 | * If we didn't find an unused CRTC, don't use any. |
| 8701 | */ |
| 8702 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8703 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8704 | goto fail_unlock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8705 | } |
| 8706 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8707 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 8708 | if (ret) |
| 8709 | goto fail_unlock; |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 8710 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
| 8711 | to_intel_connector(connector)->new_encoder = intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8712 | |
| 8713 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8714 | intel_crtc->new_enabled = true; |
| 8715 | intel_crtc->new_config = &intel_crtc->config; |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8716 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8717 | old->load_detect_temp = true; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8718 | old->release_fb = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8719 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 8720 | if (!mode) |
| 8721 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8722 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8723 | /* We need a framebuffer large enough to accommodate all accesses |
| 8724 | * that the plane may generate whilst we perform load detection. |
| 8725 | * We can not rely on the fbcon either being present (we get called |
| 8726 | * during its initialisation to detect all boot displays, or it may |
| 8727 | * not even exist) or that it is large enough to satisfy the |
| 8728 | * requested mode. |
| 8729 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8730 | fb = mode_fits_in_fbdev(dev, mode); |
| 8731 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8732 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8733 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
| 8734 | old->release_fb = fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8735 | } else |
| 8736 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8737 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8738 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8739 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8740 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8741 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8742 | if (intel_set_mode(crtc, mode, 0, 0, fb)) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 8743 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8744 | if (old->release_fb) |
| 8745 | old->release_fb->funcs->destroy(old->release_fb); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8746 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8747 | } |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8748 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8749 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 8750 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8751 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8752 | |
| 8753 | fail: |
| 8754 | intel_crtc->new_enabled = crtc->enabled; |
| 8755 | if (intel_crtc->new_enabled) |
| 8756 | intel_crtc->new_config = &intel_crtc->config; |
| 8757 | else |
| 8758 | intel_crtc->new_config = NULL; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8759 | fail_unlock: |
| 8760 | if (ret == -EDEADLK) { |
| 8761 | drm_modeset_backoff(ctx); |
| 8762 | goto retry; |
| 8763 | } |
| 8764 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8765 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8766 | } |
| 8767 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8768 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 8769 | struct intel_load_detect_pipe *old) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8770 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8771 | struct intel_encoder *intel_encoder = |
| 8772 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 8773 | struct drm_encoder *encoder = &intel_encoder->base; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 8774 | struct drm_crtc *crtc = encoder->crtc; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8775 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8776 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8777 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 8778 | connector->base.id, connector->name, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 8779 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8780 | |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8781 | if (old->load_detect_temp) { |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 8782 | to_intel_connector(connector)->new_encoder = NULL; |
| 8783 | intel_encoder->new_crtc = NULL; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8784 | intel_crtc->new_enabled = false; |
| 8785 | intel_crtc->new_config = NULL; |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 8786 | intel_set_mode(crtc, NULL, 0, 0, NULL); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8787 | |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 8788 | if (old->release_fb) { |
| 8789 | drm_framebuffer_unregister_private(old->release_fb); |
| 8790 | drm_framebuffer_unreference(old->release_fb); |
| 8791 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8792 | |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 8793 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8794 | } |
| 8795 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 8796 | /* Switch crtc and encoder back off if necessary */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8797 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
| 8798 | connector->funcs->dpms(connector, old->dpms_mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8799 | } |
| 8800 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8801 | static int i9xx_pll_refclk(struct drm_device *dev, |
| 8802 | const struct intel_crtc_config *pipe_config) |
| 8803 | { |
| 8804 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8805 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 8806 | |
| 8807 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8808 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8809 | else if (HAS_PCH_SPLIT(dev)) |
| 8810 | return 120000; |
| 8811 | else if (!IS_GEN2(dev)) |
| 8812 | return 96000; |
| 8813 | else |
| 8814 | return 48000; |
| 8815 | } |
| 8816 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8817 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8818 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
| 8819 | struct intel_crtc_config *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8820 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8821 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8822 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8823 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8824 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8825 | u32 fp; |
| 8826 | intel_clock_t clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8827 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8828 | |
| 8829 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8830 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8831 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8832 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8833 | |
| 8834 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 8835 | if (IS_PINEVIEW(dev)) { |
| 8836 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 8837 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 8838 | } else { |
| 8839 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 8840 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 8841 | } |
| 8842 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 8843 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 8844 | if (IS_PINEVIEW(dev)) |
| 8845 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 8846 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 8847 | else |
| 8848 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8849 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 8850 | |
| 8851 | switch (dpll & DPLL_MODE_MASK) { |
| 8852 | case DPLLB_MODE_DAC_SERIAL: |
| 8853 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 8854 | 5 : 10; |
| 8855 | break; |
| 8856 | case DPLLB_MODE_LVDS: |
| 8857 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 8858 | 7 : 14; |
| 8859 | break; |
| 8860 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 8861 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8862 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8863 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8864 | } |
| 8865 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 8866 | if (IS_PINEVIEW(dev)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8867 | pineview_clock(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 8868 | else |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8869 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8870 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 8871 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 8872 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8873 | |
| 8874 | if (is_lvds) { |
| 8875 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 8876 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 8877 | |
| 8878 | if (lvds & LVDS_CLKB_POWER_UP) |
| 8879 | clock.p2 = 7; |
| 8880 | else |
| 8881 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8882 | } else { |
| 8883 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 8884 | clock.p1 = 2; |
| 8885 | else { |
| 8886 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 8887 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 8888 | } |
| 8889 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 8890 | clock.p2 = 4; |
| 8891 | else |
| 8892 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8893 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8894 | |
| 8895 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8896 | } |
| 8897 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8898 | /* |
| 8899 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 8900 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8901 | * encoder's get_config() function. |
| 8902 | */ |
| 8903 | pipe_config->port_clock = clock.dot; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8904 | } |
| 8905 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 8906 | int intel_dotclock_calculate(int link_freq, |
| 8907 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8908 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8909 | /* |
| 8910 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 8911 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8912 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 8913 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8914 | * |
| 8915 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 8916 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8917 | */ |
| 8918 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 8919 | if (!m_n->link_n) |
| 8920 | return 0; |
| 8921 | |
| 8922 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 8923 | } |
| 8924 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8925 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
| 8926 | struct intel_crtc_config *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 8927 | { |
| 8928 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8929 | |
| 8930 | /* read out port_clock from the DPLL */ |
| 8931 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 8932 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8933 | /* |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8934 | * This value does not include pixel_multiplier. |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 8935 | * We will check that port_clock and adjusted_mode.crtc_clock |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8936 | * agree once we know their relationship in the encoder's |
| 8937 | * get_config() function. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8938 | */ |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 8939 | pipe_config->adjusted_mode.crtc_clock = |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8940 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
| 8941 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8942 | } |
| 8943 | |
| 8944 | /** Returns the currently programmed mode of the given pipe. */ |
| 8945 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 8946 | struct drm_crtc *crtc) |
| 8947 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 8948 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8949 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 8950 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8951 | struct drm_display_mode *mode; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8952 | struct intel_crtc_config pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8953 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 8954 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 8955 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 8956 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8957 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8958 | |
| 8959 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 8960 | if (!mode) |
| 8961 | return NULL; |
| 8962 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8963 | /* |
| 8964 | * Construct a pipe_config sufficient for getting the clock info |
| 8965 | * back out of crtc_clock_get. |
| 8966 | * |
| 8967 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 8968 | * to use a real value here instead. |
| 8969 | */ |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8970 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8971 | pipe_config.pixel_multiplier = 1; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8972 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 8973 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 8974 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8975 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
| 8976 | |
Ville Syrjälä | 773ae03 | 2013-09-23 17:48:20 +0300 | [diff] [blame] | 8977 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8978 | mode->hdisplay = (htot & 0xffff) + 1; |
| 8979 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 8980 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 8981 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 8982 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 8983 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 8984 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 8985 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 8986 | |
| 8987 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8988 | |
| 8989 | return mode; |
| 8990 | } |
| 8991 | |
Daniel Vetter | cc36513 | 2014-06-18 13:59:13 +0200 | [diff] [blame] | 8992 | static void intel_increase_pllclock(struct drm_device *dev, |
| 8993 | enum pipe pipe) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8994 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 8995 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 8996 | int dpll_reg = DPLL(pipe); |
| 8997 | int dpll; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8998 | |
Sonika Jindal | baff296 | 2014-07-22 11:16:35 +0530 | [diff] [blame] | 8999 | if (!HAS_GMCH_DISPLAY(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9000 | return; |
| 9001 | |
| 9002 | if (!dev_priv->lvds_downclock_avail) |
| 9003 | return; |
| 9004 | |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 9005 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9006 | if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9007 | DRM_DEBUG_DRIVER("upclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9008 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 9009 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9010 | |
| 9011 | dpll &= ~DISPLAY_RATE_SELECT_FPA1; |
| 9012 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 9013 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 9014 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9015 | dpll = I915_READ(dpll_reg); |
| 9016 | if (dpll & DISPLAY_RATE_SELECT_FPA1) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9017 | DRM_DEBUG_DRIVER("failed to upclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9018 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9019 | } |
| 9020 | |
| 9021 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 9022 | { |
| 9023 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9024 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9025 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9026 | |
Sonika Jindal | baff296 | 2014-07-22 11:16:35 +0530 | [diff] [blame] | 9027 | if (!HAS_GMCH_DISPLAY(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9028 | return; |
| 9029 | |
| 9030 | if (!dev_priv->lvds_downclock_avail) |
| 9031 | return; |
| 9032 | |
| 9033 | /* |
| 9034 | * Since this is called by a timer, we should never get here in |
| 9035 | * the manual case. |
| 9036 | */ |
| 9037 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9038 | int pipe = intel_crtc->pipe; |
| 9039 | int dpll_reg = DPLL(pipe); |
Daniel Vetter | dc257cf | 2012-05-07 11:30:46 +0200 | [diff] [blame] | 9040 | int dpll; |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9041 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9042 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9043 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 9044 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9045 | |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9046 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9047 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 9048 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 9049 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9050 | dpll = I915_READ(dpll_reg); |
| 9051 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9052 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9053 | } |
| 9054 | |
| 9055 | } |
| 9056 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9057 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9058 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9059 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9060 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9061 | if (dev_priv->mm.busy) |
| 9062 | return; |
| 9063 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 9064 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9065 | i915_update_gfx_val(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9066 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9067 | } |
| 9068 | |
| 9069 | void intel_mark_idle(struct drm_device *dev) |
| 9070 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9071 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9072 | struct drm_crtc *crtc; |
| 9073 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9074 | if (!dev_priv->mm.busy) |
| 9075 | return; |
| 9076 | |
| 9077 | dev_priv->mm.busy = false; |
| 9078 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 9079 | if (!i915.powersave) |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 9080 | goto out; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9081 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 9082 | for_each_crtc(dev, crtc) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9083 | if (!crtc->primary->fb) |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9084 | continue; |
| 9085 | |
| 9086 | intel_decrease_pllclock(crtc); |
| 9087 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9088 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 9089 | if (INTEL_INFO(dev)->gen >= 6) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9090 | gen6_rps_idle(dev->dev_private); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 9091 | |
| 9092 | out: |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 9093 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9094 | } |
| 9095 | |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 9096 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9097 | /** |
| 9098 | * intel_mark_fb_busy - mark given planes as busy |
| 9099 | * @dev: DRM device |
| 9100 | * @frontbuffer_bits: bits for the affected planes |
| 9101 | * @ring: optional ring for asynchronous commands |
| 9102 | * |
| 9103 | * This function gets called every time the screen contents change. It can be |
| 9104 | * used to keep e.g. the update rate at the nominal refresh rate with DRRS. |
| 9105 | */ |
| 9106 | static void intel_mark_fb_busy(struct drm_device *dev, |
| 9107 | unsigned frontbuffer_bits, |
| 9108 | struct intel_engine_cs *ring) |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9109 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 9110 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | cc36513 | 2014-06-18 13:59:13 +0200 | [diff] [blame] | 9111 | enum pipe pipe; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9112 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 9113 | if (!i915.powersave) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9114 | return; |
| 9115 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 9116 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9117 | if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe))) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9118 | continue; |
| 9119 | |
Daniel Vetter | cc36513 | 2014-06-18 13:59:13 +0200 | [diff] [blame] | 9120 | intel_increase_pllclock(dev, pipe); |
Chris Wilson | c65355b | 2013-06-06 16:53:41 -0300 | [diff] [blame] | 9121 | if (ring && intel_fbc_enabled(dev)) |
| 9122 | ring->fbc_dirty = true; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9123 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9124 | } |
| 9125 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9126 | /** |
| 9127 | * intel_fb_obj_invalidate - invalidate frontbuffer object |
| 9128 | * @obj: GEM object to invalidate |
| 9129 | * @ring: set for asynchronous rendering |
| 9130 | * |
| 9131 | * This function gets called every time rendering on the given object starts and |
| 9132 | * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must |
| 9133 | * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed |
| 9134 | * until the rendering completes or a flip on this frontbuffer plane is |
| 9135 | * scheduled. |
| 9136 | */ |
| 9137 | void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj, |
| 9138 | struct intel_engine_cs *ring) |
| 9139 | { |
| 9140 | struct drm_device *dev = obj->base.dev; |
| 9141 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9142 | |
| 9143 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 9144 | |
| 9145 | if (!obj->frontbuffer_bits) |
| 9146 | return; |
| 9147 | |
| 9148 | if (ring) { |
| 9149 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9150 | dev_priv->fb_tracking.busy_bits |
| 9151 | |= obj->frontbuffer_bits; |
| 9152 | dev_priv->fb_tracking.flip_bits |
| 9153 | &= ~obj->frontbuffer_bits; |
| 9154 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9155 | } |
| 9156 | |
| 9157 | intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring); |
| 9158 | |
Daniel Vetter | 9ca1530 | 2014-07-11 10:30:16 -0700 | [diff] [blame] | 9159 | intel_edp_psr_invalidate(dev, obj->frontbuffer_bits); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9160 | } |
| 9161 | |
| 9162 | /** |
| 9163 | * intel_frontbuffer_flush - flush frontbuffer |
| 9164 | * @dev: DRM device |
| 9165 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 9166 | * |
| 9167 | * This function gets called every time rendering on the given planes has |
| 9168 | * completed and frontbuffer caching can be started again. Flushes will get |
| 9169 | * delayed if they're blocked by some oustanding asynchronous rendering. |
| 9170 | * |
| 9171 | * Can be called without any locks held. |
| 9172 | */ |
| 9173 | void intel_frontbuffer_flush(struct drm_device *dev, |
| 9174 | unsigned frontbuffer_bits) |
| 9175 | { |
| 9176 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9177 | |
| 9178 | /* Delay flushing when rings are still busy.*/ |
| 9179 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9180 | frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits; |
| 9181 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9182 | |
| 9183 | intel_mark_fb_busy(dev, frontbuffer_bits, NULL); |
| 9184 | |
Daniel Vetter | 9ca1530 | 2014-07-11 10:30:16 -0700 | [diff] [blame] | 9185 | intel_edp_psr_flush(dev, frontbuffer_bits); |
Rodrigo Vivi | c5ad011 | 2014-08-04 03:51:38 -0700 | [diff] [blame] | 9186 | |
Ville Syrjälä | c317adc | 2014-09-03 14:09:50 +0300 | [diff] [blame] | 9187 | /* |
| 9188 | * FIXME: Unconditional fbc flushing here is a rather gross hack and |
| 9189 | * needs to be reworked into a proper frontbuffer tracking scheme like |
| 9190 | * psr employs. |
| 9191 | */ |
| 9192 | if (IS_BROADWELL(dev)) |
Rodrigo Vivi | c5ad011 | 2014-08-04 03:51:38 -0700 | [diff] [blame] | 9193 | gen8_fbc_sw_flush(dev, FBC_REND_CACHE_CLEAN); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9194 | } |
| 9195 | |
| 9196 | /** |
| 9197 | * intel_fb_obj_flush - flush frontbuffer object |
| 9198 | * @obj: GEM object to flush |
| 9199 | * @retire: set when retiring asynchronous rendering |
| 9200 | * |
| 9201 | * This function gets called every time rendering on the given object has |
| 9202 | * completed and frontbuffer caching can be started again. If @retire is true |
| 9203 | * then any delayed flushes will be unblocked. |
| 9204 | */ |
| 9205 | void intel_fb_obj_flush(struct drm_i915_gem_object *obj, |
| 9206 | bool retire) |
| 9207 | { |
| 9208 | struct drm_device *dev = obj->base.dev; |
| 9209 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9210 | unsigned frontbuffer_bits; |
| 9211 | |
| 9212 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 9213 | |
| 9214 | if (!obj->frontbuffer_bits) |
| 9215 | return; |
| 9216 | |
| 9217 | frontbuffer_bits = obj->frontbuffer_bits; |
| 9218 | |
| 9219 | if (retire) { |
| 9220 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9221 | /* Filter out new bits since rendering started. */ |
| 9222 | frontbuffer_bits &= dev_priv->fb_tracking.busy_bits; |
| 9223 | |
| 9224 | dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits; |
| 9225 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9226 | } |
| 9227 | |
| 9228 | intel_frontbuffer_flush(dev, frontbuffer_bits); |
| 9229 | } |
| 9230 | |
| 9231 | /** |
| 9232 | * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip |
| 9233 | * @dev: DRM device |
| 9234 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 9235 | * |
| 9236 | * This function gets called after scheduling a flip on @obj. The actual |
| 9237 | * frontbuffer flushing will be delayed until completion is signalled with |
| 9238 | * intel_frontbuffer_flip_complete. If an invalidate happens in between this |
| 9239 | * flush will be cancelled. |
| 9240 | * |
| 9241 | * Can be called without any locks held. |
| 9242 | */ |
| 9243 | void intel_frontbuffer_flip_prepare(struct drm_device *dev, |
| 9244 | unsigned frontbuffer_bits) |
| 9245 | { |
| 9246 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9247 | |
| 9248 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9249 | dev_priv->fb_tracking.flip_bits |
| 9250 | |= frontbuffer_bits; |
| 9251 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9252 | } |
| 9253 | |
| 9254 | /** |
| 9255 | * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush |
| 9256 | * @dev: DRM device |
| 9257 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 9258 | * |
| 9259 | * This function gets called after the flip has been latched and will complete |
| 9260 | * on the next vblank. It will execute the fush if it hasn't been cancalled yet. |
| 9261 | * |
| 9262 | * Can be called without any locks held. |
| 9263 | */ |
| 9264 | void intel_frontbuffer_flip_complete(struct drm_device *dev, |
| 9265 | unsigned frontbuffer_bits) |
| 9266 | { |
| 9267 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9268 | |
| 9269 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9270 | /* Mask any cancelled flips. */ |
| 9271 | frontbuffer_bits &= dev_priv->fb_tracking.flip_bits; |
| 9272 | dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits; |
| 9273 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9274 | |
| 9275 | intel_frontbuffer_flush(dev, frontbuffer_bits); |
| 9276 | } |
| 9277 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9278 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 9279 | { |
| 9280 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9281 | struct drm_device *dev = crtc->dev; |
| 9282 | struct intel_unpin_work *work; |
| 9283 | unsigned long flags; |
| 9284 | |
| 9285 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9286 | work = intel_crtc->unpin_work; |
| 9287 | intel_crtc->unpin_work = NULL; |
| 9288 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9289 | |
| 9290 | if (work) { |
| 9291 | cancel_work_sync(&work->work); |
| 9292 | kfree(work); |
| 9293 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9294 | |
| 9295 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9296 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9297 | kfree(intel_crtc); |
| 9298 | } |
| 9299 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9300 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 9301 | { |
| 9302 | struct intel_unpin_work *work = |
| 9303 | container_of(__work, struct intel_unpin_work, work); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9304 | struct drm_device *dev = work->crtc->dev; |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9305 | enum pipe pipe = to_intel_crtc(work->crtc)->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9306 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9307 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 9308 | intel_unpin_fb_obj(work->old_fb_obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9309 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
| 9310 | drm_gem_object_unreference(&work->old_fb_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 9311 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9312 | intel_update_fbc(dev); |
| 9313 | mutex_unlock(&dev->struct_mutex); |
| 9314 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9315 | intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 9316 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9317 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
| 9318 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); |
| 9319 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9320 | kfree(work); |
| 9321 | } |
| 9322 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9323 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9324 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9325 | { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9326 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9327 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9328 | unsigned long flags; |
| 9329 | |
| 9330 | /* Ignore early vblank irqs */ |
| 9331 | if (intel_crtc == NULL) |
| 9332 | return; |
| 9333 | |
| 9334 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9335 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9336 | |
| 9337 | /* Ensure we don't miss a work->pending update ... */ |
| 9338 | smp_rmb(); |
| 9339 | |
| 9340 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9341 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9342 | return; |
| 9343 | } |
| 9344 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9345 | page_flip_completed(intel_crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 9346 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9347 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9348 | } |
| 9349 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9350 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 9351 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9352 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9353 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 9354 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9355 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9356 | } |
| 9357 | |
| 9358 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 9359 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9360 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9361 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 9362 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9363 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9364 | } |
| 9365 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9366 | /* Is 'a' after or equal to 'b'? */ |
| 9367 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 9368 | { |
| 9369 | return !((a - b) & 0x80000000); |
| 9370 | } |
| 9371 | |
| 9372 | static bool page_flip_finished(struct intel_crtc *crtc) |
| 9373 | { |
| 9374 | struct drm_device *dev = crtc->base.dev; |
| 9375 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9376 | |
| 9377 | /* |
| 9378 | * The relevant registers doen't exist on pre-ctg. |
| 9379 | * As the flip done interrupt doesn't trigger for mmio |
| 9380 | * flips on gmch platforms, a flip count check isn't |
| 9381 | * really needed there. But since ctg has the registers, |
| 9382 | * include it in the check anyway. |
| 9383 | */ |
| 9384 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 9385 | return true; |
| 9386 | |
| 9387 | /* |
| 9388 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 9389 | * used the same base address. In that case the mmio flip might |
| 9390 | * have completed, but the CS hasn't even executed the flip yet. |
| 9391 | * |
| 9392 | * A flip count check isn't enough as the CS might have updated |
| 9393 | * the base address just after start of vblank, but before we |
| 9394 | * managed to process the interrupt. This means we'd complete the |
| 9395 | * CS flip too soon. |
| 9396 | * |
| 9397 | * Combining both checks should get us a good enough result. It may |
| 9398 | * still happen that the CS flip has been executed, but has not |
| 9399 | * yet actually completed. But in case the base address is the same |
| 9400 | * anyway, we don't really care. |
| 9401 | */ |
| 9402 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 9403 | crtc->unpin_work->gtt_offset && |
| 9404 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), |
| 9405 | crtc->unpin_work->flip_count); |
| 9406 | } |
| 9407 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9408 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 9409 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9410 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9411 | struct intel_crtc *intel_crtc = |
| 9412 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 9413 | unsigned long flags; |
| 9414 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9415 | /* NB: An MMIO update of the plane base pointer will also |
| 9416 | * generate a page-flip completion irq, i.e. every modeset |
| 9417 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 9418 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9419 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9420 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9421 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9422 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9423 | } |
| 9424 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9425 | static inline void intel_mark_page_flip_active(struct intel_crtc *intel_crtc) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9426 | { |
| 9427 | /* Ensure that the work item is consistent when activating it ... */ |
| 9428 | smp_wmb(); |
| 9429 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); |
| 9430 | /* and that it is marked active as soon as the irq could fire. */ |
| 9431 | smp_wmb(); |
| 9432 | } |
| 9433 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9434 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 9435 | struct drm_crtc *crtc, |
| 9436 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9437 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9438 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9439 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9440 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9441 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9442 | u32 flip_mask; |
| 9443 | int ret; |
| 9444 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9445 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9446 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9447 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9448 | |
| 9449 | /* Can't queue multiple flips, so wait for the previous |
| 9450 | * one to finish before executing the next. |
| 9451 | */ |
| 9452 | if (intel_crtc->plane) |
| 9453 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9454 | else |
| 9455 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9456 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9457 | intel_ring_emit(ring, MI_NOOP); |
| 9458 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9459 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9460 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9461 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9462 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9463 | |
| 9464 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9465 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9466 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9467 | } |
| 9468 | |
| 9469 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 9470 | struct drm_crtc *crtc, |
| 9471 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9472 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9473 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9474 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9475 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9476 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9477 | u32 flip_mask; |
| 9478 | int ret; |
| 9479 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9480 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9481 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9482 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9483 | |
| 9484 | if (intel_crtc->plane) |
| 9485 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9486 | else |
| 9487 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9488 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9489 | intel_ring_emit(ring, MI_NOOP); |
| 9490 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
| 9491 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9492 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9493 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9494 | intel_ring_emit(ring, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9495 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9496 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9497 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9498 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9499 | } |
| 9500 | |
| 9501 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 9502 | struct drm_crtc *crtc, |
| 9503 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9504 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9505 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9506 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9507 | { |
| 9508 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9509 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9510 | uint32_t pf, pipesrc; |
| 9511 | int ret; |
| 9512 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9513 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9514 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9515 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9516 | |
| 9517 | /* i965+ uses the linear or tiled offsets from the |
| 9518 | * Display Registers (which do not change across a page-flip) |
| 9519 | * so we need only reprogram the base address. |
| 9520 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9521 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9522 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9523 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9524 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 9525 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9526 | |
| 9527 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 9528 | * untested on non-native modes, so ignore it for now. |
| 9529 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 9530 | */ |
| 9531 | pf = 0; |
| 9532 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9533 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9534 | |
| 9535 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9536 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9537 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9538 | } |
| 9539 | |
| 9540 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 9541 | struct drm_crtc *crtc, |
| 9542 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9543 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9544 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9545 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9546 | { |
| 9547 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9548 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9549 | uint32_t pf, pipesrc; |
| 9550 | int ret; |
| 9551 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9552 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9553 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9554 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9555 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9556 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9557 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9558 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9559 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9560 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 9561 | /* Contrary to the suggestions in the documentation, |
| 9562 | * "Enable Panel Fitter" does not seem to be required when page |
| 9563 | * flipping with a non-native mode, and worse causes a normal |
| 9564 | * modeset to fail. |
| 9565 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 9566 | */ |
| 9567 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9568 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9569 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9570 | |
| 9571 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9572 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9573 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9574 | } |
| 9575 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9576 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 9577 | struct drm_crtc *crtc, |
| 9578 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9579 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9580 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9581 | uint32_t flags) |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9582 | { |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9583 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9584 | uint32_t plane_bit = 0; |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9585 | int len, ret; |
| 9586 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9587 | switch (intel_crtc->plane) { |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9588 | case PLANE_A: |
| 9589 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 9590 | break; |
| 9591 | case PLANE_B: |
| 9592 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 9593 | break; |
| 9594 | case PLANE_C: |
| 9595 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 9596 | break; |
| 9597 | default: |
| 9598 | WARN_ONCE(1, "unknown plane in flip command\n"); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9599 | return -ENODEV; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9600 | } |
| 9601 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9602 | len = 4; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9603 | if (ring->id == RCS) { |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9604 | len += 6; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9605 | /* |
| 9606 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 9607 | * 48bits addresses, and we need a NOOP for the batch size to |
| 9608 | * stay even. |
| 9609 | */ |
| 9610 | if (IS_GEN8(dev)) |
| 9611 | len += 2; |
| 9612 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9613 | |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9614 | /* |
| 9615 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 9616 | * "The full packet must be contained within the same cache line." |
| 9617 | * |
| 9618 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 9619 | * cacheline, if we ever start emitting more commands before |
| 9620 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 9621 | * then do the cacheline alignment, and finally emit the |
| 9622 | * MI_DISPLAY_FLIP. |
| 9623 | */ |
| 9624 | ret = intel_ring_cacheline_align(ring); |
| 9625 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9626 | return ret; |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9627 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9628 | ret = intel_ring_begin(ring, len); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9629 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9630 | return ret; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9631 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9632 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 9633 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 9634 | * more than one flip event at any time (or ensure that one flip message |
| 9635 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 9636 | * Experimentation says that BCS works despite DERRMR masking all |
| 9637 | * flip-done completion events and that unmasking all planes at once |
| 9638 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 9639 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 9640 | */ |
| 9641 | if (ring->id == RCS) { |
| 9642 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
| 9643 | intel_ring_emit(ring, DERRMR); |
| 9644 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 9645 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 9646 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9647 | if (IS_GEN8(dev)) |
| 9648 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) | |
| 9649 | MI_SRM_LRM_GLOBAL_GTT); |
| 9650 | else |
| 9651 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | |
| 9652 | MI_SRM_LRM_GLOBAL_GTT); |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9653 | intel_ring_emit(ring, DERRMR); |
| 9654 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9655 | if (IS_GEN8(dev)) { |
| 9656 | intel_ring_emit(ring, 0); |
| 9657 | intel_ring_emit(ring, MI_NOOP); |
| 9658 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9659 | } |
| 9660 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9661 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 9662 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9663 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9664 | intel_ring_emit(ring, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9665 | |
| 9666 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9667 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9668 | return 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9669 | } |
| 9670 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9671 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
| 9672 | struct drm_i915_gem_object *obj) |
| 9673 | { |
| 9674 | /* |
| 9675 | * This is not being used for older platforms, because |
| 9676 | * non-availability of flip done interrupt forces us to use |
| 9677 | * CS flips. Older platforms derive flip done using some clever |
| 9678 | * tricks involving the flip_pending status bits and vblank irqs. |
| 9679 | * So using MMIO flips there would disrupt this mechanism. |
| 9680 | */ |
| 9681 | |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 9682 | if (ring == NULL) |
| 9683 | return true; |
| 9684 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9685 | if (INTEL_INFO(ring->dev)->gen < 5) |
| 9686 | return false; |
| 9687 | |
| 9688 | if (i915.use_mmio_flip < 0) |
| 9689 | return false; |
| 9690 | else if (i915.use_mmio_flip > 0) |
| 9691 | return true; |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 9692 | else if (i915.enable_execlists) |
| 9693 | return true; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9694 | else |
| 9695 | return ring != obj->ring; |
| 9696 | } |
| 9697 | |
| 9698 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 9699 | { |
| 9700 | struct drm_device *dev = intel_crtc->base.dev; |
| 9701 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9702 | struct intel_framebuffer *intel_fb = |
| 9703 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 9704 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 9705 | u32 dspcntr; |
| 9706 | u32 reg; |
| 9707 | |
| 9708 | intel_mark_page_flip_active(intel_crtc); |
| 9709 | |
| 9710 | reg = DSPCNTR(intel_crtc->plane); |
| 9711 | dspcntr = I915_READ(reg); |
| 9712 | |
| 9713 | if (INTEL_INFO(dev)->gen >= 4) { |
| 9714 | if (obj->tiling_mode != I915_TILING_NONE) |
| 9715 | dspcntr |= DISPPLANE_TILED; |
| 9716 | else |
| 9717 | dspcntr &= ~DISPPLANE_TILED; |
| 9718 | } |
| 9719 | I915_WRITE(reg, dspcntr); |
| 9720 | |
| 9721 | I915_WRITE(DSPSURF(intel_crtc->plane), |
| 9722 | intel_crtc->unpin_work->gtt_offset); |
| 9723 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
| 9724 | } |
| 9725 | |
| 9726 | static int intel_postpone_flip(struct drm_i915_gem_object *obj) |
| 9727 | { |
| 9728 | struct intel_engine_cs *ring; |
| 9729 | int ret; |
| 9730 | |
| 9731 | lockdep_assert_held(&obj->base.dev->struct_mutex); |
| 9732 | |
| 9733 | if (!obj->last_write_seqno) |
| 9734 | return 0; |
| 9735 | |
| 9736 | ring = obj->ring; |
| 9737 | |
| 9738 | if (i915_seqno_passed(ring->get_seqno(ring, true), |
| 9739 | obj->last_write_seqno)) |
| 9740 | return 0; |
| 9741 | |
| 9742 | ret = i915_gem_check_olr(ring, obj->last_write_seqno); |
| 9743 | if (ret) |
| 9744 | return ret; |
| 9745 | |
| 9746 | if (WARN_ON(!ring->irq_get(ring))) |
| 9747 | return 0; |
| 9748 | |
| 9749 | return 1; |
| 9750 | } |
| 9751 | |
| 9752 | void intel_notify_mmio_flip(struct intel_engine_cs *ring) |
| 9753 | { |
| 9754 | struct drm_i915_private *dev_priv = to_i915(ring->dev); |
| 9755 | struct intel_crtc *intel_crtc; |
| 9756 | unsigned long irq_flags; |
| 9757 | u32 seqno; |
| 9758 | |
| 9759 | seqno = ring->get_seqno(ring, false); |
| 9760 | |
| 9761 | spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags); |
| 9762 | for_each_intel_crtc(ring->dev, intel_crtc) { |
| 9763 | struct intel_mmio_flip *mmio_flip; |
| 9764 | |
| 9765 | mmio_flip = &intel_crtc->mmio_flip; |
| 9766 | if (mmio_flip->seqno == 0) |
| 9767 | continue; |
| 9768 | |
| 9769 | if (ring->id != mmio_flip->ring_id) |
| 9770 | continue; |
| 9771 | |
| 9772 | if (i915_seqno_passed(seqno, mmio_flip->seqno)) { |
| 9773 | intel_do_mmio_flip(intel_crtc); |
| 9774 | mmio_flip->seqno = 0; |
| 9775 | ring->irq_put(ring); |
| 9776 | } |
| 9777 | } |
| 9778 | spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags); |
| 9779 | } |
| 9780 | |
| 9781 | static int intel_queue_mmio_flip(struct drm_device *dev, |
| 9782 | struct drm_crtc *crtc, |
| 9783 | struct drm_framebuffer *fb, |
| 9784 | struct drm_i915_gem_object *obj, |
| 9785 | struct intel_engine_cs *ring, |
| 9786 | uint32_t flags) |
| 9787 | { |
| 9788 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9789 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9790 | unsigned long irq_flags; |
| 9791 | int ret; |
| 9792 | |
| 9793 | if (WARN_ON(intel_crtc->mmio_flip.seqno)) |
| 9794 | return -EBUSY; |
| 9795 | |
| 9796 | ret = intel_postpone_flip(obj); |
| 9797 | if (ret < 0) |
| 9798 | return ret; |
| 9799 | if (ret == 0) { |
| 9800 | intel_do_mmio_flip(intel_crtc); |
| 9801 | return 0; |
| 9802 | } |
| 9803 | |
| 9804 | spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags); |
| 9805 | intel_crtc->mmio_flip.seqno = obj->last_write_seqno; |
| 9806 | intel_crtc->mmio_flip.ring_id = obj->ring->id; |
| 9807 | spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags); |
| 9808 | |
| 9809 | /* |
| 9810 | * Double check to catch cases where irq fired before |
| 9811 | * mmio flip data was ready |
| 9812 | */ |
| 9813 | intel_notify_mmio_flip(obj->ring); |
| 9814 | return 0; |
| 9815 | } |
| 9816 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9817 | static int intel_default_queue_flip(struct drm_device *dev, |
| 9818 | struct drm_crtc *crtc, |
| 9819 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9820 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9821 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9822 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9823 | { |
| 9824 | return -ENODEV; |
| 9825 | } |
| 9826 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9827 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
| 9828 | struct drm_crtc *crtc) |
| 9829 | { |
| 9830 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9831 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9832 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 9833 | u32 addr; |
| 9834 | |
| 9835 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) |
| 9836 | return true; |
| 9837 | |
| 9838 | if (!work->enable_stall_check) |
| 9839 | return false; |
| 9840 | |
| 9841 | if (work->flip_ready_vblank == 0) { |
| 9842 | if (work->flip_queued_ring && |
| 9843 | !i915_seqno_passed(work->flip_queued_ring->get_seqno(work->flip_queued_ring, true), |
| 9844 | work->flip_queued_seqno)) |
| 9845 | return false; |
| 9846 | |
| 9847 | work->flip_ready_vblank = drm_vblank_count(dev, intel_crtc->pipe); |
| 9848 | } |
| 9849 | |
| 9850 | if (drm_vblank_count(dev, intel_crtc->pipe) - work->flip_ready_vblank < 3) |
| 9851 | return false; |
| 9852 | |
| 9853 | /* Potential stall - if we see that the flip has happened, |
| 9854 | * assume a missed interrupt. */ |
| 9855 | if (INTEL_INFO(dev)->gen >= 4) |
| 9856 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 9857 | else |
| 9858 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 9859 | |
| 9860 | /* There is a potential issue here with a false positive after a flip |
| 9861 | * to the same address. We could address this by checking for a |
| 9862 | * non-incrementing frame counter. |
| 9863 | */ |
| 9864 | return addr == work->gtt_offset; |
| 9865 | } |
| 9866 | |
| 9867 | void intel_check_page_flip(struct drm_device *dev, int pipe) |
| 9868 | { |
| 9869 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9870 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 9871 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9872 | unsigned long flags; |
| 9873 | |
| 9874 | if (crtc == NULL) |
| 9875 | return; |
| 9876 | |
| 9877 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9878 | if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) { |
| 9879 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
| 9880 | intel_crtc->unpin_work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
| 9881 | page_flip_completed(intel_crtc); |
| 9882 | } |
| 9883 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9884 | } |
| 9885 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9886 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 9887 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9888 | struct drm_pending_vblank_event *event, |
| 9889 | uint32_t page_flip_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9890 | { |
| 9891 | struct drm_device *dev = crtc->dev; |
| 9892 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9893 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 9894 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9895 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 9896 | enum pipe pipe = intel_crtc->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9897 | struct intel_unpin_work *work; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9898 | struct intel_engine_cs *ring; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9899 | unsigned long flags; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 9900 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9901 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 9902 | //trigger software GT busyness calculation |
| 9903 | gen8_flip_interrupt(dev); |
| 9904 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 9905 | /* |
| 9906 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 9907 | * check to be safe. In the future we may enable pageflipping from |
| 9908 | * a disabled primary plane. |
| 9909 | */ |
| 9910 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 9911 | return -EBUSY; |
| 9912 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 9913 | /* Can't change pixel format via MI display flips. */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9914 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 9915 | return -EINVAL; |
| 9916 | |
| 9917 | /* |
| 9918 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 9919 | * Note that pitch changes could also affect these register. |
| 9920 | */ |
| 9921 | if (INTEL_INFO(dev)->gen > 3 && |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9922 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 9923 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 9924 | return -EINVAL; |
| 9925 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 9926 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 9927 | goto out_hang; |
| 9928 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 9929 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9930 | if (work == NULL) |
| 9931 | return -ENOMEM; |
| 9932 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9933 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9934 | work->crtc = crtc; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 9935 | work->old_fb_obj = intel_fb_obj(old_fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9936 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 9937 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 9938 | ret = drm_crtc_vblank_get(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 9939 | if (ret) |
| 9940 | goto free_work; |
| 9941 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9942 | /* We borrow the event spin lock for protecting unpin_work */ |
| 9943 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9944 | if (intel_crtc->unpin_work) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9945 | /* Before declaring the flip queue wedged, check if |
| 9946 | * the hardware completed the operation behind our backs. |
| 9947 | */ |
| 9948 | if (__intel_pageflip_stall_check(dev, crtc)) { |
| 9949 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 9950 | page_flip_completed(intel_crtc); |
| 9951 | } else { |
| 9952 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
| 9953 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 9954 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9955 | drm_crtc_vblank_put(crtc); |
| 9956 | kfree(work); |
| 9957 | return -EBUSY; |
| 9958 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9959 | } |
| 9960 | intel_crtc->unpin_work = work; |
| 9961 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9962 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9963 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 9964 | flush_workqueue(dev_priv->wq); |
| 9965 | |
Chris Wilson | 7915810 | 2012-05-23 11:13:58 +0100 | [diff] [blame] | 9966 | ret = i915_mutex_lock_interruptible(dev); |
| 9967 | if (ret) |
| 9968 | goto cleanup; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9969 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 9970 | /* Reference the objects for the scheduled work. */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9971 | drm_gem_object_reference(&work->old_fb_obj->base); |
| 9972 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9973 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9974 | crtc->primary->fb = fb; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 9975 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 9976 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 9977 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9978 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 9979 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 9980 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9981 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 9982 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9983 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9984 | if (IS_VALLEYVIEW(dev)) { |
| 9985 | ring = &dev_priv->ring[BCS]; |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 9986 | if (obj->tiling_mode != work->old_fb_obj->tiling_mode) |
| 9987 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
| 9988 | ring = NULL; |
Chris Wilson | 2a92d5b | 2014-07-08 10:40:29 +0100 | [diff] [blame] | 9989 | } else if (IS_IVYBRIDGE(dev)) { |
| 9990 | ring = &dev_priv->ring[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9991 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 9992 | ring = obj->ring; |
| 9993 | if (ring == NULL || ring->id != RCS) |
| 9994 | ring = &dev_priv->ring[BCS]; |
| 9995 | } else { |
| 9996 | ring = &dev_priv->ring[RCS]; |
| 9997 | } |
| 9998 | |
| 9999 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10000 | if (ret) |
| 10001 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10002 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10003 | work->gtt_offset = |
| 10004 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset; |
| 10005 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10006 | if (use_mmio_flip(ring, obj)) { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10007 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
| 10008 | page_flip_flags); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10009 | if (ret) |
| 10010 | goto cleanup_unpin; |
| 10011 | |
| 10012 | work->flip_queued_seqno = obj->last_write_seqno; |
| 10013 | work->flip_queued_ring = obj->ring; |
| 10014 | } else { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10015 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring, |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10016 | page_flip_flags); |
| 10017 | if (ret) |
| 10018 | goto cleanup_unpin; |
| 10019 | |
| 10020 | work->flip_queued_seqno = intel_ring_get_seqno(ring); |
| 10021 | work->flip_queued_ring = ring; |
| 10022 | } |
| 10023 | |
| 10024 | work->flip_queued_vblank = drm_vblank_count(dev, intel_crtc->pipe); |
| 10025 | work->enable_stall_check = true; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10026 | |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10027 | i915_gem_track_fb(work->old_fb_obj, obj, |
| 10028 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 10029 | |
Chris Wilson | 7782de3 | 2011-07-08 12:22:41 +0100 | [diff] [blame] | 10030 | intel_disable_fbc(dev); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10031 | intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10032 | mutex_unlock(&dev->struct_mutex); |
| 10033 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 10034 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 10035 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10036 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10037 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10038 | cleanup_unpin: |
| 10039 | intel_unpin_fb_obj(obj); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10040 | cleanup_pending: |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10041 | atomic_dec(&intel_crtc->unpin_work_count); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10042 | crtc->primary->fb = old_fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 10043 | drm_gem_object_unreference(&work->old_fb_obj->base); |
| 10044 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10045 | mutex_unlock(&dev->struct_mutex); |
| 10046 | |
Chris Wilson | 7915810 | 2012-05-23 11:13:58 +0100 | [diff] [blame] | 10047 | cleanup: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10048 | spin_lock_irqsave(&dev->event_lock, flags); |
| 10049 | intel_crtc->unpin_work = NULL; |
| 10050 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10051 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 10052 | drm_crtc_vblank_put(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 10053 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10054 | kfree(work); |
| 10055 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10056 | if (ret == -EIO) { |
| 10057 | out_hang: |
| 10058 | intel_crtc_wait_for_pending_flips(crtc); |
| 10059 | ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 10060 | if (ret == 0 && event) { |
| 10061 | spin_lock_irqsave(&dev->event_lock, flags); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10062 | drm_send_vblank_event(dev, pipe, event); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 10063 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 10064 | } |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10065 | } |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10066 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10067 | } |
| 10068 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10069 | static struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10070 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 10071 | .load_lut = intel_crtc_load_lut, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10072 | }; |
| 10073 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10074 | /** |
| 10075 | * intel_modeset_update_staged_output_state |
| 10076 | * |
| 10077 | * Updates the staged output configuration state, e.g. after we've read out the |
| 10078 | * current hw state. |
| 10079 | */ |
| 10080 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) |
| 10081 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10082 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10083 | struct intel_encoder *encoder; |
| 10084 | struct intel_connector *connector; |
| 10085 | |
| 10086 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 10087 | base.head) { |
| 10088 | connector->new_encoder = |
| 10089 | to_intel_encoder(connector->base.encoder); |
| 10090 | } |
| 10091 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10092 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10093 | encoder->new_crtc = |
| 10094 | to_intel_crtc(encoder->base.crtc); |
| 10095 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10096 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10097 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10098 | crtc->new_enabled = crtc->base.enabled; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 10099 | |
| 10100 | if (crtc->new_enabled) |
| 10101 | crtc->new_config = &crtc->config; |
| 10102 | else |
| 10103 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10104 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10105 | } |
| 10106 | |
| 10107 | /** |
| 10108 | * intel_modeset_commit_output_state |
| 10109 | * |
| 10110 | * This function copies the stage display pipe configuration to the real one. |
| 10111 | */ |
| 10112 | static void intel_modeset_commit_output_state(struct drm_device *dev) |
| 10113 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10114 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10115 | struct intel_encoder *encoder; |
| 10116 | struct intel_connector *connector; |
| 10117 | |
| 10118 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 10119 | base.head) { |
| 10120 | connector->base.encoder = &connector->new_encoder->base; |
| 10121 | } |
| 10122 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10123 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10124 | encoder->base.crtc = &encoder->new_crtc->base; |
| 10125 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10126 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10127 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10128 | crtc->base.enabled = crtc->new_enabled; |
| 10129 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10130 | } |
| 10131 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10132 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10133 | connected_sink_compute_bpp(struct intel_connector *connector, |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10134 | struct intel_crtc_config *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10135 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10136 | int bpp = pipe_config->pipe_bpp; |
| 10137 | |
| 10138 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 10139 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10140 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10141 | |
| 10142 | /* Don't use an invalid EDID bpc value */ |
| 10143 | if (connector->base.display_info.bpc && |
| 10144 | connector->base.display_info.bpc * 3 < bpp) { |
| 10145 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 10146 | bpp, connector->base.display_info.bpc*3); |
| 10147 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 10148 | } |
| 10149 | |
| 10150 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
| 10151 | if (connector->base.display_info.bpc == 0 && bpp > 24) { |
| 10152 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 10153 | bpp); |
| 10154 | pipe_config->pipe_bpp = 24; |
| 10155 | } |
| 10156 | } |
| 10157 | |
| 10158 | static int |
| 10159 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
| 10160 | struct drm_framebuffer *fb, |
| 10161 | struct intel_crtc_config *pipe_config) |
| 10162 | { |
| 10163 | struct drm_device *dev = crtc->base.dev; |
| 10164 | struct intel_connector *connector; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10165 | int bpp; |
| 10166 | |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10167 | switch (fb->pixel_format) { |
| 10168 | case DRM_FORMAT_C8: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10169 | bpp = 8*3; /* since we go through a colormap */ |
| 10170 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10171 | case DRM_FORMAT_XRGB1555: |
| 10172 | case DRM_FORMAT_ARGB1555: |
| 10173 | /* checked in intel_framebuffer_init already */ |
| 10174 | if (WARN_ON(INTEL_INFO(dev)->gen > 3)) |
| 10175 | return -EINVAL; |
| 10176 | case DRM_FORMAT_RGB565: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10177 | bpp = 6*3; /* min is 18bpp */ |
| 10178 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10179 | case DRM_FORMAT_XBGR8888: |
| 10180 | case DRM_FORMAT_ABGR8888: |
| 10181 | /* checked in intel_framebuffer_init already */ |
| 10182 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
| 10183 | return -EINVAL; |
| 10184 | case DRM_FORMAT_XRGB8888: |
| 10185 | case DRM_FORMAT_ARGB8888: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10186 | bpp = 8*3; |
| 10187 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10188 | case DRM_FORMAT_XRGB2101010: |
| 10189 | case DRM_FORMAT_ARGB2101010: |
| 10190 | case DRM_FORMAT_XBGR2101010: |
| 10191 | case DRM_FORMAT_ABGR2101010: |
| 10192 | /* checked in intel_framebuffer_init already */ |
| 10193 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10194 | return -EINVAL; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10195 | bpp = 10*3; |
| 10196 | break; |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10197 | /* TODO: gen4+ supports 16 bpc floating point, too. */ |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10198 | default: |
| 10199 | DRM_DEBUG_KMS("unsupported depth\n"); |
| 10200 | return -EINVAL; |
| 10201 | } |
| 10202 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10203 | pipe_config->pipe_bpp = bpp; |
| 10204 | |
| 10205 | /* Clamp display bpp to EDID value */ |
| 10206 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10207 | base.head) { |
Daniel Vetter | 1b829e0 | 2013-06-02 13:26:24 +0200 | [diff] [blame] | 10208 | if (!connector->new_encoder || |
| 10209 | connector->new_encoder->new_crtc != crtc) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10210 | continue; |
| 10211 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10212 | connected_sink_compute_bpp(connector, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10213 | } |
| 10214 | |
| 10215 | return bpp; |
| 10216 | } |
| 10217 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10218 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 10219 | { |
| 10220 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 10221 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 10222 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10223 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 10224 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 10225 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 10226 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 10227 | } |
| 10228 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10229 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
| 10230 | struct intel_crtc_config *pipe_config, |
| 10231 | const char *context) |
| 10232 | { |
| 10233 | DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id, |
| 10234 | context, pipe_name(crtc->pipe)); |
| 10235 | |
| 10236 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); |
| 10237 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 10238 | pipe_config->pipe_bpp, pipe_config->dither); |
| 10239 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10240 | pipe_config->has_pch_encoder, |
| 10241 | pipe_config->fdi_lanes, |
| 10242 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 10243 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 10244 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10245 | DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10246 | pipe_config->has_dp_encoder, |
| 10247 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 10248 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 10249 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10250 | |
| 10251 | DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
| 10252 | pipe_config->has_dp_encoder, |
| 10253 | pipe_config->dp_m2_n2.gmch_m, |
| 10254 | pipe_config->dp_m2_n2.gmch_n, |
| 10255 | pipe_config->dp_m2_n2.link_m, |
| 10256 | pipe_config->dp_m2_n2.link_n, |
| 10257 | pipe_config->dp_m2_n2.tu); |
| 10258 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10259 | DRM_DEBUG_KMS("requested mode:\n"); |
| 10260 | drm_mode_debug_printmodeline(&pipe_config->requested_mode); |
| 10261 | DRM_DEBUG_KMS("adjusted mode:\n"); |
| 10262 | drm_mode_debug_printmodeline(&pipe_config->adjusted_mode); |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10263 | intel_dump_crtc_timings(&pipe_config->adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 10264 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10265 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 10266 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10267 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 10268 | pipe_config->gmch_pfit.control, |
| 10269 | pipe_config->gmch_pfit.pgm_ratios, |
| 10270 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10271 | DRM_DEBUG_KMS("pch pfit: pos: 0x%08x, size: 0x%08x, %s\n", |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10272 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10273 | pipe_config->pch_pfit.size, |
| 10274 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10275 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 10276 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10277 | } |
| 10278 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10279 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10280 | const struct intel_encoder *b) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10281 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10282 | /* masks could be asymmetric, so check both ways */ |
| 10283 | return a == b || (a->cloneable & (1 << b->type) && |
| 10284 | b->cloneable & (1 << a->type)); |
| 10285 | } |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10286 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10287 | static bool check_single_encoder_cloning(struct intel_crtc *crtc, |
| 10288 | struct intel_encoder *encoder) |
| 10289 | { |
| 10290 | struct drm_device *dev = crtc->base.dev; |
| 10291 | struct intel_encoder *source_encoder; |
| 10292 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10293 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10294 | if (source_encoder->new_crtc != crtc) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10295 | continue; |
| 10296 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10297 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10298 | return false; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10299 | } |
| 10300 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10301 | return true; |
| 10302 | } |
| 10303 | |
| 10304 | static bool check_encoder_cloning(struct intel_crtc *crtc) |
| 10305 | { |
| 10306 | struct drm_device *dev = crtc->base.dev; |
| 10307 | struct intel_encoder *encoder; |
| 10308 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10309 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10310 | if (encoder->new_crtc != crtc) |
| 10311 | continue; |
| 10312 | |
| 10313 | if (!check_single_encoder_cloning(crtc, encoder)) |
| 10314 | return false; |
| 10315 | } |
| 10316 | |
| 10317 | return true; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10318 | } |
| 10319 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10320 | static struct intel_crtc_config * |
| 10321 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10322 | struct drm_framebuffer *fb, |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10323 | struct drm_display_mode *mode) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10324 | { |
| 10325 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10326 | struct intel_encoder *encoder; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10327 | struct intel_crtc_config *pipe_config; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10328 | int plane_bpp, ret = -EINVAL; |
| 10329 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10330 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10331 | if (!check_encoder_cloning(to_intel_crtc(crtc))) { |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10332 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 10333 | return ERR_PTR(-EINVAL); |
| 10334 | } |
| 10335 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10336 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 10337 | if (!pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10338 | return ERR_PTR(-ENOMEM); |
| 10339 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10340 | drm_mode_copy(&pipe_config->adjusted_mode, mode); |
| 10341 | drm_mode_copy(&pipe_config->requested_mode, mode); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10342 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 10343 | pipe_config->cpu_transcoder = |
| 10344 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10345 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10346 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10347 | /* |
| 10348 | * Sanitize sync polarity flags based on requested ones. If neither |
| 10349 | * positive or negative polarity is requested, treat this as meaning |
| 10350 | * negative polarity. |
| 10351 | */ |
| 10352 | if (!(pipe_config->adjusted_mode.flags & |
| 10353 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
| 10354 | pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
| 10355 | |
| 10356 | if (!(pipe_config->adjusted_mode.flags & |
| 10357 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
| 10358 | pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
| 10359 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10360 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
| 10361 | * plane pixel format and any sink constraints into account. Returns the |
| 10362 | * source plane bpp so that dithering can be selected on mismatches |
| 10363 | * after encoders and crtc also have had their say. */ |
| 10364 | plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 10365 | fb, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10366 | if (plane_bpp < 0) |
| 10367 | goto fail; |
| 10368 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10369 | /* |
| 10370 | * Determine the real pipe dimensions. Note that stereo modes can |
| 10371 | * increase the actual pipe size due to the frame doubling and |
| 10372 | * insertion of additional space for blanks between the frame. This |
| 10373 | * is stored in the crtc timings. We use the requested mode to do this |
| 10374 | * computation to clearly distinguish it from the adjusted mode, which |
| 10375 | * can be changed by the connectors in the below retry loop. |
| 10376 | */ |
| 10377 | drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE); |
| 10378 | pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay; |
| 10379 | pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay; |
| 10380 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10381 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10382 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10383 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10384 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10385 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10386 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Damien Lespiau | 6ce70f5 | 2013-09-25 16:45:38 +0100 | [diff] [blame] | 10387 | drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10388 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10389 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 10390 | * adjust it according to limitations or connector properties, and also |
| 10391 | * a chance to reject the mode entirely. |
| 10392 | */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10393 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10394 | |
| 10395 | if (&encoder->new_crtc->base != crtc) |
| 10396 | continue; |
Daniel Vetter | 7ae8923 | 2013-03-27 00:44:52 +0100 | [diff] [blame] | 10397 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 10398 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 10399 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10400 | goto fail; |
| 10401 | } |
| 10402 | } |
| 10403 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10404 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 10405 | * done afterwards in case the encoder adjusts the mode. */ |
| 10406 | if (!pipe_config->port_clock) |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10407 | pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock |
| 10408 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10409 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 10410 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10411 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10412 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 10413 | goto fail; |
| 10414 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10415 | |
| 10416 | if (ret == RETRY) { |
| 10417 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 10418 | ret = -EINVAL; |
| 10419 | goto fail; |
| 10420 | } |
| 10421 | |
| 10422 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 10423 | retry = false; |
| 10424 | goto encoder_retry; |
| 10425 | } |
| 10426 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10427 | pipe_config->dither = pipe_config->pipe_bpp != plane_bpp; |
| 10428 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
| 10429 | plane_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
| 10430 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10431 | return pipe_config; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10432 | fail: |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10433 | kfree(pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10434 | return ERR_PTR(ret); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10435 | } |
| 10436 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10437 | /* Computes which crtcs are affected and sets the relevant bits in the mask. For |
| 10438 | * simplicity we use the crtc's pipe number (because it's easier to obtain). */ |
| 10439 | static void |
| 10440 | intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes, |
| 10441 | unsigned *prepare_pipes, unsigned *disable_pipes) |
| 10442 | { |
| 10443 | struct intel_crtc *intel_crtc; |
| 10444 | struct drm_device *dev = crtc->dev; |
| 10445 | struct intel_encoder *encoder; |
| 10446 | struct intel_connector *connector; |
| 10447 | struct drm_crtc *tmp_crtc; |
| 10448 | |
| 10449 | *disable_pipes = *modeset_pipes = *prepare_pipes = 0; |
| 10450 | |
| 10451 | /* Check which crtcs have changed outputs connected to them, these need |
| 10452 | * to be part of the prepare_pipes mask. We don't (yet) support global |
| 10453 | * modeset across multiple crtcs, so modeset_pipes will only have one |
| 10454 | * bit set at most. */ |
| 10455 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 10456 | base.head) { |
| 10457 | if (connector->base.encoder == &connector->new_encoder->base) |
| 10458 | continue; |
| 10459 | |
| 10460 | if (connector->base.encoder) { |
| 10461 | tmp_crtc = connector->base.encoder->crtc; |
| 10462 | |
| 10463 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 10464 | } |
| 10465 | |
| 10466 | if (connector->new_encoder) |
| 10467 | *prepare_pipes |= |
| 10468 | 1 << connector->new_encoder->new_crtc->pipe; |
| 10469 | } |
| 10470 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10471 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10472 | if (encoder->base.crtc == &encoder->new_crtc->base) |
| 10473 | continue; |
| 10474 | |
| 10475 | if (encoder->base.crtc) { |
| 10476 | tmp_crtc = encoder->base.crtc; |
| 10477 | |
| 10478 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 10479 | } |
| 10480 | |
| 10481 | if (encoder->new_crtc) |
| 10482 | *prepare_pipes |= 1 << encoder->new_crtc->pipe; |
| 10483 | } |
| 10484 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10485 | /* Check for pipes that will be enabled/disabled ... */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10486 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10487 | if (intel_crtc->base.enabled == intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10488 | continue; |
| 10489 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10490 | if (!intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10491 | *disable_pipes |= 1 << intel_crtc->pipe; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10492 | else |
| 10493 | *prepare_pipes |= 1 << intel_crtc->pipe; |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10494 | } |
| 10495 | |
| 10496 | |
| 10497 | /* set_mode is also used to update properties on life display pipes. */ |
| 10498 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10499 | if (intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10500 | *prepare_pipes |= 1 << intel_crtc->pipe; |
| 10501 | |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 10502 | /* |
| 10503 | * For simplicity do a full modeset on any pipe where the output routing |
| 10504 | * changed. We could be more clever, but that would require us to be |
| 10505 | * more careful with calling the relevant encoder->mode_set functions. |
| 10506 | */ |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10507 | if (*prepare_pipes) |
| 10508 | *modeset_pipes = *prepare_pipes; |
| 10509 | |
| 10510 | /* ... and mask these out. */ |
| 10511 | *modeset_pipes &= ~(*disable_pipes); |
| 10512 | *prepare_pipes &= ~(*disable_pipes); |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 10513 | |
| 10514 | /* |
| 10515 | * HACK: We don't (yet) fully support global modesets. intel_set_config |
| 10516 | * obies this rule, but the modeset restore mode of |
| 10517 | * intel_modeset_setup_hw_state does not. |
| 10518 | */ |
| 10519 | *modeset_pipes &= 1 << intel_crtc->pipe; |
| 10520 | *prepare_pipes &= 1 << intel_crtc->pipe; |
Daniel Vetter | e3641d3 | 2013-04-11 19:49:07 +0200 | [diff] [blame] | 10521 | |
| 10522 | DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n", |
| 10523 | *modeset_pipes, *prepare_pipes, *disable_pipes); |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10524 | } |
| 10525 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10526 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
| 10527 | { |
| 10528 | struct drm_encoder *encoder; |
| 10529 | struct drm_device *dev = crtc->dev; |
| 10530 | |
| 10531 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 10532 | if (encoder->crtc == crtc) |
| 10533 | return true; |
| 10534 | |
| 10535 | return false; |
| 10536 | } |
| 10537 | |
| 10538 | static void |
| 10539 | intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes) |
| 10540 | { |
| 10541 | struct intel_encoder *intel_encoder; |
| 10542 | struct intel_crtc *intel_crtc; |
| 10543 | struct drm_connector *connector; |
| 10544 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10545 | for_each_intel_encoder(dev, intel_encoder) { |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10546 | if (!intel_encoder->base.crtc) |
| 10547 | continue; |
| 10548 | |
| 10549 | intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
| 10550 | |
| 10551 | if (prepare_pipes & (1 << intel_crtc->pipe)) |
| 10552 | intel_encoder->connectors_active = false; |
| 10553 | } |
| 10554 | |
| 10555 | intel_modeset_commit_output_state(dev); |
| 10556 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10557 | /* Double check state. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10558 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10559 | WARN_ON(intel_crtc->base.enabled != intel_crtc_in_use(&intel_crtc->base)); |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 10560 | WARN_ON(intel_crtc->new_config && |
| 10561 | intel_crtc->new_config != &intel_crtc->config); |
| 10562 | WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10563 | } |
| 10564 | |
| 10565 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 10566 | if (!connector->encoder || !connector->encoder->crtc) |
| 10567 | continue; |
| 10568 | |
| 10569 | intel_crtc = to_intel_crtc(connector->encoder->crtc); |
| 10570 | |
| 10571 | if (prepare_pipes & (1 << intel_crtc->pipe)) { |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 10572 | struct drm_property *dpms_property = |
| 10573 | dev->mode_config.dpms_property; |
| 10574 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10575 | connector->dpms = DRM_MODE_DPMS_ON; |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 10576 | drm_object_property_set_value(&connector->base, |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 10577 | dpms_property, |
| 10578 | DRM_MODE_DPMS_ON); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10579 | |
| 10580 | intel_encoder = to_intel_encoder(connector->encoder); |
| 10581 | intel_encoder->connectors_active = true; |
| 10582 | } |
| 10583 | } |
| 10584 | |
| 10585 | } |
| 10586 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 10587 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10588 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 10589 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10590 | |
| 10591 | if (clock1 == clock2) |
| 10592 | return true; |
| 10593 | |
| 10594 | if (!clock1 || !clock2) |
| 10595 | return false; |
| 10596 | |
| 10597 | diff = abs(clock1 - clock2); |
| 10598 | |
| 10599 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 10600 | return true; |
| 10601 | |
| 10602 | return false; |
| 10603 | } |
| 10604 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10605 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 10606 | list_for_each_entry((intel_crtc), \ |
| 10607 | &(dev)->mode_config.crtc_list, \ |
| 10608 | base.head) \ |
Daniel Vetter | 0973f18 | 2013-04-19 11:25:33 +0200 | [diff] [blame] | 10609 | if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10610 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10611 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 10612 | intel_pipe_config_compare(struct drm_device *dev, |
| 10613 | struct intel_crtc_config *current_config, |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10614 | struct intel_crtc_config *pipe_config) |
| 10615 | { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10616 | #define PIPE_CONF_CHECK_X(name) \ |
| 10617 | if (current_config->name != pipe_config->name) { \ |
| 10618 | DRM_ERROR("mismatch in " #name " " \ |
| 10619 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 10620 | current_config->name, \ |
| 10621 | pipe_config->name); \ |
| 10622 | return false; \ |
| 10623 | } |
| 10624 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10625 | #define PIPE_CONF_CHECK_I(name) \ |
| 10626 | if (current_config->name != pipe_config->name) { \ |
| 10627 | DRM_ERROR("mismatch in " #name " " \ |
| 10628 | "(expected %i, found %i)\n", \ |
| 10629 | current_config->name, \ |
| 10630 | pipe_config->name); \ |
| 10631 | return false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 10632 | } |
| 10633 | |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10634 | /* This is required for BDW+ where there is only one set of registers for |
| 10635 | * switching between high and low RR. |
| 10636 | * This macro can be used whenever a comparison has to be made between one |
| 10637 | * hw state and multiple sw state variables. |
| 10638 | */ |
| 10639 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ |
| 10640 | if ((current_config->name != pipe_config->name) && \ |
| 10641 | (current_config->alt_name != pipe_config->name)) { \ |
| 10642 | DRM_ERROR("mismatch in " #name " " \ |
| 10643 | "(expected %i or %i, found %i)\n", \ |
| 10644 | current_config->name, \ |
| 10645 | current_config->alt_name, \ |
| 10646 | pipe_config->name); \ |
| 10647 | return false; \ |
| 10648 | } |
| 10649 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10650 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 10651 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Jesse Barnes | 6f02488 | 2013-07-01 10:19:09 -0700 | [diff] [blame] | 10652 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10653 | "(expected %i, found %i)\n", \ |
| 10654 | current_config->name & (mask), \ |
| 10655 | pipe_config->name & (mask)); \ |
| 10656 | return false; \ |
| 10657 | } |
| 10658 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10659 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 10660 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
| 10661 | DRM_ERROR("mismatch in " #name " " \ |
| 10662 | "(expected %i, found %i)\n", \ |
| 10663 | current_config->name, \ |
| 10664 | pipe_config->name); \ |
| 10665 | return false; \ |
| 10666 | } |
| 10667 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10668 | #define PIPE_CONF_QUIRK(quirk) \ |
| 10669 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 10670 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 10671 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 10672 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10673 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 10674 | PIPE_CONF_CHECK_I(fdi_lanes); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 10675 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
| 10676 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); |
| 10677 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); |
| 10678 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); |
| 10679 | PIPE_CONF_CHECK_I(fdi_m_n.tu); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10680 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10681 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10682 | |
| 10683 | if (INTEL_INFO(dev)->gen < 8) { |
| 10684 | PIPE_CONF_CHECK_I(dp_m_n.gmch_m); |
| 10685 | PIPE_CONF_CHECK_I(dp_m_n.gmch_n); |
| 10686 | PIPE_CONF_CHECK_I(dp_m_n.link_m); |
| 10687 | PIPE_CONF_CHECK_I(dp_m_n.link_n); |
| 10688 | PIPE_CONF_CHECK_I(dp_m_n.tu); |
| 10689 | |
| 10690 | if (current_config->has_drrs) { |
| 10691 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m); |
| 10692 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n); |
| 10693 | PIPE_CONF_CHECK_I(dp_m2_n2.link_m); |
| 10694 | PIPE_CONF_CHECK_I(dp_m2_n2.link_n); |
| 10695 | PIPE_CONF_CHECK_I(dp_m2_n2.tu); |
| 10696 | } |
| 10697 | } else { |
| 10698 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m); |
| 10699 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n); |
| 10700 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m); |
| 10701 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n); |
| 10702 | PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu); |
| 10703 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10704 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10705 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay); |
| 10706 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal); |
| 10707 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start); |
| 10708 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end); |
| 10709 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start); |
| 10710 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end); |
| 10711 | |
| 10712 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay); |
| 10713 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal); |
| 10714 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start); |
| 10715 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end); |
| 10716 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start); |
| 10717 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end); |
| 10718 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 10719 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 10720 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 10721 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
| 10722 | IS_VALLEYVIEW(dev)) |
| 10723 | PIPE_CONF_CHECK_I(limited_color_range); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10724 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 10725 | PIPE_CONF_CHECK_I(has_audio); |
| 10726 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10727 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10728 | DRM_MODE_FLAG_INTERLACE); |
| 10729 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10730 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
| 10731 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10732 | DRM_MODE_FLAG_PHSYNC); |
| 10733 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10734 | DRM_MODE_FLAG_NHSYNC); |
| 10735 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10736 | DRM_MODE_FLAG_PVSYNC); |
| 10737 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10738 | DRM_MODE_FLAG_NVSYNC); |
| 10739 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 10740 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10741 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 10742 | PIPE_CONF_CHECK_I(pipe_src_h); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10743 | |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 10744 | /* |
| 10745 | * FIXME: BIOS likes to set up a cloned config with lvds+external |
| 10746 | * screen. Since we don't yet re-compute the pipe config when moving |
| 10747 | * just the lvds port away to another pipe the sw tracking won't match. |
| 10748 | * |
| 10749 | * Proper atomic modesets with recomputed global state will fix this. |
| 10750 | * Until then just don't check gmch state for inherited modes. |
| 10751 | */ |
| 10752 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) { |
| 10753 | PIPE_CONF_CHECK_I(gmch_pfit.control); |
| 10754 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 10755 | if (INTEL_INFO(dev)->gen < 4) |
| 10756 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
| 10757 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); |
| 10758 | } |
| 10759 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10760 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 10761 | if (current_config->pch_pfit.enabled) { |
| 10762 | PIPE_CONF_CHECK_I(pch_pfit.pos); |
| 10763 | PIPE_CONF_CHECK_I(pch_pfit.size); |
| 10764 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 10765 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 10766 | /* BDW+ don't expose a synchronous way to read the state */ |
| 10767 | if (IS_HASWELL(dev)) |
| 10768 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10769 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 10770 | PIPE_CONF_CHECK_I(double_wide); |
| 10771 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10772 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 10773 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10774 | PIPE_CONF_CHECK_I(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10775 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 10776 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10777 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 10778 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 10779 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10780 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 10781 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 10782 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 10783 | |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 10784 | PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock); |
| 10785 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10786 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10787 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10788 | #undef PIPE_CONF_CHECK_I |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10789 | #undef PIPE_CONF_CHECK_I_ALT |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10790 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10791 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10792 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 10793 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10794 | return true; |
| 10795 | } |
| 10796 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10797 | static void |
| 10798 | check_connector_state(struct drm_device *dev) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10799 | { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10800 | struct intel_connector *connector; |
| 10801 | |
| 10802 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 10803 | base.head) { |
| 10804 | /* This also checks the encoder/connector hw state with the |
| 10805 | * ->get_hw_state callbacks. */ |
| 10806 | intel_connector_check_state(connector); |
| 10807 | |
| 10808 | WARN(&connector->new_encoder->base != connector->base.encoder, |
| 10809 | "connector's staged encoder doesn't match current encoder\n"); |
| 10810 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10811 | } |
| 10812 | |
| 10813 | static void |
| 10814 | check_encoder_state(struct drm_device *dev) |
| 10815 | { |
| 10816 | struct intel_encoder *encoder; |
| 10817 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10818 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10819 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10820 | bool enabled = false; |
| 10821 | bool active = false; |
| 10822 | enum pipe pipe, tracked_pipe; |
| 10823 | |
| 10824 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 10825 | encoder->base.base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10826 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10827 | |
| 10828 | WARN(&encoder->new_crtc->base != encoder->base.crtc, |
| 10829 | "encoder's stage crtc doesn't match current crtc\n"); |
| 10830 | WARN(encoder->connectors_active && !encoder->base.crtc, |
| 10831 | "encoder's active_connectors set, but no crtc\n"); |
| 10832 | |
| 10833 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 10834 | base.head) { |
| 10835 | if (connector->base.encoder != &encoder->base) |
| 10836 | continue; |
| 10837 | enabled = true; |
| 10838 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) |
| 10839 | active = true; |
| 10840 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 10841 | /* |
| 10842 | * for MST connectors if we unplug the connector is gone |
| 10843 | * away but the encoder is still connected to a crtc |
| 10844 | * until a modeset happens in response to the hotplug. |
| 10845 | */ |
| 10846 | if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST) |
| 10847 | continue; |
| 10848 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10849 | WARN(!!encoder->base.crtc != enabled, |
| 10850 | "encoder's enabled state mismatch " |
| 10851 | "(expected %i, found %i)\n", |
| 10852 | !!encoder->base.crtc, enabled); |
| 10853 | WARN(active && !encoder->base.crtc, |
| 10854 | "active encoder with no crtc\n"); |
| 10855 | |
| 10856 | WARN(encoder->connectors_active != active, |
| 10857 | "encoder's computed active state doesn't match tracked active state " |
| 10858 | "(expected %i, found %i)\n", active, encoder->connectors_active); |
| 10859 | |
| 10860 | active = encoder->get_hw_state(encoder, &pipe); |
| 10861 | WARN(active != encoder->connectors_active, |
| 10862 | "encoder's hw state doesn't match sw tracking " |
| 10863 | "(expected %i, found %i)\n", |
| 10864 | encoder->connectors_active, active); |
| 10865 | |
| 10866 | if (!encoder->base.crtc) |
| 10867 | continue; |
| 10868 | |
| 10869 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; |
| 10870 | WARN(active && pipe != tracked_pipe, |
| 10871 | "active encoder's pipe doesn't match" |
| 10872 | "(expected %i, found %i)\n", |
| 10873 | tracked_pipe, pipe); |
| 10874 | |
| 10875 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10876 | } |
| 10877 | |
| 10878 | static void |
| 10879 | check_crtc_state(struct drm_device *dev) |
| 10880 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10881 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10882 | struct intel_crtc *crtc; |
| 10883 | struct intel_encoder *encoder; |
| 10884 | struct intel_crtc_config pipe_config; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10885 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10886 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10887 | bool enabled = false; |
| 10888 | bool active = false; |
| 10889 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 10890 | memset(&pipe_config, 0, sizeof(pipe_config)); |
| 10891 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10892 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 10893 | crtc->base.base.id); |
| 10894 | |
| 10895 | WARN(crtc->active && !crtc->base.enabled, |
| 10896 | "active crtc, but not enabled in sw tracking\n"); |
| 10897 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10898 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10899 | if (encoder->base.crtc != &crtc->base) |
| 10900 | continue; |
| 10901 | enabled = true; |
| 10902 | if (encoder->connectors_active) |
| 10903 | active = true; |
| 10904 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10905 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10906 | WARN(active != crtc->active, |
| 10907 | "crtc's computed active state doesn't match tracked active state " |
| 10908 | "(expected %i, found %i)\n", active, crtc->active); |
| 10909 | WARN(enabled != crtc->base.enabled, |
| 10910 | "crtc's computed enabled state doesn't match tracked enabled state " |
| 10911 | "(expected %i, found %i)\n", enabled, crtc->base.enabled); |
| 10912 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10913 | active = dev_priv->display.get_pipe_config(crtc, |
| 10914 | &pipe_config); |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 10915 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 10916 | /* hw state is inconsistent with the pipe quirk */ |
| 10917 | if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 10918 | (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 10919 | active = crtc->active; |
| 10920 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10921 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 3eaba51 | 2013-08-05 17:57:48 +0300 | [diff] [blame] | 10922 | enum pipe pipe; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10923 | if (encoder->base.crtc != &crtc->base) |
| 10924 | continue; |
Daniel Vetter | 1d37b68 | 2013-11-18 09:00:59 +0100 | [diff] [blame] | 10925 | if (encoder->get_hw_state(encoder, &pipe)) |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10926 | encoder->get_config(encoder, &pipe_config); |
| 10927 | } |
| 10928 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10929 | WARN(crtc->active != active, |
| 10930 | "crtc active state doesn't match with hw state " |
| 10931 | "(expected %i, found %i)\n", crtc->active, active); |
| 10932 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10933 | if (active && |
| 10934 | !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) { |
| 10935 | WARN(1, "pipe state doesn't match!\n"); |
| 10936 | intel_dump_pipe_config(crtc, &pipe_config, |
| 10937 | "[hw state]"); |
| 10938 | intel_dump_pipe_config(crtc, &crtc->config, |
| 10939 | "[sw state]"); |
| 10940 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10941 | } |
| 10942 | } |
| 10943 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10944 | static void |
| 10945 | check_shared_dpll_state(struct drm_device *dev) |
| 10946 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10947 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10948 | struct intel_crtc *crtc; |
| 10949 | struct intel_dpll_hw_state dpll_hw_state; |
| 10950 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 10951 | |
| 10952 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 10953 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 10954 | int enabled_crtcs = 0, active_crtcs = 0; |
| 10955 | bool active; |
| 10956 | |
| 10957 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 10958 | |
| 10959 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 10960 | |
| 10961 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 10962 | |
| 10963 | WARN(pll->active > pll->refcount, |
| 10964 | "more active pll users than references: %i vs %i\n", |
| 10965 | pll->active, pll->refcount); |
| 10966 | WARN(pll->active && !pll->on, |
| 10967 | "pll in active use but not on in sw tracking\n"); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 10968 | WARN(pll->on && !pll->active, |
| 10969 | "pll in on but not on in use in sw tracking\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 10970 | WARN(pll->on != active, |
| 10971 | "pll on state mismatch (expected %i, found %i)\n", |
| 10972 | pll->on, active); |
| 10973 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10974 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 10975 | if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll) |
| 10976 | enabled_crtcs++; |
| 10977 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 10978 | active_crtcs++; |
| 10979 | } |
| 10980 | WARN(pll->active != active_crtcs, |
| 10981 | "pll active crtcs mismatch (expected %i, found %i)\n", |
| 10982 | pll->active, active_crtcs); |
| 10983 | WARN(pll->refcount != enabled_crtcs, |
| 10984 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
| 10985 | pll->refcount, enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10986 | |
| 10987 | WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state, |
| 10988 | sizeof(dpll_hw_state)), |
| 10989 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 10990 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 10991 | } |
| 10992 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10993 | void |
| 10994 | intel_modeset_check_state(struct drm_device *dev) |
| 10995 | { |
| 10996 | check_connector_state(dev); |
| 10997 | check_encoder_state(dev); |
| 10998 | check_crtc_state(dev); |
| 10999 | check_shared_dpll_state(dev); |
| 11000 | } |
| 11001 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11002 | void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config, |
| 11003 | int dotclock) |
| 11004 | { |
| 11005 | /* |
| 11006 | * FDI already provided one idea for the dotclock. |
| 11007 | * Yell if the encoder disagrees. |
| 11008 | */ |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11009 | WARN(!intel_fuzzy_clock_check(pipe_config->adjusted_mode.crtc_clock, dotclock), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11010 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 11011 | pipe_config->adjusted_mode.crtc_clock, dotclock); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11012 | } |
| 11013 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11014 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 11015 | { |
| 11016 | struct drm_device *dev = crtc->base.dev; |
| 11017 | |
| 11018 | /* |
| 11019 | * The scanline counter increments at the leading edge of hsync. |
| 11020 | * |
| 11021 | * On most platforms it starts counting from vtotal-1 on the |
| 11022 | * first active line. That means the scanline counter value is |
| 11023 | * always one less than what we would expect. Ie. just after |
| 11024 | * start of vblank, which also occurs at start of hsync (on the |
| 11025 | * last active line), the scanline counter will read vblank_start-1. |
| 11026 | * |
| 11027 | * On gen2 the scanline counter starts counting from 1 instead |
| 11028 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 11029 | * to keep the value positive), instead of adding one. |
| 11030 | * |
| 11031 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 11032 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 11033 | * there's an extra 1 line difference. So we need to add two instead of |
| 11034 | * one to the value. |
| 11035 | */ |
| 11036 | if (IS_GEN2(dev)) { |
| 11037 | const struct drm_display_mode *mode = &crtc->config.adjusted_mode; |
| 11038 | int vtotal; |
| 11039 | |
| 11040 | vtotal = mode->crtc_vtotal; |
| 11041 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 11042 | vtotal /= 2; |
| 11043 | |
| 11044 | crtc->scanline_offset = vtotal - 1; |
| 11045 | } else if (HAS_DDI(dev) && |
| 11046 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) { |
| 11047 | crtc->scanline_offset = 2; |
| 11048 | } else |
| 11049 | crtc->scanline_offset = 1; |
| 11050 | } |
| 11051 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11052 | static int __intel_set_mode(struct drm_crtc *crtc, |
| 11053 | struct drm_display_mode *mode, |
| 11054 | int x, int y, struct drm_framebuffer *fb) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11055 | { |
| 11056 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11057 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11058 | struct drm_display_mode *saved_mode; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11059 | struct intel_crtc_config *pipe_config = NULL; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11060 | struct intel_crtc *intel_crtc; |
| 11061 | unsigned disable_pipes, prepare_pipes, modeset_pipes; |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11062 | int ret = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11063 | |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11064 | saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11065 | if (!saved_mode) |
| 11066 | return -ENOMEM; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11067 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 11068 | intel_modeset_affected_pipes(crtc, &modeset_pipes, |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11069 | &prepare_pipes, &disable_pipes); |
| 11070 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11071 | *saved_mode = crtc->mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11072 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11073 | /* Hack: Because we don't (yet) support global modeset on multiple |
| 11074 | * crtcs, we don't keep track of the new mode for more than one crtc. |
| 11075 | * Hence simply check whether any bit is set in modeset_pipes in all the |
| 11076 | * pieces of code that are not yet converted to deal with mutliple crtcs |
| 11077 | * changing their mode at the same time. */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11078 | if (modeset_pipes) { |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 11079 | pipe_config = intel_modeset_pipe_config(crtc, fb, mode); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11080 | if (IS_ERR(pipe_config)) { |
| 11081 | ret = PTR_ERR(pipe_config); |
| 11082 | pipe_config = NULL; |
| 11083 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11084 | goto out; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11085 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11086 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 11087 | "[modeset]"); |
Ville Syrjälä | 50741ab | 2014-01-10 11:28:07 +0200 | [diff] [blame] | 11088 | to_intel_crtc(crtc)->new_config = pipe_config; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11089 | } |
| 11090 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 11091 | /* |
| 11092 | * See if the config requires any additional preparation, e.g. |
| 11093 | * to adjust global state with pipes off. We need to do this |
| 11094 | * here so we can get the modeset_pipe updated config for the new |
| 11095 | * mode set on this crtc. For other crtcs we need to use the |
| 11096 | * adjusted_mode bits in the crtc directly. |
| 11097 | */ |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 11098 | if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 11099 | valleyview_modeset_global_pipes(dev, &prepare_pipes); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 11100 | |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 11101 | /* may have added more to prepare_pipes than we should */ |
| 11102 | prepare_pipes &= ~disable_pipes; |
| 11103 | } |
| 11104 | |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 11105 | for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc) |
| 11106 | intel_crtc_disable(&intel_crtc->base); |
| 11107 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11108 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
| 11109 | if (intel_crtc->base.enabled) |
| 11110 | dev_priv->display.crtc_disable(&intel_crtc->base); |
| 11111 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11112 | |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 11113 | /* crtc->mode is already used by the ->mode_set callbacks, hence we need |
| 11114 | * to set it here already despite that we pass it down the callchain. |
| 11115 | */ |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11116 | if (modeset_pipes) { |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11117 | crtc->mode = *mode; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11118 | /* mode_set/enable/disable functions rely on a correct pipe |
| 11119 | * config. */ |
| 11120 | to_intel_crtc(crtc)->config = *pipe_config; |
Ville Syrjälä | 50741ab | 2014-01-10 11:28:07 +0200 | [diff] [blame] | 11121 | to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config; |
Ville Syrjälä | c326c0a | 2013-10-28 12:53:41 +0200 | [diff] [blame] | 11122 | |
| 11123 | /* |
| 11124 | * Calculate and store various constants which |
| 11125 | * are later needed by vblank and swap-completion |
| 11126 | * timestamping. They are derived from true hwmode. |
| 11127 | */ |
| 11128 | drm_calc_timestamping_constants(crtc, |
| 11129 | &pipe_config->adjusted_mode); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11130 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11131 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11132 | /* Only after disabling all output pipelines that will be changed can we |
| 11133 | * update the the output configuration. */ |
| 11134 | intel_modeset_update_state(dev, prepare_pipes); |
| 11135 | |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 11136 | if (dev_priv->display.modeset_global_resources) |
| 11137 | dev_priv->display.modeset_global_resources(dev); |
| 11138 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11139 | /* Set up the DPLL and any encoders state that needs to adjust or depend |
| 11140 | * on the DPLL. |
| 11141 | */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11142 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11143 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
| 11144 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb); |
| 11145 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Daniel Vetter | 4c10794 | 2014-04-24 23:55:05 +0200 | [diff] [blame] | 11146 | |
| 11147 | mutex_lock(&dev->struct_mutex); |
| 11148 | ret = intel_pin_and_fence_fb_obj(dev, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11149 | obj, |
Daniel Vetter | 4c10794 | 2014-04-24 23:55:05 +0200 | [diff] [blame] | 11150 | NULL); |
| 11151 | if (ret != 0) { |
| 11152 | DRM_ERROR("pin & fence failed\n"); |
| 11153 | mutex_unlock(&dev->struct_mutex); |
| 11154 | goto done; |
| 11155 | } |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11156 | if (old_fb) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11157 | intel_unpin_fb_obj(old_obj); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11158 | i915_gem_track_fb(old_obj, obj, |
| 11159 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe)); |
Daniel Vetter | 4c10794 | 2014-04-24 23:55:05 +0200 | [diff] [blame] | 11160 | mutex_unlock(&dev->struct_mutex); |
| 11161 | |
| 11162 | crtc->primary->fb = fb; |
| 11163 | crtc->x = x; |
| 11164 | crtc->y = y; |
| 11165 | |
Daniel Vetter | 4271b75 | 2014-04-24 23:55:00 +0200 | [diff] [blame] | 11166 | ret = dev_priv->display.crtc_mode_set(&intel_crtc->base, |
| 11167 | x, y, fb); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11168 | if (ret) |
| 11169 | goto done; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11170 | } |
| 11171 | |
| 11172 | /* Now enable the clocks, plane, pipe, and connectors that we set up. */ |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11173 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
| 11174 | update_scanline_offset(intel_crtc); |
| 11175 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11176 | dev_priv->display.crtc_enable(&intel_crtc->base); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11177 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11178 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11179 | /* FIXME: add subpixel order */ |
| 11180 | done: |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11181 | if (ret && crtc->enabled) |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11182 | crtc->mode = *saved_mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11183 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11184 | out: |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11185 | kfree(pipe_config); |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11186 | kfree(saved_mode); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11187 | return ret; |
| 11188 | } |
| 11189 | |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 11190 | static int intel_set_mode(struct drm_crtc *crtc, |
| 11191 | struct drm_display_mode *mode, |
| 11192 | int x, int y, struct drm_framebuffer *fb) |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11193 | { |
| 11194 | int ret; |
| 11195 | |
| 11196 | ret = __intel_set_mode(crtc, mode, x, y, fb); |
| 11197 | |
| 11198 | if (ret == 0) |
| 11199 | intel_modeset_check_state(crtc->dev); |
| 11200 | |
| 11201 | return ret; |
| 11202 | } |
| 11203 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11204 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 11205 | { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11206 | intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11207 | } |
| 11208 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11209 | #undef for_each_intel_crtc_masked |
| 11210 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11211 | static void intel_set_config_free(struct intel_set_config *config) |
| 11212 | { |
| 11213 | if (!config) |
| 11214 | return; |
| 11215 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11216 | kfree(config->save_connector_encoders); |
| 11217 | kfree(config->save_encoder_crtcs); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11218 | kfree(config->save_crtc_enabled); |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11219 | kfree(config); |
| 11220 | } |
| 11221 | |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11222 | static int intel_set_config_save_state(struct drm_device *dev, |
| 11223 | struct intel_set_config *config) |
| 11224 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11225 | struct drm_crtc *crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11226 | struct drm_encoder *encoder; |
| 11227 | struct drm_connector *connector; |
| 11228 | int count; |
| 11229 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11230 | config->save_crtc_enabled = |
| 11231 | kcalloc(dev->mode_config.num_crtc, |
| 11232 | sizeof(bool), GFP_KERNEL); |
| 11233 | if (!config->save_crtc_enabled) |
| 11234 | return -ENOMEM; |
| 11235 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11236 | config->save_encoder_crtcs = |
| 11237 | kcalloc(dev->mode_config.num_encoder, |
| 11238 | sizeof(struct drm_crtc *), GFP_KERNEL); |
| 11239 | if (!config->save_encoder_crtcs) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11240 | return -ENOMEM; |
| 11241 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11242 | config->save_connector_encoders = |
| 11243 | kcalloc(dev->mode_config.num_connector, |
| 11244 | sizeof(struct drm_encoder *), GFP_KERNEL); |
| 11245 | if (!config->save_connector_encoders) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11246 | return -ENOMEM; |
| 11247 | |
| 11248 | /* Copy data. Note that driver private data is not affected. |
| 11249 | * Should anything bad happen only the expected state is |
| 11250 | * restored, not the drivers personal bookkeeping. |
| 11251 | */ |
| 11252 | count = 0; |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 11253 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11254 | config->save_crtc_enabled[count++] = crtc->enabled; |
| 11255 | } |
| 11256 | |
| 11257 | count = 0; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11258 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11259 | config->save_encoder_crtcs[count++] = encoder->crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11260 | } |
| 11261 | |
| 11262 | count = 0; |
| 11263 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11264 | config->save_connector_encoders[count++] = connector->encoder; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11265 | } |
| 11266 | |
| 11267 | return 0; |
| 11268 | } |
| 11269 | |
| 11270 | static void intel_set_config_restore_state(struct drm_device *dev, |
| 11271 | struct intel_set_config *config) |
| 11272 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11273 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11274 | struct intel_encoder *encoder; |
| 11275 | struct intel_connector *connector; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11276 | int count; |
| 11277 | |
| 11278 | count = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11279 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11280 | crtc->new_enabled = config->save_crtc_enabled[count++]; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11281 | |
| 11282 | if (crtc->new_enabled) |
| 11283 | crtc->new_config = &crtc->config; |
| 11284 | else |
| 11285 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11286 | } |
| 11287 | |
| 11288 | count = 0; |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11289 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11290 | encoder->new_crtc = |
| 11291 | to_intel_crtc(config->save_encoder_crtcs[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11292 | } |
| 11293 | |
| 11294 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11295 | list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) { |
| 11296 | connector->new_encoder = |
| 11297 | to_intel_encoder(config->save_connector_encoders[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11298 | } |
| 11299 | } |
| 11300 | |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11301 | static bool |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11302 | is_crtc_connector_off(struct drm_mode_set *set) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11303 | { |
| 11304 | int i; |
| 11305 | |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11306 | if (set->num_connectors == 0) |
| 11307 | return false; |
| 11308 | |
| 11309 | if (WARN_ON(set->connectors == NULL)) |
| 11310 | return false; |
| 11311 | |
| 11312 | for (i = 0; i < set->num_connectors; i++) |
| 11313 | if (set->connectors[i]->encoder && |
| 11314 | set->connectors[i]->encoder->crtc == set->crtc && |
| 11315 | set->connectors[i]->dpms != DRM_MODE_DPMS_ON) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11316 | return true; |
| 11317 | |
| 11318 | return false; |
| 11319 | } |
| 11320 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11321 | static void |
| 11322 | intel_set_config_compute_mode_changes(struct drm_mode_set *set, |
| 11323 | struct intel_set_config *config) |
| 11324 | { |
| 11325 | |
| 11326 | /* We should be able to check here if the fb has the same properties |
| 11327 | * and then just flip_or_move it */ |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11328 | if (is_crtc_connector_off(set)) { |
| 11329 | config->mode_changed = true; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11330 | } else if (set->crtc->primary->fb != set->fb) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11331 | /* |
| 11332 | * If we have no fb, we can only flip as long as the crtc is |
| 11333 | * active, otherwise we need a full mode set. The crtc may |
| 11334 | * be active if we've only disabled the primary plane, or |
| 11335 | * in fastboot situations. |
| 11336 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11337 | if (set->crtc->primary->fb == NULL) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 11338 | struct intel_crtc *intel_crtc = |
| 11339 | to_intel_crtc(set->crtc); |
| 11340 | |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11341 | if (intel_crtc->active) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 11342 | DRM_DEBUG_KMS("crtc has no fb, will flip\n"); |
| 11343 | config->fb_changed = true; |
| 11344 | } else { |
| 11345 | DRM_DEBUG_KMS("inactive crtc, full mode set\n"); |
| 11346 | config->mode_changed = true; |
| 11347 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11348 | } else if (set->fb == NULL) { |
| 11349 | config->mode_changed = true; |
Daniel Vetter | 72f4901 | 2013-03-28 16:01:35 +0100 | [diff] [blame] | 11350 | } else if (set->fb->pixel_format != |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11351 | set->crtc->primary->fb->pixel_format) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11352 | config->mode_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11353 | } else { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11354 | config->fb_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11355 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11356 | } |
| 11357 | |
Daniel Vetter | 835c587 | 2012-07-10 18:11:08 +0200 | [diff] [blame] | 11358 | 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] | 11359 | config->fb_changed = true; |
| 11360 | |
| 11361 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
| 11362 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
| 11363 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 11364 | drm_mode_debug_printmodeline(set->mode); |
| 11365 | config->mode_changed = true; |
| 11366 | } |
Chris Wilson | a1d9570 | 2013-08-13 18:48:47 +0100 | [diff] [blame] | 11367 | |
| 11368 | DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n", |
| 11369 | set->crtc->base.id, config->mode_changed, config->fb_changed); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11370 | } |
| 11371 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11372 | static int |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11373 | intel_modeset_stage_output_state(struct drm_device *dev, |
| 11374 | struct drm_mode_set *set, |
| 11375 | struct intel_set_config *config) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11376 | { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11377 | struct intel_connector *connector; |
| 11378 | struct intel_encoder *encoder; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11379 | struct intel_crtc *crtc; |
Paulo Zanoni | f3f0857 | 2013-08-12 14:56:53 -0300 | [diff] [blame] | 11380 | int ro; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11381 | |
Damien Lespiau | 9abdda7 | 2013-02-13 13:29:23 +0000 | [diff] [blame] | 11382 | /* 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] | 11383 | * of connectors. For paranoia, double-check this. */ |
| 11384 | WARN_ON(!set->fb && (set->num_connectors != 0)); |
| 11385 | WARN_ON(set->fb && (set->num_connectors == 0)); |
| 11386 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11387 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 11388 | base.head) { |
| 11389 | /* Otherwise traverse passed in connector list and get encoders |
| 11390 | * for them. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11391 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11392 | if (set->connectors[ro] == &connector->base) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11393 | connector->new_encoder = intel_find_encoder(connector, to_intel_crtc(set->crtc)->pipe); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11394 | break; |
| 11395 | } |
| 11396 | } |
| 11397 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11398 | /* If we disable the crtc, disable all its connectors. Also, if |
| 11399 | * the connector is on the changing crtc but not on the new |
| 11400 | * connector list, disable it. */ |
| 11401 | if ((!set->fb || ro == set->num_connectors) && |
| 11402 | connector->base.encoder && |
| 11403 | connector->base.encoder->crtc == set->crtc) { |
| 11404 | connector->new_encoder = NULL; |
| 11405 | |
| 11406 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", |
| 11407 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11408 | connector->base.name); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11409 | } |
| 11410 | |
| 11411 | |
| 11412 | if (&connector->new_encoder->base != connector->base.encoder) { |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11413 | DRM_DEBUG_KMS("encoder changed, full mode switch\n"); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11414 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11415 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11416 | } |
| 11417 | /* connector->new_encoder is now updated for all connectors. */ |
| 11418 | |
| 11419 | /* Update crtc of enabled connectors. */ |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11420 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 11421 | base.head) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11422 | struct drm_crtc *new_crtc; |
| 11423 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11424 | if (!connector->new_encoder) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11425 | continue; |
| 11426 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11427 | new_crtc = connector->new_encoder->base.crtc; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11428 | |
| 11429 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11430 | if (set->connectors[ro] == &connector->base) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11431 | new_crtc = set->crtc; |
| 11432 | } |
| 11433 | |
| 11434 | /* Make sure the new CRTC will work with the encoder */ |
Thierry Reding | 1450991 | 2014-01-13 12:00:22 +0100 | [diff] [blame] | 11435 | if (!drm_encoder_crtc_ok(&connector->new_encoder->base, |
| 11436 | new_crtc)) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11437 | return -EINVAL; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11438 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11439 | connector->new_encoder->new_crtc = to_intel_crtc(new_crtc); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11440 | |
| 11441 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
| 11442 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11443 | connector->base.name, |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11444 | new_crtc->base.id); |
| 11445 | } |
| 11446 | |
| 11447 | /* Check for any encoders that needs to be disabled. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11448 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11449 | int num_connectors = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11450 | list_for_each_entry(connector, |
| 11451 | &dev->mode_config.connector_list, |
| 11452 | base.head) { |
| 11453 | if (connector->new_encoder == encoder) { |
| 11454 | WARN_ON(!connector->new_encoder->new_crtc); |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11455 | num_connectors++; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11456 | } |
| 11457 | } |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11458 | |
| 11459 | if (num_connectors == 0) |
| 11460 | encoder->new_crtc = NULL; |
| 11461 | else if (num_connectors > 1) |
| 11462 | return -EINVAL; |
| 11463 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11464 | /* Only now check for crtc changes so we don't miss encoders |
| 11465 | * that will be disabled. */ |
| 11466 | if (&encoder->new_crtc->base != encoder->base.crtc) { |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11467 | DRM_DEBUG_KMS("crtc changed, full mode switch\n"); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11468 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11469 | } |
| 11470 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11471 | /* Now we've also updated encoder->new_crtc for all encoders. */ |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11472 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 11473 | base.head) { |
| 11474 | if (connector->new_encoder) |
| 11475 | if (connector->new_encoder != connector->encoder) |
| 11476 | connector->encoder = connector->new_encoder; |
| 11477 | } |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11478 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11479 | crtc->new_enabled = false; |
| 11480 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11481 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11482 | if (encoder->new_crtc == crtc) { |
| 11483 | crtc->new_enabled = true; |
| 11484 | break; |
| 11485 | } |
| 11486 | } |
| 11487 | |
| 11488 | if (crtc->new_enabled != crtc->base.enabled) { |
| 11489 | DRM_DEBUG_KMS("crtc %sabled, full mode switch\n", |
| 11490 | crtc->new_enabled ? "en" : "dis"); |
| 11491 | config->mode_changed = true; |
| 11492 | } |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11493 | |
| 11494 | if (crtc->new_enabled) |
| 11495 | crtc->new_config = &crtc->config; |
| 11496 | else |
| 11497 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11498 | } |
| 11499 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11500 | return 0; |
| 11501 | } |
| 11502 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11503 | static void disable_crtc_nofb(struct intel_crtc *crtc) |
| 11504 | { |
| 11505 | struct drm_device *dev = crtc->base.dev; |
| 11506 | struct intel_encoder *encoder; |
| 11507 | struct intel_connector *connector; |
| 11508 | |
| 11509 | DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n", |
| 11510 | pipe_name(crtc->pipe)); |
| 11511 | |
| 11512 | list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) { |
| 11513 | if (connector->new_encoder && |
| 11514 | connector->new_encoder->new_crtc == crtc) |
| 11515 | connector->new_encoder = NULL; |
| 11516 | } |
| 11517 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11518 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11519 | if (encoder->new_crtc == crtc) |
| 11520 | encoder->new_crtc = NULL; |
| 11521 | } |
| 11522 | |
| 11523 | crtc->new_enabled = false; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11524 | crtc->new_config = NULL; |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11525 | } |
| 11526 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11527 | static int intel_crtc_set_config(struct drm_mode_set *set) |
| 11528 | { |
| 11529 | struct drm_device *dev; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11530 | struct drm_mode_set save_set; |
| 11531 | struct intel_set_config *config; |
| 11532 | int ret; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11533 | |
Daniel Vetter | 8d3e375 | 2012-07-05 16:09:09 +0200 | [diff] [blame] | 11534 | BUG_ON(!set); |
| 11535 | BUG_ON(!set->crtc); |
| 11536 | BUG_ON(!set->crtc->helper_private); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11537 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 11538 | /* Enforce sane interface api - has been abused by the fb helper. */ |
| 11539 | BUG_ON(!set->mode && set->fb); |
| 11540 | BUG_ON(set->fb && set->num_connectors == 0); |
Daniel Vetter | 431e50f | 2012-07-10 17:53:42 +0200 | [diff] [blame] | 11541 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11542 | if (set->fb) { |
| 11543 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", |
| 11544 | set->crtc->base.id, set->fb->base.id, |
| 11545 | (int)set->num_connectors, set->x, set->y); |
| 11546 | } else { |
| 11547 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11548 | } |
| 11549 | |
| 11550 | dev = set->crtc->dev; |
| 11551 | |
| 11552 | ret = -ENOMEM; |
| 11553 | config = kzalloc(sizeof(*config), GFP_KERNEL); |
| 11554 | if (!config) |
| 11555 | goto out_config; |
| 11556 | |
| 11557 | ret = intel_set_config_save_state(dev, config); |
| 11558 | if (ret) |
| 11559 | goto out_config; |
| 11560 | |
| 11561 | save_set.crtc = set->crtc; |
| 11562 | save_set.mode = &set->crtc->mode; |
| 11563 | save_set.x = set->crtc->x; |
| 11564 | save_set.y = set->crtc->y; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11565 | save_set.fb = set->crtc->primary->fb; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11566 | |
| 11567 | /* Compute whether we need a full modeset, only an fb base update or no |
| 11568 | * change at all. In the future we might also check whether only the |
| 11569 | * mode changed, e.g. for LVDS where we only change the panel fitter in |
| 11570 | * such cases. */ |
| 11571 | intel_set_config_compute_mode_changes(set, config); |
| 11572 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11573 | ret = intel_modeset_stage_output_state(dev, set, config); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11574 | if (ret) |
| 11575 | goto fail; |
| 11576 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11577 | if (config->mode_changed) { |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11578 | ret = intel_set_mode(set->crtc, set->mode, |
| 11579 | set->x, set->y, set->fb); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11580 | } else if (config->fb_changed) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11581 | struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc); |
| 11582 | |
Ville Syrjälä | 4878cae | 2013-02-18 19:08:48 +0200 | [diff] [blame] | 11583 | intel_crtc_wait_for_pending_flips(set->crtc); |
| 11584 | |
Daniel Vetter | 4f660f4 | 2012-07-02 09:47:37 +0200 | [diff] [blame] | 11585 | ret = intel_pipe_set_base(set->crtc, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 11586 | set->x, set->y, set->fb); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11587 | |
| 11588 | /* |
| 11589 | * We need to make sure the primary plane is re-enabled if it |
| 11590 | * has previously been turned off. |
| 11591 | */ |
| 11592 | if (!intel_crtc->primary_enabled && ret == 0) { |
| 11593 | WARN_ON(!intel_crtc->active); |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 11594 | intel_enable_primary_hw_plane(set->crtc->primary, set->crtc); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11595 | } |
| 11596 | |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 11597 | /* |
| 11598 | * In the fastboot case this may be our only check of the |
| 11599 | * state after boot. It would be better to only do it on |
| 11600 | * the first update, but we don't have a nice way of doing that |
| 11601 | * (and really, set_config isn't used much for high freq page |
| 11602 | * flipping, so increasing its cost here shouldn't be a big |
| 11603 | * deal). |
| 11604 | */ |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 11605 | if (i915.fastboot && ret == 0) |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 11606 | intel_modeset_check_state(set->crtc->dev); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11607 | } |
| 11608 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 11609 | if (ret) { |
Daniel Vetter | bf67dfe | 2013-06-25 11:06:52 +0200 | [diff] [blame] | 11610 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
| 11611 | set->crtc->base.id, ret); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11612 | fail: |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 11613 | intel_set_config_restore_state(dev, config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11614 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11615 | /* |
| 11616 | * HACK: if the pipe was on, but we didn't have a framebuffer, |
| 11617 | * force the pipe off to avoid oopsing in the modeset code |
| 11618 | * due to fb==NULL. This should only happen during boot since |
| 11619 | * we don't yet reconstruct the FB from the hardware state. |
| 11620 | */ |
| 11621 | if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb) |
| 11622 | disable_crtc_nofb(to_intel_crtc(save_set.crtc)); |
| 11623 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 11624 | /* Try to restore the config */ |
| 11625 | if (config->mode_changed && |
| 11626 | intel_set_mode(save_set.crtc, save_set.mode, |
| 11627 | save_set.x, save_set.y, save_set.fb)) |
| 11628 | DRM_ERROR("failed to restore config after modeset failure\n"); |
| 11629 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11630 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11631 | out_config: |
| 11632 | intel_set_config_free(config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11633 | return ret; |
| 11634 | } |
| 11635 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11636 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11637 | .gamma_set = intel_crtc_gamma_set, |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11638 | .set_config = intel_crtc_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11639 | .destroy = intel_crtc_destroy, |
| 11640 | .page_flip = intel_crtc_page_flip, |
| 11641 | }; |
| 11642 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11643 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
| 11644 | struct intel_shared_dpll *pll, |
| 11645 | struct intel_dpll_hw_state *hw_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11646 | { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11647 | uint32_t val; |
| 11648 | |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 11649 | if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
| 11650 | return false; |
| 11651 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11652 | val = I915_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11653 | hw_state->dpll = val; |
| 11654 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); |
| 11655 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11656 | |
| 11657 | return val & DPLL_VCO_ENABLE; |
| 11658 | } |
| 11659 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11660 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
| 11661 | struct intel_shared_dpll *pll) |
| 11662 | { |
| 11663 | I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0); |
| 11664 | I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1); |
| 11665 | } |
| 11666 | |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11667 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
| 11668 | struct intel_shared_dpll *pll) |
| 11669 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11670 | /* PCH refclock must be enabled first */ |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 11671 | ibx_assert_pch_refclk_enabled(dev_priv); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11672 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11673 | I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll); |
| 11674 | |
| 11675 | /* Wait for the clocks to stabilize. */ |
| 11676 | POSTING_READ(PCH_DPLL(pll->id)); |
| 11677 | udelay(150); |
| 11678 | |
| 11679 | /* The pixel multiplier can only be updated once the |
| 11680 | * DPLL is enabled and the clocks are stable. |
| 11681 | * |
| 11682 | * So write it again. |
| 11683 | */ |
| 11684 | I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll); |
| 11685 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11686 | udelay(200); |
| 11687 | } |
| 11688 | |
| 11689 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, |
| 11690 | struct intel_shared_dpll *pll) |
| 11691 | { |
| 11692 | struct drm_device *dev = dev_priv->dev; |
| 11693 | struct intel_crtc *crtc; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11694 | |
| 11695 | /* Make sure no transcoder isn't still depending on us. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11696 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11697 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
| 11698 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); |
| 11699 | } |
| 11700 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11701 | I915_WRITE(PCH_DPLL(pll->id), 0); |
| 11702 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11703 | udelay(200); |
| 11704 | } |
| 11705 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 11706 | static char *ibx_pch_dpll_names[] = { |
| 11707 | "PCH DPLL A", |
| 11708 | "PCH DPLL B", |
| 11709 | }; |
| 11710 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11711 | static void ibx_pch_dpll_init(struct drm_device *dev) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11712 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11713 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11714 | int i; |
| 11715 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11716 | dev_priv->num_shared_dpll = 2; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11717 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 11718 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 11719 | dev_priv->shared_dplls[i].id = i; |
| 11720 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11721 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11722 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
| 11723 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11724 | dev_priv->shared_dplls[i].get_hw_state = |
| 11725 | ibx_pch_dpll_get_hw_state; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11726 | } |
| 11727 | } |
| 11728 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11729 | static void intel_shared_dpll_init(struct drm_device *dev) |
| 11730 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11731 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11732 | |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 11733 | if (HAS_DDI(dev)) |
| 11734 | intel_ddi_pll_init(dev); |
| 11735 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11736 | ibx_pch_dpll_init(dev); |
| 11737 | else |
| 11738 | dev_priv->num_shared_dpll = 0; |
| 11739 | |
| 11740 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11741 | } |
| 11742 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11743 | static int |
| 11744 | intel_primary_plane_disable(struct drm_plane *plane) |
| 11745 | { |
| 11746 | struct drm_device *dev = plane->dev; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11747 | struct intel_crtc *intel_crtc; |
| 11748 | |
| 11749 | if (!plane->fb) |
| 11750 | return 0; |
| 11751 | |
| 11752 | BUG_ON(!plane->crtc); |
| 11753 | |
| 11754 | intel_crtc = to_intel_crtc(plane->crtc); |
| 11755 | |
| 11756 | /* |
| 11757 | * Even though we checked plane->fb above, it's still possible that |
| 11758 | * the primary plane has been implicitly disabled because the crtc |
| 11759 | * coordinates given weren't visible, or because we detected |
| 11760 | * that it was 100% covered by a sprite plane. Or, the CRTC may be |
| 11761 | * off and we've set a fb, but haven't actually turned on the CRTC yet. |
| 11762 | * In either case, we need to unpin the FB and let the fb pointer get |
| 11763 | * updated, but otherwise we don't need to touch the hardware. |
| 11764 | */ |
| 11765 | if (!intel_crtc->primary_enabled) |
| 11766 | goto disable_unpin; |
| 11767 | |
| 11768 | intel_crtc_wait_for_pending_flips(plane->crtc); |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 11769 | intel_disable_primary_hw_plane(plane, plane->crtc); |
| 11770 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11771 | disable_unpin: |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11772 | mutex_lock(&dev->struct_mutex); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11773 | i915_gem_track_fb(intel_fb_obj(plane->fb), NULL, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11774 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe)); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11775 | intel_unpin_fb_obj(intel_fb_obj(plane->fb)); |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11776 | mutex_unlock(&dev->struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11777 | plane->fb = NULL; |
| 11778 | |
| 11779 | return 0; |
| 11780 | } |
| 11781 | |
| 11782 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 11783 | intel_check_primary_plane(struct drm_plane *plane, |
| 11784 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11785 | { |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 11786 | struct drm_crtc *crtc = state->crtc; |
| 11787 | struct drm_framebuffer *fb = state->fb; |
| 11788 | struct drm_rect *dest = &state->dst; |
| 11789 | struct drm_rect *src = &state->src; |
| 11790 | const struct drm_rect *clip = &state->clip; |
| 11791 | |
| 11792 | return drm_plane_helper_check_update(plane, crtc, fb, |
| 11793 | src, dest, clip, |
| 11794 | DRM_PLANE_HELPER_NO_SCALING, |
| 11795 | DRM_PLANE_HELPER_NO_SCALING, |
| 11796 | false, true, &state->visible); |
| 11797 | } |
| 11798 | |
| 11799 | static int |
| 11800 | intel_commit_primary_plane(struct drm_plane *plane, |
| 11801 | struct intel_plane_state *state) |
| 11802 | { |
| 11803 | struct drm_crtc *crtc = state->crtc; |
| 11804 | struct drm_framebuffer *fb = state->fb; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11805 | struct drm_device *dev = crtc->dev; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11806 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11807 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11808 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 11809 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 11810 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 11811 | struct drm_rect *src = &state->src; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11812 | int ret; |
| 11813 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11814 | intel_crtc_wait_for_pending_flips(crtc); |
| 11815 | |
| 11816 | /* |
| 11817 | * If clipping results in a non-visible primary plane, we'll disable |
| 11818 | * the primary plane. Note that this is a bit different than what |
| 11819 | * happens if userspace explicitly disables the plane by passing fb=0 |
| 11820 | * because plane->fb still gets set and pinned. |
| 11821 | */ |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 11822 | if (!state->visible) { |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11823 | mutex_lock(&dev->struct_mutex); |
| 11824 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11825 | /* |
| 11826 | * Try to pin the new fb first so that we can bail out if we |
| 11827 | * fail. |
| 11828 | */ |
| 11829 | if (plane->fb != fb) { |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11830 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11831 | if (ret) { |
| 11832 | mutex_unlock(&dev->struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11833 | return ret; |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11834 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11835 | } |
| 11836 | |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11837 | i915_gem_track_fb(old_obj, obj, |
| 11838 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe)); |
| 11839 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11840 | if (intel_crtc->primary_enabled) |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 11841 | intel_disable_primary_hw_plane(plane, crtc); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11842 | |
| 11843 | |
| 11844 | if (plane->fb != fb) |
| 11845 | if (plane->fb) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11846 | intel_unpin_fb_obj(old_obj); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11847 | |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11848 | mutex_unlock(&dev->struct_mutex); |
| 11849 | |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 11850 | } else { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11851 | if (intel_crtc && intel_crtc->active && |
| 11852 | intel_crtc->primary_enabled) { |
| 11853 | /* |
| 11854 | * FBC does not work on some platforms for rotated |
| 11855 | * planes, so disable it when rotation is not 0 and |
| 11856 | * update it when rotation is set back to 0. |
| 11857 | * |
| 11858 | * FIXME: This is redundant with the fbc update done in |
| 11859 | * the primary plane enable function except that that |
| 11860 | * one is done too late. We eventually need to unify |
| 11861 | * this. |
| 11862 | */ |
| 11863 | if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
| 11864 | dev_priv->fbc.plane == intel_crtc->plane && |
| 11865 | intel_plane->rotation != BIT(DRM_ROTATE_0)) { |
| 11866 | intel_disable_fbc(dev); |
| 11867 | } |
| 11868 | } |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 11869 | ret = intel_pipe_set_base(crtc, src->x1, src->y1, fb); |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 11870 | if (ret) |
| 11871 | return ret; |
| 11872 | |
| 11873 | if (!intel_crtc->primary_enabled) |
| 11874 | intel_enable_primary_hw_plane(plane, crtc); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11875 | } |
| 11876 | |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 11877 | intel_plane->crtc_x = state->orig_dst.x1; |
| 11878 | intel_plane->crtc_y = state->orig_dst.y1; |
| 11879 | intel_plane->crtc_w = drm_rect_width(&state->orig_dst); |
| 11880 | intel_plane->crtc_h = drm_rect_height(&state->orig_dst); |
| 11881 | intel_plane->src_x = state->orig_src.x1; |
| 11882 | intel_plane->src_y = state->orig_src.y1; |
| 11883 | intel_plane->src_w = drm_rect_width(&state->orig_src); |
| 11884 | intel_plane->src_h = drm_rect_height(&state->orig_src); |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 11885 | intel_plane->obj = obj; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11886 | |
| 11887 | return 0; |
| 11888 | } |
| 11889 | |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 11890 | static int |
| 11891 | intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 11892 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
| 11893 | unsigned int crtc_w, unsigned int crtc_h, |
| 11894 | uint32_t src_x, uint32_t src_y, |
| 11895 | uint32_t src_w, uint32_t src_h) |
| 11896 | { |
| 11897 | struct intel_plane_state state; |
| 11898 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11899 | int ret; |
| 11900 | |
| 11901 | state.crtc = crtc; |
| 11902 | state.fb = fb; |
| 11903 | |
| 11904 | /* sample coordinates in 16.16 fixed point */ |
| 11905 | state.src.x1 = src_x; |
| 11906 | state.src.x2 = src_x + src_w; |
| 11907 | state.src.y1 = src_y; |
| 11908 | state.src.y2 = src_y + src_h; |
| 11909 | |
| 11910 | /* integer pixels */ |
| 11911 | state.dst.x1 = crtc_x; |
| 11912 | state.dst.x2 = crtc_x + crtc_w; |
| 11913 | state.dst.y1 = crtc_y; |
| 11914 | state.dst.y2 = crtc_y + crtc_h; |
| 11915 | |
| 11916 | state.clip.x1 = 0; |
| 11917 | state.clip.y1 = 0; |
| 11918 | state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0; |
| 11919 | state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0; |
| 11920 | |
| 11921 | state.orig_src = state.src; |
| 11922 | state.orig_dst = state.dst; |
| 11923 | |
| 11924 | ret = intel_check_primary_plane(plane, &state); |
| 11925 | if (ret) |
| 11926 | return ret; |
| 11927 | |
| 11928 | intel_commit_primary_plane(plane, &state); |
| 11929 | |
| 11930 | return 0; |
| 11931 | } |
| 11932 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11933 | /* Common destruction function for both primary and cursor planes */ |
| 11934 | static void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11935 | { |
| 11936 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 11937 | drm_plane_cleanup(plane); |
| 11938 | kfree(intel_plane); |
| 11939 | } |
| 11940 | |
| 11941 | static const struct drm_plane_funcs intel_primary_plane_funcs = { |
| 11942 | .update_plane = intel_primary_plane_setplane, |
| 11943 | .disable_plane = intel_primary_plane_disable, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11944 | .destroy = intel_plane_destroy, |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11945 | .set_property = intel_plane_set_property |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11946 | }; |
| 11947 | |
| 11948 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 11949 | int pipe) |
| 11950 | { |
| 11951 | struct intel_plane *primary; |
| 11952 | const uint32_t *intel_primary_formats; |
| 11953 | int num_formats; |
| 11954 | |
| 11955 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
| 11956 | if (primary == NULL) |
| 11957 | return NULL; |
| 11958 | |
| 11959 | primary->can_scale = false; |
| 11960 | primary->max_downscale = 1; |
| 11961 | primary->pipe = pipe; |
| 11962 | primary->plane = pipe; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11963 | primary->rotation = BIT(DRM_ROTATE_0); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11964 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 11965 | primary->plane = !pipe; |
| 11966 | |
| 11967 | if (INTEL_INFO(dev)->gen <= 3) { |
| 11968 | intel_primary_formats = intel_primary_formats_gen2; |
| 11969 | num_formats = ARRAY_SIZE(intel_primary_formats_gen2); |
| 11970 | } else { |
| 11971 | intel_primary_formats = intel_primary_formats_gen4; |
| 11972 | num_formats = ARRAY_SIZE(intel_primary_formats_gen4); |
| 11973 | } |
| 11974 | |
| 11975 | drm_universal_plane_init(dev, &primary->base, 0, |
| 11976 | &intel_primary_plane_funcs, |
| 11977 | intel_primary_formats, num_formats, |
| 11978 | DRM_PLANE_TYPE_PRIMARY); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11979 | |
| 11980 | if (INTEL_INFO(dev)->gen >= 4) { |
| 11981 | if (!dev->mode_config.rotation_property) |
| 11982 | dev->mode_config.rotation_property = |
| 11983 | drm_mode_create_rotation_property(dev, |
| 11984 | BIT(DRM_ROTATE_0) | |
| 11985 | BIT(DRM_ROTATE_180)); |
| 11986 | if (dev->mode_config.rotation_property) |
| 11987 | drm_object_attach_property(&primary->base.base, |
| 11988 | dev->mode_config.rotation_property, |
| 11989 | primary->rotation); |
| 11990 | } |
| 11991 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11992 | return &primary->base; |
| 11993 | } |
| 11994 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11995 | static int |
| 11996 | intel_cursor_plane_disable(struct drm_plane *plane) |
| 11997 | { |
| 11998 | if (!plane->fb) |
| 11999 | return 0; |
| 12000 | |
| 12001 | BUG_ON(!plane->crtc); |
| 12002 | |
| 12003 | return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0); |
| 12004 | } |
| 12005 | |
| 12006 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12007 | intel_check_cursor_plane(struct drm_plane *plane, |
| 12008 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12009 | { |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12010 | struct drm_crtc *crtc = state->crtc; |
| 12011 | struct drm_framebuffer *fb = state->fb; |
| 12012 | struct drm_rect *dest = &state->dst; |
| 12013 | struct drm_rect *src = &state->src; |
| 12014 | const struct drm_rect *clip = &state->clip; |
| 12015 | |
| 12016 | return drm_plane_helper_check_update(plane, crtc, fb, |
| 12017 | src, dest, clip, |
| 12018 | DRM_PLANE_HELPER_NO_SCALING, |
| 12019 | DRM_PLANE_HELPER_NO_SCALING, |
| 12020 | true, true, &state->visible); |
| 12021 | } |
| 12022 | |
| 12023 | static int |
| 12024 | intel_commit_cursor_plane(struct drm_plane *plane, |
| 12025 | struct intel_plane_state *state) |
| 12026 | { |
| 12027 | struct drm_crtc *crtc = state->crtc; |
| 12028 | struct drm_framebuffer *fb = state->fb; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12029 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12030 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 12031 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12032 | int crtc_w, crtc_h; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12033 | |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12034 | crtc->cursor_x = state->orig_dst.x1; |
| 12035 | crtc->cursor_y = state->orig_dst.y1; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12036 | if (fb != crtc->cursor->fb) { |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12037 | crtc_w = drm_rect_width(&state->orig_dst); |
| 12038 | crtc_h = drm_rect_height(&state->orig_dst); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12039 | return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h); |
| 12040 | } else { |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12041 | intel_crtc_update_cursor(crtc, state->visible); |
Daniel Vetter | 4ed9109 | 2014-08-08 20:27:01 +0200 | [diff] [blame] | 12042 | |
| 12043 | intel_frontbuffer_flip(crtc->dev, |
| 12044 | INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe)); |
| 12045 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12046 | return 0; |
| 12047 | } |
| 12048 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12049 | |
| 12050 | static int |
| 12051 | intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc, |
| 12052 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
| 12053 | unsigned int crtc_w, unsigned int crtc_h, |
| 12054 | uint32_t src_x, uint32_t src_y, |
| 12055 | uint32_t src_w, uint32_t src_h) |
| 12056 | { |
| 12057 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12058 | struct intel_plane_state state; |
| 12059 | int ret; |
| 12060 | |
| 12061 | state.crtc = crtc; |
| 12062 | state.fb = fb; |
| 12063 | |
| 12064 | /* sample coordinates in 16.16 fixed point */ |
| 12065 | state.src.x1 = src_x; |
| 12066 | state.src.x2 = src_x + src_w; |
| 12067 | state.src.y1 = src_y; |
| 12068 | state.src.y2 = src_y + src_h; |
| 12069 | |
| 12070 | /* integer pixels */ |
| 12071 | state.dst.x1 = crtc_x; |
| 12072 | state.dst.x2 = crtc_x + crtc_w; |
| 12073 | state.dst.y1 = crtc_y; |
| 12074 | state.dst.y2 = crtc_y + crtc_h; |
| 12075 | |
| 12076 | state.clip.x1 = 0; |
| 12077 | state.clip.y1 = 0; |
| 12078 | state.clip.x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0; |
| 12079 | state.clip.y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0; |
| 12080 | |
| 12081 | state.orig_src = state.src; |
| 12082 | state.orig_dst = state.dst; |
| 12083 | |
| 12084 | ret = intel_check_cursor_plane(plane, &state); |
| 12085 | if (ret) |
| 12086 | return ret; |
| 12087 | |
| 12088 | return intel_commit_cursor_plane(plane, &state); |
| 12089 | } |
| 12090 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12091 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { |
| 12092 | .update_plane = intel_cursor_plane_update, |
| 12093 | .disable_plane = intel_cursor_plane_disable, |
| 12094 | .destroy = intel_plane_destroy, |
| 12095 | }; |
| 12096 | |
| 12097 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 12098 | int pipe) |
| 12099 | { |
| 12100 | struct intel_plane *cursor; |
| 12101 | |
| 12102 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
| 12103 | if (cursor == NULL) |
| 12104 | return NULL; |
| 12105 | |
| 12106 | cursor->can_scale = false; |
| 12107 | cursor->max_downscale = 1; |
| 12108 | cursor->pipe = pipe; |
| 12109 | cursor->plane = pipe; |
| 12110 | |
| 12111 | drm_universal_plane_init(dev, &cursor->base, 0, |
| 12112 | &intel_cursor_plane_funcs, |
| 12113 | intel_cursor_formats, |
| 12114 | ARRAY_SIZE(intel_cursor_formats), |
| 12115 | DRM_PLANE_TYPE_CURSOR); |
| 12116 | return &cursor->base; |
| 12117 | } |
| 12118 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 12119 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12120 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12121 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12122 | struct intel_crtc *intel_crtc; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12123 | struct drm_plane *primary = NULL; |
| 12124 | struct drm_plane *cursor = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12125 | int i, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12126 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 12127 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12128 | if (intel_crtc == NULL) |
| 12129 | return; |
| 12130 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12131 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12132 | if (!primary) |
| 12133 | goto fail; |
| 12134 | |
| 12135 | cursor = intel_cursor_plane_create(dev, pipe); |
| 12136 | if (!cursor) |
| 12137 | goto fail; |
| 12138 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12139 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12140 | cursor, &intel_crtc_funcs); |
| 12141 | if (ret) |
| 12142 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12143 | |
| 12144 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12145 | for (i = 0; i < 256; i++) { |
| 12146 | intel_crtc->lut_r[i] = i; |
| 12147 | intel_crtc->lut_g[i] = i; |
| 12148 | intel_crtc->lut_b[i] = i; |
| 12149 | } |
| 12150 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 12151 | /* |
| 12152 | * On gen2/3 only plane A can do fbc, but the panel fitter and lvds port |
Daniel Vetter | 8c0f92e | 2014-06-16 02:08:26 +0200 | [diff] [blame] | 12153 | * is hooked to pipe B. Hence we want plane A feeding pipe B. |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 12154 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 12155 | intel_crtc->pipe = pipe; |
| 12156 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 12157 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 12158 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 12159 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 12160 | } |
| 12161 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 12162 | intel_crtc->cursor_base = ~0; |
| 12163 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 12164 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 12165 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 12166 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 12167 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 12168 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 12169 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 12170 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12171 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 12172 | |
| 12173 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12174 | return; |
| 12175 | |
| 12176 | fail: |
| 12177 | if (primary) |
| 12178 | drm_plane_cleanup(primary); |
| 12179 | if (cursor) |
| 12180 | drm_plane_cleanup(cursor); |
| 12181 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12182 | } |
| 12183 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12184 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 12185 | { |
| 12186 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 12187 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12188 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 12189 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12190 | |
| 12191 | if (!encoder) |
| 12192 | return INVALID_PIPE; |
| 12193 | |
| 12194 | return to_intel_crtc(encoder->crtc)->pipe; |
| 12195 | } |
| 12196 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12197 | 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] | 12198 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12199 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12200 | struct drm_i915_get_pipe_from_crtc_id *pipe_from_crtc_id = data; |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12201 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12202 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12203 | |
Daniel Vetter | 1cff8f6 | 2012-04-24 09:55:08 +0200 | [diff] [blame] | 12204 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 12205 | return -ENODEV; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12206 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12207 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12208 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12209 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12210 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 12211 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12212 | } |
| 12213 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12214 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12215 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12216 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12217 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12218 | } |
| 12219 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12220 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12221 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12222 | struct drm_device *dev = encoder->base.dev; |
| 12223 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12224 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12225 | int entry = 0; |
| 12226 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12227 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 12228 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12229 | index_mask |= (1 << entry); |
| 12230 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12231 | entry++; |
| 12232 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12233 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12234 | return index_mask; |
| 12235 | } |
| 12236 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 12237 | static bool has_edp_a(struct drm_device *dev) |
| 12238 | { |
| 12239 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12240 | |
| 12241 | if (!IS_MOBILE(dev)) |
| 12242 | return false; |
| 12243 | |
| 12244 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 12245 | return false; |
| 12246 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 12247 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 12248 | return false; |
| 12249 | |
| 12250 | return true; |
| 12251 | } |
| 12252 | |
Damien Lespiau | ba0fbca | 2014-01-08 14:18:23 +0000 | [diff] [blame] | 12253 | const char *intel_output_name(int output) |
| 12254 | { |
| 12255 | static const char *names[] = { |
| 12256 | [INTEL_OUTPUT_UNUSED] = "Unused", |
| 12257 | [INTEL_OUTPUT_ANALOG] = "Analog", |
| 12258 | [INTEL_OUTPUT_DVO] = "DVO", |
| 12259 | [INTEL_OUTPUT_SDVO] = "SDVO", |
| 12260 | [INTEL_OUTPUT_LVDS] = "LVDS", |
| 12261 | [INTEL_OUTPUT_TVOUT] = "TV", |
| 12262 | [INTEL_OUTPUT_HDMI] = "HDMI", |
| 12263 | [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort", |
| 12264 | [INTEL_OUTPUT_EDP] = "eDP", |
| 12265 | [INTEL_OUTPUT_DSI] = "DSI", |
| 12266 | [INTEL_OUTPUT_UNKNOWN] = "Unknown", |
| 12267 | }; |
| 12268 | |
| 12269 | if (output < 0 || output >= ARRAY_SIZE(names) || !names[output]) |
| 12270 | return "Invalid"; |
| 12271 | |
| 12272 | return names[output]; |
| 12273 | } |
| 12274 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 12275 | static bool intel_crt_present(struct drm_device *dev) |
| 12276 | { |
| 12277 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12278 | |
| 12279 | if (IS_ULT(dev)) |
| 12280 | return false; |
| 12281 | |
| 12282 | if (IS_CHERRYVIEW(dev)) |
| 12283 | return false; |
| 12284 | |
| 12285 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) |
| 12286 | return false; |
| 12287 | |
| 12288 | return true; |
| 12289 | } |
| 12290 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12291 | static void intel_setup_outputs(struct drm_device *dev) |
| 12292 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 12293 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12294 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12295 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12296 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 12297 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12298 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 12299 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 12300 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12301 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 12302 | if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 12303 | int found; |
| 12304 | |
| 12305 | /* Haswell uses DDI functions to detect digital outputs */ |
| 12306 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
| 12307 | /* DDI A only supports eDP */ |
| 12308 | if (found) |
| 12309 | intel_ddi_init(dev, PORT_A); |
| 12310 | |
| 12311 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 12312 | * register */ |
| 12313 | found = I915_READ(SFUSE_STRAP); |
| 12314 | |
| 12315 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 12316 | intel_ddi_init(dev, PORT_B); |
| 12317 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 12318 | intel_ddi_init(dev, PORT_C); |
| 12319 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 12320 | intel_ddi_init(dev, PORT_D); |
| 12321 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12322 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 12323 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 12324 | |
| 12325 | if (has_edp_a(dev)) |
| 12326 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12327 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 12328 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 12329 | /* PCH SDVOB multiplex with HDMIB */ |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 12330 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12331 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12332 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 12333 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12334 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12335 | } |
| 12336 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 12337 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12338 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12339 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 12340 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12341 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12342 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 12343 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12344 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 12345 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 12346 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12347 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 12348 | } else if (IS_VALLEYVIEW(dev)) { |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 12349 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) { |
| 12350 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
| 12351 | PORT_B); |
| 12352 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED) |
| 12353 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); |
| 12354 | } |
| 12355 | |
Jesse Barnes | 6f6005a | 2013-08-09 09:34:35 -0700 | [diff] [blame] | 12356 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) { |
| 12357 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
| 12358 | PORT_C); |
| 12359 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED) |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 12360 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); |
Jesse Barnes | 6f6005a | 2013-08-09 09:34:35 -0700 | [diff] [blame] | 12361 | } |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 12362 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 12363 | if (IS_CHERRYVIEW(dev)) { |
| 12364 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) { |
| 12365 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
| 12366 | PORT_D); |
| 12367 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) |
| 12368 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); |
| 12369 | } |
| 12370 | } |
| 12371 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 12372 | intel_dsi_init(dev); |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 12373 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12374 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 12375 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12376 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12377 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12378 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12379 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 12380 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12381 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12382 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12383 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 12384 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12385 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 12386 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 12387 | |
| 12388 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 12389 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12390 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12391 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12392 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12393 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12394 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12395 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12396 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12397 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 12398 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12399 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12400 | } |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 12401 | if (SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12402 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 12403 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12404 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12405 | if (SUPPORTS_INTEGRATED_DP(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 12406 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12407 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 12408 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12409 | intel_dvo_init(dev); |
| 12410 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 12411 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12412 | intel_tv_init(dev); |
| 12413 | |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 12414 | intel_edp_psr_init(dev); |
| 12415 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12416 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12417 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 12418 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12419 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12420 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 12421 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 12422 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 12423 | |
| 12424 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12425 | } |
| 12426 | |
| 12427 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 12428 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 12429 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12430 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12431 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 12432 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 12433 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 12434 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 12435 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 12436 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12437 | kfree(intel_fb); |
| 12438 | } |
| 12439 | |
| 12440 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12441 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12442 | unsigned int *handle) |
| 12443 | { |
| 12444 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12445 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12446 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12447 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12448 | } |
| 12449 | |
| 12450 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 12451 | .destroy = intel_user_framebuffer_destroy, |
| 12452 | .create_handle = intel_user_framebuffer_create_handle, |
| 12453 | }; |
| 12454 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 12455 | static int intel_framebuffer_init(struct drm_device *dev, |
| 12456 | struct intel_framebuffer *intel_fb, |
| 12457 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 12458 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12459 | { |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 12460 | int aligned_height; |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 12461 | int pitch_limit; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12462 | int ret; |
| 12463 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 12464 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 12465 | |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12466 | if (obj->tiling_mode == I915_TILING_Y) { |
| 12467 | DRM_DEBUG("hardware does not support tiling Y\n"); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12468 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12469 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12470 | |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12471 | if (mode_cmd->pitches[0] & 63) { |
| 12472 | DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n", |
| 12473 | mode_cmd->pitches[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12474 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12475 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12476 | |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 12477 | if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) { |
| 12478 | pitch_limit = 32*1024; |
| 12479 | } else if (INTEL_INFO(dev)->gen >= 4) { |
| 12480 | if (obj->tiling_mode) |
| 12481 | pitch_limit = 16*1024; |
| 12482 | else |
| 12483 | pitch_limit = 32*1024; |
| 12484 | } else if (INTEL_INFO(dev)->gen >= 3) { |
| 12485 | if (obj->tiling_mode) |
| 12486 | pitch_limit = 8*1024; |
| 12487 | else |
| 12488 | pitch_limit = 16*1024; |
| 12489 | } else |
| 12490 | /* XXX DSPC is limited to 4k tiled */ |
| 12491 | pitch_limit = 8*1024; |
| 12492 | |
| 12493 | if (mode_cmd->pitches[0] > pitch_limit) { |
| 12494 | DRM_DEBUG("%s pitch (%d) must be at less than %d\n", |
| 12495 | obj->tiling_mode ? "tiled" : "linear", |
| 12496 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12497 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12498 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12499 | |
| 12500 | if (obj->tiling_mode != I915_TILING_NONE && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12501 | mode_cmd->pitches[0] != obj->stride) { |
| 12502 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 12503 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12504 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12505 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12506 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12507 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 12508 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12509 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 12510 | case DRM_FORMAT_RGB565: |
| 12511 | case DRM_FORMAT_XRGB8888: |
| 12512 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12513 | break; |
| 12514 | case DRM_FORMAT_XRGB1555: |
| 12515 | case DRM_FORMAT_ARGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12516 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12517 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12518 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12519 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12520 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12521 | break; |
| 12522 | case DRM_FORMAT_XBGR8888: |
| 12523 | case DRM_FORMAT_ABGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 12524 | case DRM_FORMAT_XRGB2101010: |
| 12525 | case DRM_FORMAT_ARGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12526 | case DRM_FORMAT_XBGR2101010: |
| 12527 | case DRM_FORMAT_ABGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12528 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12529 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12530 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12531 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12532 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 12533 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 12534 | case DRM_FORMAT_YUYV: |
| 12535 | case DRM_FORMAT_UYVY: |
| 12536 | case DRM_FORMAT_YVYU: |
| 12537 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12538 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12539 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12540 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12541 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12542 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12543 | break; |
| 12544 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12545 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12546 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12547 | return -EINVAL; |
| 12548 | } |
| 12549 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 12550 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 12551 | if (mode_cmd->offsets[0] != 0) |
| 12552 | return -EINVAL; |
| 12553 | |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 12554 | aligned_height = intel_align_height(dev, mode_cmd->height, |
| 12555 | obj->tiling_mode); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 12556 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 12557 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 12558 | return -EINVAL; |
| 12559 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 12560 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 12561 | intel_fb->obj = obj; |
Daniel Vetter | 80075d4 | 2013-10-09 21:23:52 +0200 | [diff] [blame] | 12562 | intel_fb->obj->framebuffer_references++; |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 12563 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12564 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 12565 | if (ret) { |
| 12566 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 12567 | return ret; |
| 12568 | } |
| 12569 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12570 | return 0; |
| 12571 | } |
| 12572 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12573 | static struct drm_framebuffer * |
| 12574 | intel_user_framebuffer_create(struct drm_device *dev, |
| 12575 | struct drm_file *filp, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 12576 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12577 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12578 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12579 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 12580 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
| 12581 | mode_cmd->handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 12582 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 12583 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12584 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 12585 | return intel_framebuffer_create(dev, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12586 | } |
| 12587 | |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 12588 | #ifndef CONFIG_DRM_I915_FBDEV |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 12589 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 12590 | { |
| 12591 | } |
| 12592 | #endif |
| 12593 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12594 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12595 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 12596 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12597 | }; |
| 12598 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12599 | /* Set up chip specific display functions */ |
| 12600 | static void intel_init_display(struct drm_device *dev) |
| 12601 | { |
| 12602 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12603 | |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 12604 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
| 12605 | dev_priv->display.find_dpll = g4x_find_best_dpll; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 12606 | else if (IS_CHERRYVIEW(dev)) |
| 12607 | dev_priv->display.find_dpll = chv_find_best_dpll; |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 12608 | else if (IS_VALLEYVIEW(dev)) |
| 12609 | dev_priv->display.find_dpll = vlv_find_best_dpll; |
| 12610 | else if (IS_PINEVIEW(dev)) |
| 12611 | dev_priv->display.find_dpll = pnv_find_best_dpll; |
| 12612 | else |
| 12613 | dev_priv->display.find_dpll = i9xx_find_best_dpll; |
| 12614 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 12615 | if (HAS_DDI(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12616 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 12617 | dev_priv->display.get_plane_config = ironlake_get_plane_config; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 12618 | dev_priv->display.crtc_mode_set = haswell_crtc_mode_set; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 12619 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 12620 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 12621 | dev_priv->display.off = ironlake_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 12622 | dev_priv->display.update_primary_plane = |
| 12623 | ironlake_update_primary_plane; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 12624 | } else if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12625 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 12626 | dev_priv->display.get_plane_config = ironlake_get_plane_config; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 12627 | dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 12628 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 12629 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12630 | dev_priv->display.off = ironlake_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 12631 | dev_priv->display.update_primary_plane = |
| 12632 | ironlake_update_primary_plane; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 12633 | } else if (IS_VALLEYVIEW(dev)) { |
| 12634 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 12635 | dev_priv->display.get_plane_config = i9xx_get_plane_config; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 12636 | dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; |
| 12637 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 12638 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 12639 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 12640 | dev_priv->display.update_primary_plane = |
| 12641 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 12642 | } else { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12643 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 12644 | dev_priv->display.get_plane_config = i9xx_get_plane_config; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 12645 | dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 12646 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 12647 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12648 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 12649 | dev_priv->display.update_primary_plane = |
| 12650 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 12651 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12652 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12653 | /* Returns the core display clock speed */ |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 12654 | if (IS_VALLEYVIEW(dev)) |
| 12655 | dev_priv->display.get_display_clock_speed = |
| 12656 | valleyview_get_display_clock_speed; |
| 12657 | else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev))) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12658 | dev_priv->display.get_display_clock_speed = |
| 12659 | i945_get_display_clock_speed; |
| 12660 | else if (IS_I915G(dev)) |
| 12661 | dev_priv->display.get_display_clock_speed = |
| 12662 | i915_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 12663 | else if (IS_I945GM(dev) || IS_845G(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12664 | dev_priv->display.get_display_clock_speed = |
| 12665 | i9xx_misc_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 12666 | else if (IS_PINEVIEW(dev)) |
| 12667 | dev_priv->display.get_display_clock_speed = |
| 12668 | pnv_get_display_clock_speed; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12669 | else if (IS_I915GM(dev)) |
| 12670 | dev_priv->display.get_display_clock_speed = |
| 12671 | i915gm_get_display_clock_speed; |
| 12672 | else if (IS_I865G(dev)) |
| 12673 | dev_priv->display.get_display_clock_speed = |
| 12674 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 12675 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12676 | dev_priv->display.get_display_clock_speed = |
| 12677 | i855_get_display_clock_speed; |
| 12678 | else /* 852, 830 */ |
| 12679 | dev_priv->display.get_display_clock_speed = |
| 12680 | i830_get_display_clock_speed; |
| 12681 | |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 12682 | if (IS_G4X(dev)) { |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 12683 | dev_priv->display.write_eld = g4x_write_eld; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 12684 | } else if (IS_GEN5(dev)) { |
| 12685 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
| 12686 | dev_priv->display.write_eld = ironlake_write_eld; |
| 12687 | } else if (IS_GEN6(dev)) { |
| 12688 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
| 12689 | dev_priv->display.write_eld = ironlake_write_eld; |
| 12690 | dev_priv->display.modeset_global_resources = |
| 12691 | snb_modeset_global_resources; |
| 12692 | } else if (IS_IVYBRIDGE(dev)) { |
| 12693 | /* FIXME: detect B0+ stepping and use auto training */ |
| 12694 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
| 12695 | dev_priv->display.write_eld = ironlake_write_eld; |
| 12696 | dev_priv->display.modeset_global_resources = |
| 12697 | ivb_modeset_global_resources; |
Paulo Zanoni | 059b2fe | 2014-09-02 16:53:57 -0300 | [diff] [blame] | 12698 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 12699 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
| 12700 | dev_priv->display.write_eld = haswell_write_eld; |
| 12701 | dev_priv->display.modeset_global_resources = |
| 12702 | haswell_modeset_global_resources; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 12703 | } else if (IS_VALLEYVIEW(dev)) { |
| 12704 | dev_priv->display.modeset_global_resources = |
| 12705 | valleyview_modeset_global_resources; |
Mengdong Lin | 9ca2fe7 | 2013-11-01 00:17:03 -0400 | [diff] [blame] | 12706 | dev_priv->display.write_eld = ironlake_write_eld; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12707 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 12708 | |
| 12709 | /* Default just returns -ENODEV to indicate unsupported */ |
| 12710 | dev_priv->display.queue_flip = intel_default_queue_flip; |
| 12711 | |
| 12712 | switch (INTEL_INFO(dev)->gen) { |
| 12713 | case 2: |
| 12714 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 12715 | break; |
| 12716 | |
| 12717 | case 3: |
| 12718 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 12719 | break; |
| 12720 | |
| 12721 | case 4: |
| 12722 | case 5: |
| 12723 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 12724 | break; |
| 12725 | |
| 12726 | case 6: |
| 12727 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 12728 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 12729 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 12730 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 12731 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 12732 | break; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 12733 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 12734 | |
| 12735 | intel_panel_init_backlight_funcs(dev); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 12736 | |
| 12737 | mutex_init(&dev_priv->pps_mutex); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12738 | } |
| 12739 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12740 | /* |
| 12741 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 12742 | * resume, or other times. This quirk makes sure that's the case for |
| 12743 | * affected systems. |
| 12744 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 12745 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12746 | { |
| 12747 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12748 | |
| 12749 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 12750 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12751 | } |
| 12752 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 12753 | static void quirk_pipeb_force(struct drm_device *dev) |
| 12754 | { |
| 12755 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12756 | |
| 12757 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 12758 | DRM_INFO("applying pipe b force quirk\n"); |
| 12759 | } |
| 12760 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 12761 | /* |
| 12762 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 12763 | */ |
| 12764 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 12765 | { |
| 12766 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12767 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 12768 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 12769 | } |
| 12770 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 12771 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 12772 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 12773 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 12774 | */ |
| 12775 | static void quirk_invert_brightness(struct drm_device *dev) |
| 12776 | { |
| 12777 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12778 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 12779 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12780 | } |
| 12781 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 12782 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 12783 | static void quirk_backlight_present(struct drm_device *dev) |
| 12784 | { |
| 12785 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12786 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 12787 | DRM_INFO("applying backlight present quirk\n"); |
| 12788 | } |
| 12789 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12790 | struct intel_quirk { |
| 12791 | int device; |
| 12792 | int subsystem_vendor; |
| 12793 | int subsystem_device; |
| 12794 | void (*hook)(struct drm_device *dev); |
| 12795 | }; |
| 12796 | |
Egbert Eich | 5f85f176 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 12797 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 12798 | struct intel_dmi_quirk { |
| 12799 | void (*hook)(struct drm_device *dev); |
| 12800 | const struct dmi_system_id (*dmi_id_list)[]; |
| 12801 | }; |
| 12802 | |
| 12803 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 12804 | { |
| 12805 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 12806 | return 1; |
| 12807 | } |
| 12808 | |
| 12809 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 12810 | { |
| 12811 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 12812 | { |
| 12813 | .callback = intel_dmi_reverse_brightness, |
| 12814 | .ident = "NCR Corporation", |
| 12815 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 12816 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 12817 | }, |
| 12818 | }, |
| 12819 | { } /* terminating entry */ |
| 12820 | }, |
| 12821 | .hook = quirk_invert_brightness, |
| 12822 | }, |
| 12823 | }; |
| 12824 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 12825 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12826 | /* HP Mini needs pipe A force quirk (LP: #322104) */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 12827 | { 0x27ae, 0x103c, 0x361a, quirk_pipea_force }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12828 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12829 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 12830 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 12831 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12832 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 12833 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 12834 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 12835 | /* 830 needs to leave pipe A & dpll A up */ |
| 12836 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 12837 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 12838 | /* 830 needs to leave pipe B & dpll B up */ |
| 12839 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 12840 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 12841 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 12842 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 12843 | |
| 12844 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 12845 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 12846 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 12847 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 12848 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 12849 | |
| 12850 | /* Acer/eMachines G725 */ |
| 12851 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 12852 | |
| 12853 | /* Acer/eMachines e725 */ |
| 12854 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 12855 | |
| 12856 | /* Acer/Packard Bell NCL20 */ |
| 12857 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 12858 | |
| 12859 | /* Acer Aspire 4736Z */ |
| 12860 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 12861 | |
| 12862 | /* Acer Aspire 5336 */ |
| 12863 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 12864 | |
| 12865 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 12866 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 12867 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 12868 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 12869 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 12870 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 12871 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 12872 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 12873 | |
| 12874 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 12875 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12876 | }; |
| 12877 | |
| 12878 | static void intel_init_quirks(struct drm_device *dev) |
| 12879 | { |
| 12880 | struct pci_dev *d = dev->pdev; |
| 12881 | int i; |
| 12882 | |
| 12883 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 12884 | struct intel_quirk *q = &intel_quirks[i]; |
| 12885 | |
| 12886 | if (d->device == q->device && |
| 12887 | (d->subsystem_vendor == q->subsystem_vendor || |
| 12888 | q->subsystem_vendor == PCI_ANY_ID) && |
| 12889 | (d->subsystem_device == q->subsystem_device || |
| 12890 | q->subsystem_device == PCI_ANY_ID)) |
| 12891 | q->hook(dev); |
| 12892 | } |
Egbert Eich | 5f85f176 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 12893 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 12894 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 12895 | intel_dmi_quirks[i].hook(dev); |
| 12896 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12897 | } |
| 12898 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12899 | /* Disable the VGA plane that we never use */ |
| 12900 | static void i915_disable_vga(struct drm_device *dev) |
| 12901 | { |
| 12902 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12903 | u8 sr1; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 12904 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12905 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 12906 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12907 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 12908 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12909 | sr1 = inb(VGA_SR_DATA); |
| 12910 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 12911 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 12912 | udelay(300); |
| 12913 | |
Ville Syrjälä | 69769f9 | 2014-08-15 01:22:08 +0300 | [diff] [blame] | 12914 | /* |
| 12915 | * Fujitsu-Siemens Lifebook S6010 (830) has problems resuming |
| 12916 | * from S3 without preserving (some of?) the other bits. |
| 12917 | */ |
| 12918 | I915_WRITE(vga_reg, dev_priv->bios_vgacntr | VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12919 | POSTING_READ(vga_reg); |
| 12920 | } |
| 12921 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 12922 | void intel_modeset_init_hw(struct drm_device *dev) |
| 12923 | { |
Eugeni Dodonov | a8f78b5 | 2012-06-28 15:55:35 -0300 | [diff] [blame] | 12924 | intel_prepare_ddi(dev); |
| 12925 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 12926 | if (IS_VALLEYVIEW(dev)) |
| 12927 | vlv_update_cdclk(dev); |
| 12928 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 12929 | intel_init_clock_gating(dev); |
| 12930 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 12931 | intel_enable_gt_powersave(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 12932 | } |
| 12933 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 12934 | void intel_modeset_suspend_hw(struct drm_device *dev) |
| 12935 | { |
| 12936 | intel_suspend_hw(dev); |
| 12937 | } |
| 12938 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12939 | void intel_modeset_init(struct drm_device *dev) |
| 12940 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 12941 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 12942 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 12943 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 12944 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12945 | |
| 12946 | drm_mode_config_init(dev); |
| 12947 | |
| 12948 | dev->mode_config.min_width = 0; |
| 12949 | dev->mode_config.min_height = 0; |
| 12950 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 12951 | dev->mode_config.preferred_depth = 24; |
| 12952 | dev->mode_config.prefer_shadow = 1; |
| 12953 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 12954 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12955 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12956 | intel_init_quirks(dev); |
| 12957 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 12958 | intel_init_pm(dev); |
| 12959 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 12960 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 12961 | return; |
| 12962 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12963 | intel_init_display(dev); |
| 12964 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 12965 | if (IS_GEN2(dev)) { |
| 12966 | dev->mode_config.max_width = 2048; |
| 12967 | dev->mode_config.max_height = 2048; |
| 12968 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 12969 | dev->mode_config.max_width = 4096; |
| 12970 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12971 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 12972 | dev->mode_config.max_width = 8192; |
| 12973 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12974 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 12975 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 12976 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 12977 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 12978 | dev->mode_config.cursor_height = 1023; |
| 12979 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 12980 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 12981 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 12982 | } else { |
| 12983 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 12984 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 12985 | } |
| 12986 | |
Ben Widawsky | 5d4545a | 2013-01-17 12:45:15 -0800 | [diff] [blame] | 12987 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12988 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 12989 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 12990 | INTEL_INFO(dev)->num_pipes, |
| 12991 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12992 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 12993 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 12994 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 12995 | for_each_sprite(pipe, sprite) { |
| 12996 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 12997 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 12998 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 12999 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 13000 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13001 | } |
| 13002 | |
Jesse Barnes | f42bb70 | 2013-12-16 16:34:23 -0800 | [diff] [blame] | 13003 | intel_init_dpio(dev); |
| 13004 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 13005 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13006 | |
Ville Syrjälä | 69769f9 | 2014-08-15 01:22:08 +0300 | [diff] [blame] | 13007 | /* save the BIOS value before clobbering it */ |
| 13008 | dev_priv->bios_vgacntr = I915_READ(i915_vgacntrl_reg(dev)); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13009 | /* Just disable it once at startup */ |
| 13010 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13011 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 13012 | |
| 13013 | /* Just in case the BIOS is doing something questionable. */ |
| 13014 | intel_disable_fbc(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 13015 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13016 | drm_modeset_lock_all(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 13017 | intel_modeset_setup_hw_state(dev, false); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13018 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13019 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13020 | for_each_intel_crtc(dev, crtc) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13021 | if (!crtc->active) |
| 13022 | continue; |
| 13023 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13024 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13025 | * Note that reserving the BIOS fb up front prevents us |
| 13026 | * from stuffing other stolen allocations like the ring |
| 13027 | * on top. This prevents some ugliness at boot time, and |
| 13028 | * can even allow for smooth boot transitions if the BIOS |
| 13029 | * fb is large enough for the active pipe configuration. |
| 13030 | */ |
| 13031 | if (dev_priv->display.get_plane_config) { |
| 13032 | dev_priv->display.get_plane_config(crtc, |
| 13033 | &crtc->plane_config); |
| 13034 | /* |
| 13035 | * If the fb is shared between multiple heads, we'll |
| 13036 | * just get the first one. |
| 13037 | */ |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13038 | intel_find_plane_obj(crtc, &crtc->plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13039 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13040 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 13041 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 13042 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13043 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 13044 | { |
| 13045 | struct intel_connector *connector; |
| 13046 | struct drm_connector *crt = NULL; |
| 13047 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 13048 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13049 | |
| 13050 | /* We can't just switch on the pipe A, we need to set things up with a |
| 13051 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 13052 | * by enabling the load detect pipe once. */ |
| 13053 | list_for_each_entry(connector, |
| 13054 | &dev->mode_config.connector_list, |
| 13055 | base.head) { |
| 13056 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 13057 | crt = &connector->base; |
| 13058 | break; |
| 13059 | } |
| 13060 | } |
| 13061 | |
| 13062 | if (!crt) |
| 13063 | return; |
| 13064 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 13065 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
| 13066 | intel_release_load_detect_pipe(crt, &load_detect_temp); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13067 | } |
| 13068 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13069 | static bool |
| 13070 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 13071 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 13072 | struct drm_device *dev = crtc->base.dev; |
| 13073 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13074 | u32 reg, val; |
| 13075 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 13076 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13077 | return true; |
| 13078 | |
| 13079 | reg = DSPCNTR(!crtc->plane); |
| 13080 | val = I915_READ(reg); |
| 13081 | |
| 13082 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 13083 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 13084 | return false; |
| 13085 | |
| 13086 | return true; |
| 13087 | } |
| 13088 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13089 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 13090 | { |
| 13091 | struct drm_device *dev = crtc->base.dev; |
| 13092 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13093 | u32 reg; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13094 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13095 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 13096 | reg = PIPECONF(crtc->config.cpu_transcoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13097 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 13098 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 13099 | /* restore vblank interrupts to correct state */ |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 13100 | if (crtc->active) { |
| 13101 | update_scanline_offset(crtc); |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 13102 | drm_vblank_on(dev, crtc->pipe); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 13103 | } else |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 13104 | drm_vblank_off(dev, crtc->pipe); |
| 13105 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13106 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13107 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 13108 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 13109 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13110 | struct intel_connector *connector; |
| 13111 | bool plane; |
| 13112 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13113 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 13114 | crtc->base.base.id); |
| 13115 | |
| 13116 | /* Pipe has the wrong plane attached and the plane is active. |
| 13117 | * Temporarily change the plane mapping and disable everything |
| 13118 | * ... */ |
| 13119 | plane = crtc->plane; |
| 13120 | crtc->plane = !plane; |
Daniel Vetter | 9c8958b | 2014-07-14 19:35:31 +0200 | [diff] [blame] | 13121 | crtc->primary_enabled = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13122 | dev_priv->display.crtc_disable(&crtc->base); |
| 13123 | crtc->plane = plane; |
| 13124 | |
| 13125 | /* ... and break all links. */ |
| 13126 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 13127 | base.head) { |
| 13128 | if (connector->encoder->base.crtc != &crtc->base) |
| 13129 | continue; |
| 13130 | |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13131 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 13132 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13133 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13134 | /* multiple connectors may have the same encoder: |
| 13135 | * handle them and break crtc link separately */ |
| 13136 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 13137 | base.head) |
| 13138 | if (connector->encoder->base.crtc == &crtc->base) { |
| 13139 | connector->encoder->base.crtc = NULL; |
| 13140 | connector->encoder->connectors_active = false; |
| 13141 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13142 | |
| 13143 | WARN_ON(crtc->active); |
| 13144 | crtc->base.enabled = false; |
| 13145 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13146 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13147 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 13148 | crtc->pipe == PIPE_A && !crtc->active) { |
| 13149 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 13150 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 13151 | * call below we restore the pipe to the right state, but leave |
| 13152 | * the required bits on. */ |
| 13153 | intel_enable_pipe_a(dev); |
| 13154 | } |
| 13155 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13156 | /* Adjust the state of the output pipe according to whether we |
| 13157 | * have active connectors/encoders. */ |
| 13158 | intel_crtc_update_dpms(&crtc->base); |
| 13159 | |
| 13160 | if (crtc->active != crtc->base.enabled) { |
| 13161 | struct intel_encoder *encoder; |
| 13162 | |
| 13163 | /* This can happen either due to bugs in the get_hw_state |
| 13164 | * functions or because the pipe is force-enabled due to the |
| 13165 | * pipe A quirk. */ |
| 13166 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", |
| 13167 | crtc->base.base.id, |
| 13168 | crtc->base.enabled ? "enabled" : "disabled", |
| 13169 | crtc->active ? "enabled" : "disabled"); |
| 13170 | |
| 13171 | crtc->base.enabled = crtc->active; |
| 13172 | |
| 13173 | /* Because we only establish the connector -> encoder -> |
| 13174 | * crtc links if something is active, this means the |
| 13175 | * crtc is now deactivated. Break the links. connector |
| 13176 | * -> encoder links are only establish when things are |
| 13177 | * actually up, hence no need to break them. */ |
| 13178 | WARN_ON(crtc->active); |
| 13179 | |
| 13180 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
| 13181 | WARN_ON(encoder->connectors_active); |
| 13182 | encoder->base.crtc = NULL; |
| 13183 | } |
| 13184 | } |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 13185 | |
Ville Syrjälä | a3ed6aa | 2014-09-03 14:09:52 +0300 | [diff] [blame] | 13186 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 13187 | /* |
| 13188 | * We start out with underrun reporting disabled to avoid races. |
| 13189 | * For correct bookkeeping mark this on active crtcs. |
| 13190 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 13191 | * Also on gmch platforms we dont have any hardware bits to |
| 13192 | * disable the underrun reporting. Which means we need to start |
| 13193 | * out with underrun reporting disabled also on inactive pipes, |
| 13194 | * since otherwise we'll complain about the garbage we read when |
| 13195 | * e.g. coming up after runtime pm. |
| 13196 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 13197 | * No protection against concurrent access is required - at |
| 13198 | * worst a fifo underrun happens which also sets this to false. |
| 13199 | */ |
| 13200 | crtc->cpu_fifo_underrun_disabled = true; |
| 13201 | crtc->pch_fifo_underrun_disabled = true; |
| 13202 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13203 | } |
| 13204 | |
| 13205 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 13206 | { |
| 13207 | struct intel_connector *connector; |
| 13208 | struct drm_device *dev = encoder->base.dev; |
| 13209 | |
| 13210 | /* We need to check both for a crtc link (meaning that the |
| 13211 | * encoder is active and trying to read from a pipe) and the |
| 13212 | * pipe itself being active. */ |
| 13213 | bool has_active_crtc = encoder->base.crtc && |
| 13214 | to_intel_crtc(encoder->base.crtc)->active; |
| 13215 | |
| 13216 | if (encoder->connectors_active && !has_active_crtc) { |
| 13217 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 13218 | encoder->base.base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13219 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13220 | |
| 13221 | /* Connector is active, but has no active pipe. This is |
| 13222 | * fallout from our resume register restoring. Disable |
| 13223 | * the encoder manually again. */ |
| 13224 | if (encoder->base.crtc) { |
| 13225 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 13226 | encoder->base.base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13227 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13228 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 13229 | if (encoder->post_disable) |
| 13230 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13231 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13232 | encoder->base.crtc = NULL; |
| 13233 | encoder->connectors_active = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13234 | |
| 13235 | /* Inconsistent output/port/pipe state happens presumably due to |
| 13236 | * a bug in one of the get_hw_state functions. Or someplace else |
| 13237 | * in our code, like the register restore mess on resume. Clamp |
| 13238 | * things to off as a safer default. */ |
| 13239 | list_for_each_entry(connector, |
| 13240 | &dev->mode_config.connector_list, |
| 13241 | base.head) { |
| 13242 | if (connector->encoder != encoder) |
| 13243 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13244 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 13245 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13246 | } |
| 13247 | } |
| 13248 | /* Enabled encoders without active connectors will be fixed in |
| 13249 | * the crtc fixup. */ |
| 13250 | } |
| 13251 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13252 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 13253 | { |
| 13254 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 13255 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 13256 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13257 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 13258 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 13259 | i915_disable_vga(dev); |
| 13260 | } |
| 13261 | } |
| 13262 | |
| 13263 | void i915_redisable_vga(struct drm_device *dev) |
| 13264 | { |
| 13265 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13266 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 13267 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 13268 | * at a very early point in our resume sequence, where the power well |
| 13269 | * structures are not yet restored. Since this function is at a very |
| 13270 | * paranoid "someone might have enabled VGA while we were not looking" |
| 13271 | * level, just check if the power well is enabled instead of trying to |
| 13272 | * follow the "don't touch the power well if we don't need it" policy |
| 13273 | * the rest of the driver uses. */ |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13274 | if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 13275 | return; |
| 13276 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13277 | i915_redisable_vga_power_on(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 13278 | } |
| 13279 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 13280 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
| 13281 | { |
| 13282 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 13283 | |
| 13284 | if (!crtc->active) |
| 13285 | return false; |
| 13286 | |
| 13287 | return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE; |
| 13288 | } |
| 13289 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13290 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13291 | { |
| 13292 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13293 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13294 | struct intel_crtc *crtc; |
| 13295 | struct intel_encoder *encoder; |
| 13296 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13297 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13298 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13299 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 13300 | memset(&crtc->config, 0, sizeof(crtc->config)); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 13301 | |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 13302 | crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE; |
| 13303 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13304 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
| 13305 | &crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13306 | |
| 13307 | crtc->base.enabled = crtc->active; |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 13308 | crtc->primary_enabled = primary_get_hw_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13309 | |
| 13310 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 13311 | crtc->base.base.id, |
| 13312 | crtc->active ? "enabled" : "disabled"); |
| 13313 | } |
| 13314 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13315 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 13316 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 13317 | |
| 13318 | pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state); |
| 13319 | pll->active = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13320 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13321 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 13322 | pll->active++; |
| 13323 | } |
| 13324 | pll->refcount = pll->active; |
| 13325 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 13326 | DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n", |
| 13327 | pll->name, pll->refcount, pll->on); |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 13328 | |
| 13329 | if (pll->refcount) |
| 13330 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13331 | } |
| 13332 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13333 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13334 | pipe = 0; |
| 13335 | |
| 13336 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 13337 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 13338 | encoder->base.crtc = &crtc->base; |
Daniel Vetter | 1d37b68 | 2013-11-18 09:00:59 +0100 | [diff] [blame] | 13339 | encoder->get_config(encoder, &crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13340 | } else { |
| 13341 | encoder->base.crtc = NULL; |
| 13342 | } |
| 13343 | |
| 13344 | encoder->connectors_active = false; |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 13345 | DRM_DEBUG_KMS("[ENCODER:%d:%s] hw state readout: %s, pipe %c\n", |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13346 | encoder->base.base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13347 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13348 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 13349 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13350 | } |
| 13351 | |
| 13352 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 13353 | base.head) { |
| 13354 | if (connector->get_hw_state(connector)) { |
| 13355 | connector->base.dpms = DRM_MODE_DPMS_ON; |
| 13356 | connector->encoder->connectors_active = true; |
| 13357 | connector->base.encoder = &connector->encoder->base; |
| 13358 | } else { |
| 13359 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 13360 | connector->base.encoder = NULL; |
| 13361 | } |
| 13362 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 13363 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 13364 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13365 | connector->base.encoder ? "enabled" : "disabled"); |
| 13366 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13367 | } |
| 13368 | |
| 13369 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm |
| 13370 | * and i915 state tracking structures. */ |
| 13371 | void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 13372 | bool force_restore) |
| 13373 | { |
| 13374 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13375 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13376 | struct intel_crtc *crtc; |
| 13377 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 13378 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13379 | |
| 13380 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13381 | |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 13382 | /* |
| 13383 | * Now that we have the config, copy it to each CRTC struct |
| 13384 | * Note that this could go away if we move to using crtc_config |
| 13385 | * checking everywhere. |
| 13386 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13387 | for_each_intel_crtc(dev, crtc) { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 13388 | if (crtc->active && i915.fastboot) { |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 13389 | intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 13390 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
| 13391 | crtc->base.base.id); |
| 13392 | drm_mode_debug_printmodeline(&crtc->base.mode); |
| 13393 | } |
| 13394 | } |
| 13395 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13396 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13397 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13398 | intel_sanitize_encoder(encoder); |
| 13399 | } |
| 13400 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13401 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13402 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 13403 | intel_sanitize_crtc(crtc); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 13404 | intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13405 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 13406 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 13407 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 13408 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 13409 | |
| 13410 | if (!pll->on || pll->active) |
| 13411 | continue; |
| 13412 | |
| 13413 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 13414 | |
| 13415 | pll->disable(dev_priv, pll); |
| 13416 | pll->on = false; |
| 13417 | } |
| 13418 | |
Ville Syrjälä | 96f90c5 | 2013-12-05 15:51:38 +0200 | [diff] [blame] | 13419 | if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 13420 | ilk_wm_get_hw_state(dev); |
| 13421 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 13422 | if (force_restore) { |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 13423 | i915_redisable_vga(dev); |
| 13424 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13425 | /* |
| 13426 | * We need to use raw interfaces for restoring state to avoid |
| 13427 | * checking (bogus) intermediate states. |
| 13428 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13429 | for_each_pipe(dev_priv, pipe) { |
Jesse Barnes | b5644d0 | 2013-03-26 13:25:27 -0700 | [diff] [blame] | 13430 | struct drm_crtc *crtc = |
| 13431 | dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13432 | |
| 13433 | __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 13434 | crtc->primary->fb); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 13435 | } |
| 13436 | } else { |
| 13437 | intel_modeset_update_staged_output_state(dev); |
| 13438 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13439 | |
| 13440 | intel_modeset_check_state(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 13441 | } |
| 13442 | |
| 13443 | void intel_modeset_gem_init(struct drm_device *dev) |
| 13444 | { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13445 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 13446 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13447 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 13448 | mutex_lock(&dev->struct_mutex); |
| 13449 | intel_init_gt_powersave(dev); |
| 13450 | mutex_unlock(&dev->struct_mutex); |
| 13451 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 13452 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 13453 | |
| 13454 | intel_setup_overlay(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13455 | |
| 13456 | /* |
| 13457 | * Make sure any fbs we allocated at startup are properly |
| 13458 | * pinned & fenced. When we do the allocation it's too early |
| 13459 | * for this. |
| 13460 | */ |
| 13461 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 13462 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 13463 | obj = intel_fb_obj(c->primary->fb); |
| 13464 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13465 | continue; |
| 13466 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 13467 | if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13468 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 13469 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 13470 | drm_framebuffer_unreference(c->primary->fb); |
| 13471 | c->primary->fb = NULL; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13472 | } |
| 13473 | } |
| 13474 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13475 | } |
| 13476 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 13477 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 13478 | { |
| 13479 | struct drm_connector *connector = &intel_connector->base; |
| 13480 | |
| 13481 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 13482 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 13483 | } |
| 13484 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13485 | void intel_modeset_cleanup(struct drm_device *dev) |
| 13486 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13487 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 13488 | struct drm_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13489 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13490 | /* |
| 13491 | * Interrupts and polling as the first thing to avoid creating havoc. |
| 13492 | * Too much stuff here (turning of rps, connectors, ...) would |
| 13493 | * experience fancy races otherwise. |
| 13494 | */ |
| 13495 | drm_irq_uninstall(dev); |
Imre Deak | 1d0d343 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 13496 | intel_hpd_cancel_work(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 13497 | dev_priv->pm._irqs_disabled = true; |
| 13498 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13499 | /* |
| 13500 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 13501 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 13502 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 13503 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13504 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13505 | mutex_lock(&dev->struct_mutex); |
| 13506 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 13507 | intel_unregister_dsm_handler(); |
| 13508 | |
Chris Wilson | 973d04f | 2011-07-08 12:22:37 +0100 | [diff] [blame] | 13509 | intel_disable_fbc(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13510 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 13511 | intel_disable_gt_powersave(dev); |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 13512 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 13513 | ironlake_teardown_rc6(dev); |
| 13514 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 13515 | mutex_unlock(&dev->struct_mutex); |
| 13516 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 13517 | /* flush any delayed tasks or pending work */ |
| 13518 | flush_scheduled_work(); |
| 13519 | |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 13520 | /* destroy the backlight and sysfs files before encoders/connectors */ |
| 13521 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 13522 | struct intel_connector *intel_connector; |
| 13523 | |
| 13524 | intel_connector = to_intel_connector(connector); |
| 13525 | intel_connector->unregister(intel_connector); |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 13526 | } |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 13527 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13528 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 13529 | |
| 13530 | intel_cleanup_overlay(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 13531 | |
| 13532 | mutex_lock(&dev->struct_mutex); |
| 13533 | intel_cleanup_gt_powersave(dev); |
| 13534 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13535 | } |
| 13536 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 13537 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 13538 | * Return which encoder is currently attached for connector. |
| 13539 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 13540 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13541 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 13542 | return &intel_attached_encoder(connector)->base; |
| 13543 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13544 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 13545 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 13546 | struct intel_encoder *encoder) |
| 13547 | { |
| 13548 | connector->encoder = encoder; |
| 13549 | drm_mode_connector_attach_encoder(&connector->base, |
| 13550 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13551 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 13552 | |
| 13553 | /* |
| 13554 | * set vga decode state - true == enable VGA decode |
| 13555 | */ |
| 13556 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 13557 | { |
| 13558 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 13559 | unsigned reg = INTEL_INFO(dev)->gen >= 6 ? SNB_GMCH_CTRL : INTEL_GMCH_CTRL; |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 13560 | u16 gmch_ctrl; |
| 13561 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 13562 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 13563 | DRM_ERROR("failed to read control word\n"); |
| 13564 | return -EIO; |
| 13565 | } |
| 13566 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 13567 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 13568 | return 0; |
| 13569 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 13570 | if (state) |
| 13571 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 13572 | else |
| 13573 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 13574 | |
| 13575 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 13576 | DRM_ERROR("failed to write control word\n"); |
| 13577 | return -EIO; |
| 13578 | } |
| 13579 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 13580 | return 0; |
| 13581 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13582 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13583 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 13584 | |
| 13585 | u32 power_well_driver; |
| 13586 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13587 | int num_transcoders; |
| 13588 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13589 | struct intel_cursor_error_state { |
| 13590 | u32 control; |
| 13591 | u32 position; |
| 13592 | u32 base; |
| 13593 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 13594 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13595 | |
| 13596 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13597 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13598 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 13599 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 13600 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13601 | |
| 13602 | struct intel_plane_error_state { |
| 13603 | u32 control; |
| 13604 | u32 stride; |
| 13605 | u32 size; |
| 13606 | u32 pos; |
| 13607 | u32 addr; |
| 13608 | u32 surface; |
| 13609 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 13610 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13611 | |
| 13612 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13613 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13614 | enum transcoder cpu_transcoder; |
| 13615 | |
| 13616 | u32 conf; |
| 13617 | |
| 13618 | u32 htotal; |
| 13619 | u32 hblank; |
| 13620 | u32 hsync; |
| 13621 | u32 vtotal; |
| 13622 | u32 vblank; |
| 13623 | u32 vsync; |
| 13624 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13625 | }; |
| 13626 | |
| 13627 | struct intel_display_error_state * |
| 13628 | intel_display_capture_error_state(struct drm_device *dev) |
| 13629 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13630 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13631 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13632 | int transcoders[] = { |
| 13633 | TRANSCODER_A, |
| 13634 | TRANSCODER_B, |
| 13635 | TRANSCODER_C, |
| 13636 | TRANSCODER_EDP, |
| 13637 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13638 | int i; |
| 13639 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13640 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 13641 | return NULL; |
| 13642 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 13643 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13644 | if (error == NULL) |
| 13645 | return NULL; |
| 13646 | |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 13647 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 13648 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 13649 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13650 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13651 | error->pipe[i].power_domain_on = |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 13652 | intel_display_power_enabled_unlocked(dev_priv, |
| 13653 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13654 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 13655 | continue; |
| 13656 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 13657 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 13658 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 13659 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13660 | |
| 13661 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 13662 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 13663 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 13664 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 13665 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 13666 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 13667 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 13668 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13669 | if (INTEL_INFO(dev)->gen >= 4) { |
| 13670 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 13671 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 13672 | } |
| 13673 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13674 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 13675 | |
Sonika Jindal | 3abfce7 | 2014-07-21 15:23:43 +0530 | [diff] [blame] | 13676 | if (HAS_GMCH_DISPLAY(dev)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 13677 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13678 | } |
| 13679 | |
| 13680 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; |
| 13681 | if (HAS_DDI(dev_priv->dev)) |
| 13682 | error->num_transcoders++; /* Account for eDP. */ |
| 13683 | |
| 13684 | for (i = 0; i < error->num_transcoders; i++) { |
| 13685 | enum transcoder cpu_transcoder = transcoders[i]; |
| 13686 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13687 | error->transcoder[i].power_domain_on = |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 13688 | intel_display_power_enabled_unlocked(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 13689 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13690 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 13691 | continue; |
| 13692 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13693 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 13694 | |
| 13695 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 13696 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 13697 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 13698 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 13699 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 13700 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 13701 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13702 | } |
| 13703 | |
| 13704 | return error; |
| 13705 | } |
| 13706 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13707 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 13708 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13709 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13710 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13711 | struct drm_device *dev, |
| 13712 | struct intel_display_error_state *error) |
| 13713 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13714 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13715 | int i; |
| 13716 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13717 | if (!error) |
| 13718 | return; |
| 13719 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13720 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 13721 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13722 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 13723 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13724 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13725 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13726 | err_printf(m, " Power: %s\n", |
| 13727 | error->pipe[i].power_domain_on ? "on" : "off"); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13728 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 13729 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13730 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13731 | err_printf(m, "Plane [%d]:\n", i); |
| 13732 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 13733 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 13734 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13735 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 13736 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 13737 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 13738 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13739 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13740 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13741 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 13742 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13743 | } |
| 13744 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13745 | err_printf(m, "Cursor [%d]:\n", i); |
| 13746 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 13747 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 13748 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13749 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13750 | |
| 13751 | for (i = 0; i < error->num_transcoders; i++) { |
Chris Wilson | 1cf84bb | 2013-10-21 09:10:33 +0100 | [diff] [blame] | 13752 | err_printf(m, "CPU transcoder: %c\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13753 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13754 | err_printf(m, " Power: %s\n", |
| 13755 | error->transcoder[i].power_domain_on ? "on" : "off"); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13756 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 13757 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 13758 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 13759 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 13760 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 13761 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 13762 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 13763 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13764 | } |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 13765 | |
| 13766 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) |
| 13767 | { |
| 13768 | struct intel_crtc *crtc; |
| 13769 | |
| 13770 | for_each_intel_crtc(dev, crtc) { |
| 13771 | struct intel_unpin_work *work; |
| 13772 | unsigned long irqflags; |
| 13773 | |
| 13774 | spin_lock_irqsave(&dev->event_lock, irqflags); |
| 13775 | |
| 13776 | work = crtc->unpin_work; |
| 13777 | |
| 13778 | if (work && work->event && |
| 13779 | work->event->base.file_priv == file) { |
| 13780 | kfree(work->event); |
| 13781 | work->event = NULL; |
| 13782 | } |
| 13783 | |
| 13784 | spin_unlock_irqrestore(&dev->event_lock, irqflags); |
| 13785 | } |
| 13786 | } |