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ä | 57e22f4 | 2013-11-06 13:56:28 -0200 | [diff] [blame] | 895 | static void g4x_wait_for_vblank(struct drm_device *dev, int pipe) |
Paulo Zanoni | a928d53 | 2012-05-04 17:18:15 -0300 | [diff] [blame] | 896 | { |
| 897 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 57e22f4 | 2013-11-06 13:56:28 -0200 | [diff] [blame] | 898 | u32 frame, frame_reg = PIPE_FRMCOUNT_GM45(pipe); |
Paulo Zanoni | a928d53 | 2012-05-04 17:18:15 -0300 | [diff] [blame] | 899 | |
| 900 | frame = I915_READ(frame_reg); |
| 901 | |
| 902 | if (wait_for(I915_READ_NOTRACE(frame_reg) != frame, 50)) |
Damien Lespiau | 31e4b89 | 2014-08-18 13:51:00 +0100 | [diff] [blame] | 903 | WARN(1, "vblank wait on pipe %c timed out\n", |
| 904 | pipe_name(pipe)); |
Paulo Zanoni | a928d53 | 2012-05-04 17:18:15 -0300 | [diff] [blame] | 905 | } |
| 906 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 907 | /** |
| 908 | * intel_wait_for_vblank - wait for vblank on a given pipe |
| 909 | * @dev: drm device |
| 910 | * @pipe: pipe to wait for |
| 911 | * |
| 912 | * Wait for vblank to occur on a given pipe. Needed for various bits of |
| 913 | * mode setting code. |
| 914 | */ |
| 915 | void intel_wait_for_vblank(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 916 | { |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 917 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 918 | int pipestat_reg = PIPESTAT(pipe); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 919 | |
Ville Syrjälä | 57e22f4 | 2013-11-06 13:56:28 -0200 | [diff] [blame] | 920 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) { |
| 921 | g4x_wait_for_vblank(dev, pipe); |
Paulo Zanoni | a928d53 | 2012-05-04 17:18:15 -0300 | [diff] [blame] | 922 | return; |
| 923 | } |
| 924 | |
Chris Wilson | 300387c | 2010-09-05 20:25:43 +0100 | [diff] [blame] | 925 | /* Clear existing vblank status. Note this will clear any other |
| 926 | * sticky status fields as well. |
| 927 | * |
| 928 | * This races with i915_driver_irq_handler() with the result |
| 929 | * that either function could miss a vblank event. Here it is not |
| 930 | * fatal, as we will either wait upon the next vblank interrupt or |
| 931 | * timeout. Generally speaking intel_wait_for_vblank() is only |
| 932 | * called during modeset at which time the GPU should be idle and |
| 933 | * should *not* be performing page flips and thus not waiting on |
| 934 | * vblanks... |
| 935 | * Currently, the result of us stealing a vblank from the irq |
| 936 | * handler is that a single frame will be skipped during swapbuffers. |
| 937 | */ |
| 938 | I915_WRITE(pipestat_reg, |
| 939 | I915_READ(pipestat_reg) | PIPE_VBLANK_INTERRUPT_STATUS); |
| 940 | |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 941 | /* Wait for vblank interrupt bit to set */ |
Chris Wilson | 481b6af | 2010-08-23 17:43:35 +0100 | [diff] [blame] | 942 | if (wait_for(I915_READ(pipestat_reg) & |
| 943 | PIPE_VBLANK_INTERRUPT_STATUS, |
| 944 | 50)) |
Damien Lespiau | 31e4b89 | 2014-08-18 13:51:00 +0100 | [diff] [blame] | 945 | DRM_DEBUG_KMS("vblank wait on pipe %c timed out\n", |
| 946 | pipe_name(pipe)); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 947 | } |
| 948 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 949 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 950 | { |
| 951 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 952 | u32 reg = PIPEDSL(pipe); |
| 953 | u32 line1, line2; |
| 954 | u32 line_mask; |
| 955 | |
| 956 | if (IS_GEN2(dev)) |
| 957 | line_mask = DSL_LINEMASK_GEN2; |
| 958 | else |
| 959 | line_mask = DSL_LINEMASK_GEN3; |
| 960 | |
| 961 | line1 = I915_READ(reg) & line_mask; |
| 962 | mdelay(5); |
| 963 | line2 = I915_READ(reg) & line_mask; |
| 964 | |
| 965 | return line1 == line2; |
| 966 | } |
| 967 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 968 | /* |
| 969 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 970 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 971 | * |
| 972 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 973 | * spinning on the vblank interrupt status bit, since we won't actually |
| 974 | * see an interrupt when the pipe is disabled. |
| 975 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 976 | * On Gen4 and above: |
| 977 | * wait for the pipe register state bit to turn off |
| 978 | * |
| 979 | * Otherwise: |
| 980 | * wait for the display line value to settle (it usually |
| 981 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 982 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 983 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 984 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 985 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 986 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 987 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 988 | enum transcoder cpu_transcoder = crtc->config.cpu_transcoder; |
| 989 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 990 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 991 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 992 | int reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 993 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 994 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 995 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 996 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 997 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 998 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 999 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1000 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1001 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1002 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1005 | /* |
| 1006 | * ibx_digital_port_connected - is the specified port connected? |
| 1007 | * @dev_priv: i915 private structure |
| 1008 | * @port: the port to test |
| 1009 | * |
| 1010 | * Returns true if @port is connected, false otherwise. |
| 1011 | */ |
| 1012 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 1013 | struct intel_digital_port *port) |
| 1014 | { |
| 1015 | u32 bit; |
| 1016 | |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1017 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1018 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1019 | case PORT_B: |
| 1020 | bit = SDE_PORTB_HOTPLUG; |
| 1021 | break; |
| 1022 | case PORT_C: |
| 1023 | bit = SDE_PORTC_HOTPLUG; |
| 1024 | break; |
| 1025 | case PORT_D: |
| 1026 | bit = SDE_PORTD_HOTPLUG; |
| 1027 | break; |
| 1028 | default: |
| 1029 | return true; |
| 1030 | } |
| 1031 | } else { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1032 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1033 | case PORT_B: |
| 1034 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 1035 | break; |
| 1036 | case PORT_C: |
| 1037 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 1038 | break; |
| 1039 | case PORT_D: |
| 1040 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 1041 | break; |
| 1042 | default: |
| 1043 | return true; |
| 1044 | } |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1045 | } |
| 1046 | |
| 1047 | return I915_READ(SDEISR) & bit; |
| 1048 | } |
| 1049 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1050 | static const char *state_string(bool enabled) |
| 1051 | { |
| 1052 | return enabled ? "on" : "off"; |
| 1053 | } |
| 1054 | |
| 1055 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1056 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1057 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1058 | { |
| 1059 | int reg; |
| 1060 | u32 val; |
| 1061 | bool cur_state; |
| 1062 | |
| 1063 | reg = DPLL(pipe); |
| 1064 | val = I915_READ(reg); |
| 1065 | cur_state = !!(val & DPLL_VCO_ENABLE); |
| 1066 | WARN(cur_state != state, |
| 1067 | "PLL state assertion failure (expected %s, current %s)\n", |
| 1068 | state_string(state), state_string(cur_state)); |
| 1069 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1070 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1071 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
| 1072 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
| 1073 | { |
| 1074 | u32 val; |
| 1075 | bool cur_state; |
| 1076 | |
| 1077 | mutex_lock(&dev_priv->dpio_lock); |
| 1078 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
| 1079 | mutex_unlock(&dev_priv->dpio_lock); |
| 1080 | |
| 1081 | cur_state = val & DSI_PLL_VCO_EN; |
| 1082 | WARN(cur_state != state, |
| 1083 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
| 1084 | state_string(state), state_string(cur_state)); |
| 1085 | } |
| 1086 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) |
| 1087 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) |
| 1088 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1089 | struct intel_shared_dpll * |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1090 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1091 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1092 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 1093 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 1094 | if (crtc->config.shared_dpll < 0) |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1095 | return NULL; |
| 1096 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 1097 | return &dev_priv->shared_dplls[crtc->config.shared_dpll]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1098 | } |
| 1099 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1100 | /* For ILK+ */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1101 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
| 1102 | struct intel_shared_dpll *pll, |
| 1103 | bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1104 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1105 | bool cur_state; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1106 | struct intel_dpll_hw_state hw_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1107 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1108 | if (WARN (!pll, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1109 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1110 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1111 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1112 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1113 | WARN(cur_state != state, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1114 | "%s assertion failure (expected %s, current %s)\n", |
| 1115 | pll->name, state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1116 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1117 | |
| 1118 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1119 | enum pipe pipe, bool state) |
| 1120 | { |
| 1121 | int reg; |
| 1122 | u32 val; |
| 1123 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1124 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1125 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1126 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1127 | if (HAS_DDI(dev_priv->dev)) { |
| 1128 | /* DDI does not have a specific FDI_TX register */ |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1129 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1130 | val = I915_READ(reg); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1131 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1132 | } else { |
| 1133 | reg = FDI_TX_CTL(pipe); |
| 1134 | val = I915_READ(reg); |
| 1135 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1136 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1137 | WARN(cur_state != state, |
| 1138 | "FDI TX state assertion failure (expected %s, current %s)\n", |
| 1139 | state_string(state), state_string(cur_state)); |
| 1140 | } |
| 1141 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1142 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1143 | |
| 1144 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1145 | enum pipe pipe, bool state) |
| 1146 | { |
| 1147 | int reg; |
| 1148 | u32 val; |
| 1149 | bool cur_state; |
| 1150 | |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1151 | reg = FDI_RX_CTL(pipe); |
| 1152 | val = I915_READ(reg); |
| 1153 | cur_state = !!(val & FDI_RX_ENABLE); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1154 | WARN(cur_state != state, |
| 1155 | "FDI RX state assertion failure (expected %s, current %s)\n", |
| 1156 | state_string(state), state_string(cur_state)); |
| 1157 | } |
| 1158 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1159 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1160 | |
| 1161 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1162 | enum pipe pipe) |
| 1163 | { |
| 1164 | int reg; |
| 1165 | u32 val; |
| 1166 | |
| 1167 | /* ILK FDI PLL is always enabled */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1168 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1169 | return; |
| 1170 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1171 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1172 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1173 | return; |
| 1174 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1175 | reg = FDI_TX_CTL(pipe); |
| 1176 | val = I915_READ(reg); |
| 1177 | WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
| 1178 | } |
| 1179 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1180 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1181 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1182 | { |
| 1183 | int reg; |
| 1184 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1185 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1186 | |
| 1187 | reg = FDI_RX_CTL(pipe); |
| 1188 | val = I915_READ(reg); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1189 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
| 1190 | WARN(cur_state != state, |
| 1191 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
| 1192 | state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1193 | } |
| 1194 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1195 | static void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1196 | enum pipe pipe) |
| 1197 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1198 | struct drm_device *dev = dev_priv->dev; |
| 1199 | int pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1200 | u32 val; |
| 1201 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1202 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1203 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1204 | if (WARN_ON(HAS_DDI(dev))) |
| 1205 | return; |
| 1206 | |
| 1207 | if (HAS_PCH_SPLIT(dev)) { |
| 1208 | u32 port_sel; |
| 1209 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1210 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1211 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1212 | |
| 1213 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1214 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1215 | panel_pipe = PIPE_B; |
| 1216 | /* XXX: else fix for eDP */ |
| 1217 | } else if (IS_VALLEYVIEW(dev)) { |
| 1218 | /* presumably write lock depends on pipe, not port select */ |
| 1219 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1220 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1221 | } else { |
| 1222 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1223 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1224 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1225 | } |
| 1226 | |
| 1227 | val = I915_READ(pp_reg); |
| 1228 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1229 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1230 | locked = false; |
| 1231 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1232 | WARN(panel_pipe == pipe && locked, |
| 1233 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1234 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1235 | } |
| 1236 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1237 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1238 | enum pipe pipe, bool state) |
| 1239 | { |
| 1240 | struct drm_device *dev = dev_priv->dev; |
| 1241 | bool cur_state; |
| 1242 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1243 | if (IS_845G(dev) || IS_I865G(dev)) |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1244 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1245 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1246 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1247 | |
| 1248 | WARN(cur_state != state, |
| 1249 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
| 1250 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
| 1251 | } |
| 1252 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1253 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1254 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1255 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1256 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1257 | { |
| 1258 | int reg; |
| 1259 | u32 val; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1260 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1261 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1262 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1263 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame^] | 1264 | /* if we need the pipe quirk it must be always on */ |
| 1265 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1266 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1267 | state = true; |
| 1268 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 1269 | if (!intel_display_power_enabled(dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 1270 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1271 | cur_state = false; |
| 1272 | } else { |
| 1273 | reg = PIPECONF(cpu_transcoder); |
| 1274 | val = I915_READ(reg); |
| 1275 | cur_state = !!(val & PIPECONF_ENABLE); |
| 1276 | } |
| 1277 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1278 | WARN(cur_state != state, |
| 1279 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1280 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1281 | } |
| 1282 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1283 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1284 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1285 | { |
| 1286 | int reg; |
| 1287 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1288 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1289 | |
| 1290 | reg = DSPCNTR(plane); |
| 1291 | val = I915_READ(reg); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1292 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
| 1293 | WARN(cur_state != state, |
| 1294 | "plane %c assertion failure (expected %s, current %s)\n", |
| 1295 | plane_name(plane), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1296 | } |
| 1297 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1298 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1299 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1300 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1301 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1302 | enum pipe pipe) |
| 1303 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1304 | struct drm_device *dev = dev_priv->dev; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1305 | int reg, i; |
| 1306 | u32 val; |
| 1307 | int cur_pipe; |
| 1308 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1309 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1310 | if (INTEL_INFO(dev)->gen >= 4) { |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1311 | reg = DSPCNTR(pipe); |
| 1312 | val = I915_READ(reg); |
Damien Lespiau | 83f26f1 | 2014-03-17 17:59:48 +0000 | [diff] [blame] | 1313 | WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1314 | "plane %c assertion failure, should be disabled but not\n", |
| 1315 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1316 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1317 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1318 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1319 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1320 | for_each_pipe(dev_priv, i) { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1321 | reg = DSPCNTR(i); |
| 1322 | val = I915_READ(reg); |
| 1323 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 1324 | DISPPLANE_SEL_PIPE_SHIFT; |
| 1325 | WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1326 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1327 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1328 | } |
| 1329 | } |
| 1330 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1331 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1332 | enum pipe pipe) |
| 1333 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1334 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1335 | int reg, sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1336 | u32 val; |
| 1337 | |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1338 | if (IS_VALLEYVIEW(dev)) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1339 | for_each_sprite(pipe, sprite) { |
| 1340 | reg = SPCNTR(pipe, sprite); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1341 | val = I915_READ(reg); |
Damien Lespiau | 83f26f1 | 2014-03-17 17:59:48 +0000 | [diff] [blame] | 1342 | WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1343 | "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] | 1344 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1345 | } |
| 1346 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 1347 | reg = SPRCTL(pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1348 | val = I915_READ(reg); |
Damien Lespiau | 83f26f1 | 2014-03-17 17:59:48 +0000 | [diff] [blame] | 1349 | WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1350 | "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] | 1351 | plane_name(pipe), pipe_name(pipe)); |
| 1352 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1353 | reg = DVSCNTR(pipe); |
| 1354 | val = I915_READ(reg); |
Damien Lespiau | 83f26f1 | 2014-03-17 17:59:48 +0000 | [diff] [blame] | 1355 | WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1356 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1357 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1358 | } |
| 1359 | } |
| 1360 | |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 1361 | 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] | 1362 | { |
| 1363 | u32 val; |
| 1364 | bool enabled; |
| 1365 | |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 1366 | 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] | 1367 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1368 | val = I915_READ(PCH_DREF_CONTROL); |
| 1369 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | |
| 1370 | DREF_SUPERSPREAD_SOURCE_MASK)); |
| 1371 | WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
| 1372 | } |
| 1373 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1374 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1375 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1376 | { |
| 1377 | int reg; |
| 1378 | u32 val; |
| 1379 | bool enabled; |
| 1380 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1381 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1382 | val = I915_READ(reg); |
| 1383 | enabled = !!(val & TRANS_ENABLE); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1384 | WARN(enabled, |
| 1385 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1386 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1387 | } |
| 1388 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1389 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1390 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1391 | { |
| 1392 | if ((val & DP_PORT_EN) == 0) |
| 1393 | return false; |
| 1394 | |
| 1395 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1396 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); |
| 1397 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); |
| 1398 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1399 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1400 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1401 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1402 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1403 | } else { |
| 1404 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1405 | return false; |
| 1406 | } |
| 1407 | return true; |
| 1408 | } |
| 1409 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1410 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1411 | enum pipe pipe, u32 val) |
| 1412 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1413 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1414 | return false; |
| 1415 | |
| 1416 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1417 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1418 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1419 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1420 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1421 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1422 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1423 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1424 | return false; |
| 1425 | } |
| 1426 | return true; |
| 1427 | } |
| 1428 | |
| 1429 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1430 | enum pipe pipe, u32 val) |
| 1431 | { |
| 1432 | if ((val & LVDS_PORT_EN) == 0) |
| 1433 | return false; |
| 1434 | |
| 1435 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1436 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1437 | return false; |
| 1438 | } else { |
| 1439 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1440 | return false; |
| 1441 | } |
| 1442 | return true; |
| 1443 | } |
| 1444 | |
| 1445 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1446 | enum pipe pipe, u32 val) |
| 1447 | { |
| 1448 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1449 | return false; |
| 1450 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1451 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1452 | return false; |
| 1453 | } else { |
| 1454 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1455 | return false; |
| 1456 | } |
| 1457 | return true; |
| 1458 | } |
| 1459 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1460 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1461 | enum pipe pipe, int reg, u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1462 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1463 | u32 val = I915_READ(reg); |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1464 | WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1465 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1466 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1467 | |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1468 | WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
| 1469 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1470 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
| 1474 | enum pipe pipe, int reg) |
| 1475 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1476 | u32 val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1477 | WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1478 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1479 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1480 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1481 | WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1482 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1483 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1484 | } |
| 1485 | |
| 1486 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1487 | enum pipe pipe) |
| 1488 | { |
| 1489 | int reg; |
| 1490 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1491 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1492 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1493 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1494 | 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] | 1495 | |
| 1496 | reg = PCH_ADPA; |
| 1497 | val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1498 | WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1499 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1500 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1501 | |
| 1502 | reg = PCH_LVDS; |
| 1503 | val = I915_READ(reg); |
Xu, Anhua | b70ad58 | 2012-08-13 03:08:33 +0000 | [diff] [blame] | 1504 | WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1505 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1506 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1507 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1508 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1509 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1510 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1511 | } |
| 1512 | |
Jesse Barnes | 40e9cf6 | 2013-10-03 11:35:46 -0700 | [diff] [blame] | 1513 | static void intel_init_dpio(struct drm_device *dev) |
| 1514 | { |
| 1515 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1516 | |
| 1517 | if (!IS_VALLEYVIEW(dev)) |
| 1518 | return; |
| 1519 | |
Chon Ming Lee | a09cadd | 2014-04-09 13:28:14 +0300 | [diff] [blame] | 1520 | /* |
| 1521 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), |
| 1522 | * CHV x1 PHY (DP/HDMI D) |
| 1523 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) |
| 1524 | */ |
| 1525 | if (IS_CHERRYVIEW(dev)) { |
| 1526 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; |
| 1527 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; |
| 1528 | } else { |
| 1529 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; |
| 1530 | } |
Jesse Barnes | 5382f5f35 | 2013-12-16 16:34:24 -0800 | [diff] [blame] | 1531 | } |
| 1532 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1533 | static void vlv_enable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1534 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1535 | struct drm_device *dev = crtc->base.dev; |
| 1536 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1537 | int reg = DPLL(crtc->pipe); |
| 1538 | u32 dpll = crtc->config.dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1539 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1540 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1541 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1542 | /* No really, not for ILK+ */ |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1543 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); |
| 1544 | |
| 1545 | /* PLL is protected by panel, make sure we can write it */ |
Jani Nikula | 6a9e736 | 2014-08-22 15:06:35 +0300 | [diff] [blame] | 1546 | if (IS_MOBILE(dev_priv->dev)) |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1547 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1548 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1549 | I915_WRITE(reg, dpll); |
| 1550 | POSTING_READ(reg); |
| 1551 | udelay(150); |
| 1552 | |
| 1553 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1554 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); |
| 1555 | |
| 1556 | I915_WRITE(DPLL_MD(crtc->pipe), crtc->config.dpll_hw_state.dpll_md); |
| 1557 | POSTING_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1558 | |
| 1559 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1560 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1561 | POSTING_READ(reg); |
| 1562 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1563 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1564 | POSTING_READ(reg); |
| 1565 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1566 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1567 | POSTING_READ(reg); |
| 1568 | udelay(150); /* wait for warmup */ |
| 1569 | } |
| 1570 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1571 | static void chv_enable_pll(struct intel_crtc *crtc) |
| 1572 | { |
| 1573 | struct drm_device *dev = crtc->base.dev; |
| 1574 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1575 | int pipe = crtc->pipe; |
| 1576 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1577 | u32 tmp; |
| 1578 | |
| 1579 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 1580 | |
| 1581 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); |
| 1582 | |
| 1583 | mutex_lock(&dev_priv->dpio_lock); |
| 1584 | |
| 1585 | /* Enable back the 10bit clock to display controller */ |
| 1586 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1587 | tmp |= DPIO_DCLKP_EN; |
| 1588 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1589 | |
| 1590 | /* |
| 1591 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1592 | */ |
| 1593 | udelay(1); |
| 1594 | |
| 1595 | /* Enable PLL */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1596 | I915_WRITE(DPLL(pipe), crtc->config.dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1597 | |
| 1598 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1599 | 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] | 1600 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
| 1601 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1602 | /* not sure when this should be written */ |
| 1603 | I915_WRITE(DPLL_MD(pipe), crtc->config.dpll_hw_state.dpll_md); |
| 1604 | POSTING_READ(DPLL_MD(pipe)); |
| 1605 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1606 | mutex_unlock(&dev_priv->dpio_lock); |
| 1607 | } |
| 1608 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1609 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1610 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1611 | struct drm_device *dev = crtc->base.dev; |
| 1612 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1613 | int reg = DPLL(crtc->pipe); |
| 1614 | u32 dpll = crtc->config.dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1615 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1616 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1617 | |
| 1618 | /* No really, not for ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1619 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1620 | |
| 1621 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1622 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1623 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1624 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1625 | I915_WRITE(reg, dpll); |
| 1626 | |
| 1627 | /* Wait for the clocks to stabilize. */ |
| 1628 | POSTING_READ(reg); |
| 1629 | udelay(150); |
| 1630 | |
| 1631 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1632 | I915_WRITE(DPLL_MD(crtc->pipe), |
| 1633 | crtc->config.dpll_hw_state.dpll_md); |
| 1634 | } else { |
| 1635 | /* The pixel multiplier can only be updated once the |
| 1636 | * DPLL is enabled and the clocks are stable. |
| 1637 | * |
| 1638 | * So write it again. |
| 1639 | */ |
| 1640 | I915_WRITE(reg, dpll); |
| 1641 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1642 | |
| 1643 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1644 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1645 | POSTING_READ(reg); |
| 1646 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1647 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1648 | POSTING_READ(reg); |
| 1649 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1650 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1651 | POSTING_READ(reg); |
| 1652 | udelay(150); /* wait for warmup */ |
| 1653 | } |
| 1654 | |
| 1655 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1656 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1657 | * @dev_priv: i915 private structure |
| 1658 | * @pipe: pipe PLL to disable |
| 1659 | * |
| 1660 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1661 | * |
| 1662 | * Note! This is for pre-ILK only. |
| 1663 | */ |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1664 | static void i9xx_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1665 | { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame^] | 1666 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1667 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1668 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1669 | return; |
| 1670 | |
| 1671 | /* Make sure the pipe isn't still relying on us */ |
| 1672 | assert_pipe_disabled(dev_priv, pipe); |
| 1673 | |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1674 | I915_WRITE(DPLL(pipe), 0); |
| 1675 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1676 | } |
| 1677 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1678 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1679 | { |
| 1680 | u32 val = 0; |
| 1681 | |
| 1682 | /* Make sure the pipe isn't still relying on us */ |
| 1683 | assert_pipe_disabled(dev_priv, pipe); |
| 1684 | |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1685 | /* |
| 1686 | * Leave integrated clock source and reference clock enabled for pipe B. |
| 1687 | * The latter is needed for VGA hotplug / manual detection. |
| 1688 | */ |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1689 | if (pipe == PIPE_B) |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1690 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1691 | I915_WRITE(DPLL(pipe), val); |
| 1692 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1693 | |
| 1694 | } |
| 1695 | |
| 1696 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1697 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1698 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1699 | u32 val; |
| 1700 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1701 | /* Make sure the pipe isn't still relying on us */ |
| 1702 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1703 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1704 | /* Set PLL en = 0 */ |
Ville Syrjälä | d17ec4c | 2014-06-28 02:03:59 +0300 | [diff] [blame] | 1705 | val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1706 | if (pipe != PIPE_A) |
| 1707 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1708 | I915_WRITE(DPLL(pipe), val); |
| 1709 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1710 | |
| 1711 | mutex_lock(&dev_priv->dpio_lock); |
| 1712 | |
| 1713 | /* Disable 10bit clock to display controller */ |
| 1714 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1715 | val &= ~DPIO_DCLKP_EN; |
| 1716 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1717 | |
Ville Syrjälä | 61407f6 | 2014-05-27 16:32:55 +0300 | [diff] [blame] | 1718 | /* disable left/right clock distribution */ |
| 1719 | if (pipe != PIPE_B) { |
| 1720 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); |
| 1721 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); |
| 1722 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); |
| 1723 | } else { |
| 1724 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); |
| 1725 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); |
| 1726 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); |
| 1727 | } |
| 1728 | |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1729 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1732 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
| 1733 | struct intel_digital_port *dport) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1734 | { |
| 1735 | u32 port_mask; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1736 | int dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1737 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1738 | switch (dport->port) { |
| 1739 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1740 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1741 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1742 | break; |
| 1743 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1744 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1745 | dpll_reg = DPLL(0); |
| 1746 | break; |
| 1747 | case PORT_D: |
| 1748 | port_mask = DPLL_PORTD_READY_MASK; |
| 1749 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1750 | break; |
| 1751 | default: |
| 1752 | BUG(); |
| 1753 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1754 | |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1755 | if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1756 | 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] | 1757 | port_name(dport->port), I915_READ(dpll_reg)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1758 | } |
| 1759 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1760 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
| 1761 | { |
| 1762 | struct drm_device *dev = crtc->base.dev; |
| 1763 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1764 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 1765 | |
Chris Wilson | be19f0f | 2014-05-28 16:16:42 +0100 | [diff] [blame] | 1766 | if (WARN_ON(pll == NULL)) |
| 1767 | return; |
| 1768 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1769 | WARN_ON(!pll->refcount); |
| 1770 | if (pll->active == 0) { |
| 1771 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); |
| 1772 | WARN_ON(pll->on); |
| 1773 | assert_shared_dpll_disabled(dev_priv, pll); |
| 1774 | |
| 1775 | pll->mode_set(dev_priv, pll); |
| 1776 | } |
| 1777 | } |
| 1778 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1779 | /** |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1780 | * intel_enable_shared_dpll - enable PCH PLL |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1781 | * @dev_priv: i915 private structure |
| 1782 | * @pipe: pipe PLL to enable |
| 1783 | * |
| 1784 | * The PCH PLL needs to be enabled before the PCH transcoder, since it |
| 1785 | * drives the transcoder clock. |
| 1786 | */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1787 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1788 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1789 | struct drm_device *dev = crtc->base.dev; |
| 1790 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1791 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1792 | |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1793 | if (WARN_ON(pll == NULL)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1794 | return; |
| 1795 | |
| 1796 | if (WARN_ON(pll->refcount == 0)) |
| 1797 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1798 | |
Damien Lespiau | 74dd692 | 2014-07-29 18:06:17 +0100 | [diff] [blame] | 1799 | 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] | 1800 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1801 | crtc->base.base.id); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1802 | |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1803 | if (pll->active++) { |
| 1804 | WARN_ON(!pll->on); |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1805 | assert_shared_dpll_enabled(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1806 | return; |
| 1807 | } |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1808 | WARN_ON(pll->on); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1809 | |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1810 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 1811 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1812 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1813 | pll->enable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1814 | pll->on = true; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1815 | } |
| 1816 | |
Damien Lespiau | f6daaec | 2014-08-09 23:00:56 +0100 | [diff] [blame] | 1817 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1818 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1819 | struct drm_device *dev = crtc->base.dev; |
| 1820 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1821 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 4c609cb | 2011-09-02 12:52:11 -0700 | [diff] [blame] | 1822 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1823 | /* PCH only available on ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1824 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1825 | if (WARN_ON(pll == NULL)) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1826 | return; |
| 1827 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1828 | if (WARN_ON(pll->refcount == 0)) |
| 1829 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1830 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1831 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
| 1832 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1833 | crtc->base.base.id); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1834 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1835 | if (WARN_ON(pll->active == 0)) { |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1836 | assert_shared_dpll_disabled(dev_priv, pll); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1837 | return; |
| 1838 | } |
| 1839 | |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1840 | assert_shared_dpll_enabled(dev_priv, pll); |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1841 | WARN_ON(!pll->on); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1842 | if (--pll->active) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1843 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1844 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1845 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1846 | pll->disable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1847 | pll->on = false; |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1848 | |
| 1849 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1850 | } |
| 1851 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1852 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1853 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1854 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1855 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1856 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1857 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1858 | uint32_t reg, val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1859 | |
| 1860 | /* PCH only available on ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1861 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1862 | |
| 1863 | /* Make sure PCH DPLL is enabled */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 1864 | assert_shared_dpll_enabled(dev_priv, |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1865 | intel_crtc_to_shared_dpll(intel_crtc)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1866 | |
| 1867 | /* FDI must be feeding us bits for PCH ports */ |
| 1868 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1869 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1870 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1871 | if (HAS_PCH_CPT(dev)) { |
| 1872 | /* Workaround: Set the timing override bit before enabling the |
| 1873 | * pch transcoder. */ |
| 1874 | reg = TRANS_CHICKEN2(pipe); |
| 1875 | val = I915_READ(reg); |
| 1876 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1877 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1878 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1879 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1880 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1881 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1882 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1883 | |
| 1884 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1885 | /* |
| 1886 | * make the BPC in transcoder be consistent with |
| 1887 | * that in pipeconf reg. |
| 1888 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1889 | val &= ~PIPECONF_BPC_MASK; |
| 1890 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1891 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1892 | |
| 1893 | val &= ~TRANS_INTERLACE_MASK; |
| 1894 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1895 | if (HAS_PCH_IBX(dev_priv->dev) && |
| 1896 | intel_pipe_has_type(crtc, INTEL_OUTPUT_SDVO)) |
| 1897 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1898 | else |
| 1899 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1900 | else |
| 1901 | val |= TRANS_PROGRESSIVE; |
| 1902 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1903 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1904 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1905 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1906 | } |
| 1907 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1908 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1909 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1910 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1911 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1912 | |
| 1913 | /* PCH only available on ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1914 | BUG_ON(INTEL_INFO(dev_priv->dev)->gen < 5); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1915 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1916 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1917 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1918 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1919 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1920 | /* Workaround: set timing override bit. */ |
| 1921 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1922 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1923 | I915_WRITE(_TRANSA_CHICKEN2, val); |
| 1924 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1925 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1926 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1927 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1928 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1929 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1930 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1931 | else |
| 1932 | val |= TRANS_PROGRESSIVE; |
| 1933 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1934 | I915_WRITE(LPT_TRANSCONF, val); |
| 1935 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1936 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1937 | } |
| 1938 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1939 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1940 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1941 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1942 | struct drm_device *dev = dev_priv->dev; |
| 1943 | uint32_t reg, val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1944 | |
| 1945 | /* FDI relies on the transcoder */ |
| 1946 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 1947 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 1948 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1949 | /* Ports must be off as well */ |
| 1950 | assert_pch_ports_disabled(dev_priv, pipe); |
| 1951 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1952 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1953 | val = I915_READ(reg); |
| 1954 | val &= ~TRANS_ENABLE; |
| 1955 | I915_WRITE(reg, val); |
| 1956 | /* wait for PCH transcoder off, transcoder state */ |
| 1957 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1958 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1959 | |
| 1960 | if (!HAS_PCH_IBX(dev)) { |
| 1961 | /* Workaround: Clear the timing override chicken bit again. */ |
| 1962 | reg = TRANS_CHICKEN2(pipe); |
| 1963 | val = I915_READ(reg); |
| 1964 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1965 | I915_WRITE(reg, val); |
| 1966 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1967 | } |
| 1968 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 1969 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1970 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1971 | u32 val; |
| 1972 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1973 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1974 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1975 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1976 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1977 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 1978 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1979 | |
| 1980 | /* Workaround: clear timing override bit. */ |
| 1981 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1982 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1983 | I915_WRITE(_TRANSA_CHICKEN2, val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 1987 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1988 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1989 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1990 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1991 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1992 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 1993 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1994 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 1995 | struct drm_device *dev = crtc->base.dev; |
| 1996 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1997 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1998 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1999 | pipe); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2000 | enum pipe pch_transcoder; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2001 | int reg; |
| 2002 | u32 val; |
| 2003 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2004 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2005 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2006 | assert_sprites_disabled(dev_priv, pipe); |
| 2007 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 2008 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2009 | pch_transcoder = TRANSCODER_A; |
| 2010 | else |
| 2011 | pch_transcoder = pipe; |
| 2012 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2013 | /* |
| 2014 | * A pipe without a PLL won't actually be able to drive bits from |
| 2015 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 2016 | * need the check. |
| 2017 | */ |
| 2018 | if (!HAS_PCH_SPLIT(dev_priv->dev)) |
Paulo Zanoni | fbf3218 | 2014-01-17 13:51:11 -0200 | [diff] [blame] | 2019 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 2020 | assert_dsi_pll_enabled(dev_priv); |
| 2021 | else |
| 2022 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2023 | else { |
Paulo Zanoni | 30421c4 | 2014-01-17 13:51:10 -0200 | [diff] [blame] | 2024 | if (crtc->config.has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2025 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2026 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2027 | assert_fdi_tx_pll_enabled(dev_priv, |
| 2028 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2029 | } |
| 2030 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 2031 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2032 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2033 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2034 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2035 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame^] | 2036 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 2037 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2038 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2039 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2040 | |
| 2041 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 2042 | POSTING_READ(reg); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2043 | } |
| 2044 | |
| 2045 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2046 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2047 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2048 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2049 | * Disable the pipe of @crtc, making sure that various hardware |
| 2050 | * specific requirements are met, if applicable, e.g. plane |
| 2051 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2052 | * |
| 2053 | * Will wait until the pipe has shut down before returning. |
| 2054 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2055 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2056 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2057 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 2058 | enum transcoder cpu_transcoder = crtc->config.cpu_transcoder; |
| 2059 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2060 | int reg; |
| 2061 | u32 val; |
| 2062 | |
| 2063 | /* |
| 2064 | * Make sure planes won't keep trying to pump pixels to us, |
| 2065 | * or we might hang the display. |
| 2066 | */ |
| 2067 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2068 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2069 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2070 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2071 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2072 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2073 | if ((val & PIPECONF_ENABLE) == 0) |
| 2074 | return; |
| 2075 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2076 | /* |
| 2077 | * Double wide has implications for planes |
| 2078 | * so best keep it disabled when not needed. |
| 2079 | */ |
| 2080 | if (crtc->config.double_wide) |
| 2081 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2082 | |
| 2083 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame^] | 2084 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2085 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2086 | val &= ~PIPECONF_ENABLE; |
| 2087 | |
| 2088 | I915_WRITE(reg, val); |
| 2089 | if ((val & PIPECONF_ENABLE) == 0) |
| 2090 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2091 | } |
| 2092 | |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2093 | /* |
| 2094 | * Plane regs are double buffered, going from enabled->disabled needs a |
| 2095 | * trigger in order to latch. The display address reg provides this. |
| 2096 | */ |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2097 | void intel_flush_primary_plane(struct drm_i915_private *dev_priv, |
| 2098 | enum plane plane) |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2099 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 2100 | struct drm_device *dev = dev_priv->dev; |
| 2101 | u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2102 | |
| 2103 | I915_WRITE(reg, I915_READ(reg)); |
| 2104 | POSTING_READ(reg); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2105 | } |
| 2106 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2107 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2108 | * 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] | 2109 | * @plane: plane to be enabled |
| 2110 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2111 | * |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2112 | * Enable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2113 | */ |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2114 | static void intel_enable_primary_hw_plane(struct drm_plane *plane, |
| 2115 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2116 | { |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2117 | struct drm_device *dev = plane->dev; |
| 2118 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2119 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2120 | |
| 2121 | /* 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] | 2122 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2123 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2124 | if (intel_crtc->primary_enabled) |
| 2125 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2126 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2127 | intel_crtc->primary_enabled = true; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2128 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2129 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2130 | crtc->x, crtc->y); |
Ville Syrjälä | 33c3b0d | 2014-06-24 13:59:28 +0300 | [diff] [blame] | 2131 | |
| 2132 | /* |
| 2133 | * BDW signals flip done immediately if the plane |
| 2134 | * is disabled, even if the plane enable is already |
| 2135 | * armed to occur at the next vblank :( |
| 2136 | */ |
| 2137 | if (IS_BROADWELL(dev)) |
| 2138 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2139 | } |
| 2140 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2141 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2142 | * intel_disable_primary_hw_plane - disable the primary hardware plane |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2143 | * @plane: plane to be disabled |
| 2144 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2145 | * |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2146 | * Disable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2147 | */ |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2148 | static void intel_disable_primary_hw_plane(struct drm_plane *plane, |
| 2149 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2150 | { |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2151 | struct drm_device *dev = plane->dev; |
| 2152 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2153 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2154 | |
| 2155 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2156 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2157 | if (!intel_crtc->primary_enabled) |
| 2158 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2159 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2160 | intel_crtc->primary_enabled = false; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2161 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2162 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2163 | crtc->x, crtc->y); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2164 | } |
| 2165 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2166 | static bool need_vtd_wa(struct drm_device *dev) |
| 2167 | { |
| 2168 | #ifdef CONFIG_INTEL_IOMMU |
| 2169 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2170 | return true; |
| 2171 | #endif |
| 2172 | return false; |
| 2173 | } |
| 2174 | |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2175 | static int intel_align_height(struct drm_device *dev, int height, bool tiled) |
| 2176 | { |
| 2177 | int tile_height; |
| 2178 | |
| 2179 | tile_height = tiled ? (IS_GEN2(dev) ? 16 : 8) : 1; |
| 2180 | return ALIGN(height, tile_height); |
| 2181 | } |
| 2182 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2183 | int |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2184 | intel_pin_and_fence_fb_obj(struct drm_device *dev, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2185 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2186 | struct intel_engine_cs *pipelined) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2187 | { |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2188 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2189 | u32 alignment; |
| 2190 | int ret; |
| 2191 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2192 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2193 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 2194 | switch (obj->tiling_mode) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2195 | case I915_TILING_NONE: |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2196 | if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
| 2197 | alignment = 128 * 1024; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2198 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2199 | alignment = 4 * 1024; |
| 2200 | else |
| 2201 | alignment = 64 * 1024; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2202 | break; |
| 2203 | case I915_TILING_X: |
| 2204 | /* pin() will align the object as required by fence */ |
| 2205 | alignment = 0; |
| 2206 | break; |
| 2207 | case I915_TILING_Y: |
Daniel Vetter | 80075d4 | 2013-10-09 21:23:52 +0200 | [diff] [blame] | 2208 | WARN(1, "Y tiled bo slipped through, driver bug!\n"); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2209 | return -EINVAL; |
| 2210 | default: |
| 2211 | BUG(); |
| 2212 | } |
| 2213 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2214 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2215 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2216 | * we should always have valid PTE following the scanout preventing |
| 2217 | * the VT-d warning. |
| 2218 | */ |
| 2219 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2220 | alignment = 256 * 1024; |
| 2221 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2222 | dev_priv->mm.interruptible = false; |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 2223 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2224 | if (ret) |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2225 | goto err_interruptible; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2226 | |
| 2227 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2228 | * fence, whereas 965+ only requires a fence if using |
| 2229 | * framebuffer compression. For simplicity, we always install |
| 2230 | * a fence as the cost is not that onerous. |
| 2231 | */ |
Chris Wilson | 06d9813 | 2012-04-17 15:31:24 +0100 | [diff] [blame] | 2232 | ret = i915_gem_object_get_fence(obj); |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2233 | if (ret) |
| 2234 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2235 | |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2236 | i915_gem_object_pin_fence(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2237 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2238 | dev_priv->mm.interruptible = true; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2239 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2240 | |
| 2241 | err_unpin: |
Chris Wilson | cc98b41 | 2013-08-09 12:25:09 +0100 | [diff] [blame] | 2242 | i915_gem_object_unpin_from_display_plane(obj); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2243 | err_interruptible: |
| 2244 | dev_priv->mm.interruptible = true; |
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; |
| 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; |
| 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 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 2728 | static int |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2729 | intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2730 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2731 | { |
| 2732 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2733 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2734 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 2735 | enum pipe pipe = intel_crtc->pipe; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2736 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
| 2737 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 2738 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2739 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2740 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 2741 | if (intel_crtc_has_pending_flip(crtc)) { |
| 2742 | DRM_ERROR("pipe is still busy with an old pageflip\n"); |
| 2743 | return -EBUSY; |
| 2744 | } |
| 2745 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2746 | /* no fb bound */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2747 | if (!fb) { |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2748 | DRM_ERROR("No FB bound\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2749 | return 0; |
| 2750 | } |
| 2751 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 2752 | if (intel_crtc->plane > INTEL_INFO(dev)->num_pipes) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 2753 | DRM_ERROR("no plane for crtc: plane %c, num_pipes %d\n", |
| 2754 | plane_name(intel_crtc->plane), |
| 2755 | INTEL_INFO(dev)->num_pipes); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2756 | return -EINVAL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2757 | } |
| 2758 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2759 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 2760 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
| 2761 | if (ret == 0) |
Matt Roper | 91565c8 | 2014-06-24 17:05:02 -0700 | [diff] [blame] | 2762 | i915_gem_track_fb(old_obj, obj, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 2763 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Ville Syrjälä | 8ac36ec | 2014-03-11 19:37:33 +0200 | [diff] [blame] | 2764 | mutex_unlock(&dev->struct_mutex); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2765 | if (ret != 0) { |
Jesse Barnes | a5071c2 | 2011-07-19 15:38:56 -0700 | [diff] [blame] | 2766 | DRM_ERROR("pin & fence failed\n"); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2767 | return ret; |
| 2768 | } |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2769 | |
Damien Lespiau | bb2043d | 2013-09-30 14:21:49 +0100 | [diff] [blame] | 2770 | /* |
| 2771 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 2772 | * that in compute_mode_changes we check the native mode (not the pfit |
| 2773 | * mode) to see if we can flip rather than do a full mode set. In the |
| 2774 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 2775 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 2776 | * sized surface. |
| 2777 | * |
| 2778 | * To fix this properly, we need to hoist the checks up into |
| 2779 | * compute_mode_changes (or above), check the actual pfit state and |
| 2780 | * whether the platform allows pfit disable with pipe active, and only |
| 2781 | * then update the pipesrc and pfit state, even on the flip path. |
| 2782 | */ |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 2783 | if (i915.fastboot) { |
Damien Lespiau | d7bf63f | 2013-09-30 14:21:50 +0100 | [diff] [blame] | 2784 | const struct drm_display_mode *adjusted_mode = |
| 2785 | &intel_crtc->config.adjusted_mode; |
| 2786 | |
Jesse Barnes | 4d6a3e6 | 2013-06-26 01:38:18 +0300 | [diff] [blame] | 2787 | I915_WRITE(PIPESRC(intel_crtc->pipe), |
Damien Lespiau | d7bf63f | 2013-09-30 14:21:50 +0100 | [diff] [blame] | 2788 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | |
| 2789 | (adjusted_mode->crtc_vdisplay - 1)); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 2790 | if (!intel_crtc->config.pch_pfit.enabled && |
Jesse Barnes | 4d6a3e6 | 2013-06-26 01:38:18 +0300 | [diff] [blame] | 2791 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
| 2792 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
| 2793 | I915_WRITE(PF_CTL(intel_crtc->pipe), 0); |
| 2794 | I915_WRITE(PF_WIN_POS(intel_crtc->pipe), 0); |
| 2795 | I915_WRITE(PF_WIN_SZ(intel_crtc->pipe), 0); |
| 2796 | } |
Jesse Barnes | 0637d60 | 2013-12-19 10:48:01 -0800 | [diff] [blame] | 2797 | intel_crtc->config.pipe_src_w = adjusted_mode->crtc_hdisplay; |
| 2798 | intel_crtc->config.pipe_src_h = adjusted_mode->crtc_vdisplay; |
Jesse Barnes | 4d6a3e6 | 2013-06-26 01:38:18 +0300 | [diff] [blame] | 2799 | } |
| 2800 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2801 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
Kristian Høgsberg | 3c4fdcf | 2008-12-17 22:14:46 -0500 | [diff] [blame] | 2802 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 2803 | if (intel_crtc->active) |
| 2804 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 2805 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2806 | crtc->primary->fb = fb; |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 2807 | crtc->x = x; |
| 2808 | crtc->y = y; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 2809 | |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 2810 | if (old_fb) { |
Daniel Vetter | d7697ee | 2013-06-02 17:23:01 +0200 | [diff] [blame] | 2811 | if (intel_crtc->active && old_fb != fb) |
| 2812 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Ville Syrjälä | 8ac36ec | 2014-03-11 19:37:33 +0200 | [diff] [blame] | 2813 | mutex_lock(&dev->struct_mutex); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2814 | intel_unpin_fb_obj(old_obj); |
Ville Syrjälä | 8ac36ec | 2014-03-11 19:37:33 +0200 | [diff] [blame] | 2815 | mutex_unlock(&dev->struct_mutex); |
Chris Wilson | b7f1de2 | 2010-12-14 16:09:31 +0000 | [diff] [blame] | 2816 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 2817 | |
Ville Syrjälä | 8ac36ec | 2014-03-11 19:37:33 +0200 | [diff] [blame] | 2818 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2819 | intel_update_fbc(dev); |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2820 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2821 | |
Chris Wilson | 5c3b82e | 2009-02-11 13:25:09 +0000 | [diff] [blame] | 2822 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 2823 | } |
| 2824 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2825 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 2826 | { |
| 2827 | struct drm_device *dev = crtc->dev; |
| 2828 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2829 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2830 | int pipe = intel_crtc->pipe; |
| 2831 | u32 reg, temp; |
| 2832 | |
| 2833 | /* enable normal train */ |
| 2834 | reg = FDI_TX_CTL(pipe); |
| 2835 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 2836 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2837 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 2838 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 2839 | } else { |
| 2840 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2841 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2842 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2843 | I915_WRITE(reg, temp); |
| 2844 | |
| 2845 | reg = FDI_RX_CTL(pipe); |
| 2846 | temp = I915_READ(reg); |
| 2847 | if (HAS_PCH_CPT(dev)) { |
| 2848 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 2849 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 2850 | } else { |
| 2851 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2852 | temp |= FDI_LINK_TRAIN_NONE; |
| 2853 | } |
| 2854 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 2855 | |
| 2856 | /* wait one idle pattern time */ |
| 2857 | POSTING_READ(reg); |
| 2858 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 2859 | |
| 2860 | /* IVB wants error correction enabled */ |
| 2861 | if (IS_IVYBRIDGE(dev)) |
| 2862 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 2863 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 2864 | } |
| 2865 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 2866 | static bool pipe_has_enabled_pch(struct intel_crtc *crtc) |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 2867 | { |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 2868 | return crtc->base.enabled && crtc->active && |
| 2869 | crtc->config.has_pch_encoder; |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 2870 | } |
| 2871 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2872 | static void ivb_modeset_global_resources(struct drm_device *dev) |
| 2873 | { |
| 2874 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2875 | struct intel_crtc *pipe_B_crtc = |
| 2876 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]); |
| 2877 | struct intel_crtc *pipe_C_crtc = |
| 2878 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_C]); |
| 2879 | uint32_t temp; |
| 2880 | |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 2881 | /* |
| 2882 | * When everything is off disable fdi C so that we could enable fdi B |
| 2883 | * with all lanes. Note that we don't care about enabled pipes without |
| 2884 | * an enabled pch encoder. |
| 2885 | */ |
| 2886 | if (!pipe_has_enabled_pch(pipe_B_crtc) && |
| 2887 | !pipe_has_enabled_pch(pipe_C_crtc)) { |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 2888 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 2889 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 2890 | |
| 2891 | temp = I915_READ(SOUTH_CHICKEN1); |
| 2892 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 2893 | DRM_DEBUG_KMS("disabling fdi C rx\n"); |
| 2894 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 2895 | } |
| 2896 | } |
| 2897 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2898 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 2899 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 2900 | { |
| 2901 | struct drm_device *dev = crtc->dev; |
| 2902 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2903 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2904 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2905 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2906 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 2907 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2908 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 2909 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2910 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 2911 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2912 | reg = FDI_RX_IMR(pipe); |
| 2913 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2914 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 2915 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2916 | I915_WRITE(reg, temp); |
| 2917 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2918 | udelay(150); |
| 2919 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2920 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2921 | reg = FDI_TX_CTL(pipe); |
| 2922 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 2923 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
| 2924 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2925 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2926 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2927 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2928 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2929 | reg = FDI_RX_CTL(pipe); |
| 2930 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2931 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2932 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2933 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 2934 | |
| 2935 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2936 | udelay(150); |
| 2937 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2938 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 2939 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 2940 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 2941 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 2942 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2943 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2944 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2945 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2946 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2947 | |
| 2948 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 2949 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2950 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2951 | break; |
| 2952 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2953 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2954 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2955 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2956 | |
| 2957 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2958 | reg = FDI_TX_CTL(pipe); |
| 2959 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2960 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2961 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2962 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2963 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2964 | reg = FDI_RX_CTL(pipe); |
| 2965 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2966 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 2967 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2968 | I915_WRITE(reg, temp); |
| 2969 | |
| 2970 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2971 | udelay(150); |
| 2972 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2973 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2974 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2975 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2976 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 2977 | |
| 2978 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2979 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2980 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 2981 | break; |
| 2982 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2983 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 2984 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2985 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2986 | |
| 2987 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 2988 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2989 | } |
| 2990 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 2991 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 2992 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 2993 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 2994 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 2995 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 2996 | }; |
| 2997 | |
| 2998 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 2999 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3000 | { |
| 3001 | struct drm_device *dev = crtc->dev; |
| 3002 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3003 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3004 | int pipe = intel_crtc->pipe; |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3005 | u32 reg, temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3006 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3007 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3008 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3009 | reg = FDI_RX_IMR(pipe); |
| 3010 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3011 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3012 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3013 | I915_WRITE(reg, temp); |
| 3014 | |
| 3015 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3016 | udelay(150); |
| 3017 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3018 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3019 | reg = FDI_TX_CTL(pipe); |
| 3020 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3021 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
| 3022 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3023 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3024 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3025 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3026 | /* SNB-B */ |
| 3027 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3028 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3029 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3030 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3031 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3032 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3033 | reg = FDI_RX_CTL(pipe); |
| 3034 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3035 | if (HAS_PCH_CPT(dev)) { |
| 3036 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3037 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3038 | } else { |
| 3039 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3040 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3041 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3042 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3043 | |
| 3044 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3045 | udelay(150); |
| 3046 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3047 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3048 | reg = FDI_TX_CTL(pipe); |
| 3049 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3050 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3051 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3052 | I915_WRITE(reg, temp); |
| 3053 | |
| 3054 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3055 | udelay(500); |
| 3056 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3057 | for (retry = 0; retry < 5; retry++) { |
| 3058 | reg = FDI_RX_IIR(pipe); |
| 3059 | temp = I915_READ(reg); |
| 3060 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3061 | if (temp & FDI_RX_BIT_LOCK) { |
| 3062 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3063 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3064 | break; |
| 3065 | } |
| 3066 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3067 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3068 | if (retry < 5) |
| 3069 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3070 | } |
| 3071 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3072 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3073 | |
| 3074 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3075 | reg = FDI_TX_CTL(pipe); |
| 3076 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3077 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3078 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3079 | if (IS_GEN6(dev)) { |
| 3080 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3081 | /* SNB-B */ |
| 3082 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3083 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3084 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3085 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3086 | reg = FDI_RX_CTL(pipe); |
| 3087 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3088 | if (HAS_PCH_CPT(dev)) { |
| 3089 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3090 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3091 | } else { |
| 3092 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3093 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3094 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3095 | I915_WRITE(reg, temp); |
| 3096 | |
| 3097 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3098 | udelay(150); |
| 3099 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3100 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3101 | reg = FDI_TX_CTL(pipe); |
| 3102 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3103 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3104 | temp |= snb_b_fdi_train_param[i]; |
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(500); |
| 3109 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3110 | for (retry = 0; retry < 5; retry++) { |
| 3111 | reg = FDI_RX_IIR(pipe); |
| 3112 | temp = I915_READ(reg); |
| 3113 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3114 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3115 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3116 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3117 | break; |
| 3118 | } |
| 3119 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3120 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3121 | if (retry < 5) |
| 3122 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3123 | } |
| 3124 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3125 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3126 | |
| 3127 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3128 | } |
| 3129 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3130 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3131 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3132 | { |
| 3133 | struct drm_device *dev = crtc->dev; |
| 3134 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3135 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3136 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3137 | u32 reg, temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3138 | |
| 3139 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3140 | for train result */ |
| 3141 | reg = FDI_RX_IMR(pipe); |
| 3142 | temp = I915_READ(reg); |
| 3143 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3144 | temp &= ~FDI_RX_BIT_LOCK; |
| 3145 | I915_WRITE(reg, temp); |
| 3146 | |
| 3147 | POSTING_READ(reg); |
| 3148 | udelay(150); |
| 3149 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3150 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3151 | I915_READ(FDI_RX_IIR(pipe))); |
| 3152 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3153 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3154 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3155 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3156 | reg = FDI_TX_CTL(pipe); |
| 3157 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3158 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3159 | temp &= ~FDI_TX_ENABLE; |
| 3160 | I915_WRITE(reg, temp); |
| 3161 | |
| 3162 | reg = FDI_RX_CTL(pipe); |
| 3163 | temp = I915_READ(reg); |
| 3164 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3165 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3166 | temp &= ~FDI_RX_ENABLE; |
| 3167 | I915_WRITE(reg, temp); |
| 3168 | |
| 3169 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3170 | reg = FDI_TX_CTL(pipe); |
| 3171 | temp = I915_READ(reg); |
| 3172 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
| 3173 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
| 3174 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3175 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3176 | temp |= snb_b_fdi_train_param[j/2]; |
| 3177 | temp |= FDI_COMPOSITE_SYNC; |
| 3178 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3179 | |
| 3180 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3181 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3182 | |
| 3183 | reg = FDI_RX_CTL(pipe); |
| 3184 | temp = I915_READ(reg); |
| 3185 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3186 | temp |= FDI_COMPOSITE_SYNC; |
| 3187 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3188 | |
| 3189 | POSTING_READ(reg); |
| 3190 | udelay(1); /* should be 0.5us */ |
| 3191 | |
| 3192 | for (i = 0; i < 4; i++) { |
| 3193 | reg = FDI_RX_IIR(pipe); |
| 3194 | temp = I915_READ(reg); |
| 3195 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3196 | |
| 3197 | if (temp & FDI_RX_BIT_LOCK || |
| 3198 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3199 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3200 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3201 | i); |
| 3202 | break; |
| 3203 | } |
| 3204 | udelay(1); /* should be 0.5us */ |
| 3205 | } |
| 3206 | if (i == 4) { |
| 3207 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3208 | continue; |
| 3209 | } |
| 3210 | |
| 3211 | /* Train 2 */ |
| 3212 | reg = FDI_TX_CTL(pipe); |
| 3213 | temp = I915_READ(reg); |
| 3214 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3215 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3216 | I915_WRITE(reg, temp); |
| 3217 | |
| 3218 | reg = FDI_RX_CTL(pipe); |
| 3219 | temp = I915_READ(reg); |
| 3220 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3221 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3222 | I915_WRITE(reg, temp); |
| 3223 | |
| 3224 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3225 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3226 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3227 | for (i = 0; i < 4; i++) { |
| 3228 | reg = FDI_RX_IIR(pipe); |
| 3229 | temp = I915_READ(reg); |
| 3230 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3231 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3232 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3233 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3234 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3235 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3236 | i); |
| 3237 | goto train_done; |
| 3238 | } |
| 3239 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3240 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3241 | if (i == 4) |
| 3242 | 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] | 3243 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3244 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3245 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3246 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3247 | } |
| 3248 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3249 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3250 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3251 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3252 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3253 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3254 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3255 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3256 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3257 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3258 | reg = FDI_RX_CTL(pipe); |
| 3259 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3260 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
| 3261 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config.fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3262 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3263 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3264 | |
| 3265 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3266 | udelay(200); |
| 3267 | |
| 3268 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3269 | temp = I915_READ(reg); |
| 3270 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3271 | |
| 3272 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3273 | udelay(200); |
| 3274 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3275 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3276 | reg = FDI_TX_CTL(pipe); |
| 3277 | temp = I915_READ(reg); |
| 3278 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3279 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3280 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3281 | POSTING_READ(reg); |
| 3282 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3283 | } |
| 3284 | } |
| 3285 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3286 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3287 | { |
| 3288 | struct drm_device *dev = intel_crtc->base.dev; |
| 3289 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3290 | int pipe = intel_crtc->pipe; |
| 3291 | u32 reg, temp; |
| 3292 | |
| 3293 | /* Switch from PCDclk to Rawclk */ |
| 3294 | reg = FDI_RX_CTL(pipe); |
| 3295 | temp = I915_READ(reg); |
| 3296 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3297 | |
| 3298 | /* Disable CPU FDI TX PLL */ |
| 3299 | reg = FDI_TX_CTL(pipe); |
| 3300 | temp = I915_READ(reg); |
| 3301 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3302 | |
| 3303 | POSTING_READ(reg); |
| 3304 | udelay(100); |
| 3305 | |
| 3306 | reg = FDI_RX_CTL(pipe); |
| 3307 | temp = I915_READ(reg); |
| 3308 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3309 | |
| 3310 | /* Wait for the clocks to turn off. */ |
| 3311 | POSTING_READ(reg); |
| 3312 | udelay(100); |
| 3313 | } |
| 3314 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3315 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3316 | { |
| 3317 | struct drm_device *dev = crtc->dev; |
| 3318 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3319 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3320 | int pipe = intel_crtc->pipe; |
| 3321 | u32 reg, temp; |
| 3322 | |
| 3323 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3324 | reg = FDI_TX_CTL(pipe); |
| 3325 | temp = I915_READ(reg); |
| 3326 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3327 | POSTING_READ(reg); |
| 3328 | |
| 3329 | reg = FDI_RX_CTL(pipe); |
| 3330 | temp = I915_READ(reg); |
| 3331 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3332 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3333 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3334 | |
| 3335 | POSTING_READ(reg); |
| 3336 | udelay(100); |
| 3337 | |
| 3338 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3339 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3340 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3341 | |
| 3342 | /* still set train pattern 1 */ |
| 3343 | reg = FDI_TX_CTL(pipe); |
| 3344 | temp = I915_READ(reg); |
| 3345 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3346 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3347 | I915_WRITE(reg, temp); |
| 3348 | |
| 3349 | reg = FDI_RX_CTL(pipe); |
| 3350 | temp = I915_READ(reg); |
| 3351 | if (HAS_PCH_CPT(dev)) { |
| 3352 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3353 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3354 | } else { |
| 3355 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3356 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3357 | } |
| 3358 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3359 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3360 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3361 | I915_WRITE(reg, temp); |
| 3362 | |
| 3363 | POSTING_READ(reg); |
| 3364 | udelay(100); |
| 3365 | } |
| 3366 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3367 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3368 | { |
| 3369 | struct intel_crtc *crtc; |
| 3370 | |
| 3371 | /* Note that we don't need to be called with mode_config.lock here |
| 3372 | * as our list of CRTC objects is static for the lifetime of the |
| 3373 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3374 | * happily treat the predicates as racy, atomic checks as userspace |
| 3375 | * cannot claim and pin a new fb without at least acquring the |
| 3376 | * struct_mutex and so serialising with us. |
| 3377 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3378 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3379 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3380 | continue; |
| 3381 | |
| 3382 | if (crtc->unpin_work) |
| 3383 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3384 | |
| 3385 | return true; |
| 3386 | } |
| 3387 | |
| 3388 | return false; |
| 3389 | } |
| 3390 | |
Ville Syrjälä | 46a55d3 | 2014-05-21 14:04:46 +0300 | [diff] [blame] | 3391 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3392 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3393 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3394 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3395 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3396 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Daniel Vetter | eed6d67 | 2014-05-19 16:09:35 +0200 | [diff] [blame] | 3397 | WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
| 3398 | !intel_crtc_has_pending_flip(crtc), |
| 3399 | 60*HZ) == 0); |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3400 | |
Chris Wilson | 975d568 | 2014-08-20 13:13:34 +0100 | [diff] [blame] | 3401 | if (crtc->primary->fb) { |
| 3402 | mutex_lock(&dev->struct_mutex); |
| 3403 | intel_finish_fb(crtc->primary->fb); |
| 3404 | mutex_unlock(&dev->struct_mutex); |
| 3405 | } |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3406 | } |
| 3407 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3408 | /* Program iCLKIP clock to the desired frequency */ |
| 3409 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3410 | { |
| 3411 | struct drm_device *dev = crtc->dev; |
| 3412 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 3413 | int clock = to_intel_crtc(crtc)->config.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3414 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3415 | u32 temp; |
| 3416 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3417 | mutex_lock(&dev_priv->dpio_lock); |
| 3418 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3419 | /* It is necessary to ungate the pixclk gate prior to programming |
| 3420 | * the divisors, and gate it back when it is done. |
| 3421 | */ |
| 3422 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3423 | |
| 3424 | /* Disable SSCCTL */ |
| 3425 | intel_sbi_write(dev_priv, SBI_SSCCTL6, |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3426 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
| 3427 | SBI_SSCCTL_DISABLE, |
| 3428 | SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3429 | |
| 3430 | /* 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] | 3431 | if (clock == 20000) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3432 | auxdiv = 1; |
| 3433 | divsel = 0x41; |
| 3434 | phaseinc = 0x20; |
| 3435 | } else { |
| 3436 | /* The iCLK virtual clock root frequency is in MHz, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 3437 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3438 | * divisors, it is necessary to divide one by another, so we |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3439 | * convert the virtual clock precision to KHz here for higher |
| 3440 | * precision. |
| 3441 | */ |
| 3442 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3443 | u32 iclk_pi_range = 64; |
| 3444 | u32 desired_divisor, msb_divisor_value, pi_value; |
| 3445 | |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 3446 | desired_divisor = (iclk_virtual_root_freq / clock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3447 | msb_divisor_value = desired_divisor / iclk_pi_range; |
| 3448 | pi_value = desired_divisor % iclk_pi_range; |
| 3449 | |
| 3450 | auxdiv = 0; |
| 3451 | divsel = msb_divisor_value - 2; |
| 3452 | phaseinc = pi_value; |
| 3453 | } |
| 3454 | |
| 3455 | /* This should not happen with any sane values */ |
| 3456 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 3457 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 3458 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 3459 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 3460 | |
| 3461 | 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] | 3462 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3463 | auxdiv, |
| 3464 | divsel, |
| 3465 | phasedir, |
| 3466 | phaseinc); |
| 3467 | |
| 3468 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3469 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3470 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3471 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3472 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3473 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3474 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3475 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3476 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3477 | |
| 3478 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3479 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3480 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3481 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3482 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3483 | |
| 3484 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3485 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3486 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3487 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3488 | |
| 3489 | /* Wait for initialization time */ |
| 3490 | udelay(24); |
| 3491 | |
| 3492 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3493 | |
| 3494 | mutex_unlock(&dev_priv->dpio_lock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3495 | } |
| 3496 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3497 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 3498 | enum pipe pch_transcoder) |
| 3499 | { |
| 3500 | struct drm_device *dev = crtc->base.dev; |
| 3501 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3502 | enum transcoder cpu_transcoder = crtc->config.cpu_transcoder; |
| 3503 | |
| 3504 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 3505 | I915_READ(HTOTAL(cpu_transcoder))); |
| 3506 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 3507 | I915_READ(HBLANK(cpu_transcoder))); |
| 3508 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 3509 | I915_READ(HSYNC(cpu_transcoder))); |
| 3510 | |
| 3511 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 3512 | I915_READ(VTOTAL(cpu_transcoder))); |
| 3513 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 3514 | I915_READ(VBLANK(cpu_transcoder))); |
| 3515 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 3516 | I915_READ(VSYNC(cpu_transcoder))); |
| 3517 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 3518 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 3519 | } |
| 3520 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3521 | static void cpt_enable_fdi_bc_bifurcation(struct drm_device *dev) |
| 3522 | { |
| 3523 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3524 | uint32_t temp; |
| 3525 | |
| 3526 | temp = I915_READ(SOUTH_CHICKEN1); |
| 3527 | if (temp & FDI_BC_BIFURCATION_SELECT) |
| 3528 | return; |
| 3529 | |
| 3530 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 3531 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 3532 | |
| 3533 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 3534 | DRM_DEBUG_KMS("enabling fdi C rx\n"); |
| 3535 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 3536 | POSTING_READ(SOUTH_CHICKEN1); |
| 3537 | } |
| 3538 | |
| 3539 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 3540 | { |
| 3541 | struct drm_device *dev = intel_crtc->base.dev; |
| 3542 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3543 | |
| 3544 | switch (intel_crtc->pipe) { |
| 3545 | case PIPE_A: |
| 3546 | break; |
| 3547 | case PIPE_B: |
| 3548 | if (intel_crtc->config.fdi_lanes > 2) |
| 3549 | WARN_ON(I915_READ(SOUTH_CHICKEN1) & FDI_BC_BIFURCATION_SELECT); |
| 3550 | else |
| 3551 | cpt_enable_fdi_bc_bifurcation(dev); |
| 3552 | |
| 3553 | break; |
| 3554 | case PIPE_C: |
| 3555 | cpt_enable_fdi_bc_bifurcation(dev); |
| 3556 | |
| 3557 | break; |
| 3558 | default: |
| 3559 | BUG(); |
| 3560 | } |
| 3561 | } |
| 3562 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3563 | /* |
| 3564 | * Enable PCH resources required for PCH ports: |
| 3565 | * - PCH PLLs |
| 3566 | * - FDI training & RX/TX |
| 3567 | * - update transcoder timings |
| 3568 | * - DP transcoding bits |
| 3569 | * - transcoder |
| 3570 | */ |
| 3571 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3572 | { |
| 3573 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3574 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3575 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3576 | int pipe = intel_crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3577 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3578 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 3579 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 3580 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3581 | if (IS_IVYBRIDGE(dev)) |
| 3582 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 3583 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 3584 | /* Write the TU size bits before fdi link training, so that error |
| 3585 | * detection works. */ |
| 3586 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 3587 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 3588 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3589 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 3590 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3591 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3592 | /* We need to program the right clock selection before writing the pixel |
| 3593 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3594 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3595 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 3596 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3597 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 3598 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 3599 | sel = TRANS_DPLLB_SEL(pipe); |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 3600 | if (intel_crtc->config.shared_dpll == DPLL_ID_PCH_PLL_B) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3601 | temp |= sel; |
| 3602 | else |
| 3603 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3604 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3605 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3606 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3607 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 3608 | * transcoder, and we actually should do this to not upset any PCH |
| 3609 | * transcoder that already use the clock when we share it. |
| 3610 | * |
| 3611 | * Note that enable_shared_dpll tries to do the right thing, but |
| 3612 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 3613 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 3614 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3615 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 3616 | /* set transcoder timing, panel must allow it */ |
| 3617 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3618 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3619 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3620 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3621 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3622 | /* For PCH DP, enable TRANS_DP_CTL */ |
| 3623 | if (HAS_PCH_CPT(dev) && |
Keith Packard | 417e822 | 2011-11-01 19:54:11 -0700 | [diff] [blame] | 3624 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 3625 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3626 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3627 | reg = TRANS_DP_CTL(pipe); |
| 3628 | temp = I915_READ(reg); |
| 3629 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 3630 | TRANS_DP_SYNC_MASK | |
| 3631 | TRANS_DP_BPC_MASK); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3632 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
| 3633 | TRANS_DP_ENH_FRAMING); |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 3634 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3635 | |
| 3636 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3637 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3638 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3639 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3640 | |
| 3641 | switch (intel_trans_dp_port_sel(crtc)) { |
| 3642 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3643 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3644 | break; |
| 3645 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3646 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3647 | break; |
| 3648 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3649 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3650 | break; |
| 3651 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 3652 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3653 | } |
| 3654 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3655 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3656 | } |
| 3657 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 3658 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3659 | } |
| 3660 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3661 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 3662 | { |
| 3663 | struct drm_device *dev = crtc->dev; |
| 3664 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3665 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 3666 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3667 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 3668 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3669 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 3670 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3671 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 3672 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3673 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3674 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 3675 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3676 | } |
| 3677 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 3678 | void intel_put_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3679 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3680 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3681 | |
| 3682 | if (pll == NULL) |
| 3683 | return; |
| 3684 | |
| 3685 | if (pll->refcount == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3686 | WARN(1, "bad %s refcount\n", pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3687 | return; |
| 3688 | } |
| 3689 | |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 3690 | if (--pll->refcount == 0) { |
| 3691 | WARN_ON(pll->on); |
| 3692 | WARN_ON(pll->active); |
| 3693 | } |
| 3694 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 3695 | crtc->config.shared_dpll = DPLL_ID_PRIVATE; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3696 | } |
| 3697 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 3698 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3699 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3700 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 3701 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 3702 | enum intel_dpll_id i; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3703 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3704 | if (pll) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3705 | DRM_DEBUG_KMS("CRTC:%d dropping existing %s\n", |
| 3706 | crtc->base.base.id, pll->name); |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 3707 | intel_put_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3708 | } |
| 3709 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3710 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 3711 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 3712 | i = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3713 | pll = &dev_priv->shared_dplls[i]; |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3714 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3715 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 3716 | crtc->base.base.id, pll->name); |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3717 | |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 3718 | WARN_ON(pll->refcount); |
| 3719 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 3720 | goto found; |
| 3721 | } |
| 3722 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3723 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 3724 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3725 | |
| 3726 | /* Only want to check enabled timings first */ |
| 3727 | if (pll->refcount == 0) |
| 3728 | continue; |
| 3729 | |
Daniel Vetter | b89a1d3 | 2013-06-05 13:34:24 +0200 | [diff] [blame] | 3730 | if (memcmp(&crtc->config.dpll_hw_state, &pll->hw_state, |
| 3731 | sizeof(pll->hw_state)) == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3732 | 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] | 3733 | crtc->base.base.id, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3734 | pll->name, pll->refcount, pll->active); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3735 | |
| 3736 | goto found; |
| 3737 | } |
| 3738 | } |
| 3739 | |
| 3740 | /* Ok no matching timings, maybe there's a free one? */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 3741 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 3742 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3743 | if (pll->refcount == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3744 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
| 3745 | crtc->base.base.id, pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3746 | goto found; |
| 3747 | } |
| 3748 | } |
| 3749 | |
| 3750 | return NULL; |
| 3751 | |
| 3752 | found: |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 3753 | if (pll->refcount == 0) |
| 3754 | pll->hw_state = crtc->config.dpll_hw_state; |
| 3755 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 3756 | crtc->config.shared_dpll = i; |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 3757 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
| 3758 | pipe_name(crtc->pipe)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 3759 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3760 | pll->refcount++; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3761 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3762 | return pll; |
| 3763 | } |
| 3764 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 3765 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3766 | { |
| 3767 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 3768 | int dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3769 | u32 temp; |
| 3770 | |
| 3771 | temp = I915_READ(dslreg); |
| 3772 | udelay(500); |
| 3773 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3774 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 3775 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 3776 | } |
| 3777 | } |
| 3778 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 3779 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 3780 | { |
| 3781 | struct drm_device *dev = crtc->base.dev; |
| 3782 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3783 | int pipe = crtc->pipe; |
| 3784 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 3785 | if (crtc->config.pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 3786 | /* Force use of hard-coded filter coefficients |
| 3787 | * as some pre-programmed values are broken, |
| 3788 | * e.g. x201. |
| 3789 | */ |
| 3790 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 3791 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 3792 | PF_PIPE_SEL_IVB(pipe)); |
| 3793 | else |
| 3794 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
| 3795 | I915_WRITE(PF_WIN_POS(pipe), crtc->config.pch_pfit.pos); |
| 3796 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config.pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 3797 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3798 | } |
| 3799 | |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3800 | static void intel_enable_planes(struct drm_crtc *crtc) |
| 3801 | { |
| 3802 | struct drm_device *dev = crtc->dev; |
| 3803 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3804 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3805 | struct intel_plane *intel_plane; |
| 3806 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3807 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 3808 | intel_plane = to_intel_plane(plane); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3809 | if (intel_plane->pipe == pipe) |
| 3810 | intel_plane_restore(&intel_plane->base); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3811 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3812 | } |
| 3813 | |
| 3814 | static void intel_disable_planes(struct drm_crtc *crtc) |
| 3815 | { |
| 3816 | struct drm_device *dev = crtc->dev; |
| 3817 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3818 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3819 | struct intel_plane *intel_plane; |
| 3820 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3821 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 3822 | intel_plane = to_intel_plane(plane); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3823 | if (intel_plane->pipe == pipe) |
| 3824 | intel_plane_disable(&intel_plane->base); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 3825 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 3826 | } |
| 3827 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 3828 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3829 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 3830 | struct drm_device *dev = crtc->base.dev; |
| 3831 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3832 | |
| 3833 | if (!crtc->config.ips_enabled) |
| 3834 | return; |
| 3835 | |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 3836 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
| 3837 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3838 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3839 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 3840 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 3841 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3842 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 3843 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 3844 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 3845 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 3846 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 3847 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 3848 | */ |
| 3849 | } else { |
| 3850 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 3851 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 3852 | * is essentially intel_wait_for_vblank. If we don't have this |
| 3853 | * and don't wait for vblanks until the end of crtc_enable, then |
| 3854 | * the HW state readout code will complain that the expected |
| 3855 | * IPS_CTL value is not the one we read. */ |
| 3856 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 3857 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 3858 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3859 | } |
| 3860 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 3861 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3862 | { |
| 3863 | struct drm_device *dev = crtc->base.dev; |
| 3864 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3865 | |
| 3866 | if (!crtc->config.ips_enabled) |
| 3867 | return; |
| 3868 | |
| 3869 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 3870 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 3871 | mutex_lock(&dev_priv->rps.hw_lock); |
| 3872 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 3873 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 3874 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 3875 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 3876 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 3877 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 3878 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 3879 | POSTING_READ(IPS_CTL); |
| 3880 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3881 | |
| 3882 | /* We need to wait for a vblank before we can disable the plane. */ |
| 3883 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3884 | } |
| 3885 | |
| 3886 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 3887 | static void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 3888 | { |
| 3889 | struct drm_device *dev = crtc->dev; |
| 3890 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3891 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3892 | enum pipe pipe = intel_crtc->pipe; |
| 3893 | int palreg = PALETTE(pipe); |
| 3894 | int i; |
| 3895 | bool reenable_ips = false; |
| 3896 | |
| 3897 | /* The clocks have to be on to load the palette. */ |
| 3898 | if (!crtc->enabled || !intel_crtc->active) |
| 3899 | return; |
| 3900 | |
| 3901 | if (!HAS_PCH_SPLIT(dev_priv->dev)) { |
| 3902 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
| 3903 | assert_dsi_pll_enabled(dev_priv); |
| 3904 | else |
| 3905 | assert_pll_enabled(dev_priv, pipe); |
| 3906 | } |
| 3907 | |
| 3908 | /* use legacy palette for Ironlake */ |
Sonika Jindal | 7a1db49 | 2014-07-22 11:18:27 +0530 | [diff] [blame] | 3909 | if (!HAS_GMCH_DISPLAY(dev)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3910 | palreg = LGC_PALETTE(pipe); |
| 3911 | |
| 3912 | /* Workaround : Do not read or write the pipe palette/gamma data while |
| 3913 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 3914 | */ |
Paulo Zanoni | 41e6fc4 | 2014-01-08 17:26:31 -0200 | [diff] [blame] | 3915 | if (IS_HASWELL(dev) && intel_crtc->config.ips_enabled && |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 3916 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
| 3917 | GAMMA_MODE_MODE_SPLIT)) { |
| 3918 | hsw_disable_ips(intel_crtc); |
| 3919 | reenable_ips = true; |
| 3920 | } |
| 3921 | |
| 3922 | for (i = 0; i < 256; i++) { |
| 3923 | I915_WRITE(palreg + 4 * i, |
| 3924 | (intel_crtc->lut_r[i] << 16) | |
| 3925 | (intel_crtc->lut_g[i] << 8) | |
| 3926 | intel_crtc->lut_b[i]); |
| 3927 | } |
| 3928 | |
| 3929 | if (reenable_ips) |
| 3930 | hsw_enable_ips(intel_crtc); |
| 3931 | } |
| 3932 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 3933 | static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable) |
| 3934 | { |
| 3935 | if (!enable && intel_crtc->overlay) { |
| 3936 | struct drm_device *dev = intel_crtc->base.dev; |
| 3937 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3938 | |
| 3939 | mutex_lock(&dev->struct_mutex); |
| 3940 | dev_priv->mm.interruptible = false; |
| 3941 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 3942 | dev_priv->mm.interruptible = true; |
| 3943 | mutex_unlock(&dev->struct_mutex); |
| 3944 | } |
| 3945 | |
| 3946 | /* Let userspace switch the overlay on again. In most cases userspace |
| 3947 | * has to recompute where to put it anyway. |
| 3948 | */ |
| 3949 | } |
| 3950 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 3951 | static void intel_crtc_enable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3952 | { |
| 3953 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3954 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3955 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3956 | |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 3957 | drm_vblank_on(dev, pipe); |
| 3958 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 3959 | intel_enable_primary_hw_plane(crtc->primary, crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3960 | intel_enable_planes(crtc); |
| 3961 | intel_crtc_update_cursor(crtc, true); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 3962 | intel_crtc_dpms_overlay(intel_crtc, true); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3963 | |
| 3964 | hsw_enable_ips(intel_crtc); |
| 3965 | |
| 3966 | mutex_lock(&dev->struct_mutex); |
| 3967 | intel_update_fbc(dev); |
| 3968 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 3969 | |
| 3970 | /* |
| 3971 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 3972 | * to compute the mask of flip planes precisely. For the time being |
| 3973 | * consider this a flip from a NULL plane. |
| 3974 | */ |
| 3975 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3976 | } |
| 3977 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 3978 | static void intel_crtc_disable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3979 | { |
| 3980 | struct drm_device *dev = crtc->dev; |
| 3981 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3982 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3983 | int pipe = intel_crtc->pipe; |
| 3984 | int plane = intel_crtc->plane; |
| 3985 | |
| 3986 | intel_crtc_wait_for_pending_flips(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3987 | |
| 3988 | if (dev_priv->fbc.plane == plane) |
| 3989 | intel_disable_fbc(dev); |
| 3990 | |
| 3991 | hsw_disable_ips(intel_crtc); |
| 3992 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 3993 | intel_crtc_dpms_overlay(intel_crtc, false); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 3994 | intel_crtc_update_cursor(crtc, false); |
| 3995 | intel_disable_planes(crtc); |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 3996 | intel_disable_primary_hw_plane(crtc->primary, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 3997 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 3998 | /* |
| 3999 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4000 | * to compute the mask of flip planes precisely. For the time being |
| 4001 | * consider this a flip to a NULL plane. |
| 4002 | */ |
| 4003 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
| 4004 | |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4005 | drm_vblank_off(dev, pipe); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4006 | } |
| 4007 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4008 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4009 | { |
| 4010 | struct drm_device *dev = crtc->dev; |
| 4011 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4012 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4013 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4014 | int pipe = intel_crtc->pipe; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4015 | |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 4016 | WARN_ON(!crtc->enabled); |
| 4017 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4018 | if (intel_crtc->active) |
| 4019 | return; |
| 4020 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4021 | if (intel_crtc->config.has_pch_encoder) |
| 4022 | intel_prepare_shared_dpll(intel_crtc); |
| 4023 | |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4024 | if (intel_crtc->config.has_dp_encoder) |
| 4025 | intel_dp_set_m_n(intel_crtc); |
| 4026 | |
| 4027 | intel_set_pipe_timings(intel_crtc); |
| 4028 | |
| 4029 | if (intel_crtc->config.has_pch_encoder) { |
| 4030 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 4031 | &intel_crtc->config.fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4032 | } |
| 4033 | |
| 4034 | ironlake_set_pipeconf(crtc); |
| 4035 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4036 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4037 | |
| 4038 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 4039 | intel_set_pch_fifo_underrun_reporting(dev, pipe, true); |
| 4040 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4041 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4042 | if (encoder->pre_enable) |
| 4043 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4044 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 4045 | if (intel_crtc->config.has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4046 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4047 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4048 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4049 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4050 | } else { |
| 4051 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4052 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4053 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4054 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4055 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4056 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4057 | /* |
| 4058 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4059 | * clocks enabled |
| 4060 | */ |
| 4061 | intel_crtc_load_lut(crtc); |
| 4062 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4063 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4064 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4065 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 4066 | if (intel_crtc->config.has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4067 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4068 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4069 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4070 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4071 | |
| 4072 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4073 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Daniel Vetter | 6ce9410 | 2012-10-04 19:20:03 +0200 | [diff] [blame] | 4074 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4075 | intel_crtc_enable_planes(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4076 | } |
| 4077 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4078 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4079 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4080 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4081 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4082 | } |
| 4083 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4084 | /* |
| 4085 | * This implements the workaround described in the "notes" section of the mode |
| 4086 | * set sequence documentation. When going from no pipes or single pipe to |
| 4087 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 4088 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 4089 | */ |
| 4090 | static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc) |
| 4091 | { |
| 4092 | struct drm_device *dev = crtc->base.dev; |
| 4093 | struct intel_crtc *crtc_it, *other_active_crtc = NULL; |
| 4094 | |
| 4095 | /* We want to get the other_active_crtc only if there's only 1 other |
| 4096 | * active crtc. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4097 | for_each_intel_crtc(dev, crtc_it) { |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4098 | if (!crtc_it->active || crtc_it == crtc) |
| 4099 | continue; |
| 4100 | |
| 4101 | if (other_active_crtc) |
| 4102 | return; |
| 4103 | |
| 4104 | other_active_crtc = crtc_it; |
| 4105 | } |
| 4106 | if (!other_active_crtc) |
| 4107 | return; |
| 4108 | |
| 4109 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4110 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4111 | } |
| 4112 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4113 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 4114 | { |
| 4115 | struct drm_device *dev = crtc->dev; |
| 4116 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4117 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4118 | struct intel_encoder *encoder; |
| 4119 | int pipe = intel_crtc->pipe; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4120 | |
| 4121 | WARN_ON(!crtc->enabled); |
| 4122 | |
| 4123 | if (intel_crtc->active) |
| 4124 | return; |
| 4125 | |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4126 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4127 | intel_enable_shared_dpll(intel_crtc); |
| 4128 | |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4129 | if (intel_crtc->config.has_dp_encoder) |
| 4130 | intel_dp_set_m_n(intel_crtc); |
| 4131 | |
| 4132 | intel_set_pipe_timings(intel_crtc); |
| 4133 | |
| 4134 | if (intel_crtc->config.has_pch_encoder) { |
| 4135 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 4136 | &intel_crtc->config.fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | haswell_set_pipeconf(crtc); |
| 4140 | |
| 4141 | intel_set_pipe_csc(crtc); |
| 4142 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4143 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4144 | |
| 4145 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4146 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4147 | if (encoder->pre_enable) |
| 4148 | encoder->pre_enable(encoder); |
| 4149 | |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4150 | if (intel_crtc->config.has_pch_encoder) { |
| 4151 | intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true); |
| 4152 | dev_priv->display.fdi_link_train(crtc); |
| 4153 | } |
| 4154 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4155 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4156 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4157 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4158 | |
| 4159 | /* |
| 4160 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4161 | * clocks enabled |
| 4162 | */ |
| 4163 | intel_crtc_load_lut(crtc); |
| 4164 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4165 | intel_ddi_set_pipe_settings(crtc); |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 4166 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4167 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4168 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4169 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4170 | |
Daniel Vetter | 5bfe2ac | 2013-03-27 00:44:55 +0100 | [diff] [blame] | 4171 | if (intel_crtc->config.has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4172 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4173 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4174 | if (intel_crtc->config.dp_encoder_is_mst) |
| 4175 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 4176 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4177 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4178 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4179 | intel_opregion_notify_encoder(encoder, true); |
| 4180 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4181 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4182 | /* If we change the relative order between pipe/planes enabling, we need |
| 4183 | * to change the workaround. */ |
| 4184 | haswell_mode_set_planes_workaround(intel_crtc); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4185 | intel_crtc_enable_planes(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4186 | } |
| 4187 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4188 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
| 4189 | { |
| 4190 | struct drm_device *dev = crtc->base.dev; |
| 4191 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4192 | int pipe = crtc->pipe; |
| 4193 | |
| 4194 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4195 | * 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] | 4196 | if (crtc->config.pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4197 | I915_WRITE(PF_CTL(pipe), 0); |
| 4198 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 4199 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 4200 | } |
| 4201 | } |
| 4202 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4203 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 4204 | { |
| 4205 | struct drm_device *dev = crtc->dev; |
| 4206 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4207 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4208 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4209 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4210 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4211 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4212 | if (!intel_crtc->active) |
| 4213 | return; |
| 4214 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4215 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4216 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4217 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4218 | encoder->disable(encoder); |
| 4219 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4220 | if (intel_crtc->config.has_pch_encoder) |
| 4221 | intel_set_pch_fifo_underrun_reporting(dev, pipe, false); |
| 4222 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4223 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4224 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4225 | if (intel_crtc->config.dp_encoder_is_mst) |
| 4226 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 4227 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4228 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4229 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 4230 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4231 | if (encoder->post_disable) |
| 4232 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4233 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4234 | if (intel_crtc->config.has_pch_encoder) { |
| 4235 | ironlake_fdi_disable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4236 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4237 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
| 4238 | intel_set_pch_fifo_underrun_reporting(dev, pipe, true); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4239 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4240 | if (HAS_PCH_CPT(dev)) { |
| 4241 | /* disable TRANS_DP_CTL */ |
| 4242 | reg = TRANS_DP_CTL(pipe); |
| 4243 | temp = I915_READ(reg); |
| 4244 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 4245 | TRANS_DP_PORT_SEL_MASK); |
| 4246 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 4247 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4248 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4249 | /* disable DPLL_SEL */ |
| 4250 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4251 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4252 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 4253 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4254 | |
| 4255 | /* disable PCH DPLL */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4256 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4257 | |
| 4258 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4259 | } |
| 4260 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4261 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4262 | intel_update_watermarks(crtc); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4263 | |
| 4264 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4265 | intel_update_fbc(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4266 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4267 | } |
| 4268 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4269 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 4270 | { |
| 4271 | struct drm_device *dev = crtc->dev; |
| 4272 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4273 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4274 | struct intel_encoder *encoder; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 4275 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4276 | |
| 4277 | if (!intel_crtc->active) |
| 4278 | return; |
| 4279 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4280 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | dda9a66 | 2013-09-19 17:00:37 -0300 | [diff] [blame] | 4281 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4282 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 4283 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4284 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4285 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4286 | |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4287 | if (intel_crtc->config.has_pch_encoder) |
| 4288 | intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, false); |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4289 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4290 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 4291 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4292 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4293 | ironlake_pfit_disable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4294 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4295 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4296 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 4297 | if (intel_crtc->config.has_pch_encoder) { |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 4298 | lpt_disable_pch_transcoder(dev_priv); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4299 | intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A, true); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 4300 | intel_ddi_fdi_disable(crtc); |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 4301 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4302 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 4303 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4304 | if (encoder->post_disable) |
| 4305 | encoder->post_disable(encoder); |
| 4306 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4307 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4308 | intel_update_watermarks(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4309 | |
| 4310 | mutex_lock(&dev->struct_mutex); |
| 4311 | intel_update_fbc(dev); |
| 4312 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4313 | |
| 4314 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4315 | intel_disable_shared_dpll(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4316 | } |
| 4317 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4318 | static void ironlake_crtc_off(struct drm_crtc *crtc) |
| 4319 | { |
| 4320 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4321 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4322 | } |
| 4323 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 4324 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4325 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 4326 | { |
| 4327 | struct drm_device *dev = crtc->base.dev; |
| 4328 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4329 | struct intel_crtc_config *pipe_config = &crtc->config; |
| 4330 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 4331 | if (!crtc->config.gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4332 | return; |
| 4333 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 4334 | /* |
| 4335 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 4336 | * according to register description and PRM. |
| 4337 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4338 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 4339 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 4340 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4341 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 4342 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 4343 | |
| 4344 | /* Border color in case we don't scale up to the full screen. Black by |
| 4345 | * default, change to something else for debugging. */ |
| 4346 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4347 | } |
| 4348 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4349 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 4350 | { |
| 4351 | switch (port) { |
| 4352 | case PORT_A: |
| 4353 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; |
| 4354 | case PORT_B: |
| 4355 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; |
| 4356 | case PORT_C: |
| 4357 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; |
| 4358 | case PORT_D: |
| 4359 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; |
| 4360 | default: |
| 4361 | WARN_ON_ONCE(1); |
| 4362 | return POWER_DOMAIN_PORT_OTHER; |
| 4363 | } |
| 4364 | } |
| 4365 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4366 | #define for_each_power_domain(domain, mask) \ |
| 4367 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ |
| 4368 | if ((1 << (domain)) & (mask)) |
| 4369 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4370 | enum intel_display_power_domain |
| 4371 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4372 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4373 | struct drm_device *dev = intel_encoder->base.dev; |
| 4374 | struct intel_digital_port *intel_dig_port; |
| 4375 | |
| 4376 | switch (intel_encoder->type) { |
| 4377 | case INTEL_OUTPUT_UNKNOWN: |
| 4378 | /* Only DDI platforms should ever use this output type */ |
| 4379 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 4380 | case INTEL_OUTPUT_DISPLAYPORT: |
| 4381 | case INTEL_OUTPUT_HDMI: |
| 4382 | case INTEL_OUTPUT_EDP: |
| 4383 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4384 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4385 | case INTEL_OUTPUT_DP_MST: |
| 4386 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 4387 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4388 | case INTEL_OUTPUT_ANALOG: |
| 4389 | return POWER_DOMAIN_PORT_CRT; |
| 4390 | case INTEL_OUTPUT_DSI: |
| 4391 | return POWER_DOMAIN_PORT_DSI; |
| 4392 | default: |
| 4393 | return POWER_DOMAIN_PORT_OTHER; |
| 4394 | } |
| 4395 | } |
| 4396 | |
| 4397 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) |
| 4398 | { |
| 4399 | struct drm_device *dev = crtc->dev; |
| 4400 | struct intel_encoder *intel_encoder; |
| 4401 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4402 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4403 | unsigned long mask; |
| 4404 | enum transcoder transcoder; |
| 4405 | |
| 4406 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); |
| 4407 | |
| 4408 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 4409 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Daniel Vetter | fabf6e5 | 2014-05-29 14:10:22 +0200 | [diff] [blame] | 4410 | if (intel_crtc->config.pch_pfit.enabled || |
| 4411 | intel_crtc->config.pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4412 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 4413 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4414 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 4415 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
| 4416 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4417 | return mask; |
| 4418 | } |
| 4419 | |
| 4420 | void intel_display_set_init_power(struct drm_i915_private *dev_priv, |
| 4421 | bool enable) |
| 4422 | { |
| 4423 | if (dev_priv->power_domains.init_power_on == enable) |
| 4424 | return; |
| 4425 | |
| 4426 | if (enable) |
| 4427 | intel_display_power_get(dev_priv, POWER_DOMAIN_INIT); |
| 4428 | else |
| 4429 | intel_display_power_put(dev_priv, POWER_DOMAIN_INIT); |
| 4430 | |
| 4431 | dev_priv->power_domains.init_power_on = enable; |
| 4432 | } |
| 4433 | |
| 4434 | static void modeset_update_crtc_power_domains(struct drm_device *dev) |
| 4435 | { |
| 4436 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4437 | unsigned long pipe_domains[I915_MAX_PIPES] = { 0, }; |
| 4438 | struct intel_crtc *crtc; |
| 4439 | |
| 4440 | /* |
| 4441 | * First get all needed power domains, then put all unneeded, to avoid |
| 4442 | * any unnecessary toggling of the power wells. |
| 4443 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4444 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4445 | enum intel_display_power_domain domain; |
| 4446 | |
| 4447 | if (!crtc->base.enabled) |
| 4448 | continue; |
| 4449 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4450 | pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4451 | |
| 4452 | for_each_power_domain(domain, pipe_domains[crtc->pipe]) |
| 4453 | intel_display_power_get(dev_priv, domain); |
| 4454 | } |
| 4455 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4456 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4457 | enum intel_display_power_domain domain; |
| 4458 | |
| 4459 | for_each_power_domain(domain, crtc->enabled_power_domains) |
| 4460 | intel_display_power_put(dev_priv, domain); |
| 4461 | |
| 4462 | crtc->enabled_power_domains = pipe_domains[crtc->pipe]; |
| 4463 | } |
| 4464 | |
| 4465 | intel_display_set_init_power(dev_priv, false); |
| 4466 | } |
| 4467 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4468 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4469 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4470 | { |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 4471 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4472 | |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 4473 | /* Obtain SKU information */ |
| 4474 | mutex_lock(&dev_priv->dpio_lock); |
| 4475 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 4476 | CCK_FUSE_HPLL_FREQ_MASK; |
| 4477 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4478 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4479 | return vco_freq[hpll_freq] * 1000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4480 | } |
| 4481 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4482 | static void vlv_update_cdclk(struct drm_device *dev) |
| 4483 | { |
| 4484 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4485 | |
| 4486 | dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev); |
| 4487 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz", |
| 4488 | dev_priv->vlv_cdclk_freq); |
| 4489 | |
| 4490 | /* |
| 4491 | * Program the gmbus_freq based on the cdclk frequency. |
| 4492 | * BSpec erroneously claims we should aim for 4MHz, but |
| 4493 | * in fact 1MHz is the correct frequency. |
| 4494 | */ |
| 4495 | I915_WRITE(GMBUSFREQ_VLV, dev_priv->vlv_cdclk_freq); |
| 4496 | } |
| 4497 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4498 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 4499 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 4500 | { |
| 4501 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4502 | u32 val, cmd; |
| 4503 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 4504 | 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] | 4505 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4506 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4507 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4508 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4509 | cmd = 1; |
| 4510 | else |
| 4511 | cmd = 0; |
| 4512 | |
| 4513 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4514 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 4515 | val &= ~DSPFREQGUAR_MASK; |
| 4516 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 4517 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 4518 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 4519 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 4520 | 50)) { |
| 4521 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 4522 | } |
| 4523 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4524 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4525 | if (cdclk == 400000) { |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4526 | u32 divider, vco; |
| 4527 | |
| 4528 | vco = valleyview_get_vco(dev_priv); |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4529 | divider = DIV_ROUND_CLOSEST(vco << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4530 | |
| 4531 | mutex_lock(&dev_priv->dpio_lock); |
| 4532 | /* adjust cdclk divider */ |
| 4533 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Ville Syrjälä | 9cf33db | 2014-06-13 13:37:48 +0300 | [diff] [blame] | 4534 | val &= ~DISPLAY_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4535 | val |= divider; |
| 4536 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 4537 | |
| 4538 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
| 4539 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 4540 | 50)) |
| 4541 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4542 | mutex_unlock(&dev_priv->dpio_lock); |
| 4543 | } |
| 4544 | |
| 4545 | mutex_lock(&dev_priv->dpio_lock); |
| 4546 | /* adjust self-refresh exit latency value */ |
| 4547 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 4548 | val &= ~0x7f; |
| 4549 | |
| 4550 | /* |
| 4551 | * For high bandwidth configs, we set a higher latency in the bunit |
| 4552 | * so that the core display fetch happens in time to avoid underruns. |
| 4553 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4554 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4555 | val |= 4500 / 250; /* 4.5 usec */ |
| 4556 | else |
| 4557 | val |= 3000 / 250; /* 3.0 usec */ |
| 4558 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
| 4559 | mutex_unlock(&dev_priv->dpio_lock); |
| 4560 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4561 | vlv_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4562 | } |
| 4563 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 4564 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 4565 | { |
| 4566 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4567 | u32 val, cmd; |
| 4568 | |
| 4569 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq); |
| 4570 | |
| 4571 | switch (cdclk) { |
| 4572 | case 400000: |
| 4573 | cmd = 3; |
| 4574 | break; |
| 4575 | case 333333: |
| 4576 | case 320000: |
| 4577 | cmd = 2; |
| 4578 | break; |
| 4579 | case 266667: |
| 4580 | cmd = 1; |
| 4581 | break; |
| 4582 | case 200000: |
| 4583 | cmd = 0; |
| 4584 | break; |
| 4585 | default: |
| 4586 | WARN_ON(1); |
| 4587 | return; |
| 4588 | } |
| 4589 | |
| 4590 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4591 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 4592 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 4593 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 4594 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 4595 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 4596 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 4597 | 50)) { |
| 4598 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 4599 | } |
| 4600 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4601 | |
| 4602 | vlv_update_cdclk(dev); |
| 4603 | } |
| 4604 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4605 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 4606 | int max_pixclk) |
| 4607 | { |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 4608 | int vco = valleyview_get_vco(dev_priv); |
| 4609 | int freq_320 = (vco << 1) % 320000 != 0 ? 333333 : 320000; |
| 4610 | |
Ville Syrjälä | d49a340 | 2014-06-28 02:03:58 +0300 | [diff] [blame] | 4611 | /* FIXME: Punit isn't quite ready yet */ |
| 4612 | if (IS_CHERRYVIEW(dev_priv->dev)) |
| 4613 | return 400000; |
| 4614 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4615 | /* |
| 4616 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 4617 | * 200MHz |
| 4618 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 4619 | * 320/333MHz (depends on HPLL freq) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4620 | * 400MHz |
| 4621 | * So we check to see whether we're above 90% of the lower bin and |
| 4622 | * adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 4623 | * |
| 4624 | * We seem to get an unstable or solid color picture at 200MHz. |
| 4625 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 4626 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4627 | */ |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 4628 | if (max_pixclk > freq_320*9/10) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4629 | return 400000; |
| 4630 | else if (max_pixclk > 266667*9/10) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 4631 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 4632 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4633 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 4634 | else |
| 4635 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4636 | } |
| 4637 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4638 | /* compute the max pixel clock for new configuration */ |
| 4639 | static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4640 | { |
| 4641 | struct drm_device *dev = dev_priv->dev; |
| 4642 | struct intel_crtc *intel_crtc; |
| 4643 | int max_pixclk = 0; |
| 4644 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4645 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4646 | if (intel_crtc->new_enabled) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4647 | max_pixclk = max(max_pixclk, |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4648 | intel_crtc->new_config->adjusted_mode.crtc_clock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4649 | } |
| 4650 | |
| 4651 | return max_pixclk; |
| 4652 | } |
| 4653 | |
| 4654 | static void valleyview_modeset_global_pipes(struct drm_device *dev, |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4655 | unsigned *prepare_pipes) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4656 | { |
| 4657 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4658 | struct intel_crtc *intel_crtc; |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4659 | int max_pixclk = intel_mode_max_pixclk(dev_priv); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4660 | |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 4661 | if (valleyview_calc_cdclk(dev_priv, max_pixclk) == |
| 4662 | dev_priv->vlv_cdclk_freq) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4663 | return; |
| 4664 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4665 | /* disable/enable all currently active pipes while we change cdclk */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4666 | for_each_intel_crtc(dev, intel_crtc) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4667 | if (intel_crtc->base.enabled) |
| 4668 | *prepare_pipes |= (1 << intel_crtc->pipe); |
| 4669 | } |
| 4670 | |
| 4671 | static void valleyview_modeset_global_resources(struct drm_device *dev) |
| 4672 | { |
| 4673 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 4674 | int max_pixclk = intel_mode_max_pixclk(dev_priv); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4675 | int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
| 4676 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 4677 | if (req_cdclk != dev_priv->vlv_cdclk_freq) { |
| 4678 | if (IS_CHERRYVIEW(dev)) |
| 4679 | cherryview_set_cdclk(dev, req_cdclk); |
| 4680 | else |
| 4681 | valleyview_set_cdclk(dev, req_cdclk); |
| 4682 | } |
| 4683 | |
Imre Deak | 77961eb | 2014-03-05 16:20:56 +0200 | [diff] [blame] | 4684 | modeset_update_crtc_power_domains(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4685 | } |
| 4686 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4687 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 4688 | { |
| 4689 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4690 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4691 | struct intel_encoder *encoder; |
| 4692 | int pipe = intel_crtc->pipe; |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 4693 | bool is_dsi; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4694 | |
| 4695 | WARN_ON(!crtc->enabled); |
| 4696 | |
| 4697 | if (intel_crtc->active) |
| 4698 | return; |
| 4699 | |
Shobhit Kumar | 8525a23 | 2014-06-25 12:20:39 +0530 | [diff] [blame] | 4700 | is_dsi = intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI); |
| 4701 | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 4702 | if (!is_dsi) { |
| 4703 | if (IS_CHERRYVIEW(dev)) |
| 4704 | chv_prepare_pll(intel_crtc); |
| 4705 | else |
| 4706 | vlv_prepare_pll(intel_crtc); |
| 4707 | } |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 4708 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 4709 | if (intel_crtc->config.has_dp_encoder) |
| 4710 | intel_dp_set_m_n(intel_crtc); |
| 4711 | |
| 4712 | intel_set_pipe_timings(intel_crtc); |
| 4713 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 4714 | i9xx_set_pipeconf(intel_crtc); |
| 4715 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4716 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4717 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4718 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 4719 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4720 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4721 | if (encoder->pre_pll_enable) |
| 4722 | encoder->pre_pll_enable(encoder); |
| 4723 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 4724 | if (!is_dsi) { |
| 4725 | if (IS_CHERRYVIEW(dev)) |
| 4726 | chv_enable_pll(intel_crtc); |
| 4727 | else |
| 4728 | vlv_enable_pll(intel_crtc); |
| 4729 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4730 | |
| 4731 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4732 | if (encoder->pre_enable) |
| 4733 | encoder->pre_enable(encoder); |
| 4734 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4735 | i9xx_pfit_enable(intel_crtc); |
| 4736 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 4737 | intel_crtc_load_lut(crtc); |
| 4738 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4739 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4740 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 4741 | |
Jani Nikula | 5004945 | 2013-07-30 12:20:32 +0300 | [diff] [blame] | 4742 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4743 | encoder->enable(encoder); |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 4744 | |
| 4745 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 4746 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 4747 | /* Underruns don't raise interrupts, so check manually. */ |
| 4748 | i9xx_check_fifo_underruns(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4749 | } |
| 4750 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 4751 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 4752 | { |
| 4753 | struct drm_device *dev = crtc->base.dev; |
| 4754 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4755 | |
| 4756 | I915_WRITE(FP0(crtc->pipe), crtc->config.dpll_hw_state.fp0); |
| 4757 | I915_WRITE(FP1(crtc->pipe), crtc->config.dpll_hw_state.fp1); |
| 4758 | } |
| 4759 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4760 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4761 | { |
| 4762 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4763 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4764 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4765 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4766 | |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 4767 | WARN_ON(!crtc->enabled); |
| 4768 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4769 | if (intel_crtc->active) |
| 4770 | return; |
| 4771 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 4772 | i9xx_set_pll_dividers(intel_crtc); |
| 4773 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 4774 | if (intel_crtc->config.has_dp_encoder) |
| 4775 | intel_dp_set_m_n(intel_crtc); |
| 4776 | |
| 4777 | intel_set_pipe_timings(intel_crtc); |
| 4778 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 4779 | i9xx_set_pipeconf(intel_crtc); |
| 4780 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4781 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4782 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4783 | if (!IS_GEN2(dev)) |
| 4784 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 4785 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 4786 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 4787 | if (encoder->pre_enable) |
| 4788 | encoder->pre_enable(encoder); |
| 4789 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4790 | i9xx_enable_pll(intel_crtc); |
| 4791 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4792 | i9xx_pfit_enable(intel_crtc); |
| 4793 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 4794 | intel_crtc_load_lut(crtc); |
| 4795 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4796 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4797 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 4798 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4799 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4800 | encoder->enable(encoder); |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 4801 | |
| 4802 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 4803 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4804 | /* |
| 4805 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4806 | * So don't enable underrun reporting before at least some planes |
| 4807 | * are enabled. |
| 4808 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4809 | * but leave the pipe running. |
| 4810 | */ |
| 4811 | if (IS_GEN2(dev)) |
| 4812 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, true); |
| 4813 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 4814 | /* Underruns don't raise interrupts, so check manually. */ |
| 4815 | i9xx_check_fifo_underruns(dev); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4816 | } |
| 4817 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 4818 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 4819 | { |
| 4820 | struct drm_device *dev = crtc->base.dev; |
| 4821 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 4822 | |
| 4823 | if (!crtc->config.gmch_pfit.control) |
| 4824 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 4825 | |
| 4826 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 4827 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 4828 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 4829 | I915_READ(PFIT_CONTROL)); |
| 4830 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 4831 | } |
| 4832 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4833 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 4834 | { |
| 4835 | struct drm_device *dev = crtc->dev; |
| 4836 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4837 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4838 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4839 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4840 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4841 | if (!intel_crtc->active) |
| 4842 | return; |
| 4843 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4844 | /* |
| 4845 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 4846 | * So diasble underrun reporting before all the planes get disabled. |
| 4847 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 4848 | * but leave the pipe running. |
| 4849 | */ |
| 4850 | if (IS_GEN2(dev)) |
| 4851 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, false); |
| 4852 | |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 4853 | /* |
| 4854 | * Vblank time updates from the shadow to live plane control register |
| 4855 | * are blocked if the memory self-refresh mode is active at that |
| 4856 | * moment. So to make sure the plane gets truly disabled, disable |
| 4857 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 4858 | * will be checked/applied by the HW only at the next frame start |
| 4859 | * event which is after the vblank start event, so we need to have a |
| 4860 | * wait-for-vblank between disabling the plane and the pipe. |
| 4861 | */ |
| 4862 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 4863 | intel_crtc_disable_planes(crtc); |
| 4864 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4865 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4866 | encoder->disable(encoder); |
| 4867 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 4868 | /* |
| 4869 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 4870 | * wait for planes to fully turn off before disabling the pipe. |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 4871 | * We also need to wait on all gmch platforms because of the |
| 4872 | * self-refresh mode constraint explained above. |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 4873 | */ |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 4874 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 4875 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4876 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 4877 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 4878 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 4879 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 4880 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4881 | if (encoder->post_disable) |
| 4882 | encoder->post_disable(encoder); |
| 4883 | |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 4884 | if (!intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) { |
| 4885 | if (IS_CHERRYVIEW(dev)) |
| 4886 | chv_disable_pll(dev_priv, pipe); |
| 4887 | else if (IS_VALLEYVIEW(dev)) |
| 4888 | vlv_disable_pll(dev_priv, pipe); |
| 4889 | else |
| 4890 | i9xx_disable_pll(dev_priv, pipe); |
| 4891 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4892 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 4893 | if (!IS_GEN2(dev)) |
| 4894 | intel_set_cpu_fifo_underrun_reporting(dev, pipe, false); |
| 4895 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4896 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4897 | intel_update_watermarks(crtc); |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4898 | |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 4899 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 4900 | intel_update_fbc(dev); |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 4901 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 4902 | } |
| 4903 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4904 | static void i9xx_crtc_off(struct drm_crtc *crtc) |
| 4905 | { |
| 4906 | } |
| 4907 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 4908 | static void intel_crtc_update_sarea(struct drm_crtc *crtc, |
| 4909 | bool enabled) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4910 | { |
| 4911 | struct drm_device *dev = crtc->dev; |
| 4912 | struct drm_i915_master_private *master_priv; |
| 4913 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4914 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4915 | |
| 4916 | if (!dev->primary->master) |
| 4917 | return; |
| 4918 | |
| 4919 | master_priv = dev->primary->master->driver_priv; |
| 4920 | if (!master_priv->sarea_priv) |
| 4921 | return; |
| 4922 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4923 | switch (pipe) { |
| 4924 | case 0: |
| 4925 | master_priv->sarea_priv->pipeA_w = enabled ? crtc->mode.hdisplay : 0; |
| 4926 | master_priv->sarea_priv->pipeA_h = enabled ? crtc->mode.vdisplay : 0; |
| 4927 | break; |
| 4928 | case 1: |
| 4929 | master_priv->sarea_priv->pipeB_w = enabled ? crtc->mode.hdisplay : 0; |
| 4930 | master_priv->sarea_priv->pipeB_h = enabled ? crtc->mode.vdisplay : 0; |
| 4931 | break; |
| 4932 | default: |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 4933 | 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] | 4934 | break; |
| 4935 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4936 | } |
| 4937 | |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 4938 | /* Master function to enable/disable CRTC and corresponding power wells */ |
| 4939 | void intel_crtc_control(struct drm_crtc *crtc, bool enable) |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 4940 | { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 4941 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4942 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 4943 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 4944 | enum intel_display_power_domain domain; |
| 4945 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 4946 | |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 4947 | if (enable) { |
| 4948 | if (!intel_crtc->active) { |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 4949 | domains = get_crtc_power_domains(crtc); |
| 4950 | for_each_power_domain(domain, domains) |
| 4951 | intel_display_power_get(dev_priv, domain); |
| 4952 | intel_crtc->enabled_power_domains = domains; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 4953 | |
| 4954 | dev_priv->display.crtc_enable(crtc); |
| 4955 | } |
| 4956 | } else { |
| 4957 | if (intel_crtc->active) { |
| 4958 | dev_priv->display.crtc_disable(crtc); |
| 4959 | |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 4960 | domains = intel_crtc->enabled_power_domains; |
| 4961 | for_each_power_domain(domain, domains) |
| 4962 | intel_display_power_put(dev_priv, domain); |
| 4963 | intel_crtc->enabled_power_domains = 0; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 4964 | } |
| 4965 | } |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | /** |
| 4969 | * Sets the power management mode of the pipe and plane. |
| 4970 | */ |
| 4971 | void intel_crtc_update_dpms(struct drm_crtc *crtc) |
| 4972 | { |
| 4973 | struct drm_device *dev = crtc->dev; |
| 4974 | struct intel_encoder *intel_encoder; |
| 4975 | bool enable = false; |
| 4976 | |
| 4977 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 4978 | enable |= intel_encoder->connectors_active; |
| 4979 | |
| 4980 | intel_crtc_control(crtc, enable); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 4981 | |
| 4982 | intel_crtc_update_sarea(crtc, enable); |
| 4983 | } |
| 4984 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 4985 | static void intel_crtc_disable(struct drm_crtc *crtc) |
| 4986 | { |
| 4987 | struct drm_device *dev = crtc->dev; |
| 4988 | struct drm_connector *connector; |
| 4989 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 4990 | 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] | 4991 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 4992 | |
| 4993 | /* crtc should still be enabled when we disable it. */ |
| 4994 | WARN_ON(!crtc->enabled); |
| 4995 | |
| 4996 | dev_priv->display.crtc_disable(crtc); |
| 4997 | intel_crtc_update_sarea(crtc, false); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4998 | dev_priv->display.off(crtc); |
| 4999 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 5000 | if (crtc->primary->fb) { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5001 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 5002 | intel_unpin_fb_obj(old_obj); |
| 5003 | i915_gem_track_fb(old_obj, NULL, |
| 5004 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5005 | mutex_unlock(&dev->struct_mutex); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 5006 | crtc->primary->fb = NULL; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5007 | } |
| 5008 | |
| 5009 | /* Update computed state. */ |
| 5010 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 5011 | if (!connector->encoder || !connector->encoder->crtc) |
| 5012 | continue; |
| 5013 | |
| 5014 | if (connector->encoder->crtc != crtc) |
| 5015 | continue; |
| 5016 | |
| 5017 | connector->dpms = DRM_MODE_DPMS_OFF; |
| 5018 | to_intel_encoder(connector->encoder)->connectors_active = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5019 | } |
| 5020 | } |
| 5021 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5022 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 5023 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5024 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5025 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5026 | drm_encoder_cleanup(encoder); |
| 5027 | kfree(intel_encoder); |
| 5028 | } |
| 5029 | |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5030 | /* 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] | 5031 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
| 5032 | * state of the entire output pipe. */ |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5033 | static void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5034 | { |
| 5035 | if (mode == DRM_MODE_DPMS_ON) { |
| 5036 | encoder->connectors_active = true; |
| 5037 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5038 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5039 | } else { |
| 5040 | encoder->connectors_active = false; |
| 5041 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5042 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5043 | } |
| 5044 | } |
| 5045 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5046 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 5047 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5048 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5049 | { |
| 5050 | if (connector->get_hw_state(connector)) { |
| 5051 | struct intel_encoder *encoder = connector->encoder; |
| 5052 | struct drm_crtc *crtc; |
| 5053 | bool encoder_enabled; |
| 5054 | enum pipe pipe; |
| 5055 | |
| 5056 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 5057 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 5058 | connector->base.name); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5059 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5060 | /* there is no real hw state for MST connectors */ |
| 5061 | if (connector->mst_port) |
| 5062 | return; |
| 5063 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5064 | WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
| 5065 | "wrong connector dpms state\n"); |
| 5066 | WARN(connector->base.encoder != &encoder->base, |
| 5067 | "active connector not linked to encoder\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5068 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5069 | if (encoder) { |
| 5070 | WARN(!encoder->connectors_active, |
| 5071 | "encoder->connectors_active not set\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5072 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5073 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); |
| 5074 | WARN(!encoder_enabled, "encoder not enabled\n"); |
| 5075 | if (WARN_ON(!encoder->base.crtc)) |
| 5076 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5077 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5078 | crtc = encoder->base.crtc; |
| 5079 | |
| 5080 | WARN(!crtc->enabled, "crtc not enabled\n"); |
| 5081 | WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
| 5082 | WARN(pipe != to_intel_crtc(crtc)->pipe, |
| 5083 | "encoder active on the wrong pipe\n"); |
| 5084 | } |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5085 | } |
| 5086 | } |
| 5087 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5088 | /* Even simpler default implementation, if there's really no special case to |
| 5089 | * consider. */ |
| 5090 | void intel_connector_dpms(struct drm_connector *connector, int mode) |
| 5091 | { |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5092 | /* All the simple cases only support two dpms states. */ |
| 5093 | if (mode != DRM_MODE_DPMS_ON) |
| 5094 | mode = DRM_MODE_DPMS_OFF; |
| 5095 | |
| 5096 | if (mode == connector->dpms) |
| 5097 | return; |
| 5098 | |
| 5099 | connector->dpms = mode; |
| 5100 | |
| 5101 | /* Only need to change hw state when actually enabled */ |
Chris Wilson | c9976dc | 2013-09-29 19:15:07 +0100 | [diff] [blame] | 5102 | if (connector->encoder) |
| 5103 | intel_encoder_dpms(to_intel_encoder(connector->encoder), mode); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5104 | |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5105 | intel_modeset_check_state(connector->dev); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5106 | } |
| 5107 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5108 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 5109 | * one connector and no cloning and hence the encoder state determines the state |
| 5110 | * of the connector. */ |
| 5111 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 5112 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 5113 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5114 | struct intel_encoder *encoder = connector->encoder; |
| 5115 | |
| 5116 | return encoder->get_hw_state(encoder, &pipe); |
| 5117 | } |
| 5118 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5119 | static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
| 5120 | struct intel_crtc_config *pipe_config) |
| 5121 | { |
| 5122 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5123 | struct intel_crtc *pipe_B_crtc = |
| 5124 | to_intel_crtc(dev_priv->pipe_to_crtc_mapping[PIPE_B]); |
| 5125 | |
| 5126 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 5127 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5128 | if (pipe_config->fdi_lanes > 4) { |
| 5129 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 5130 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5131 | return false; |
| 5132 | } |
| 5133 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 5134 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5135 | if (pipe_config->fdi_lanes > 2) { |
| 5136 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 5137 | pipe_config->fdi_lanes); |
| 5138 | return false; |
| 5139 | } else { |
| 5140 | return true; |
| 5141 | } |
| 5142 | } |
| 5143 | |
| 5144 | if (INTEL_INFO(dev)->num_pipes == 2) |
| 5145 | return true; |
| 5146 | |
| 5147 | /* Ivybridge 3 pipe is really complicated */ |
| 5148 | switch (pipe) { |
| 5149 | case PIPE_A: |
| 5150 | return true; |
| 5151 | case PIPE_B: |
| 5152 | if (dev_priv->pipe_to_crtc_mapping[PIPE_C]->enabled && |
| 5153 | pipe_config->fdi_lanes > 2) { |
| 5154 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 5155 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5156 | return false; |
| 5157 | } |
| 5158 | return true; |
| 5159 | case PIPE_C: |
Daniel Vetter | 1e833f4 | 2013-02-19 22:31:57 +0100 | [diff] [blame] | 5160 | if (!pipe_has_enabled_pch(pipe_B_crtc) || |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5161 | pipe_B_crtc->config.fdi_lanes <= 2) { |
| 5162 | if (pipe_config->fdi_lanes > 2) { |
| 5163 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 5164 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5165 | return false; |
| 5166 | } |
| 5167 | } else { |
| 5168 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
| 5169 | return false; |
| 5170 | } |
| 5171 | return true; |
| 5172 | default: |
| 5173 | BUG(); |
| 5174 | } |
| 5175 | } |
| 5176 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5177 | #define RETRY 1 |
| 5178 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, |
| 5179 | struct intel_crtc_config *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5180 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5181 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5182 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 5183 | int lane, link_bw, fdi_dotclock; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5184 | bool setup_ok, needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5185 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5186 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5187 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 5188 | * each output octet as 10 bits. The actual frequency |
| 5189 | * is stored as a divider into a 100MHz clock, and the |
| 5190 | * mode pixel clock is stored in units of 1KHz. |
| 5191 | * Hence the bw of each lane in terms of the mode signal |
| 5192 | * is: |
| 5193 | */ |
| 5194 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
| 5195 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5196 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5197 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5198 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5199 | pipe_config->pipe_bpp); |
| 5200 | |
| 5201 | pipe_config->fdi_lanes = lane; |
| 5202 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5203 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5204 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5205 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5206 | setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
| 5207 | intel_crtc->pipe, pipe_config); |
| 5208 | if (!setup_ok && pipe_config->pipe_bpp > 6*3) { |
| 5209 | pipe_config->pipe_bpp -= 2*3; |
| 5210 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 5211 | pipe_config->pipe_bpp); |
| 5212 | needs_recompute = true; |
| 5213 | pipe_config->bw_constrained = true; |
| 5214 | |
| 5215 | goto retry; |
| 5216 | } |
| 5217 | |
| 5218 | if (needs_recompute) |
| 5219 | return RETRY; |
| 5220 | |
| 5221 | return setup_ok ? 0 : -EINVAL; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5222 | } |
| 5223 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5224 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
| 5225 | struct intel_crtc_config *pipe_config) |
| 5226 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5227 | pipe_config->ips_enabled = i915.enable_ips && |
Paulo Zanoni | 3c4ca58 | 2013-05-31 16:33:23 -0300 | [diff] [blame] | 5228 | hsw_crtc_supports_ips(crtc) && |
Jesse Barnes | b6dfdc9 | 2013-07-25 10:06:50 -0700 | [diff] [blame] | 5229 | pipe_config->pipe_bpp <= 24; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5230 | } |
| 5231 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5232 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5233 | struct intel_crtc_config *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5234 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5235 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 5236 | struct drm_display_mode *adjusted_mode = &pipe_config->adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5237 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5238 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5239 | if (INTEL_INFO(dev)->gen < 4) { |
| 5240 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5241 | int clock_limit = |
| 5242 | dev_priv->display.get_display_clock_speed(dev); |
| 5243 | |
| 5244 | /* |
| 5245 | * Enable pixel doubling when the dot clock |
| 5246 | * is > 90% of the (display) core speed. |
| 5247 | * |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5248 | * GDG double wide on either pipe, |
| 5249 | * otherwise pipe A only. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5250 | */ |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5251 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5252 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5253 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5254 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5255 | } |
| 5256 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5257 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5258 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5259 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5260 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 5261 | /* |
| 5262 | * Pipe horizontal size must be even in: |
| 5263 | * - DVO ganged mode |
| 5264 | * - LVDS dual channel mode |
| 5265 | * - Double wide pipe |
| 5266 | */ |
| 5267 | if ((intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
| 5268 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 5269 | pipe_config->pipe_src_w &= ~1; |
| 5270 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 5271 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 5272 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5273 | */ |
| 5274 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
| 5275 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5276 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5277 | |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5278 | 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] | 5279 | pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */ |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5280 | } 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] | 5281 | /* only a 8bpc pipe, with 6bpc dither through the panel fitter |
| 5282 | * for lvds. */ |
| 5283 | pipe_config->pipe_bpp = 8*3; |
| 5284 | } |
| 5285 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 5286 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5287 | hsw_compute_ips_config(crtc, pipe_config); |
| 5288 | |
Daniel Vetter | 1203043 | 2014-06-25 22:02:00 +0300 | [diff] [blame] | 5289 | /* |
| 5290 | * XXX: PCH/WRPLL clock sharing is done in ->mode_set, so make sure the |
| 5291 | * old clock survives for now. |
| 5292 | */ |
| 5293 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev) || HAS_DDI(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5294 | pipe_config->shared_dpll = crtc->config.shared_dpll; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5295 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5296 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5297 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5298 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5299 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5300 | } |
| 5301 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 5302 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 5303 | { |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5304 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5305 | int vco = valleyview_get_vco(dev_priv); |
| 5306 | u32 val; |
| 5307 | int divider; |
| 5308 | |
Ville Syrjälä | d49a340 | 2014-06-28 02:03:58 +0300 | [diff] [blame] | 5309 | /* FIXME: Punit isn't quite ready yet */ |
| 5310 | if (IS_CHERRYVIEW(dev)) |
| 5311 | return 400000; |
| 5312 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5313 | mutex_lock(&dev_priv->dpio_lock); |
| 5314 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
| 5315 | mutex_unlock(&dev_priv->dpio_lock); |
| 5316 | |
| 5317 | divider = val & DISPLAY_FREQUENCY_VALUES; |
| 5318 | |
Ville Syrjälä | 7d007f4 | 2014-06-13 13:37:53 +0300 | [diff] [blame] | 5319 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
| 5320 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 5321 | "cdclk change in progress\n"); |
| 5322 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5323 | return DIV_ROUND_CLOSEST(vco << 1, divider + 1); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 5324 | } |
| 5325 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5326 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5327 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5328 | return 400000; |
| 5329 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5330 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5331 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 5332 | { |
| 5333 | return 333000; |
| 5334 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5335 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5336 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 5337 | { |
| 5338 | return 200000; |
| 5339 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5340 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 5341 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 5342 | { |
| 5343 | u16 gcfgc = 0; |
| 5344 | |
| 5345 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 5346 | |
| 5347 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 5348 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
| 5349 | return 267000; |
| 5350 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
| 5351 | return 333000; |
| 5352 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
| 5353 | return 444000; |
| 5354 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 5355 | return 200000; |
| 5356 | default: |
| 5357 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 5358 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
| 5359 | return 133000; |
| 5360 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
| 5361 | return 167000; |
| 5362 | } |
| 5363 | } |
| 5364 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5365 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 5366 | { |
| 5367 | u16 gcfgc = 0; |
| 5368 | |
| 5369 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 5370 | |
| 5371 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5372 | return 133000; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5373 | else { |
| 5374 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 5375 | case GC_DISPLAY_CLOCK_333_MHZ: |
| 5376 | return 333000; |
| 5377 | default: |
| 5378 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 5379 | return 190000; |
| 5380 | } |
| 5381 | } |
| 5382 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5383 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5384 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 5385 | { |
| 5386 | return 266000; |
| 5387 | } |
| 5388 | |
| 5389 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 5390 | { |
| 5391 | u16 hpllcc = 0; |
| 5392 | /* Assume that the hardware is in the high speed state. This |
| 5393 | * should be the default. |
| 5394 | */ |
| 5395 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 5396 | case GC_CLOCK_133_200: |
| 5397 | case GC_CLOCK_100_200: |
| 5398 | return 200000; |
| 5399 | case GC_CLOCK_166_250: |
| 5400 | return 250000; |
| 5401 | case GC_CLOCK_100_133: |
| 5402 | return 133000; |
| 5403 | } |
| 5404 | |
| 5405 | /* Shouldn't happen */ |
| 5406 | return 0; |
| 5407 | } |
| 5408 | |
| 5409 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 5410 | { |
| 5411 | return 133000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5412 | } |
| 5413 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5414 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5415 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5416 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5417 | while (*num > DATA_LINK_M_N_MASK || |
| 5418 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5419 | *num >>= 1; |
| 5420 | *den >>= 1; |
| 5421 | } |
| 5422 | } |
| 5423 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5424 | static void compute_m_n(unsigned int m, unsigned int n, |
| 5425 | uint32_t *ret_m, uint32_t *ret_n) |
| 5426 | { |
| 5427 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 5428 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 5429 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 5430 | } |
| 5431 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5432 | void |
| 5433 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 5434 | int pixel_clock, int link_clock, |
| 5435 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5436 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5437 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5438 | |
| 5439 | compute_m_n(bits_per_pixel * pixel_clock, |
| 5440 | link_clock * nlanes * 8, |
| 5441 | &m_n->gmch_m, &m_n->gmch_n); |
| 5442 | |
| 5443 | compute_m_n(pixel_clock, link_clock, |
| 5444 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5445 | } |
| 5446 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 5447 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 5448 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5449 | if (i915.panel_use_ssc >= 0) |
| 5450 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5451 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 5452 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 5453 | } |
| 5454 | |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5455 | static int i9xx_get_refclk(struct drm_crtc *crtc, int num_connectors) |
| 5456 | { |
| 5457 | struct drm_device *dev = crtc->dev; |
| 5458 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5459 | int refclk; |
| 5460 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5461 | if (IS_VALLEYVIEW(dev)) { |
Daniel Vetter | 9a0ea49 | 2013-09-16 11:29:34 +0200 | [diff] [blame] | 5462 | refclk = 100000; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5463 | } else if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5464 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 5465 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 5466 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5467 | } else if (!IS_GEN2(dev)) { |
| 5468 | refclk = 96000; |
| 5469 | } else { |
| 5470 | refclk = 48000; |
| 5471 | } |
| 5472 | |
| 5473 | return refclk; |
| 5474 | } |
| 5475 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5476 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5477 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 5478 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5479 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5480 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5481 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 5482 | { |
| 5483 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5484 | } |
| 5485 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5486 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5487 | intel_clock_t *reduced_clock) |
| 5488 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5489 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5490 | u32 fp, fp2 = 0; |
| 5491 | |
| 5492 | if (IS_PINEVIEW(dev)) { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5493 | fp = pnv_dpll_compute_fp(&crtc->config.dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5494 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5495 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5496 | } else { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5497 | fp = i9xx_dpll_compute_fp(&crtc->config.dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5498 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5499 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5500 | } |
| 5501 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5502 | crtc->config.dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5503 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5504 | crtc->lowfreq_avail = false; |
| 5505 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5506 | reduced_clock && i915.powersave) { |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5507 | crtc->config.dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5508 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5509 | } else { |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5510 | crtc->config.dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5511 | } |
| 5512 | } |
| 5513 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 5514 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 5515 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5516 | { |
| 5517 | u32 reg_val; |
| 5518 | |
| 5519 | /* |
| 5520 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 5521 | * and set it to a reasonable value instead. |
| 5522 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5523 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5524 | reg_val &= 0xffffff00; |
| 5525 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5526 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5527 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5528 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5529 | reg_val &= 0x8cffffff; |
| 5530 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5531 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5532 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5533 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5534 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5535 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5536 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5537 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5538 | reg_val &= 0x00ffffff; |
| 5539 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5540 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5541 | } |
| 5542 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5543 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 5544 | struct intel_link_m_n *m_n) |
| 5545 | { |
| 5546 | struct drm_device *dev = crtc->base.dev; |
| 5547 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5548 | int pipe = crtc->pipe; |
| 5549 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 5550 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 5551 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 5552 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 5553 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5554 | } |
| 5555 | |
| 5556 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 5557 | struct intel_link_m_n *m_n, |
| 5558 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5559 | { |
| 5560 | struct drm_device *dev = crtc->base.dev; |
| 5561 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5562 | int pipe = crtc->pipe; |
| 5563 | enum transcoder transcoder = crtc->config.cpu_transcoder; |
| 5564 | |
| 5565 | if (INTEL_INFO(dev)->gen >= 5) { |
| 5566 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 5567 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 5568 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 5569 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 5570 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 5571 | * for gen < 8) and if DRRS is supported (to make sure the |
| 5572 | * registers are not unnecessarily accessed). |
| 5573 | */ |
| 5574 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
| 5575 | crtc->config.has_drrs) { |
| 5576 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 5577 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 5578 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 5579 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 5580 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 5581 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5582 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 5583 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 5584 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 5585 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 5586 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 5587 | } |
| 5588 | } |
| 5589 | |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 5590 | void intel_dp_set_m_n(struct intel_crtc *crtc) |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 5591 | { |
| 5592 | if (crtc->config.has_pch_encoder) |
| 5593 | intel_pch_transcoder_set_m_n(crtc, &crtc->config.dp_m_n); |
| 5594 | else |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 5595 | intel_cpu_transcoder_set_m_n(crtc, &crtc->config.dp_m_n, |
| 5596 | &crtc->config.dp_m2_n2); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 5597 | } |
| 5598 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5599 | static void vlv_update_pll(struct intel_crtc *crtc) |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5600 | { |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5601 | u32 dpll, dpll_md; |
| 5602 | |
| 5603 | /* |
| 5604 | * Enable DPIO clock input. We should never disable the reference |
| 5605 | * clock for pipe B, since VGA hotplug / manual detection depends |
| 5606 | * on it. |
| 5607 | */ |
| 5608 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | |
| 5609 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; |
| 5610 | /* We should never disable this, set it here for state tracking */ |
| 5611 | if (crtc->pipe == PIPE_B) |
| 5612 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 5613 | dpll |= DPLL_VCO_ENABLE; |
| 5614 | crtc->config.dpll_hw_state.dpll = dpll; |
| 5615 | |
| 5616 | dpll_md = (crtc->config.pixel_multiplier - 1) |
| 5617 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 5618 | crtc->config.dpll_hw_state.dpll_md = dpll_md; |
| 5619 | } |
| 5620 | |
| 5621 | static void vlv_prepare_pll(struct intel_crtc *crtc) |
| 5622 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5623 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5624 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5625 | int pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5626 | u32 mdiv; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5627 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5628 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5629 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 5630 | mutex_lock(&dev_priv->dpio_lock); |
| 5631 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5632 | bestn = crtc->config.dpll.n; |
| 5633 | bestm1 = crtc->config.dpll.m1; |
| 5634 | bestm2 = crtc->config.dpll.m2; |
| 5635 | bestp1 = crtc->config.dpll.p1; |
| 5636 | bestp2 = crtc->config.dpll.p2; |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5637 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5638 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 5639 | |
| 5640 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5641 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 5642 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5643 | |
| 5644 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5645 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5646 | |
| 5647 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5648 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5649 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5650 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5651 | |
| 5652 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5653 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5654 | |
| 5655 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5656 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 5657 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 5658 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5659 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 5660 | |
| 5661 | /* |
| 5662 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 5663 | * but we don't support that). |
| 5664 | * Note: don't use the DAC post divider as it seems unstable. |
| 5665 | */ |
| 5666 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5667 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5668 | |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5669 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5670 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5671 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5672 | /* Set HBR and RBR LPF coefficients */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 5673 | if (crtc->config.port_clock == 162000 || |
Ville Syrjälä | 99750bd | 2013-06-14 14:02:52 +0300 | [diff] [blame] | 5674 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_ANALOG) || |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5675 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5676 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b012 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 5677 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5678 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5679 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5680 | 0x00d0000f); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5681 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5682 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP) || |
| 5683 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) { |
| 5684 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5685 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5686 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5687 | 0x0df40000); |
| 5688 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5689 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5690 | 0x0df70000); |
| 5691 | } else { /* HDMI or VGA */ |
| 5692 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 5693 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5694 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5695 | 0x0df70000); |
| 5696 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5697 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5698 | 0x0df40000); |
| 5699 | } |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5700 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5701 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5702 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
| 5703 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT) || |
| 5704 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_EDP)) |
| 5705 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5706 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5707 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5708 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 5709 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | a0c4da2 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5710 | } |
| 5711 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5712 | static void chv_update_pll(struct intel_crtc *crtc) |
| 5713 | { |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5714 | crtc->config.dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV | |
| 5715 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
| 5716 | DPLL_VCO_ENABLE; |
| 5717 | if (crtc->pipe != PIPE_A) |
| 5718 | crtc->config.dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 5719 | |
| 5720 | crtc->config.dpll_hw_state.dpll_md = |
| 5721 | (crtc->config.pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
| 5722 | } |
| 5723 | |
| 5724 | static void chv_prepare_pll(struct intel_crtc *crtc) |
| 5725 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5726 | struct drm_device *dev = crtc->base.dev; |
| 5727 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5728 | int pipe = crtc->pipe; |
| 5729 | int dpll_reg = DPLL(crtc->pipe); |
| 5730 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Ville Syrjälä | 580d381 | 2014-04-09 13:29:00 +0300 | [diff] [blame] | 5731 | u32 loopfilter, intcoeff; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5732 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
| 5733 | int refclk; |
| 5734 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5735 | bestn = crtc->config.dpll.n; |
| 5736 | bestm2_frac = crtc->config.dpll.m2 & 0x3fffff; |
| 5737 | bestm1 = crtc->config.dpll.m1; |
| 5738 | bestm2 = crtc->config.dpll.m2 >> 22; |
| 5739 | bestp1 = crtc->config.dpll.p1; |
| 5740 | bestp2 = crtc->config.dpll.p2; |
| 5741 | |
| 5742 | /* |
| 5743 | * Enable Refclk and SSC |
| 5744 | */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 5745 | I915_WRITE(dpll_reg, |
| 5746 | crtc->config.dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
| 5747 | |
| 5748 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5749 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5750 | /* p1 and p2 divider */ |
| 5751 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 5752 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 5753 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 5754 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 5755 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 5756 | |
| 5757 | /* Feedback post-divider - m2 */ |
| 5758 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 5759 | |
| 5760 | /* Feedback refclk divider - n and m1 */ |
| 5761 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 5762 | DPIO_CHV_M1_DIV_BY_2 | |
| 5763 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 5764 | |
| 5765 | /* M2 fraction division */ |
| 5766 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
| 5767 | |
| 5768 | /* M2 fraction division enable */ |
| 5769 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), |
| 5770 | DPIO_CHV_FRAC_DIV_EN | |
| 5771 | (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT)); |
| 5772 | |
| 5773 | /* Loop filter */ |
| 5774 | refclk = i9xx_get_refclk(&crtc->base, 0); |
| 5775 | loopfilter = 5 << DPIO_CHV_PROP_COEFF_SHIFT | |
| 5776 | 2 << DPIO_CHV_GAIN_CTRL_SHIFT; |
| 5777 | if (refclk == 100000) |
| 5778 | intcoeff = 11; |
| 5779 | else if (refclk == 38400) |
| 5780 | intcoeff = 10; |
| 5781 | else |
| 5782 | intcoeff = 9; |
| 5783 | loopfilter |= intcoeff << DPIO_CHV_INT_COEFF_SHIFT; |
| 5784 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 5785 | |
| 5786 | /* AFC Recal */ |
| 5787 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 5788 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 5789 | DPIO_AFC_RECAL); |
| 5790 | |
| 5791 | mutex_unlock(&dev_priv->dpio_lock); |
| 5792 | } |
| 5793 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5794 | static void i9xx_update_pll(struct intel_crtc *crtc, |
| 5795 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5796 | int num_connectors) |
| 5797 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5798 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5799 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5800 | u32 dpll; |
| 5801 | bool is_sdvo; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5802 | struct dpll *clock = &crtc->config.dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5803 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5804 | i9xx_update_pll_dividers(crtc, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 5805 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5806 | is_sdvo = intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_SDVO) || |
| 5807 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5808 | |
| 5809 | dpll = DPLL_VGA_MODE_DIS; |
| 5810 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5811 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5812 | dpll |= DPLLB_MODE_LVDS; |
| 5813 | else |
| 5814 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 5815 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 5816 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 5817 | dpll |= (crtc->config.pixel_multiplier - 1) |
| 5818 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5819 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 5820 | |
| 5821 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 5822 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 5823 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5824 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DISPLAYPORT)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 5825 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5826 | |
| 5827 | /* compute bitmask from p1 value */ |
| 5828 | if (IS_PINEVIEW(dev)) |
| 5829 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 5830 | else { |
| 5831 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 5832 | if (IS_G4X(dev) && reduced_clock) |
| 5833 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 5834 | } |
| 5835 | switch (clock->p2) { |
| 5836 | case 5: |
| 5837 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 5838 | break; |
| 5839 | case 7: |
| 5840 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 5841 | break; |
| 5842 | case 10: |
| 5843 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 5844 | break; |
| 5845 | case 14: |
| 5846 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 5847 | break; |
| 5848 | } |
| 5849 | if (INTEL_INFO(dev)->gen >= 4) |
| 5850 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 5851 | |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 5852 | if (crtc->config.sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5853 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5854 | else if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5855 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 5856 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 5857 | else |
| 5858 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 5859 | |
| 5860 | dpll |= DPLL_VCO_ENABLE; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5861 | crtc->config.dpll_hw_state.dpll = dpll; |
| 5862 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5863 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 5864 | u32 dpll_md = (crtc->config.pixel_multiplier - 1) |
| 5865 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5866 | crtc->config.dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5867 | } |
| 5868 | } |
| 5869 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5870 | static void i8xx_update_pll(struct intel_crtc *crtc, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5871 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5872 | int num_connectors) |
| 5873 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5874 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5875 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5876 | u32 dpll; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5877 | struct dpll *clock = &crtc->config.dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5878 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5879 | i9xx_update_pll_dividers(crtc, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 5880 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5881 | dpll = DPLL_VGA_MODE_DIS; |
| 5882 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5883 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5884 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 5885 | } else { |
| 5886 | if (clock->p1 == 2) |
| 5887 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 5888 | else |
| 5889 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 5890 | if (clock->p2 == 4) |
| 5891 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 5892 | } |
| 5893 | |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 5894 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_DVO)) |
| 5895 | dpll |= DPLL_DVO_2X_MODE; |
| 5896 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5897 | if (intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5898 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 5899 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 5900 | else |
| 5901 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 5902 | |
| 5903 | dpll |= DPLL_VCO_ENABLE; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 5904 | crtc->config.dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 5905 | } |
| 5906 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 5907 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5908 | { |
| 5909 | struct drm_device *dev = intel_crtc->base.dev; |
| 5910 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5911 | enum pipe pipe = intel_crtc->pipe; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 5912 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 5913 | struct drm_display_mode *adjusted_mode = |
| 5914 | &intel_crtc->config.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 5915 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 5916 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 5917 | |
| 5918 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 5919 | * the hw state checker will get angry at the mismatch. */ |
| 5920 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 5921 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5922 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 5923 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5924 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 5925 | crtc_vtotal -= 1; |
| 5926 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 5927 | |
| 5928 | if (intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO)) |
| 5929 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 5930 | else |
| 5931 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 5932 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 5933 | if (vsyncshift < 0) |
| 5934 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5935 | } |
| 5936 | |
| 5937 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 5938 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5939 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 5940 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5941 | (adjusted_mode->crtc_hdisplay - 1) | |
| 5942 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 5943 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5944 | (adjusted_mode->crtc_hblank_start - 1) | |
| 5945 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 5946 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5947 | (adjusted_mode->crtc_hsync_start - 1) | |
| 5948 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 5949 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 5950 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5951 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 5952 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 5953 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5954 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 5955 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 5956 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5957 | (adjusted_mode->crtc_vsync_start - 1) | |
| 5958 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 5959 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 5960 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 5961 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 5962 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 5963 | * bits. */ |
| 5964 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 5965 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 5966 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 5967 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5968 | /* pipesrc controls the size that is scaled from, which should |
| 5969 | * always be the user's requested size. |
| 5970 | */ |
| 5971 | I915_WRITE(PIPESRC(pipe), |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 5972 | ((intel_crtc->config.pipe_src_w - 1) << 16) | |
| 5973 | (intel_crtc->config.pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 5974 | } |
| 5975 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 5976 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
| 5977 | struct intel_crtc_config *pipe_config) |
| 5978 | { |
| 5979 | struct drm_device *dev = crtc->base.dev; |
| 5980 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5981 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 5982 | uint32_t tmp; |
| 5983 | |
| 5984 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
| 5985 | pipe_config->adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 5986 | pipe_config->adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
| 5987 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
| 5988 | pipe_config->adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 5989 | pipe_config->adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
| 5990 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
| 5991 | pipe_config->adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 5992 | pipe_config->adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
| 5993 | |
| 5994 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
| 5995 | pipe_config->adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 5996 | pipe_config->adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
| 5997 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
| 5998 | pipe_config->adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 5999 | pipe_config->adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
| 6000 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
| 6001 | pipe_config->adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 6002 | pipe_config->adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
| 6003 | |
| 6004 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
| 6005 | pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 6006 | pipe_config->adjusted_mode.crtc_vtotal += 1; |
| 6007 | pipe_config->adjusted_mode.crtc_vblank_end += 1; |
| 6008 | } |
| 6009 | |
| 6010 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 6011 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 6012 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 6013 | |
| 6014 | pipe_config->requested_mode.vdisplay = pipe_config->pipe_src_h; |
| 6015 | pipe_config->requested_mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6016 | } |
| 6017 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6018 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
| 6019 | struct intel_crtc_config *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6020 | { |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6021 | mode->hdisplay = pipe_config->adjusted_mode.crtc_hdisplay; |
| 6022 | mode->htotal = pipe_config->adjusted_mode.crtc_htotal; |
| 6023 | mode->hsync_start = pipe_config->adjusted_mode.crtc_hsync_start; |
| 6024 | mode->hsync_end = pipe_config->adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6025 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6026 | mode->vdisplay = pipe_config->adjusted_mode.crtc_vdisplay; |
| 6027 | mode->vtotal = pipe_config->adjusted_mode.crtc_vtotal; |
| 6028 | mode->vsync_start = pipe_config->adjusted_mode.crtc_vsync_start; |
| 6029 | mode->vsync_end = pipe_config->adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6030 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6031 | mode->flags = pipe_config->adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6032 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6033 | mode->clock = pipe_config->adjusted_mode.crtc_clock; |
| 6034 | mode->flags |= pipe_config->adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6035 | } |
| 6036 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6037 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 6038 | { |
| 6039 | struct drm_device *dev = intel_crtc->base.dev; |
| 6040 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6041 | uint32_t pipeconf; |
| 6042 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6043 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6044 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame^] | 6045 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 6046 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 6047 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 6048 | |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6049 | if (intel_crtc->config.double_wide) |
| 6050 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6051 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6052 | /* only g4x and later have fancy bpc/dither controls */ |
| 6053 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6054 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
| 6055 | if (intel_crtc->config.dither && intel_crtc->config.pipe_bpp != 30) |
| 6056 | pipeconf |= PIPECONF_DITHER_EN | |
| 6057 | PIPECONF_DITHER_TYPE_SP; |
| 6058 | |
| 6059 | switch (intel_crtc->config.pipe_bpp) { |
| 6060 | case 18: |
| 6061 | pipeconf |= PIPECONF_6BPC; |
| 6062 | break; |
| 6063 | case 24: |
| 6064 | pipeconf |= PIPECONF_8BPC; |
| 6065 | break; |
| 6066 | case 30: |
| 6067 | pipeconf |= PIPECONF_10BPC; |
| 6068 | break; |
| 6069 | default: |
| 6070 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 6071 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6072 | } |
| 6073 | } |
| 6074 | |
| 6075 | if (HAS_PIPE_CXSR(dev)) { |
| 6076 | if (intel_crtc->lowfreq_avail) { |
| 6077 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 6078 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 6079 | } else { |
| 6080 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6081 | } |
| 6082 | } |
| 6083 | |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 6084 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
| 6085 | if (INTEL_INFO(dev)->gen < 4 || |
| 6086 | intel_pipe_has_type(&intel_crtc->base, INTEL_OUTPUT_SDVO)) |
| 6087 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 6088 | else |
| 6089 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 6090 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6091 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 6092 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6093 | if (IS_VALLEYVIEW(dev) && intel_crtc->config.limited_color_range) |
| 6094 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 6095 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6096 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 6097 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 6098 | } |
| 6099 | |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6100 | static int i9xx_crtc_mode_set(struct drm_crtc *crtc, |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6101 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 6102 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6103 | { |
| 6104 | struct drm_device *dev = crtc->dev; |
| 6105 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6106 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6107 | int refclk, num_connectors = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6108 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | a16af721 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 6109 | bool ok, has_reduced_clock = false; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6110 | bool is_lvds = false, is_dsi = false; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6111 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 6112 | const intel_limit_t *limit; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6113 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 6114 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6115 | switch (encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6116 | case INTEL_OUTPUT_LVDS: |
| 6117 | is_lvds = true; |
| 6118 | break; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6119 | case INTEL_OUTPUT_DSI: |
| 6120 | is_dsi = true; |
| 6121 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6122 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 6123 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6124 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6125 | } |
| 6126 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6127 | if (is_dsi) |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6128 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6129 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6130 | if (!intel_crtc->config.clock_set) { |
| 6131 | refclk = i9xx_get_refclk(crtc, num_connectors); |
| 6132 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6133 | /* |
| 6134 | * Returns a set of divisors for the desired target clock with |
| 6135 | * the given refclk, or FALSE. The returned values represent |
| 6136 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + |
| 6137 | * 2) / p1 / p2. |
| 6138 | */ |
| 6139 | limit = intel_limit(crtc, refclk); |
| 6140 | ok = dev_priv->display.find_dpll(limit, crtc, |
| 6141 | intel_crtc->config.port_clock, |
| 6142 | refclk, NULL, &clock); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6143 | if (!ok) { |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6144 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 6145 | return -EINVAL; |
| 6146 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6147 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6148 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 6149 | /* |
| 6150 | * Ensure we match the reduced clock's P to the target |
| 6151 | * clock. If the clocks don't match, we can't switch |
| 6152 | * the display clock by using the FP0/FP1. In such case |
| 6153 | * we will disable the LVDS downclock feature. |
| 6154 | */ |
| 6155 | has_reduced_clock = |
| 6156 | dev_priv->display.find_dpll(limit, crtc, |
| 6157 | dev_priv->lvds_downclock, |
| 6158 | refclk, &clock, |
| 6159 | &reduced_clock); |
| 6160 | } |
| 6161 | /* Compat-code for transition, will disappear. */ |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6162 | intel_crtc->config.dpll.n = clock.n; |
| 6163 | intel_crtc->config.dpll.m1 = clock.m1; |
| 6164 | intel_crtc->config.dpll.m2 = clock.m2; |
| 6165 | intel_crtc->config.dpll.p1 = clock.p1; |
| 6166 | intel_crtc->config.dpll.p2 = clock.p2; |
| 6167 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6168 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6169 | if (IS_GEN2(dev)) { |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 6170 | i8xx_update_pll(intel_crtc, |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6171 | has_reduced_clock ? &reduced_clock : NULL, |
| 6172 | num_connectors); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6173 | } else if (IS_CHERRYVIEW(dev)) { |
| 6174 | chv_update_pll(intel_crtc); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6175 | } else if (IS_VALLEYVIEW(dev)) { |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6176 | vlv_update_pll(intel_crtc); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6177 | } else { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6178 | i9xx_update_pll(intel_crtc, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6179 | has_reduced_clock ? &reduced_clock : NULL, |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 6180 | num_connectors); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6181 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6182 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 6183 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6184 | } |
| 6185 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6186 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
| 6187 | struct intel_crtc_config *pipe_config) |
| 6188 | { |
| 6189 | struct drm_device *dev = crtc->base.dev; |
| 6190 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6191 | uint32_t tmp; |
| 6192 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 6193 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 6194 | return; |
| 6195 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6196 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6197 | if (!(tmp & PFIT_ENABLE)) |
| 6198 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6199 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6200 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6201 | if (INTEL_INFO(dev)->gen < 4) { |
| 6202 | if (crtc->pipe != PIPE_B) |
| 6203 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6204 | } else { |
| 6205 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 6206 | return; |
| 6207 | } |
| 6208 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6209 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6210 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 6211 | if (INTEL_INFO(dev)->gen < 5) |
| 6212 | pipe_config->gmch_pfit.lvds_border_bits = |
| 6213 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 6214 | } |
| 6215 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6216 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
| 6217 | struct intel_crtc_config *pipe_config) |
| 6218 | { |
| 6219 | struct drm_device *dev = crtc->base.dev; |
| 6220 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6221 | int pipe = pipe_config->cpu_transcoder; |
| 6222 | intel_clock_t clock; |
| 6223 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 6224 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6225 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 6226 | /* In case of MIPI DPLL will not even be used */ |
| 6227 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) |
| 6228 | return; |
| 6229 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6230 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6231 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6232 | mutex_unlock(&dev_priv->dpio_lock); |
| 6233 | |
| 6234 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 6235 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 6236 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 6237 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 6238 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 6239 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 6240 | vlv_clock(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6241 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 6242 | /* clock.dot is the fast clock */ |
| 6243 | pipe_config->port_clock = clock.dot / 5; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6244 | } |
| 6245 | |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6246 | static void i9xx_get_plane_config(struct intel_crtc *crtc, |
| 6247 | struct intel_plane_config *plane_config) |
| 6248 | { |
| 6249 | struct drm_device *dev = crtc->base.dev; |
| 6250 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6251 | u32 val, base, offset; |
| 6252 | int pipe = crtc->pipe, plane = crtc->plane; |
| 6253 | int fourcc, pixel_format; |
| 6254 | int aligned_height; |
| 6255 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 6256 | crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL); |
| 6257 | if (!crtc->base.primary->fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6258 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 6259 | return; |
| 6260 | } |
| 6261 | |
| 6262 | val = I915_READ(DSPCNTR(plane)); |
| 6263 | |
| 6264 | if (INTEL_INFO(dev)->gen >= 4) |
| 6265 | if (val & DISPPLANE_TILED) |
| 6266 | plane_config->tiled = true; |
| 6267 | |
| 6268 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
| 6269 | fourcc = intel_format_to_fourcc(pixel_format); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 6270 | crtc->base.primary->fb->pixel_format = fourcc; |
| 6271 | crtc->base.primary->fb->bits_per_pixel = |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6272 | drm_format_plane_cpp(fourcc, 0) * 8; |
| 6273 | |
| 6274 | if (INTEL_INFO(dev)->gen >= 4) { |
| 6275 | if (plane_config->tiled) |
| 6276 | offset = I915_READ(DSPTILEOFF(plane)); |
| 6277 | else |
| 6278 | offset = I915_READ(DSPLINOFF(plane)); |
| 6279 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 6280 | } else { |
| 6281 | base = I915_READ(DSPADDR(plane)); |
| 6282 | } |
| 6283 | plane_config->base = base; |
| 6284 | |
| 6285 | val = I915_READ(PIPESRC(pipe)); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 6286 | crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1; |
| 6287 | crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6288 | |
| 6289 | val = I915_READ(DSPSTRIDE(pipe)); |
Rafael Barbalho | 026b96e | 2014-07-28 19:56:27 +0100 | [diff] [blame] | 6290 | crtc->base.primary->fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6291 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 6292 | aligned_height = intel_align_height(dev, crtc->base.primary->fb->height, |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6293 | plane_config->tiled); |
| 6294 | |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 6295 | plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] * |
| 6296 | aligned_height); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6297 | |
| 6298 | 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] | 6299 | pipe, plane, crtc->base.primary->fb->width, |
| 6300 | crtc->base.primary->fb->height, |
| 6301 | crtc->base.primary->fb->bits_per_pixel, base, |
| 6302 | crtc->base.primary->fb->pitches[0], |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6303 | plane_config->size); |
| 6304 | |
| 6305 | } |
| 6306 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 6307 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
| 6308 | struct intel_crtc_config *pipe_config) |
| 6309 | { |
| 6310 | struct drm_device *dev = crtc->base.dev; |
| 6311 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6312 | int pipe = pipe_config->cpu_transcoder; |
| 6313 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
| 6314 | intel_clock_t clock; |
| 6315 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2; |
| 6316 | int refclk = 100000; |
| 6317 | |
| 6318 | mutex_lock(&dev_priv->dpio_lock); |
| 6319 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 6320 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 6321 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 6322 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
| 6323 | mutex_unlock(&dev_priv->dpio_lock); |
| 6324 | |
| 6325 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; |
| 6326 | clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff); |
| 6327 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 6328 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 6329 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 6330 | |
| 6331 | chv_clock(refclk, &clock); |
| 6332 | |
| 6333 | /* clock.dot is the fast clock */ |
| 6334 | pipe_config->port_clock = clock.dot / 5; |
| 6335 | } |
| 6336 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6337 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
| 6338 | struct intel_crtc_config *pipe_config) |
| 6339 | { |
| 6340 | struct drm_device *dev = crtc->base.dev; |
| 6341 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6342 | uint32_t tmp; |
| 6343 | |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 6344 | if (!intel_display_power_enabled(dev_priv, |
| 6345 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 6346 | return false; |
| 6347 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 6348 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 6349 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 6350 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6351 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 6352 | if (!(tmp & PIPECONF_ENABLE)) |
| 6353 | return false; |
| 6354 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 6355 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
| 6356 | switch (tmp & PIPECONF_BPC_MASK) { |
| 6357 | case PIPECONF_6BPC: |
| 6358 | pipe_config->pipe_bpp = 18; |
| 6359 | break; |
| 6360 | case PIPECONF_8BPC: |
| 6361 | pipe_config->pipe_bpp = 24; |
| 6362 | break; |
| 6363 | case PIPECONF_10BPC: |
| 6364 | pipe_config->pipe_bpp = 30; |
| 6365 | break; |
| 6366 | default: |
| 6367 | break; |
| 6368 | } |
| 6369 | } |
| 6370 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 6371 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
| 6372 | pipe_config->limited_color_range = true; |
| 6373 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 6374 | if (INTEL_INFO(dev)->gen < 4) |
| 6375 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 6376 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6377 | intel_get_pipe_timings(crtc, pipe_config); |
| 6378 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6379 | i9xx_get_pfit_config(crtc, pipe_config); |
| 6380 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6381 | if (INTEL_INFO(dev)->gen >= 4) { |
| 6382 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
| 6383 | pipe_config->pixel_multiplier = |
| 6384 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 6385 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6386 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6387 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 6388 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 6389 | pipe_config->pixel_multiplier = |
| 6390 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 6391 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 6392 | } else { |
| 6393 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 6394 | * port and will be fixed up in the encoder->get_config |
| 6395 | * function. */ |
| 6396 | pipe_config->pixel_multiplier = 1; |
| 6397 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6398 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
| 6399 | if (!IS_VALLEYVIEW(dev)) { |
| 6400 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 6401 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 6402 | } else { |
| 6403 | /* Mask out read-only status bits. */ |
| 6404 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 6405 | DPLL_PORTC_READY_MASK | |
| 6406 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6407 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6408 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 6409 | if (IS_CHERRYVIEW(dev)) |
| 6410 | chv_crtc_clock_get(crtc, pipe_config); |
| 6411 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6412 | vlv_crtc_clock_get(crtc, pipe_config); |
| 6413 | else |
| 6414 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 6415 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6416 | return true; |
| 6417 | } |
| 6418 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6419 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6420 | { |
| 6421 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6422 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6423 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6424 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6425 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6426 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6427 | bool has_ck505 = false; |
| 6428 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6429 | |
| 6430 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 6431 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6432 | switch (encoder->type) { |
| 6433 | case INTEL_OUTPUT_LVDS: |
| 6434 | has_panel = true; |
| 6435 | has_lvds = true; |
| 6436 | break; |
| 6437 | case INTEL_OUTPUT_EDP: |
| 6438 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 6439 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6440 | has_cpu_edp = true; |
| 6441 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6442 | } |
| 6443 | } |
| 6444 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6445 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6446 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6447 | can_ssc = has_ck505; |
| 6448 | } else { |
| 6449 | has_ck505 = false; |
| 6450 | can_ssc = true; |
| 6451 | } |
| 6452 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 6453 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 6454 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6455 | |
| 6456 | /* Ironlake: try to setup display ref clock before DPLL |
| 6457 | * enabling. This is only under driver's control after |
| 6458 | * PCH B stepping, previous chipset stepping should be |
| 6459 | * ignoring this setting. |
| 6460 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6461 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6462 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6463 | /* As we must carefully and slowly disable/enable each source in turn, |
| 6464 | * compute the final state we want first and check if we need to |
| 6465 | * make any changes at all. |
| 6466 | */ |
| 6467 | final = val; |
| 6468 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6469 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6470 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6471 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6472 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 6473 | |
| 6474 | final &= ~DREF_SSC_SOURCE_MASK; |
| 6475 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 6476 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6477 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6478 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6479 | final |= DREF_SSC_SOURCE_ENABLE; |
| 6480 | |
| 6481 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 6482 | final |= DREF_SSC1_ENABLE; |
| 6483 | |
| 6484 | if (has_cpu_edp) { |
| 6485 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 6486 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 6487 | else |
| 6488 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 6489 | } else |
| 6490 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 6491 | } else { |
| 6492 | final |= DREF_SSC_SOURCE_DISABLE; |
| 6493 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 6494 | } |
| 6495 | |
| 6496 | if (final == val) |
| 6497 | return; |
| 6498 | |
| 6499 | /* Always enable nonspread source */ |
| 6500 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 6501 | |
| 6502 | if (has_ck505) |
| 6503 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 6504 | else |
| 6505 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 6506 | |
| 6507 | if (has_panel) { |
| 6508 | val &= ~DREF_SSC_SOURCE_MASK; |
| 6509 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6510 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6511 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6512 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6513 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6514 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 6515 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6516 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6517 | |
| 6518 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6519 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6520 | POSTING_READ(PCH_DREF_CONTROL); |
| 6521 | udelay(200); |
| 6522 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6523 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6524 | |
| 6525 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6526 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 6527 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6528 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6529 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 6530 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6531 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6532 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6533 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6534 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6535 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6536 | POSTING_READ(PCH_DREF_CONTROL); |
| 6537 | udelay(200); |
| 6538 | } else { |
| 6539 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 6540 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6541 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6542 | |
| 6543 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6544 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6545 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6546 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6547 | POSTING_READ(PCH_DREF_CONTROL); |
| 6548 | udelay(200); |
| 6549 | |
| 6550 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6551 | val &= ~DREF_SSC_SOURCE_MASK; |
| 6552 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6553 | |
| 6554 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6555 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 6556 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6557 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6558 | POSTING_READ(PCH_DREF_CONTROL); |
| 6559 | udelay(200); |
| 6560 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 6561 | |
| 6562 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 6563 | } |
| 6564 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6565 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6566 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6567 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6568 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6569 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 6570 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 6571 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6572 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6573 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 6574 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 6575 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6576 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6577 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 6578 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 6579 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6580 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6581 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 6582 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 6583 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6584 | } |
| 6585 | |
| 6586 | /* WaMPhyProgramming:hsw */ |
| 6587 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 6588 | { |
| 6589 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6590 | |
| 6591 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 6592 | tmp &= ~(0xFF << 24); |
| 6593 | tmp |= (0x12 << 24); |
| 6594 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 6595 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6596 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 6597 | tmp |= (1 << 11); |
| 6598 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 6599 | |
| 6600 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 6601 | tmp |= (1 << 11); |
| 6602 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 6603 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6604 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 6605 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 6606 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 6607 | |
| 6608 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 6609 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 6610 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 6611 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6612 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 6613 | tmp &= ~(7 << 13); |
| 6614 | tmp |= (5 << 13); |
| 6615 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6616 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6617 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 6618 | tmp &= ~(7 << 13); |
| 6619 | tmp |= (5 << 13); |
| 6620 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6621 | |
| 6622 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 6623 | tmp &= ~0xFF; |
| 6624 | tmp |= 0x1C; |
| 6625 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 6626 | |
| 6627 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 6628 | tmp &= ~0xFF; |
| 6629 | tmp |= 0x1C; |
| 6630 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 6631 | |
| 6632 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 6633 | tmp &= ~(0xFF << 16); |
| 6634 | tmp |= (0x1C << 16); |
| 6635 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 6636 | |
| 6637 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 6638 | tmp &= ~(0xFF << 16); |
| 6639 | tmp |= (0x1C << 16); |
| 6640 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 6641 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6642 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 6643 | tmp |= (1 << 27); |
| 6644 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6645 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6646 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 6647 | tmp |= (1 << 27); |
| 6648 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6649 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6650 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 6651 | tmp &= ~(0xF << 28); |
| 6652 | tmp |= (4 << 28); |
| 6653 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6654 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 6655 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 6656 | tmp &= ~(0xF << 28); |
| 6657 | tmp |= (4 << 28); |
| 6658 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6659 | } |
| 6660 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6661 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 6662 | * Programming" based on the parameters passed: |
| 6663 | * - Sequence to enable CLKOUT_DP |
| 6664 | * - Sequence to enable CLKOUT_DP without spread |
| 6665 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 6666 | */ |
| 6667 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 6668 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6669 | { |
| 6670 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6671 | uint32_t reg, tmp; |
| 6672 | |
| 6673 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 6674 | with_spread = true; |
| 6675 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && |
| 6676 | with_fdi, "LP PCH doesn't have FDI\n")) |
| 6677 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6678 | |
| 6679 | mutex_lock(&dev_priv->dpio_lock); |
| 6680 | |
| 6681 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 6682 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 6683 | tmp |= SBI_SSCCTL_PATHALT; |
| 6684 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 6685 | |
| 6686 | udelay(24); |
| 6687 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6688 | if (with_spread) { |
| 6689 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 6690 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 6691 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 6692 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6693 | if (with_fdi) { |
| 6694 | lpt_reset_fdi_mphy(dev_priv); |
| 6695 | lpt_program_fdi_mphy(dev_priv); |
| 6696 | } |
| 6697 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6698 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 6699 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 6700 | SBI_GEN0 : SBI_DBUFF0; |
| 6701 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 6702 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 6703 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 6704 | |
| 6705 | mutex_unlock(&dev_priv->dpio_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6706 | } |
| 6707 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 6708 | /* Sequence to disable CLKOUT_DP */ |
| 6709 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 6710 | { |
| 6711 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6712 | uint32_t reg, tmp; |
| 6713 | |
| 6714 | mutex_lock(&dev_priv->dpio_lock); |
| 6715 | |
| 6716 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 6717 | SBI_GEN0 : SBI_DBUFF0; |
| 6718 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 6719 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 6720 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 6721 | |
| 6722 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 6723 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 6724 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 6725 | tmp |= SBI_SSCCTL_PATHALT; |
| 6726 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 6727 | udelay(32); |
| 6728 | } |
| 6729 | tmp |= SBI_SSCCTL_DISABLE; |
| 6730 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 6731 | } |
| 6732 | |
| 6733 | mutex_unlock(&dev_priv->dpio_lock); |
| 6734 | } |
| 6735 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 6736 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 6737 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 6738 | struct intel_encoder *encoder; |
| 6739 | bool has_vga = false; |
| 6740 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 6741 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 6742 | switch (encoder->type) { |
| 6743 | case INTEL_OUTPUT_ANALOG: |
| 6744 | has_vga = true; |
| 6745 | break; |
| 6746 | } |
| 6747 | } |
| 6748 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 6749 | if (has_vga) |
| 6750 | lpt_enable_clkout_dp(dev, true, true); |
| 6751 | else |
| 6752 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 6753 | } |
| 6754 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 6755 | /* |
| 6756 | * Initialize reference clocks when the driver loads |
| 6757 | */ |
| 6758 | void intel_init_pch_refclk(struct drm_device *dev) |
| 6759 | { |
| 6760 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 6761 | ironlake_init_pch_refclk(dev); |
| 6762 | else if (HAS_PCH_LPT(dev)) |
| 6763 | lpt_init_pch_refclk(dev); |
| 6764 | } |
| 6765 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6766 | static int ironlake_get_refclk(struct drm_crtc *crtc) |
| 6767 | { |
| 6768 | struct drm_device *dev = crtc->dev; |
| 6769 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6770 | struct intel_encoder *encoder; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6771 | int num_connectors = 0; |
| 6772 | bool is_lvds = false; |
| 6773 | |
Daniel Vetter | 6c2b7c12 | 2012-07-05 09:50:24 +0200 | [diff] [blame] | 6774 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6775 | switch (encoder->type) { |
| 6776 | case INTEL_OUTPUT_LVDS: |
| 6777 | is_lvds = true; |
| 6778 | break; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6779 | } |
| 6780 | num_connectors++; |
| 6781 | } |
| 6782 | |
| 6783 | 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] | 6784 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6785 | dev_priv->vbt.lvds_ssc_freq); |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 6786 | return dev_priv->vbt.lvds_ssc_freq; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 6787 | } |
| 6788 | |
| 6789 | return 120000; |
| 6790 | } |
| 6791 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 6792 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6793 | { |
| 6794 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 6795 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6796 | int pipe = intel_crtc->pipe; |
| 6797 | uint32_t val; |
| 6798 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 6799 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6800 | |
Daniel Vetter | 965e0c4 | 2013-03-27 00:44:57 +0100 | [diff] [blame] | 6801 | switch (intel_crtc->config.pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6802 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 6803 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6804 | break; |
| 6805 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 6806 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6807 | break; |
| 6808 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 6809 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6810 | break; |
| 6811 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 6812 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6813 | break; |
| 6814 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 6815 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 6816 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6817 | } |
| 6818 | |
Daniel Vetter | d8b3224 | 2013-04-25 17:54:44 +0200 | [diff] [blame] | 6819 | if (intel_crtc->config.dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6820 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 6821 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 6822 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6823 | val |= PIPECONF_INTERLACED_ILK; |
| 6824 | else |
| 6825 | val |= PIPECONF_PROGRESSIVE; |
| 6826 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6827 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 6828 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 6829 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 6830 | I915_WRITE(PIPECONF(pipe), val); |
| 6831 | POSTING_READ(PIPECONF(pipe)); |
| 6832 | } |
| 6833 | |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6834 | /* |
| 6835 | * Set up the pipe CSC unit. |
| 6836 | * |
| 6837 | * Currently only full range RGB to limited range RGB conversion |
| 6838 | * is supported, but eventually this should handle various |
| 6839 | * RGB<->YCbCr scenarios as well. |
| 6840 | */ |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6841 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6842 | { |
| 6843 | struct drm_device *dev = crtc->dev; |
| 6844 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6845 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 6846 | int pipe = intel_crtc->pipe; |
| 6847 | uint16_t coeff = 0x7800; /* 1.0 */ |
| 6848 | |
| 6849 | /* |
| 6850 | * TODO: Check what kind of values actually come out of the pipe |
| 6851 | * with these coeff/postoff values and adjust to get the best |
| 6852 | * accuracy. Perhaps we even need to take the bpc value into |
| 6853 | * consideration. |
| 6854 | */ |
| 6855 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6856 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6857 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
| 6858 | |
| 6859 | /* |
| 6860 | * GY/GU and RY/RU should be the other way around according |
| 6861 | * to BSpec, but reality doesn't agree. Just set them up in |
| 6862 | * a way that results in the correct picture. |
| 6863 | */ |
| 6864 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); |
| 6865 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); |
| 6866 | |
| 6867 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); |
| 6868 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); |
| 6869 | |
| 6870 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); |
| 6871 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); |
| 6872 | |
| 6873 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); |
| 6874 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); |
| 6875 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); |
| 6876 | |
| 6877 | if (INTEL_INFO(dev)->gen > 6) { |
| 6878 | uint16_t postoff = 0; |
| 6879 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6880 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 32cf0cb | 2013-11-28 22:10:38 +0200 | [diff] [blame] | 6881 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6882 | |
| 6883 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); |
| 6884 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); |
| 6885 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); |
| 6886 | |
| 6887 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); |
| 6888 | } else { |
| 6889 | uint32_t mode = CSC_MODE_YUV_TO_RGB; |
| 6890 | |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 6891 | if (intel_crtc->config.limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 6892 | mode |= CSC_BLACK_SCREEN_OFFSET; |
| 6893 | |
| 6894 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); |
| 6895 | } |
| 6896 | } |
| 6897 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 6898 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6899 | { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 6900 | struct drm_device *dev = crtc->dev; |
| 6901 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6902 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 6903 | enum pipe pipe = intel_crtc->pipe; |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 6904 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6905 | uint32_t val; |
| 6906 | |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 6907 | val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6908 | |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 6909 | if (IS_HASWELL(dev) && intel_crtc->config.dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6910 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 6911 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 6912 | if (intel_crtc->config.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6913 | val |= PIPECONF_INTERLACED_ILK; |
| 6914 | else |
| 6915 | val |= PIPECONF_PROGRESSIVE; |
| 6916 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 6917 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 6918 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 6919 | |
| 6920 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); |
| 6921 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 6922 | |
| 6923 | if (IS_BROADWELL(dev)) { |
| 6924 | val = 0; |
| 6925 | |
| 6926 | switch (intel_crtc->config.pipe_bpp) { |
| 6927 | case 18: |
| 6928 | val |= PIPEMISC_DITHER_6_BPC; |
| 6929 | break; |
| 6930 | case 24: |
| 6931 | val |= PIPEMISC_DITHER_8_BPC; |
| 6932 | break; |
| 6933 | case 30: |
| 6934 | val |= PIPEMISC_DITHER_10_BPC; |
| 6935 | break; |
| 6936 | case 36: |
| 6937 | val |= PIPEMISC_DITHER_12_BPC; |
| 6938 | break; |
| 6939 | default: |
| 6940 | /* Case prevented by pipe_config_set_bpp. */ |
| 6941 | BUG(); |
| 6942 | } |
| 6943 | |
| 6944 | if (intel_crtc->config.dither) |
| 6945 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 6946 | |
| 6947 | I915_WRITE(PIPEMISC(pipe), val); |
| 6948 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 6949 | } |
| 6950 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 6951 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 6952 | intel_clock_t *clock, |
| 6953 | bool *has_reduced_clock, |
| 6954 | intel_clock_t *reduced_clock) |
| 6955 | { |
| 6956 | struct drm_device *dev = crtc->dev; |
| 6957 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6958 | struct intel_encoder *intel_encoder; |
| 6959 | int refclk; |
| 6960 | const intel_limit_t *limit; |
Daniel Vetter | a16af721 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 6961 | bool ret, is_lvds = false; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 6962 | |
| 6963 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 6964 | switch (intel_encoder->type) { |
| 6965 | case INTEL_OUTPUT_LVDS: |
| 6966 | is_lvds = true; |
| 6967 | break; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 6968 | } |
| 6969 | } |
| 6970 | |
| 6971 | refclk = ironlake_get_refclk(crtc); |
| 6972 | |
| 6973 | /* |
| 6974 | * Returns a set of divisors for the desired target clock with the given |
| 6975 | * refclk, or FALSE. The returned values represent the clock equation: |
| 6976 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 6977 | */ |
| 6978 | limit = intel_limit(crtc, refclk); |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 6979 | ret = dev_priv->display.find_dpll(limit, crtc, |
| 6980 | to_intel_crtc(crtc)->config.port_clock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 6981 | refclk, NULL, clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 6982 | if (!ret) |
| 6983 | return false; |
| 6984 | |
| 6985 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 6986 | /* |
| 6987 | * Ensure we match the reduced clock's P to the target clock. |
| 6988 | * If the clocks don't match, we can't switch the display clock |
| 6989 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 6990 | * downclock feature. |
| 6991 | */ |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 6992 | *has_reduced_clock = |
| 6993 | dev_priv->display.find_dpll(limit, crtc, |
| 6994 | dev_priv->lvds_downclock, |
| 6995 | refclk, clock, |
| 6996 | reduced_clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 6997 | } |
| 6998 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 6999 | return true; |
| 7000 | } |
| 7001 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7002 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 7003 | { |
| 7004 | /* |
| 7005 | * Account for spread spectrum to avoid |
| 7006 | * oversubscribing the link. Max center spread |
| 7007 | * is 2.5%; use 5% for safety's sake. |
| 7008 | */ |
| 7009 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 7010 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7011 | } |
| 7012 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7013 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 7014 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7015 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 7016 | } |
| 7017 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7018 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7019 | u32 *fp, |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7020 | intel_clock_t *reduced_clock, u32 *fp2) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7021 | { |
| 7022 | struct drm_crtc *crtc = &intel_crtc->base; |
| 7023 | struct drm_device *dev = crtc->dev; |
| 7024 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7025 | struct intel_encoder *intel_encoder; |
| 7026 | uint32_t dpll; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7027 | int factor, num_connectors = 0; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 7028 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7029 | |
| 7030 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) { |
| 7031 | switch (intel_encoder->type) { |
| 7032 | case INTEL_OUTPUT_LVDS: |
| 7033 | is_lvds = true; |
| 7034 | break; |
| 7035 | case INTEL_OUTPUT_SDVO: |
| 7036 | case INTEL_OUTPUT_HDMI: |
| 7037 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7038 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7039 | } |
| 7040 | |
| 7041 | num_connectors++; |
| 7042 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7043 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7044 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7045 | factor = 21; |
| 7046 | if (is_lvds) { |
| 7047 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 7048 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 7049 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7050 | factor = 25; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 7051 | } else if (intel_crtc->config.sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7052 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7053 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7054 | if (ironlake_needs_fb_cb_tune(&intel_crtc->config.dpll, factor)) |
Daniel Vetter | 7d0ac5b | 2013-04-04 22:20:32 +0200 | [diff] [blame] | 7055 | *fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7056 | |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7057 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
| 7058 | *fp2 |= FP_CB_TUNE; |
| 7059 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 7060 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7061 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7062 | if (is_lvds) |
| 7063 | dpll |= DPLLB_MODE_LVDS; |
| 7064 | else |
| 7065 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7066 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7067 | dpll |= (intel_crtc->config.pixel_multiplier - 1) |
| 7068 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7069 | |
| 7070 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7071 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 9566e9a | 2013-04-19 11:14:36 +0200 | [diff] [blame] | 7072 | if (intel_crtc->config.has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7073 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7074 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7075 | /* compute bitmask from p1 value */ |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7076 | 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] | 7077 | /* also FPA1 */ |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7078 | 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] | 7079 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7080 | switch (intel_crtc->config.dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7081 | case 5: |
| 7082 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7083 | break; |
| 7084 | case 7: |
| 7085 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7086 | break; |
| 7087 | case 10: |
| 7088 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7089 | break; |
| 7090 | case 14: |
| 7091 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7092 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7093 | } |
| 7094 | |
Daniel Vetter | b4c09f3 | 2013-04-30 14:01:42 +0200 | [diff] [blame] | 7095 | 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] | 7096 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7097 | else |
| 7098 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7099 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 7100 | return dpll | DPLL_VCO_ENABLE; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7101 | } |
| 7102 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7103 | static int ironlake_crtc_mode_set(struct drm_crtc *crtc, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7104 | int x, int y, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 7105 | struct drm_framebuffer *fb) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7106 | { |
| 7107 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7108 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7109 | int num_connectors = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7110 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7111 | u32 dpll = 0, fp = 0, fp2 = 0; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 7112 | bool ok, has_reduced_clock = false; |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 7113 | bool is_lvds = false; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 7114 | struct intel_encoder *encoder; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 7115 | struct intel_shared_dpll *pll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7116 | |
| 7117 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 7118 | switch (encoder->type) { |
| 7119 | case INTEL_OUTPUT_LVDS: |
| 7120 | is_lvds = true; |
| 7121 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7122 | } |
| 7123 | |
| 7124 | num_connectors++; |
| 7125 | } |
| 7126 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 7127 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 7128 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 7129 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 7130 | ok = ironlake_compute_clocks(crtc, &clock, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7131 | &has_reduced_clock, &reduced_clock); |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7132 | if (!ok && !intel_crtc->config.clock_set) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7133 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7134 | return -EINVAL; |
| 7135 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7136 | /* Compat-code for transition, will disappear. */ |
| 7137 | if (!intel_crtc->config.clock_set) { |
| 7138 | intel_crtc->config.dpll.n = clock.n; |
| 7139 | intel_crtc->config.dpll.m1 = clock.m1; |
| 7140 | intel_crtc->config.dpll.m2 = clock.m2; |
| 7141 | intel_crtc->config.dpll.p1 = clock.p1; |
| 7142 | intel_crtc->config.dpll.p2 = clock.p2; |
| 7143 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7144 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 7145 | /* 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] | 7146 | if (intel_crtc->config.has_pch_encoder) { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7147 | fp = i9xx_dpll_compute_fp(&intel_crtc->config.dpll); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7148 | if (has_reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7149 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7150 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7151 | dpll = ironlake_compute_dpll(intel_crtc, |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7152 | &fp, &reduced_clock, |
| 7153 | has_reduced_clock ? &fp2 : NULL); |
| 7154 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 7155 | intel_crtc->config.dpll_hw_state.dpll = dpll; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7156 | intel_crtc->config.dpll_hw_state.fp0 = fp; |
| 7157 | if (has_reduced_clock) |
| 7158 | intel_crtc->config.dpll_hw_state.fp1 = fp2; |
| 7159 | else |
| 7160 | intel_crtc->config.dpll_hw_state.fp1 = fp; |
| 7161 | |
Daniel Vetter | b89a1d3 | 2013-06-05 13:34:24 +0200 | [diff] [blame] | 7162 | pll = intel_get_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 7163 | if (pll == NULL) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 7164 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 7165 | pipe_name(intel_crtc->pipe)); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 7166 | return -EINVAL; |
| 7167 | } |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 7168 | } else |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 7169 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7170 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 7171 | if (is_lvds && has_reduced_clock && i915.powersave) |
Daniel Vetter | bcd644e | 2013-06-05 13:34:22 +0200 | [diff] [blame] | 7172 | intel_crtc->lowfreq_avail = true; |
| 7173 | else |
| 7174 | intel_crtc->lowfreq_avail = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 7175 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7176 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7177 | } |
| 7178 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7179 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 7180 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7181 | { |
| 7182 | struct drm_device *dev = crtc->base.dev; |
| 7183 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7184 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7185 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7186 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 7187 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 7188 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 7189 | & ~TU_SIZE_MASK; |
| 7190 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 7191 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 7192 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7193 | } |
| 7194 | |
| 7195 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 7196 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7197 | struct intel_link_m_n *m_n, |
| 7198 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7199 | { |
| 7200 | struct drm_device *dev = crtc->base.dev; |
| 7201 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7202 | enum pipe pipe = crtc->pipe; |
| 7203 | |
| 7204 | if (INTEL_INFO(dev)->gen >= 5) { |
| 7205 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 7206 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 7207 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 7208 | & ~TU_SIZE_MASK; |
| 7209 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 7210 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 7211 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7212 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 7213 | * gen < 8) and if DRRS is supported (to make sure the |
| 7214 | * registers are not unnecessarily read). |
| 7215 | */ |
| 7216 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
| 7217 | crtc->config.has_drrs) { |
| 7218 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 7219 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 7220 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 7221 | & ~TU_SIZE_MASK; |
| 7222 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 7223 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 7224 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7225 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7226 | } else { |
| 7227 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 7228 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 7229 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 7230 | & ~TU_SIZE_MASK; |
| 7231 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 7232 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 7233 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7234 | } |
| 7235 | } |
| 7236 | |
| 7237 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
| 7238 | struct intel_crtc_config *pipe_config) |
| 7239 | { |
| 7240 | if (crtc->config.has_pch_encoder) |
| 7241 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 7242 | else |
| 7243 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7244 | &pipe_config->dp_m_n, |
| 7245 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7246 | } |
| 7247 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7248 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
| 7249 | struct intel_crtc_config *pipe_config) |
| 7250 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7251 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7252 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7253 | } |
| 7254 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7255 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
| 7256 | struct intel_crtc_config *pipe_config) |
| 7257 | { |
| 7258 | struct drm_device *dev = crtc->base.dev; |
| 7259 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7260 | uint32_t tmp; |
| 7261 | |
| 7262 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 7263 | |
| 7264 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 7265 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7266 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 7267 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 7268 | |
| 7269 | /* We currently do not free assignements of panel fitters on |
| 7270 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 7271 | * differentiates them) so just WARN about this case for now. */ |
| 7272 | if (IS_GEN7(dev)) { |
| 7273 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 7274 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 7275 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7276 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7277 | } |
| 7278 | |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7279 | static void ironlake_get_plane_config(struct intel_crtc *crtc, |
| 7280 | struct intel_plane_config *plane_config) |
| 7281 | { |
| 7282 | struct drm_device *dev = crtc->base.dev; |
| 7283 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7284 | u32 val, base, offset; |
| 7285 | int pipe = crtc->pipe, plane = crtc->plane; |
| 7286 | int fourcc, pixel_format; |
| 7287 | int aligned_height; |
| 7288 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 7289 | crtc->base.primary->fb = kzalloc(sizeof(struct intel_framebuffer), GFP_KERNEL); |
| 7290 | if (!crtc->base.primary->fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7291 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7292 | return; |
| 7293 | } |
| 7294 | |
| 7295 | val = I915_READ(DSPCNTR(plane)); |
| 7296 | |
| 7297 | if (INTEL_INFO(dev)->gen >= 4) |
| 7298 | if (val & DISPPLANE_TILED) |
| 7299 | plane_config->tiled = true; |
| 7300 | |
| 7301 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
| 7302 | fourcc = intel_format_to_fourcc(pixel_format); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 7303 | crtc->base.primary->fb->pixel_format = fourcc; |
| 7304 | crtc->base.primary->fb->bits_per_pixel = |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7305 | drm_format_plane_cpp(fourcc, 0) * 8; |
| 7306 | |
| 7307 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 7308 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
| 7309 | offset = I915_READ(DSPOFFSET(plane)); |
| 7310 | } else { |
| 7311 | if (plane_config->tiled) |
| 7312 | offset = I915_READ(DSPTILEOFF(plane)); |
| 7313 | else |
| 7314 | offset = I915_READ(DSPLINOFF(plane)); |
| 7315 | } |
| 7316 | plane_config->base = base; |
| 7317 | |
| 7318 | val = I915_READ(PIPESRC(pipe)); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 7319 | crtc->base.primary->fb->width = ((val >> 16) & 0xfff) + 1; |
| 7320 | crtc->base.primary->fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7321 | |
| 7322 | val = I915_READ(DSPSTRIDE(pipe)); |
Rafael Barbalho | 026b96e | 2014-07-28 19:56:27 +0100 | [diff] [blame] | 7323 | crtc->base.primary->fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7324 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 7325 | aligned_height = intel_align_height(dev, crtc->base.primary->fb->height, |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7326 | plane_config->tiled); |
| 7327 | |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 7328 | plane_config->size = PAGE_ALIGN(crtc->base.primary->fb->pitches[0] * |
| 7329 | aligned_height); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7330 | |
| 7331 | 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] | 7332 | pipe, plane, crtc->base.primary->fb->width, |
| 7333 | crtc->base.primary->fb->height, |
| 7334 | crtc->base.primary->fb->bits_per_pixel, base, |
| 7335 | crtc->base.primary->fb->pitches[0], |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7336 | plane_config->size); |
| 7337 | } |
| 7338 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7339 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
| 7340 | struct intel_crtc_config *pipe_config) |
| 7341 | { |
| 7342 | struct drm_device *dev = crtc->base.dev; |
| 7343 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7344 | uint32_t tmp; |
| 7345 | |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 7346 | if (!intel_display_power_enabled(dev_priv, |
| 7347 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 7348 | return false; |
| 7349 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7350 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7351 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7352 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7353 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7354 | if (!(tmp & PIPECONF_ENABLE)) |
| 7355 | return false; |
| 7356 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7357 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7358 | case PIPECONF_6BPC: |
| 7359 | pipe_config->pipe_bpp = 18; |
| 7360 | break; |
| 7361 | case PIPECONF_8BPC: |
| 7362 | pipe_config->pipe_bpp = 24; |
| 7363 | break; |
| 7364 | case PIPECONF_10BPC: |
| 7365 | pipe_config->pipe_bpp = 30; |
| 7366 | break; |
| 7367 | case PIPECONF_12BPC: |
| 7368 | pipe_config->pipe_bpp = 36; |
| 7369 | break; |
| 7370 | default: |
| 7371 | break; |
| 7372 | } |
| 7373 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 7374 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 7375 | pipe_config->limited_color_range = true; |
| 7376 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 7377 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7378 | struct intel_shared_dpll *pll; |
| 7379 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 7380 | pipe_config->has_pch_encoder = true; |
| 7381 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 7382 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 7383 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 7384 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7385 | |
| 7386 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7387 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7388 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 7389 | pipe_config->shared_dpll = |
| 7390 | (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7391 | } else { |
| 7392 | tmp = I915_READ(PCH_DPLL_SEL); |
| 7393 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
| 7394 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; |
| 7395 | else |
| 7396 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; |
| 7397 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7398 | |
| 7399 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 7400 | |
| 7401 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 7402 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 7403 | |
| 7404 | tmp = pipe_config->dpll_hw_state.dpll; |
| 7405 | pipe_config->pixel_multiplier = |
| 7406 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 7407 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 7408 | |
| 7409 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7410 | } else { |
| 7411 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 7412 | } |
| 7413 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7414 | intel_get_pipe_timings(crtc, pipe_config); |
| 7415 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7416 | ironlake_get_pfit_config(crtc, pipe_config); |
| 7417 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7418 | return true; |
| 7419 | } |
| 7420 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7421 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 7422 | { |
| 7423 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7424 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7425 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 7426 | for_each_intel_crtc(dev, crtc) |
Paulo Zanoni | 798183c | 2013-12-06 20:29:01 -0200 | [diff] [blame] | 7427 | WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7428 | pipe_name(crtc->pipe)); |
| 7429 | |
| 7430 | WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
Daniel Vetter | 8cc3e16 | 2014-06-25 22:01:46 +0300 | [diff] [blame] | 7431 | WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
| 7432 | WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 7433 | WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7434 | WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 7435 | WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
| 7436 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 7437 | if (IS_HASWELL(dev)) |
| 7438 | WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
| 7439 | "CPU PWM2 enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7440 | WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
| 7441 | "PCH PWM1 enabled\n"); |
| 7442 | WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
| 7443 | "Utility pin enabled\n"); |
| 7444 | WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
| 7445 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 7446 | /* |
| 7447 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 7448 | * interrupts remain enabled. We used to check for that, but since it's |
| 7449 | * gen-specific and since we only disable LCPLL after we fully disable |
| 7450 | * the interrupts, the check below should be enough. |
| 7451 | */ |
Jesse Barnes | 9df7575f | 2014-06-20 09:29:20 -0700 | [diff] [blame] | 7452 | WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7453 | } |
| 7454 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7455 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 7456 | { |
| 7457 | struct drm_device *dev = dev_priv->dev; |
| 7458 | |
| 7459 | if (IS_HASWELL(dev)) |
| 7460 | return I915_READ(D_COMP_HSW); |
| 7461 | else |
| 7462 | return I915_READ(D_COMP_BDW); |
| 7463 | } |
| 7464 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7465 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 7466 | { |
| 7467 | struct drm_device *dev = dev_priv->dev; |
| 7468 | |
| 7469 | if (IS_HASWELL(dev)) { |
| 7470 | mutex_lock(&dev_priv->rps.hw_lock); |
| 7471 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 7472 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 7473 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7474 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 7475 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7476 | I915_WRITE(D_COMP_BDW, val); |
| 7477 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7478 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7479 | } |
| 7480 | |
| 7481 | /* |
| 7482 | * This function implements pieces of two sequences from BSpec: |
| 7483 | * - Sequence for display software to disable LCPLL |
| 7484 | * - Sequence for display software to allow package C8+ |
| 7485 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 7486 | * register. Callers should take care of disabling all the display engine |
| 7487 | * functions, doing the mode unset, fixing interrupts, etc. |
| 7488 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 7489 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 7490 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7491 | { |
| 7492 | uint32_t val; |
| 7493 | |
| 7494 | assert_can_disable_lcpll(dev_priv); |
| 7495 | |
| 7496 | val = I915_READ(LCPLL_CTL); |
| 7497 | |
| 7498 | if (switch_to_fclk) { |
| 7499 | val |= LCPLL_CD_SOURCE_FCLK; |
| 7500 | I915_WRITE(LCPLL_CTL, val); |
| 7501 | |
| 7502 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 7503 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 7504 | DRM_ERROR("Switching to FCLK failed\n"); |
| 7505 | |
| 7506 | val = I915_READ(LCPLL_CTL); |
| 7507 | } |
| 7508 | |
| 7509 | val |= LCPLL_PLL_DISABLE; |
| 7510 | I915_WRITE(LCPLL_CTL, val); |
| 7511 | POSTING_READ(LCPLL_CTL); |
| 7512 | |
| 7513 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 7514 | DRM_ERROR("LCPLL still locked\n"); |
| 7515 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7516 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7517 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7518 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7519 | ndelay(100); |
| 7520 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7521 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 7522 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7523 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 7524 | |
| 7525 | if (allow_power_down) { |
| 7526 | val = I915_READ(LCPLL_CTL); |
| 7527 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 7528 | I915_WRITE(LCPLL_CTL, val); |
| 7529 | POSTING_READ(LCPLL_CTL); |
| 7530 | } |
| 7531 | } |
| 7532 | |
| 7533 | /* |
| 7534 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 7535 | * source. |
| 7536 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 7537 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7538 | { |
| 7539 | uint32_t val; |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 7540 | unsigned long irqflags; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7541 | |
| 7542 | val = I915_READ(LCPLL_CTL); |
| 7543 | |
| 7544 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 7545 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 7546 | return; |
| 7547 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 7548 | /* |
| 7549 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 7550 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. |
| 7551 | * |
| 7552 | * The other problem is that hsw_restore_lcpll() is called as part of |
| 7553 | * the runtime PM resume sequence, so we can't just call |
| 7554 | * gen6_gt_force_wake_get() because that function calls |
| 7555 | * intel_runtime_pm_get(), and we can't change the runtime PM refcount |
| 7556 | * while we are on the resume sequence. So to solve this problem we have |
| 7557 | * to call special forcewake code that doesn't touch runtime PM and |
| 7558 | * doesn't enable the forcewake delayed work. |
| 7559 | */ |
| 7560 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 7561 | if (dev_priv->uncore.forcewake_count++ == 0) |
| 7562 | dev_priv->uncore.funcs.force_wake_get(dev_priv, FORCEWAKE_ALL); |
| 7563 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 7564 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7565 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 7566 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 7567 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 7568 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7569 | } |
| 7570 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 7571 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7572 | val |= D_COMP_COMP_FORCE; |
| 7573 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 7574 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7575 | |
| 7576 | val = I915_READ(LCPLL_CTL); |
| 7577 | val &= ~LCPLL_PLL_DISABLE; |
| 7578 | I915_WRITE(LCPLL_CTL, val); |
| 7579 | |
| 7580 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 7581 | DRM_ERROR("LCPLL not locked yet\n"); |
| 7582 | |
| 7583 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 7584 | val = I915_READ(LCPLL_CTL); |
| 7585 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 7586 | I915_WRITE(LCPLL_CTL, val); |
| 7587 | |
| 7588 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 7589 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 7590 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 7591 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 7592 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 7593 | /* See the big comment above. */ |
| 7594 | spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); |
| 7595 | if (--dev_priv->uncore.forcewake_count == 0) |
| 7596 | dev_priv->uncore.funcs.force_wake_put(dev_priv, FORCEWAKE_ALL); |
| 7597 | spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 7598 | } |
| 7599 | |
Paulo Zanoni | 765dab6 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 7600 | /* |
| 7601 | * Package states C8 and deeper are really deep PC states that can only be |
| 7602 | * reached when all the devices on the system allow it, so even if the graphics |
| 7603 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 7604 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 7605 | * |
| 7606 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 7607 | * well is disabled and most interrupts are disabled, and these are also |
| 7608 | * requirements for runtime PM. When these conditions are met, we manually do |
| 7609 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 7610 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 7611 | * hang the machine. |
| 7612 | * |
| 7613 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 7614 | * the state of some registers, so when we come back from PC8+ we need to |
| 7615 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 7616 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 7617 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 7618 | * because of the runtime PM support). |
| 7619 | * |
| 7620 | * For more, read "Display Sequences for Package C8" on the hardware |
| 7621 | * documentation. |
| 7622 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 7623 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7624 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7625 | struct drm_device *dev = dev_priv->dev; |
| 7626 | uint32_t val; |
| 7627 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7628 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 7629 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7630 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 7631 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 7632 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 7633 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 7634 | } |
| 7635 | |
| 7636 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7637 | hsw_disable_lcpll(dev_priv, true, true); |
| 7638 | } |
| 7639 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 7640 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7641 | { |
| 7642 | struct drm_device *dev = dev_priv->dev; |
| 7643 | uint32_t val; |
| 7644 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7645 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 7646 | |
| 7647 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7648 | lpt_init_pch_refclk(dev); |
| 7649 | |
| 7650 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 7651 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 7652 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 7653 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 7654 | } |
| 7655 | |
| 7656 | intel_prepare_ddi(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 7657 | } |
| 7658 | |
Paulo Zanoni | 9a952a0 | 2014-03-07 20:12:34 -0300 | [diff] [blame] | 7659 | static void snb_modeset_global_resources(struct drm_device *dev) |
| 7660 | { |
| 7661 | modeset_update_crtc_power_domains(dev); |
| 7662 | } |
| 7663 | |
Imre Deak | 4f07412 | 2013-10-16 17:25:51 +0300 | [diff] [blame] | 7664 | static void haswell_modeset_global_resources(struct drm_device *dev) |
| 7665 | { |
Paulo Zanoni | da72356 | 2013-12-19 11:54:51 -0200 | [diff] [blame] | 7666 | modeset_update_crtc_power_domains(dev); |
Daniel Vetter | d6dd9eb | 2013-01-29 16:35:20 -0200 | [diff] [blame] | 7667 | } |
| 7668 | |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 7669 | static int haswell_crtc_mode_set(struct drm_crtc *crtc, |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 7670 | int x, int y, |
| 7671 | struct drm_framebuffer *fb) |
| 7672 | { |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 7673 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 7674 | |
Paulo Zanoni | 566b734 | 2013-11-25 15:27:08 -0200 | [diff] [blame] | 7675 | if (!intel_ddi_pll_select(intel_crtc)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 7676 | return -EINVAL; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 7677 | |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 7678 | intel_crtc->lowfreq_avail = false; |
| 7679 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7680 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7681 | } |
| 7682 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 7683 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 7684 | enum port port, |
| 7685 | struct intel_crtc_config *pipe_config) |
| 7686 | { |
| 7687 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 7688 | |
| 7689 | switch (pipe_config->ddi_pll_sel) { |
| 7690 | case PORT_CLK_SEL_WRPLL1: |
| 7691 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; |
| 7692 | break; |
| 7693 | case PORT_CLK_SEL_WRPLL2: |
| 7694 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; |
| 7695 | break; |
| 7696 | } |
| 7697 | } |
| 7698 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 7699 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
| 7700 | struct intel_crtc_config *pipe_config) |
| 7701 | { |
| 7702 | struct drm_device *dev = crtc->base.dev; |
| 7703 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 7704 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 7705 | enum port port; |
| 7706 | uint32_t tmp; |
| 7707 | |
| 7708 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 7709 | |
| 7710 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 7711 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 7712 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 7713 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 7714 | if (pipe_config->shared_dpll >= 0) { |
| 7715 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 7716 | |
| 7717 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 7718 | &pipe_config->dpll_hw_state)); |
| 7719 | } |
| 7720 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 7721 | /* |
| 7722 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 7723 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 7724 | * the PCH transcoder is on. |
| 7725 | */ |
| 7726 | if ((port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
| 7727 | pipe_config->has_pch_encoder = true; |
| 7728 | |
| 7729 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 7730 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 7731 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 7732 | |
| 7733 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 7734 | } |
| 7735 | } |
| 7736 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7737 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
| 7738 | struct intel_crtc_config *pipe_config) |
| 7739 | { |
| 7740 | struct drm_device *dev = crtc->base.dev; |
| 7741 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7742 | enum intel_display_power_domain pfit_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7743 | uint32_t tmp; |
| 7744 | |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7745 | if (!intel_display_power_enabled(dev_priv, |
| 7746 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 7747 | return false; |
| 7748 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7749 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7750 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
| 7751 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7752 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 7753 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 7754 | enum pipe trans_edp_pipe; |
| 7755 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 7756 | default: |
| 7757 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 7758 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 7759 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 7760 | trans_edp_pipe = PIPE_A; |
| 7761 | break; |
| 7762 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 7763 | trans_edp_pipe = PIPE_B; |
| 7764 | break; |
| 7765 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 7766 | trans_edp_pipe = PIPE_C; |
| 7767 | break; |
| 7768 | } |
| 7769 | |
| 7770 | if (trans_edp_pipe == crtc->pipe) |
| 7771 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 7772 | } |
| 7773 | |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7774 | if (!intel_display_power_enabled(dev_priv, |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7775 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
Paulo Zanoni | 2bfce95 | 2013-04-18 16:35:40 -0300 | [diff] [blame] | 7776 | return false; |
| 7777 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7778 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7779 | if (!(tmp & PIPECONF_ENABLE)) |
| 7780 | return false; |
| 7781 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 7782 | haswell_get_ddi_port_state(crtc, pipe_config); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 7783 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7784 | intel_get_pipe_timings(crtc, pipe_config); |
| 7785 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7786 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
Imre Deak | da7e29b | 2014-02-18 00:02:02 +0200 | [diff] [blame] | 7787 | if (intel_display_power_enabled(dev_priv, pfit_domain)) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7788 | ironlake_get_pfit_config(crtc, pipe_config); |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 7789 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 7790 | if (IS_HASWELL(dev)) |
| 7791 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 7792 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 7793 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7794 | pipe_config->pixel_multiplier = 1; |
| 7795 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7796 | return true; |
| 7797 | } |
| 7798 | |
Jani Nikula | 1a91510 | 2013-10-16 12:34:48 +0300 | [diff] [blame] | 7799 | static struct { |
| 7800 | int clock; |
| 7801 | u32 config; |
| 7802 | } hdmi_audio_clock[] = { |
| 7803 | { DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 }, |
| 7804 | { 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */ |
| 7805 | { 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 }, |
| 7806 | { 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 }, |
| 7807 | { 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 }, |
| 7808 | { 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 }, |
| 7809 | { DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 }, |
| 7810 | { 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 }, |
| 7811 | { DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 }, |
| 7812 | { 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 }, |
| 7813 | }; |
| 7814 | |
| 7815 | /* get AUD_CONFIG_PIXEL_CLOCK_HDMI_* value for mode */ |
| 7816 | static u32 audio_config_hdmi_pixel_clock(struct drm_display_mode *mode) |
| 7817 | { |
| 7818 | int i; |
| 7819 | |
| 7820 | for (i = 0; i < ARRAY_SIZE(hdmi_audio_clock); i++) { |
| 7821 | if (mode->clock == hdmi_audio_clock[i].clock) |
| 7822 | break; |
| 7823 | } |
| 7824 | |
| 7825 | if (i == ARRAY_SIZE(hdmi_audio_clock)) { |
| 7826 | DRM_DEBUG_KMS("HDMI audio pixel clock setting for %d not found, falling back to defaults\n", mode->clock); |
| 7827 | i = 1; |
| 7828 | } |
| 7829 | |
| 7830 | DRM_DEBUG_KMS("Configuring HDMI audio for pixel clock %d (0x%08x)\n", |
| 7831 | hdmi_audio_clock[i].clock, |
| 7832 | hdmi_audio_clock[i].config); |
| 7833 | |
| 7834 | return hdmi_audio_clock[i].config; |
| 7835 | } |
| 7836 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 7837 | static bool intel_eld_uptodate(struct drm_connector *connector, |
| 7838 | int reg_eldv, uint32_t bits_eldv, |
| 7839 | int reg_elda, uint32_t bits_elda, |
| 7840 | int reg_edid) |
| 7841 | { |
| 7842 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 7843 | uint8_t *eld = connector->eld; |
| 7844 | uint32_t i; |
| 7845 | |
| 7846 | i = I915_READ(reg_eldv); |
| 7847 | i &= bits_eldv; |
| 7848 | |
| 7849 | if (!eld[0]) |
| 7850 | return !i; |
| 7851 | |
| 7852 | if (!i) |
| 7853 | return false; |
| 7854 | |
| 7855 | i = I915_READ(reg_elda); |
| 7856 | i &= ~bits_elda; |
| 7857 | I915_WRITE(reg_elda, i); |
| 7858 | |
| 7859 | for (i = 0; i < eld[2]; i++) |
| 7860 | if (I915_READ(reg_edid) != *((uint32_t *)eld + i)) |
| 7861 | return false; |
| 7862 | |
| 7863 | return true; |
| 7864 | } |
| 7865 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 7866 | static void g4x_write_eld(struct drm_connector *connector, |
Jani Nikula | 3442705 | 2013-10-16 12:34:47 +0300 | [diff] [blame] | 7867 | struct drm_crtc *crtc, |
| 7868 | struct drm_display_mode *mode) |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 7869 | { |
| 7870 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 7871 | uint8_t *eld = connector->eld; |
| 7872 | uint32_t eldv; |
| 7873 | uint32_t len; |
| 7874 | uint32_t i; |
| 7875 | |
| 7876 | i = I915_READ(G4X_AUD_VID_DID); |
| 7877 | |
| 7878 | if (i == INTEL_AUDIO_DEVBLC || i == INTEL_AUDIO_DEVCL) |
| 7879 | eldv = G4X_ELDV_DEVCL_DEVBLC; |
| 7880 | else |
| 7881 | eldv = G4X_ELDV_DEVCTG; |
| 7882 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 7883 | if (intel_eld_uptodate(connector, |
| 7884 | G4X_AUD_CNTL_ST, eldv, |
| 7885 | G4X_AUD_CNTL_ST, G4X_ELD_ADDR, |
| 7886 | G4X_HDMIW_HDMIEDID)) |
| 7887 | return; |
| 7888 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 7889 | i = I915_READ(G4X_AUD_CNTL_ST); |
| 7890 | i &= ~(eldv | G4X_ELD_ADDR); |
| 7891 | len = (i >> 9) & 0x1f; /* ELD buffer size */ |
| 7892 | I915_WRITE(G4X_AUD_CNTL_ST, i); |
| 7893 | |
| 7894 | if (!eld[0]) |
| 7895 | return; |
| 7896 | |
| 7897 | len = min_t(uint8_t, eld[2], len); |
| 7898 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 7899 | for (i = 0; i < len; i++) |
| 7900 | I915_WRITE(G4X_HDMIW_HDMIEDID, *((uint32_t *)eld + i)); |
| 7901 | |
| 7902 | i = I915_READ(G4X_AUD_CNTL_ST); |
| 7903 | i |= eldv; |
| 7904 | I915_WRITE(G4X_AUD_CNTL_ST, i); |
| 7905 | } |
| 7906 | |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7907 | static void haswell_write_eld(struct drm_connector *connector, |
Jani Nikula | 3442705 | 2013-10-16 12:34:47 +0300 | [diff] [blame] | 7908 | struct drm_crtc *crtc, |
| 7909 | struct drm_display_mode *mode) |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7910 | { |
| 7911 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 7912 | uint8_t *eld = connector->eld; |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7913 | uint32_t eldv; |
| 7914 | uint32_t i; |
| 7915 | int len; |
| 7916 | int pipe = to_intel_crtc(crtc)->pipe; |
| 7917 | int tmp; |
| 7918 | |
| 7919 | int hdmiw_hdmiedid = HSW_AUD_EDID_DATA(pipe); |
| 7920 | int aud_cntl_st = HSW_AUD_DIP_ELD_CTRL(pipe); |
| 7921 | int aud_config = HSW_AUD_CFG(pipe); |
| 7922 | int aud_cntrl_st2 = HSW_AUD_PIN_ELD_CP_VLD; |
| 7923 | |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7924 | /* Audio output enable */ |
| 7925 | DRM_DEBUG_DRIVER("HDMI audio: enable codec\n"); |
| 7926 | tmp = I915_READ(aud_cntrl_st2); |
| 7927 | tmp |= (AUDIO_OUTPUT_ENABLE_A << (pipe * 4)); |
| 7928 | I915_WRITE(aud_cntrl_st2, tmp); |
Daniel Vetter | c790579 | 2014-04-16 16:56:09 +0200 | [diff] [blame] | 7929 | POSTING_READ(aud_cntrl_st2); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7930 | |
Daniel Vetter | c790579 | 2014-04-16 16:56:09 +0200 | [diff] [blame] | 7931 | assert_pipe_disabled(dev_priv, to_intel_crtc(crtc)->pipe); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7932 | |
| 7933 | /* Set ELD valid state */ |
| 7934 | tmp = I915_READ(aud_cntrl_st2); |
Takashi Iwai | 7e7cb34 | 2013-09-10 07:30:36 +0200 | [diff] [blame] | 7935 | 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] | 7936 | tmp |= (AUDIO_ELD_VALID_A << (pipe * 4)); |
| 7937 | I915_WRITE(aud_cntrl_st2, tmp); |
| 7938 | tmp = I915_READ(aud_cntrl_st2); |
Takashi Iwai | 7e7cb34 | 2013-09-10 07:30:36 +0200 | [diff] [blame] | 7939 | DRM_DEBUG_DRIVER("HDMI audio: eld vld status=0x%08x\n", tmp); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7940 | |
| 7941 | /* Enable HDMI mode */ |
| 7942 | tmp = I915_READ(aud_config); |
Takashi Iwai | 7e7cb34 | 2013-09-10 07:30:36 +0200 | [diff] [blame] | 7943 | DRM_DEBUG_DRIVER("HDMI audio: audio conf: 0x%08x\n", tmp); |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7944 | /* clear N_programing_enable and N_value_index */ |
| 7945 | tmp &= ~(AUD_CONFIG_N_VALUE_INDEX | AUD_CONFIG_N_PROG_ENABLE); |
| 7946 | I915_WRITE(aud_config, tmp); |
| 7947 | |
| 7948 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
| 7949 | |
| 7950 | eldv = AUDIO_ELD_VALID_A << (pipe * 4); |
| 7951 | |
| 7952 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
| 7953 | DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n"); |
| 7954 | eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */ |
| 7955 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
Jani Nikula | 1a91510 | 2013-10-16 12:34:48 +0300 | [diff] [blame] | 7956 | } else { |
| 7957 | I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode)); |
| 7958 | } |
Wang Xingchao | 83358c85 | 2012-08-16 22:43:37 +0800 | [diff] [blame] | 7959 | |
| 7960 | if (intel_eld_uptodate(connector, |
| 7961 | aud_cntrl_st2, eldv, |
| 7962 | aud_cntl_st, IBX_ELD_ADDRESS, |
| 7963 | hdmiw_hdmiedid)) |
| 7964 | return; |
| 7965 | |
| 7966 | i = I915_READ(aud_cntrl_st2); |
| 7967 | i &= ~eldv; |
| 7968 | I915_WRITE(aud_cntrl_st2, i); |
| 7969 | |
| 7970 | if (!eld[0]) |
| 7971 | return; |
| 7972 | |
| 7973 | i = I915_READ(aud_cntl_st); |
| 7974 | i &= ~IBX_ELD_ADDRESS; |
| 7975 | I915_WRITE(aud_cntl_st, i); |
| 7976 | i = (i >> 29) & DIP_PORT_SEL_MASK; /* DIP_Port_Select, 0x1 = PortB */ |
| 7977 | DRM_DEBUG_DRIVER("port num:%d\n", i); |
| 7978 | |
| 7979 | len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
| 7980 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 7981 | for (i = 0; i < len; i++) |
| 7982 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 7983 | |
| 7984 | i = I915_READ(aud_cntrl_st2); |
| 7985 | i |= eldv; |
| 7986 | I915_WRITE(aud_cntrl_st2, i); |
| 7987 | |
| 7988 | } |
| 7989 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 7990 | static void ironlake_write_eld(struct drm_connector *connector, |
Jani Nikula | 3442705 | 2013-10-16 12:34:47 +0300 | [diff] [blame] | 7991 | struct drm_crtc *crtc, |
| 7992 | struct drm_display_mode *mode) |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 7993 | { |
| 7994 | struct drm_i915_private *dev_priv = connector->dev->dev_private; |
| 7995 | uint8_t *eld = connector->eld; |
| 7996 | uint32_t eldv; |
| 7997 | uint32_t i; |
| 7998 | int len; |
| 7999 | int hdmiw_hdmiedid; |
Wu Fengguang | b6daa02 | 2012-01-06 14:41:31 -0600 | [diff] [blame] | 8000 | int aud_config; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8001 | int aud_cntl_st; |
| 8002 | int aud_cntrl_st2; |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 8003 | int pipe = to_intel_crtc(crtc)->pipe; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8004 | |
Wu Fengguang | b3f33cb | 2011-12-09 20:42:17 +0800 | [diff] [blame] | 8005 | if (HAS_PCH_IBX(connector->dev)) { |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 8006 | hdmiw_hdmiedid = IBX_HDMIW_HDMIEDID(pipe); |
| 8007 | aud_config = IBX_AUD_CFG(pipe); |
| 8008 | aud_cntl_st = IBX_AUD_CNTL_ST(pipe); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8009 | aud_cntrl_st2 = IBX_AUD_CNTL_ST2; |
Mengdong Lin | 9ca2fe7 | 2013-11-01 00:17:03 -0400 | [diff] [blame] | 8010 | } else if (IS_VALLEYVIEW(connector->dev)) { |
| 8011 | hdmiw_hdmiedid = VLV_HDMIW_HDMIEDID(pipe); |
| 8012 | aud_config = VLV_AUD_CFG(pipe); |
| 8013 | aud_cntl_st = VLV_AUD_CNTL_ST(pipe); |
| 8014 | aud_cntrl_st2 = VLV_AUD_CNTL_ST2; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8015 | } else { |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 8016 | hdmiw_hdmiedid = CPT_HDMIW_HDMIEDID(pipe); |
| 8017 | aud_config = CPT_AUD_CFG(pipe); |
| 8018 | aud_cntl_st = CPT_AUD_CNTL_ST(pipe); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8019 | aud_cntrl_st2 = CPT_AUD_CNTRL_ST2; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8020 | } |
| 8021 | |
Wang Xingchao | 9b138a8 | 2012-08-09 16:52:18 +0800 | [diff] [blame] | 8022 | DRM_DEBUG_DRIVER("ELD on pipe %c\n", pipe_name(pipe)); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8023 | |
Mengdong Lin | 9ca2fe7 | 2013-11-01 00:17:03 -0400 | [diff] [blame] | 8024 | if (IS_VALLEYVIEW(connector->dev)) { |
| 8025 | struct intel_encoder *intel_encoder; |
| 8026 | struct intel_digital_port *intel_dig_port; |
| 8027 | |
| 8028 | intel_encoder = intel_attached_encoder(connector); |
| 8029 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
| 8030 | i = intel_dig_port->port; |
| 8031 | } else { |
| 8032 | i = I915_READ(aud_cntl_st); |
| 8033 | i = (i >> 29) & DIP_PORT_SEL_MASK; |
| 8034 | /* DIP_Port_Select, 0x1 = PortB */ |
| 8035 | } |
| 8036 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8037 | if (!i) { |
| 8038 | DRM_DEBUG_DRIVER("Audio directed to unknown port\n"); |
| 8039 | /* operate blindly on all ports */ |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8040 | eldv = IBX_ELD_VALIDB; |
| 8041 | eldv |= IBX_ELD_VALIDB << 4; |
| 8042 | eldv |= IBX_ELD_VALIDB << 8; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8043 | } else { |
Ville Syrjälä | 2582a85 | 2013-04-17 17:48:47 +0300 | [diff] [blame] | 8044 | DRM_DEBUG_DRIVER("ELD on port %c\n", port_name(i)); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8045 | eldv = IBX_ELD_VALIDB << ((i - 1) * 4); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8046 | } |
| 8047 | |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 8048 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { |
| 8049 | DRM_DEBUG_DRIVER("ELD: DisplayPort detected\n"); |
| 8050 | eld[5] |= (1 << 2); /* Conn_Type, 0x1 = DisplayPort */ |
Wu Fengguang | b6daa02 | 2012-01-06 14:41:31 -0600 | [diff] [blame] | 8051 | I915_WRITE(aud_config, AUD_CONFIG_N_VALUE_INDEX); /* 0x1 = DP */ |
Jani Nikula | 1a91510 | 2013-10-16 12:34:48 +0300 | [diff] [blame] | 8052 | } else { |
| 8053 | I915_WRITE(aud_config, audio_config_hdmi_pixel_clock(mode)); |
| 8054 | } |
Wu Fengguang | 3a9627f | 2011-12-09 20:42:19 +0800 | [diff] [blame] | 8055 | |
| 8056 | if (intel_eld_uptodate(connector, |
| 8057 | aud_cntrl_st2, eldv, |
| 8058 | aud_cntl_st, IBX_ELD_ADDRESS, |
| 8059 | hdmiw_hdmiedid)) |
| 8060 | return; |
| 8061 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8062 | i = I915_READ(aud_cntrl_st2); |
| 8063 | i &= ~eldv; |
| 8064 | I915_WRITE(aud_cntrl_st2, i); |
| 8065 | |
| 8066 | if (!eld[0]) |
| 8067 | return; |
| 8068 | |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8069 | i = I915_READ(aud_cntl_st); |
Wu Fengguang | 1202b4c6 | 2011-12-09 20:42:18 +0800 | [diff] [blame] | 8070 | i &= ~IBX_ELD_ADDRESS; |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8071 | I915_WRITE(aud_cntl_st, i); |
| 8072 | |
| 8073 | len = min_t(uint8_t, eld[2], 21); /* 84 bytes of hw ELD buffer */ |
| 8074 | DRM_DEBUG_DRIVER("ELD size %d\n", len); |
| 8075 | for (i = 0; i < len; i++) |
| 8076 | I915_WRITE(hdmiw_hdmiedid, *((uint32_t *)eld + i)); |
| 8077 | |
| 8078 | i = I915_READ(aud_cntrl_st2); |
| 8079 | i |= eldv; |
| 8080 | I915_WRITE(aud_cntrl_st2, i); |
| 8081 | } |
| 8082 | |
| 8083 | void intel_write_eld(struct drm_encoder *encoder, |
| 8084 | struct drm_display_mode *mode) |
| 8085 | { |
| 8086 | struct drm_crtc *crtc = encoder->crtc; |
| 8087 | struct drm_connector *connector; |
| 8088 | struct drm_device *dev = encoder->dev; |
| 8089 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8090 | |
| 8091 | connector = drm_select_eld(encoder, mode); |
| 8092 | if (!connector) |
| 8093 | return; |
| 8094 | |
| 8095 | DRM_DEBUG_DRIVER("ELD on [CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
| 8096 | connector->base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 8097 | connector->name, |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8098 | connector->encoder->base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 8099 | connector->encoder->name); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8100 | |
| 8101 | connector->eld[6] = drm_av_sync_delay(connector, mode) / 2; |
| 8102 | |
| 8103 | if (dev_priv->display.write_eld) |
Jani Nikula | 3442705 | 2013-10-16 12:34:47 +0300 | [diff] [blame] | 8104 | dev_priv->display.write_eld(connector, crtc, mode); |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 8105 | } |
| 8106 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8107 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8108 | { |
| 8109 | struct drm_device *dev = crtc->dev; |
| 8110 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8111 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8112 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8113 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8114 | if (base) { |
| 8115 | unsigned int width = intel_crtc->cursor_width; |
| 8116 | unsigned int height = intel_crtc->cursor_height; |
| 8117 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 8118 | |
| 8119 | switch (stride) { |
| 8120 | default: |
| 8121 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 8122 | width, stride); |
| 8123 | stride = 256; |
| 8124 | /* fallthrough */ |
| 8125 | case 256: |
| 8126 | case 512: |
| 8127 | case 1024: |
| 8128 | case 2048: |
| 8129 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8130 | } |
| 8131 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8132 | cntl |= CURSOR_ENABLE | |
| 8133 | CURSOR_GAMMA_ENABLE | |
| 8134 | CURSOR_FORMAT_ARGB | |
| 8135 | CURSOR_STRIDE(stride); |
| 8136 | |
| 8137 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8138 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8139 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8140 | if (intel_crtc->cursor_cntl != 0 && |
| 8141 | (intel_crtc->cursor_base != base || |
| 8142 | intel_crtc->cursor_size != size || |
| 8143 | intel_crtc->cursor_cntl != cntl)) { |
| 8144 | /* On these chipsets we can only modify the base/size/stride |
| 8145 | * whilst the cursor is disabled. |
| 8146 | */ |
| 8147 | I915_WRITE(_CURACNTR, 0); |
| 8148 | POSTING_READ(_CURACNTR); |
| 8149 | intel_crtc->cursor_cntl = 0; |
| 8150 | } |
| 8151 | |
| 8152 | if (intel_crtc->cursor_base != base) |
| 8153 | I915_WRITE(_CURABASE, base); |
| 8154 | |
| 8155 | if (intel_crtc->cursor_size != size) { |
| 8156 | I915_WRITE(CURSIZE, size); |
| 8157 | intel_crtc->cursor_size = size; |
| 8158 | } |
| 8159 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8160 | if (intel_crtc->cursor_cntl != cntl) { |
| 8161 | I915_WRITE(_CURACNTR, cntl); |
| 8162 | POSTING_READ(_CURACNTR); |
| 8163 | intel_crtc->cursor_cntl = cntl; |
| 8164 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8165 | } |
| 8166 | |
| 8167 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8168 | { |
| 8169 | struct drm_device *dev = crtc->dev; |
| 8170 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8171 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8172 | int pipe = intel_crtc->pipe; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8173 | uint32_t cntl; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8174 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8175 | cntl = 0; |
| 8176 | if (base) { |
| 8177 | cntl = MCURSOR_GAMMA_ENABLE; |
| 8178 | switch (intel_crtc->cursor_width) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8179 | case 64: |
| 8180 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 8181 | break; |
| 8182 | case 128: |
| 8183 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 8184 | break; |
| 8185 | case 256: |
| 8186 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 8187 | break; |
| 8188 | default: |
| 8189 | WARN_ON(1); |
| 8190 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8191 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8192 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8193 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8194 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 8195 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
| 8196 | |
| 8197 | if (intel_crtc->cursor_cntl != cntl) { |
| 8198 | I915_WRITE(CURCNTR(pipe), cntl); |
| 8199 | POSTING_READ(CURCNTR(pipe)); |
| 8200 | intel_crtc->cursor_cntl = cntl; |
| 8201 | } |
| 8202 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8203 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8204 | I915_WRITE(CURBASE(pipe), base); |
| 8205 | POSTING_READ(CURBASE(pipe)); |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8206 | } |
| 8207 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8208 | /* 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] | 8209 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 8210 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8211 | { |
| 8212 | struct drm_device *dev = crtc->dev; |
| 8213 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8214 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8215 | int pipe = intel_crtc->pipe; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 8216 | int x = crtc->cursor_x; |
| 8217 | int y = crtc->cursor_y; |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8218 | u32 base = 0, pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8219 | |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8220 | if (on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8221 | base = intel_crtc->cursor_addr; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8222 | |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8223 | if (x >= intel_crtc->config.pipe_src_w) |
| 8224 | base = 0; |
| 8225 | |
| 8226 | if (y >= intel_crtc->config.pipe_src_h) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8227 | base = 0; |
| 8228 | |
| 8229 | if (x < 0) { |
Ville Syrjälä | efc9064 | 2013-09-04 18:25:30 +0300 | [diff] [blame] | 8230 | if (x + intel_crtc->cursor_width <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8231 | base = 0; |
| 8232 | |
| 8233 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 8234 | x = -x; |
| 8235 | } |
| 8236 | pos |= x << CURSOR_X_SHIFT; |
| 8237 | |
| 8238 | if (y < 0) { |
Ville Syrjälä | efc9064 | 2013-09-04 18:25:30 +0300 | [diff] [blame] | 8239 | if (y + intel_crtc->cursor_height <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8240 | base = 0; |
| 8241 | |
| 8242 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 8243 | y = -y; |
| 8244 | } |
| 8245 | pos |= y << CURSOR_Y_SHIFT; |
| 8246 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8247 | if (base == 0 && intel_crtc->cursor_base == 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8248 | return; |
| 8249 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8250 | I915_WRITE(CURPOS(pipe), pos); |
| 8251 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 8252 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8253 | i845_update_cursor(crtc, base); |
| 8254 | else |
| 8255 | i9xx_update_cursor(crtc, base); |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8256 | intel_crtc->cursor_base = base; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8257 | } |
| 8258 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8259 | static bool cursor_size_ok(struct drm_device *dev, |
| 8260 | uint32_t width, uint32_t height) |
| 8261 | { |
| 8262 | if (width == 0 || height == 0) |
| 8263 | return false; |
| 8264 | |
| 8265 | /* |
| 8266 | * 845g/865g are special in that they are only limited by |
| 8267 | * the width of their cursors, the height is arbitrary up to |
| 8268 | * the precision of the register. Everything else requires |
| 8269 | * square cursors, limited to a few power-of-two sizes. |
| 8270 | */ |
| 8271 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 8272 | if ((width & 63) != 0) |
| 8273 | return false; |
| 8274 | |
| 8275 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 8276 | return false; |
| 8277 | |
| 8278 | if (height > 1023) |
| 8279 | return false; |
| 8280 | } else { |
| 8281 | switch (width | height) { |
| 8282 | case 256: |
| 8283 | case 128: |
| 8284 | if (IS_GEN2(dev)) |
| 8285 | return false; |
| 8286 | case 64: |
| 8287 | break; |
| 8288 | default: |
| 8289 | return false; |
| 8290 | } |
| 8291 | } |
| 8292 | |
| 8293 | return true; |
| 8294 | } |
| 8295 | |
Matt Roper | e328795 | 2014-06-10 08:28:12 -0700 | [diff] [blame] | 8296 | /* |
| 8297 | * intel_crtc_cursor_set_obj - Set cursor to specified GEM object |
| 8298 | * |
| 8299 | * Note that the object's reference will be consumed if the update fails. If |
| 8300 | * the update succeeds, the reference of the old object (if any) will be |
| 8301 | * consumed. |
| 8302 | */ |
| 8303 | static int intel_crtc_cursor_set_obj(struct drm_crtc *crtc, |
| 8304 | struct drm_i915_gem_object *obj, |
| 8305 | uint32_t width, uint32_t height) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8306 | { |
| 8307 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8308 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 8309 | enum pipe pipe = intel_crtc->pipe; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8310 | unsigned old_width, stride; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8311 | uint32_t addr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8312 | int ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8313 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8314 | /* if we want to turn off the cursor ignore width and height */ |
Matt Roper | e328795 | 2014-06-10 08:28:12 -0700 | [diff] [blame] | 8315 | if (!obj) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 8316 | DRM_DEBUG_KMS("cursor off\n"); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8317 | addr = 0; |
Pierre Willenbrock | 5004417 | 2009-02-23 10:12:15 +1000 | [diff] [blame] | 8318 | mutex_lock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8319 | goto finish; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8320 | } |
| 8321 | |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8322 | /* Check for which cursor types we support */ |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8323 | if (!cursor_size_ok(dev, width, height)) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8324 | DRM_DEBUG("Cursor dimension not supported\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8325 | return -EINVAL; |
| 8326 | } |
| 8327 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8328 | stride = roundup_pow_of_two(width) * 4; |
| 8329 | if (obj->base.size < stride * height) { |
Matt Roper | e328795 | 2014-06-10 08:28:12 -0700 | [diff] [blame] | 8330 | DRM_DEBUG_KMS("buffer is too small\n"); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 8331 | ret = -ENOMEM; |
| 8332 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8333 | } |
| 8334 | |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 8335 | /* 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] | 8336 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 8337 | if (!INTEL_INFO(dev)->cursor_needs_physical) { |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 8338 | unsigned alignment; |
| 8339 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 8340 | if (obj->tiling_mode) { |
Daniel Vetter | 3b25b31 | 2014-02-14 14:06:06 +0100 | [diff] [blame] | 8341 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 8342 | ret = -EINVAL; |
| 8343 | goto fail_locked; |
| 8344 | } |
| 8345 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 8346 | /* Note that the w/a also requires 2 PTE of padding following |
| 8347 | * the bo. We currently fill all unused PTE with the shadow |
| 8348 | * page and so we should always have valid PTE following the |
| 8349 | * cursor preventing the VT-d warning. |
| 8350 | */ |
| 8351 | alignment = 0; |
| 8352 | if (need_vtd_wa(dev)) |
| 8353 | alignment = 64*1024; |
| 8354 | |
| 8355 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, NULL); |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 8356 | if (ret) { |
Daniel Vetter | 3b25b31 | 2014-02-14 14:06:06 +0100 | [diff] [blame] | 8357 | DRM_DEBUG_KMS("failed to move cursor bo into the GTT\n"); |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 8358 | goto fail_locked; |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 8359 | } |
| 8360 | |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 8361 | ret = i915_gem_object_put_fence(obj); |
| 8362 | if (ret) { |
Daniel Vetter | 3b25b31 | 2014-02-14 14:06:06 +0100 | [diff] [blame] | 8363 | DRM_DEBUG_KMS("failed to release fence for cursor"); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 8364 | goto fail_unpin; |
| 8365 | } |
| 8366 | |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 8367 | addr = i915_gem_obj_ggtt_offset(obj); |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 8368 | } else { |
Chris Wilson | 6eeefaf | 2010-08-07 11:01:39 +0100 | [diff] [blame] | 8369 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
Chris Wilson | 0073115 | 2014-05-21 12:42:56 +0100 | [diff] [blame] | 8370 | ret = i915_gem_object_attach_phys(obj, align); |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 8371 | if (ret) { |
Daniel Vetter | 3b25b31 | 2014-02-14 14:06:06 +0100 | [diff] [blame] | 8372 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 8373 | goto fail_locked; |
Dave Airlie | 71acb5e | 2008-12-30 20:31:46 +1000 | [diff] [blame] | 8374 | } |
Chris Wilson | 0073115 | 2014-05-21 12:42:56 +0100 | [diff] [blame] | 8375 | addr = obj->phys_handle->busaddr; |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8376 | } |
| 8377 | |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8378 | finish: |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8379 | if (intel_crtc->cursor_bo) { |
Chris Wilson | 0073115 | 2014-05-21 12:42:56 +0100 | [diff] [blame] | 8380 | if (!INTEL_INFO(dev)->cursor_needs_physical) |
Chris Wilson | cc98b41 | 2013-08-09 12:25:09 +0100 | [diff] [blame] | 8381 | i915_gem_object_unpin_from_display_plane(intel_crtc->cursor_bo); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8382 | } |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 8383 | |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 8384 | i915_gem_track_fb(intel_crtc->cursor_bo, obj, |
| 8385 | INTEL_FRONTBUFFER_CURSOR(pipe)); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 8386 | mutex_unlock(&dev->struct_mutex); |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8387 | |
Chris Wilson | 64f962e | 2014-03-26 12:38:15 +0000 | [diff] [blame] | 8388 | old_width = intel_crtc->cursor_width; |
| 8389 | |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8390 | intel_crtc->cursor_addr = addr; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8391 | intel_crtc->cursor_bo = obj; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8392 | intel_crtc->cursor_width = width; |
| 8393 | intel_crtc->cursor_height = height; |
| 8394 | |
Chris Wilson | 64f962e | 2014-03-26 12:38:15 +0000 | [diff] [blame] | 8395 | if (intel_crtc->active) { |
| 8396 | if (old_width != width) |
| 8397 | intel_update_watermarks(crtc); |
Ville Syrjälä | f2f5f77 | 2013-09-17 18:33:44 +0300 | [diff] [blame] | 8398 | intel_crtc_update_cursor(crtc, intel_crtc->cursor_bo != NULL); |
Chris Wilson | 64f962e | 2014-03-26 12:38:15 +0000 | [diff] [blame] | 8399 | } |
Kristian Høgsberg | 3f8bc37 | 2008-12-17 22:14:59 -0500 | [diff] [blame] | 8400 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 8401 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_CURSOR(pipe)); |
| 8402 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8403 | return 0; |
Chris Wilson | e7b526b | 2010-06-02 08:30:48 +0100 | [diff] [blame] | 8404 | fail_unpin: |
Chris Wilson | cc98b41 | 2013-08-09 12:25:09 +0100 | [diff] [blame] | 8405 | i915_gem_object_unpin_from_display_plane(obj); |
Kristian Høgsberg | 7f9872e | 2009-02-13 20:56:49 -0500 | [diff] [blame] | 8406 | fail_locked: |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 8407 | mutex_unlock(&dev->struct_mutex); |
Luca Barbieri | bc9025b | 2010-02-09 05:49:12 +0000 | [diff] [blame] | 8408 | fail: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 8409 | drm_gem_object_unreference_unlocked(&obj->base); |
Dave Airlie | 34b8686e | 2009-01-15 14:03:07 +1000 | [diff] [blame] | 8410 | return ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8411 | } |
| 8412 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8413 | 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] | 8414 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8415 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 8416 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8417 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8418 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 8419 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8420 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 8421 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 8422 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 8423 | } |
| 8424 | |
| 8425 | intel_crtc_load_lut(crtc); |
| 8426 | } |
| 8427 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8428 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 8429 | static struct drm_display_mode load_detect_mode = { |
| 8430 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 8431 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 8432 | }; |
| 8433 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 8434 | struct drm_framebuffer * |
| 8435 | __intel_framebuffer_create(struct drm_device *dev, |
| 8436 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 8437 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8438 | { |
| 8439 | struct intel_framebuffer *intel_fb; |
| 8440 | int ret; |
| 8441 | |
| 8442 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 8443 | if (!intel_fb) { |
| 8444 | drm_gem_object_unreference_unlocked(&obj->base); |
| 8445 | return ERR_PTR(-ENOMEM); |
| 8446 | } |
| 8447 | |
| 8448 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8449 | if (ret) |
| 8450 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8451 | |
| 8452 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8453 | err: |
| 8454 | drm_gem_object_unreference_unlocked(&obj->base); |
| 8455 | kfree(intel_fb); |
| 8456 | |
| 8457 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8458 | } |
| 8459 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 8460 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 8461 | intel_framebuffer_create(struct drm_device *dev, |
| 8462 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 8463 | struct drm_i915_gem_object *obj) |
| 8464 | { |
| 8465 | struct drm_framebuffer *fb; |
| 8466 | int ret; |
| 8467 | |
| 8468 | ret = i915_mutex_lock_interruptible(dev); |
| 8469 | if (ret) |
| 8470 | return ERR_PTR(ret); |
| 8471 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 8472 | mutex_unlock(&dev->struct_mutex); |
| 8473 | |
| 8474 | return fb; |
| 8475 | } |
| 8476 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8477 | static u32 |
| 8478 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 8479 | { |
| 8480 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 8481 | return ALIGN(pitch, 64); |
| 8482 | } |
| 8483 | |
| 8484 | static u32 |
| 8485 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 8486 | { |
| 8487 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 8488 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8489 | } |
| 8490 | |
| 8491 | static struct drm_framebuffer * |
| 8492 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 8493 | struct drm_display_mode *mode, |
| 8494 | int depth, int bpp) |
| 8495 | { |
| 8496 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 8497 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8498 | |
| 8499 | obj = i915_gem_alloc_object(dev, |
| 8500 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 8501 | if (obj == NULL) |
| 8502 | return ERR_PTR(-ENOMEM); |
| 8503 | |
| 8504 | mode_cmd.width = mode->hdisplay; |
| 8505 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 8506 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 8507 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 8508 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8509 | |
| 8510 | return intel_framebuffer_create(dev, &mode_cmd, obj); |
| 8511 | } |
| 8512 | |
| 8513 | static struct drm_framebuffer * |
| 8514 | mode_fits_in_fbdev(struct drm_device *dev, |
| 8515 | struct drm_display_mode *mode) |
| 8516 | { |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 8517 | #ifdef CONFIG_DRM_I915_FBDEV |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8518 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8519 | struct drm_i915_gem_object *obj; |
| 8520 | struct drm_framebuffer *fb; |
| 8521 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 8522 | if (!dev_priv->fbdev) |
| 8523 | return NULL; |
| 8524 | |
| 8525 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8526 | return NULL; |
| 8527 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 8528 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 8529 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8530 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 8531 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 8532 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 8533 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8534 | return NULL; |
| 8535 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 8536 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8537 | return NULL; |
| 8538 | |
| 8539 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 8540 | #else |
| 8541 | return NULL; |
| 8542 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8543 | } |
| 8544 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8545 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8546 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8547 | struct intel_load_detect_pipe *old, |
| 8548 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8549 | { |
| 8550 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8551 | struct intel_encoder *intel_encoder = |
| 8552 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8553 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 8554 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8555 | struct drm_crtc *crtc = NULL; |
| 8556 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8557 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8558 | struct drm_mode_config *config = &dev->mode_config; |
| 8559 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8560 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8561 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 8562 | connector->base.id, connector->name, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 8563 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8564 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8565 | retry: |
| 8566 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 8567 | if (ret) |
| 8568 | goto fail_unlock; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 8569 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8570 | /* |
| 8571 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 8572 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8573 | * - if the connector already has an assigned crtc, use it (but make |
| 8574 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 8575 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8576 | * - try to find the first unused crtc that can drive this connector, |
| 8577 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8578 | */ |
| 8579 | |
| 8580 | /* See if we already have a CRTC for this connector */ |
| 8581 | if (encoder->crtc) { |
| 8582 | crtc = encoder->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8583 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8584 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 8585 | if (ret) |
| 8586 | goto fail_unlock; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 8587 | |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8588 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8589 | old->load_detect_temp = false; |
| 8590 | |
| 8591 | /* Make sure the crtc and connector are running */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8592 | if (connector->dpms != DRM_MODE_DPMS_ON) |
| 8593 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8594 | |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8595 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8596 | } |
| 8597 | |
| 8598 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 8599 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8600 | i++; |
| 8601 | if (!(encoder->possible_crtcs & (1 << i))) |
| 8602 | continue; |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 8603 | if (possible_crtc->enabled) |
| 8604 | continue; |
| 8605 | /* This can occur when applying the pipe A quirk on resume. */ |
| 8606 | if (to_intel_crtc(possible_crtc)->new_enabled) |
| 8607 | continue; |
| 8608 | |
| 8609 | crtc = possible_crtc; |
| 8610 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8611 | } |
| 8612 | |
| 8613 | /* |
| 8614 | * If we didn't find an unused CRTC, don't use any. |
| 8615 | */ |
| 8616 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8617 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8618 | goto fail_unlock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8619 | } |
| 8620 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8621 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 8622 | if (ret) |
| 8623 | goto fail_unlock; |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 8624 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
| 8625 | to_intel_connector(connector)->new_encoder = intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8626 | |
| 8627 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8628 | intel_crtc->new_enabled = true; |
| 8629 | intel_crtc->new_config = &intel_crtc->config; |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8630 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8631 | old->load_detect_temp = true; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8632 | old->release_fb = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8633 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 8634 | if (!mode) |
| 8635 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8636 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8637 | /* We need a framebuffer large enough to accommodate all accesses |
| 8638 | * that the plane may generate whilst we perform load detection. |
| 8639 | * We can not rely on the fbcon either being present (we get called |
| 8640 | * during its initialisation to detect all boot displays, or it may |
| 8641 | * not even exist) or that it is large enough to satisfy the |
| 8642 | * requested mode. |
| 8643 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8644 | fb = mode_fits_in_fbdev(dev, mode); |
| 8645 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8646 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8647 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
| 8648 | old->release_fb = fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8649 | } else |
| 8650 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8651 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8652 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8653 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8654 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8655 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8656 | if (intel_set_mode(crtc, mode, 0, 0, fb)) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 8657 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8658 | if (old->release_fb) |
| 8659 | old->release_fb->funcs->destroy(old->release_fb); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8660 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8661 | } |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8662 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8663 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 8664 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8665 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8666 | |
| 8667 | fail: |
| 8668 | intel_crtc->new_enabled = crtc->enabled; |
| 8669 | if (intel_crtc->new_enabled) |
| 8670 | intel_crtc->new_config = &intel_crtc->config; |
| 8671 | else |
| 8672 | intel_crtc->new_config = NULL; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8673 | fail_unlock: |
| 8674 | if (ret == -EDEADLK) { |
| 8675 | drm_modeset_backoff(ctx); |
| 8676 | goto retry; |
| 8677 | } |
| 8678 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8679 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8680 | } |
| 8681 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8682 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 8683 | struct intel_load_detect_pipe *old) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8684 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8685 | struct intel_encoder *intel_encoder = |
| 8686 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 8687 | struct drm_encoder *encoder = &intel_encoder->base; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 8688 | struct drm_crtc *crtc = encoder->crtc; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8689 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8690 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8691 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 8692 | connector->base.id, connector->name, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 8693 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8694 | |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8695 | if (old->load_detect_temp) { |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 8696 | to_intel_connector(connector)->new_encoder = NULL; |
| 8697 | intel_encoder->new_crtc = NULL; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8698 | intel_crtc->new_enabled = false; |
| 8699 | intel_crtc->new_config = NULL; |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 8700 | intel_set_mode(crtc, NULL, 0, 0, NULL); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8701 | |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 8702 | if (old->release_fb) { |
| 8703 | drm_framebuffer_unregister_private(old->release_fb); |
| 8704 | drm_framebuffer_unreference(old->release_fb); |
| 8705 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8706 | |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 8707 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8708 | } |
| 8709 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 8710 | /* Switch crtc and encoder back off if necessary */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8711 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
| 8712 | connector->funcs->dpms(connector, old->dpms_mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8713 | } |
| 8714 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8715 | static int i9xx_pll_refclk(struct drm_device *dev, |
| 8716 | const struct intel_crtc_config *pipe_config) |
| 8717 | { |
| 8718 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8719 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 8720 | |
| 8721 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 8722 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8723 | else if (HAS_PCH_SPLIT(dev)) |
| 8724 | return 120000; |
| 8725 | else if (!IS_GEN2(dev)) |
| 8726 | return 96000; |
| 8727 | else |
| 8728 | return 48000; |
| 8729 | } |
| 8730 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8731 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8732 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
| 8733 | struct intel_crtc_config *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8734 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8735 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8736 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8737 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8738 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8739 | u32 fp; |
| 8740 | intel_clock_t clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8741 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8742 | |
| 8743 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8744 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8745 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8746 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8747 | |
| 8748 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 8749 | if (IS_PINEVIEW(dev)) { |
| 8750 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 8751 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 8752 | } else { |
| 8753 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 8754 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 8755 | } |
| 8756 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 8757 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 8758 | if (IS_PINEVIEW(dev)) |
| 8759 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 8760 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 8761 | else |
| 8762 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8763 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 8764 | |
| 8765 | switch (dpll & DPLL_MODE_MASK) { |
| 8766 | case DPLLB_MODE_DAC_SERIAL: |
| 8767 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 8768 | 5 : 10; |
| 8769 | break; |
| 8770 | case DPLLB_MODE_LVDS: |
| 8771 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 8772 | 7 : 14; |
| 8773 | break; |
| 8774 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 8775 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8776 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8777 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8778 | } |
| 8779 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 8780 | if (IS_PINEVIEW(dev)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8781 | pineview_clock(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 8782 | else |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8783 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8784 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 8785 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 8786 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8787 | |
| 8788 | if (is_lvds) { |
| 8789 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 8790 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 8791 | |
| 8792 | if (lvds & LVDS_CLKB_POWER_UP) |
| 8793 | clock.p2 = 7; |
| 8794 | else |
| 8795 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8796 | } else { |
| 8797 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 8798 | clock.p1 = 2; |
| 8799 | else { |
| 8800 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 8801 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 8802 | } |
| 8803 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 8804 | clock.p2 = 4; |
| 8805 | else |
| 8806 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8807 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 8808 | |
| 8809 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8810 | } |
| 8811 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8812 | /* |
| 8813 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 8814 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8815 | * encoder's get_config() function. |
| 8816 | */ |
| 8817 | pipe_config->port_clock = clock.dot; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8818 | } |
| 8819 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 8820 | int intel_dotclock_calculate(int link_freq, |
| 8821 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8822 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8823 | /* |
| 8824 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 8825 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8826 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 8827 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8828 | * |
| 8829 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 8830 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8831 | */ |
| 8832 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 8833 | if (!m_n->link_n) |
| 8834 | return 0; |
| 8835 | |
| 8836 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 8837 | } |
| 8838 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8839 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
| 8840 | struct intel_crtc_config *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 8841 | { |
| 8842 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8843 | |
| 8844 | /* read out port_clock from the DPLL */ |
| 8845 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 8846 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8847 | /* |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8848 | * This value does not include pixel_multiplier. |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 8849 | * We will check that port_clock and adjusted_mode.crtc_clock |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8850 | * agree once we know their relationship in the encoder's |
| 8851 | * get_config() function. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8852 | */ |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 8853 | pipe_config->adjusted_mode.crtc_clock = |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8854 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
| 8855 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8856 | } |
| 8857 | |
| 8858 | /** Returns the currently programmed mode of the given pipe. */ |
| 8859 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 8860 | struct drm_crtc *crtc) |
| 8861 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 8862 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8863 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 8864 | enum transcoder cpu_transcoder = intel_crtc->config.cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8865 | struct drm_display_mode *mode; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8866 | struct intel_crtc_config pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 8867 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 8868 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 8869 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 8870 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8871 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8872 | |
| 8873 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 8874 | if (!mode) |
| 8875 | return NULL; |
| 8876 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8877 | /* |
| 8878 | * Construct a pipe_config sufficient for getting the clock info |
| 8879 | * back out of crtc_clock_get. |
| 8880 | * |
| 8881 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 8882 | * to use a real value here instead. |
| 8883 | */ |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8884 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8885 | pipe_config.pixel_multiplier = 1; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 8886 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 8887 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 8888 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 8889 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
| 8890 | |
Ville Syrjälä | 773ae03 | 2013-09-23 17:48:20 +0300 | [diff] [blame] | 8891 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8892 | mode->hdisplay = (htot & 0xffff) + 1; |
| 8893 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 8894 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 8895 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 8896 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 8897 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 8898 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 8899 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 8900 | |
| 8901 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8902 | |
| 8903 | return mode; |
| 8904 | } |
| 8905 | |
Daniel Vetter | cc36513 | 2014-06-18 13:59:13 +0200 | [diff] [blame] | 8906 | static void intel_increase_pllclock(struct drm_device *dev, |
| 8907 | enum pipe pipe) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8908 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 8909 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 8910 | int dpll_reg = DPLL(pipe); |
| 8911 | int dpll; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8912 | |
Sonika Jindal | baff296 | 2014-07-22 11:16:35 +0530 | [diff] [blame] | 8913 | if (!HAS_GMCH_DISPLAY(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8914 | return; |
| 8915 | |
| 8916 | if (!dev_priv->lvds_downclock_avail) |
| 8917 | return; |
| 8918 | |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 8919 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8920 | if (!HAS_PIPE_CXSR(dev) && (dpll & DISPLAY_RATE_SELECT_FPA1)) { |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 8921 | DRM_DEBUG_DRIVER("upclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8922 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 8923 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8924 | |
| 8925 | dpll &= ~DISPLAY_RATE_SELECT_FPA1; |
| 8926 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 8927 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | dbdc647 | 2010-12-30 09:36:39 -0800 | [diff] [blame] | 8928 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8929 | dpll = I915_READ(dpll_reg); |
| 8930 | if (dpll & DISPLAY_RATE_SELECT_FPA1) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 8931 | DRM_DEBUG_DRIVER("failed to upclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8932 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8933 | } |
| 8934 | |
| 8935 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 8936 | { |
| 8937 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 8938 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8939 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8940 | |
Sonika Jindal | baff296 | 2014-07-22 11:16:35 +0530 | [diff] [blame] | 8941 | if (!HAS_GMCH_DISPLAY(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8942 | return; |
| 8943 | |
| 8944 | if (!dev_priv->lvds_downclock_avail) |
| 8945 | return; |
| 8946 | |
| 8947 | /* |
| 8948 | * Since this is called by a timer, we should never get here in |
| 8949 | * the manual case. |
| 8950 | */ |
| 8951 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 8952 | int pipe = intel_crtc->pipe; |
| 8953 | int dpll_reg = DPLL(pipe); |
Daniel Vetter | dc257cf | 2012-05-07 11:30:46 +0200 | [diff] [blame] | 8954 | int dpll; |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 8955 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 8956 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8957 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 8958 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8959 | |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 8960 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8961 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 8962 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 8963 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8964 | dpll = I915_READ(dpll_reg); |
| 8965 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 8966 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8967 | } |
| 8968 | |
| 8969 | } |
| 8970 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 8971 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 8972 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8973 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8974 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 8975 | if (dev_priv->mm.busy) |
| 8976 | return; |
| 8977 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 8978 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8979 | i915_update_gfx_val(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 8980 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 8981 | } |
| 8982 | |
| 8983 | void intel_mark_idle(struct drm_device *dev) |
| 8984 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8985 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 8986 | struct drm_crtc *crtc; |
| 8987 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 8988 | if (!dev_priv->mm.busy) |
| 8989 | return; |
| 8990 | |
| 8991 | dev_priv->mm.busy = false; |
| 8992 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 8993 | if (!i915.powersave) |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 8994 | goto out; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 8995 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 8996 | for_each_crtc(dev, crtc) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 8997 | if (!crtc->primary->fb) |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 8998 | continue; |
| 8999 | |
| 9000 | intel_decrease_pllclock(crtc); |
| 9001 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9002 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 9003 | if (INTEL_INFO(dev)->gen >= 6) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9004 | gen6_rps_idle(dev->dev_private); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 9005 | |
| 9006 | out: |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 9007 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9008 | } |
| 9009 | |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 9010 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9011 | /** |
| 9012 | * intel_mark_fb_busy - mark given planes as busy |
| 9013 | * @dev: DRM device |
| 9014 | * @frontbuffer_bits: bits for the affected planes |
| 9015 | * @ring: optional ring for asynchronous commands |
| 9016 | * |
| 9017 | * This function gets called every time the screen contents change. It can be |
| 9018 | * used to keep e.g. the update rate at the nominal refresh rate with DRRS. |
| 9019 | */ |
| 9020 | static void intel_mark_fb_busy(struct drm_device *dev, |
| 9021 | unsigned frontbuffer_bits, |
| 9022 | struct intel_engine_cs *ring) |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9023 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 9024 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | cc36513 | 2014-06-18 13:59:13 +0200 | [diff] [blame] | 9025 | enum pipe pipe; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9026 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 9027 | if (!i915.powersave) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9028 | return; |
| 9029 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 9030 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9031 | if (!(frontbuffer_bits & INTEL_FRONTBUFFER_ALL_MASK(pipe))) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9032 | continue; |
| 9033 | |
Daniel Vetter | cc36513 | 2014-06-18 13:59:13 +0200 | [diff] [blame] | 9034 | intel_increase_pllclock(dev, pipe); |
Chris Wilson | c65355b | 2013-06-06 16:53:41 -0300 | [diff] [blame] | 9035 | if (ring && intel_fbc_enabled(dev)) |
| 9036 | ring->fbc_dirty = true; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9037 | } |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9038 | } |
| 9039 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9040 | /** |
| 9041 | * intel_fb_obj_invalidate - invalidate frontbuffer object |
| 9042 | * @obj: GEM object to invalidate |
| 9043 | * @ring: set for asynchronous rendering |
| 9044 | * |
| 9045 | * This function gets called every time rendering on the given object starts and |
| 9046 | * frontbuffer caching (fbc, low refresh rate for DRRS, panel self refresh) must |
| 9047 | * be invalidated. If @ring is non-NULL any subsequent invalidation will be delayed |
| 9048 | * until the rendering completes or a flip on this frontbuffer plane is |
| 9049 | * scheduled. |
| 9050 | */ |
| 9051 | void intel_fb_obj_invalidate(struct drm_i915_gem_object *obj, |
| 9052 | struct intel_engine_cs *ring) |
| 9053 | { |
| 9054 | struct drm_device *dev = obj->base.dev; |
| 9055 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9056 | |
| 9057 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 9058 | |
| 9059 | if (!obj->frontbuffer_bits) |
| 9060 | return; |
| 9061 | |
| 9062 | if (ring) { |
| 9063 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9064 | dev_priv->fb_tracking.busy_bits |
| 9065 | |= obj->frontbuffer_bits; |
| 9066 | dev_priv->fb_tracking.flip_bits |
| 9067 | &= ~obj->frontbuffer_bits; |
| 9068 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9069 | } |
| 9070 | |
| 9071 | intel_mark_fb_busy(dev, obj->frontbuffer_bits, ring); |
| 9072 | |
Daniel Vetter | 9ca1530 | 2014-07-11 10:30:16 -0700 | [diff] [blame] | 9073 | intel_edp_psr_invalidate(dev, obj->frontbuffer_bits); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9074 | } |
| 9075 | |
| 9076 | /** |
| 9077 | * intel_frontbuffer_flush - flush frontbuffer |
| 9078 | * @dev: DRM device |
| 9079 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 9080 | * |
| 9081 | * This function gets called every time rendering on the given planes has |
| 9082 | * completed and frontbuffer caching can be started again. Flushes will get |
| 9083 | * delayed if they're blocked by some oustanding asynchronous rendering. |
| 9084 | * |
| 9085 | * Can be called without any locks held. |
| 9086 | */ |
| 9087 | void intel_frontbuffer_flush(struct drm_device *dev, |
| 9088 | unsigned frontbuffer_bits) |
| 9089 | { |
| 9090 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9091 | |
| 9092 | /* Delay flushing when rings are still busy.*/ |
| 9093 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9094 | frontbuffer_bits &= ~dev_priv->fb_tracking.busy_bits; |
| 9095 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9096 | |
| 9097 | intel_mark_fb_busy(dev, frontbuffer_bits, NULL); |
| 9098 | |
Daniel Vetter | 9ca1530 | 2014-07-11 10:30:16 -0700 | [diff] [blame] | 9099 | intel_edp_psr_flush(dev, frontbuffer_bits); |
Rodrigo Vivi | c5ad011 | 2014-08-04 03:51:38 -0700 | [diff] [blame] | 9100 | |
| 9101 | if (IS_GEN8(dev)) |
| 9102 | gen8_fbc_sw_flush(dev, FBC_REND_CACHE_CLEAN); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9103 | } |
| 9104 | |
| 9105 | /** |
| 9106 | * intel_fb_obj_flush - flush frontbuffer object |
| 9107 | * @obj: GEM object to flush |
| 9108 | * @retire: set when retiring asynchronous rendering |
| 9109 | * |
| 9110 | * This function gets called every time rendering on the given object has |
| 9111 | * completed and frontbuffer caching can be started again. If @retire is true |
| 9112 | * then any delayed flushes will be unblocked. |
| 9113 | */ |
| 9114 | void intel_fb_obj_flush(struct drm_i915_gem_object *obj, |
| 9115 | bool retire) |
| 9116 | { |
| 9117 | struct drm_device *dev = obj->base.dev; |
| 9118 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9119 | unsigned frontbuffer_bits; |
| 9120 | |
| 9121 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 9122 | |
| 9123 | if (!obj->frontbuffer_bits) |
| 9124 | return; |
| 9125 | |
| 9126 | frontbuffer_bits = obj->frontbuffer_bits; |
| 9127 | |
| 9128 | if (retire) { |
| 9129 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9130 | /* Filter out new bits since rendering started. */ |
| 9131 | frontbuffer_bits &= dev_priv->fb_tracking.busy_bits; |
| 9132 | |
| 9133 | dev_priv->fb_tracking.busy_bits &= ~frontbuffer_bits; |
| 9134 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9135 | } |
| 9136 | |
| 9137 | intel_frontbuffer_flush(dev, frontbuffer_bits); |
| 9138 | } |
| 9139 | |
| 9140 | /** |
| 9141 | * intel_frontbuffer_flip_prepare - prepare asnychronous frontbuffer flip |
| 9142 | * @dev: DRM device |
| 9143 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 9144 | * |
| 9145 | * This function gets called after scheduling a flip on @obj. The actual |
| 9146 | * frontbuffer flushing will be delayed until completion is signalled with |
| 9147 | * intel_frontbuffer_flip_complete. If an invalidate happens in between this |
| 9148 | * flush will be cancelled. |
| 9149 | * |
| 9150 | * Can be called without any locks held. |
| 9151 | */ |
| 9152 | void intel_frontbuffer_flip_prepare(struct drm_device *dev, |
| 9153 | unsigned frontbuffer_bits) |
| 9154 | { |
| 9155 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9156 | |
| 9157 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9158 | dev_priv->fb_tracking.flip_bits |
| 9159 | |= frontbuffer_bits; |
| 9160 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9161 | } |
| 9162 | |
| 9163 | /** |
| 9164 | * intel_frontbuffer_flip_complete - complete asynchronous frontbuffer flush |
| 9165 | * @dev: DRM device |
| 9166 | * @frontbuffer_bits: frontbuffer plane tracking bits |
| 9167 | * |
| 9168 | * This function gets called after the flip has been latched and will complete |
| 9169 | * on the next vblank. It will execute the fush if it hasn't been cancalled yet. |
| 9170 | * |
| 9171 | * Can be called without any locks held. |
| 9172 | */ |
| 9173 | void intel_frontbuffer_flip_complete(struct drm_device *dev, |
| 9174 | unsigned frontbuffer_bits) |
| 9175 | { |
| 9176 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9177 | |
| 9178 | mutex_lock(&dev_priv->fb_tracking.lock); |
| 9179 | /* Mask any cancelled flips. */ |
| 9180 | frontbuffer_bits &= dev_priv->fb_tracking.flip_bits; |
| 9181 | dev_priv->fb_tracking.flip_bits &= ~frontbuffer_bits; |
| 9182 | mutex_unlock(&dev_priv->fb_tracking.lock); |
| 9183 | |
| 9184 | intel_frontbuffer_flush(dev, frontbuffer_bits); |
| 9185 | } |
| 9186 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9187 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 9188 | { |
| 9189 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9190 | struct drm_device *dev = crtc->dev; |
| 9191 | struct intel_unpin_work *work; |
| 9192 | unsigned long flags; |
| 9193 | |
| 9194 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9195 | work = intel_crtc->unpin_work; |
| 9196 | intel_crtc->unpin_work = NULL; |
| 9197 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9198 | |
| 9199 | if (work) { |
| 9200 | cancel_work_sync(&work->work); |
| 9201 | kfree(work); |
| 9202 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9203 | |
| 9204 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9205 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9206 | kfree(intel_crtc); |
| 9207 | } |
| 9208 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9209 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 9210 | { |
| 9211 | struct intel_unpin_work *work = |
| 9212 | container_of(__work, struct intel_unpin_work, work); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9213 | struct drm_device *dev = work->crtc->dev; |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9214 | enum pipe pipe = to_intel_crtc(work->crtc)->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9215 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9216 | mutex_lock(&dev->struct_mutex); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 9217 | intel_unpin_fb_obj(work->old_fb_obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9218 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
| 9219 | drm_gem_object_unreference(&work->old_fb_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 9220 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9221 | intel_update_fbc(dev); |
| 9222 | mutex_unlock(&dev->struct_mutex); |
| 9223 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9224 | intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 9225 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9226 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
| 9227 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); |
| 9228 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9229 | kfree(work); |
| 9230 | } |
| 9231 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9232 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9233 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9234 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9235 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9236 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9237 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9238 | unsigned long flags; |
| 9239 | |
| 9240 | /* Ignore early vblank irqs */ |
| 9241 | if (intel_crtc == NULL) |
| 9242 | return; |
| 9243 | |
| 9244 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9245 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9246 | |
| 9247 | /* Ensure we don't miss a work->pending update ... */ |
| 9248 | smp_rmb(); |
| 9249 | |
| 9250 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9251 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9252 | return; |
| 9253 | } |
| 9254 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9255 | /* and that the unpin work is consistent wrt ->pending. */ |
| 9256 | smp_rmb(); |
| 9257 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9258 | intel_crtc->unpin_work = NULL; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9259 | |
Rob Clark | 45a066e | 2012-10-08 14:50:40 -0500 | [diff] [blame] | 9260 | if (work->event) |
| 9261 | drm_send_vblank_event(dev, intel_crtc->pipe, work->event); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9262 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 9263 | drm_crtc_vblank_put(crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 9264 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9265 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9266 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 9267 | wake_up_all(&dev_priv->pending_flip_queue); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9268 | |
| 9269 | queue_work(dev_priv->wq, &work->work); |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 9270 | |
| 9271 | trace_i915_flip_complete(intel_crtc->plane, work->pending_flip_obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9272 | } |
| 9273 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9274 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 9275 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9276 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9277 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 9278 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9279 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9280 | } |
| 9281 | |
| 9282 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 9283 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9284 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9285 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 9286 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9287 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9288 | } |
| 9289 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9290 | /* Is 'a' after or equal to 'b'? */ |
| 9291 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 9292 | { |
| 9293 | return !((a - b) & 0x80000000); |
| 9294 | } |
| 9295 | |
| 9296 | static bool page_flip_finished(struct intel_crtc *crtc) |
| 9297 | { |
| 9298 | struct drm_device *dev = crtc->base.dev; |
| 9299 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9300 | |
| 9301 | /* |
| 9302 | * The relevant registers doen't exist on pre-ctg. |
| 9303 | * As the flip done interrupt doesn't trigger for mmio |
| 9304 | * flips on gmch platforms, a flip count check isn't |
| 9305 | * really needed there. But since ctg has the registers, |
| 9306 | * include it in the check anyway. |
| 9307 | */ |
| 9308 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 9309 | return true; |
| 9310 | |
| 9311 | /* |
| 9312 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 9313 | * used the same base address. In that case the mmio flip might |
| 9314 | * have completed, but the CS hasn't even executed the flip yet. |
| 9315 | * |
| 9316 | * A flip count check isn't enough as the CS might have updated |
| 9317 | * the base address just after start of vblank, but before we |
| 9318 | * managed to process the interrupt. This means we'd complete the |
| 9319 | * CS flip too soon. |
| 9320 | * |
| 9321 | * Combining both checks should get us a good enough result. It may |
| 9322 | * still happen that the CS flip has been executed, but has not |
| 9323 | * yet actually completed. But in case the base address is the same |
| 9324 | * anyway, we don't really care. |
| 9325 | */ |
| 9326 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 9327 | crtc->unpin_work->gtt_offset && |
| 9328 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), |
| 9329 | crtc->unpin_work->flip_count); |
| 9330 | } |
| 9331 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9332 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 9333 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9334 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9335 | struct intel_crtc *intel_crtc = |
| 9336 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 9337 | unsigned long flags; |
| 9338 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9339 | /* NB: An MMIO update of the plane base pointer will also |
| 9340 | * generate a page-flip completion irq, i.e. every modeset |
| 9341 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 9342 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9343 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9344 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9345 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9346 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9347 | } |
| 9348 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9349 | 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] | 9350 | { |
| 9351 | /* Ensure that the work item is consistent when activating it ... */ |
| 9352 | smp_wmb(); |
| 9353 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); |
| 9354 | /* and that it is marked active as soon as the irq could fire. */ |
| 9355 | smp_wmb(); |
| 9356 | } |
| 9357 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9358 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 9359 | struct drm_crtc *crtc, |
| 9360 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9361 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9362 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9363 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9364 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9365 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9366 | u32 flip_mask; |
| 9367 | int ret; |
| 9368 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9369 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9370 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9371 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9372 | |
| 9373 | /* Can't queue multiple flips, so wait for the previous |
| 9374 | * one to finish before executing the next. |
| 9375 | */ |
| 9376 | if (intel_crtc->plane) |
| 9377 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9378 | else |
| 9379 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9380 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9381 | intel_ring_emit(ring, MI_NOOP); |
| 9382 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9383 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9384 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9385 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9386 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9387 | |
| 9388 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9389 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9390 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9391 | } |
| 9392 | |
| 9393 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 9394 | struct drm_crtc *crtc, |
| 9395 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9396 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9397 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9398 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9399 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9400 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9401 | u32 flip_mask; |
| 9402 | int ret; |
| 9403 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9404 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9405 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9406 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9407 | |
| 9408 | if (intel_crtc->plane) |
| 9409 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9410 | else |
| 9411 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9412 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9413 | intel_ring_emit(ring, MI_NOOP); |
| 9414 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
| 9415 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9416 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9417 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9418 | intel_ring_emit(ring, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9419 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9420 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9421 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9422 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9423 | } |
| 9424 | |
| 9425 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 9426 | struct drm_crtc *crtc, |
| 9427 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9428 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9429 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9430 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9431 | { |
| 9432 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9433 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9434 | uint32_t pf, pipesrc; |
| 9435 | int ret; |
| 9436 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9437 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9438 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9439 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9440 | |
| 9441 | /* i965+ uses the linear or tiled offsets from the |
| 9442 | * Display Registers (which do not change across a page-flip) |
| 9443 | * so we need only reprogram the base address. |
| 9444 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9445 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9446 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9447 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9448 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 9449 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9450 | |
| 9451 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 9452 | * untested on non-native modes, so ignore it for now. |
| 9453 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 9454 | */ |
| 9455 | pf = 0; |
| 9456 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9457 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9458 | |
| 9459 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9460 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9461 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9462 | } |
| 9463 | |
| 9464 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 9465 | struct drm_crtc *crtc, |
| 9466 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9467 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9468 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9469 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9470 | { |
| 9471 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9472 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9473 | uint32_t pf, pipesrc; |
| 9474 | int ret; |
| 9475 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9476 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9477 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9478 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9479 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9480 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9481 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9482 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9483 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9484 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 9485 | /* Contrary to the suggestions in the documentation, |
| 9486 | * "Enable Panel Fitter" does not seem to be required when page |
| 9487 | * flipping with a non-native mode, and worse causes a normal |
| 9488 | * modeset to fail. |
| 9489 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 9490 | */ |
| 9491 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9492 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9493 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9494 | |
| 9495 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9496 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9497 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9498 | } |
| 9499 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9500 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 9501 | struct drm_crtc *crtc, |
| 9502 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9503 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9504 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9505 | uint32_t flags) |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9506 | { |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9507 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9508 | uint32_t plane_bit = 0; |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9509 | int len, ret; |
| 9510 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9511 | switch (intel_crtc->plane) { |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9512 | case PLANE_A: |
| 9513 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 9514 | break; |
| 9515 | case PLANE_B: |
| 9516 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 9517 | break; |
| 9518 | case PLANE_C: |
| 9519 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 9520 | break; |
| 9521 | default: |
| 9522 | WARN_ONCE(1, "unknown plane in flip command\n"); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9523 | return -ENODEV; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9524 | } |
| 9525 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9526 | len = 4; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9527 | if (ring->id == RCS) { |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9528 | len += 6; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9529 | /* |
| 9530 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 9531 | * 48bits addresses, and we need a NOOP for the batch size to |
| 9532 | * stay even. |
| 9533 | */ |
| 9534 | if (IS_GEN8(dev)) |
| 9535 | len += 2; |
| 9536 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9537 | |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9538 | /* |
| 9539 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 9540 | * "The full packet must be contained within the same cache line." |
| 9541 | * |
| 9542 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 9543 | * cacheline, if we ever start emitting more commands before |
| 9544 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 9545 | * then do the cacheline alignment, and finally emit the |
| 9546 | * MI_DISPLAY_FLIP. |
| 9547 | */ |
| 9548 | ret = intel_ring_cacheline_align(ring); |
| 9549 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9550 | return ret; |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9551 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9552 | ret = intel_ring_begin(ring, len); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9553 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9554 | return ret; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9555 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9556 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 9557 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 9558 | * more than one flip event at any time (or ensure that one flip message |
| 9559 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 9560 | * Experimentation says that BCS works despite DERRMR masking all |
| 9561 | * flip-done completion events and that unmasking all planes at once |
| 9562 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 9563 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 9564 | */ |
| 9565 | if (ring->id == RCS) { |
| 9566 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
| 9567 | intel_ring_emit(ring, DERRMR); |
| 9568 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 9569 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 9570 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9571 | if (IS_GEN8(dev)) |
| 9572 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) | |
| 9573 | MI_SRM_LRM_GLOBAL_GTT); |
| 9574 | else |
| 9575 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | |
| 9576 | MI_SRM_LRM_GLOBAL_GTT); |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9577 | intel_ring_emit(ring, DERRMR); |
| 9578 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9579 | if (IS_GEN8(dev)) { |
| 9580 | intel_ring_emit(ring, 0); |
| 9581 | intel_ring_emit(ring, MI_NOOP); |
| 9582 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9583 | } |
| 9584 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9585 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 9586 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9587 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9588 | intel_ring_emit(ring, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9589 | |
| 9590 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9591 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9592 | return 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9593 | } |
| 9594 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9595 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
| 9596 | struct drm_i915_gem_object *obj) |
| 9597 | { |
| 9598 | /* |
| 9599 | * This is not being used for older platforms, because |
| 9600 | * non-availability of flip done interrupt forces us to use |
| 9601 | * CS flips. Older platforms derive flip done using some clever |
| 9602 | * tricks involving the flip_pending status bits and vblank irqs. |
| 9603 | * So using MMIO flips there would disrupt this mechanism. |
| 9604 | */ |
| 9605 | |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 9606 | if (ring == NULL) |
| 9607 | return true; |
| 9608 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9609 | if (INTEL_INFO(ring->dev)->gen < 5) |
| 9610 | return false; |
| 9611 | |
| 9612 | if (i915.use_mmio_flip < 0) |
| 9613 | return false; |
| 9614 | else if (i915.use_mmio_flip > 0) |
| 9615 | return true; |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 9616 | else if (i915.enable_execlists) |
| 9617 | return true; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9618 | else |
| 9619 | return ring != obj->ring; |
| 9620 | } |
| 9621 | |
| 9622 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 9623 | { |
| 9624 | struct drm_device *dev = intel_crtc->base.dev; |
| 9625 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9626 | struct intel_framebuffer *intel_fb = |
| 9627 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 9628 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 9629 | u32 dspcntr; |
| 9630 | u32 reg; |
| 9631 | |
| 9632 | intel_mark_page_flip_active(intel_crtc); |
| 9633 | |
| 9634 | reg = DSPCNTR(intel_crtc->plane); |
| 9635 | dspcntr = I915_READ(reg); |
| 9636 | |
| 9637 | if (INTEL_INFO(dev)->gen >= 4) { |
| 9638 | if (obj->tiling_mode != I915_TILING_NONE) |
| 9639 | dspcntr |= DISPPLANE_TILED; |
| 9640 | else |
| 9641 | dspcntr &= ~DISPPLANE_TILED; |
| 9642 | } |
| 9643 | I915_WRITE(reg, dspcntr); |
| 9644 | |
| 9645 | I915_WRITE(DSPSURF(intel_crtc->plane), |
| 9646 | intel_crtc->unpin_work->gtt_offset); |
| 9647 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
| 9648 | } |
| 9649 | |
| 9650 | static int intel_postpone_flip(struct drm_i915_gem_object *obj) |
| 9651 | { |
| 9652 | struct intel_engine_cs *ring; |
| 9653 | int ret; |
| 9654 | |
| 9655 | lockdep_assert_held(&obj->base.dev->struct_mutex); |
| 9656 | |
| 9657 | if (!obj->last_write_seqno) |
| 9658 | return 0; |
| 9659 | |
| 9660 | ring = obj->ring; |
| 9661 | |
| 9662 | if (i915_seqno_passed(ring->get_seqno(ring, true), |
| 9663 | obj->last_write_seqno)) |
| 9664 | return 0; |
| 9665 | |
| 9666 | ret = i915_gem_check_olr(ring, obj->last_write_seqno); |
| 9667 | if (ret) |
| 9668 | return ret; |
| 9669 | |
| 9670 | if (WARN_ON(!ring->irq_get(ring))) |
| 9671 | return 0; |
| 9672 | |
| 9673 | return 1; |
| 9674 | } |
| 9675 | |
| 9676 | void intel_notify_mmio_flip(struct intel_engine_cs *ring) |
| 9677 | { |
| 9678 | struct drm_i915_private *dev_priv = to_i915(ring->dev); |
| 9679 | struct intel_crtc *intel_crtc; |
| 9680 | unsigned long irq_flags; |
| 9681 | u32 seqno; |
| 9682 | |
| 9683 | seqno = ring->get_seqno(ring, false); |
| 9684 | |
| 9685 | spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags); |
| 9686 | for_each_intel_crtc(ring->dev, intel_crtc) { |
| 9687 | struct intel_mmio_flip *mmio_flip; |
| 9688 | |
| 9689 | mmio_flip = &intel_crtc->mmio_flip; |
| 9690 | if (mmio_flip->seqno == 0) |
| 9691 | continue; |
| 9692 | |
| 9693 | if (ring->id != mmio_flip->ring_id) |
| 9694 | continue; |
| 9695 | |
| 9696 | if (i915_seqno_passed(seqno, mmio_flip->seqno)) { |
| 9697 | intel_do_mmio_flip(intel_crtc); |
| 9698 | mmio_flip->seqno = 0; |
| 9699 | ring->irq_put(ring); |
| 9700 | } |
| 9701 | } |
| 9702 | spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags); |
| 9703 | } |
| 9704 | |
| 9705 | static int intel_queue_mmio_flip(struct drm_device *dev, |
| 9706 | struct drm_crtc *crtc, |
| 9707 | struct drm_framebuffer *fb, |
| 9708 | struct drm_i915_gem_object *obj, |
| 9709 | struct intel_engine_cs *ring, |
| 9710 | uint32_t flags) |
| 9711 | { |
| 9712 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9713 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9714 | unsigned long irq_flags; |
| 9715 | int ret; |
| 9716 | |
| 9717 | if (WARN_ON(intel_crtc->mmio_flip.seqno)) |
| 9718 | return -EBUSY; |
| 9719 | |
| 9720 | ret = intel_postpone_flip(obj); |
| 9721 | if (ret < 0) |
| 9722 | return ret; |
| 9723 | if (ret == 0) { |
| 9724 | intel_do_mmio_flip(intel_crtc); |
| 9725 | return 0; |
| 9726 | } |
| 9727 | |
| 9728 | spin_lock_irqsave(&dev_priv->mmio_flip_lock, irq_flags); |
| 9729 | intel_crtc->mmio_flip.seqno = obj->last_write_seqno; |
| 9730 | intel_crtc->mmio_flip.ring_id = obj->ring->id; |
| 9731 | spin_unlock_irqrestore(&dev_priv->mmio_flip_lock, irq_flags); |
| 9732 | |
| 9733 | /* |
| 9734 | * Double check to catch cases where irq fired before |
| 9735 | * mmio flip data was ready |
| 9736 | */ |
| 9737 | intel_notify_mmio_flip(obj->ring); |
| 9738 | return 0; |
| 9739 | } |
| 9740 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9741 | static int intel_default_queue_flip(struct drm_device *dev, |
| 9742 | struct drm_crtc *crtc, |
| 9743 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9744 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9745 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9746 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9747 | { |
| 9748 | return -ENODEV; |
| 9749 | } |
| 9750 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9751 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 9752 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9753 | struct drm_pending_vblank_event *event, |
| 9754 | uint32_t page_flip_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9755 | { |
| 9756 | struct drm_device *dev = crtc->dev; |
| 9757 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9758 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 9759 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9760 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 9761 | enum pipe pipe = intel_crtc->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9762 | struct intel_unpin_work *work; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9763 | struct intel_engine_cs *ring; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9764 | unsigned long flags; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 9765 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9766 | |
Daisy Sun | c76bb61 | 2014-08-11 11:08:38 -0700 | [diff] [blame] | 9767 | //trigger software GT busyness calculation |
| 9768 | gen8_flip_interrupt(dev); |
| 9769 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 9770 | /* |
| 9771 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 9772 | * check to be safe. In the future we may enable pageflipping from |
| 9773 | * a disabled primary plane. |
| 9774 | */ |
| 9775 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 9776 | return -EBUSY; |
| 9777 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 9778 | /* Can't change pixel format via MI display flips. */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9779 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 9780 | return -EINVAL; |
| 9781 | |
| 9782 | /* |
| 9783 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 9784 | * Note that pitch changes could also affect these register. |
| 9785 | */ |
| 9786 | if (INTEL_INFO(dev)->gen > 3 && |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9787 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 9788 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 9789 | return -EINVAL; |
| 9790 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 9791 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 9792 | goto out_hang; |
| 9793 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 9794 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9795 | if (work == NULL) |
| 9796 | return -ENOMEM; |
| 9797 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9798 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9799 | work->crtc = crtc; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 9800 | work->old_fb_obj = intel_fb_obj(old_fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9801 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 9802 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 9803 | ret = drm_crtc_vblank_get(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 9804 | if (ret) |
| 9805 | goto free_work; |
| 9806 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9807 | /* We borrow the event spin lock for protecting unpin_work */ |
| 9808 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9809 | if (intel_crtc->unpin_work) { |
| 9810 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9811 | kfree(work); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 9812 | drm_crtc_vblank_put(crtc); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 9813 | |
| 9814 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9815 | return -EBUSY; |
| 9816 | } |
| 9817 | intel_crtc->unpin_work = work; |
| 9818 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9819 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9820 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 9821 | flush_workqueue(dev_priv->wq); |
| 9822 | |
Chris Wilson | 7915810 | 2012-05-23 11:13:58 +0100 | [diff] [blame] | 9823 | ret = i915_mutex_lock_interruptible(dev); |
| 9824 | if (ret) |
| 9825 | goto cleanup; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9826 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 9827 | /* Reference the objects for the scheduled work. */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9828 | drm_gem_object_reference(&work->old_fb_obj->base); |
| 9829 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9830 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9831 | crtc->primary->fb = fb; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 9832 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 9833 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 9834 | |
Simon Farnsworth | 4e5359c | 2010-09-01 17:47:52 +0100 | [diff] [blame] | 9835 | work->enable_stall_check = true; |
| 9836 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9837 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 9838 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 9839 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9840 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 9841 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9842 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9843 | if (IS_VALLEYVIEW(dev)) { |
| 9844 | ring = &dev_priv->ring[BCS]; |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 9845 | if (obj->tiling_mode != work->old_fb_obj->tiling_mode) |
| 9846 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
| 9847 | ring = NULL; |
Chris Wilson | 2a92d5b | 2014-07-08 10:40:29 +0100 | [diff] [blame] | 9848 | } else if (IS_IVYBRIDGE(dev)) { |
| 9849 | ring = &dev_priv->ring[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9850 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 9851 | ring = obj->ring; |
| 9852 | if (ring == NULL || ring->id != RCS) |
| 9853 | ring = &dev_priv->ring[BCS]; |
| 9854 | } else { |
| 9855 | ring = &dev_priv->ring[RCS]; |
| 9856 | } |
| 9857 | |
| 9858 | ret = intel_pin_and_fence_fb_obj(dev, obj, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9859 | if (ret) |
| 9860 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9861 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9862 | work->gtt_offset = |
| 9863 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset; |
| 9864 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9865 | if (use_mmio_flip(ring, obj)) |
| 9866 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
| 9867 | page_flip_flags); |
| 9868 | else |
| 9869 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring, |
| 9870 | page_flip_flags); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9871 | if (ret) |
| 9872 | goto cleanup_unpin; |
| 9873 | |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 9874 | i915_gem_track_fb(work->old_fb_obj, obj, |
| 9875 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 9876 | |
Chris Wilson | 7782de3 | 2011-07-08 12:22:41 +0100 | [diff] [blame] | 9877 | intel_disable_fbc(dev); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9878 | intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9879 | mutex_unlock(&dev->struct_mutex); |
| 9880 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 9881 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 9882 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9883 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 9884 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9885 | cleanup_unpin: |
| 9886 | intel_unpin_fb_obj(obj); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9887 | cleanup_pending: |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9888 | atomic_dec(&intel_crtc->unpin_work_count); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9889 | crtc->primary->fb = old_fb; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9890 | drm_gem_object_unreference(&work->old_fb_obj->base); |
| 9891 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 9892 | mutex_unlock(&dev->struct_mutex); |
| 9893 | |
Chris Wilson | 7915810 | 2012-05-23 11:13:58 +0100 | [diff] [blame] | 9894 | cleanup: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 9895 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9896 | intel_crtc->unpin_work = NULL; |
| 9897 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9898 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 9899 | drm_crtc_vblank_put(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 9900 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 9901 | kfree(work); |
| 9902 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 9903 | if (ret == -EIO) { |
| 9904 | out_hang: |
| 9905 | intel_crtc_wait_for_pending_flips(crtc); |
| 9906 | ret = intel_pipe_set_base(crtc, crtc->x, crtc->y, fb); |
| 9907 | if (ret == 0 && event) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 9908 | drm_send_vblank_event(dev, pipe, event); |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 9909 | } |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 9910 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9911 | } |
| 9912 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 9913 | static struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 9914 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 9915 | .load_lut = intel_crtc_load_lut, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 9916 | }; |
| 9917 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 9918 | /** |
| 9919 | * intel_modeset_update_staged_output_state |
| 9920 | * |
| 9921 | * Updates the staged output configuration state, e.g. after we've read out the |
| 9922 | * current hw state. |
| 9923 | */ |
| 9924 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) |
| 9925 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 9926 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 9927 | struct intel_encoder *encoder; |
| 9928 | struct intel_connector *connector; |
| 9929 | |
| 9930 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 9931 | base.head) { |
| 9932 | connector->new_encoder = |
| 9933 | to_intel_encoder(connector->base.encoder); |
| 9934 | } |
| 9935 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 9936 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 9937 | encoder->new_crtc = |
| 9938 | to_intel_crtc(encoder->base.crtc); |
| 9939 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 9940 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9941 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 9942 | crtc->new_enabled = crtc->base.enabled; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 9943 | |
| 9944 | if (crtc->new_enabled) |
| 9945 | crtc->new_config = &crtc->config; |
| 9946 | else |
| 9947 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 9948 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 9949 | } |
| 9950 | |
| 9951 | /** |
| 9952 | * intel_modeset_commit_output_state |
| 9953 | * |
| 9954 | * This function copies the stage display pipe configuration to the real one. |
| 9955 | */ |
| 9956 | static void intel_modeset_commit_output_state(struct drm_device *dev) |
| 9957 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 9958 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 9959 | struct intel_encoder *encoder; |
| 9960 | struct intel_connector *connector; |
| 9961 | |
| 9962 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 9963 | base.head) { |
| 9964 | connector->base.encoder = &connector->new_encoder->base; |
| 9965 | } |
| 9966 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 9967 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 9968 | encoder->base.crtc = &encoder->new_crtc->base; |
| 9969 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 9970 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 9971 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 9972 | crtc->base.enabled = crtc->new_enabled; |
| 9973 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 9974 | } |
| 9975 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 9976 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9977 | connected_sink_compute_bpp(struct intel_connector *connector, |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 9978 | struct intel_crtc_config *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 9979 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 9980 | int bpp = pipe_config->pipe_bpp; |
| 9981 | |
| 9982 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 9983 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 9984 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 9985 | |
| 9986 | /* Don't use an invalid EDID bpc value */ |
| 9987 | if (connector->base.display_info.bpc && |
| 9988 | connector->base.display_info.bpc * 3 < bpp) { |
| 9989 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 9990 | bpp, connector->base.display_info.bpc*3); |
| 9991 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 9992 | } |
| 9993 | |
| 9994 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
| 9995 | if (connector->base.display_info.bpc == 0 && bpp > 24) { |
| 9996 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 9997 | bpp); |
| 9998 | pipe_config->pipe_bpp = 24; |
| 9999 | } |
| 10000 | } |
| 10001 | |
| 10002 | static int |
| 10003 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
| 10004 | struct drm_framebuffer *fb, |
| 10005 | struct intel_crtc_config *pipe_config) |
| 10006 | { |
| 10007 | struct drm_device *dev = crtc->base.dev; |
| 10008 | struct intel_connector *connector; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10009 | int bpp; |
| 10010 | |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10011 | switch (fb->pixel_format) { |
| 10012 | case DRM_FORMAT_C8: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10013 | bpp = 8*3; /* since we go through a colormap */ |
| 10014 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10015 | case DRM_FORMAT_XRGB1555: |
| 10016 | case DRM_FORMAT_ARGB1555: |
| 10017 | /* checked in intel_framebuffer_init already */ |
| 10018 | if (WARN_ON(INTEL_INFO(dev)->gen > 3)) |
| 10019 | return -EINVAL; |
| 10020 | case DRM_FORMAT_RGB565: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10021 | bpp = 6*3; /* min is 18bpp */ |
| 10022 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10023 | case DRM_FORMAT_XBGR8888: |
| 10024 | case DRM_FORMAT_ABGR8888: |
| 10025 | /* checked in intel_framebuffer_init already */ |
| 10026 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
| 10027 | return -EINVAL; |
| 10028 | case DRM_FORMAT_XRGB8888: |
| 10029 | case DRM_FORMAT_ARGB8888: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10030 | bpp = 8*3; |
| 10031 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10032 | case DRM_FORMAT_XRGB2101010: |
| 10033 | case DRM_FORMAT_ARGB2101010: |
| 10034 | case DRM_FORMAT_XBGR2101010: |
| 10035 | case DRM_FORMAT_ABGR2101010: |
| 10036 | /* checked in intel_framebuffer_init already */ |
| 10037 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10038 | return -EINVAL; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10039 | bpp = 10*3; |
| 10040 | break; |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10041 | /* TODO: gen4+ supports 16 bpc floating point, too. */ |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10042 | default: |
| 10043 | DRM_DEBUG_KMS("unsupported depth\n"); |
| 10044 | return -EINVAL; |
| 10045 | } |
| 10046 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10047 | pipe_config->pipe_bpp = bpp; |
| 10048 | |
| 10049 | /* Clamp display bpp to EDID value */ |
| 10050 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10051 | base.head) { |
Daniel Vetter | 1b829e0 | 2013-06-02 13:26:24 +0200 | [diff] [blame] | 10052 | if (!connector->new_encoder || |
| 10053 | connector->new_encoder->new_crtc != crtc) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10054 | continue; |
| 10055 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10056 | connected_sink_compute_bpp(connector, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10057 | } |
| 10058 | |
| 10059 | return bpp; |
| 10060 | } |
| 10061 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10062 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 10063 | { |
| 10064 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 10065 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 10066 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10067 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 10068 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 10069 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 10070 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 10071 | } |
| 10072 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10073 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
| 10074 | struct intel_crtc_config *pipe_config, |
| 10075 | const char *context) |
| 10076 | { |
| 10077 | DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id, |
| 10078 | context, pipe_name(crtc->pipe)); |
| 10079 | |
| 10080 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); |
| 10081 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 10082 | pipe_config->pipe_bpp, pipe_config->dither); |
| 10083 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10084 | pipe_config->has_pch_encoder, |
| 10085 | pipe_config->fdi_lanes, |
| 10086 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 10087 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 10088 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10089 | DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10090 | pipe_config->has_dp_encoder, |
| 10091 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 10092 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 10093 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10094 | |
| 10095 | DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
| 10096 | pipe_config->has_dp_encoder, |
| 10097 | pipe_config->dp_m2_n2.gmch_m, |
| 10098 | pipe_config->dp_m2_n2.gmch_n, |
| 10099 | pipe_config->dp_m2_n2.link_m, |
| 10100 | pipe_config->dp_m2_n2.link_n, |
| 10101 | pipe_config->dp_m2_n2.tu); |
| 10102 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10103 | DRM_DEBUG_KMS("requested mode:\n"); |
| 10104 | drm_mode_debug_printmodeline(&pipe_config->requested_mode); |
| 10105 | DRM_DEBUG_KMS("adjusted mode:\n"); |
| 10106 | drm_mode_debug_printmodeline(&pipe_config->adjusted_mode); |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10107 | intel_dump_crtc_timings(&pipe_config->adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 10108 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10109 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 10110 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10111 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 10112 | pipe_config->gmch_pfit.control, |
| 10113 | pipe_config->gmch_pfit.pgm_ratios, |
| 10114 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10115 | 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] | 10116 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10117 | pipe_config->pch_pfit.size, |
| 10118 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10119 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 10120 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10121 | } |
| 10122 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10123 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10124 | const struct intel_encoder *b) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10125 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10126 | /* masks could be asymmetric, so check both ways */ |
| 10127 | return a == b || (a->cloneable & (1 << b->type) && |
| 10128 | b->cloneable & (1 << a->type)); |
| 10129 | } |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10130 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10131 | static bool check_single_encoder_cloning(struct intel_crtc *crtc, |
| 10132 | struct intel_encoder *encoder) |
| 10133 | { |
| 10134 | struct drm_device *dev = crtc->base.dev; |
| 10135 | struct intel_encoder *source_encoder; |
| 10136 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10137 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10138 | if (source_encoder->new_crtc != crtc) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10139 | continue; |
| 10140 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10141 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10142 | return false; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10143 | } |
| 10144 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10145 | return true; |
| 10146 | } |
| 10147 | |
| 10148 | static bool check_encoder_cloning(struct intel_crtc *crtc) |
| 10149 | { |
| 10150 | struct drm_device *dev = crtc->base.dev; |
| 10151 | struct intel_encoder *encoder; |
| 10152 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10153 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10154 | if (encoder->new_crtc != crtc) |
| 10155 | continue; |
| 10156 | |
| 10157 | if (!check_single_encoder_cloning(crtc, encoder)) |
| 10158 | return false; |
| 10159 | } |
| 10160 | |
| 10161 | return true; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10162 | } |
| 10163 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10164 | static struct intel_crtc_config * |
| 10165 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10166 | struct drm_framebuffer *fb, |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10167 | struct drm_display_mode *mode) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10168 | { |
| 10169 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10170 | struct intel_encoder *encoder; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10171 | struct intel_crtc_config *pipe_config; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10172 | int plane_bpp, ret = -EINVAL; |
| 10173 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10174 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10175 | if (!check_encoder_cloning(to_intel_crtc(crtc))) { |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10176 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 10177 | return ERR_PTR(-EINVAL); |
| 10178 | } |
| 10179 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10180 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 10181 | if (!pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10182 | return ERR_PTR(-ENOMEM); |
| 10183 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10184 | drm_mode_copy(&pipe_config->adjusted_mode, mode); |
| 10185 | drm_mode_copy(&pipe_config->requested_mode, mode); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10186 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 10187 | pipe_config->cpu_transcoder = |
| 10188 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10189 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10190 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10191 | /* |
| 10192 | * Sanitize sync polarity flags based on requested ones. If neither |
| 10193 | * positive or negative polarity is requested, treat this as meaning |
| 10194 | * negative polarity. |
| 10195 | */ |
| 10196 | if (!(pipe_config->adjusted_mode.flags & |
| 10197 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
| 10198 | pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
| 10199 | |
| 10200 | if (!(pipe_config->adjusted_mode.flags & |
| 10201 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
| 10202 | pipe_config->adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
| 10203 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10204 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
| 10205 | * plane pixel format and any sink constraints into account. Returns the |
| 10206 | * source plane bpp so that dithering can be selected on mismatches |
| 10207 | * after encoders and crtc also have had their say. */ |
| 10208 | plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 10209 | fb, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10210 | if (plane_bpp < 0) |
| 10211 | goto fail; |
| 10212 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10213 | /* |
| 10214 | * Determine the real pipe dimensions. Note that stereo modes can |
| 10215 | * increase the actual pipe size due to the frame doubling and |
| 10216 | * insertion of additional space for blanks between the frame. This |
| 10217 | * is stored in the crtc timings. We use the requested mode to do this |
| 10218 | * computation to clearly distinguish it from the adjusted mode, which |
| 10219 | * can be changed by the connectors in the below retry loop. |
| 10220 | */ |
| 10221 | drm_mode_set_crtcinfo(&pipe_config->requested_mode, CRTC_STEREO_DOUBLE); |
| 10222 | pipe_config->pipe_src_w = pipe_config->requested_mode.crtc_hdisplay; |
| 10223 | pipe_config->pipe_src_h = pipe_config->requested_mode.crtc_vdisplay; |
| 10224 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10225 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10226 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10227 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10228 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10229 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10230 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Damien Lespiau | 6ce70f5 | 2013-09-25 16:45:38 +0100 | [diff] [blame] | 10231 | drm_mode_set_crtcinfo(&pipe_config->adjusted_mode, CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10232 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10233 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 10234 | * adjust it according to limitations or connector properties, and also |
| 10235 | * a chance to reject the mode entirely. |
| 10236 | */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10237 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10238 | |
| 10239 | if (&encoder->new_crtc->base != crtc) |
| 10240 | continue; |
Daniel Vetter | 7ae8923 | 2013-03-27 00:44:52 +0100 | [diff] [blame] | 10241 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 10242 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 10243 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10244 | goto fail; |
| 10245 | } |
| 10246 | } |
| 10247 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10248 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 10249 | * done afterwards in case the encoder adjusts the mode. */ |
| 10250 | if (!pipe_config->port_clock) |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10251 | pipe_config->port_clock = pipe_config->adjusted_mode.crtc_clock |
| 10252 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10253 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 10254 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10255 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10256 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 10257 | goto fail; |
| 10258 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10259 | |
| 10260 | if (ret == RETRY) { |
| 10261 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 10262 | ret = -EINVAL; |
| 10263 | goto fail; |
| 10264 | } |
| 10265 | |
| 10266 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 10267 | retry = false; |
| 10268 | goto encoder_retry; |
| 10269 | } |
| 10270 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10271 | pipe_config->dither = pipe_config->pipe_bpp != plane_bpp; |
| 10272 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
| 10273 | plane_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
| 10274 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10275 | return pipe_config; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10276 | fail: |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10277 | kfree(pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10278 | return ERR_PTR(ret); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10279 | } |
| 10280 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10281 | /* Computes which crtcs are affected and sets the relevant bits in the mask. For |
| 10282 | * simplicity we use the crtc's pipe number (because it's easier to obtain). */ |
| 10283 | static void |
| 10284 | intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes, |
| 10285 | unsigned *prepare_pipes, unsigned *disable_pipes) |
| 10286 | { |
| 10287 | struct intel_crtc *intel_crtc; |
| 10288 | struct drm_device *dev = crtc->dev; |
| 10289 | struct intel_encoder *encoder; |
| 10290 | struct intel_connector *connector; |
| 10291 | struct drm_crtc *tmp_crtc; |
| 10292 | |
| 10293 | *disable_pipes = *modeset_pipes = *prepare_pipes = 0; |
| 10294 | |
| 10295 | /* Check which crtcs have changed outputs connected to them, these need |
| 10296 | * to be part of the prepare_pipes mask. We don't (yet) support global |
| 10297 | * modeset across multiple crtcs, so modeset_pipes will only have one |
| 10298 | * bit set at most. */ |
| 10299 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 10300 | base.head) { |
| 10301 | if (connector->base.encoder == &connector->new_encoder->base) |
| 10302 | continue; |
| 10303 | |
| 10304 | if (connector->base.encoder) { |
| 10305 | tmp_crtc = connector->base.encoder->crtc; |
| 10306 | |
| 10307 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 10308 | } |
| 10309 | |
| 10310 | if (connector->new_encoder) |
| 10311 | *prepare_pipes |= |
| 10312 | 1 << connector->new_encoder->new_crtc->pipe; |
| 10313 | } |
| 10314 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10315 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10316 | if (encoder->base.crtc == &encoder->new_crtc->base) |
| 10317 | continue; |
| 10318 | |
| 10319 | if (encoder->base.crtc) { |
| 10320 | tmp_crtc = encoder->base.crtc; |
| 10321 | |
| 10322 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 10323 | } |
| 10324 | |
| 10325 | if (encoder->new_crtc) |
| 10326 | *prepare_pipes |= 1 << encoder->new_crtc->pipe; |
| 10327 | } |
| 10328 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10329 | /* Check for pipes that will be enabled/disabled ... */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10330 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10331 | if (intel_crtc->base.enabled == intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10332 | continue; |
| 10333 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10334 | if (!intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10335 | *disable_pipes |= 1 << intel_crtc->pipe; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10336 | else |
| 10337 | *prepare_pipes |= 1 << intel_crtc->pipe; |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10338 | } |
| 10339 | |
| 10340 | |
| 10341 | /* set_mode is also used to update properties on life display pipes. */ |
| 10342 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10343 | if (intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10344 | *prepare_pipes |= 1 << intel_crtc->pipe; |
| 10345 | |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 10346 | /* |
| 10347 | * For simplicity do a full modeset on any pipe where the output routing |
| 10348 | * changed. We could be more clever, but that would require us to be |
| 10349 | * more careful with calling the relevant encoder->mode_set functions. |
| 10350 | */ |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10351 | if (*prepare_pipes) |
| 10352 | *modeset_pipes = *prepare_pipes; |
| 10353 | |
| 10354 | /* ... and mask these out. */ |
| 10355 | *modeset_pipes &= ~(*disable_pipes); |
| 10356 | *prepare_pipes &= ~(*disable_pipes); |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 10357 | |
| 10358 | /* |
| 10359 | * HACK: We don't (yet) fully support global modesets. intel_set_config |
| 10360 | * obies this rule, but the modeset restore mode of |
| 10361 | * intel_modeset_setup_hw_state does not. |
| 10362 | */ |
| 10363 | *modeset_pipes &= 1 << intel_crtc->pipe; |
| 10364 | *prepare_pipes &= 1 << intel_crtc->pipe; |
Daniel Vetter | e3641d3 | 2013-04-11 19:49:07 +0200 | [diff] [blame] | 10365 | |
| 10366 | DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n", |
| 10367 | *modeset_pipes, *prepare_pipes, *disable_pipes); |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10368 | } |
| 10369 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10370 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
| 10371 | { |
| 10372 | struct drm_encoder *encoder; |
| 10373 | struct drm_device *dev = crtc->dev; |
| 10374 | |
| 10375 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 10376 | if (encoder->crtc == crtc) |
| 10377 | return true; |
| 10378 | |
| 10379 | return false; |
| 10380 | } |
| 10381 | |
| 10382 | static void |
| 10383 | intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes) |
| 10384 | { |
| 10385 | struct intel_encoder *intel_encoder; |
| 10386 | struct intel_crtc *intel_crtc; |
| 10387 | struct drm_connector *connector; |
| 10388 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10389 | for_each_intel_encoder(dev, intel_encoder) { |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10390 | if (!intel_encoder->base.crtc) |
| 10391 | continue; |
| 10392 | |
| 10393 | intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
| 10394 | |
| 10395 | if (prepare_pipes & (1 << intel_crtc->pipe)) |
| 10396 | intel_encoder->connectors_active = false; |
| 10397 | } |
| 10398 | |
| 10399 | intel_modeset_commit_output_state(dev); |
| 10400 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10401 | /* Double check state. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10402 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10403 | 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] | 10404 | WARN_ON(intel_crtc->new_config && |
| 10405 | intel_crtc->new_config != &intel_crtc->config); |
| 10406 | WARN_ON(intel_crtc->base.enabled != !!intel_crtc->new_config); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10407 | } |
| 10408 | |
| 10409 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 10410 | if (!connector->encoder || !connector->encoder->crtc) |
| 10411 | continue; |
| 10412 | |
| 10413 | intel_crtc = to_intel_crtc(connector->encoder->crtc); |
| 10414 | |
| 10415 | if (prepare_pipes & (1 << intel_crtc->pipe)) { |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 10416 | struct drm_property *dpms_property = |
| 10417 | dev->mode_config.dpms_property; |
| 10418 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10419 | connector->dpms = DRM_MODE_DPMS_ON; |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 10420 | drm_object_property_set_value(&connector->base, |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 10421 | dpms_property, |
| 10422 | DRM_MODE_DPMS_ON); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10423 | |
| 10424 | intel_encoder = to_intel_encoder(connector->encoder); |
| 10425 | intel_encoder->connectors_active = true; |
| 10426 | } |
| 10427 | } |
| 10428 | |
| 10429 | } |
| 10430 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 10431 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10432 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 10433 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10434 | |
| 10435 | if (clock1 == clock2) |
| 10436 | return true; |
| 10437 | |
| 10438 | if (!clock1 || !clock2) |
| 10439 | return false; |
| 10440 | |
| 10441 | diff = abs(clock1 - clock2); |
| 10442 | |
| 10443 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 10444 | return true; |
| 10445 | |
| 10446 | return false; |
| 10447 | } |
| 10448 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10449 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 10450 | list_for_each_entry((intel_crtc), \ |
| 10451 | &(dev)->mode_config.crtc_list, \ |
| 10452 | base.head) \ |
Daniel Vetter | 0973f18 | 2013-04-19 11:25:33 +0200 | [diff] [blame] | 10453 | if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10454 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10455 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 10456 | intel_pipe_config_compare(struct drm_device *dev, |
| 10457 | struct intel_crtc_config *current_config, |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10458 | struct intel_crtc_config *pipe_config) |
| 10459 | { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10460 | #define PIPE_CONF_CHECK_X(name) \ |
| 10461 | if (current_config->name != pipe_config->name) { \ |
| 10462 | DRM_ERROR("mismatch in " #name " " \ |
| 10463 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 10464 | current_config->name, \ |
| 10465 | pipe_config->name); \ |
| 10466 | return false; \ |
| 10467 | } |
| 10468 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10469 | #define PIPE_CONF_CHECK_I(name) \ |
| 10470 | if (current_config->name != pipe_config->name) { \ |
| 10471 | DRM_ERROR("mismatch in " #name " " \ |
| 10472 | "(expected %i, found %i)\n", \ |
| 10473 | current_config->name, \ |
| 10474 | pipe_config->name); \ |
| 10475 | return false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 10476 | } |
| 10477 | |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10478 | /* This is required for BDW+ where there is only one set of registers for |
| 10479 | * switching between high and low RR. |
| 10480 | * This macro can be used whenever a comparison has to be made between one |
| 10481 | * hw state and multiple sw state variables. |
| 10482 | */ |
| 10483 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ |
| 10484 | if ((current_config->name != pipe_config->name) && \ |
| 10485 | (current_config->alt_name != pipe_config->name)) { \ |
| 10486 | DRM_ERROR("mismatch in " #name " " \ |
| 10487 | "(expected %i or %i, found %i)\n", \ |
| 10488 | current_config->name, \ |
| 10489 | current_config->alt_name, \ |
| 10490 | pipe_config->name); \ |
| 10491 | return false; \ |
| 10492 | } |
| 10493 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10494 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 10495 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Jesse Barnes | 6f02488 | 2013-07-01 10:19:09 -0700 | [diff] [blame] | 10496 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10497 | "(expected %i, found %i)\n", \ |
| 10498 | current_config->name & (mask), \ |
| 10499 | pipe_config->name & (mask)); \ |
| 10500 | return false; \ |
| 10501 | } |
| 10502 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10503 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 10504 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
| 10505 | DRM_ERROR("mismatch in " #name " " \ |
| 10506 | "(expected %i, found %i)\n", \ |
| 10507 | current_config->name, \ |
| 10508 | pipe_config->name); \ |
| 10509 | return false; \ |
| 10510 | } |
| 10511 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10512 | #define PIPE_CONF_QUIRK(quirk) \ |
| 10513 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 10514 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 10515 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 10516 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10517 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 10518 | PIPE_CONF_CHECK_I(fdi_lanes); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 10519 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
| 10520 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); |
| 10521 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); |
| 10522 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); |
| 10523 | PIPE_CONF_CHECK_I(fdi_m_n.tu); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10524 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10525 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10526 | |
| 10527 | if (INTEL_INFO(dev)->gen < 8) { |
| 10528 | PIPE_CONF_CHECK_I(dp_m_n.gmch_m); |
| 10529 | PIPE_CONF_CHECK_I(dp_m_n.gmch_n); |
| 10530 | PIPE_CONF_CHECK_I(dp_m_n.link_m); |
| 10531 | PIPE_CONF_CHECK_I(dp_m_n.link_n); |
| 10532 | PIPE_CONF_CHECK_I(dp_m_n.tu); |
| 10533 | |
| 10534 | if (current_config->has_drrs) { |
| 10535 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m); |
| 10536 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n); |
| 10537 | PIPE_CONF_CHECK_I(dp_m2_n2.link_m); |
| 10538 | PIPE_CONF_CHECK_I(dp_m2_n2.link_n); |
| 10539 | PIPE_CONF_CHECK_I(dp_m2_n2.tu); |
| 10540 | } |
| 10541 | } else { |
| 10542 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m); |
| 10543 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n); |
| 10544 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m); |
| 10545 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n); |
| 10546 | PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu); |
| 10547 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10548 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10549 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hdisplay); |
| 10550 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_htotal); |
| 10551 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_start); |
| 10552 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hblank_end); |
| 10553 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_start); |
| 10554 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_hsync_end); |
| 10555 | |
| 10556 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vdisplay); |
| 10557 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vtotal); |
| 10558 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_start); |
| 10559 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vblank_end); |
| 10560 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_start); |
| 10561 | PIPE_CONF_CHECK_I(adjusted_mode.crtc_vsync_end); |
| 10562 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 10563 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 10564 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 10565 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
| 10566 | IS_VALLEYVIEW(dev)) |
| 10567 | PIPE_CONF_CHECK_I(limited_color_range); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10568 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 10569 | PIPE_CONF_CHECK_I(has_audio); |
| 10570 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10571 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10572 | DRM_MODE_FLAG_INTERLACE); |
| 10573 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10574 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
| 10575 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10576 | DRM_MODE_FLAG_PHSYNC); |
| 10577 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10578 | DRM_MODE_FLAG_NHSYNC); |
| 10579 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10580 | DRM_MODE_FLAG_PVSYNC); |
| 10581 | PIPE_CONF_CHECK_FLAGS(adjusted_mode.flags, |
| 10582 | DRM_MODE_FLAG_NVSYNC); |
| 10583 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 10584 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10585 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 10586 | PIPE_CONF_CHECK_I(pipe_src_h); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10587 | |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 10588 | /* |
| 10589 | * FIXME: BIOS likes to set up a cloned config with lvds+external |
| 10590 | * screen. Since we don't yet re-compute the pipe config when moving |
| 10591 | * just the lvds port away to another pipe the sw tracking won't match. |
| 10592 | * |
| 10593 | * Proper atomic modesets with recomputed global state will fix this. |
| 10594 | * Until then just don't check gmch state for inherited modes. |
| 10595 | */ |
| 10596 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) { |
| 10597 | PIPE_CONF_CHECK_I(gmch_pfit.control); |
| 10598 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 10599 | if (INTEL_INFO(dev)->gen < 4) |
| 10600 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
| 10601 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); |
| 10602 | } |
| 10603 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10604 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 10605 | if (current_config->pch_pfit.enabled) { |
| 10606 | PIPE_CONF_CHECK_I(pch_pfit.pos); |
| 10607 | PIPE_CONF_CHECK_I(pch_pfit.size); |
| 10608 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 10609 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 10610 | /* BDW+ don't expose a synchronous way to read the state */ |
| 10611 | if (IS_HASWELL(dev)) |
| 10612 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10613 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 10614 | PIPE_CONF_CHECK_I(double_wide); |
| 10615 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10616 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 10617 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10618 | PIPE_CONF_CHECK_I(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10619 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 10620 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10621 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 10622 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 10623 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10624 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 10625 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 10626 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 10627 | |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 10628 | PIPE_CONF_CHECK_CLOCK_FUZZY(adjusted_mode.crtc_clock); |
| 10629 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10630 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10631 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10632 | #undef PIPE_CONF_CHECK_I |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10633 | #undef PIPE_CONF_CHECK_I_ALT |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10634 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10635 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10636 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 10637 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10638 | return true; |
| 10639 | } |
| 10640 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10641 | static void |
| 10642 | check_connector_state(struct drm_device *dev) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10643 | { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10644 | struct intel_connector *connector; |
| 10645 | |
| 10646 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 10647 | base.head) { |
| 10648 | /* This also checks the encoder/connector hw state with the |
| 10649 | * ->get_hw_state callbacks. */ |
| 10650 | intel_connector_check_state(connector); |
| 10651 | |
| 10652 | WARN(&connector->new_encoder->base != connector->base.encoder, |
| 10653 | "connector's staged encoder doesn't match current encoder\n"); |
| 10654 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10655 | } |
| 10656 | |
| 10657 | static void |
| 10658 | check_encoder_state(struct drm_device *dev) |
| 10659 | { |
| 10660 | struct intel_encoder *encoder; |
| 10661 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10662 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10663 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10664 | bool enabled = false; |
| 10665 | bool active = false; |
| 10666 | enum pipe pipe, tracked_pipe; |
| 10667 | |
| 10668 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 10669 | encoder->base.base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10670 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10671 | |
| 10672 | WARN(&encoder->new_crtc->base != encoder->base.crtc, |
| 10673 | "encoder's stage crtc doesn't match current crtc\n"); |
| 10674 | WARN(encoder->connectors_active && !encoder->base.crtc, |
| 10675 | "encoder's active_connectors set, but no crtc\n"); |
| 10676 | |
| 10677 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 10678 | base.head) { |
| 10679 | if (connector->base.encoder != &encoder->base) |
| 10680 | continue; |
| 10681 | enabled = true; |
| 10682 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) |
| 10683 | active = true; |
| 10684 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 10685 | /* |
| 10686 | * for MST connectors if we unplug the connector is gone |
| 10687 | * away but the encoder is still connected to a crtc |
| 10688 | * until a modeset happens in response to the hotplug. |
| 10689 | */ |
| 10690 | if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST) |
| 10691 | continue; |
| 10692 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10693 | WARN(!!encoder->base.crtc != enabled, |
| 10694 | "encoder's enabled state mismatch " |
| 10695 | "(expected %i, found %i)\n", |
| 10696 | !!encoder->base.crtc, enabled); |
| 10697 | WARN(active && !encoder->base.crtc, |
| 10698 | "active encoder with no crtc\n"); |
| 10699 | |
| 10700 | WARN(encoder->connectors_active != active, |
| 10701 | "encoder's computed active state doesn't match tracked active state " |
| 10702 | "(expected %i, found %i)\n", active, encoder->connectors_active); |
| 10703 | |
| 10704 | active = encoder->get_hw_state(encoder, &pipe); |
| 10705 | WARN(active != encoder->connectors_active, |
| 10706 | "encoder's hw state doesn't match sw tracking " |
| 10707 | "(expected %i, found %i)\n", |
| 10708 | encoder->connectors_active, active); |
| 10709 | |
| 10710 | if (!encoder->base.crtc) |
| 10711 | continue; |
| 10712 | |
| 10713 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; |
| 10714 | WARN(active && pipe != tracked_pipe, |
| 10715 | "active encoder's pipe doesn't match" |
| 10716 | "(expected %i, found %i)\n", |
| 10717 | tracked_pipe, pipe); |
| 10718 | |
| 10719 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10720 | } |
| 10721 | |
| 10722 | static void |
| 10723 | check_crtc_state(struct drm_device *dev) |
| 10724 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10725 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10726 | struct intel_crtc *crtc; |
| 10727 | struct intel_encoder *encoder; |
| 10728 | struct intel_crtc_config pipe_config; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10729 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10730 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10731 | bool enabled = false; |
| 10732 | bool active = false; |
| 10733 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 10734 | memset(&pipe_config, 0, sizeof(pipe_config)); |
| 10735 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10736 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 10737 | crtc->base.base.id); |
| 10738 | |
| 10739 | WARN(crtc->active && !crtc->base.enabled, |
| 10740 | "active crtc, but not enabled in sw tracking\n"); |
| 10741 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10742 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10743 | if (encoder->base.crtc != &crtc->base) |
| 10744 | continue; |
| 10745 | enabled = true; |
| 10746 | if (encoder->connectors_active) |
| 10747 | active = true; |
| 10748 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10749 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10750 | WARN(active != crtc->active, |
| 10751 | "crtc's computed active state doesn't match tracked active state " |
| 10752 | "(expected %i, found %i)\n", active, crtc->active); |
| 10753 | WARN(enabled != crtc->base.enabled, |
| 10754 | "crtc's computed enabled state doesn't match tracked enabled state " |
| 10755 | "(expected %i, found %i)\n", enabled, crtc->base.enabled); |
| 10756 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10757 | active = dev_priv->display.get_pipe_config(crtc, |
| 10758 | &pipe_config); |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 10759 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame^] | 10760 | /* hw state is inconsistent with the pipe quirk */ |
| 10761 | if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 10762 | (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 10763 | active = crtc->active; |
| 10764 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10765 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 3eaba51 | 2013-08-05 17:57:48 +0300 | [diff] [blame] | 10766 | enum pipe pipe; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10767 | if (encoder->base.crtc != &crtc->base) |
| 10768 | continue; |
Daniel Vetter | 1d37b68 | 2013-11-18 09:00:59 +0100 | [diff] [blame] | 10769 | if (encoder->get_hw_state(encoder, &pipe)) |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10770 | encoder->get_config(encoder, &pipe_config); |
| 10771 | } |
| 10772 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10773 | WARN(crtc->active != active, |
| 10774 | "crtc active state doesn't match with hw state " |
| 10775 | "(expected %i, found %i)\n", crtc->active, active); |
| 10776 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10777 | if (active && |
| 10778 | !intel_pipe_config_compare(dev, &crtc->config, &pipe_config)) { |
| 10779 | WARN(1, "pipe state doesn't match!\n"); |
| 10780 | intel_dump_pipe_config(crtc, &pipe_config, |
| 10781 | "[hw state]"); |
| 10782 | intel_dump_pipe_config(crtc, &crtc->config, |
| 10783 | "[sw state]"); |
| 10784 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10785 | } |
| 10786 | } |
| 10787 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10788 | static void |
| 10789 | check_shared_dpll_state(struct drm_device *dev) |
| 10790 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10791 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10792 | struct intel_crtc *crtc; |
| 10793 | struct intel_dpll_hw_state dpll_hw_state; |
| 10794 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 10795 | |
| 10796 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 10797 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 10798 | int enabled_crtcs = 0, active_crtcs = 0; |
| 10799 | bool active; |
| 10800 | |
| 10801 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 10802 | |
| 10803 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 10804 | |
| 10805 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 10806 | |
| 10807 | WARN(pll->active > pll->refcount, |
| 10808 | "more active pll users than references: %i vs %i\n", |
| 10809 | pll->active, pll->refcount); |
| 10810 | WARN(pll->active && !pll->on, |
| 10811 | "pll in active use but not on in sw tracking\n"); |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 10812 | WARN(pll->on && !pll->active, |
| 10813 | "pll in on but not on in use in sw tracking\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 10814 | WARN(pll->on != active, |
| 10815 | "pll on state mismatch (expected %i, found %i)\n", |
| 10816 | pll->on, active); |
| 10817 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10818 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 10819 | if (crtc->base.enabled && intel_crtc_to_shared_dpll(crtc) == pll) |
| 10820 | enabled_crtcs++; |
| 10821 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 10822 | active_crtcs++; |
| 10823 | } |
| 10824 | WARN(pll->active != active_crtcs, |
| 10825 | "pll active crtcs mismatch (expected %i, found %i)\n", |
| 10826 | pll->active, active_crtcs); |
| 10827 | WARN(pll->refcount != enabled_crtcs, |
| 10828 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
| 10829 | pll->refcount, enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10830 | |
| 10831 | WARN(pll->on && memcmp(&pll->hw_state, &dpll_hw_state, |
| 10832 | sizeof(dpll_hw_state)), |
| 10833 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 10834 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 10835 | } |
| 10836 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10837 | void |
| 10838 | intel_modeset_check_state(struct drm_device *dev) |
| 10839 | { |
| 10840 | check_connector_state(dev); |
| 10841 | check_encoder_state(dev); |
| 10842 | check_crtc_state(dev); |
| 10843 | check_shared_dpll_state(dev); |
| 10844 | } |
| 10845 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10846 | void ironlake_check_encoder_dotclock(const struct intel_crtc_config *pipe_config, |
| 10847 | int dotclock) |
| 10848 | { |
| 10849 | /* |
| 10850 | * FDI already provided one idea for the dotclock. |
| 10851 | * Yell if the encoder disagrees. |
| 10852 | */ |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10853 | 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] | 10854 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10855 | pipe_config->adjusted_mode.crtc_clock, dotclock); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 10856 | } |
| 10857 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 10858 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 10859 | { |
| 10860 | struct drm_device *dev = crtc->base.dev; |
| 10861 | |
| 10862 | /* |
| 10863 | * The scanline counter increments at the leading edge of hsync. |
| 10864 | * |
| 10865 | * On most platforms it starts counting from vtotal-1 on the |
| 10866 | * first active line. That means the scanline counter value is |
| 10867 | * always one less than what we would expect. Ie. just after |
| 10868 | * start of vblank, which also occurs at start of hsync (on the |
| 10869 | * last active line), the scanline counter will read vblank_start-1. |
| 10870 | * |
| 10871 | * On gen2 the scanline counter starts counting from 1 instead |
| 10872 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 10873 | * to keep the value positive), instead of adding one. |
| 10874 | * |
| 10875 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 10876 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 10877 | * there's an extra 1 line difference. So we need to add two instead of |
| 10878 | * one to the value. |
| 10879 | */ |
| 10880 | if (IS_GEN2(dev)) { |
| 10881 | const struct drm_display_mode *mode = &crtc->config.adjusted_mode; |
| 10882 | int vtotal; |
| 10883 | |
| 10884 | vtotal = mode->crtc_vtotal; |
| 10885 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 10886 | vtotal /= 2; |
| 10887 | |
| 10888 | crtc->scanline_offset = vtotal - 1; |
| 10889 | } else if (HAS_DDI(dev) && |
| 10890 | intel_pipe_has_type(&crtc->base, INTEL_OUTPUT_HDMI)) { |
| 10891 | crtc->scanline_offset = 2; |
| 10892 | } else |
| 10893 | crtc->scanline_offset = 1; |
| 10894 | } |
| 10895 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 10896 | static int __intel_set_mode(struct drm_crtc *crtc, |
| 10897 | struct drm_display_mode *mode, |
| 10898 | int x, int y, struct drm_framebuffer *fb) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 10899 | { |
| 10900 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 10901 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 10902 | struct drm_display_mode *saved_mode; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10903 | struct intel_crtc_config *pipe_config = NULL; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10904 | struct intel_crtc *intel_crtc; |
| 10905 | unsigned disable_pipes, prepare_pipes, modeset_pipes; |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 10906 | int ret = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 10907 | |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 10908 | saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 10909 | if (!saved_mode) |
| 10910 | return -ENOMEM; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 10911 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10912 | intel_modeset_affected_pipes(crtc, &modeset_pipes, |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10913 | &prepare_pipes, &disable_pipes); |
| 10914 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 10915 | *saved_mode = crtc->mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 10916 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10917 | /* Hack: Because we don't (yet) support global modeset on multiple |
| 10918 | * crtcs, we don't keep track of the new mode for more than one crtc. |
| 10919 | * Hence simply check whether any bit is set in modeset_pipes in all the |
| 10920 | * pieces of code that are not yet converted to deal with mutliple crtcs |
| 10921 | * changing their mode at the same time. */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10922 | if (modeset_pipes) { |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10923 | pipe_config = intel_modeset_pipe_config(crtc, fb, mode); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10924 | if (IS_ERR(pipe_config)) { |
| 10925 | ret = PTR_ERR(pipe_config); |
| 10926 | pipe_config = NULL; |
| 10927 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 10928 | goto out; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10929 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10930 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 10931 | "[modeset]"); |
Ville Syrjälä | 50741ab | 2014-01-10 11:28:07 +0200 | [diff] [blame] | 10932 | to_intel_crtc(crtc)->new_config = pipe_config; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 10933 | } |
| 10934 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 10935 | /* |
| 10936 | * See if the config requires any additional preparation, e.g. |
| 10937 | * to adjust global state with pipes off. We need to do this |
| 10938 | * here so we can get the modeset_pipe updated config for the new |
| 10939 | * mode set on this crtc. For other crtcs we need to use the |
| 10940 | * adjusted_mode bits in the crtc directly. |
| 10941 | */ |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 10942 | if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 10943 | valleyview_modeset_global_pipes(dev, &prepare_pipes); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 10944 | |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 10945 | /* may have added more to prepare_pipes than we should */ |
| 10946 | prepare_pipes &= ~disable_pipes; |
| 10947 | } |
| 10948 | |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 10949 | for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc) |
| 10950 | intel_crtc_disable(&intel_crtc->base); |
| 10951 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10952 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
| 10953 | if (intel_crtc->base.enabled) |
| 10954 | dev_priv->display.crtc_disable(&intel_crtc->base); |
| 10955 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 10956 | |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 10957 | /* crtc->mode is already used by the ->mode_set callbacks, hence we need |
| 10958 | * to set it here already despite that we pass it down the callchain. |
| 10959 | */ |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10960 | if (modeset_pipes) { |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10961 | crtc->mode = *mode; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10962 | /* mode_set/enable/disable functions rely on a correct pipe |
| 10963 | * config. */ |
| 10964 | to_intel_crtc(crtc)->config = *pipe_config; |
Ville Syrjälä | 50741ab | 2014-01-10 11:28:07 +0200 | [diff] [blame] | 10965 | to_intel_crtc(crtc)->new_config = &to_intel_crtc(crtc)->config; |
Ville Syrjälä | c326c0a | 2013-10-28 12:53:41 +0200 | [diff] [blame] | 10966 | |
| 10967 | /* |
| 10968 | * Calculate and store various constants which |
| 10969 | * are later needed by vblank and swap-completion |
| 10970 | * timestamping. They are derived from true hwmode. |
| 10971 | */ |
| 10972 | drm_calc_timestamping_constants(crtc, |
| 10973 | &pipe_config->adjusted_mode); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10974 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10975 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10976 | /* Only after disabling all output pipelines that will be changed can we |
| 10977 | * update the the output configuration. */ |
| 10978 | intel_modeset_update_state(dev, prepare_pipes); |
| 10979 | |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 10980 | if (dev_priv->display.modeset_global_resources) |
| 10981 | dev_priv->display.modeset_global_resources(dev); |
| 10982 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 10983 | /* Set up the DPLL and any encoders state that needs to adjust or depend |
| 10984 | * on the DPLL. |
| 10985 | */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10986 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 10987 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
| 10988 | struct drm_i915_gem_object *old_obj = intel_fb_obj(old_fb); |
| 10989 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Daniel Vetter | 4c10794 | 2014-04-24 23:55:05 +0200 | [diff] [blame] | 10990 | |
| 10991 | mutex_lock(&dev->struct_mutex); |
| 10992 | ret = intel_pin_and_fence_fb_obj(dev, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10993 | obj, |
Daniel Vetter | 4c10794 | 2014-04-24 23:55:05 +0200 | [diff] [blame] | 10994 | NULL); |
| 10995 | if (ret != 0) { |
| 10996 | DRM_ERROR("pin & fence failed\n"); |
| 10997 | mutex_unlock(&dev->struct_mutex); |
| 10998 | goto done; |
| 10999 | } |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11000 | if (old_fb) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11001 | intel_unpin_fb_obj(old_obj); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11002 | i915_gem_track_fb(old_obj, obj, |
| 11003 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe)); |
Daniel Vetter | 4c10794 | 2014-04-24 23:55:05 +0200 | [diff] [blame] | 11004 | mutex_unlock(&dev->struct_mutex); |
| 11005 | |
| 11006 | crtc->primary->fb = fb; |
| 11007 | crtc->x = x; |
| 11008 | crtc->y = y; |
| 11009 | |
Daniel Vetter | 4271b75 | 2014-04-24 23:55:00 +0200 | [diff] [blame] | 11010 | ret = dev_priv->display.crtc_mode_set(&intel_crtc->base, |
| 11011 | x, y, fb); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11012 | if (ret) |
| 11013 | goto done; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11014 | } |
| 11015 | |
| 11016 | /* 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] | 11017 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
| 11018 | update_scanline_offset(intel_crtc); |
| 11019 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11020 | dev_priv->display.crtc_enable(&intel_crtc->base); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11021 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11022 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11023 | /* FIXME: add subpixel order */ |
| 11024 | done: |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11025 | if (ret && crtc->enabled) |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11026 | crtc->mode = *saved_mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11027 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11028 | out: |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11029 | kfree(pipe_config); |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11030 | kfree(saved_mode); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11031 | return ret; |
| 11032 | } |
| 11033 | |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 11034 | static int intel_set_mode(struct drm_crtc *crtc, |
| 11035 | struct drm_display_mode *mode, |
| 11036 | int x, int y, struct drm_framebuffer *fb) |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11037 | { |
| 11038 | int ret; |
| 11039 | |
| 11040 | ret = __intel_set_mode(crtc, mode, x, y, fb); |
| 11041 | |
| 11042 | if (ret == 0) |
| 11043 | intel_modeset_check_state(crtc->dev); |
| 11044 | |
| 11045 | return ret; |
| 11046 | } |
| 11047 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11048 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 11049 | { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11050 | 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] | 11051 | } |
| 11052 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11053 | #undef for_each_intel_crtc_masked |
| 11054 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11055 | static void intel_set_config_free(struct intel_set_config *config) |
| 11056 | { |
| 11057 | if (!config) |
| 11058 | return; |
| 11059 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11060 | kfree(config->save_connector_encoders); |
| 11061 | kfree(config->save_encoder_crtcs); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11062 | kfree(config->save_crtc_enabled); |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11063 | kfree(config); |
| 11064 | } |
| 11065 | |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11066 | static int intel_set_config_save_state(struct drm_device *dev, |
| 11067 | struct intel_set_config *config) |
| 11068 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11069 | struct drm_crtc *crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11070 | struct drm_encoder *encoder; |
| 11071 | struct drm_connector *connector; |
| 11072 | int count; |
| 11073 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11074 | config->save_crtc_enabled = |
| 11075 | kcalloc(dev->mode_config.num_crtc, |
| 11076 | sizeof(bool), GFP_KERNEL); |
| 11077 | if (!config->save_crtc_enabled) |
| 11078 | return -ENOMEM; |
| 11079 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11080 | config->save_encoder_crtcs = |
| 11081 | kcalloc(dev->mode_config.num_encoder, |
| 11082 | sizeof(struct drm_crtc *), GFP_KERNEL); |
| 11083 | if (!config->save_encoder_crtcs) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11084 | return -ENOMEM; |
| 11085 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11086 | config->save_connector_encoders = |
| 11087 | kcalloc(dev->mode_config.num_connector, |
| 11088 | sizeof(struct drm_encoder *), GFP_KERNEL); |
| 11089 | if (!config->save_connector_encoders) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11090 | return -ENOMEM; |
| 11091 | |
| 11092 | /* Copy data. Note that driver private data is not affected. |
| 11093 | * Should anything bad happen only the expected state is |
| 11094 | * restored, not the drivers personal bookkeeping. |
| 11095 | */ |
| 11096 | count = 0; |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 11097 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11098 | config->save_crtc_enabled[count++] = crtc->enabled; |
| 11099 | } |
| 11100 | |
| 11101 | count = 0; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11102 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11103 | config->save_encoder_crtcs[count++] = encoder->crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11104 | } |
| 11105 | |
| 11106 | count = 0; |
| 11107 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11108 | config->save_connector_encoders[count++] = connector->encoder; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11109 | } |
| 11110 | |
| 11111 | return 0; |
| 11112 | } |
| 11113 | |
| 11114 | static void intel_set_config_restore_state(struct drm_device *dev, |
| 11115 | struct intel_set_config *config) |
| 11116 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11117 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11118 | struct intel_encoder *encoder; |
| 11119 | struct intel_connector *connector; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11120 | int count; |
| 11121 | |
| 11122 | count = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11123 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11124 | crtc->new_enabled = config->save_crtc_enabled[count++]; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11125 | |
| 11126 | if (crtc->new_enabled) |
| 11127 | crtc->new_config = &crtc->config; |
| 11128 | else |
| 11129 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11130 | } |
| 11131 | |
| 11132 | count = 0; |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11133 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11134 | encoder->new_crtc = |
| 11135 | to_intel_crtc(config->save_encoder_crtcs[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11136 | } |
| 11137 | |
| 11138 | count = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11139 | list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) { |
| 11140 | connector->new_encoder = |
| 11141 | to_intel_encoder(config->save_connector_encoders[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11142 | } |
| 11143 | } |
| 11144 | |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11145 | static bool |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11146 | is_crtc_connector_off(struct drm_mode_set *set) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11147 | { |
| 11148 | int i; |
| 11149 | |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11150 | if (set->num_connectors == 0) |
| 11151 | return false; |
| 11152 | |
| 11153 | if (WARN_ON(set->connectors == NULL)) |
| 11154 | return false; |
| 11155 | |
| 11156 | for (i = 0; i < set->num_connectors; i++) |
| 11157 | if (set->connectors[i]->encoder && |
| 11158 | set->connectors[i]->encoder->crtc == set->crtc && |
| 11159 | set->connectors[i]->dpms != DRM_MODE_DPMS_ON) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11160 | return true; |
| 11161 | |
| 11162 | return false; |
| 11163 | } |
| 11164 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11165 | static void |
| 11166 | intel_set_config_compute_mode_changes(struct drm_mode_set *set, |
| 11167 | struct intel_set_config *config) |
| 11168 | { |
| 11169 | |
| 11170 | /* We should be able to check here if the fb has the same properties |
| 11171 | * and then just flip_or_move it */ |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11172 | if (is_crtc_connector_off(set)) { |
| 11173 | config->mode_changed = true; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11174 | } else if (set->crtc->primary->fb != set->fb) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11175 | /* |
| 11176 | * If we have no fb, we can only flip as long as the crtc is |
| 11177 | * active, otherwise we need a full mode set. The crtc may |
| 11178 | * be active if we've only disabled the primary plane, or |
| 11179 | * in fastboot situations. |
| 11180 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11181 | if (set->crtc->primary->fb == NULL) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 11182 | struct intel_crtc *intel_crtc = |
| 11183 | to_intel_crtc(set->crtc); |
| 11184 | |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11185 | if (intel_crtc->active) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 11186 | DRM_DEBUG_KMS("crtc has no fb, will flip\n"); |
| 11187 | config->fb_changed = true; |
| 11188 | } else { |
| 11189 | DRM_DEBUG_KMS("inactive crtc, full mode set\n"); |
| 11190 | config->mode_changed = true; |
| 11191 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11192 | } else if (set->fb == NULL) { |
| 11193 | config->mode_changed = true; |
Daniel Vetter | 72f4901 | 2013-03-28 16:01:35 +0100 | [diff] [blame] | 11194 | } else if (set->fb->pixel_format != |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11195 | set->crtc->primary->fb->pixel_format) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11196 | config->mode_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11197 | } else { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11198 | config->fb_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11199 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11200 | } |
| 11201 | |
Daniel Vetter | 835c587 | 2012-07-10 18:11:08 +0200 | [diff] [blame] | 11202 | 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] | 11203 | config->fb_changed = true; |
| 11204 | |
| 11205 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
| 11206 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
| 11207 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 11208 | drm_mode_debug_printmodeline(set->mode); |
| 11209 | config->mode_changed = true; |
| 11210 | } |
Chris Wilson | a1d9570 | 2013-08-13 18:48:47 +0100 | [diff] [blame] | 11211 | |
| 11212 | DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n", |
| 11213 | set->crtc->base.id, config->mode_changed, config->fb_changed); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11214 | } |
| 11215 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11216 | static int |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11217 | intel_modeset_stage_output_state(struct drm_device *dev, |
| 11218 | struct drm_mode_set *set, |
| 11219 | struct intel_set_config *config) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11220 | { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11221 | struct intel_connector *connector; |
| 11222 | struct intel_encoder *encoder; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11223 | struct intel_crtc *crtc; |
Paulo Zanoni | f3f0857 | 2013-08-12 14:56:53 -0300 | [diff] [blame] | 11224 | int ro; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11225 | |
Damien Lespiau | 9abdda7 | 2013-02-13 13:29:23 +0000 | [diff] [blame] | 11226 | /* 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] | 11227 | * of connectors. For paranoia, double-check this. */ |
| 11228 | WARN_ON(!set->fb && (set->num_connectors != 0)); |
| 11229 | WARN_ON(set->fb && (set->num_connectors == 0)); |
| 11230 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11231 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 11232 | base.head) { |
| 11233 | /* Otherwise traverse passed in connector list and get encoders |
| 11234 | * for them. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11235 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11236 | if (set->connectors[ro] == &connector->base) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11237 | 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] | 11238 | break; |
| 11239 | } |
| 11240 | } |
| 11241 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11242 | /* If we disable the crtc, disable all its connectors. Also, if |
| 11243 | * the connector is on the changing crtc but not on the new |
| 11244 | * connector list, disable it. */ |
| 11245 | if ((!set->fb || ro == set->num_connectors) && |
| 11246 | connector->base.encoder && |
| 11247 | connector->base.encoder->crtc == set->crtc) { |
| 11248 | connector->new_encoder = NULL; |
| 11249 | |
| 11250 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", |
| 11251 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11252 | connector->base.name); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11253 | } |
| 11254 | |
| 11255 | |
| 11256 | if (&connector->new_encoder->base != connector->base.encoder) { |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11257 | DRM_DEBUG_KMS("encoder changed, full mode switch\n"); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11258 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11259 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11260 | } |
| 11261 | /* connector->new_encoder is now updated for all connectors. */ |
| 11262 | |
| 11263 | /* Update crtc of enabled connectors. */ |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11264 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 11265 | base.head) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11266 | struct drm_crtc *new_crtc; |
| 11267 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11268 | if (!connector->new_encoder) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11269 | continue; |
| 11270 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11271 | new_crtc = connector->new_encoder->base.crtc; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11272 | |
| 11273 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11274 | if (set->connectors[ro] == &connector->base) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11275 | new_crtc = set->crtc; |
| 11276 | } |
| 11277 | |
| 11278 | /* Make sure the new CRTC will work with the encoder */ |
Thierry Reding | 1450991 | 2014-01-13 12:00:22 +0100 | [diff] [blame] | 11279 | if (!drm_encoder_crtc_ok(&connector->new_encoder->base, |
| 11280 | new_crtc)) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11281 | return -EINVAL; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11282 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11283 | connector->new_encoder->new_crtc = to_intel_crtc(new_crtc); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11284 | |
| 11285 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
| 11286 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11287 | connector->base.name, |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11288 | new_crtc->base.id); |
| 11289 | } |
| 11290 | |
| 11291 | /* Check for any encoders that needs to be disabled. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11292 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11293 | int num_connectors = 0; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11294 | list_for_each_entry(connector, |
| 11295 | &dev->mode_config.connector_list, |
| 11296 | base.head) { |
| 11297 | if (connector->new_encoder == encoder) { |
| 11298 | WARN_ON(!connector->new_encoder->new_crtc); |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11299 | num_connectors++; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11300 | } |
| 11301 | } |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11302 | |
| 11303 | if (num_connectors == 0) |
| 11304 | encoder->new_crtc = NULL; |
| 11305 | else if (num_connectors > 1) |
| 11306 | return -EINVAL; |
| 11307 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11308 | /* Only now check for crtc changes so we don't miss encoders |
| 11309 | * that will be disabled. */ |
| 11310 | if (&encoder->new_crtc->base != encoder->base.crtc) { |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11311 | DRM_DEBUG_KMS("crtc changed, full mode switch\n"); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11312 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11313 | } |
| 11314 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11315 | /* Now we've also updated encoder->new_crtc for all encoders. */ |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11316 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 11317 | base.head) { |
| 11318 | if (connector->new_encoder) |
| 11319 | if (connector->new_encoder != connector->encoder) |
| 11320 | connector->encoder = connector->new_encoder; |
| 11321 | } |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11322 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11323 | crtc->new_enabled = false; |
| 11324 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11325 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11326 | if (encoder->new_crtc == crtc) { |
| 11327 | crtc->new_enabled = true; |
| 11328 | break; |
| 11329 | } |
| 11330 | } |
| 11331 | |
| 11332 | if (crtc->new_enabled != crtc->base.enabled) { |
| 11333 | DRM_DEBUG_KMS("crtc %sabled, full mode switch\n", |
| 11334 | crtc->new_enabled ? "en" : "dis"); |
| 11335 | config->mode_changed = true; |
| 11336 | } |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11337 | |
| 11338 | if (crtc->new_enabled) |
| 11339 | crtc->new_config = &crtc->config; |
| 11340 | else |
| 11341 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11342 | } |
| 11343 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11344 | return 0; |
| 11345 | } |
| 11346 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11347 | static void disable_crtc_nofb(struct intel_crtc *crtc) |
| 11348 | { |
| 11349 | struct drm_device *dev = crtc->base.dev; |
| 11350 | struct intel_encoder *encoder; |
| 11351 | struct intel_connector *connector; |
| 11352 | |
| 11353 | DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n", |
| 11354 | pipe_name(crtc->pipe)); |
| 11355 | |
| 11356 | list_for_each_entry(connector, &dev->mode_config.connector_list, base.head) { |
| 11357 | if (connector->new_encoder && |
| 11358 | connector->new_encoder->new_crtc == crtc) |
| 11359 | connector->new_encoder = NULL; |
| 11360 | } |
| 11361 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11362 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11363 | if (encoder->new_crtc == crtc) |
| 11364 | encoder->new_crtc = NULL; |
| 11365 | } |
| 11366 | |
| 11367 | crtc->new_enabled = false; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11368 | crtc->new_config = NULL; |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11369 | } |
| 11370 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11371 | static int intel_crtc_set_config(struct drm_mode_set *set) |
| 11372 | { |
| 11373 | struct drm_device *dev; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11374 | struct drm_mode_set save_set; |
| 11375 | struct intel_set_config *config; |
| 11376 | int ret; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11377 | |
Daniel Vetter | 8d3e375 | 2012-07-05 16:09:09 +0200 | [diff] [blame] | 11378 | BUG_ON(!set); |
| 11379 | BUG_ON(!set->crtc); |
| 11380 | BUG_ON(!set->crtc->helper_private); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11381 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 11382 | /* Enforce sane interface api - has been abused by the fb helper. */ |
| 11383 | BUG_ON(!set->mode && set->fb); |
| 11384 | BUG_ON(set->fb && set->num_connectors == 0); |
Daniel Vetter | 431e50f | 2012-07-10 17:53:42 +0200 | [diff] [blame] | 11385 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11386 | if (set->fb) { |
| 11387 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", |
| 11388 | set->crtc->base.id, set->fb->base.id, |
| 11389 | (int)set->num_connectors, set->x, set->y); |
| 11390 | } else { |
| 11391 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11392 | } |
| 11393 | |
| 11394 | dev = set->crtc->dev; |
| 11395 | |
| 11396 | ret = -ENOMEM; |
| 11397 | config = kzalloc(sizeof(*config), GFP_KERNEL); |
| 11398 | if (!config) |
| 11399 | goto out_config; |
| 11400 | |
| 11401 | ret = intel_set_config_save_state(dev, config); |
| 11402 | if (ret) |
| 11403 | goto out_config; |
| 11404 | |
| 11405 | save_set.crtc = set->crtc; |
| 11406 | save_set.mode = &set->crtc->mode; |
| 11407 | save_set.x = set->crtc->x; |
| 11408 | save_set.y = set->crtc->y; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11409 | save_set.fb = set->crtc->primary->fb; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11410 | |
| 11411 | /* Compute whether we need a full modeset, only an fb base update or no |
| 11412 | * change at all. In the future we might also check whether only the |
| 11413 | * mode changed, e.g. for LVDS where we only change the panel fitter in |
| 11414 | * such cases. */ |
| 11415 | intel_set_config_compute_mode_changes(set, config); |
| 11416 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11417 | ret = intel_modeset_stage_output_state(dev, set, config); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11418 | if (ret) |
| 11419 | goto fail; |
| 11420 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11421 | if (config->mode_changed) { |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11422 | ret = intel_set_mode(set->crtc, set->mode, |
| 11423 | set->x, set->y, set->fb); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11424 | } else if (config->fb_changed) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11425 | struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc); |
| 11426 | |
Ville Syrjälä | 4878cae | 2013-02-18 19:08:48 +0200 | [diff] [blame] | 11427 | intel_crtc_wait_for_pending_flips(set->crtc); |
| 11428 | |
Daniel Vetter | 4f660f4 | 2012-07-02 09:47:37 +0200 | [diff] [blame] | 11429 | ret = intel_pipe_set_base(set->crtc, |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 11430 | set->x, set->y, set->fb); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11431 | |
| 11432 | /* |
| 11433 | * We need to make sure the primary plane is re-enabled if it |
| 11434 | * has previously been turned off. |
| 11435 | */ |
| 11436 | if (!intel_crtc->primary_enabled && ret == 0) { |
| 11437 | WARN_ON(!intel_crtc->active); |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 11438 | intel_enable_primary_hw_plane(set->crtc->primary, set->crtc); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11439 | } |
| 11440 | |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 11441 | /* |
| 11442 | * In the fastboot case this may be our only check of the |
| 11443 | * state after boot. It would be better to only do it on |
| 11444 | * the first update, but we don't have a nice way of doing that |
| 11445 | * (and really, set_config isn't used much for high freq page |
| 11446 | * flipping, so increasing its cost here shouldn't be a big |
| 11447 | * deal). |
| 11448 | */ |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 11449 | if (i915.fastboot && ret == 0) |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 11450 | intel_modeset_check_state(set->crtc->dev); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11451 | } |
| 11452 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 11453 | if (ret) { |
Daniel Vetter | bf67dfe | 2013-06-25 11:06:52 +0200 | [diff] [blame] | 11454 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
| 11455 | set->crtc->base.id, ret); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11456 | fail: |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 11457 | intel_set_config_restore_state(dev, config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11458 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11459 | /* |
| 11460 | * HACK: if the pipe was on, but we didn't have a framebuffer, |
| 11461 | * force the pipe off to avoid oopsing in the modeset code |
| 11462 | * due to fb==NULL. This should only happen during boot since |
| 11463 | * we don't yet reconstruct the FB from the hardware state. |
| 11464 | */ |
| 11465 | if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb) |
| 11466 | disable_crtc_nofb(to_intel_crtc(save_set.crtc)); |
| 11467 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 11468 | /* Try to restore the config */ |
| 11469 | if (config->mode_changed && |
| 11470 | intel_set_mode(save_set.crtc, save_set.mode, |
| 11471 | save_set.x, save_set.y, save_set.fb)) |
| 11472 | DRM_ERROR("failed to restore config after modeset failure\n"); |
| 11473 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11474 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11475 | out_config: |
| 11476 | intel_set_config_free(config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11477 | return ret; |
| 11478 | } |
| 11479 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11480 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11481 | .gamma_set = intel_crtc_gamma_set, |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11482 | .set_config = intel_crtc_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11483 | .destroy = intel_crtc_destroy, |
| 11484 | .page_flip = intel_crtc_page_flip, |
| 11485 | }; |
| 11486 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11487 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
| 11488 | struct intel_shared_dpll *pll, |
| 11489 | struct intel_dpll_hw_state *hw_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11490 | { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11491 | uint32_t val; |
| 11492 | |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 11493 | if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
| 11494 | return false; |
| 11495 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11496 | val = I915_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11497 | hw_state->dpll = val; |
| 11498 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); |
| 11499 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11500 | |
| 11501 | return val & DPLL_VCO_ENABLE; |
| 11502 | } |
| 11503 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11504 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
| 11505 | struct intel_shared_dpll *pll) |
| 11506 | { |
| 11507 | I915_WRITE(PCH_FP0(pll->id), pll->hw_state.fp0); |
| 11508 | I915_WRITE(PCH_FP1(pll->id), pll->hw_state.fp1); |
| 11509 | } |
| 11510 | |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11511 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
| 11512 | struct intel_shared_dpll *pll) |
| 11513 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11514 | /* PCH refclock must be enabled first */ |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 11515 | ibx_assert_pch_refclk_enabled(dev_priv); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11516 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11517 | I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll); |
| 11518 | |
| 11519 | /* Wait for the clocks to stabilize. */ |
| 11520 | POSTING_READ(PCH_DPLL(pll->id)); |
| 11521 | udelay(150); |
| 11522 | |
| 11523 | /* The pixel multiplier can only be updated once the |
| 11524 | * DPLL is enabled and the clocks are stable. |
| 11525 | * |
| 11526 | * So write it again. |
| 11527 | */ |
| 11528 | I915_WRITE(PCH_DPLL(pll->id), pll->hw_state.dpll); |
| 11529 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11530 | udelay(200); |
| 11531 | } |
| 11532 | |
| 11533 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, |
| 11534 | struct intel_shared_dpll *pll) |
| 11535 | { |
| 11536 | struct drm_device *dev = dev_priv->dev; |
| 11537 | struct intel_crtc *crtc; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11538 | |
| 11539 | /* Make sure no transcoder isn't still depending on us. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11540 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11541 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
| 11542 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); |
| 11543 | } |
| 11544 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11545 | I915_WRITE(PCH_DPLL(pll->id), 0); |
| 11546 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11547 | udelay(200); |
| 11548 | } |
| 11549 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 11550 | static char *ibx_pch_dpll_names[] = { |
| 11551 | "PCH DPLL A", |
| 11552 | "PCH DPLL B", |
| 11553 | }; |
| 11554 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11555 | static void ibx_pch_dpll_init(struct drm_device *dev) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11556 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11557 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11558 | int i; |
| 11559 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11560 | dev_priv->num_shared_dpll = 2; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11561 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 11562 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 11563 | dev_priv->shared_dplls[i].id = i; |
| 11564 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11565 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11566 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
| 11567 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11568 | dev_priv->shared_dplls[i].get_hw_state = |
| 11569 | ibx_pch_dpll_get_hw_state; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11570 | } |
| 11571 | } |
| 11572 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11573 | static void intel_shared_dpll_init(struct drm_device *dev) |
| 11574 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11575 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11576 | |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 11577 | if (HAS_DDI(dev)) |
| 11578 | intel_ddi_pll_init(dev); |
| 11579 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11580 | ibx_pch_dpll_init(dev); |
| 11581 | else |
| 11582 | dev_priv->num_shared_dpll = 0; |
| 11583 | |
| 11584 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11585 | } |
| 11586 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11587 | static int |
| 11588 | intel_primary_plane_disable(struct drm_plane *plane) |
| 11589 | { |
| 11590 | struct drm_device *dev = plane->dev; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11591 | struct intel_crtc *intel_crtc; |
| 11592 | |
| 11593 | if (!plane->fb) |
| 11594 | return 0; |
| 11595 | |
| 11596 | BUG_ON(!plane->crtc); |
| 11597 | |
| 11598 | intel_crtc = to_intel_crtc(plane->crtc); |
| 11599 | |
| 11600 | /* |
| 11601 | * Even though we checked plane->fb above, it's still possible that |
| 11602 | * the primary plane has been implicitly disabled because the crtc |
| 11603 | * coordinates given weren't visible, or because we detected |
| 11604 | * that it was 100% covered by a sprite plane. Or, the CRTC may be |
| 11605 | * off and we've set a fb, but haven't actually turned on the CRTC yet. |
| 11606 | * In either case, we need to unpin the FB and let the fb pointer get |
| 11607 | * updated, but otherwise we don't need to touch the hardware. |
| 11608 | */ |
| 11609 | if (!intel_crtc->primary_enabled) |
| 11610 | goto disable_unpin; |
| 11611 | |
| 11612 | intel_crtc_wait_for_pending_flips(plane->crtc); |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 11613 | intel_disable_primary_hw_plane(plane, plane->crtc); |
| 11614 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11615 | disable_unpin: |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11616 | mutex_lock(&dev->struct_mutex); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11617 | i915_gem_track_fb(intel_fb_obj(plane->fb), NULL, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11618 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe)); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11619 | intel_unpin_fb_obj(intel_fb_obj(plane->fb)); |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11620 | mutex_unlock(&dev->struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11621 | plane->fb = NULL; |
| 11622 | |
| 11623 | return 0; |
| 11624 | } |
| 11625 | |
| 11626 | static int |
| 11627 | intel_primary_plane_setplane(struct drm_plane *plane, struct drm_crtc *crtc, |
| 11628 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
| 11629 | unsigned int crtc_w, unsigned int crtc_h, |
| 11630 | uint32_t src_x, uint32_t src_y, |
| 11631 | uint32_t src_w, uint32_t src_h) |
| 11632 | { |
| 11633 | struct drm_device *dev = crtc->dev; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11634 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11635 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 11636 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 11637 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11638 | struct drm_rect dest = { |
| 11639 | /* integer pixels */ |
| 11640 | .x1 = crtc_x, |
| 11641 | .y1 = crtc_y, |
| 11642 | .x2 = crtc_x + crtc_w, |
| 11643 | .y2 = crtc_y + crtc_h, |
| 11644 | }; |
| 11645 | struct drm_rect src = { |
| 11646 | /* 16.16 fixed point */ |
| 11647 | .x1 = src_x, |
| 11648 | .y1 = src_y, |
| 11649 | .x2 = src_x + src_w, |
| 11650 | .y2 = src_y + src_h, |
| 11651 | }; |
| 11652 | const struct drm_rect clip = { |
| 11653 | /* integer pixels */ |
| 11654 | .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0, |
| 11655 | .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0, |
| 11656 | }; |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 11657 | const struct { |
| 11658 | int crtc_x, crtc_y; |
| 11659 | unsigned int crtc_w, crtc_h; |
| 11660 | uint32_t src_x, src_y, src_w, src_h; |
| 11661 | } orig = { |
| 11662 | .crtc_x = crtc_x, |
| 11663 | .crtc_y = crtc_y, |
| 11664 | .crtc_w = crtc_w, |
| 11665 | .crtc_h = crtc_h, |
| 11666 | .src_x = src_x, |
| 11667 | .src_y = src_y, |
| 11668 | .src_w = src_w, |
| 11669 | .src_h = src_h, |
| 11670 | }; |
| 11671 | struct intel_plane *intel_plane = to_intel_plane(plane); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11672 | bool visible; |
| 11673 | int ret; |
| 11674 | |
| 11675 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
| 11676 | &src, &dest, &clip, |
| 11677 | DRM_PLANE_HELPER_NO_SCALING, |
| 11678 | DRM_PLANE_HELPER_NO_SCALING, |
| 11679 | false, true, &visible); |
| 11680 | |
| 11681 | if (ret) |
| 11682 | return ret; |
| 11683 | |
| 11684 | /* |
| 11685 | * If the CRTC isn't enabled, we're just pinning the framebuffer, |
| 11686 | * updating the fb pointer, and returning without touching the |
| 11687 | * hardware. This allows us to later do a drmModeSetCrtc with fb=-1 to |
| 11688 | * turn on the display with all planes setup as desired. |
| 11689 | */ |
| 11690 | if (!crtc->enabled) { |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11691 | mutex_lock(&dev->struct_mutex); |
| 11692 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11693 | /* |
| 11694 | * If we already called setplane while the crtc was disabled, |
| 11695 | * we may have an fb pinned; unpin it. |
| 11696 | */ |
| 11697 | if (plane->fb) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11698 | intel_unpin_fb_obj(old_obj); |
| 11699 | |
| 11700 | i915_gem_track_fb(old_obj, obj, |
| 11701 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe)); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11702 | |
| 11703 | /* Pin and return without programming hardware */ |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11704 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
| 11705 | mutex_unlock(&dev->struct_mutex); |
| 11706 | |
| 11707 | return ret; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11708 | } |
| 11709 | |
| 11710 | intel_crtc_wait_for_pending_flips(crtc); |
| 11711 | |
| 11712 | /* |
| 11713 | * If clipping results in a non-visible primary plane, we'll disable |
| 11714 | * the primary plane. Note that this is a bit different than what |
| 11715 | * happens if userspace explicitly disables the plane by passing fb=0 |
| 11716 | * because plane->fb still gets set and pinned. |
| 11717 | */ |
| 11718 | if (!visible) { |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11719 | mutex_lock(&dev->struct_mutex); |
| 11720 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11721 | /* |
| 11722 | * Try to pin the new fb first so that we can bail out if we |
| 11723 | * fail. |
| 11724 | */ |
| 11725 | if (plane->fb != fb) { |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11726 | ret = intel_pin_and_fence_fb_obj(dev, obj, NULL); |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11727 | if (ret) { |
| 11728 | mutex_unlock(&dev->struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11729 | return ret; |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11730 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11731 | } |
| 11732 | |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11733 | i915_gem_track_fb(old_obj, obj, |
| 11734 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe)); |
| 11735 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11736 | if (intel_crtc->primary_enabled) |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 11737 | intel_disable_primary_hw_plane(plane, crtc); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11738 | |
| 11739 | |
| 11740 | if (plane->fb != fb) |
| 11741 | if (plane->fb) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 11742 | intel_unpin_fb_obj(old_obj); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11743 | |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 11744 | mutex_unlock(&dev->struct_mutex); |
| 11745 | |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 11746 | } else { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11747 | if (intel_crtc && intel_crtc->active && |
| 11748 | intel_crtc->primary_enabled) { |
| 11749 | /* |
| 11750 | * FBC does not work on some platforms for rotated |
| 11751 | * planes, so disable it when rotation is not 0 and |
| 11752 | * update it when rotation is set back to 0. |
| 11753 | * |
| 11754 | * FIXME: This is redundant with the fbc update done in |
| 11755 | * the primary plane enable function except that that |
| 11756 | * one is done too late. We eventually need to unify |
| 11757 | * this. |
| 11758 | */ |
| 11759 | if (INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
| 11760 | dev_priv->fbc.plane == intel_crtc->plane && |
| 11761 | intel_plane->rotation != BIT(DRM_ROTATE_0)) { |
| 11762 | intel_disable_fbc(dev); |
| 11763 | } |
| 11764 | } |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 11765 | ret = intel_pipe_set_base(crtc, src.x1, src.y1, fb); |
| 11766 | if (ret) |
| 11767 | return ret; |
| 11768 | |
| 11769 | if (!intel_crtc->primary_enabled) |
| 11770 | intel_enable_primary_hw_plane(plane, crtc); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11771 | } |
| 11772 | |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 11773 | intel_plane->crtc_x = orig.crtc_x; |
| 11774 | intel_plane->crtc_y = orig.crtc_y; |
| 11775 | intel_plane->crtc_w = orig.crtc_w; |
| 11776 | intel_plane->crtc_h = orig.crtc_h; |
| 11777 | intel_plane->src_x = orig.src_x; |
| 11778 | intel_plane->src_y = orig.src_y; |
| 11779 | intel_plane->src_w = orig.src_w; |
| 11780 | intel_plane->src_h = orig.src_h; |
| 11781 | intel_plane->obj = obj; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11782 | |
| 11783 | return 0; |
| 11784 | } |
| 11785 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11786 | /* Common destruction function for both primary and cursor planes */ |
| 11787 | static void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11788 | { |
| 11789 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 11790 | drm_plane_cleanup(plane); |
| 11791 | kfree(intel_plane); |
| 11792 | } |
| 11793 | |
| 11794 | static const struct drm_plane_funcs intel_primary_plane_funcs = { |
| 11795 | .update_plane = intel_primary_plane_setplane, |
| 11796 | .disable_plane = intel_primary_plane_disable, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11797 | .destroy = intel_plane_destroy, |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11798 | .set_property = intel_plane_set_property |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11799 | }; |
| 11800 | |
| 11801 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 11802 | int pipe) |
| 11803 | { |
| 11804 | struct intel_plane *primary; |
| 11805 | const uint32_t *intel_primary_formats; |
| 11806 | int num_formats; |
| 11807 | |
| 11808 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
| 11809 | if (primary == NULL) |
| 11810 | return NULL; |
| 11811 | |
| 11812 | primary->can_scale = false; |
| 11813 | primary->max_downscale = 1; |
| 11814 | primary->pipe = pipe; |
| 11815 | primary->plane = pipe; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11816 | primary->rotation = BIT(DRM_ROTATE_0); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11817 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 11818 | primary->plane = !pipe; |
| 11819 | |
| 11820 | if (INTEL_INFO(dev)->gen <= 3) { |
| 11821 | intel_primary_formats = intel_primary_formats_gen2; |
| 11822 | num_formats = ARRAY_SIZE(intel_primary_formats_gen2); |
| 11823 | } else { |
| 11824 | intel_primary_formats = intel_primary_formats_gen4; |
| 11825 | num_formats = ARRAY_SIZE(intel_primary_formats_gen4); |
| 11826 | } |
| 11827 | |
| 11828 | drm_universal_plane_init(dev, &primary->base, 0, |
| 11829 | &intel_primary_plane_funcs, |
| 11830 | intel_primary_formats, num_formats, |
| 11831 | DRM_PLANE_TYPE_PRIMARY); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 11832 | |
| 11833 | if (INTEL_INFO(dev)->gen >= 4) { |
| 11834 | if (!dev->mode_config.rotation_property) |
| 11835 | dev->mode_config.rotation_property = |
| 11836 | drm_mode_create_rotation_property(dev, |
| 11837 | BIT(DRM_ROTATE_0) | |
| 11838 | BIT(DRM_ROTATE_180)); |
| 11839 | if (dev->mode_config.rotation_property) |
| 11840 | drm_object_attach_property(&primary->base.base, |
| 11841 | dev->mode_config.rotation_property, |
| 11842 | primary->rotation); |
| 11843 | } |
| 11844 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11845 | return &primary->base; |
| 11846 | } |
| 11847 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11848 | static int |
| 11849 | intel_cursor_plane_disable(struct drm_plane *plane) |
| 11850 | { |
| 11851 | if (!plane->fb) |
| 11852 | return 0; |
| 11853 | |
| 11854 | BUG_ON(!plane->crtc); |
| 11855 | |
| 11856 | return intel_crtc_cursor_set_obj(plane->crtc, NULL, 0, 0); |
| 11857 | } |
| 11858 | |
| 11859 | static int |
| 11860 | intel_cursor_plane_update(struct drm_plane *plane, struct drm_crtc *crtc, |
| 11861 | struct drm_framebuffer *fb, int crtc_x, int crtc_y, |
| 11862 | unsigned int crtc_w, unsigned int crtc_h, |
| 11863 | uint32_t src_x, uint32_t src_y, |
| 11864 | uint32_t src_w, uint32_t src_h) |
| 11865 | { |
| 11866 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11867 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 11868 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 11869 | struct drm_rect dest = { |
| 11870 | /* integer pixels */ |
| 11871 | .x1 = crtc_x, |
| 11872 | .y1 = crtc_y, |
| 11873 | .x2 = crtc_x + crtc_w, |
| 11874 | .y2 = crtc_y + crtc_h, |
| 11875 | }; |
| 11876 | struct drm_rect src = { |
| 11877 | /* 16.16 fixed point */ |
| 11878 | .x1 = src_x, |
| 11879 | .y1 = src_y, |
| 11880 | .x2 = src_x + src_w, |
| 11881 | .y2 = src_y + src_h, |
| 11882 | }; |
| 11883 | const struct drm_rect clip = { |
| 11884 | /* integer pixels */ |
Ville Syrjälä | 1add143 | 2014-08-12 19:39:52 +0300 | [diff] [blame] | 11885 | .x2 = intel_crtc->active ? intel_crtc->config.pipe_src_w : 0, |
| 11886 | .y2 = intel_crtc->active ? intel_crtc->config.pipe_src_h : 0, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11887 | }; |
| 11888 | bool visible; |
| 11889 | int ret; |
| 11890 | |
| 11891 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
| 11892 | &src, &dest, &clip, |
| 11893 | DRM_PLANE_HELPER_NO_SCALING, |
| 11894 | DRM_PLANE_HELPER_NO_SCALING, |
| 11895 | true, true, &visible); |
| 11896 | if (ret) |
| 11897 | return ret; |
| 11898 | |
| 11899 | crtc->cursor_x = crtc_x; |
| 11900 | crtc->cursor_y = crtc_y; |
| 11901 | if (fb != crtc->cursor->fb) { |
| 11902 | return intel_crtc_cursor_set_obj(crtc, obj, crtc_w, crtc_h); |
| 11903 | } else { |
| 11904 | intel_crtc_update_cursor(crtc, visible); |
Daniel Vetter | 4ed9109 | 2014-08-08 20:27:01 +0200 | [diff] [blame] | 11905 | |
| 11906 | intel_frontbuffer_flip(crtc->dev, |
| 11907 | INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe)); |
| 11908 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11909 | return 0; |
| 11910 | } |
| 11911 | } |
| 11912 | static const struct drm_plane_funcs intel_cursor_plane_funcs = { |
| 11913 | .update_plane = intel_cursor_plane_update, |
| 11914 | .disable_plane = intel_cursor_plane_disable, |
| 11915 | .destroy = intel_plane_destroy, |
| 11916 | }; |
| 11917 | |
| 11918 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 11919 | int pipe) |
| 11920 | { |
| 11921 | struct intel_plane *cursor; |
| 11922 | |
| 11923 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
| 11924 | if (cursor == NULL) |
| 11925 | return NULL; |
| 11926 | |
| 11927 | cursor->can_scale = false; |
| 11928 | cursor->max_downscale = 1; |
| 11929 | cursor->pipe = pipe; |
| 11930 | cursor->plane = pipe; |
| 11931 | |
| 11932 | drm_universal_plane_init(dev, &cursor->base, 0, |
| 11933 | &intel_cursor_plane_funcs, |
| 11934 | intel_cursor_formats, |
| 11935 | ARRAY_SIZE(intel_cursor_formats), |
| 11936 | DRM_PLANE_TYPE_CURSOR); |
| 11937 | return &cursor->base; |
| 11938 | } |
| 11939 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 11940 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11941 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11942 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11943 | struct intel_crtc *intel_crtc; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11944 | struct drm_plane *primary = NULL; |
| 11945 | struct drm_plane *cursor = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11946 | int i, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11947 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 11948 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11949 | if (intel_crtc == NULL) |
| 11950 | return; |
| 11951 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11952 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11953 | if (!primary) |
| 11954 | goto fail; |
| 11955 | |
| 11956 | cursor = intel_cursor_plane_create(dev, pipe); |
| 11957 | if (!cursor) |
| 11958 | goto fail; |
| 11959 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11960 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11961 | cursor, &intel_crtc_funcs); |
| 11962 | if (ret) |
| 11963 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11964 | |
| 11965 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11966 | for (i = 0; i < 256; i++) { |
| 11967 | intel_crtc->lut_r[i] = i; |
| 11968 | intel_crtc->lut_g[i] = i; |
| 11969 | intel_crtc->lut_b[i] = i; |
| 11970 | } |
| 11971 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 11972 | /* |
| 11973 | * 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] | 11974 | * 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] | 11975 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 11976 | intel_crtc->pipe = pipe; |
| 11977 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 11978 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 11979 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 11980 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 11981 | } |
| 11982 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 11983 | intel_crtc->cursor_base = ~0; |
| 11984 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 11985 | intel_crtc->cursor_size = ~0; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 11986 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 11987 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 11988 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 11989 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 11990 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 11991 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 11992 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 11993 | |
| 11994 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 11995 | return; |
| 11996 | |
| 11997 | fail: |
| 11998 | if (primary) |
| 11999 | drm_plane_cleanup(primary); |
| 12000 | if (cursor) |
| 12001 | drm_plane_cleanup(cursor); |
| 12002 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12003 | } |
| 12004 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12005 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 12006 | { |
| 12007 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 12008 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12009 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 12010 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12011 | |
| 12012 | if (!encoder) |
| 12013 | return INVALID_PIPE; |
| 12014 | |
| 12015 | return to_intel_crtc(encoder->crtc)->pipe; |
| 12016 | } |
| 12017 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12018 | 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] | 12019 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12020 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12021 | 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] | 12022 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12023 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12024 | |
Daniel Vetter | 1cff8f6 | 2012-04-24 09:55:08 +0200 | [diff] [blame] | 12025 | if (!drm_core_check_feature(dev, DRIVER_MODESET)) |
| 12026 | return -ENODEV; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12027 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12028 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12029 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12030 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12031 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 12032 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12033 | } |
| 12034 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12035 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12036 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12037 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12038 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12039 | } |
| 12040 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12041 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12042 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12043 | struct drm_device *dev = encoder->base.dev; |
| 12044 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12045 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12046 | int entry = 0; |
| 12047 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12048 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 12049 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12050 | index_mask |= (1 << entry); |
| 12051 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12052 | entry++; |
| 12053 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12054 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12055 | return index_mask; |
| 12056 | } |
| 12057 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 12058 | static bool has_edp_a(struct drm_device *dev) |
| 12059 | { |
| 12060 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12061 | |
| 12062 | if (!IS_MOBILE(dev)) |
| 12063 | return false; |
| 12064 | |
| 12065 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 12066 | return false; |
| 12067 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 12068 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 12069 | return false; |
| 12070 | |
| 12071 | return true; |
| 12072 | } |
| 12073 | |
Damien Lespiau | ba0fbca | 2014-01-08 14:18:23 +0000 | [diff] [blame] | 12074 | const char *intel_output_name(int output) |
| 12075 | { |
| 12076 | static const char *names[] = { |
| 12077 | [INTEL_OUTPUT_UNUSED] = "Unused", |
| 12078 | [INTEL_OUTPUT_ANALOG] = "Analog", |
| 12079 | [INTEL_OUTPUT_DVO] = "DVO", |
| 12080 | [INTEL_OUTPUT_SDVO] = "SDVO", |
| 12081 | [INTEL_OUTPUT_LVDS] = "LVDS", |
| 12082 | [INTEL_OUTPUT_TVOUT] = "TV", |
| 12083 | [INTEL_OUTPUT_HDMI] = "HDMI", |
| 12084 | [INTEL_OUTPUT_DISPLAYPORT] = "DisplayPort", |
| 12085 | [INTEL_OUTPUT_EDP] = "eDP", |
| 12086 | [INTEL_OUTPUT_DSI] = "DSI", |
| 12087 | [INTEL_OUTPUT_UNKNOWN] = "Unknown", |
| 12088 | }; |
| 12089 | |
| 12090 | if (output < 0 || output >= ARRAY_SIZE(names) || !names[output]) |
| 12091 | return "Invalid"; |
| 12092 | |
| 12093 | return names[output]; |
| 12094 | } |
| 12095 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 12096 | static bool intel_crt_present(struct drm_device *dev) |
| 12097 | { |
| 12098 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12099 | |
| 12100 | if (IS_ULT(dev)) |
| 12101 | return false; |
| 12102 | |
| 12103 | if (IS_CHERRYVIEW(dev)) |
| 12104 | return false; |
| 12105 | |
| 12106 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) |
| 12107 | return false; |
| 12108 | |
| 12109 | return true; |
| 12110 | } |
| 12111 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12112 | static void intel_setup_outputs(struct drm_device *dev) |
| 12113 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 12114 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12115 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12116 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12117 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 12118 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12119 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 12120 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 12121 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12122 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 12123 | if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 12124 | int found; |
| 12125 | |
| 12126 | /* Haswell uses DDI functions to detect digital outputs */ |
| 12127 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
| 12128 | /* DDI A only supports eDP */ |
| 12129 | if (found) |
| 12130 | intel_ddi_init(dev, PORT_A); |
| 12131 | |
| 12132 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 12133 | * register */ |
| 12134 | found = I915_READ(SFUSE_STRAP); |
| 12135 | |
| 12136 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 12137 | intel_ddi_init(dev, PORT_B); |
| 12138 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 12139 | intel_ddi_init(dev, PORT_C); |
| 12140 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 12141 | intel_ddi_init(dev, PORT_D); |
| 12142 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12143 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 12144 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 12145 | |
| 12146 | if (has_edp_a(dev)) |
| 12147 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12148 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 12149 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 12150 | /* PCH SDVOB multiplex with HDMIB */ |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 12151 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12152 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12153 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 12154 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12155 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12156 | } |
| 12157 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 12158 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12159 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12160 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 12161 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12162 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12163 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 12164 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12165 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 12166 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 12167 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12168 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 12169 | } else if (IS_VALLEYVIEW(dev)) { |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 12170 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED) { |
| 12171 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
| 12172 | PORT_B); |
| 12173 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED) |
| 12174 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); |
| 12175 | } |
| 12176 | |
Jesse Barnes | 6f6005a | 2013-08-09 09:34:35 -0700 | [diff] [blame] | 12177 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED) { |
| 12178 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
| 12179 | PORT_C); |
| 12180 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED) |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 12181 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); |
Jesse Barnes | 6f6005a | 2013-08-09 09:34:35 -0700 | [diff] [blame] | 12182 | } |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 12183 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 12184 | if (IS_CHERRYVIEW(dev)) { |
| 12185 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) { |
| 12186 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
| 12187 | PORT_D); |
| 12188 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) |
| 12189 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); |
| 12190 | } |
| 12191 | } |
| 12192 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 12193 | intel_dsi_init(dev); |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 12194 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12195 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 12196 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12197 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12198 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12199 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12200 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 12201 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12202 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12203 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12204 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 12205 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12206 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 12207 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 12208 | |
| 12209 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 12210 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12211 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12212 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12213 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12214 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12215 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12216 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12217 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12218 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 12219 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12220 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12221 | } |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 12222 | if (SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12223 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 12224 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12225 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12226 | if (SUPPORTS_INTEGRATED_DP(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 12227 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12228 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 12229 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12230 | intel_dvo_init(dev); |
| 12231 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 12232 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12233 | intel_tv_init(dev); |
| 12234 | |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 12235 | intel_edp_psr_init(dev); |
| 12236 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12237 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12238 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 12239 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12240 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12241 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 12242 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 12243 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 12244 | |
| 12245 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12246 | } |
| 12247 | |
| 12248 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 12249 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 12250 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12251 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12252 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 12253 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 12254 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 12255 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 12256 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 12257 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12258 | kfree(intel_fb); |
| 12259 | } |
| 12260 | |
| 12261 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12262 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12263 | unsigned int *handle) |
| 12264 | { |
| 12265 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12266 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12267 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12268 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12269 | } |
| 12270 | |
| 12271 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 12272 | .destroy = intel_user_framebuffer_destroy, |
| 12273 | .create_handle = intel_user_framebuffer_create_handle, |
| 12274 | }; |
| 12275 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 12276 | static int intel_framebuffer_init(struct drm_device *dev, |
| 12277 | struct intel_framebuffer *intel_fb, |
| 12278 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 12279 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12280 | { |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 12281 | int aligned_height; |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 12282 | int pitch_limit; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12283 | int ret; |
| 12284 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 12285 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 12286 | |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12287 | if (obj->tiling_mode == I915_TILING_Y) { |
| 12288 | DRM_DEBUG("hardware does not support tiling Y\n"); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12289 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12290 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12291 | |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12292 | if (mode_cmd->pitches[0] & 63) { |
| 12293 | DRM_DEBUG("pitch (%d) must be at least 64 byte aligned\n", |
| 12294 | mode_cmd->pitches[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12295 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12296 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12297 | |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 12298 | if (INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev)) { |
| 12299 | pitch_limit = 32*1024; |
| 12300 | } else if (INTEL_INFO(dev)->gen >= 4) { |
| 12301 | if (obj->tiling_mode) |
| 12302 | pitch_limit = 16*1024; |
| 12303 | else |
| 12304 | pitch_limit = 32*1024; |
| 12305 | } else if (INTEL_INFO(dev)->gen >= 3) { |
| 12306 | if (obj->tiling_mode) |
| 12307 | pitch_limit = 8*1024; |
| 12308 | else |
| 12309 | pitch_limit = 16*1024; |
| 12310 | } else |
| 12311 | /* XXX DSPC is limited to 4k tiled */ |
| 12312 | pitch_limit = 8*1024; |
| 12313 | |
| 12314 | if (mode_cmd->pitches[0] > pitch_limit) { |
| 12315 | DRM_DEBUG("%s pitch (%d) must be at less than %d\n", |
| 12316 | obj->tiling_mode ? "tiled" : "linear", |
| 12317 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12318 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12319 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12320 | |
| 12321 | if (obj->tiling_mode != I915_TILING_NONE && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12322 | mode_cmd->pitches[0] != obj->stride) { |
| 12323 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 12324 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12325 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12326 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12327 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12328 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 12329 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12330 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 12331 | case DRM_FORMAT_RGB565: |
| 12332 | case DRM_FORMAT_XRGB8888: |
| 12333 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12334 | break; |
| 12335 | case DRM_FORMAT_XRGB1555: |
| 12336 | case DRM_FORMAT_ARGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12337 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12338 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12339 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12340 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12341 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12342 | break; |
| 12343 | case DRM_FORMAT_XBGR8888: |
| 12344 | case DRM_FORMAT_ABGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 12345 | case DRM_FORMAT_XRGB2101010: |
| 12346 | case DRM_FORMAT_ARGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12347 | case DRM_FORMAT_XBGR2101010: |
| 12348 | case DRM_FORMAT_ABGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12349 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12350 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12351 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12352 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12353 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 12354 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 12355 | case DRM_FORMAT_YUYV: |
| 12356 | case DRM_FORMAT_UYVY: |
| 12357 | case DRM_FORMAT_YVYU: |
| 12358 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12359 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12360 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12361 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12362 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12363 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12364 | break; |
| 12365 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12366 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12367 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12368 | return -EINVAL; |
| 12369 | } |
| 12370 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 12371 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 12372 | if (mode_cmd->offsets[0] != 0) |
| 12373 | return -EINVAL; |
| 12374 | |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 12375 | aligned_height = intel_align_height(dev, mode_cmd->height, |
| 12376 | obj->tiling_mode); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 12377 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 12378 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 12379 | return -EINVAL; |
| 12380 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 12381 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 12382 | intel_fb->obj = obj; |
Daniel Vetter | 80075d4 | 2013-10-09 21:23:52 +0200 | [diff] [blame] | 12383 | intel_fb->obj->framebuffer_references++; |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 12384 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12385 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 12386 | if (ret) { |
| 12387 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 12388 | return ret; |
| 12389 | } |
| 12390 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12391 | return 0; |
| 12392 | } |
| 12393 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12394 | static struct drm_framebuffer * |
| 12395 | intel_user_framebuffer_create(struct drm_device *dev, |
| 12396 | struct drm_file *filp, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 12397 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12398 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12399 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12400 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 12401 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
| 12402 | mode_cmd->handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 12403 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 12404 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12405 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 12406 | return intel_framebuffer_create(dev, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12407 | } |
| 12408 | |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 12409 | #ifndef CONFIG_DRM_I915_FBDEV |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 12410 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 12411 | { |
| 12412 | } |
| 12413 | #endif |
| 12414 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12415 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12416 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 12417 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12418 | }; |
| 12419 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12420 | /* Set up chip specific display functions */ |
| 12421 | static void intel_init_display(struct drm_device *dev) |
| 12422 | { |
| 12423 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12424 | |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 12425 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
| 12426 | dev_priv->display.find_dpll = g4x_find_best_dpll; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 12427 | else if (IS_CHERRYVIEW(dev)) |
| 12428 | dev_priv->display.find_dpll = chv_find_best_dpll; |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 12429 | else if (IS_VALLEYVIEW(dev)) |
| 12430 | dev_priv->display.find_dpll = vlv_find_best_dpll; |
| 12431 | else if (IS_PINEVIEW(dev)) |
| 12432 | dev_priv->display.find_dpll = pnv_find_best_dpll; |
| 12433 | else |
| 12434 | dev_priv->display.find_dpll = i9xx_find_best_dpll; |
| 12435 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 12436 | if (HAS_DDI(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12437 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 12438 | dev_priv->display.get_plane_config = ironlake_get_plane_config; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 12439 | dev_priv->display.crtc_mode_set = haswell_crtc_mode_set; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 12440 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 12441 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 12442 | dev_priv->display.off = ironlake_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 12443 | dev_priv->display.update_primary_plane = |
| 12444 | ironlake_update_primary_plane; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 12445 | } else if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12446 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 12447 | dev_priv->display.get_plane_config = ironlake_get_plane_config; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 12448 | dev_priv->display.crtc_mode_set = ironlake_crtc_mode_set; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 12449 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 12450 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12451 | dev_priv->display.off = ironlake_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 12452 | dev_priv->display.update_primary_plane = |
| 12453 | ironlake_update_primary_plane; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 12454 | } else if (IS_VALLEYVIEW(dev)) { |
| 12455 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 12456 | dev_priv->display.get_plane_config = i9xx_get_plane_config; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 12457 | dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; |
| 12458 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 12459 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 12460 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 12461 | dev_priv->display.update_primary_plane = |
| 12462 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 12463 | } else { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 12464 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 12465 | dev_priv->display.get_plane_config = i9xx_get_plane_config; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 12466 | dev_priv->display.crtc_mode_set = i9xx_crtc_mode_set; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 12467 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 12468 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12469 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 12470 | dev_priv->display.update_primary_plane = |
| 12471 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 12472 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12473 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12474 | /* Returns the core display clock speed */ |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 12475 | if (IS_VALLEYVIEW(dev)) |
| 12476 | dev_priv->display.get_display_clock_speed = |
| 12477 | valleyview_get_display_clock_speed; |
| 12478 | else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev))) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12479 | dev_priv->display.get_display_clock_speed = |
| 12480 | i945_get_display_clock_speed; |
| 12481 | else if (IS_I915G(dev)) |
| 12482 | dev_priv->display.get_display_clock_speed = |
| 12483 | i915_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 12484 | else if (IS_I945GM(dev) || IS_845G(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12485 | dev_priv->display.get_display_clock_speed = |
| 12486 | i9xx_misc_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 12487 | else if (IS_PINEVIEW(dev)) |
| 12488 | dev_priv->display.get_display_clock_speed = |
| 12489 | pnv_get_display_clock_speed; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12490 | else if (IS_I915GM(dev)) |
| 12491 | dev_priv->display.get_display_clock_speed = |
| 12492 | i915gm_get_display_clock_speed; |
| 12493 | else if (IS_I865G(dev)) |
| 12494 | dev_priv->display.get_display_clock_speed = |
| 12495 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 12496 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12497 | dev_priv->display.get_display_clock_speed = |
| 12498 | i855_get_display_clock_speed; |
| 12499 | else /* 852, 830 */ |
| 12500 | dev_priv->display.get_display_clock_speed = |
| 12501 | i830_get_display_clock_speed; |
| 12502 | |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 12503 | if (IS_G4X(dev)) { |
Wu Fengguang | e0dac65 | 2011-09-05 14:25:34 +0800 | [diff] [blame] | 12504 | dev_priv->display.write_eld = g4x_write_eld; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 12505 | } else if (IS_GEN5(dev)) { |
| 12506 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
| 12507 | dev_priv->display.write_eld = ironlake_write_eld; |
| 12508 | } else if (IS_GEN6(dev)) { |
| 12509 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
| 12510 | dev_priv->display.write_eld = ironlake_write_eld; |
| 12511 | dev_priv->display.modeset_global_resources = |
| 12512 | snb_modeset_global_resources; |
| 12513 | } else if (IS_IVYBRIDGE(dev)) { |
| 12514 | /* FIXME: detect B0+ stepping and use auto training */ |
| 12515 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
| 12516 | dev_priv->display.write_eld = ironlake_write_eld; |
| 12517 | dev_priv->display.modeset_global_resources = |
| 12518 | ivb_modeset_global_resources; |
| 12519 | } else if (IS_HASWELL(dev) || IS_GEN8(dev)) { |
| 12520 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
| 12521 | dev_priv->display.write_eld = haswell_write_eld; |
| 12522 | dev_priv->display.modeset_global_resources = |
| 12523 | haswell_modeset_global_resources; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 12524 | } else if (IS_VALLEYVIEW(dev)) { |
| 12525 | dev_priv->display.modeset_global_resources = |
| 12526 | valleyview_modeset_global_resources; |
Mengdong Lin | 9ca2fe7 | 2013-11-01 00:17:03 -0400 | [diff] [blame] | 12527 | dev_priv->display.write_eld = ironlake_write_eld; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12528 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 12529 | |
| 12530 | /* Default just returns -ENODEV to indicate unsupported */ |
| 12531 | dev_priv->display.queue_flip = intel_default_queue_flip; |
| 12532 | |
| 12533 | switch (INTEL_INFO(dev)->gen) { |
| 12534 | case 2: |
| 12535 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 12536 | break; |
| 12537 | |
| 12538 | case 3: |
| 12539 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 12540 | break; |
| 12541 | |
| 12542 | case 4: |
| 12543 | case 5: |
| 12544 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 12545 | break; |
| 12546 | |
| 12547 | case 6: |
| 12548 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 12549 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 12550 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 12551 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 12552 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 12553 | break; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 12554 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 12555 | |
| 12556 | intel_panel_init_backlight_funcs(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12557 | } |
| 12558 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12559 | /* |
| 12560 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 12561 | * resume, or other times. This quirk makes sure that's the case for |
| 12562 | * affected systems. |
| 12563 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 12564 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12565 | { |
| 12566 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12567 | |
| 12568 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 12569 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12570 | } |
| 12571 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame^] | 12572 | static void quirk_pipeb_force(struct drm_device *dev) |
| 12573 | { |
| 12574 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12575 | |
| 12576 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 12577 | DRM_INFO("applying pipe b force quirk\n"); |
| 12578 | } |
| 12579 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 12580 | /* |
| 12581 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 12582 | */ |
| 12583 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 12584 | { |
| 12585 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12586 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 12587 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 12588 | } |
| 12589 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 12590 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 12591 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 12592 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 12593 | */ |
| 12594 | static void quirk_invert_brightness(struct drm_device *dev) |
| 12595 | { |
| 12596 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12597 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 12598 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12599 | } |
| 12600 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 12601 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 12602 | static void quirk_backlight_present(struct drm_device *dev) |
| 12603 | { |
| 12604 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12605 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 12606 | DRM_INFO("applying backlight present quirk\n"); |
| 12607 | } |
| 12608 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12609 | struct intel_quirk { |
| 12610 | int device; |
| 12611 | int subsystem_vendor; |
| 12612 | int subsystem_device; |
| 12613 | void (*hook)(struct drm_device *dev); |
| 12614 | }; |
| 12615 | |
Egbert Eich | 5f85f176 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 12616 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 12617 | struct intel_dmi_quirk { |
| 12618 | void (*hook)(struct drm_device *dev); |
| 12619 | const struct dmi_system_id (*dmi_id_list)[]; |
| 12620 | }; |
| 12621 | |
| 12622 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 12623 | { |
| 12624 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 12625 | return 1; |
| 12626 | } |
| 12627 | |
| 12628 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 12629 | { |
| 12630 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 12631 | { |
| 12632 | .callback = intel_dmi_reverse_brightness, |
| 12633 | .ident = "NCR Corporation", |
| 12634 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 12635 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 12636 | }, |
| 12637 | }, |
| 12638 | { } /* terminating entry */ |
| 12639 | }, |
| 12640 | .hook = quirk_invert_brightness, |
| 12641 | }, |
| 12642 | }; |
| 12643 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 12644 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12645 | /* HP Mini needs pipe A force quirk (LP: #322104) */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 12646 | { 0x27ae, 0x103c, 0x361a, quirk_pipea_force }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12647 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12648 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 12649 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 12650 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12651 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 12652 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 12653 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 12654 | /* 830 needs to leave pipe A & dpll A up */ |
| 12655 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 12656 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame^] | 12657 | /* 830 needs to leave pipe B & dpll B up */ |
| 12658 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 12659 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 12660 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 12661 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 12662 | |
| 12663 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 12664 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 12665 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 12666 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 12667 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 12668 | |
| 12669 | /* Acer/eMachines G725 */ |
| 12670 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 12671 | |
| 12672 | /* Acer/eMachines e725 */ |
| 12673 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 12674 | |
| 12675 | /* Acer/Packard Bell NCL20 */ |
| 12676 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 12677 | |
| 12678 | /* Acer Aspire 4736Z */ |
| 12679 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 12680 | |
| 12681 | /* Acer Aspire 5336 */ |
| 12682 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 12683 | |
| 12684 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 12685 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 12686 | |
| 12687 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 12688 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 12689 | |
| 12690 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 12691 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12692 | }; |
| 12693 | |
| 12694 | static void intel_init_quirks(struct drm_device *dev) |
| 12695 | { |
| 12696 | struct pci_dev *d = dev->pdev; |
| 12697 | int i; |
| 12698 | |
| 12699 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 12700 | struct intel_quirk *q = &intel_quirks[i]; |
| 12701 | |
| 12702 | if (d->device == q->device && |
| 12703 | (d->subsystem_vendor == q->subsystem_vendor || |
| 12704 | q->subsystem_vendor == PCI_ANY_ID) && |
| 12705 | (d->subsystem_device == q->subsystem_device || |
| 12706 | q->subsystem_device == PCI_ANY_ID)) |
| 12707 | q->hook(dev); |
| 12708 | } |
Egbert Eich | 5f85f176 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 12709 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 12710 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 12711 | intel_dmi_quirks[i].hook(dev); |
| 12712 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12713 | } |
| 12714 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12715 | /* Disable the VGA plane that we never use */ |
| 12716 | static void i915_disable_vga(struct drm_device *dev) |
| 12717 | { |
| 12718 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12719 | u8 sr1; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 12720 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12721 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 12722 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12723 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 12724 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12725 | sr1 = inb(VGA_SR_DATA); |
| 12726 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 12727 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 12728 | udelay(300); |
| 12729 | |
| 12730 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
| 12731 | POSTING_READ(vga_reg); |
| 12732 | } |
| 12733 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 12734 | void intel_modeset_init_hw(struct drm_device *dev) |
| 12735 | { |
Eugeni Dodonov | a8f78b5 | 2012-06-28 15:55:35 -0300 | [diff] [blame] | 12736 | intel_prepare_ddi(dev); |
| 12737 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 12738 | if (IS_VALLEYVIEW(dev)) |
| 12739 | vlv_update_cdclk(dev); |
| 12740 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 12741 | intel_init_clock_gating(dev); |
| 12742 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 12743 | intel_enable_gt_powersave(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 12744 | } |
| 12745 | |
Imre Deak | 7d708ee | 2013-04-17 14:04:50 +0300 | [diff] [blame] | 12746 | void intel_modeset_suspend_hw(struct drm_device *dev) |
| 12747 | { |
| 12748 | intel_suspend_hw(dev); |
| 12749 | } |
| 12750 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12751 | void intel_modeset_init(struct drm_device *dev) |
| 12752 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 12753 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 12754 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 12755 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 12756 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12757 | |
| 12758 | drm_mode_config_init(dev); |
| 12759 | |
| 12760 | dev->mode_config.min_width = 0; |
| 12761 | dev->mode_config.min_height = 0; |
| 12762 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 12763 | dev->mode_config.preferred_depth = 24; |
| 12764 | dev->mode_config.prefer_shadow = 1; |
| 12765 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 12766 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12767 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 12768 | intel_init_quirks(dev); |
| 12769 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 12770 | intel_init_pm(dev); |
| 12771 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 12772 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 12773 | return; |
| 12774 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 12775 | intel_init_display(dev); |
| 12776 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 12777 | if (IS_GEN2(dev)) { |
| 12778 | dev->mode_config.max_width = 2048; |
| 12779 | dev->mode_config.max_height = 2048; |
| 12780 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 12781 | dev->mode_config.max_width = 4096; |
| 12782 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12783 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 12784 | dev->mode_config.max_width = 8192; |
| 12785 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12786 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 12787 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 12788 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 12789 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 12790 | dev->mode_config.cursor_height = 1023; |
| 12791 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 12792 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 12793 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 12794 | } else { |
| 12795 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 12796 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 12797 | } |
| 12798 | |
Ben Widawsky | 5d4545a | 2013-01-17 12:45:15 -0800 | [diff] [blame] | 12799 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12800 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 12801 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 12802 | INTEL_INFO(dev)->num_pipes, |
| 12803 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12804 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 12805 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 12806 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 12807 | for_each_sprite(pipe, sprite) { |
| 12808 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 12809 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 12810 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 12811 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 12812 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12813 | } |
| 12814 | |
Jesse Barnes | f42bb70 | 2013-12-16 16:34:23 -0800 | [diff] [blame] | 12815 | intel_init_dpio(dev); |
| 12816 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 12817 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12818 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 12819 | /* Just disable it once at startup */ |
| 12820 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12821 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 12822 | |
| 12823 | /* Just in case the BIOS is doing something questionable. */ |
| 12824 | intel_disable_fbc(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 12825 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 12826 | drm_modeset_lock_all(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 12827 | intel_modeset_setup_hw_state(dev, false); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 12828 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 12829 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12830 | for_each_intel_crtc(dev, crtc) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 12831 | if (!crtc->active) |
| 12832 | continue; |
| 12833 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 12834 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 12835 | * Note that reserving the BIOS fb up front prevents us |
| 12836 | * from stuffing other stolen allocations like the ring |
| 12837 | * on top. This prevents some ugliness at boot time, and |
| 12838 | * can even allow for smooth boot transitions if the BIOS |
| 12839 | * fb is large enough for the active pipe configuration. |
| 12840 | */ |
| 12841 | if (dev_priv->display.get_plane_config) { |
| 12842 | dev_priv->display.get_plane_config(crtc, |
| 12843 | &crtc->plane_config); |
| 12844 | /* |
| 12845 | * If the fb is shared between multiple heads, we'll |
| 12846 | * just get the first one. |
| 12847 | */ |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 12848 | intel_find_plane_obj(crtc, &crtc->plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 12849 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 12850 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 12851 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 12852 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 12853 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 12854 | { |
| 12855 | struct intel_connector *connector; |
| 12856 | struct drm_connector *crt = NULL; |
| 12857 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 12858 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 12859 | |
| 12860 | /* We can't just switch on the pipe A, we need to set things up with a |
| 12861 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 12862 | * by enabling the load detect pipe once. */ |
| 12863 | list_for_each_entry(connector, |
| 12864 | &dev->mode_config.connector_list, |
| 12865 | base.head) { |
| 12866 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 12867 | crt = &connector->base; |
| 12868 | break; |
| 12869 | } |
| 12870 | } |
| 12871 | |
| 12872 | if (!crt) |
| 12873 | return; |
| 12874 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 12875 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
| 12876 | intel_release_load_detect_pipe(crt, &load_detect_temp); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 12877 | } |
| 12878 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 12879 | static bool |
| 12880 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 12881 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 12882 | struct drm_device *dev = crtc->base.dev; |
| 12883 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 12884 | u32 reg, val; |
| 12885 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 12886 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 12887 | return true; |
| 12888 | |
| 12889 | reg = DSPCNTR(!crtc->plane); |
| 12890 | val = I915_READ(reg); |
| 12891 | |
| 12892 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 12893 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 12894 | return false; |
| 12895 | |
| 12896 | return true; |
| 12897 | } |
| 12898 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12899 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 12900 | { |
| 12901 | struct drm_device *dev = crtc->base.dev; |
| 12902 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 12903 | u32 reg; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12904 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12905 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 12906 | reg = PIPECONF(crtc->config.cpu_transcoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12907 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 12908 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 12909 | /* restore vblank interrupts to correct state */ |
| 12910 | if (crtc->active) |
| 12911 | drm_vblank_on(dev, crtc->pipe); |
| 12912 | else |
| 12913 | drm_vblank_off(dev, crtc->pipe); |
| 12914 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12915 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 12916 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 12917 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 12918 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12919 | struct intel_connector *connector; |
| 12920 | bool plane; |
| 12921 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12922 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 12923 | crtc->base.base.id); |
| 12924 | |
| 12925 | /* Pipe has the wrong plane attached and the plane is active. |
| 12926 | * Temporarily change the plane mapping and disable everything |
| 12927 | * ... */ |
| 12928 | plane = crtc->plane; |
| 12929 | crtc->plane = !plane; |
Daniel Vetter | 9c8958b | 2014-07-14 19:35:31 +0200 | [diff] [blame] | 12930 | crtc->primary_enabled = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12931 | dev_priv->display.crtc_disable(&crtc->base); |
| 12932 | crtc->plane = plane; |
| 12933 | |
| 12934 | /* ... and break all links. */ |
| 12935 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 12936 | base.head) { |
| 12937 | if (connector->encoder->base.crtc != &crtc->base) |
| 12938 | continue; |
| 12939 | |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 12940 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 12941 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12942 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 12943 | /* multiple connectors may have the same encoder: |
| 12944 | * handle them and break crtc link separately */ |
| 12945 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 12946 | base.head) |
| 12947 | if (connector->encoder->base.crtc == &crtc->base) { |
| 12948 | connector->encoder->base.crtc = NULL; |
| 12949 | connector->encoder->connectors_active = false; |
| 12950 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12951 | |
| 12952 | WARN_ON(crtc->active); |
| 12953 | crtc->base.enabled = false; |
| 12954 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12955 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 12956 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 12957 | crtc->pipe == PIPE_A && !crtc->active) { |
| 12958 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 12959 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 12960 | * call below we restore the pipe to the right state, but leave |
| 12961 | * the required bits on. */ |
| 12962 | intel_enable_pipe_a(dev); |
| 12963 | } |
| 12964 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 12965 | /* Adjust the state of the output pipe according to whether we |
| 12966 | * have active connectors/encoders. */ |
| 12967 | intel_crtc_update_dpms(&crtc->base); |
| 12968 | |
| 12969 | if (crtc->active != crtc->base.enabled) { |
| 12970 | struct intel_encoder *encoder; |
| 12971 | |
| 12972 | /* This can happen either due to bugs in the get_hw_state |
| 12973 | * functions or because the pipe is force-enabled due to the |
| 12974 | * pipe A quirk. */ |
| 12975 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", |
| 12976 | crtc->base.base.id, |
| 12977 | crtc->base.enabled ? "enabled" : "disabled", |
| 12978 | crtc->active ? "enabled" : "disabled"); |
| 12979 | |
| 12980 | crtc->base.enabled = crtc->active; |
| 12981 | |
| 12982 | /* Because we only establish the connector -> encoder -> |
| 12983 | * crtc links if something is active, this means the |
| 12984 | * crtc is now deactivated. Break the links. connector |
| 12985 | * -> encoder links are only establish when things are |
| 12986 | * actually up, hence no need to break them. */ |
| 12987 | WARN_ON(crtc->active); |
| 12988 | |
| 12989 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
| 12990 | WARN_ON(encoder->connectors_active); |
| 12991 | encoder->base.crtc = NULL; |
| 12992 | } |
| 12993 | } |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 12994 | |
| 12995 | if (crtc->active || IS_VALLEYVIEW(dev) || INTEL_INFO(dev)->gen < 5) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 12996 | /* |
| 12997 | * We start out with underrun reporting disabled to avoid races. |
| 12998 | * For correct bookkeeping mark this on active crtcs. |
| 12999 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 13000 | * Also on gmch platforms we dont have any hardware bits to |
| 13001 | * disable the underrun reporting. Which means we need to start |
| 13002 | * out with underrun reporting disabled also on inactive pipes, |
| 13003 | * since otherwise we'll complain about the garbage we read when |
| 13004 | * e.g. coming up after runtime pm. |
| 13005 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 13006 | * No protection against concurrent access is required - at |
| 13007 | * worst a fifo underrun happens which also sets this to false. |
| 13008 | */ |
| 13009 | crtc->cpu_fifo_underrun_disabled = true; |
| 13010 | crtc->pch_fifo_underrun_disabled = true; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 13011 | |
| 13012 | update_scanline_offset(crtc); |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 13013 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13014 | } |
| 13015 | |
| 13016 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 13017 | { |
| 13018 | struct intel_connector *connector; |
| 13019 | struct drm_device *dev = encoder->base.dev; |
| 13020 | |
| 13021 | /* We need to check both for a crtc link (meaning that the |
| 13022 | * encoder is active and trying to read from a pipe) and the |
| 13023 | * pipe itself being active. */ |
| 13024 | bool has_active_crtc = encoder->base.crtc && |
| 13025 | to_intel_crtc(encoder->base.crtc)->active; |
| 13026 | |
| 13027 | if (encoder->connectors_active && !has_active_crtc) { |
| 13028 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 13029 | encoder->base.base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13030 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13031 | |
| 13032 | /* Connector is active, but has no active pipe. This is |
| 13033 | * fallout from our resume register restoring. Disable |
| 13034 | * the encoder manually again. */ |
| 13035 | if (encoder->base.crtc) { |
| 13036 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 13037 | encoder->base.base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13038 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13039 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 13040 | if (encoder->post_disable) |
| 13041 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13042 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13043 | encoder->base.crtc = NULL; |
| 13044 | encoder->connectors_active = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13045 | |
| 13046 | /* Inconsistent output/port/pipe state happens presumably due to |
| 13047 | * a bug in one of the get_hw_state functions. Or someplace else |
| 13048 | * in our code, like the register restore mess on resume. Clamp |
| 13049 | * things to off as a safer default. */ |
| 13050 | list_for_each_entry(connector, |
| 13051 | &dev->mode_config.connector_list, |
| 13052 | base.head) { |
| 13053 | if (connector->encoder != encoder) |
| 13054 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13055 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 13056 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13057 | } |
| 13058 | } |
| 13059 | /* Enabled encoders without active connectors will be fixed in |
| 13060 | * the crtc fixup. */ |
| 13061 | } |
| 13062 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13063 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 13064 | { |
| 13065 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 13066 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 13067 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13068 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 13069 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 13070 | i915_disable_vga(dev); |
| 13071 | } |
| 13072 | } |
| 13073 | |
| 13074 | void i915_redisable_vga(struct drm_device *dev) |
| 13075 | { |
| 13076 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13077 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 13078 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 13079 | * at a very early point in our resume sequence, where the power well |
| 13080 | * structures are not yet restored. Since this function is at a very |
| 13081 | * paranoid "someone might have enabled VGA while we were not looking" |
| 13082 | * level, just check if the power well is enabled instead of trying to |
| 13083 | * follow the "don't touch the power well if we don't need it" policy |
| 13084 | * the rest of the driver uses. */ |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13085 | if (!intel_display_power_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 13086 | return; |
| 13087 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13088 | i915_redisable_vga_power_on(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 13089 | } |
| 13090 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 13091 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
| 13092 | { |
| 13093 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 13094 | |
| 13095 | if (!crtc->active) |
| 13096 | return false; |
| 13097 | |
| 13098 | return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE; |
| 13099 | } |
| 13100 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13101 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13102 | { |
| 13103 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13104 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13105 | struct intel_crtc *crtc; |
| 13106 | struct intel_encoder *encoder; |
| 13107 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13108 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13109 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13110 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 13111 | memset(&crtc->config, 0, sizeof(crtc->config)); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 13112 | |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 13113 | crtc->config.quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE; |
| 13114 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13115 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
| 13116 | &crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13117 | |
| 13118 | crtc->base.enabled = crtc->active; |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 13119 | crtc->primary_enabled = primary_get_hw_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13120 | |
| 13121 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 13122 | crtc->base.base.id, |
| 13123 | crtc->active ? "enabled" : "disabled"); |
| 13124 | } |
| 13125 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13126 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 13127 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 13128 | |
| 13129 | pll->on = pll->get_hw_state(dev_priv, pll, &pll->hw_state); |
| 13130 | pll->active = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13131 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13132 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 13133 | pll->active++; |
| 13134 | } |
| 13135 | pll->refcount = pll->active; |
| 13136 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 13137 | DRM_DEBUG_KMS("%s hw state readout: refcount %i, on %i\n", |
| 13138 | pll->name, pll->refcount, pll->on); |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 13139 | |
| 13140 | if (pll->refcount) |
| 13141 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13142 | } |
| 13143 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13144 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13145 | pipe = 0; |
| 13146 | |
| 13147 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 13148 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 13149 | encoder->base.crtc = &crtc->base; |
Daniel Vetter | 1d37b68 | 2013-11-18 09:00:59 +0100 | [diff] [blame] | 13150 | encoder->get_config(encoder, &crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13151 | } else { |
| 13152 | encoder->base.crtc = NULL; |
| 13153 | } |
| 13154 | |
| 13155 | encoder->connectors_active = false; |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 13156 | 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] | 13157 | encoder->base.base.id, |
Jani Nikula | 8e329a0 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13158 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13159 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 13160 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13161 | } |
| 13162 | |
| 13163 | list_for_each_entry(connector, &dev->mode_config.connector_list, |
| 13164 | base.head) { |
| 13165 | if (connector->get_hw_state(connector)) { |
| 13166 | connector->base.dpms = DRM_MODE_DPMS_ON; |
| 13167 | connector->encoder->connectors_active = true; |
| 13168 | connector->base.encoder = &connector->encoder->base; |
| 13169 | } else { |
| 13170 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 13171 | connector->base.encoder = NULL; |
| 13172 | } |
| 13173 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 13174 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 13175 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13176 | connector->base.encoder ? "enabled" : "disabled"); |
| 13177 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13178 | } |
| 13179 | |
| 13180 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm |
| 13181 | * and i915 state tracking structures. */ |
| 13182 | void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 13183 | bool force_restore) |
| 13184 | { |
| 13185 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13186 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13187 | struct intel_crtc *crtc; |
| 13188 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 13189 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13190 | |
| 13191 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13192 | |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 13193 | /* |
| 13194 | * Now that we have the config, copy it to each CRTC struct |
| 13195 | * Note that this could go away if we move to using crtc_config |
| 13196 | * checking everywhere. |
| 13197 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13198 | for_each_intel_crtc(dev, crtc) { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 13199 | if (crtc->active && i915.fastboot) { |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 13200 | intel_mode_from_pipe_config(&crtc->base.mode, &crtc->config); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 13201 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
| 13202 | crtc->base.base.id); |
| 13203 | drm_mode_debug_printmodeline(&crtc->base.mode); |
| 13204 | } |
| 13205 | } |
| 13206 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13207 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13208 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13209 | intel_sanitize_encoder(encoder); |
| 13210 | } |
| 13211 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13212 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13213 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 13214 | intel_sanitize_crtc(crtc); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 13215 | intel_dump_pipe_config(crtc, &crtc->config, "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13216 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 13217 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 13218 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 13219 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 13220 | |
| 13221 | if (!pll->on || pll->active) |
| 13222 | continue; |
| 13223 | |
| 13224 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 13225 | |
| 13226 | pll->disable(dev_priv, pll); |
| 13227 | pll->on = false; |
| 13228 | } |
| 13229 | |
Ville Syrjälä | 96f90c5 | 2013-12-05 15:51:38 +0200 | [diff] [blame] | 13230 | if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 13231 | ilk_wm_get_hw_state(dev); |
| 13232 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 13233 | if (force_restore) { |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 13234 | i915_redisable_vga(dev); |
| 13235 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13236 | /* |
| 13237 | * We need to use raw interfaces for restoring state to avoid |
| 13238 | * checking (bogus) intermediate states. |
| 13239 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13240 | for_each_pipe(dev_priv, pipe) { |
Jesse Barnes | b5644d0 | 2013-03-26 13:25:27 -0700 | [diff] [blame] | 13241 | struct drm_crtc *crtc = |
| 13242 | dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13243 | |
| 13244 | __intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 13245 | crtc->primary->fb); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 13246 | } |
| 13247 | } else { |
| 13248 | intel_modeset_update_staged_output_state(dev); |
| 13249 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13250 | |
| 13251 | intel_modeset_check_state(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 13252 | } |
| 13253 | |
| 13254 | void intel_modeset_gem_init(struct drm_device *dev) |
| 13255 | { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13256 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 13257 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13258 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 13259 | mutex_lock(&dev->struct_mutex); |
| 13260 | intel_init_gt_powersave(dev); |
| 13261 | mutex_unlock(&dev->struct_mutex); |
| 13262 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 13263 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 13264 | |
| 13265 | intel_setup_overlay(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13266 | |
| 13267 | /* |
| 13268 | * Make sure any fbs we allocated at startup are properly |
| 13269 | * pinned & fenced. When we do the allocation it's too early |
| 13270 | * for this. |
| 13271 | */ |
| 13272 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 13273 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 13274 | obj = intel_fb_obj(c->primary->fb); |
| 13275 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13276 | continue; |
| 13277 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 13278 | if (intel_pin_and_fence_fb_obj(dev, obj, NULL)) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13279 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 13280 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 13281 | drm_framebuffer_unreference(c->primary->fb); |
| 13282 | c->primary->fb = NULL; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13283 | } |
| 13284 | } |
| 13285 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13286 | } |
| 13287 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 13288 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 13289 | { |
| 13290 | struct drm_connector *connector = &intel_connector->base; |
| 13291 | |
| 13292 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 13293 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 13294 | } |
| 13295 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13296 | void intel_modeset_cleanup(struct drm_device *dev) |
| 13297 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13298 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 13299 | struct drm_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13300 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13301 | /* |
| 13302 | * Interrupts and polling as the first thing to avoid creating havoc. |
| 13303 | * Too much stuff here (turning of rps, connectors, ...) would |
| 13304 | * experience fancy races otherwise. |
| 13305 | */ |
| 13306 | drm_irq_uninstall(dev); |
Imre Deak | 1d0d343 | 2014-08-18 14:42:44 +0300 | [diff] [blame] | 13307 | intel_hpd_cancel_work(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 13308 | dev_priv->pm._irqs_disabled = true; |
| 13309 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13310 | /* |
| 13311 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 13312 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 13313 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 13314 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13315 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13316 | mutex_lock(&dev->struct_mutex); |
| 13317 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 13318 | intel_unregister_dsm_handler(); |
| 13319 | |
Chris Wilson | 973d04f | 2011-07-08 12:22:37 +0100 | [diff] [blame] | 13320 | intel_disable_fbc(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13321 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 13322 | intel_disable_gt_powersave(dev); |
Chris Wilson | 0cdab21 | 2010-12-05 17:27:06 +0000 | [diff] [blame] | 13323 | |
Daniel Vetter | 930ebb4 | 2012-06-29 23:32:16 +0200 | [diff] [blame] | 13324 | ironlake_teardown_rc6(dev); |
| 13325 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 13326 | mutex_unlock(&dev->struct_mutex); |
| 13327 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 13328 | /* flush any delayed tasks or pending work */ |
| 13329 | flush_scheduled_work(); |
| 13330 | |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 13331 | /* destroy the backlight and sysfs files before encoders/connectors */ |
| 13332 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 13333 | struct intel_connector *intel_connector; |
| 13334 | |
| 13335 | intel_connector = to_intel_connector(connector); |
| 13336 | intel_connector->unregister(intel_connector); |
Jani Nikula | db31af1 | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 13337 | } |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 13338 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13339 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 13340 | |
| 13341 | intel_cleanup_overlay(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 13342 | |
| 13343 | mutex_lock(&dev->struct_mutex); |
| 13344 | intel_cleanup_gt_powersave(dev); |
| 13345 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13346 | } |
| 13347 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 13348 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 13349 | * Return which encoder is currently attached for connector. |
| 13350 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 13351 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13352 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 13353 | return &intel_attached_encoder(connector)->base; |
| 13354 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13355 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 13356 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 13357 | struct intel_encoder *encoder) |
| 13358 | { |
| 13359 | connector->encoder = encoder; |
| 13360 | drm_mode_connector_attach_encoder(&connector->base, |
| 13361 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13362 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 13363 | |
| 13364 | /* |
| 13365 | * set vga decode state - true == enable VGA decode |
| 13366 | */ |
| 13367 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 13368 | { |
| 13369 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 13370 | 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] | 13371 | u16 gmch_ctrl; |
| 13372 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 13373 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 13374 | DRM_ERROR("failed to read control word\n"); |
| 13375 | return -EIO; |
| 13376 | } |
| 13377 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 13378 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 13379 | return 0; |
| 13380 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 13381 | if (state) |
| 13382 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 13383 | else |
| 13384 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 13385 | |
| 13386 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 13387 | DRM_ERROR("failed to write control word\n"); |
| 13388 | return -EIO; |
| 13389 | } |
| 13390 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 13391 | return 0; |
| 13392 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13393 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13394 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 13395 | |
| 13396 | u32 power_well_driver; |
| 13397 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13398 | int num_transcoders; |
| 13399 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13400 | struct intel_cursor_error_state { |
| 13401 | u32 control; |
| 13402 | u32 position; |
| 13403 | u32 base; |
| 13404 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 13405 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13406 | |
| 13407 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13408 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13409 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 13410 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 13411 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13412 | |
| 13413 | struct intel_plane_error_state { |
| 13414 | u32 control; |
| 13415 | u32 stride; |
| 13416 | u32 size; |
| 13417 | u32 pos; |
| 13418 | u32 addr; |
| 13419 | u32 surface; |
| 13420 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 13421 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13422 | |
| 13423 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13424 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13425 | enum transcoder cpu_transcoder; |
| 13426 | |
| 13427 | u32 conf; |
| 13428 | |
| 13429 | u32 htotal; |
| 13430 | u32 hblank; |
| 13431 | u32 hsync; |
| 13432 | u32 vtotal; |
| 13433 | u32 vblank; |
| 13434 | u32 vsync; |
| 13435 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13436 | }; |
| 13437 | |
| 13438 | struct intel_display_error_state * |
| 13439 | intel_display_capture_error_state(struct drm_device *dev) |
| 13440 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13441 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13442 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13443 | int transcoders[] = { |
| 13444 | TRANSCODER_A, |
| 13445 | TRANSCODER_B, |
| 13446 | TRANSCODER_C, |
| 13447 | TRANSCODER_EDP, |
| 13448 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13449 | int i; |
| 13450 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13451 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 13452 | return NULL; |
| 13453 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 13454 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13455 | if (error == NULL) |
| 13456 | return NULL; |
| 13457 | |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 13458 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 13459 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 13460 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13461 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13462 | error->pipe[i].power_domain_on = |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 13463 | intel_display_power_enabled_unlocked(dev_priv, |
| 13464 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13465 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 13466 | continue; |
| 13467 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 13468 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 13469 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 13470 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13471 | |
| 13472 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 13473 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 13474 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 13475 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 13476 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 13477 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 13478 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 13479 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13480 | if (INTEL_INFO(dev)->gen >= 4) { |
| 13481 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 13482 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 13483 | } |
| 13484 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13485 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 13486 | |
Sonika Jindal | 3abfce7 | 2014-07-21 15:23:43 +0530 | [diff] [blame] | 13487 | if (HAS_GMCH_DISPLAY(dev)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 13488 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13489 | } |
| 13490 | |
| 13491 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; |
| 13492 | if (HAS_DDI(dev_priv->dev)) |
| 13493 | error->num_transcoders++; /* Account for eDP. */ |
| 13494 | |
| 13495 | for (i = 0; i < error->num_transcoders; i++) { |
| 13496 | enum transcoder cpu_transcoder = transcoders[i]; |
| 13497 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13498 | error->transcoder[i].power_domain_on = |
Imre Deak | bfafe93 | 2014-06-05 20:31:47 +0300 | [diff] [blame] | 13499 | intel_display_power_enabled_unlocked(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 13500 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13501 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 13502 | continue; |
| 13503 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13504 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 13505 | |
| 13506 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 13507 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 13508 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 13509 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 13510 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 13511 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 13512 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13513 | } |
| 13514 | |
| 13515 | return error; |
| 13516 | } |
| 13517 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13518 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 13519 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13520 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13521 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13522 | struct drm_device *dev, |
| 13523 | struct intel_display_error_state *error) |
| 13524 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13525 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13526 | int i; |
| 13527 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13528 | if (!error) |
| 13529 | return; |
| 13530 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13531 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 13532 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13533 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 13534 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13535 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13536 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13537 | err_printf(m, " Power: %s\n", |
| 13538 | error->pipe[i].power_domain_on ? "on" : "off"); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13539 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 13540 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13541 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13542 | err_printf(m, "Plane [%d]:\n", i); |
| 13543 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 13544 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 13545 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13546 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 13547 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 13548 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 13549 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13550 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13551 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13552 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 13553 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13554 | } |
| 13555 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 13556 | err_printf(m, "Cursor [%d]:\n", i); |
| 13557 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 13558 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 13559 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13560 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13561 | |
| 13562 | for (i = 0; i < error->num_transcoders; i++) { |
Chris Wilson | 1cf84bb | 2013-10-21 09:10:33 +0100 | [diff] [blame] | 13563 | err_printf(m, "CPU transcoder: %c\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13564 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 13565 | err_printf(m, " Power: %s\n", |
| 13566 | error->transcoder[i].power_domain_on ? "on" : "off"); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 13567 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 13568 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 13569 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 13570 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 13571 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 13572 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 13573 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 13574 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 13575 | } |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 13576 | |
| 13577 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) |
| 13578 | { |
| 13579 | struct intel_crtc *crtc; |
| 13580 | |
| 13581 | for_each_intel_crtc(dev, crtc) { |
| 13582 | struct intel_unpin_work *work; |
| 13583 | unsigned long irqflags; |
| 13584 | |
| 13585 | spin_lock_irqsave(&dev->event_lock, irqflags); |
| 13586 | |
| 13587 | work = crtc->unpin_work; |
| 13588 | |
| 13589 | if (work && work->event && |
| 13590 | work->event->base.file_priv == file) { |
| 13591 | kfree(work->event); |
| 13592 | work->event = NULL; |
| 13593 | } |
| 13594 | |
| 13595 | spin_unlock_irqrestore(&dev->event_lock, irqflags); |
| 13596 | } |
| 13597 | } |