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" |
Xi Ruoyao | 319c1d4 | 2015-03-12 20:16:32 +0800 | [diff] [blame] | 40 | #include <drm/drm_atomic.h> |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 41 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 42 | #include <drm/drm_dp_helper.h> |
| 43 | #include <drm/drm_crtc_helper.h> |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 44 | #include <drm/drm_plane_helper.h> |
| 45 | #include <drm/drm_rect.h> |
Keith Packard | c0f372b3 | 2011-11-16 22:24:52 -0800 | [diff] [blame] | 46 | #include <linux/dma_remapping.h> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 47 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 48 | /* Primary plane formats supported by all gen */ |
| 49 | #define COMMON_PRIMARY_FORMATS \ |
| 50 | DRM_FORMAT_C8, \ |
| 51 | DRM_FORMAT_RGB565, \ |
| 52 | DRM_FORMAT_XRGB8888, \ |
| 53 | DRM_FORMAT_ARGB8888 |
| 54 | |
| 55 | /* Primary plane formats for gen <= 3 */ |
| 56 | static const uint32_t intel_primary_formats_gen2[] = { |
| 57 | COMMON_PRIMARY_FORMATS, |
| 58 | DRM_FORMAT_XRGB1555, |
| 59 | DRM_FORMAT_ARGB1555, |
| 60 | }; |
| 61 | |
| 62 | /* Primary plane formats for gen >= 4 */ |
| 63 | static const uint32_t intel_primary_formats_gen4[] = { |
| 64 | COMMON_PRIMARY_FORMATS, \ |
| 65 | DRM_FORMAT_XBGR8888, |
| 66 | DRM_FORMAT_ABGR8888, |
| 67 | DRM_FORMAT_XRGB2101010, |
| 68 | DRM_FORMAT_ARGB2101010, |
| 69 | DRM_FORMAT_XBGR2101010, |
| 70 | DRM_FORMAT_ABGR2101010, |
| 71 | }; |
| 72 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 73 | /* Cursor formats */ |
| 74 | static const uint32_t intel_cursor_formats[] = { |
| 75 | DRM_FORMAT_ARGB8888, |
| 76 | }; |
| 77 | |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 78 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, bool on); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 79 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 80 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 81 | struct intel_crtc_state *pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 82 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 83 | struct intel_crtc_state *pipe_config); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 84 | |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 85 | static int intel_set_mode(struct drm_crtc *crtc, struct drm_display_mode *mode, |
| 86 | int x, int y, struct drm_framebuffer *old_fb); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 87 | static int intel_framebuffer_init(struct drm_device *dev, |
| 88 | struct intel_framebuffer *ifb, |
| 89 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 90 | struct drm_i915_gem_object *obj); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 91 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 92 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 93 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 94 | struct intel_link_m_n *m_n, |
| 95 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 96 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 97 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
| 98 | static void intel_set_pipe_csc(struct drm_crtc *crtc); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 99 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 100 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 101 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 102 | const struct intel_crtc_state *pipe_config); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 103 | static void intel_begin_crtc_commit(struct drm_crtc *crtc); |
| 104 | static void intel_finish_crtc_commit(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 105 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 106 | static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe) |
| 107 | { |
| 108 | if (!connector->mst_port) |
| 109 | return connector->encoder; |
| 110 | else |
| 111 | return &connector->mst_port->mst_encoders[pipe]->base; |
| 112 | } |
| 113 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 114 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 115 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 116 | } intel_range_t; |
| 117 | |
| 118 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 119 | int dot_limit; |
| 120 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 121 | } intel_p2_t; |
| 122 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 123 | typedef struct intel_limit intel_limit_t; |
| 124 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 125 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 126 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 127 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 128 | |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 129 | int |
| 130 | intel_pch_rawclk(struct drm_device *dev) |
| 131 | { |
| 132 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 133 | |
| 134 | WARN_ON(!HAS_PCH_SPLIT(dev)); |
| 135 | |
| 136 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; |
| 137 | } |
| 138 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 139 | static inline u32 /* units of 100MHz */ |
| 140 | intel_fdi_link_freq(struct drm_device *dev) |
| 141 | { |
Chris Wilson | 8b99e68 | 2010-10-13 09:59:17 +0100 | [diff] [blame] | 142 | if (IS_GEN5(dev)) { |
| 143 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 144 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; |
| 145 | } else |
| 146 | return 27; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 147 | } |
| 148 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 149 | static const intel_limit_t intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 150 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 151 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 152 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 153 | .m = { .min = 96, .max = 140 }, |
| 154 | .m1 = { .min = 18, .max = 26 }, |
| 155 | .m2 = { .min = 6, .max = 16 }, |
| 156 | .p = { .min = 4, .max = 128 }, |
| 157 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 158 | .p2 = { .dot_limit = 165000, |
| 159 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 160 | }; |
| 161 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 162 | static const intel_limit_t intel_limits_i8xx_dvo = { |
| 163 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 164 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 165 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 166 | .m = { .min = 96, .max = 140 }, |
| 167 | .m1 = { .min = 18, .max = 26 }, |
| 168 | .m2 = { .min = 6, .max = 16 }, |
| 169 | .p = { .min = 4, .max = 128 }, |
| 170 | .p1 = { .min = 2, .max = 33 }, |
| 171 | .p2 = { .dot_limit = 165000, |
| 172 | .p2_slow = 4, .p2_fast = 4 }, |
| 173 | }; |
| 174 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 175 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 176 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 177 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 178 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 179 | .m = { .min = 96, .max = 140 }, |
| 180 | .m1 = { .min = 18, .max = 26 }, |
| 181 | .m2 = { .min = 6, .max = 16 }, |
| 182 | .p = { .min = 4, .max = 128 }, |
| 183 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 184 | .p2 = { .dot_limit = 165000, |
| 185 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 186 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 187 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 188 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 189 | .dot = { .min = 20000, .max = 400000 }, |
| 190 | .vco = { .min = 1400000, .max = 2800000 }, |
| 191 | .n = { .min = 1, .max = 6 }, |
| 192 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 193 | .m1 = { .min = 8, .max = 18 }, |
| 194 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 195 | .p = { .min = 5, .max = 80 }, |
| 196 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 197 | .p2 = { .dot_limit = 200000, |
| 198 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 199 | }; |
| 200 | |
| 201 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 202 | .dot = { .min = 20000, .max = 400000 }, |
| 203 | .vco = { .min = 1400000, .max = 2800000 }, |
| 204 | .n = { .min = 1, .max = 6 }, |
| 205 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 206 | .m1 = { .min = 8, .max = 18 }, |
| 207 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 208 | .p = { .min = 7, .max = 98 }, |
| 209 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 210 | .p2 = { .dot_limit = 112000, |
| 211 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 212 | }; |
| 213 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 214 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 215 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 216 | .dot = { .min = 25000, .max = 270000 }, |
| 217 | .vco = { .min = 1750000, .max = 3500000}, |
| 218 | .n = { .min = 1, .max = 4 }, |
| 219 | .m = { .min = 104, .max = 138 }, |
| 220 | .m1 = { .min = 17, .max = 23 }, |
| 221 | .m2 = { .min = 5, .max = 11 }, |
| 222 | .p = { .min = 10, .max = 30 }, |
| 223 | .p1 = { .min = 1, .max = 3}, |
| 224 | .p2 = { .dot_limit = 270000, |
| 225 | .p2_slow = 10, |
| 226 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 227 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 228 | }; |
| 229 | |
| 230 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 231 | .dot = { .min = 22000, .max = 400000 }, |
| 232 | .vco = { .min = 1750000, .max = 3500000}, |
| 233 | .n = { .min = 1, .max = 4 }, |
| 234 | .m = { .min = 104, .max = 138 }, |
| 235 | .m1 = { .min = 16, .max = 23 }, |
| 236 | .m2 = { .min = 5, .max = 11 }, |
| 237 | .p = { .min = 5, .max = 80 }, |
| 238 | .p1 = { .min = 1, .max = 8}, |
| 239 | .p2 = { .dot_limit = 165000, |
| 240 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 241 | }; |
| 242 | |
| 243 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 244 | .dot = { .min = 20000, .max = 115000 }, |
| 245 | .vco = { .min = 1750000, .max = 3500000 }, |
| 246 | .n = { .min = 1, .max = 3 }, |
| 247 | .m = { .min = 104, .max = 138 }, |
| 248 | .m1 = { .min = 17, .max = 23 }, |
| 249 | .m2 = { .min = 5, .max = 11 }, |
| 250 | .p = { .min = 28, .max = 112 }, |
| 251 | .p1 = { .min = 2, .max = 8 }, |
| 252 | .p2 = { .dot_limit = 0, |
| 253 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 254 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 255 | }; |
| 256 | |
| 257 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 258 | .dot = { .min = 80000, .max = 224000 }, |
| 259 | .vco = { .min = 1750000, .max = 3500000 }, |
| 260 | .n = { .min = 1, .max = 3 }, |
| 261 | .m = { .min = 104, .max = 138 }, |
| 262 | .m1 = { .min = 17, .max = 23 }, |
| 263 | .m2 = { .min = 5, .max = 11 }, |
| 264 | .p = { .min = 14, .max = 42 }, |
| 265 | .p1 = { .min = 2, .max = 6 }, |
| 266 | .p2 = { .dot_limit = 0, |
| 267 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 268 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 269 | }; |
| 270 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 271 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 272 | .dot = { .min = 20000, .max = 400000}, |
| 273 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 274 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 275 | .n = { .min = 3, .max = 6 }, |
| 276 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 277 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 278 | .m1 = { .min = 0, .max = 0 }, |
| 279 | .m2 = { .min = 0, .max = 254 }, |
| 280 | .p = { .min = 5, .max = 80 }, |
| 281 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 282 | .p2 = { .dot_limit = 200000, |
| 283 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 284 | }; |
| 285 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 286 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 287 | .dot = { .min = 20000, .max = 400000 }, |
| 288 | .vco = { .min = 1700000, .max = 3500000 }, |
| 289 | .n = { .min = 3, .max = 6 }, |
| 290 | .m = { .min = 2, .max = 256 }, |
| 291 | .m1 = { .min = 0, .max = 0 }, |
| 292 | .m2 = { .min = 0, .max = 254 }, |
| 293 | .p = { .min = 7, .max = 112 }, |
| 294 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 295 | .p2 = { .dot_limit = 112000, |
| 296 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 297 | }; |
| 298 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 299 | /* Ironlake / Sandybridge |
| 300 | * |
| 301 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 302 | * the range value for them is (actual_value - 2). |
| 303 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 304 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 305 | .dot = { .min = 25000, .max = 350000 }, |
| 306 | .vco = { .min = 1760000, .max = 3510000 }, |
| 307 | .n = { .min = 1, .max = 5 }, |
| 308 | .m = { .min = 79, .max = 127 }, |
| 309 | .m1 = { .min = 12, .max = 22 }, |
| 310 | .m2 = { .min = 5, .max = 9 }, |
| 311 | .p = { .min = 5, .max = 80 }, |
| 312 | .p1 = { .min = 1, .max = 8 }, |
| 313 | .p2 = { .dot_limit = 225000, |
| 314 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 315 | }; |
| 316 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 317 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 318 | .dot = { .min = 25000, .max = 350000 }, |
| 319 | .vco = { .min = 1760000, .max = 3510000 }, |
| 320 | .n = { .min = 1, .max = 3 }, |
| 321 | .m = { .min = 79, .max = 118 }, |
| 322 | .m1 = { .min = 12, .max = 22 }, |
| 323 | .m2 = { .min = 5, .max = 9 }, |
| 324 | .p = { .min = 28, .max = 112 }, |
| 325 | .p1 = { .min = 2, .max = 8 }, |
| 326 | .p2 = { .dot_limit = 225000, |
| 327 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 328 | }; |
| 329 | |
| 330 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 331 | .dot = { .min = 25000, .max = 350000 }, |
| 332 | .vco = { .min = 1760000, .max = 3510000 }, |
| 333 | .n = { .min = 1, .max = 3 }, |
| 334 | .m = { .min = 79, .max = 127 }, |
| 335 | .m1 = { .min = 12, .max = 22 }, |
| 336 | .m2 = { .min = 5, .max = 9 }, |
| 337 | .p = { .min = 14, .max = 56 }, |
| 338 | .p1 = { .min = 2, .max = 8 }, |
| 339 | .p2 = { .dot_limit = 225000, |
| 340 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 341 | }; |
| 342 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 343 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 344 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 345 | .dot = { .min = 25000, .max = 350000 }, |
| 346 | .vco = { .min = 1760000, .max = 3510000 }, |
| 347 | .n = { .min = 1, .max = 2 }, |
| 348 | .m = { .min = 79, .max = 126 }, |
| 349 | .m1 = { .min = 12, .max = 22 }, |
| 350 | .m2 = { .min = 5, .max = 9 }, |
| 351 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 352 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 353 | .p2 = { .dot_limit = 225000, |
| 354 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 358 | .dot = { .min = 25000, .max = 350000 }, |
| 359 | .vco = { .min = 1760000, .max = 3510000 }, |
| 360 | .n = { .min = 1, .max = 3 }, |
| 361 | .m = { .min = 79, .max = 126 }, |
| 362 | .m1 = { .min = 12, .max = 22 }, |
| 363 | .m2 = { .min = 5, .max = 9 }, |
| 364 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 365 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 366 | .p2 = { .dot_limit = 225000, |
| 367 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 368 | }; |
| 369 | |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 370 | static const intel_limit_t intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 371 | /* |
| 372 | * These are the data rate limits (measured in fast clocks) |
| 373 | * since those are the strictest limits we have. The fast |
| 374 | * clock and actual rate limits are more relaxed, so checking |
| 375 | * them would make no difference. |
| 376 | */ |
| 377 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 378 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 379 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 380 | .m1 = { .min = 2, .max = 3 }, |
| 381 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 382 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 383 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 384 | }; |
| 385 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 386 | static const intel_limit_t intel_limits_chv = { |
| 387 | /* |
| 388 | * These are the data rate limits (measured in fast clocks) |
| 389 | * since those are the strictest limits we have. The fast |
| 390 | * clock and actual rate limits are more relaxed, so checking |
| 391 | * them would make no difference. |
| 392 | */ |
| 393 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 394 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 395 | .n = { .min = 1, .max = 1 }, |
| 396 | .m1 = { .min = 2, .max = 2 }, |
| 397 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 398 | .p1 = { .min = 2, .max = 4 }, |
| 399 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 400 | }; |
| 401 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 402 | static void vlv_clock(int refclk, intel_clock_t *clock) |
| 403 | { |
| 404 | clock->m = clock->m1 * clock->m2; |
| 405 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 406 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 407 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 408 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 409 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 410 | } |
| 411 | |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 412 | /** |
| 413 | * Returns whether any output on the specified pipe is of the specified type |
| 414 | */ |
Damien Lespiau | 4093561 | 2014-10-29 11:16:59 +0000 | [diff] [blame] | 415 | bool intel_pipe_has_type(struct intel_crtc *crtc, enum intel_output_type type) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 416 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 417 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 418 | struct intel_encoder *encoder; |
| 419 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 420 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 421 | if (encoder->type == type) |
| 422 | return true; |
| 423 | |
| 424 | return false; |
| 425 | } |
| 426 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 427 | /** |
| 428 | * Returns whether any output on the specified pipe will have the specified |
| 429 | * type after a staged modeset is complete, i.e., the same as |
| 430 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of |
| 431 | * encoder->crtc. |
| 432 | */ |
| 433 | static bool intel_pipe_will_have_type(struct intel_crtc *crtc, int type) |
| 434 | { |
| 435 | struct drm_device *dev = crtc->base.dev; |
| 436 | struct intel_encoder *encoder; |
| 437 | |
| 438 | for_each_intel_encoder(dev, encoder) |
| 439 | if (encoder->new_crtc == crtc && encoder->type == type) |
| 440 | return true; |
| 441 | |
| 442 | return false; |
| 443 | } |
| 444 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 445 | static const intel_limit_t *intel_ironlake_limit(struct intel_crtc *crtc, |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 446 | int refclk) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 447 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 448 | struct drm_device *dev = crtc->base.dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 449 | const intel_limit_t *limit; |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 450 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 451 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 452 | if (intel_is_dual_link_lvds(dev)) { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 453 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 454 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 455 | else |
| 456 | limit = &intel_limits_ironlake_dual_lvds; |
| 457 | } else { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 458 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 459 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 460 | else |
| 461 | limit = &intel_limits_ironlake_single_lvds; |
| 462 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 463 | } else |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 464 | limit = &intel_limits_ironlake_dac; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 465 | |
| 466 | return limit; |
| 467 | } |
| 468 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 469 | static const intel_limit_t *intel_g4x_limit(struct intel_crtc *crtc) |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 470 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 471 | struct drm_device *dev = crtc->base.dev; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 472 | const intel_limit_t *limit; |
| 473 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 474 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 475 | if (intel_is_dual_link_lvds(dev)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 476 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 477 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 478 | limit = &intel_limits_g4x_single_channel_lvds; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 479 | } else if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_HDMI) || |
| 480 | intel_pipe_will_have_type(crtc, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 481 | limit = &intel_limits_g4x_hdmi; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 482 | } else if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 483 | limit = &intel_limits_g4x_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 484 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 485 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 486 | |
| 487 | return limit; |
| 488 | } |
| 489 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 490 | static const intel_limit_t *intel_limit(struct intel_crtc *crtc, int refclk) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 491 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 492 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 493 | const intel_limit_t *limit; |
| 494 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 495 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 496 | limit = intel_ironlake_limit(crtc, refclk); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 497 | else if (IS_G4X(dev)) { |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 498 | limit = intel_g4x_limit(crtc); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 499 | } else if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 500 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 501 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 502 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 503 | limit = &intel_limits_pineview_sdvo; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 504 | } else if (IS_CHERRYVIEW(dev)) { |
| 505 | limit = &intel_limits_chv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 506 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 507 | limit = &intel_limits_vlv; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 508 | } else if (!IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 509 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 510 | limit = &intel_limits_i9xx_lvds; |
| 511 | else |
| 512 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 513 | } else { |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 514 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 515 | limit = &intel_limits_i8xx_lvds; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 516 | else if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_DVO)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 517 | limit = &intel_limits_i8xx_dvo; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 518 | else |
| 519 | limit = &intel_limits_i8xx_dac; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 520 | } |
| 521 | return limit; |
| 522 | } |
| 523 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 524 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
| 525 | static void pineview_clock(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 526 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 527 | clock->m = clock->m2 + 2; |
| 528 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 529 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 530 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 531 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 532 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 533 | } |
| 534 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 535 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 536 | { |
| 537 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 538 | } |
| 539 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 540 | static void i9xx_clock(int refclk, intel_clock_t *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 541 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 542 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 543 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 544 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
| 545 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 546 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 547 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 548 | } |
| 549 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 550 | static void chv_clock(int refclk, intel_clock_t *clock) |
| 551 | { |
| 552 | clock->m = clock->m1 * clock->m2; |
| 553 | clock->p = clock->p1 * clock->p2; |
| 554 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 555 | return; |
| 556 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 557 | clock->n << 22); |
| 558 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
| 559 | } |
| 560 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 561 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 562 | /** |
| 563 | * Returns whether the given set of divisors are valid for a given refclk with |
| 564 | * the given connectors. |
| 565 | */ |
| 566 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 567 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 568 | const intel_limit_t *limit, |
| 569 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 570 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 571 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 572 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 573 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 574 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 575 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 576 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 577 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 578 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 579 | |
| 580 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev)) |
| 581 | if (clock->m1 <= clock->m2) |
| 582 | INTELPllInvalid("m1 <= m2\n"); |
| 583 | |
| 584 | if (!IS_VALLEYVIEW(dev)) { |
| 585 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 586 | INTELPllInvalid("p out of range\n"); |
| 587 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 588 | INTELPllInvalid("m out of range\n"); |
| 589 | } |
| 590 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 591 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 592 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 593 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 594 | * connector, etc., rather than just a single range. |
| 595 | */ |
| 596 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 597 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 598 | |
| 599 | return true; |
| 600 | } |
| 601 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 602 | static bool |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 603 | i9xx_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 604 | int target, int refclk, intel_clock_t *match_clock, |
| 605 | intel_clock_t *best_clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 606 | { |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 607 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 608 | intel_clock_t clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 609 | int err = target; |
| 610 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 611 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 612 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 613 | * For LVDS just rely on its current settings for dual-channel. |
| 614 | * We haven't figured out how to reliably set up different |
| 615 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 616 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 617 | if (intel_is_dual_link_lvds(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 618 | clock.p2 = limit->p2.p2_fast; |
| 619 | else |
| 620 | clock.p2 = limit->p2.p2_slow; |
| 621 | } else { |
| 622 | if (target < limit->p2.dot_limit) |
| 623 | clock.p2 = limit->p2.p2_slow; |
| 624 | else |
| 625 | clock.p2 = limit->p2.p2_fast; |
| 626 | } |
| 627 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 628 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 629 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 630 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 631 | clock.m1++) { |
| 632 | for (clock.m2 = limit->m2.min; |
| 633 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 634 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 635 | break; |
| 636 | for (clock.n = limit->n.min; |
| 637 | clock.n <= limit->n.max; clock.n++) { |
| 638 | for (clock.p1 = limit->p1.min; |
| 639 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 640 | int this_err; |
| 641 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 642 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 643 | if (!intel_PLL_is_valid(dev, limit, |
| 644 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 645 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 646 | if (match_clock && |
| 647 | clock.p != match_clock->p) |
| 648 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 649 | |
| 650 | this_err = abs(clock.dot - target); |
| 651 | if (this_err < err) { |
| 652 | *best_clock = clock; |
| 653 | err = this_err; |
| 654 | } |
| 655 | } |
| 656 | } |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | return (err != target); |
| 661 | } |
| 662 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 663 | static bool |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 664 | pnv_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 665 | int target, int refclk, intel_clock_t *match_clock, |
| 666 | intel_clock_t *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 667 | { |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 668 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 669 | intel_clock_t clock; |
| 670 | int err = target; |
| 671 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 672 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 673 | /* |
| 674 | * For LVDS just rely on its current settings for dual-channel. |
| 675 | * We haven't figured out how to reliably set up different |
| 676 | * single/dual channel state, if we even can. |
| 677 | */ |
| 678 | if (intel_is_dual_link_lvds(dev)) |
| 679 | clock.p2 = limit->p2.p2_fast; |
| 680 | else |
| 681 | clock.p2 = limit->p2.p2_slow; |
| 682 | } else { |
| 683 | if (target < limit->p2.dot_limit) |
| 684 | clock.p2 = limit->p2.p2_slow; |
| 685 | else |
| 686 | clock.p2 = limit->p2.p2_fast; |
| 687 | } |
| 688 | |
| 689 | memset(best_clock, 0, sizeof(*best_clock)); |
| 690 | |
| 691 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 692 | clock.m1++) { |
| 693 | for (clock.m2 = limit->m2.min; |
| 694 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 695 | for (clock.n = limit->n.min; |
| 696 | clock.n <= limit->n.max; clock.n++) { |
| 697 | for (clock.p1 = limit->p1.min; |
| 698 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 699 | int this_err; |
| 700 | |
| 701 | pineview_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 702 | if (!intel_PLL_is_valid(dev, limit, |
| 703 | &clock)) |
| 704 | continue; |
| 705 | if (match_clock && |
| 706 | clock.p != match_clock->p) |
| 707 | continue; |
| 708 | |
| 709 | this_err = abs(clock.dot - target); |
| 710 | if (this_err < err) { |
| 711 | *best_clock = clock; |
| 712 | err = this_err; |
| 713 | } |
| 714 | } |
| 715 | } |
| 716 | } |
| 717 | } |
| 718 | |
| 719 | return (err != target); |
| 720 | } |
| 721 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 722 | static bool |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 723 | g4x_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 724 | int target, int refclk, intel_clock_t *match_clock, |
| 725 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 726 | { |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 727 | struct drm_device *dev = crtc->base.dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 728 | intel_clock_t clock; |
| 729 | int max_n; |
| 730 | bool found; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 731 | /* approximately equals target * 0.00585 */ |
| 732 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 733 | found = false; |
| 734 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 735 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 736 | if (intel_is_dual_link_lvds(dev)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 737 | clock.p2 = limit->p2.p2_fast; |
| 738 | else |
| 739 | clock.p2 = limit->p2.p2_slow; |
| 740 | } else { |
| 741 | if (target < limit->p2.dot_limit) |
| 742 | clock.p2 = limit->p2.p2_slow; |
| 743 | else |
| 744 | clock.p2 = limit->p2.p2_fast; |
| 745 | } |
| 746 | |
| 747 | memset(best_clock, 0, sizeof(*best_clock)); |
| 748 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 749 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 750 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 751 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 752 | for (clock.m1 = limit->m1.max; |
| 753 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 754 | for (clock.m2 = limit->m2.max; |
| 755 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 756 | for (clock.p1 = limit->p1.max; |
| 757 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 758 | int this_err; |
| 759 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 760 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 761 | if (!intel_PLL_is_valid(dev, limit, |
| 762 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 763 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 764 | |
| 765 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 766 | if (this_err < err_most) { |
| 767 | *best_clock = clock; |
| 768 | err_most = this_err; |
| 769 | max_n = clock.n; |
| 770 | found = true; |
| 771 | } |
| 772 | } |
| 773 | } |
| 774 | } |
| 775 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 776 | return found; |
| 777 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 778 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 779 | /* |
| 780 | * Check if the calculated PLL configuration is more optimal compared to the |
| 781 | * best configuration and error found so far. Return the calculated error. |
| 782 | */ |
| 783 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
| 784 | const intel_clock_t *calculated_clock, |
| 785 | const intel_clock_t *best_clock, |
| 786 | unsigned int best_error_ppm, |
| 787 | unsigned int *error_ppm) |
| 788 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 789 | /* |
| 790 | * For CHV ignore the error and consider only the P value. |
| 791 | * Prefer a bigger P value based on HW requirements. |
| 792 | */ |
| 793 | if (IS_CHERRYVIEW(dev)) { |
| 794 | *error_ppm = 0; |
| 795 | |
| 796 | return calculated_clock->p > best_clock->p; |
| 797 | } |
| 798 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 799 | if (WARN_ON_ONCE(!target_freq)) |
| 800 | return false; |
| 801 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 802 | *error_ppm = div_u64(1000000ULL * |
| 803 | abs(target_freq - calculated_clock->dot), |
| 804 | target_freq); |
| 805 | /* |
| 806 | * Prefer a better P value over a better (smaller) error if the error |
| 807 | * is small. Ensure this preference for future configurations too by |
| 808 | * setting the error to 0. |
| 809 | */ |
| 810 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 811 | *error_ppm = 0; |
| 812 | |
| 813 | return true; |
| 814 | } |
| 815 | |
| 816 | return *error_ppm + 10 < best_error_ppm; |
| 817 | } |
| 818 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 819 | static bool |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 820 | vlv_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 821 | int target, int refclk, intel_clock_t *match_clock, |
| 822 | intel_clock_t *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 823 | { |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 824 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 825 | intel_clock_t clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 826 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 827 | /* min update 19.2 MHz */ |
| 828 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 829 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 830 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 831 | target *= 5; /* fast clock */ |
| 832 | |
| 833 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 834 | |
| 835 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 836 | 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] | 837 | 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] | 838 | 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] | 839 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 840 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 841 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 842 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; clock.m1++) { |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 843 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 844 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 845 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 846 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 847 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 848 | vlv_clock(refclk, &clock); |
| 849 | |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 850 | if (!intel_PLL_is_valid(dev, limit, |
| 851 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 852 | continue; |
| 853 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 854 | if (!vlv_PLL_is_optimal(dev, target, |
| 855 | &clock, |
| 856 | best_clock, |
| 857 | bestppm, &ppm)) |
| 858 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 859 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 860 | *best_clock = clock; |
| 861 | bestppm = ppm; |
| 862 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 863 | } |
| 864 | } |
| 865 | } |
| 866 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 867 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 868 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 869 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 870 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 871 | static bool |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 872 | chv_find_best_dpll(const intel_limit_t *limit, struct intel_crtc *crtc, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 873 | int target, int refclk, intel_clock_t *match_clock, |
| 874 | intel_clock_t *best_clock) |
| 875 | { |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 876 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 877 | unsigned int best_error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 878 | intel_clock_t clock; |
| 879 | uint64_t m2; |
| 880 | int found = false; |
| 881 | |
| 882 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 883 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 884 | |
| 885 | /* |
| 886 | * Based on hardware doc, the n always set to 1, and m1 always |
| 887 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 888 | * revisit this because n may not 1 anymore. |
| 889 | */ |
| 890 | clock.n = 1, clock.m1 = 2; |
| 891 | target *= 5; /* fast clock */ |
| 892 | |
| 893 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 894 | for (clock.p2 = limit->p2.p2_fast; |
| 895 | clock.p2 >= limit->p2.p2_slow; |
| 896 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 897 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 898 | |
| 899 | clock.p = clock.p1 * clock.p2; |
| 900 | |
| 901 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 902 | clock.n) << 22, refclk * clock.m1); |
| 903 | |
| 904 | if (m2 > INT_MAX/clock.m1) |
| 905 | continue; |
| 906 | |
| 907 | clock.m2 = m2; |
| 908 | |
| 909 | chv_clock(refclk, &clock); |
| 910 | |
| 911 | if (!intel_PLL_is_valid(dev, limit, &clock)) |
| 912 | continue; |
| 913 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 914 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 915 | best_error_ppm, &error_ppm)) |
| 916 | continue; |
| 917 | |
| 918 | *best_clock = clock; |
| 919 | best_error_ppm = error_ppm; |
| 920 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 921 | } |
| 922 | } |
| 923 | |
| 924 | return found; |
| 925 | } |
| 926 | |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 927 | bool intel_crtc_active(struct drm_crtc *crtc) |
| 928 | { |
| 929 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 930 | |
| 931 | /* Be paranoid as we can arrive here with only partial |
| 932 | * state retrieved from the hardware during setup. |
| 933 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 934 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 935 | * as Haswell has gained clock readout/fastboot support. |
| 936 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 937 | * 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] | 938 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 939 | * |
| 940 | * FIXME: The intel_crtc->active here should be switched to |
| 941 | * crtc->state->active once we have proper CRTC states wired up |
| 942 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 943 | */ |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 944 | return intel_crtc->active && crtc->primary->state->fb && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 945 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 946 | } |
| 947 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 948 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 949 | enum pipe pipe) |
| 950 | { |
| 951 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 952 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 953 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 954 | return intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 955 | } |
| 956 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 957 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 958 | { |
| 959 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 960 | u32 reg = PIPEDSL(pipe); |
| 961 | u32 line1, line2; |
| 962 | u32 line_mask; |
| 963 | |
| 964 | if (IS_GEN2(dev)) |
| 965 | line_mask = DSL_LINEMASK_GEN2; |
| 966 | else |
| 967 | line_mask = DSL_LINEMASK_GEN3; |
| 968 | |
| 969 | line1 = I915_READ(reg) & line_mask; |
| 970 | mdelay(5); |
| 971 | line2 = I915_READ(reg) & line_mask; |
| 972 | |
| 973 | return line1 == line2; |
| 974 | } |
| 975 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 976 | /* |
| 977 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 978 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 979 | * |
| 980 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 981 | * spinning on the vblank interrupt status bit, since we won't actually |
| 982 | * see an interrupt when the pipe is disabled. |
| 983 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 984 | * On Gen4 and above: |
| 985 | * wait for the pipe register state bit to turn off |
| 986 | * |
| 987 | * Otherwise: |
| 988 | * wait for the display line value to settle (it usually |
| 989 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 990 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 991 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 992 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 993 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 994 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 995 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 996 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 997 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 998 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 999 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1000 | int reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1001 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1002 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1003 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 1004 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1005 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1006 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1007 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1008 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1009 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1010 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1011 | } |
| 1012 | |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1013 | /* |
| 1014 | * ibx_digital_port_connected - is the specified port connected? |
| 1015 | * @dev_priv: i915 private structure |
| 1016 | * @port: the port to test |
| 1017 | * |
| 1018 | * Returns true if @port is connected, false otherwise. |
| 1019 | */ |
| 1020 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 1021 | struct intel_digital_port *port) |
| 1022 | { |
| 1023 | u32 bit; |
| 1024 | |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1025 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1026 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1027 | case PORT_B: |
| 1028 | bit = SDE_PORTB_HOTPLUG; |
| 1029 | break; |
| 1030 | case PORT_C: |
| 1031 | bit = SDE_PORTC_HOTPLUG; |
| 1032 | break; |
| 1033 | case PORT_D: |
| 1034 | bit = SDE_PORTD_HOTPLUG; |
| 1035 | break; |
| 1036 | default: |
| 1037 | return true; |
| 1038 | } |
| 1039 | } else { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1040 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1041 | case PORT_B: |
| 1042 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 1043 | break; |
| 1044 | case PORT_C: |
| 1045 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 1046 | break; |
| 1047 | case PORT_D: |
| 1048 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 1049 | break; |
| 1050 | default: |
| 1051 | return true; |
| 1052 | } |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
| 1055 | return I915_READ(SDEISR) & bit; |
| 1056 | } |
| 1057 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1058 | static const char *state_string(bool enabled) |
| 1059 | { |
| 1060 | return enabled ? "on" : "off"; |
| 1061 | } |
| 1062 | |
| 1063 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1064 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1065 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1066 | { |
| 1067 | int reg; |
| 1068 | u32 val; |
| 1069 | bool cur_state; |
| 1070 | |
| 1071 | reg = DPLL(pipe); |
| 1072 | val = I915_READ(reg); |
| 1073 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1074 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1075 | "PLL state assertion failure (expected %s, current %s)\n", |
| 1076 | state_string(state), state_string(cur_state)); |
| 1077 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1078 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1079 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
| 1080 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
| 1081 | { |
| 1082 | u32 val; |
| 1083 | bool cur_state; |
| 1084 | |
| 1085 | mutex_lock(&dev_priv->dpio_lock); |
| 1086 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
| 1087 | mutex_unlock(&dev_priv->dpio_lock); |
| 1088 | |
| 1089 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1090 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1091 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
| 1092 | state_string(state), state_string(cur_state)); |
| 1093 | } |
| 1094 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) |
| 1095 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) |
| 1096 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1097 | struct intel_shared_dpll * |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1098 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1099 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1100 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 1101 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1102 | if (crtc->config->shared_dpll < 0) |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1103 | return NULL; |
| 1104 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1105 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1106 | } |
| 1107 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1108 | /* For ILK+ */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1109 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
| 1110 | struct intel_shared_dpll *pll, |
| 1111 | bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1112 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1113 | bool cur_state; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1114 | struct intel_dpll_hw_state hw_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1115 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1116 | if (WARN (!pll, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1117 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1118 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1119 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1120 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1121 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1122 | "%s assertion failure (expected %s, current %s)\n", |
| 1123 | pll->name, state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1124 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1125 | |
| 1126 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1127 | enum pipe pipe, bool state) |
| 1128 | { |
| 1129 | int reg; |
| 1130 | u32 val; |
| 1131 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1132 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1133 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1134 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1135 | if (HAS_DDI(dev_priv->dev)) { |
| 1136 | /* DDI does not have a specific FDI_TX register */ |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1137 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1138 | val = I915_READ(reg); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1139 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1140 | } else { |
| 1141 | reg = FDI_TX_CTL(pipe); |
| 1142 | val = I915_READ(reg); |
| 1143 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1144 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1145 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1146 | "FDI TX state assertion failure (expected %s, current %s)\n", |
| 1147 | state_string(state), state_string(cur_state)); |
| 1148 | } |
| 1149 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1150 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1151 | |
| 1152 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1153 | enum pipe pipe, bool state) |
| 1154 | { |
| 1155 | int reg; |
| 1156 | u32 val; |
| 1157 | bool cur_state; |
| 1158 | |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1159 | reg = FDI_RX_CTL(pipe); |
| 1160 | val = I915_READ(reg); |
| 1161 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1162 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1163 | "FDI RX state assertion failure (expected %s, current %s)\n", |
| 1164 | state_string(state), state_string(cur_state)); |
| 1165 | } |
| 1166 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1167 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1168 | |
| 1169 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1170 | enum pipe pipe) |
| 1171 | { |
| 1172 | int reg; |
| 1173 | u32 val; |
| 1174 | |
| 1175 | /* ILK FDI PLL is always enabled */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1176 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1177 | return; |
| 1178 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1179 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1180 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1181 | return; |
| 1182 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1183 | reg = FDI_TX_CTL(pipe); |
| 1184 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1185 | I915_STATE_WARN(!(val & FDI_TX_PLL_ENABLE), "FDI TX PLL assertion failure, should be active but is disabled\n"); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1186 | } |
| 1187 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1188 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1189 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1190 | { |
| 1191 | int reg; |
| 1192 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1193 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1194 | |
| 1195 | reg = FDI_RX_CTL(pipe); |
| 1196 | val = I915_READ(reg); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1197 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1198 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1199 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
| 1200 | state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1201 | } |
| 1202 | |
Daniel Vetter | b680c37 | 2014-09-19 18:27:27 +0200 | [diff] [blame] | 1203 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1204 | enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1205 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1206 | struct drm_device *dev = dev_priv->dev; |
| 1207 | int pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1208 | u32 val; |
| 1209 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1210 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1211 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1212 | if (WARN_ON(HAS_DDI(dev))) |
| 1213 | return; |
| 1214 | |
| 1215 | if (HAS_PCH_SPLIT(dev)) { |
| 1216 | u32 port_sel; |
| 1217 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1218 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1219 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1220 | |
| 1221 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1222 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1223 | panel_pipe = PIPE_B; |
| 1224 | /* XXX: else fix for eDP */ |
| 1225 | } else if (IS_VALLEYVIEW(dev)) { |
| 1226 | /* presumably write lock depends on pipe, not port select */ |
| 1227 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1228 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1229 | } else { |
| 1230 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1231 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1232 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | val = I915_READ(pp_reg); |
| 1236 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1237 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1238 | locked = false; |
| 1239 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1240 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1241 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1242 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1243 | } |
| 1244 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1245 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1246 | enum pipe pipe, bool state) |
| 1247 | { |
| 1248 | struct drm_device *dev = dev_priv->dev; |
| 1249 | bool cur_state; |
| 1250 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1251 | if (IS_845G(dev) || IS_I865G(dev)) |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1252 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1253 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1254 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1255 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1256 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1257 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
| 1258 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
| 1259 | } |
| 1260 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1261 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1262 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1263 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1264 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1265 | { |
| 1266 | int reg; |
| 1267 | u32 val; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1268 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1269 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1270 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1271 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1272 | /* if we need the pipe quirk it must be always on */ |
| 1273 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1274 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1275 | state = true; |
| 1276 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1277 | if (!intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 1278 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1279 | cur_state = false; |
| 1280 | } else { |
| 1281 | reg = PIPECONF(cpu_transcoder); |
| 1282 | val = I915_READ(reg); |
| 1283 | cur_state = !!(val & PIPECONF_ENABLE); |
| 1284 | } |
| 1285 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1286 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1287 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1288 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1289 | } |
| 1290 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1291 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1292 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1293 | { |
| 1294 | int reg; |
| 1295 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1296 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1297 | |
| 1298 | reg = DSPCNTR(plane); |
| 1299 | val = I915_READ(reg); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1300 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1301 | I915_STATE_WARN(cur_state != state, |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1302 | "plane %c assertion failure (expected %s, current %s)\n", |
| 1303 | plane_name(plane), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1304 | } |
| 1305 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1306 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1307 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1308 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1309 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1310 | enum pipe pipe) |
| 1311 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1312 | struct drm_device *dev = dev_priv->dev; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1313 | int reg, i; |
| 1314 | u32 val; |
| 1315 | int cur_pipe; |
| 1316 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1317 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1318 | if (INTEL_INFO(dev)->gen >= 4) { |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1319 | reg = DSPCNTR(pipe); |
| 1320 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1321 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1322 | "plane %c assertion failure, should be disabled but not\n", |
| 1323 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1324 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1325 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1326 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1327 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1328 | for_each_pipe(dev_priv, i) { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1329 | reg = DSPCNTR(i); |
| 1330 | val = I915_READ(reg); |
| 1331 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 1332 | DISPPLANE_SEL_PIPE_SHIFT; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1333 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1334 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1335 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1336 | } |
| 1337 | } |
| 1338 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1339 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1340 | enum pipe pipe) |
| 1341 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1342 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1343 | int reg, sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1344 | u32 val; |
| 1345 | |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1346 | if (INTEL_INFO(dev)->gen >= 9) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1347 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1348 | val = I915_READ(PLANE_CTL(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1349 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1350 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
| 1351 | sprite, pipe_name(pipe)); |
| 1352 | } |
| 1353 | } else if (IS_VALLEYVIEW(dev)) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1354 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1355 | reg = SPCNTR(pipe, sprite); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1356 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1357 | I915_STATE_WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1358 | "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] | 1359 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1360 | } |
| 1361 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 1362 | reg = SPRCTL(pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1363 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1364 | I915_STATE_WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1365 | "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] | 1366 | plane_name(pipe), pipe_name(pipe)); |
| 1367 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1368 | reg = DVSCNTR(pipe); |
| 1369 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1370 | I915_STATE_WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1371 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1372 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1376 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1377 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1378 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1379 | drm_crtc_vblank_put(crtc); |
| 1380 | } |
| 1381 | |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 1382 | 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] | 1383 | { |
| 1384 | u32 val; |
| 1385 | bool enabled; |
| 1386 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1387 | I915_STATE_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] | 1388 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1389 | val = I915_READ(PCH_DREF_CONTROL); |
| 1390 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | |
| 1391 | DREF_SUPERSPREAD_SOURCE_MASK)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1392 | I915_STATE_WARN(!enabled, "PCH refclk assertion failure, should be active but is disabled\n"); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1393 | } |
| 1394 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1395 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1396 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1397 | { |
| 1398 | int reg; |
| 1399 | u32 val; |
| 1400 | bool enabled; |
| 1401 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1402 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1403 | val = I915_READ(reg); |
| 1404 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1405 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1406 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1407 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1408 | } |
| 1409 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1410 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1411 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1412 | { |
| 1413 | if ((val & DP_PORT_EN) == 0) |
| 1414 | return false; |
| 1415 | |
| 1416 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1417 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); |
| 1418 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); |
| 1419 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1420 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1421 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1422 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1423 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1424 | } else { |
| 1425 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1426 | return false; |
| 1427 | } |
| 1428 | return true; |
| 1429 | } |
| 1430 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1431 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1432 | enum pipe pipe, u32 val) |
| 1433 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1434 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1435 | return false; |
| 1436 | |
| 1437 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1438 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1439 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1440 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1441 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1442 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1443 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1444 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1445 | return false; |
| 1446 | } |
| 1447 | return true; |
| 1448 | } |
| 1449 | |
| 1450 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1451 | enum pipe pipe, u32 val) |
| 1452 | { |
| 1453 | if ((val & LVDS_PORT_EN) == 0) |
| 1454 | return false; |
| 1455 | |
| 1456 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1457 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1458 | return false; |
| 1459 | } else { |
| 1460 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1461 | return false; |
| 1462 | } |
| 1463 | return true; |
| 1464 | } |
| 1465 | |
| 1466 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1467 | enum pipe pipe, u32 val) |
| 1468 | { |
| 1469 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1470 | return false; |
| 1471 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1472 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1473 | return false; |
| 1474 | } else { |
| 1475 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1476 | return false; |
| 1477 | } |
| 1478 | return true; |
| 1479 | } |
| 1480 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1481 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1482 | enum pipe pipe, int reg, u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1483 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1484 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1485 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1486 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1487 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1488 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1489 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & DP_PORT_EN) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1490 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1491 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1492 | } |
| 1493 | |
| 1494 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
| 1495 | enum pipe pipe, int reg) |
| 1496 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1497 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1498 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1499 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1500 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1501 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1502 | I915_STATE_WARN(HAS_PCH_IBX(dev_priv->dev) && (val & SDVO_ENABLE) == 0 |
Daniel Vetter | 75c5da2 | 2012-09-10 21:58:29 +0200 | [diff] [blame] | 1503 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1504 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1505 | } |
| 1506 | |
| 1507 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1508 | enum pipe pipe) |
| 1509 | { |
| 1510 | int reg; |
| 1511 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1512 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1513 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1514 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1515 | 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] | 1516 | |
| 1517 | reg = PCH_ADPA; |
| 1518 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1519 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1520 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1521 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1522 | |
| 1523 | reg = PCH_LVDS; |
| 1524 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1525 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1526 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1527 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1528 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1529 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1530 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1531 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1532 | } |
| 1533 | |
Jesse Barnes | 40e9cf6 | 2013-10-03 11:35:46 -0700 | [diff] [blame] | 1534 | static void intel_init_dpio(struct drm_device *dev) |
| 1535 | { |
| 1536 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1537 | |
| 1538 | if (!IS_VALLEYVIEW(dev)) |
| 1539 | return; |
| 1540 | |
Chon Ming Lee | a09cadd | 2014-04-09 13:28:14 +0300 | [diff] [blame] | 1541 | /* |
| 1542 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), |
| 1543 | * CHV x1 PHY (DP/HDMI D) |
| 1544 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) |
| 1545 | */ |
| 1546 | if (IS_CHERRYVIEW(dev)) { |
| 1547 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; |
| 1548 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; |
| 1549 | } else { |
| 1550 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; |
| 1551 | } |
Jesse Barnes | 5382f5f35 | 2013-12-16 16:34:24 -0800 | [diff] [blame] | 1552 | } |
| 1553 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1554 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1555 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1556 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1557 | struct drm_device *dev = crtc->base.dev; |
| 1558 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1559 | int reg = DPLL(crtc->pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1560 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1561 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1562 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1563 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1564 | /* No really, not for ILK+ */ |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1565 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); |
| 1566 | |
| 1567 | /* PLL is protected by panel, make sure we can write it */ |
Jani Nikula | 6a9e736 | 2014-08-22 15:06:35 +0300 | [diff] [blame] | 1568 | if (IS_MOBILE(dev_priv->dev)) |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1569 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1570 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1571 | I915_WRITE(reg, dpll); |
| 1572 | POSTING_READ(reg); |
| 1573 | udelay(150); |
| 1574 | |
| 1575 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1576 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); |
| 1577 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1578 | I915_WRITE(DPLL_MD(crtc->pipe), pipe_config->dpll_hw_state.dpll_md); |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1579 | POSTING_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1580 | |
| 1581 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1582 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1583 | POSTING_READ(reg); |
| 1584 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1585 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1586 | POSTING_READ(reg); |
| 1587 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1588 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1589 | POSTING_READ(reg); |
| 1590 | udelay(150); /* wait for warmup */ |
| 1591 | } |
| 1592 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1593 | static void chv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1594 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1595 | { |
| 1596 | struct drm_device *dev = crtc->base.dev; |
| 1597 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1598 | int pipe = crtc->pipe; |
| 1599 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1600 | u32 tmp; |
| 1601 | |
| 1602 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 1603 | |
| 1604 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); |
| 1605 | |
| 1606 | mutex_lock(&dev_priv->dpio_lock); |
| 1607 | |
| 1608 | /* Enable back the 10bit clock to display controller */ |
| 1609 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1610 | tmp |= DPIO_DCLKP_EN; |
| 1611 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1612 | |
| 1613 | /* |
| 1614 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1615 | */ |
| 1616 | udelay(1); |
| 1617 | |
| 1618 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1619 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1620 | |
| 1621 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1622 | 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] | 1623 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
| 1624 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1625 | /* not sure when this should be written */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1626 | I915_WRITE(DPLL_MD(pipe), pipe_config->dpll_hw_state.dpll_md); |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1627 | POSTING_READ(DPLL_MD(pipe)); |
| 1628 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1629 | mutex_unlock(&dev_priv->dpio_lock); |
| 1630 | } |
| 1631 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1632 | static int intel_num_dvo_pipes(struct drm_device *dev) |
| 1633 | { |
| 1634 | struct intel_crtc *crtc; |
| 1635 | int count = 0; |
| 1636 | |
| 1637 | for_each_intel_crtc(dev, crtc) |
| 1638 | count += crtc->active && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1639 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1640 | |
| 1641 | return count; |
| 1642 | } |
| 1643 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1644 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1645 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1646 | struct drm_device *dev = crtc->base.dev; |
| 1647 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1648 | int reg = DPLL(crtc->pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1649 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1650 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1651 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1652 | |
| 1653 | /* No really, not for ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1654 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1655 | |
| 1656 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1657 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1658 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1659 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1660 | /* Enable DVO 2x clock on both PLLs if necessary */ |
| 1661 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { |
| 1662 | /* |
| 1663 | * It appears to be important that we don't enable this |
| 1664 | * for the current pipe before otherwise configuring the |
| 1665 | * PLL. No idea how this should be handled if multiple |
| 1666 | * DVO outputs are enabled simultaneosly. |
| 1667 | */ |
| 1668 | dpll |= DPLL_DVO_2X_MODE; |
| 1669 | I915_WRITE(DPLL(!crtc->pipe), |
| 1670 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1671 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1672 | |
| 1673 | /* Wait for the clocks to stabilize. */ |
| 1674 | POSTING_READ(reg); |
| 1675 | udelay(150); |
| 1676 | |
| 1677 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1678 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1679 | crtc->config->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1680 | } else { |
| 1681 | /* The pixel multiplier can only be updated once the |
| 1682 | * DPLL is enabled and the clocks are stable. |
| 1683 | * |
| 1684 | * So write it again. |
| 1685 | */ |
| 1686 | I915_WRITE(reg, dpll); |
| 1687 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1688 | |
| 1689 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1690 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1691 | POSTING_READ(reg); |
| 1692 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1693 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1694 | POSTING_READ(reg); |
| 1695 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1696 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1697 | POSTING_READ(reg); |
| 1698 | udelay(150); /* wait for warmup */ |
| 1699 | } |
| 1700 | |
| 1701 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1702 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1703 | * @dev_priv: i915 private structure |
| 1704 | * @pipe: pipe PLL to disable |
| 1705 | * |
| 1706 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1707 | * |
| 1708 | * Note! This is for pre-ILK only. |
| 1709 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1710 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1711 | { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1712 | struct drm_device *dev = crtc->base.dev; |
| 1713 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1714 | enum pipe pipe = crtc->pipe; |
| 1715 | |
| 1716 | /* Disable DVO 2x clock on both PLLs if necessary */ |
| 1717 | if (IS_I830(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1718 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1719 | intel_num_dvo_pipes(dev) == 1) { |
| 1720 | I915_WRITE(DPLL(PIPE_B), |
| 1721 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1722 | I915_WRITE(DPLL(PIPE_A), |
| 1723 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1724 | } |
| 1725 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1726 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1727 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1728 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1729 | return; |
| 1730 | |
| 1731 | /* Make sure the pipe isn't still relying on us */ |
| 1732 | assert_pipe_disabled(dev_priv, pipe); |
| 1733 | |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1734 | I915_WRITE(DPLL(pipe), 0); |
| 1735 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1736 | } |
| 1737 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1738 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1739 | { |
| 1740 | u32 val = 0; |
| 1741 | |
| 1742 | /* Make sure the pipe isn't still relying on us */ |
| 1743 | assert_pipe_disabled(dev_priv, pipe); |
| 1744 | |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1745 | /* |
| 1746 | * Leave integrated clock source and reference clock enabled for pipe B. |
| 1747 | * The latter is needed for VGA hotplug / manual detection. |
| 1748 | */ |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1749 | if (pipe == PIPE_B) |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1750 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1751 | I915_WRITE(DPLL(pipe), val); |
| 1752 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1753 | |
| 1754 | } |
| 1755 | |
| 1756 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1757 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1758 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1759 | u32 val; |
| 1760 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1761 | /* Make sure the pipe isn't still relying on us */ |
| 1762 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1763 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1764 | /* Set PLL en = 0 */ |
Ville Syrjälä | d17ec4c | 2014-06-28 02:03:59 +0300 | [diff] [blame] | 1765 | val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1766 | if (pipe != PIPE_A) |
| 1767 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1768 | I915_WRITE(DPLL(pipe), val); |
| 1769 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1770 | |
| 1771 | mutex_lock(&dev_priv->dpio_lock); |
| 1772 | |
| 1773 | /* Disable 10bit clock to display controller */ |
| 1774 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1775 | val &= ~DPIO_DCLKP_EN; |
| 1776 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1777 | |
Ville Syrjälä | 61407f6 | 2014-05-27 16:32:55 +0300 | [diff] [blame] | 1778 | /* disable left/right clock distribution */ |
| 1779 | if (pipe != PIPE_B) { |
| 1780 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); |
| 1781 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); |
| 1782 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); |
| 1783 | } else { |
| 1784 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); |
| 1785 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); |
| 1786 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); |
| 1787 | } |
| 1788 | |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1789 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1790 | } |
| 1791 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1792 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
| 1793 | struct intel_digital_port *dport) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1794 | { |
| 1795 | u32 port_mask; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1796 | int dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1797 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1798 | switch (dport->port) { |
| 1799 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1800 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1801 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1802 | break; |
| 1803 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1804 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1805 | dpll_reg = DPLL(0); |
| 1806 | break; |
| 1807 | case PORT_D: |
| 1808 | port_mask = DPLL_PORTD_READY_MASK; |
| 1809 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1810 | break; |
| 1811 | default: |
| 1812 | BUG(); |
| 1813 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1814 | |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1815 | if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1816 | 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] | 1817 | port_name(dport->port), I915_READ(dpll_reg)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1818 | } |
| 1819 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1820 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
| 1821 | { |
| 1822 | struct drm_device *dev = crtc->base.dev; |
| 1823 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1824 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 1825 | |
Chris Wilson | be19f0f | 2014-05-28 16:16:42 +0100 | [diff] [blame] | 1826 | if (WARN_ON(pll == NULL)) |
| 1827 | return; |
| 1828 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1829 | WARN_ON(!pll->config.crtc_mask); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1830 | if (pll->active == 0) { |
| 1831 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); |
| 1832 | WARN_ON(pll->on); |
| 1833 | assert_shared_dpll_disabled(dev_priv, pll); |
| 1834 | |
| 1835 | pll->mode_set(dev_priv, pll); |
| 1836 | } |
| 1837 | } |
| 1838 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1839 | /** |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1840 | * intel_enable_shared_dpll - enable PCH PLL |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1841 | * @dev_priv: i915 private structure |
| 1842 | * @pipe: pipe PLL to enable |
| 1843 | * |
| 1844 | * The PCH PLL needs to be enabled before the PCH transcoder, since it |
| 1845 | * drives the transcoder clock. |
| 1846 | */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1847 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1848 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1849 | struct drm_device *dev = crtc->base.dev; |
| 1850 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1851 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1852 | |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1853 | if (WARN_ON(pll == NULL)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1854 | return; |
| 1855 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1856 | if (WARN_ON(pll->config.crtc_mask == 0)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1857 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1858 | |
Damien Lespiau | 74dd692 | 2014-07-29 18:06:17 +0100 | [diff] [blame] | 1859 | 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] | 1860 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1861 | crtc->base.base.id); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1862 | |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1863 | if (pll->active++) { |
| 1864 | WARN_ON(!pll->on); |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1865 | assert_shared_dpll_enabled(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1866 | return; |
| 1867 | } |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1868 | WARN_ON(pll->on); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1869 | |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1870 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 1871 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1872 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1873 | pll->enable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1874 | pll->on = true; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1875 | } |
| 1876 | |
Damien Lespiau | f6daaec | 2014-08-09 23:00:56 +0100 | [diff] [blame] | 1877 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1878 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1879 | struct drm_device *dev = crtc->base.dev; |
| 1880 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1881 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 4c609cb | 2011-09-02 12:52:11 -0700 | [diff] [blame] | 1882 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1883 | /* PCH only available on ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1884 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1885 | if (WARN_ON(pll == NULL)) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1886 | return; |
| 1887 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1888 | if (WARN_ON(pll->config.crtc_mask == 0)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1889 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1890 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1891 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
| 1892 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1893 | crtc->base.base.id); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1894 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1895 | if (WARN_ON(pll->active == 0)) { |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1896 | assert_shared_dpll_disabled(dev_priv, pll); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1897 | return; |
| 1898 | } |
| 1899 | |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1900 | assert_shared_dpll_enabled(dev_priv, pll); |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1901 | WARN_ON(!pll->on); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1902 | if (--pll->active) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1903 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1904 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1905 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1906 | pll->disable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1907 | pll->on = false; |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1908 | |
| 1909 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1910 | } |
| 1911 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1912 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1913 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1914 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1915 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1916 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1917 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1918 | uint32_t reg, val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1919 | |
| 1920 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1921 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1922 | |
| 1923 | /* Make sure PCH DPLL is enabled */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 1924 | assert_shared_dpll_enabled(dev_priv, |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1925 | intel_crtc_to_shared_dpll(intel_crtc)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1926 | |
| 1927 | /* FDI must be feeding us bits for PCH ports */ |
| 1928 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1929 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1930 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1931 | if (HAS_PCH_CPT(dev)) { |
| 1932 | /* Workaround: Set the timing override bit before enabling the |
| 1933 | * pch transcoder. */ |
| 1934 | reg = TRANS_CHICKEN2(pipe); |
| 1935 | val = I915_READ(reg); |
| 1936 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1937 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1938 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1939 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1940 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1941 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1942 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1943 | |
| 1944 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1945 | /* |
| 1946 | * make the BPC in transcoder be consistent with |
| 1947 | * that in pipeconf reg. |
| 1948 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1949 | val &= ~PIPECONF_BPC_MASK; |
| 1950 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1951 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1952 | |
| 1953 | val &= ~TRANS_INTERLACE_MASK; |
| 1954 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1955 | if (HAS_PCH_IBX(dev_priv->dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1956 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1957 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1958 | else |
| 1959 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1960 | else |
| 1961 | val |= TRANS_PROGRESSIVE; |
| 1962 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1963 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1964 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1965 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1966 | } |
| 1967 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1968 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1969 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1970 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1971 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1972 | |
| 1973 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1974 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1975 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1976 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 1977 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1978 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1979 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 1980 | /* Workaround: set 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); |
| 1984 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 1985 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1986 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1987 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 1988 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 1989 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 1990 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1991 | else |
| 1992 | val |= TRANS_PROGRESSIVE; |
| 1993 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1994 | I915_WRITE(LPT_TRANSCONF, val); |
| 1995 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1996 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1997 | } |
| 1998 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1999 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 2000 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2001 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2002 | struct drm_device *dev = dev_priv->dev; |
| 2003 | uint32_t reg, val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2004 | |
| 2005 | /* FDI relies on the transcoder */ |
| 2006 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 2007 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 2008 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 2009 | /* Ports must be off as well */ |
| 2010 | assert_pch_ports_disabled(dev_priv, pipe); |
| 2011 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2012 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2013 | val = I915_READ(reg); |
| 2014 | val &= ~TRANS_ENABLE; |
| 2015 | I915_WRITE(reg, val); |
| 2016 | /* wait for PCH transcoder off, transcoder state */ |
| 2017 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 2018 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2019 | |
| 2020 | if (!HAS_PCH_IBX(dev)) { |
| 2021 | /* Workaround: Clear the timing override chicken bit again. */ |
| 2022 | reg = TRANS_CHICKEN2(pipe); |
| 2023 | val = I915_READ(reg); |
| 2024 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 2025 | I915_WRITE(reg, val); |
| 2026 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2027 | } |
| 2028 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 2029 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2030 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2031 | u32 val; |
| 2032 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2033 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2034 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2035 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2036 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2037 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 2038 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2039 | |
| 2040 | /* Workaround: clear timing override bit. */ |
| 2041 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2042 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2043 | I915_WRITE(_TRANSA_CHICKEN2, val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
| 2046 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2047 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2048 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2049 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2050 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2051 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2052 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 2053 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2054 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2055 | struct drm_device *dev = crtc->base.dev; |
| 2056 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2057 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2058 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 2059 | pipe); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2060 | enum pipe pch_transcoder; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2061 | int reg; |
| 2062 | u32 val; |
| 2063 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2064 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2065 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2066 | assert_sprites_disabled(dev_priv, pipe); |
| 2067 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 2068 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2069 | pch_transcoder = TRANSCODER_A; |
| 2070 | else |
| 2071 | pch_transcoder = pipe; |
| 2072 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2073 | /* |
| 2074 | * A pipe without a PLL won't actually be able to drive bits from |
| 2075 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 2076 | * need the check. |
| 2077 | */ |
| 2078 | if (!HAS_PCH_SPLIT(dev_priv->dev)) |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 2079 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 2080 | assert_dsi_pll_enabled(dev_priv); |
| 2081 | else |
| 2082 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2083 | else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2084 | if (crtc->config->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2085 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2086 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2087 | assert_fdi_tx_pll_enabled(dev_priv, |
| 2088 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2089 | } |
| 2090 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 2091 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2092 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2093 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2094 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2095 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2096 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 2097 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2098 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2099 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2100 | |
| 2101 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 2102 | POSTING_READ(reg); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2106 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2107 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2108 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2109 | * Disable the pipe of @crtc, making sure that various hardware |
| 2110 | * specific requirements are met, if applicable, e.g. plane |
| 2111 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2112 | * |
| 2113 | * Will wait until the pipe has shut down before returning. |
| 2114 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2115 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2116 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2117 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2118 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2119 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2120 | int reg; |
| 2121 | u32 val; |
| 2122 | |
| 2123 | /* |
| 2124 | * Make sure planes won't keep trying to pump pixels to us, |
| 2125 | * or we might hang the display. |
| 2126 | */ |
| 2127 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2128 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2129 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2130 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2131 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2132 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2133 | if ((val & PIPECONF_ENABLE) == 0) |
| 2134 | return; |
| 2135 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2136 | /* |
| 2137 | * Double wide has implications for planes |
| 2138 | * so best keep it disabled when not needed. |
| 2139 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2140 | if (crtc->config->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2141 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2142 | |
| 2143 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2144 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2145 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2146 | val &= ~PIPECONF_ENABLE; |
| 2147 | |
| 2148 | I915_WRITE(reg, val); |
| 2149 | if ((val & PIPECONF_ENABLE) == 0) |
| 2150 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2151 | } |
| 2152 | |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2153 | /* |
| 2154 | * Plane regs are double buffered, going from enabled->disabled needs a |
| 2155 | * trigger in order to latch. The display address reg provides this. |
| 2156 | */ |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2157 | void intel_flush_primary_plane(struct drm_i915_private *dev_priv, |
| 2158 | enum plane plane) |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2159 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 2160 | struct drm_device *dev = dev_priv->dev; |
| 2161 | u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2162 | |
| 2163 | I915_WRITE(reg, I915_READ(reg)); |
| 2164 | POSTING_READ(reg); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2167 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2168 | * intel_enable_primary_hw_plane - enable the primary plane on a given pipe |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2169 | * @plane: plane to be enabled |
| 2170 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2171 | * |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2172 | * Enable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2173 | */ |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2174 | static void intel_enable_primary_hw_plane(struct drm_plane *plane, |
| 2175 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2176 | { |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2177 | struct drm_device *dev = plane->dev; |
| 2178 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2179 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2180 | |
| 2181 | /* If the pipe isn't enabled, we can't pump pixels and may hang */ |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2182 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2183 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2184 | if (intel_crtc->primary_enabled) |
| 2185 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2186 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2187 | intel_crtc->primary_enabled = true; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2188 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2189 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2190 | crtc->x, crtc->y); |
Ville Syrjälä | 33c3b0d | 2014-06-24 13:59:28 +0300 | [diff] [blame] | 2191 | |
| 2192 | /* |
| 2193 | * BDW signals flip done immediately if the plane |
| 2194 | * is disabled, even if the plane enable is already |
| 2195 | * armed to occur at the next vblank :( |
| 2196 | */ |
| 2197 | if (IS_BROADWELL(dev)) |
| 2198 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2199 | } |
| 2200 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2201 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2202 | * intel_disable_primary_hw_plane - disable the primary hardware plane |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2203 | * @plane: plane to be disabled |
| 2204 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2205 | * |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2206 | * Disable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2207 | */ |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2208 | static void intel_disable_primary_hw_plane(struct drm_plane *plane, |
| 2209 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2210 | { |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2211 | struct drm_device *dev = plane->dev; |
| 2212 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2213 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2214 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 2215 | if (WARN_ON(!intel_crtc->active)) |
| 2216 | return; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2217 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2218 | if (!intel_crtc->primary_enabled) |
| 2219 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2220 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2221 | intel_crtc->primary_enabled = false; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2222 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2223 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2224 | crtc->x, crtc->y); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2225 | } |
| 2226 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2227 | static bool need_vtd_wa(struct drm_device *dev) |
| 2228 | { |
| 2229 | #ifdef CONFIG_INTEL_IOMMU |
| 2230 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2231 | return true; |
| 2232 | #endif |
| 2233 | return false; |
| 2234 | } |
| 2235 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 2236 | static unsigned int |
| 2237 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
| 2238 | uint64_t fb_format_modifier) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2239 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 2240 | unsigned int tile_height; |
| 2241 | uint32_t pixel_bytes; |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2242 | |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2243 | switch (fb_format_modifier) { |
| 2244 | case DRM_FORMAT_MOD_NONE: |
| 2245 | tile_height = 1; |
| 2246 | break; |
| 2247 | case I915_FORMAT_MOD_X_TILED: |
| 2248 | tile_height = IS_GEN2(dev) ? 16 : 8; |
| 2249 | break; |
| 2250 | case I915_FORMAT_MOD_Y_TILED: |
| 2251 | tile_height = 32; |
| 2252 | break; |
| 2253 | case I915_FORMAT_MOD_Yf_TILED: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 2254 | pixel_bytes = drm_format_plane_cpp(pixel_format, 0); |
| 2255 | switch (pixel_bytes) { |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2256 | default: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 2257 | case 1: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2258 | tile_height = 64; |
| 2259 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 2260 | case 2: |
| 2261 | case 4: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2262 | tile_height = 32; |
| 2263 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 2264 | case 8: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2265 | tile_height = 16; |
| 2266 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 2267 | case 16: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2268 | WARN_ONCE(1, |
| 2269 | "128-bit pixels are not supported for display!"); |
| 2270 | tile_height = 16; |
| 2271 | break; |
| 2272 | } |
| 2273 | break; |
| 2274 | default: |
| 2275 | MISSING_CASE(fb_format_modifier); |
| 2276 | tile_height = 1; |
| 2277 | break; |
| 2278 | } |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 2279 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 2280 | return tile_height; |
| 2281 | } |
| 2282 | |
| 2283 | unsigned int |
| 2284 | intel_fb_align_height(struct drm_device *dev, unsigned int height, |
| 2285 | uint32_t pixel_format, uint64_t fb_format_modifier) |
| 2286 | { |
| 2287 | return ALIGN(height, intel_tile_height(dev, pixel_format, |
| 2288 | fb_format_modifier)); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2289 | } |
| 2290 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2291 | int |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2292 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
| 2293 | struct drm_framebuffer *fb, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2294 | struct intel_engine_cs *pipelined) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2295 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2296 | struct drm_device *dev = fb->dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2297 | struct drm_i915_private *dev_priv = dev->dev_private; |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2298 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2299 | u32 alignment; |
| 2300 | int ret; |
| 2301 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2302 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2303 | |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2304 | switch (fb->modifier[0]) { |
| 2305 | case DRM_FORMAT_MOD_NONE: |
Damien Lespiau | 1fada4c | 2013-07-03 21:06:02 +0100 | [diff] [blame] | 2306 | if (INTEL_INFO(dev)->gen >= 9) |
| 2307 | alignment = 256 * 1024; |
| 2308 | else if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2309 | alignment = 128 * 1024; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2310 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2311 | alignment = 4 * 1024; |
| 2312 | else |
| 2313 | alignment = 64 * 1024; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2314 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2315 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | 1fada4c | 2013-07-03 21:06:02 +0100 | [diff] [blame] | 2316 | if (INTEL_INFO(dev)->gen >= 9) |
| 2317 | alignment = 256 * 1024; |
| 2318 | else { |
| 2319 | /* pin() will align the object as required by fence */ |
| 2320 | alignment = 0; |
| 2321 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2322 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2323 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | 1327b9a | 2015-02-27 11:15:20 +0000 | [diff] [blame] | 2324 | case I915_FORMAT_MOD_Yf_TILED: |
| 2325 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, |
| 2326 | "Y tiling bo slipped through, driver bug!\n")) |
| 2327 | return -EINVAL; |
| 2328 | alignment = 1 * 1024 * 1024; |
| 2329 | break; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2330 | default: |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2331 | MISSING_CASE(fb->modifier[0]); |
| 2332 | return -EINVAL; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2333 | } |
| 2334 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2335 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2336 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2337 | * we should always have valid PTE following the scanout preventing |
| 2338 | * the VT-d warning. |
| 2339 | */ |
| 2340 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2341 | alignment = 256 * 1024; |
| 2342 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2343 | /* |
| 2344 | * Global gtt pte registers are special registers which actually forward |
| 2345 | * writes to a chunk of system memory. Which means that there is no risk |
| 2346 | * that the register values disappear as soon as we call |
| 2347 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2348 | * pin/unpin/fence and not more. |
| 2349 | */ |
| 2350 | intel_runtime_pm_get(dev_priv); |
| 2351 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2352 | dev_priv->mm.interruptible = false; |
Chris Wilson | 2da3b9b | 2011-04-14 09:41:17 +0100 | [diff] [blame] | 2353 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2354 | if (ret) |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2355 | goto err_interruptible; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2356 | |
| 2357 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2358 | * fence, whereas 965+ only requires a fence if using |
| 2359 | * framebuffer compression. For simplicity, we always install |
| 2360 | * a fence as the cost is not that onerous. |
| 2361 | */ |
Chris Wilson | 06d9813 | 2012-04-17 15:31:24 +0100 | [diff] [blame] | 2362 | ret = i915_gem_object_get_fence(obj); |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2363 | if (ret) |
| 2364 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2365 | |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2366 | i915_gem_object_pin_fence(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2367 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2368 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2369 | intel_runtime_pm_put(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2370 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2371 | |
| 2372 | err_unpin: |
Chris Wilson | cc98b41 | 2013-08-09 12:25:09 +0100 | [diff] [blame] | 2373 | i915_gem_object_unpin_from_display_plane(obj); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2374 | err_interruptible: |
| 2375 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2376 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2377 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2378 | } |
| 2379 | |
Damien Lespiau | f63bdb5 | 2015-02-10 19:32:24 +0000 | [diff] [blame] | 2380 | static void intel_unpin_fb_obj(struct drm_i915_gem_object *obj) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2381 | { |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2382 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2383 | |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2384 | i915_gem_object_unpin_fence(obj); |
Chris Wilson | cc98b41 | 2013-08-09 12:25:09 +0100 | [diff] [blame] | 2385 | i915_gem_object_unpin_from_display_plane(obj); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2386 | } |
| 2387 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2388 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
| 2389 | * is assumed to be a power-of-two. */ |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2390 | unsigned long intel_gen4_compute_page_offset(int *x, int *y, |
| 2391 | unsigned int tiling_mode, |
| 2392 | unsigned int cpp, |
| 2393 | unsigned int pitch) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2394 | { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2395 | if (tiling_mode != I915_TILING_NONE) { |
| 2396 | unsigned int tile_rows, tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2397 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2398 | tile_rows = *y / 8; |
| 2399 | *y %= 8; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2400 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2401 | tiles = *x / (512/cpp); |
| 2402 | *x %= 512/cpp; |
| 2403 | |
| 2404 | return tile_rows * pitch * 8 + tiles * 4096; |
| 2405 | } else { |
| 2406 | unsigned int offset; |
| 2407 | |
| 2408 | offset = *y * pitch + *x * cpp; |
| 2409 | *y = 0; |
| 2410 | *x = (offset & 4095) / cpp; |
| 2411 | return offset & -4096; |
| 2412 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2413 | } |
| 2414 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2415 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2416 | { |
| 2417 | switch (format) { |
| 2418 | case DISPPLANE_8BPP: |
| 2419 | return DRM_FORMAT_C8; |
| 2420 | case DISPPLANE_BGRX555: |
| 2421 | return DRM_FORMAT_XRGB1555; |
| 2422 | case DISPPLANE_BGRX565: |
| 2423 | return DRM_FORMAT_RGB565; |
| 2424 | default: |
| 2425 | case DISPPLANE_BGRX888: |
| 2426 | return DRM_FORMAT_XRGB8888; |
| 2427 | case DISPPLANE_RGBX888: |
| 2428 | return DRM_FORMAT_XBGR8888; |
| 2429 | case DISPPLANE_BGRX101010: |
| 2430 | return DRM_FORMAT_XRGB2101010; |
| 2431 | case DISPPLANE_RGBX101010: |
| 2432 | return DRM_FORMAT_XBGR2101010; |
| 2433 | } |
| 2434 | } |
| 2435 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2436 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
| 2437 | { |
| 2438 | switch (format) { |
| 2439 | case PLANE_CTL_FORMAT_RGB_565: |
| 2440 | return DRM_FORMAT_RGB565; |
| 2441 | default: |
| 2442 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2443 | if (rgb_order) { |
| 2444 | if (alpha) |
| 2445 | return DRM_FORMAT_ABGR8888; |
| 2446 | else |
| 2447 | return DRM_FORMAT_XBGR8888; |
| 2448 | } else { |
| 2449 | if (alpha) |
| 2450 | return DRM_FORMAT_ARGB8888; |
| 2451 | else |
| 2452 | return DRM_FORMAT_XRGB8888; |
| 2453 | } |
| 2454 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2455 | if (rgb_order) |
| 2456 | return DRM_FORMAT_XBGR2101010; |
| 2457 | else |
| 2458 | return DRM_FORMAT_XRGB2101010; |
| 2459 | } |
| 2460 | } |
| 2461 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2462 | static bool |
| 2463 | intel_alloc_plane_obj(struct intel_crtc *crtc, |
| 2464 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2465 | { |
| 2466 | struct drm_device *dev = crtc->base.dev; |
| 2467 | struct drm_i915_gem_object *obj = NULL; |
| 2468 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2469 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2470 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2471 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2472 | PAGE_SIZE); |
| 2473 | |
| 2474 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2475 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2476 | if (plane_config->size == 0) |
| 2477 | return false; |
| 2478 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2479 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
| 2480 | base_aligned, |
| 2481 | base_aligned, |
| 2482 | size_aligned); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2483 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2484 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2485 | |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 2486 | obj->tiling_mode = plane_config->tiling; |
| 2487 | if (obj->tiling_mode == I915_TILING_X) |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2488 | obj->stride = fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2489 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2490 | mode_cmd.pixel_format = fb->pixel_format; |
| 2491 | mode_cmd.width = fb->width; |
| 2492 | mode_cmd.height = fb->height; |
| 2493 | mode_cmd.pitches[0] = fb->pitches[0]; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2494 | mode_cmd.modifier[0] = fb->modifier[0]; |
| 2495 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2496 | |
| 2497 | mutex_lock(&dev->struct_mutex); |
| 2498 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2499 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2500 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2501 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2502 | goto out_unref_obj; |
| 2503 | } |
| 2504 | |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 2505 | obj->frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(crtc->pipe); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2506 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2507 | |
| 2508 | DRM_DEBUG_KMS("plane fb obj %p\n", obj); |
| 2509 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2510 | |
| 2511 | out_unref_obj: |
| 2512 | drm_gem_object_unreference(&obj->base); |
| 2513 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2514 | return false; |
| 2515 | } |
| 2516 | |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 2517 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
| 2518 | static void |
| 2519 | update_state_fb(struct drm_plane *plane) |
| 2520 | { |
| 2521 | if (plane->fb == plane->state->fb) |
| 2522 | return; |
| 2523 | |
| 2524 | if (plane->state->fb) |
| 2525 | drm_framebuffer_unreference(plane->state->fb); |
| 2526 | plane->state->fb = plane->fb; |
| 2527 | if (plane->state->fb) |
| 2528 | drm_framebuffer_reference(plane->state->fb); |
| 2529 | } |
| 2530 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2531 | static void |
| 2532 | intel_find_plane_obj(struct intel_crtc *intel_crtc, |
| 2533 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2534 | { |
| 2535 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | d9ceb81 | 2014-10-09 12:57:43 -0700 | [diff] [blame] | 2536 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2537 | struct drm_crtc *c; |
| 2538 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2539 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2540 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2541 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2542 | return; |
| 2543 | |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2544 | if (intel_alloc_plane_obj(intel_crtc, plane_config)) { |
Damien Lespiau | fb9981a | 2015-02-05 19:24:25 +0000 | [diff] [blame] | 2545 | struct drm_plane *primary = intel_crtc->base.primary; |
| 2546 | |
| 2547 | primary->fb = &plane_config->fb->base; |
| 2548 | primary->state->crtc = &intel_crtc->base; |
| 2549 | update_state_fb(primary); |
| 2550 | |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2551 | return; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2552 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2553 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2554 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2555 | |
| 2556 | /* |
| 2557 | * Failed to alloc the obj, check to see if we should share |
| 2558 | * an fb with another CRTC instead |
| 2559 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2560 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2561 | i = to_intel_crtc(c); |
| 2562 | |
| 2563 | if (c == &intel_crtc->base) |
| 2564 | continue; |
| 2565 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2566 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2567 | continue; |
| 2568 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2569 | obj = intel_fb_obj(c->primary->fb); |
| 2570 | if (obj == NULL) |
| 2571 | continue; |
| 2572 | |
| 2573 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
Damien Lespiau | fb9981a | 2015-02-05 19:24:25 +0000 | [diff] [blame] | 2574 | struct drm_plane *primary = intel_crtc->base.primary; |
| 2575 | |
Jesse Barnes | d9ceb81 | 2014-10-09 12:57:43 -0700 | [diff] [blame] | 2576 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2577 | dev_priv->preserve_bios_swizzle = true; |
| 2578 | |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2579 | drm_framebuffer_reference(c->primary->fb); |
Damien Lespiau | fb9981a | 2015-02-05 19:24:25 +0000 | [diff] [blame] | 2580 | primary->fb = c->primary->fb; |
| 2581 | primary->state->crtc = &intel_crtc->base; |
Damien Lespiau | 5ba76c4 | 2015-02-05 17:22:15 +0000 | [diff] [blame] | 2582 | update_state_fb(intel_crtc->base.primary); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2583 | obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2584 | break; |
| 2585 | } |
| 2586 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2587 | } |
| 2588 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2589 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
| 2590 | struct drm_framebuffer *fb, |
| 2591 | int x, int y) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2592 | { |
| 2593 | struct drm_device *dev = crtc->dev; |
| 2594 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2595 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2596 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2597 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2598 | unsigned long linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2599 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2600 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2601 | int pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2602 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2603 | if (!intel_crtc->primary_enabled) { |
| 2604 | I915_WRITE(reg, 0); |
| 2605 | if (INTEL_INFO(dev)->gen >= 4) |
| 2606 | I915_WRITE(DSPSURF(plane), 0); |
| 2607 | else |
| 2608 | I915_WRITE(DSPADDR(plane), 0); |
| 2609 | POSTING_READ(reg); |
| 2610 | return; |
| 2611 | } |
| 2612 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2613 | obj = intel_fb_obj(fb); |
| 2614 | if (WARN_ON(obj == NULL)) |
| 2615 | return; |
| 2616 | |
| 2617 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2618 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2619 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2620 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2621 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2622 | |
| 2623 | if (INTEL_INFO(dev)->gen < 4) { |
| 2624 | if (intel_crtc->pipe == PIPE_B) |
| 2625 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 2626 | |
| 2627 | /* pipesrc and dspsize control the size that is scaled from, |
| 2628 | * which should always be the user's requested size. |
| 2629 | */ |
| 2630 | I915_WRITE(DSPSIZE(plane), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2631 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
| 2632 | (intel_crtc->config->pipe_src_w - 1)); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2633 | I915_WRITE(DSPPOS(plane), 0); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2634 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
| 2635 | I915_WRITE(PRIMSIZE(plane), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2636 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
| 2637 | (intel_crtc->config->pipe_src_w - 1)); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2638 | I915_WRITE(PRIMPOS(plane), 0); |
| 2639 | I915_WRITE(PRIMCNSTALPHA(plane), 0); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2640 | } |
| 2641 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2642 | switch (fb->pixel_format) { |
| 2643 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2644 | dspcntr |= DISPPLANE_8BPP; |
| 2645 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2646 | case DRM_FORMAT_XRGB1555: |
| 2647 | case DRM_FORMAT_ARGB1555: |
| 2648 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2649 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2650 | case DRM_FORMAT_RGB565: |
| 2651 | dspcntr |= DISPPLANE_BGRX565; |
| 2652 | break; |
| 2653 | case DRM_FORMAT_XRGB8888: |
| 2654 | case DRM_FORMAT_ARGB8888: |
| 2655 | dspcntr |= DISPPLANE_BGRX888; |
| 2656 | break; |
| 2657 | case DRM_FORMAT_XBGR8888: |
| 2658 | case DRM_FORMAT_ABGR8888: |
| 2659 | dspcntr |= DISPPLANE_RGBX888; |
| 2660 | break; |
| 2661 | case DRM_FORMAT_XRGB2101010: |
| 2662 | case DRM_FORMAT_ARGB2101010: |
| 2663 | dspcntr |= DISPPLANE_BGRX101010; |
| 2664 | break; |
| 2665 | case DRM_FORMAT_XBGR2101010: |
| 2666 | case DRM_FORMAT_ABGR2101010: |
| 2667 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2668 | break; |
| 2669 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2670 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2671 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2672 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2673 | if (INTEL_INFO(dev)->gen >= 4 && |
| 2674 | obj->tiling_mode != I915_TILING_NONE) |
| 2675 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2676 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 2677 | if (IS_G4X(dev)) |
| 2678 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2679 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2680 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2681 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2682 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2683 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2684 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2685 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2686 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2687 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2688 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2689 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2690 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2691 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2692 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2693 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2694 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2695 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2696 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2697 | |
| 2698 | /* Finding the last pixel of the last line of the display |
| 2699 | data and adding to linear_offset*/ |
| 2700 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2701 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2702 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2703 | } |
| 2704 | |
| 2705 | I915_WRITE(reg, dspcntr); |
| 2706 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2707 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2708 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2709 | I915_WRITE(DSPSURF(plane), |
| 2710 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2711 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2712 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2713 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2714 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2715 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2718 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
| 2719 | struct drm_framebuffer *fb, |
| 2720 | int x, int y) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2721 | { |
| 2722 | struct drm_device *dev = crtc->dev; |
| 2723 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2724 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2725 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2726 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2727 | unsigned long linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2728 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2729 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2730 | int pixel_size; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2731 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2732 | if (!intel_crtc->primary_enabled) { |
| 2733 | I915_WRITE(reg, 0); |
| 2734 | I915_WRITE(DSPSURF(plane), 0); |
| 2735 | POSTING_READ(reg); |
| 2736 | return; |
| 2737 | } |
| 2738 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2739 | obj = intel_fb_obj(fb); |
| 2740 | if (WARN_ON(obj == NULL)) |
| 2741 | return; |
| 2742 | |
| 2743 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2744 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2745 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2746 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2747 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2748 | |
| 2749 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 2750 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 2751 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2752 | switch (fb->pixel_format) { |
| 2753 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2754 | dspcntr |= DISPPLANE_8BPP; |
| 2755 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2756 | case DRM_FORMAT_RGB565: |
| 2757 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2758 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2759 | case DRM_FORMAT_XRGB8888: |
| 2760 | case DRM_FORMAT_ARGB8888: |
| 2761 | dspcntr |= DISPPLANE_BGRX888; |
| 2762 | break; |
| 2763 | case DRM_FORMAT_XBGR8888: |
| 2764 | case DRM_FORMAT_ABGR8888: |
| 2765 | dspcntr |= DISPPLANE_RGBX888; |
| 2766 | break; |
| 2767 | case DRM_FORMAT_XRGB2101010: |
| 2768 | case DRM_FORMAT_ARGB2101010: |
| 2769 | dspcntr |= DISPPLANE_BGRX101010; |
| 2770 | break; |
| 2771 | case DRM_FORMAT_XBGR2101010: |
| 2772 | case DRM_FORMAT_ABGR2101010: |
| 2773 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2774 | break; |
| 2775 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2776 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2780 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2781 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2782 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 2783 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2784 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2785 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2786 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2787 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2788 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2789 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2790 | linear_offset -= intel_crtc->dspaddr_offset; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2791 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2792 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2793 | |
| 2794 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2795 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2796 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2797 | |
| 2798 | /* Finding the last pixel of the last line of the display |
| 2799 | data and adding to linear_offset*/ |
| 2800 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2801 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2802 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2803 | } |
| 2804 | } |
| 2805 | |
| 2806 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2807 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2808 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2809 | I915_WRITE(DSPSURF(plane), |
| 2810 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 2811 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2812 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2813 | } else { |
| 2814 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2815 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2816 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2817 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2818 | } |
| 2819 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2820 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
| 2821 | uint32_t pixel_format) |
| 2822 | { |
| 2823 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; |
| 2824 | |
| 2825 | /* |
| 2826 | * The stride is either expressed as a multiple of 64 bytes |
| 2827 | * chunks for linear buffers or in number of tiles for tiled |
| 2828 | * buffers. |
| 2829 | */ |
| 2830 | switch (fb_modifier) { |
| 2831 | case DRM_FORMAT_MOD_NONE: |
| 2832 | return 64; |
| 2833 | case I915_FORMAT_MOD_X_TILED: |
| 2834 | if (INTEL_INFO(dev)->gen == 2) |
| 2835 | return 128; |
| 2836 | return 512; |
| 2837 | case I915_FORMAT_MOD_Y_TILED: |
| 2838 | /* No need to check for old gens and Y tiling since this is |
| 2839 | * about the display engine and those will be blocked before |
| 2840 | * we get here. |
| 2841 | */ |
| 2842 | return 128; |
| 2843 | case I915_FORMAT_MOD_Yf_TILED: |
| 2844 | if (bits_per_pixel == 8) |
| 2845 | return 64; |
| 2846 | else |
| 2847 | return 128; |
| 2848 | default: |
| 2849 | MISSING_CASE(fb_modifier); |
| 2850 | return 64; |
| 2851 | } |
| 2852 | } |
| 2853 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2854 | static void skylake_update_primary_plane(struct drm_crtc *crtc, |
| 2855 | struct drm_framebuffer *fb, |
| 2856 | int x, int y) |
| 2857 | { |
| 2858 | struct drm_device *dev = crtc->dev; |
| 2859 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2860 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2861 | struct drm_i915_gem_object *obj; |
| 2862 | int pipe = intel_crtc->pipe; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2863 | u32 plane_ctl, stride_div; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2864 | |
| 2865 | if (!intel_crtc->primary_enabled) { |
| 2866 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
| 2867 | I915_WRITE(PLANE_SURF(pipe, 0), 0); |
| 2868 | POSTING_READ(PLANE_CTL(pipe, 0)); |
| 2869 | return; |
| 2870 | } |
| 2871 | |
| 2872 | plane_ctl = PLANE_CTL_ENABLE | |
| 2873 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 2874 | PLANE_CTL_PIPE_CSC_ENABLE; |
| 2875 | |
| 2876 | switch (fb->pixel_format) { |
| 2877 | case DRM_FORMAT_RGB565: |
| 2878 | plane_ctl |= PLANE_CTL_FORMAT_RGB_565; |
| 2879 | break; |
| 2880 | case DRM_FORMAT_XRGB8888: |
| 2881 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2882 | break; |
Jani Nikula | f75fb42 | 2015-02-10 13:15:49 +0200 | [diff] [blame] | 2883 | case DRM_FORMAT_ARGB8888: |
| 2884 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2885 | plane_ctl |= PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 2886 | break; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2887 | case DRM_FORMAT_XBGR8888: |
| 2888 | plane_ctl |= PLANE_CTL_ORDER_RGBX; |
| 2889 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2890 | break; |
Jani Nikula | f75fb42 | 2015-02-10 13:15:49 +0200 | [diff] [blame] | 2891 | case DRM_FORMAT_ABGR8888: |
| 2892 | plane_ctl |= PLANE_CTL_ORDER_RGBX; |
| 2893 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2894 | plane_ctl |= PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 2895 | break; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2896 | case DRM_FORMAT_XRGB2101010: |
| 2897 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_2101010; |
| 2898 | break; |
| 2899 | case DRM_FORMAT_XBGR2101010: |
| 2900 | plane_ctl |= PLANE_CTL_ORDER_RGBX; |
| 2901 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_2101010; |
| 2902 | break; |
| 2903 | default: |
| 2904 | BUG(); |
| 2905 | } |
| 2906 | |
Daniel Vetter | 30af77c | 2015-02-10 17:16:11 +0000 | [diff] [blame] | 2907 | switch (fb->modifier[0]) { |
| 2908 | case DRM_FORMAT_MOD_NONE: |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2909 | break; |
Daniel Vetter | 30af77c | 2015-02-10 17:16:11 +0000 | [diff] [blame] | 2910 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2911 | plane_ctl |= PLANE_CTL_TILED_X; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2912 | break; |
| 2913 | case I915_FORMAT_MOD_Y_TILED: |
| 2914 | plane_ctl |= PLANE_CTL_TILED_Y; |
| 2915 | break; |
| 2916 | case I915_FORMAT_MOD_Yf_TILED: |
| 2917 | plane_ctl |= PLANE_CTL_TILED_YF; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2918 | break; |
| 2919 | default: |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2920 | MISSING_CASE(fb->modifier[0]); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2921 | } |
| 2922 | |
| 2923 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2924 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) |
Sonika Jindal | 1447dde | 2014-10-04 10:53:31 +0100 | [diff] [blame] | 2925 | plane_ctl |= PLANE_CTL_ROTATE_180; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2926 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2927 | obj = intel_fb_obj(fb); |
| 2928 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 2929 | fb->pixel_format); |
| 2930 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2931 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
| 2932 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2933 | I915_WRITE(PLANE_POS(pipe, 0), 0); |
| 2934 | I915_WRITE(PLANE_OFFSET(pipe, 0), (y << 16) | x); |
| 2935 | I915_WRITE(PLANE_SIZE(pipe, 0), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2936 | (intel_crtc->config->pipe_src_h - 1) << 16 | |
| 2937 | (intel_crtc->config->pipe_src_w - 1)); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2938 | I915_WRITE(PLANE_STRIDE(pipe, 0), fb->pitches[0] / stride_div); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2939 | I915_WRITE(PLANE_SURF(pipe, 0), i915_gem_obj_ggtt_offset(obj)); |
| 2940 | |
| 2941 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 2942 | } |
| 2943 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2944 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 2945 | static int |
| 2946 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 2947 | int x, int y, enum mode_set_atomic state) |
| 2948 | { |
| 2949 | struct drm_device *dev = crtc->dev; |
| 2950 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2951 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 2952 | if (dev_priv->display.disable_fbc) |
| 2953 | dev_priv->display.disable_fbc(dev); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2954 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2955 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
| 2956 | |
| 2957 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2958 | } |
| 2959 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 2960 | static void intel_complete_page_flips(struct drm_device *dev) |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2961 | { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2962 | struct drm_crtc *crtc; |
| 2963 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2964 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2965 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2966 | enum plane plane = intel_crtc->plane; |
| 2967 | |
| 2968 | intel_prepare_page_flip(dev, plane); |
| 2969 | intel_finish_page_flip_plane(dev, plane); |
| 2970 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 2971 | } |
| 2972 | |
| 2973 | static void intel_update_primary_planes(struct drm_device *dev) |
| 2974 | { |
| 2975 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2976 | struct drm_crtc *crtc; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2977 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2978 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2979 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2980 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 2981 | drm_modeset_lock(&crtc->mutex, NULL); |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 2982 | /* |
| 2983 | * FIXME: Once we have proper support for primary planes (and |
| 2984 | * disabling them without disabling the entire crtc) allow again |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2985 | * a NULL crtc->primary->fb. |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 2986 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 2987 | if (intel_crtc->active && crtc->primary->fb) |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2988 | dev_priv->display.update_primary_plane(crtc, |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 2989 | crtc->primary->fb, |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2990 | crtc->x, |
| 2991 | crtc->y); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 2992 | drm_modeset_unlock(&crtc->mutex); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 2993 | } |
| 2994 | } |
| 2995 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 2996 | void intel_prepare_reset(struct drm_device *dev) |
| 2997 | { |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 2998 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 2999 | struct intel_crtc *crtc; |
| 3000 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3001 | /* no reset support for gen2 */ |
| 3002 | if (IS_GEN2(dev)) |
| 3003 | return; |
| 3004 | |
| 3005 | /* reset doesn't touch the display */ |
| 3006 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
| 3007 | return; |
| 3008 | |
| 3009 | drm_modeset_lock_all(dev); |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3010 | |
| 3011 | /* |
| 3012 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3013 | * g33 docs say we should at least disable all the planes. |
| 3014 | */ |
| 3015 | for_each_intel_crtc(dev, crtc) { |
| 3016 | if (crtc->active) |
| 3017 | dev_priv->display.crtc_disable(&crtc->base); |
| 3018 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | void intel_finish_reset(struct drm_device *dev) |
| 3022 | { |
| 3023 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3024 | |
| 3025 | /* |
| 3026 | * Flips in the rings will be nuked by the reset, |
| 3027 | * so complete all pending flips so that user space |
| 3028 | * will get its events and not get stuck. |
| 3029 | */ |
| 3030 | intel_complete_page_flips(dev); |
| 3031 | |
| 3032 | /* no reset support for gen2 */ |
| 3033 | if (IS_GEN2(dev)) |
| 3034 | return; |
| 3035 | |
| 3036 | /* reset doesn't touch the display */ |
| 3037 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { |
| 3038 | /* |
| 3039 | * Flips in the rings have been nuked by the reset, |
| 3040 | * so update the base address of all primary |
| 3041 | * planes to the the last fb to make sure we're |
| 3042 | * showing the correct fb after a reset. |
| 3043 | */ |
| 3044 | intel_update_primary_planes(dev); |
| 3045 | return; |
| 3046 | } |
| 3047 | |
| 3048 | /* |
| 3049 | * The display has been reset as well, |
| 3050 | * so need a full re-initialization. |
| 3051 | */ |
| 3052 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3053 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3054 | |
| 3055 | intel_modeset_init_hw(dev); |
| 3056 | |
| 3057 | spin_lock_irq(&dev_priv->irq_lock); |
| 3058 | if (dev_priv->display.hpd_irq_setup) |
| 3059 | dev_priv->display.hpd_irq_setup(dev); |
| 3060 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3061 | |
| 3062 | intel_modeset_setup_hw_state(dev, true); |
| 3063 | |
| 3064 | intel_hpd_init(dev_priv); |
| 3065 | |
| 3066 | drm_modeset_unlock_all(dev); |
| 3067 | } |
| 3068 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 3069 | static int |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3070 | intel_finish_fb(struct drm_framebuffer *old_fb) |
| 3071 | { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 3072 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3073 | struct drm_i915_private *dev_priv = obj->base.dev->dev_private; |
| 3074 | bool was_interruptible = dev_priv->mm.interruptible; |
| 3075 | int ret; |
| 3076 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3077 | /* Big Hammer, we also need to ensure that any pending |
| 3078 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 3079 | * current scanout is retired before unpinning the old |
| 3080 | * framebuffer. |
| 3081 | * |
| 3082 | * This should only fail upon a hung GPU, in which case we |
| 3083 | * can safely continue. |
| 3084 | */ |
| 3085 | dev_priv->mm.interruptible = false; |
| 3086 | ret = i915_gem_object_finish_gpu(obj); |
| 3087 | dev_priv->mm.interruptible = was_interruptible; |
| 3088 | |
| 3089 | return ret; |
| 3090 | } |
| 3091 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3092 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 3093 | { |
| 3094 | struct drm_device *dev = crtc->dev; |
| 3095 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3096 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3097 | bool pending; |
| 3098 | |
| 3099 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 3100 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 3101 | return false; |
| 3102 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3103 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3104 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3105 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3106 | |
| 3107 | return pending; |
| 3108 | } |
| 3109 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3110 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
| 3111 | { |
| 3112 | struct drm_device *dev = crtc->base.dev; |
| 3113 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3114 | const struct drm_display_mode *adjusted_mode; |
| 3115 | |
| 3116 | if (!i915.fastboot) |
| 3117 | return; |
| 3118 | |
| 3119 | /* |
| 3120 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3121 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3122 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3123 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3124 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3125 | * sized surface. |
| 3126 | * |
| 3127 | * To fix this properly, we need to hoist the checks up into |
| 3128 | * compute_mode_changes (or above), check the actual pfit state and |
| 3129 | * whether the platform allows pfit disable with pipe active, and only |
| 3130 | * then update the pipesrc and pfit state, even on the flip path. |
| 3131 | */ |
| 3132 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3133 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3134 | |
| 3135 | I915_WRITE(PIPESRC(crtc->pipe), |
| 3136 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | |
| 3137 | (adjusted_mode->crtc_vdisplay - 1)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3138 | if (!crtc->config->pch_pfit.enabled && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 3139 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
| 3140 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3141 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
| 3142 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); |
| 3143 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); |
| 3144 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3145 | crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay; |
| 3146 | crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3147 | } |
| 3148 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3149 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 3150 | { |
| 3151 | struct drm_device *dev = crtc->dev; |
| 3152 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3153 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3154 | int pipe = intel_crtc->pipe; |
| 3155 | u32 reg, temp; |
| 3156 | |
| 3157 | /* enable normal train */ |
| 3158 | reg = FDI_TX_CTL(pipe); |
| 3159 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3160 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3161 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3162 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3163 | } else { |
| 3164 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3165 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3166 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3167 | I915_WRITE(reg, temp); |
| 3168 | |
| 3169 | reg = FDI_RX_CTL(pipe); |
| 3170 | temp = I915_READ(reg); |
| 3171 | if (HAS_PCH_CPT(dev)) { |
| 3172 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3173 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3174 | } else { |
| 3175 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3176 | temp |= FDI_LINK_TRAIN_NONE; |
| 3177 | } |
| 3178 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3179 | |
| 3180 | /* wait one idle pattern time */ |
| 3181 | POSTING_READ(reg); |
| 3182 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3183 | |
| 3184 | /* IVB wants error correction enabled */ |
| 3185 | if (IS_IVYBRIDGE(dev)) |
| 3186 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3187 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3188 | } |
| 3189 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3190 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 3191 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 3192 | { |
| 3193 | struct drm_device *dev = crtc->dev; |
| 3194 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3195 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3196 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3197 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3198 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3199 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3200 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3201 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3202 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3203 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3204 | reg = FDI_RX_IMR(pipe); |
| 3205 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3206 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3207 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3208 | I915_WRITE(reg, temp); |
| 3209 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3210 | udelay(150); |
| 3211 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3212 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3213 | reg = FDI_TX_CTL(pipe); |
| 3214 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3215 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3216 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3217 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3218 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3219 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3220 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3221 | reg = FDI_RX_CTL(pipe); |
| 3222 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3223 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3224 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3225 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3226 | |
| 3227 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3228 | udelay(150); |
| 3229 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3230 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3231 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3232 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3233 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3234 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3235 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3236 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3237 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3238 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3239 | |
| 3240 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3241 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3242 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3243 | break; |
| 3244 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3245 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3246 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3247 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3248 | |
| 3249 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3250 | reg = FDI_TX_CTL(pipe); |
| 3251 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3252 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3253 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3254 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3255 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3256 | reg = FDI_RX_CTL(pipe); |
| 3257 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3258 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3259 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3260 | I915_WRITE(reg, temp); |
| 3261 | |
| 3262 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3263 | udelay(150); |
| 3264 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3265 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3266 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3267 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3268 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3269 | |
| 3270 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3271 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3272 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3273 | break; |
| 3274 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3275 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3276 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3277 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3278 | |
| 3279 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3280 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3281 | } |
| 3282 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3283 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3284 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3285 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3286 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3287 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3288 | }; |
| 3289 | |
| 3290 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3291 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3292 | { |
| 3293 | struct drm_device *dev = crtc->dev; |
| 3294 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3295 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3296 | int pipe = intel_crtc->pipe; |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3297 | u32 reg, temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3298 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3299 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3300 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3301 | reg = FDI_RX_IMR(pipe); |
| 3302 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3303 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3304 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3305 | I915_WRITE(reg, temp); |
| 3306 | |
| 3307 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3308 | udelay(150); |
| 3309 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3310 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3311 | reg = FDI_TX_CTL(pipe); |
| 3312 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3313 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3314 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3315 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3316 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3317 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3318 | /* SNB-B */ |
| 3319 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3320 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3321 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3322 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3323 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3324 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3325 | reg = FDI_RX_CTL(pipe); |
| 3326 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3327 | if (HAS_PCH_CPT(dev)) { |
| 3328 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3329 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3330 | } else { |
| 3331 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3332 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3333 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3334 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3335 | |
| 3336 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3337 | udelay(150); |
| 3338 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3339 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3340 | reg = FDI_TX_CTL(pipe); |
| 3341 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3342 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3343 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3344 | I915_WRITE(reg, temp); |
| 3345 | |
| 3346 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3347 | udelay(500); |
| 3348 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3349 | for (retry = 0; retry < 5; retry++) { |
| 3350 | reg = FDI_RX_IIR(pipe); |
| 3351 | temp = I915_READ(reg); |
| 3352 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3353 | if (temp & FDI_RX_BIT_LOCK) { |
| 3354 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3355 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3356 | break; |
| 3357 | } |
| 3358 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3359 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3360 | if (retry < 5) |
| 3361 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3362 | } |
| 3363 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3364 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3365 | |
| 3366 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3367 | reg = FDI_TX_CTL(pipe); |
| 3368 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3369 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3370 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3371 | if (IS_GEN6(dev)) { |
| 3372 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3373 | /* SNB-B */ |
| 3374 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3375 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3376 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3377 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3378 | reg = FDI_RX_CTL(pipe); |
| 3379 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3380 | if (HAS_PCH_CPT(dev)) { |
| 3381 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3382 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3383 | } else { |
| 3384 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3385 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3386 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3387 | I915_WRITE(reg, temp); |
| 3388 | |
| 3389 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3390 | udelay(150); |
| 3391 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3392 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3393 | reg = FDI_TX_CTL(pipe); |
| 3394 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3395 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3396 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3397 | I915_WRITE(reg, temp); |
| 3398 | |
| 3399 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3400 | udelay(500); |
| 3401 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3402 | for (retry = 0; retry < 5; retry++) { |
| 3403 | reg = FDI_RX_IIR(pipe); |
| 3404 | temp = I915_READ(reg); |
| 3405 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3406 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3407 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3408 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3409 | break; |
| 3410 | } |
| 3411 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3412 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3413 | if (retry < 5) |
| 3414 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3415 | } |
| 3416 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3417 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3418 | |
| 3419 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3420 | } |
| 3421 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3422 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3423 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3424 | { |
| 3425 | struct drm_device *dev = crtc->dev; |
| 3426 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3427 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3428 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3429 | u32 reg, temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3430 | |
| 3431 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3432 | for train result */ |
| 3433 | reg = FDI_RX_IMR(pipe); |
| 3434 | temp = I915_READ(reg); |
| 3435 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3436 | temp &= ~FDI_RX_BIT_LOCK; |
| 3437 | I915_WRITE(reg, temp); |
| 3438 | |
| 3439 | POSTING_READ(reg); |
| 3440 | udelay(150); |
| 3441 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3442 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3443 | I915_READ(FDI_RX_IIR(pipe))); |
| 3444 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3445 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3446 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3447 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3448 | reg = FDI_TX_CTL(pipe); |
| 3449 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3450 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3451 | temp &= ~FDI_TX_ENABLE; |
| 3452 | I915_WRITE(reg, temp); |
| 3453 | |
| 3454 | reg = FDI_RX_CTL(pipe); |
| 3455 | temp = I915_READ(reg); |
| 3456 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3457 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3458 | temp &= ~FDI_RX_ENABLE; |
| 3459 | I915_WRITE(reg, temp); |
| 3460 | |
| 3461 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3462 | reg = FDI_TX_CTL(pipe); |
| 3463 | temp = I915_READ(reg); |
| 3464 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3465 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3466 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3467 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3468 | temp |= snb_b_fdi_train_param[j/2]; |
| 3469 | temp |= FDI_COMPOSITE_SYNC; |
| 3470 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3471 | |
| 3472 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3473 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3474 | |
| 3475 | reg = FDI_RX_CTL(pipe); |
| 3476 | temp = I915_READ(reg); |
| 3477 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3478 | temp |= FDI_COMPOSITE_SYNC; |
| 3479 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3480 | |
| 3481 | POSTING_READ(reg); |
| 3482 | udelay(1); /* should be 0.5us */ |
| 3483 | |
| 3484 | for (i = 0; i < 4; i++) { |
| 3485 | reg = FDI_RX_IIR(pipe); |
| 3486 | temp = I915_READ(reg); |
| 3487 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3488 | |
| 3489 | if (temp & FDI_RX_BIT_LOCK || |
| 3490 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3491 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3492 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3493 | i); |
| 3494 | break; |
| 3495 | } |
| 3496 | udelay(1); /* should be 0.5us */ |
| 3497 | } |
| 3498 | if (i == 4) { |
| 3499 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3500 | continue; |
| 3501 | } |
| 3502 | |
| 3503 | /* Train 2 */ |
| 3504 | reg = FDI_TX_CTL(pipe); |
| 3505 | temp = I915_READ(reg); |
| 3506 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3507 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3508 | I915_WRITE(reg, temp); |
| 3509 | |
| 3510 | reg = FDI_RX_CTL(pipe); |
| 3511 | temp = I915_READ(reg); |
| 3512 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3513 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3514 | I915_WRITE(reg, temp); |
| 3515 | |
| 3516 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3517 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3518 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3519 | for (i = 0; i < 4; i++) { |
| 3520 | reg = FDI_RX_IIR(pipe); |
| 3521 | temp = I915_READ(reg); |
| 3522 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3523 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3524 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3525 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3526 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3527 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3528 | i); |
| 3529 | goto train_done; |
| 3530 | } |
| 3531 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3532 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3533 | if (i == 4) |
| 3534 | 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] | 3535 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3536 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3537 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3538 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3539 | } |
| 3540 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3541 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3542 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3543 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3544 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3545 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3546 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3547 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3548 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3549 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3550 | reg = FDI_RX_CTL(pipe); |
| 3551 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3552 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3553 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3554 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3555 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3556 | |
| 3557 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3558 | udelay(200); |
| 3559 | |
| 3560 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3561 | temp = I915_READ(reg); |
| 3562 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3563 | |
| 3564 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3565 | udelay(200); |
| 3566 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3567 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3568 | reg = FDI_TX_CTL(pipe); |
| 3569 | temp = I915_READ(reg); |
| 3570 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3571 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3572 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3573 | POSTING_READ(reg); |
| 3574 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3575 | } |
| 3576 | } |
| 3577 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3578 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3579 | { |
| 3580 | struct drm_device *dev = intel_crtc->base.dev; |
| 3581 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3582 | int pipe = intel_crtc->pipe; |
| 3583 | u32 reg, temp; |
| 3584 | |
| 3585 | /* Switch from PCDclk to Rawclk */ |
| 3586 | reg = FDI_RX_CTL(pipe); |
| 3587 | temp = I915_READ(reg); |
| 3588 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3589 | |
| 3590 | /* Disable CPU FDI TX PLL */ |
| 3591 | reg = FDI_TX_CTL(pipe); |
| 3592 | temp = I915_READ(reg); |
| 3593 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3594 | |
| 3595 | POSTING_READ(reg); |
| 3596 | udelay(100); |
| 3597 | |
| 3598 | reg = FDI_RX_CTL(pipe); |
| 3599 | temp = I915_READ(reg); |
| 3600 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3601 | |
| 3602 | /* Wait for the clocks to turn off. */ |
| 3603 | POSTING_READ(reg); |
| 3604 | udelay(100); |
| 3605 | } |
| 3606 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3607 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3608 | { |
| 3609 | struct drm_device *dev = crtc->dev; |
| 3610 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3611 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3612 | int pipe = intel_crtc->pipe; |
| 3613 | u32 reg, temp; |
| 3614 | |
| 3615 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3616 | reg = FDI_TX_CTL(pipe); |
| 3617 | temp = I915_READ(reg); |
| 3618 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3619 | POSTING_READ(reg); |
| 3620 | |
| 3621 | reg = FDI_RX_CTL(pipe); |
| 3622 | temp = I915_READ(reg); |
| 3623 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3624 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3625 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3626 | |
| 3627 | POSTING_READ(reg); |
| 3628 | udelay(100); |
| 3629 | |
| 3630 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3631 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3632 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3633 | |
| 3634 | /* still set train pattern 1 */ |
| 3635 | reg = FDI_TX_CTL(pipe); |
| 3636 | temp = I915_READ(reg); |
| 3637 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3638 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3639 | I915_WRITE(reg, temp); |
| 3640 | |
| 3641 | reg = FDI_RX_CTL(pipe); |
| 3642 | temp = I915_READ(reg); |
| 3643 | if (HAS_PCH_CPT(dev)) { |
| 3644 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3645 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3646 | } else { |
| 3647 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3648 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3649 | } |
| 3650 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3651 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3652 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3653 | I915_WRITE(reg, temp); |
| 3654 | |
| 3655 | POSTING_READ(reg); |
| 3656 | udelay(100); |
| 3657 | } |
| 3658 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3659 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3660 | { |
| 3661 | struct intel_crtc *crtc; |
| 3662 | |
| 3663 | /* Note that we don't need to be called with mode_config.lock here |
| 3664 | * as our list of CRTC objects is static for the lifetime of the |
| 3665 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3666 | * happily treat the predicates as racy, atomic checks as userspace |
| 3667 | * cannot claim and pin a new fb without at least acquring the |
| 3668 | * struct_mutex and so serialising with us. |
| 3669 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3670 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3671 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3672 | continue; |
| 3673 | |
| 3674 | if (crtc->unpin_work) |
| 3675 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3676 | |
| 3677 | return true; |
| 3678 | } |
| 3679 | |
| 3680 | return false; |
| 3681 | } |
| 3682 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3683 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
| 3684 | { |
| 3685 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 3686 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 3687 | |
| 3688 | /* ensure that the unpin work is consistent wrt ->pending. */ |
| 3689 | smp_rmb(); |
| 3690 | intel_crtc->unpin_work = NULL; |
| 3691 | |
| 3692 | if (work->event) |
| 3693 | drm_send_vblank_event(intel_crtc->base.dev, |
| 3694 | intel_crtc->pipe, |
| 3695 | work->event); |
| 3696 | |
| 3697 | drm_crtc_vblank_put(&intel_crtc->base); |
| 3698 | |
| 3699 | wake_up_all(&dev_priv->pending_flip_queue); |
| 3700 | queue_work(dev_priv->wq, &work->work); |
| 3701 | |
| 3702 | trace_i915_flip_complete(intel_crtc->plane, |
| 3703 | work->pending_flip_obj); |
| 3704 | } |
| 3705 | |
Ville Syrjälä | 46a55d3 | 2014-05-21 14:04:46 +0300 | [diff] [blame] | 3706 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3707 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3708 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3709 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3710 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3711 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3712 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
| 3713 | !intel_crtc_has_pending_flip(crtc), |
| 3714 | 60*HZ) == 0)) { |
| 3715 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3716 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3717 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3718 | if (intel_crtc->unpin_work) { |
| 3719 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 3720 | page_flip_completed(intel_crtc); |
| 3721 | } |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3722 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3723 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3724 | |
Chris Wilson | 975d568 | 2014-08-20 13:13:34 +0100 | [diff] [blame] | 3725 | if (crtc->primary->fb) { |
| 3726 | mutex_lock(&dev->struct_mutex); |
| 3727 | intel_finish_fb(crtc->primary->fb); |
| 3728 | mutex_unlock(&dev->struct_mutex); |
| 3729 | } |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3730 | } |
| 3731 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3732 | /* Program iCLKIP clock to the desired frequency */ |
| 3733 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3734 | { |
| 3735 | struct drm_device *dev = crtc->dev; |
| 3736 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3737 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3738 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3739 | u32 temp; |
| 3740 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3741 | mutex_lock(&dev_priv->dpio_lock); |
| 3742 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3743 | /* It is necessary to ungate the pixclk gate prior to programming |
| 3744 | * the divisors, and gate it back when it is done. |
| 3745 | */ |
| 3746 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3747 | |
| 3748 | /* Disable SSCCTL */ |
| 3749 | intel_sbi_write(dev_priv, SBI_SSCCTL6, |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3750 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
| 3751 | SBI_SSCCTL_DISABLE, |
| 3752 | SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3753 | |
| 3754 | /* 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] | 3755 | if (clock == 20000) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3756 | auxdiv = 1; |
| 3757 | divsel = 0x41; |
| 3758 | phaseinc = 0x20; |
| 3759 | } else { |
| 3760 | /* The iCLK virtual clock root frequency is in MHz, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 3761 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3762 | * divisors, it is necessary to divide one by another, so we |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3763 | * convert the virtual clock precision to KHz here for higher |
| 3764 | * precision. |
| 3765 | */ |
| 3766 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3767 | u32 iclk_pi_range = 64; |
| 3768 | u32 desired_divisor, msb_divisor_value, pi_value; |
| 3769 | |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 3770 | desired_divisor = (iclk_virtual_root_freq / clock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3771 | msb_divisor_value = desired_divisor / iclk_pi_range; |
| 3772 | pi_value = desired_divisor % iclk_pi_range; |
| 3773 | |
| 3774 | auxdiv = 0; |
| 3775 | divsel = msb_divisor_value - 2; |
| 3776 | phaseinc = pi_value; |
| 3777 | } |
| 3778 | |
| 3779 | /* This should not happen with any sane values */ |
| 3780 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 3781 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 3782 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 3783 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 3784 | |
| 3785 | 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] | 3786 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3787 | auxdiv, |
| 3788 | divsel, |
| 3789 | phasedir, |
| 3790 | phaseinc); |
| 3791 | |
| 3792 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3793 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3794 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3795 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3796 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3797 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3798 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3799 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3800 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3801 | |
| 3802 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3803 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3804 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3805 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3806 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3807 | |
| 3808 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3809 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3810 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3811 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3812 | |
| 3813 | /* Wait for initialization time */ |
| 3814 | udelay(24); |
| 3815 | |
| 3816 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3817 | |
| 3818 | mutex_unlock(&dev_priv->dpio_lock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3819 | } |
| 3820 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3821 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 3822 | enum pipe pch_transcoder) |
| 3823 | { |
| 3824 | struct drm_device *dev = crtc->base.dev; |
| 3825 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3826 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3827 | |
| 3828 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 3829 | I915_READ(HTOTAL(cpu_transcoder))); |
| 3830 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 3831 | I915_READ(HBLANK(cpu_transcoder))); |
| 3832 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 3833 | I915_READ(HSYNC(cpu_transcoder))); |
| 3834 | |
| 3835 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 3836 | I915_READ(VTOTAL(cpu_transcoder))); |
| 3837 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 3838 | I915_READ(VBLANK(cpu_transcoder))); |
| 3839 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 3840 | I915_READ(VSYNC(cpu_transcoder))); |
| 3841 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 3842 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 3843 | } |
| 3844 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3845 | static void cpt_set_fdi_bc_bifurcation(struct drm_device *dev, bool enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3846 | { |
| 3847 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3848 | uint32_t temp; |
| 3849 | |
| 3850 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3851 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3852 | return; |
| 3853 | |
| 3854 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 3855 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 3856 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3857 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 3858 | if (enable) |
| 3859 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 3860 | |
| 3861 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3862 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 3863 | POSTING_READ(SOUTH_CHICKEN1); |
| 3864 | } |
| 3865 | |
| 3866 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 3867 | { |
| 3868 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3869 | |
| 3870 | switch (intel_crtc->pipe) { |
| 3871 | case PIPE_A: |
| 3872 | break; |
| 3873 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3874 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3875 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3876 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3877 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3878 | |
| 3879 | break; |
| 3880 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3881 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3882 | |
| 3883 | break; |
| 3884 | default: |
| 3885 | BUG(); |
| 3886 | } |
| 3887 | } |
| 3888 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3889 | /* |
| 3890 | * Enable PCH resources required for PCH ports: |
| 3891 | * - PCH PLLs |
| 3892 | * - FDI training & RX/TX |
| 3893 | * - update transcoder timings |
| 3894 | * - DP transcoding bits |
| 3895 | * - transcoder |
| 3896 | */ |
| 3897 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3898 | { |
| 3899 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3900 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3901 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3902 | int pipe = intel_crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3903 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3904 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 3905 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 3906 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3907 | if (IS_IVYBRIDGE(dev)) |
| 3908 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 3909 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 3910 | /* Write the TU size bits before fdi link training, so that error |
| 3911 | * detection works. */ |
| 3912 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 3913 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 3914 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3915 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 3916 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3917 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3918 | /* We need to program the right clock selection before writing the pixel |
| 3919 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3920 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3921 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 3922 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3923 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 3924 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 3925 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3926 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3927 | temp |= sel; |
| 3928 | else |
| 3929 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3930 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3931 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3932 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3933 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 3934 | * transcoder, and we actually should do this to not upset any PCH |
| 3935 | * transcoder that already use the clock when we share it. |
| 3936 | * |
| 3937 | * Note that enable_shared_dpll tries to do the right thing, but |
| 3938 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 3939 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 3940 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 3941 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 3942 | /* set transcoder timing, panel must allow it */ |
| 3943 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3944 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3945 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 3946 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3947 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3948 | /* For PCH DP, enable TRANS_DP_CTL */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3949 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3950 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3951 | reg = TRANS_DP_CTL(pipe); |
| 3952 | temp = I915_READ(reg); |
| 3953 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 3954 | TRANS_DP_SYNC_MASK | |
| 3955 | TRANS_DP_BPC_MASK); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3956 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
| 3957 | TRANS_DP_ENH_FRAMING); |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 3958 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3959 | |
| 3960 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3961 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3962 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3963 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3964 | |
| 3965 | switch (intel_trans_dp_port_sel(crtc)) { |
| 3966 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3967 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3968 | break; |
| 3969 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3970 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3971 | break; |
| 3972 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3973 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3974 | break; |
| 3975 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 3976 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3977 | } |
| 3978 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3979 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 3980 | } |
| 3981 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 3982 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3983 | } |
| 3984 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3985 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 3986 | { |
| 3987 | struct drm_device *dev = crtc->dev; |
| 3988 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3989 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3990 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3991 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 3992 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3993 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 3994 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3995 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 3996 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3997 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 3998 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 3999 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4000 | } |
| 4001 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 4002 | void intel_put_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4003 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4004 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4005 | |
| 4006 | if (pll == NULL) |
| 4007 | return; |
| 4008 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 4009 | if (!(pll->config.crtc_mask & (1 << crtc->pipe))) { |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 4010 | WARN(1, "bad %s crtc mask\n", pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4011 | return; |
| 4012 | } |
| 4013 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 4014 | pll->config.crtc_mask &= ~(1 << crtc->pipe); |
| 4015 | if (pll->config.crtc_mask == 0) { |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 4016 | WARN_ON(pll->on); |
| 4017 | WARN_ON(pll->active); |
| 4018 | } |
| 4019 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4020 | crtc->config->shared_dpll = DPLL_ID_PRIVATE; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4021 | } |
| 4022 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4023 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
| 4024 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4025 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4026 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4027 | struct intel_shared_dpll *pll; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4028 | enum intel_dpll_id i; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4029 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4030 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 4031 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 4032 | i = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4033 | pll = &dev_priv->shared_dplls[i]; |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4034 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4035 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 4036 | crtc->base.base.id, pll->name); |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4037 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4038 | WARN_ON(pll->new_config->crtc_mask); |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4039 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4040 | goto found; |
| 4041 | } |
| 4042 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4043 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4044 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4045 | |
| 4046 | /* Only want to check enabled timings first */ |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4047 | if (pll->new_config->crtc_mask == 0) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4048 | continue; |
| 4049 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4050 | if (memcmp(&crtc_state->dpll_hw_state, |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4051 | &pll->new_config->hw_state, |
| 4052 | sizeof(pll->new_config->hw_state)) == 0) { |
| 4053 | DRM_DEBUG_KMS("CRTC:%d sharing existing %s (crtc mask 0x%08x, ative %d)\n", |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 4054 | crtc->base.base.id, pll->name, |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4055 | pll->new_config->crtc_mask, |
| 4056 | pll->active); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4057 | goto found; |
| 4058 | } |
| 4059 | } |
| 4060 | |
| 4061 | /* Ok no matching timings, maybe there's a free one? */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4062 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4063 | pll = &dev_priv->shared_dplls[i]; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4064 | if (pll->new_config->crtc_mask == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4065 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
| 4066 | crtc->base.base.id, pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4067 | goto found; |
| 4068 | } |
| 4069 | } |
| 4070 | |
| 4071 | return NULL; |
| 4072 | |
| 4073 | found: |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4074 | if (pll->new_config->crtc_mask == 0) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4075 | pll->new_config->hw_state = crtc_state->dpll_hw_state; |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4076 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4077 | crtc_state->shared_dpll = i; |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4078 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
| 4079 | pipe_name(crtc->pipe)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 4080 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4081 | pll->new_config->crtc_mask |= 1 << crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4082 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4083 | return pll; |
| 4084 | } |
| 4085 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4086 | /** |
| 4087 | * intel_shared_dpll_start_config - start a new PLL staged config |
| 4088 | * @dev_priv: DRM device |
| 4089 | * @clear_pipes: mask of pipes that will have their PLLs freed |
| 4090 | * |
| 4091 | * Starts a new PLL staged config, copying the current config but |
| 4092 | * releasing the references of pipes specified in clear_pipes. |
| 4093 | */ |
| 4094 | static int intel_shared_dpll_start_config(struct drm_i915_private *dev_priv, |
| 4095 | unsigned clear_pipes) |
| 4096 | { |
| 4097 | struct intel_shared_dpll *pll; |
| 4098 | enum intel_dpll_id i; |
| 4099 | |
| 4100 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4101 | pll = &dev_priv->shared_dplls[i]; |
| 4102 | |
| 4103 | pll->new_config = kmemdup(&pll->config, sizeof pll->config, |
| 4104 | GFP_KERNEL); |
| 4105 | if (!pll->new_config) |
| 4106 | goto cleanup; |
| 4107 | |
| 4108 | pll->new_config->crtc_mask &= ~clear_pipes; |
| 4109 | } |
| 4110 | |
| 4111 | return 0; |
| 4112 | |
| 4113 | cleanup: |
| 4114 | while (--i >= 0) { |
| 4115 | pll = &dev_priv->shared_dplls[i]; |
Ander Conselvan de Oliveira | f354d73 | 2014-11-07 14:07:41 +0200 | [diff] [blame] | 4116 | kfree(pll->new_config); |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4117 | pll->new_config = NULL; |
| 4118 | } |
| 4119 | |
| 4120 | return -ENOMEM; |
| 4121 | } |
| 4122 | |
| 4123 | static void intel_shared_dpll_commit(struct drm_i915_private *dev_priv) |
| 4124 | { |
| 4125 | struct intel_shared_dpll *pll; |
| 4126 | enum intel_dpll_id i; |
| 4127 | |
| 4128 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4129 | pll = &dev_priv->shared_dplls[i]; |
| 4130 | |
| 4131 | WARN_ON(pll->new_config == &pll->config); |
| 4132 | |
| 4133 | pll->config = *pll->new_config; |
| 4134 | kfree(pll->new_config); |
| 4135 | pll->new_config = NULL; |
| 4136 | } |
| 4137 | } |
| 4138 | |
| 4139 | static void intel_shared_dpll_abort_config(struct drm_i915_private *dev_priv) |
| 4140 | { |
| 4141 | struct intel_shared_dpll *pll; |
| 4142 | enum intel_dpll_id i; |
| 4143 | |
| 4144 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4145 | pll = &dev_priv->shared_dplls[i]; |
| 4146 | |
| 4147 | WARN_ON(pll->new_config == &pll->config); |
| 4148 | |
| 4149 | kfree(pll->new_config); |
| 4150 | pll->new_config = NULL; |
| 4151 | } |
| 4152 | } |
| 4153 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4154 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4155 | { |
| 4156 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 4157 | int dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4158 | u32 temp; |
| 4159 | |
| 4160 | temp = I915_READ(dslreg); |
| 4161 | udelay(500); |
| 4162 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4163 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4164 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4165 | } |
| 4166 | } |
| 4167 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4168 | static void skylake_pfit_enable(struct intel_crtc *crtc) |
| 4169 | { |
| 4170 | struct drm_device *dev = crtc->base.dev; |
| 4171 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4172 | int pipe = crtc->pipe; |
| 4173 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4174 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4175 | I915_WRITE(PS_CTL(pipe), PS_ENABLE); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4176 | I915_WRITE(PS_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4177 | I915_WRITE(PS_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4178 | } |
| 4179 | } |
| 4180 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4181 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4182 | { |
| 4183 | struct drm_device *dev = crtc->base.dev; |
| 4184 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4185 | int pipe = crtc->pipe; |
| 4186 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4187 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4188 | /* Force use of hard-coded filter coefficients |
| 4189 | * as some pre-programmed values are broken, |
| 4190 | * e.g. x201. |
| 4191 | */ |
| 4192 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 4193 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4194 | PF_PIPE_SEL_IVB(pipe)); |
| 4195 | else |
| 4196 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4197 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4198 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4199 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4200 | } |
| 4201 | |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4202 | static void intel_enable_sprite_planes(struct drm_crtc *crtc) |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4203 | { |
| 4204 | struct drm_device *dev = crtc->dev; |
| 4205 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4206 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4207 | struct intel_plane *intel_plane; |
| 4208 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4209 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 4210 | intel_plane = to_intel_plane(plane); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4211 | if (intel_plane->pipe == pipe) |
| 4212 | intel_plane_restore(&intel_plane->base); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4213 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4214 | } |
| 4215 | |
Matt Roper | 0d703d4 | 2015-03-04 10:49:04 -0800 | [diff] [blame] | 4216 | /* |
| 4217 | * Disable a plane internally without actually modifying the plane's state. |
| 4218 | * This will allow us to easily restore the plane later by just reprogramming |
| 4219 | * its state. |
| 4220 | */ |
| 4221 | static void disable_plane_internal(struct drm_plane *plane) |
| 4222 | { |
| 4223 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 4224 | struct drm_plane_state *state = |
| 4225 | plane->funcs->atomic_duplicate_state(plane); |
| 4226 | struct intel_plane_state *intel_state = to_intel_plane_state(state); |
| 4227 | |
| 4228 | intel_state->visible = false; |
| 4229 | intel_plane->commit_plane(plane, intel_state); |
| 4230 | |
| 4231 | intel_plane_destroy_state(plane, state); |
| 4232 | } |
| 4233 | |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4234 | static void intel_disable_sprite_planes(struct drm_crtc *crtc) |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4235 | { |
| 4236 | struct drm_device *dev = crtc->dev; |
| 4237 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4238 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4239 | struct intel_plane *intel_plane; |
| 4240 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4241 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 4242 | intel_plane = to_intel_plane(plane); |
Matt Roper | 0d703d4 | 2015-03-04 10:49:04 -0800 | [diff] [blame] | 4243 | if (plane->fb && intel_plane->pipe == pipe) |
| 4244 | disable_plane_internal(plane); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4245 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4246 | } |
| 4247 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4248 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4249 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4250 | struct drm_device *dev = crtc->base.dev; |
| 4251 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4252 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4253 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4254 | return; |
| 4255 | |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4256 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
| 4257 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4258 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4259 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4260 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4261 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4262 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 4263 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4264 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4265 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4266 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4267 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4268 | */ |
| 4269 | } else { |
| 4270 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4271 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4272 | * is essentially intel_wait_for_vblank. If we don't have this |
| 4273 | * and don't wait for vblanks until the end of crtc_enable, then |
| 4274 | * the HW state readout code will complain that the expected |
| 4275 | * IPS_CTL value is not the one we read. */ |
| 4276 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 4277 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 4278 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4279 | } |
| 4280 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4281 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4282 | { |
| 4283 | struct drm_device *dev = crtc->base.dev; |
| 4284 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4285 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4286 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4287 | return; |
| 4288 | |
| 4289 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4290 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4291 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4292 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 4293 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4294 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 4295 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 4296 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4297 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4298 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4299 | POSTING_READ(IPS_CTL); |
| 4300 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4301 | |
| 4302 | /* We need to wait for a vblank before we can disable the plane. */ |
| 4303 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4304 | } |
| 4305 | |
| 4306 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 4307 | static void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 4308 | { |
| 4309 | struct drm_device *dev = crtc->dev; |
| 4310 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4311 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4312 | enum pipe pipe = intel_crtc->pipe; |
| 4313 | int palreg = PALETTE(pipe); |
| 4314 | int i; |
| 4315 | bool reenable_ips = false; |
| 4316 | |
| 4317 | /* The clocks have to be on to load the palette. */ |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4318 | if (!crtc->state->enable || !intel_crtc->active) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4319 | return; |
| 4320 | |
| 4321 | if (!HAS_PCH_SPLIT(dev_priv->dev)) { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 4322 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4323 | assert_dsi_pll_enabled(dev_priv); |
| 4324 | else |
| 4325 | assert_pll_enabled(dev_priv, pipe); |
| 4326 | } |
| 4327 | |
| 4328 | /* use legacy palette for Ironlake */ |
Sonika Jindal | 7a1db49 | 2014-07-22 11:18:27 +0530 | [diff] [blame] | 4329 | if (!HAS_GMCH_DISPLAY(dev)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4330 | palreg = LGC_PALETTE(pipe); |
| 4331 | |
| 4332 | /* Workaround : Do not read or write the pipe palette/gamma data while |
| 4333 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 4334 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4335 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4336 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
| 4337 | GAMMA_MODE_MODE_SPLIT)) { |
| 4338 | hsw_disable_ips(intel_crtc); |
| 4339 | reenable_ips = true; |
| 4340 | } |
| 4341 | |
| 4342 | for (i = 0; i < 256; i++) { |
| 4343 | I915_WRITE(palreg + 4 * i, |
| 4344 | (intel_crtc->lut_r[i] << 16) | |
| 4345 | (intel_crtc->lut_g[i] << 8) | |
| 4346 | intel_crtc->lut_b[i]); |
| 4347 | } |
| 4348 | |
| 4349 | if (reenable_ips) |
| 4350 | hsw_enable_ips(intel_crtc); |
| 4351 | } |
| 4352 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4353 | static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable) |
| 4354 | { |
| 4355 | if (!enable && intel_crtc->overlay) { |
| 4356 | struct drm_device *dev = intel_crtc->base.dev; |
| 4357 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4358 | |
| 4359 | mutex_lock(&dev->struct_mutex); |
| 4360 | dev_priv->mm.interruptible = false; |
| 4361 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 4362 | dev_priv->mm.interruptible = true; |
| 4363 | mutex_unlock(&dev->struct_mutex); |
| 4364 | } |
| 4365 | |
| 4366 | /* Let userspace switch the overlay on again. In most cases userspace |
| 4367 | * has to recompute where to put it anyway. |
| 4368 | */ |
| 4369 | } |
| 4370 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4371 | static void intel_crtc_enable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4372 | { |
| 4373 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4374 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4375 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4376 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 4377 | intel_enable_primary_hw_plane(crtc->primary, crtc); |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4378 | intel_enable_sprite_planes(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4379 | intel_crtc_update_cursor(crtc, true); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4380 | intel_crtc_dpms_overlay(intel_crtc, true); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4381 | |
| 4382 | hsw_enable_ips(intel_crtc); |
| 4383 | |
| 4384 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4385 | intel_fbc_update(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4386 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4387 | |
| 4388 | /* |
| 4389 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4390 | * to compute the mask of flip planes precisely. For the time being |
| 4391 | * consider this a flip from a NULL plane. |
| 4392 | */ |
| 4393 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4394 | } |
| 4395 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4396 | static void intel_crtc_disable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4397 | { |
| 4398 | struct drm_device *dev = crtc->dev; |
| 4399 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4400 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4401 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4402 | |
| 4403 | intel_crtc_wait_for_pending_flips(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4404 | |
Paulo Zanoni | e35fef2 | 2015-02-09 14:46:29 -0200 | [diff] [blame] | 4405 | if (dev_priv->fbc.crtc == intel_crtc) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4406 | intel_fbc_disable(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4407 | |
| 4408 | hsw_disable_ips(intel_crtc); |
| 4409 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4410 | intel_crtc_dpms_overlay(intel_crtc, false); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4411 | intel_crtc_update_cursor(crtc, false); |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4412 | intel_disable_sprite_planes(crtc); |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 4413 | intel_disable_primary_hw_plane(crtc->primary, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4414 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4415 | /* |
| 4416 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4417 | * to compute the mask of flip planes precisely. For the time being |
| 4418 | * consider this a flip to a NULL plane. |
| 4419 | */ |
| 4420 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4421 | } |
| 4422 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4423 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4424 | { |
| 4425 | struct drm_device *dev = crtc->dev; |
| 4426 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4427 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4428 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4429 | int pipe = intel_crtc->pipe; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4430 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4431 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 4432 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4433 | if (intel_crtc->active) |
| 4434 | return; |
| 4435 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4436 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4437 | intel_prepare_shared_dpll(intel_crtc); |
| 4438 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4439 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4440 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4441 | |
| 4442 | intel_set_pipe_timings(intel_crtc); |
| 4443 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4444 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4445 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4446 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | ironlake_set_pipeconf(crtc); |
| 4450 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4451 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4452 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4453 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4454 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4455 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4456 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4457 | if (encoder->pre_enable) |
| 4458 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4459 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4460 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4461 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4462 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4463 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4464 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4465 | } else { |
| 4466 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4467 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4468 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4469 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4470 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4471 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4472 | /* |
| 4473 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4474 | * clocks enabled |
| 4475 | */ |
| 4476 | intel_crtc_load_lut(crtc); |
| 4477 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4478 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4479 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4480 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4481 | if (intel_crtc->config->has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4482 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4483 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4484 | assert_vblank_disabled(crtc); |
| 4485 | drm_crtc_vblank_on(crtc); |
| 4486 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4487 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4488 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4489 | |
| 4490 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4491 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Daniel Vetter | 6ce9410 | 2012-10-04 19:20:03 +0200 | [diff] [blame] | 4492 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4493 | intel_crtc_enable_planes(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4494 | } |
| 4495 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4496 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4497 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4498 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4499 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4500 | } |
| 4501 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4502 | /* |
| 4503 | * This implements the workaround described in the "notes" section of the mode |
| 4504 | * set sequence documentation. When going from no pipes or single pipe to |
| 4505 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 4506 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 4507 | */ |
| 4508 | static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc) |
| 4509 | { |
| 4510 | struct drm_device *dev = crtc->base.dev; |
| 4511 | struct intel_crtc *crtc_it, *other_active_crtc = NULL; |
| 4512 | |
| 4513 | /* We want to get the other_active_crtc only if there's only 1 other |
| 4514 | * active crtc. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4515 | for_each_intel_crtc(dev, crtc_it) { |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4516 | if (!crtc_it->active || crtc_it == crtc) |
| 4517 | continue; |
| 4518 | |
| 4519 | if (other_active_crtc) |
| 4520 | return; |
| 4521 | |
| 4522 | other_active_crtc = crtc_it; |
| 4523 | } |
| 4524 | if (!other_active_crtc) |
| 4525 | return; |
| 4526 | |
| 4527 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4528 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4529 | } |
| 4530 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4531 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 4532 | { |
| 4533 | struct drm_device *dev = crtc->dev; |
| 4534 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4535 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4536 | struct intel_encoder *encoder; |
| 4537 | int pipe = intel_crtc->pipe; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4538 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4539 | WARN_ON(!crtc->state->enable); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4540 | |
| 4541 | if (intel_crtc->active) |
| 4542 | return; |
| 4543 | |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4544 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4545 | intel_enable_shared_dpll(intel_crtc); |
| 4546 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4547 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4548 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4549 | |
| 4550 | intel_set_pipe_timings(intel_crtc); |
| 4551 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4552 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
| 4553 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), |
| 4554 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 4555 | } |
| 4556 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4557 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4558 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4559 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4560 | } |
| 4561 | |
| 4562 | haswell_set_pipeconf(crtc); |
| 4563 | |
| 4564 | intel_set_pipe_csc(crtc); |
| 4565 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4566 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4567 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4568 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4569 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4570 | if (encoder->pre_enable) |
| 4571 | encoder->pre_enable(encoder); |
| 4572 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4573 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4574 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4575 | true); |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4576 | dev_priv->display.fdi_link_train(crtc); |
| 4577 | } |
| 4578 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4579 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4580 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4581 | if (IS_SKYLAKE(dev)) |
| 4582 | skylake_pfit_enable(intel_crtc); |
| 4583 | else |
| 4584 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4585 | |
| 4586 | /* |
| 4587 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4588 | * clocks enabled |
| 4589 | */ |
| 4590 | intel_crtc_load_lut(crtc); |
| 4591 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4592 | intel_ddi_set_pipe_settings(crtc); |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 4593 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4594 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4595 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4596 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4597 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4598 | if (intel_crtc->config->has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4599 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4600 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4601 | if (intel_crtc->config->dp_encoder_is_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4602 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 4603 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4604 | assert_vblank_disabled(crtc); |
| 4605 | drm_crtc_vblank_on(crtc); |
| 4606 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4607 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4608 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4609 | intel_opregion_notify_encoder(encoder, true); |
| 4610 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4611 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4612 | /* If we change the relative order between pipe/planes enabling, we need |
| 4613 | * to change the workaround. */ |
| 4614 | haswell_mode_set_planes_workaround(intel_crtc); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4615 | intel_crtc_enable_planes(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4616 | } |
| 4617 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4618 | static void skylake_pfit_disable(struct intel_crtc *crtc) |
| 4619 | { |
| 4620 | struct drm_device *dev = crtc->base.dev; |
| 4621 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4622 | int pipe = crtc->pipe; |
| 4623 | |
| 4624 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4625 | * it's in use. The hw state code will make sure we get this right. */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4626 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4627 | I915_WRITE(PS_CTL(pipe), 0); |
| 4628 | I915_WRITE(PS_WIN_POS(pipe), 0); |
| 4629 | I915_WRITE(PS_WIN_SZ(pipe), 0); |
| 4630 | } |
| 4631 | } |
| 4632 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4633 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
| 4634 | { |
| 4635 | struct drm_device *dev = crtc->base.dev; |
| 4636 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4637 | int pipe = crtc->pipe; |
| 4638 | |
| 4639 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4640 | * it's in use. The hw state code will make sure we get this right. */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4641 | if (crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4642 | I915_WRITE(PF_CTL(pipe), 0); |
| 4643 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 4644 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 4645 | } |
| 4646 | } |
| 4647 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4648 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 4649 | { |
| 4650 | struct drm_device *dev = crtc->dev; |
| 4651 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4652 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4653 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4654 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4655 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4656 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4657 | if (!intel_crtc->active) |
| 4658 | return; |
| 4659 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4660 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4661 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4662 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4663 | encoder->disable(encoder); |
| 4664 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4665 | drm_crtc_vblank_off(crtc); |
| 4666 | assert_vblank_disabled(crtc); |
| 4667 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4668 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4669 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4670 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4671 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4672 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4673 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4674 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 4675 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4676 | if (encoder->post_disable) |
| 4677 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4678 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4679 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4680 | ironlake_fdi_disable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4681 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4682 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4683 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4684 | if (HAS_PCH_CPT(dev)) { |
| 4685 | /* disable TRANS_DP_CTL */ |
| 4686 | reg = TRANS_DP_CTL(pipe); |
| 4687 | temp = I915_READ(reg); |
| 4688 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 4689 | TRANS_DP_PORT_SEL_MASK); |
| 4690 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 4691 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4692 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4693 | /* disable DPLL_SEL */ |
| 4694 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4695 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4696 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 4697 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4698 | |
| 4699 | /* disable PCH DPLL */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4700 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4701 | |
| 4702 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4703 | } |
| 4704 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4705 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4706 | intel_update_watermarks(crtc); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4707 | |
| 4708 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4709 | intel_fbc_update(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4710 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4711 | } |
| 4712 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4713 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 4714 | { |
| 4715 | struct drm_device *dev = crtc->dev; |
| 4716 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4717 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4718 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4719 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4720 | |
| 4721 | if (!intel_crtc->active) |
| 4722 | return; |
| 4723 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4724 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | dda9a66 | 2013-09-19 17:00:37 -0300 | [diff] [blame] | 4725 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4726 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 4727 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4728 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4729 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4730 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4731 | drm_crtc_vblank_off(crtc); |
| 4732 | assert_vblank_disabled(crtc); |
| 4733 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4734 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4735 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4736 | false); |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4737 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4738 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4739 | if (intel_crtc->config->dp_encoder_is_mst) |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 4740 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 4741 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 4742 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4743 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4744 | if (IS_SKYLAKE(dev)) |
| 4745 | skylake_pfit_disable(intel_crtc); |
| 4746 | else |
| 4747 | ironlake_pfit_disable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4748 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4749 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4750 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4751 | if (intel_crtc->config->has_pch_encoder) { |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 4752 | lpt_disable_pch_transcoder(dev_priv); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 4753 | intel_ddi_fdi_disable(crtc); |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 4754 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4755 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 4756 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4757 | if (encoder->post_disable) |
| 4758 | encoder->post_disable(encoder); |
| 4759 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4760 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4761 | intel_update_watermarks(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4762 | |
| 4763 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4764 | intel_fbc_update(dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4765 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4766 | |
| 4767 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4768 | intel_disable_shared_dpll(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4769 | } |
| 4770 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4771 | static void ironlake_crtc_off(struct drm_crtc *crtc) |
| 4772 | { |
| 4773 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4774 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4775 | } |
| 4776 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 4777 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4778 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 4779 | { |
| 4780 | struct drm_device *dev = crtc->base.dev; |
| 4781 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4782 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4783 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 4784 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4785 | return; |
| 4786 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 4787 | /* |
| 4788 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 4789 | * according to register description and PRM. |
| 4790 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4791 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 4792 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 4793 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4794 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 4795 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 4796 | |
| 4797 | /* Border color in case we don't scale up to the full screen. Black by |
| 4798 | * default, change to something else for debugging. */ |
| 4799 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4800 | } |
| 4801 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4802 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 4803 | { |
| 4804 | switch (port) { |
| 4805 | case PORT_A: |
| 4806 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; |
| 4807 | case PORT_B: |
| 4808 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; |
| 4809 | case PORT_C: |
| 4810 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; |
| 4811 | case PORT_D: |
| 4812 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; |
| 4813 | default: |
| 4814 | WARN_ON_ONCE(1); |
| 4815 | return POWER_DOMAIN_PORT_OTHER; |
| 4816 | } |
| 4817 | } |
| 4818 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4819 | #define for_each_power_domain(domain, mask) \ |
| 4820 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ |
| 4821 | if ((1 << (domain)) & (mask)) |
| 4822 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4823 | enum intel_display_power_domain |
| 4824 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4825 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4826 | struct drm_device *dev = intel_encoder->base.dev; |
| 4827 | struct intel_digital_port *intel_dig_port; |
| 4828 | |
| 4829 | switch (intel_encoder->type) { |
| 4830 | case INTEL_OUTPUT_UNKNOWN: |
| 4831 | /* Only DDI platforms should ever use this output type */ |
| 4832 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 4833 | case INTEL_OUTPUT_DISPLAYPORT: |
| 4834 | case INTEL_OUTPUT_HDMI: |
| 4835 | case INTEL_OUTPUT_EDP: |
| 4836 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4837 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4838 | case INTEL_OUTPUT_DP_MST: |
| 4839 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 4840 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4841 | case INTEL_OUTPUT_ANALOG: |
| 4842 | return POWER_DOMAIN_PORT_CRT; |
| 4843 | case INTEL_OUTPUT_DSI: |
| 4844 | return POWER_DOMAIN_PORT_DSI; |
| 4845 | default: |
| 4846 | return POWER_DOMAIN_PORT_OTHER; |
| 4847 | } |
| 4848 | } |
| 4849 | |
| 4850 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) |
| 4851 | { |
| 4852 | struct drm_device *dev = crtc->dev; |
| 4853 | struct intel_encoder *intel_encoder; |
| 4854 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4855 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4856 | unsigned long mask; |
| 4857 | enum transcoder transcoder; |
| 4858 | |
| 4859 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); |
| 4860 | |
| 4861 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 4862 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4863 | if (intel_crtc->config->pch_pfit.enabled || |
| 4864 | intel_crtc->config->pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4865 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 4866 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4867 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 4868 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
| 4869 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4870 | return mask; |
| 4871 | } |
| 4872 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4873 | static void modeset_update_crtc_power_domains(struct drm_device *dev) |
| 4874 | { |
| 4875 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4876 | unsigned long pipe_domains[I915_MAX_PIPES] = { 0, }; |
| 4877 | struct intel_crtc *crtc; |
| 4878 | |
| 4879 | /* |
| 4880 | * First get all needed power domains, then put all unneeded, to avoid |
| 4881 | * any unnecessary toggling of the power wells. |
| 4882 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4883 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4884 | enum intel_display_power_domain domain; |
| 4885 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4886 | if (!crtc->base.state->enable) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4887 | continue; |
| 4888 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4889 | pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4890 | |
| 4891 | for_each_power_domain(domain, pipe_domains[crtc->pipe]) |
| 4892 | intel_display_power_get(dev_priv, domain); |
| 4893 | } |
| 4894 | |
Ville Syrjälä | 50f6e50 | 2014-11-06 14:49:12 +0200 | [diff] [blame] | 4895 | if (dev_priv->display.modeset_global_resources) |
| 4896 | dev_priv->display.modeset_global_resources(dev); |
| 4897 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4898 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4899 | enum intel_display_power_domain domain; |
| 4900 | |
| 4901 | for_each_power_domain(domain, crtc->enabled_power_domains) |
| 4902 | intel_display_power_put(dev_priv, domain); |
| 4903 | |
| 4904 | crtc->enabled_power_domains = pipe_domains[crtc->pipe]; |
| 4905 | } |
| 4906 | |
| 4907 | intel_display_set_init_power(dev_priv, false); |
| 4908 | } |
| 4909 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4910 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4911 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4912 | { |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 4913 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4914 | |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 4915 | /* Obtain SKU information */ |
| 4916 | mutex_lock(&dev_priv->dpio_lock); |
| 4917 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 4918 | CCK_FUSE_HPLL_FREQ_MASK; |
| 4919 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4920 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4921 | return vco_freq[hpll_freq] * 1000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4922 | } |
| 4923 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4924 | static void vlv_update_cdclk(struct drm_device *dev) |
| 4925 | { |
| 4926 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4927 | |
| 4928 | dev_priv->vlv_cdclk_freq = dev_priv->display.get_display_clock_speed(dev); |
Ville Syrjälä | 43dc52c | 2014-10-07 17:41:20 +0300 | [diff] [blame] | 4929 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4930 | dev_priv->vlv_cdclk_freq); |
| 4931 | |
| 4932 | /* |
| 4933 | * Program the gmbus_freq based on the cdclk frequency. |
| 4934 | * BSpec erroneously claims we should aim for 4MHz, but |
| 4935 | * in fact 1MHz is the correct frequency. |
| 4936 | */ |
Ville Syrjälä | 6be1e3d | 2014-10-16 20:52:31 +0300 | [diff] [blame] | 4937 | I915_WRITE(GMBUSFREQ_VLV, DIV_ROUND_UP(dev_priv->vlv_cdclk_freq, 1000)); |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4938 | } |
| 4939 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4940 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 4941 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 4942 | { |
| 4943 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4944 | u32 val, cmd; |
| 4945 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 4946 | 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] | 4947 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4948 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4949 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4950 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4951 | cmd = 1; |
| 4952 | else |
| 4953 | cmd = 0; |
| 4954 | |
| 4955 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4956 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 4957 | val &= ~DSPFREQGUAR_MASK; |
| 4958 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 4959 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 4960 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 4961 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 4962 | 50)) { |
| 4963 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 4964 | } |
| 4965 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4966 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4967 | if (cdclk == 400000) { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 4968 | u32 divider; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4969 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 4970 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4971 | |
| 4972 | mutex_lock(&dev_priv->dpio_lock); |
| 4973 | /* adjust cdclk divider */ |
| 4974 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Ville Syrjälä | 9cf33db | 2014-06-13 13:37:48 +0300 | [diff] [blame] | 4975 | val &= ~DISPLAY_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4976 | val |= divider; |
| 4977 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 4978 | |
| 4979 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
| 4980 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 4981 | 50)) |
| 4982 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4983 | mutex_unlock(&dev_priv->dpio_lock); |
| 4984 | } |
| 4985 | |
| 4986 | mutex_lock(&dev_priv->dpio_lock); |
| 4987 | /* adjust self-refresh exit latency value */ |
| 4988 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 4989 | val &= ~0x7f; |
| 4990 | |
| 4991 | /* |
| 4992 | * For high bandwidth configs, we set a higher latency in the bunit |
| 4993 | * so that the core display fetch happens in time to avoid underruns. |
| 4994 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4995 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4996 | val |= 4500 / 250; /* 4.5 usec */ |
| 4997 | else |
| 4998 | val |= 3000 / 250; /* 3.0 usec */ |
| 4999 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
| 5000 | mutex_unlock(&dev_priv->dpio_lock); |
| 5001 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5002 | vlv_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5003 | } |
| 5004 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5005 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5006 | { |
| 5007 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5008 | u32 val, cmd; |
| 5009 | |
| 5010 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq); |
| 5011 | |
| 5012 | switch (cdclk) { |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5013 | case 333333: |
| 5014 | case 320000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5015 | case 266667: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5016 | case 200000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5017 | break; |
| 5018 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 5019 | MISSING_CASE(cdclk); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5020 | return; |
| 5021 | } |
| 5022 | |
Ville Syrjälä | 9d0d3fd | 2015-03-02 20:07:17 +0200 | [diff] [blame] | 5023 | /* |
| 5024 | * Specs are full of misinformation, but testing on actual |
| 5025 | * hardware has shown that we just need to write the desired |
| 5026 | * CCK divider into the Punit register. |
| 5027 | */ |
| 5028 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
| 5029 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5030 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5031 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5032 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 5033 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 5034 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5035 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5036 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 5037 | 50)) { |
| 5038 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5039 | } |
| 5040 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5041 | |
| 5042 | vlv_update_cdclk(dev); |
| 5043 | } |
| 5044 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5045 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5046 | int max_pixclk) |
| 5047 | { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5048 | int freq_320 = (dev_priv->hpll_freq << 1) % 320000 != 0 ? 333333 : 320000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5049 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5050 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5051 | /* |
| 5052 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 5053 | * 200MHz |
| 5054 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5055 | * 320/333MHz (depends on HPLL freq) |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5056 | * 400MHz (VLV only) |
| 5057 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) |
| 5058 | * of the lower bin and adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5059 | * |
| 5060 | * We seem to get an unstable or solid color picture at 200MHz. |
| 5061 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 5062 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5063 | */ |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5064 | if (!IS_CHERRYVIEW(dev_priv) && |
| 5065 | max_pixclk > freq_320*limit/100) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5066 | return 400000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5067 | else if (max_pixclk > 266667*limit/100) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5068 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5069 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5070 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5071 | else |
| 5072 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5073 | } |
| 5074 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5075 | /* compute the max pixel clock for new configuration */ |
| 5076 | static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5077 | { |
| 5078 | struct drm_device *dev = dev_priv->dev; |
| 5079 | struct intel_crtc *intel_crtc; |
| 5080 | int max_pixclk = 0; |
| 5081 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5082 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5083 | if (intel_crtc->new_enabled) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5084 | max_pixclk = max(max_pixclk, |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 5085 | intel_crtc->new_config->base.adjusted_mode.crtc_clock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5086 | } |
| 5087 | |
| 5088 | return max_pixclk; |
| 5089 | } |
| 5090 | |
| 5091 | static void valleyview_modeset_global_pipes(struct drm_device *dev, |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5092 | unsigned *prepare_pipes) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5093 | { |
| 5094 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5095 | struct intel_crtc *intel_crtc; |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5096 | int max_pixclk = intel_mode_max_pixclk(dev_priv); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5097 | |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 5098 | if (valleyview_calc_cdclk(dev_priv, max_pixclk) == |
| 5099 | dev_priv->vlv_cdclk_freq) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5100 | return; |
| 5101 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5102 | /* disable/enable all currently active pipes while we change cdclk */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5103 | for_each_intel_crtc(dev, intel_crtc) |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5104 | if (intel_crtc->base.state->enable) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5105 | *prepare_pipes |= (1 << intel_crtc->pipe); |
| 5106 | } |
| 5107 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5108 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
| 5109 | { |
| 5110 | unsigned int credits, default_credits; |
| 5111 | |
| 5112 | if (IS_CHERRYVIEW(dev_priv)) |
| 5113 | default_credits = PFI_CREDIT(12); |
| 5114 | else |
| 5115 | default_credits = PFI_CREDIT(8); |
| 5116 | |
| 5117 | if (DIV_ROUND_CLOSEST(dev_priv->vlv_cdclk_freq, 1000) >= dev_priv->rps.cz_freq) { |
| 5118 | /* CHV suggested value is 31 or 63 */ |
| 5119 | if (IS_CHERRYVIEW(dev_priv)) |
| 5120 | credits = PFI_CREDIT_31; |
| 5121 | else |
| 5122 | credits = PFI_CREDIT(15); |
| 5123 | } else { |
| 5124 | credits = default_credits; |
| 5125 | } |
| 5126 | |
| 5127 | /* |
| 5128 | * WA - write default credits before re-programming |
| 5129 | * FIXME: should we also set the resend bit here? |
| 5130 | */ |
| 5131 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5132 | default_credits); |
| 5133 | |
| 5134 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5135 | credits | PFI_CREDIT_RESEND); |
| 5136 | |
| 5137 | /* |
| 5138 | * FIXME is this guaranteed to clear |
| 5139 | * immediately or should we poll for it? |
| 5140 | */ |
| 5141 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); |
| 5142 | } |
| 5143 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5144 | static void valleyview_modeset_global_resources(struct drm_device *dev) |
| 5145 | { |
| 5146 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5147 | int max_pixclk = intel_mode_max_pixclk(dev_priv); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5148 | int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
| 5149 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5150 | if (req_cdclk != dev_priv->vlv_cdclk_freq) { |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5151 | /* |
| 5152 | * FIXME: We can end up here with all power domains off, yet |
| 5153 | * with a CDCLK frequency other than the minimum. To account |
| 5154 | * for this take the PIPE-A power domain, which covers the HW |
| 5155 | * blocks needed for the following programming. This can be |
| 5156 | * removed once it's guaranteed that we get here either with |
| 5157 | * the minimum CDCLK set, or the required power domains |
| 5158 | * enabled. |
| 5159 | */ |
| 5160 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); |
| 5161 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5162 | if (IS_CHERRYVIEW(dev)) |
| 5163 | cherryview_set_cdclk(dev, req_cdclk); |
| 5164 | else |
| 5165 | valleyview_set_cdclk(dev, req_cdclk); |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5166 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5167 | vlv_program_pfi_credits(dev_priv); |
| 5168 | |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5169 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5170 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5171 | } |
| 5172 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5173 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 5174 | { |
| 5175 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5176 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5177 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5178 | struct intel_encoder *encoder; |
| 5179 | int pipe = intel_crtc->pipe; |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 5180 | bool is_dsi; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5181 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5182 | WARN_ON(!crtc->state->enable); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5183 | |
| 5184 | if (intel_crtc->active) |
| 5185 | return; |
| 5186 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5187 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
Shobhit Kumar | 8525a23 | 2014-06-25 12:20:39 +0530 | [diff] [blame] | 5188 | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5189 | if (!is_dsi) { |
| 5190 | if (IS_CHERRYVIEW(dev)) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5191 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5192 | else |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5193 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5194 | } |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5195 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5196 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5197 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5198 | |
| 5199 | intel_set_pipe_timings(intel_crtc); |
| 5200 | |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 5201 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
| 5202 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5203 | |
| 5204 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 5205 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 5206 | } |
| 5207 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5208 | i9xx_set_pipeconf(intel_crtc); |
| 5209 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5210 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5211 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5212 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5213 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5214 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5215 | if (encoder->pre_pll_enable) |
| 5216 | encoder->pre_pll_enable(encoder); |
| 5217 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5218 | if (!is_dsi) { |
| 5219 | if (IS_CHERRYVIEW(dev)) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5220 | chv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5221 | else |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5222 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5223 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5224 | |
| 5225 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5226 | if (encoder->pre_enable) |
| 5227 | encoder->pre_enable(encoder); |
| 5228 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5229 | i9xx_pfit_enable(intel_crtc); |
| 5230 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 5231 | intel_crtc_load_lut(crtc); |
| 5232 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5233 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5234 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 5235 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5236 | assert_vblank_disabled(crtc); |
| 5237 | drm_crtc_vblank_on(crtc); |
| 5238 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5239 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5240 | encoder->enable(encoder); |
| 5241 | |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 5242 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 5243 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 5244 | /* Underruns don't raise interrupts, so check manually. */ |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5245 | i9xx_check_fifo_underruns(dev_priv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5246 | } |
| 5247 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5248 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 5249 | { |
| 5250 | struct drm_device *dev = crtc->base.dev; |
| 5251 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5252 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5253 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 5254 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5255 | } |
| 5256 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5257 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5258 | { |
| 5259 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5260 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5261 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5262 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5263 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5264 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5265 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 5266 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5267 | if (intel_crtc->active) |
| 5268 | return; |
| 5269 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5270 | i9xx_set_pll_dividers(intel_crtc); |
| 5271 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5272 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5273 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5274 | |
| 5275 | intel_set_pipe_timings(intel_crtc); |
| 5276 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5277 | i9xx_set_pipeconf(intel_crtc); |
| 5278 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5279 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 5280 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5281 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5282 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5283 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 5284 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 5285 | if (encoder->pre_enable) |
| 5286 | encoder->pre_enable(encoder); |
| 5287 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 5288 | i9xx_enable_pll(intel_crtc); |
| 5289 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5290 | i9xx_pfit_enable(intel_crtc); |
| 5291 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 5292 | intel_crtc_load_lut(crtc); |
| 5293 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5294 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5295 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 5296 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5297 | assert_vblank_disabled(crtc); |
| 5298 | drm_crtc_vblank_on(crtc); |
| 5299 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5300 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5301 | encoder->enable(encoder); |
| 5302 | |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 5303 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 5304 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5305 | /* |
| 5306 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5307 | * So don't enable underrun reporting before at least some planes |
| 5308 | * are enabled. |
| 5309 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5310 | * but leave the pipe running. |
| 5311 | */ |
| 5312 | if (IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5313 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5314 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 5315 | /* Underruns don't raise interrupts, so check manually. */ |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5316 | i9xx_check_fifo_underruns(dev_priv); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5317 | } |
| 5318 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5319 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 5320 | { |
| 5321 | struct drm_device *dev = crtc->base.dev; |
| 5322 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5323 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5324 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5325 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5326 | |
| 5327 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5328 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5329 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 5330 | I915_READ(PFIT_CONTROL)); |
| 5331 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5332 | } |
| 5333 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5334 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 5335 | { |
| 5336 | struct drm_device *dev = crtc->dev; |
| 5337 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5338 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5339 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5340 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5341 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5342 | if (!intel_crtc->active) |
| 5343 | return; |
| 5344 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5345 | /* |
| 5346 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5347 | * So diasble underrun reporting before all the planes get disabled. |
| 5348 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5349 | * but leave the pipe running. |
| 5350 | */ |
| 5351 | if (IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5352 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5353 | |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 5354 | /* |
| 5355 | * Vblank time updates from the shadow to live plane control register |
| 5356 | * are blocked if the memory self-refresh mode is active at that |
| 5357 | * moment. So to make sure the plane gets truly disabled, disable |
| 5358 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5359 | * will be checked/applied by the HW only at the next frame start |
| 5360 | * event which is after the vblank start event, so we need to have a |
| 5361 | * wait-for-vblank between disabling the plane and the pipe. |
| 5362 | */ |
| 5363 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 5364 | intel_crtc_disable_planes(crtc); |
| 5365 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 5366 | /* |
| 5367 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 5368 | * wait for planes to fully turn off before disabling the pipe. |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 5369 | * We also need to wait on all gmch platforms because of the |
| 5370 | * self-refresh mode constraint explained above. |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 5371 | */ |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 5372 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 5373 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5374 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5375 | encoder->disable(encoder); |
| 5376 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5377 | drm_crtc_vblank_off(crtc); |
| 5378 | assert_vblank_disabled(crtc); |
| 5379 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 5380 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 5381 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5382 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 5383 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5384 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5385 | if (encoder->post_disable) |
| 5386 | encoder->post_disable(encoder); |
| 5387 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5388 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 5389 | if (IS_CHERRYVIEW(dev)) |
| 5390 | chv_disable_pll(dev_priv, pipe); |
| 5391 | else if (IS_VALLEYVIEW(dev)) |
| 5392 | vlv_disable_pll(dev_priv, pipe); |
| 5393 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 5394 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 5395 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5396 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5397 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5398 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5399 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5400 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 5401 | intel_update_watermarks(crtc); |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5402 | |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 5403 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 5404 | intel_fbc_update(dev); |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 5405 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5406 | } |
| 5407 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5408 | static void i9xx_crtc_off(struct drm_crtc *crtc) |
| 5409 | { |
| 5410 | } |
| 5411 | |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 5412 | /* Master function to enable/disable CRTC and corresponding power wells */ |
| 5413 | void intel_crtc_control(struct drm_crtc *crtc, bool enable) |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5414 | { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5415 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5416 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5417 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5418 | enum intel_display_power_domain domain; |
| 5419 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5420 | |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5421 | if (enable) { |
| 5422 | if (!intel_crtc->active) { |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 5423 | domains = get_crtc_power_domains(crtc); |
| 5424 | for_each_power_domain(domain, domains) |
| 5425 | intel_display_power_get(dev_priv, domain); |
| 5426 | intel_crtc->enabled_power_domains = domains; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5427 | |
| 5428 | dev_priv->display.crtc_enable(crtc); |
| 5429 | } |
| 5430 | } else { |
| 5431 | if (intel_crtc->active) { |
| 5432 | dev_priv->display.crtc_disable(crtc); |
| 5433 | |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 5434 | domains = intel_crtc->enabled_power_domains; |
| 5435 | for_each_power_domain(domain, domains) |
| 5436 | intel_display_power_put(dev_priv, domain); |
| 5437 | intel_crtc->enabled_power_domains = 0; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5438 | } |
| 5439 | } |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 5440 | } |
| 5441 | |
| 5442 | /** |
| 5443 | * Sets the power management mode of the pipe and plane. |
| 5444 | */ |
| 5445 | void intel_crtc_update_dpms(struct drm_crtc *crtc) |
| 5446 | { |
| 5447 | struct drm_device *dev = crtc->dev; |
| 5448 | struct intel_encoder *intel_encoder; |
| 5449 | bool enable = false; |
| 5450 | |
| 5451 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 5452 | enable |= intel_encoder->connectors_active; |
| 5453 | |
| 5454 | intel_crtc_control(crtc, enable); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5455 | } |
| 5456 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5457 | static void intel_crtc_disable(struct drm_crtc *crtc) |
| 5458 | { |
| 5459 | struct drm_device *dev = crtc->dev; |
| 5460 | struct drm_connector *connector; |
| 5461 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5462 | |
| 5463 | /* crtc should still be enabled when we disable it. */ |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5464 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5465 | |
| 5466 | dev_priv->display.crtc_disable(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5467 | dev_priv->display.off(crtc); |
| 5468 | |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 5469 | crtc->primary->funcs->disable_plane(crtc->primary); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5470 | |
| 5471 | /* Update computed state. */ |
| 5472 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 5473 | if (!connector->encoder || !connector->encoder->crtc) |
| 5474 | continue; |
| 5475 | |
| 5476 | if (connector->encoder->crtc != crtc) |
| 5477 | continue; |
| 5478 | |
| 5479 | connector->dpms = DRM_MODE_DPMS_OFF; |
| 5480 | to_intel_encoder(connector->encoder)->connectors_active = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5481 | } |
| 5482 | } |
| 5483 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5484 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 5485 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5486 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5487 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5488 | drm_encoder_cleanup(encoder); |
| 5489 | kfree(intel_encoder); |
| 5490 | } |
| 5491 | |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5492 | /* 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] | 5493 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
| 5494 | * state of the entire output pipe. */ |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5495 | static void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5496 | { |
| 5497 | if (mode == DRM_MODE_DPMS_ON) { |
| 5498 | encoder->connectors_active = true; |
| 5499 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5500 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5501 | } else { |
| 5502 | encoder->connectors_active = false; |
| 5503 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5504 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5505 | } |
| 5506 | } |
| 5507 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5508 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 5509 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5510 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5511 | { |
| 5512 | if (connector->get_hw_state(connector)) { |
| 5513 | struct intel_encoder *encoder = connector->encoder; |
| 5514 | struct drm_crtc *crtc; |
| 5515 | bool encoder_enabled; |
| 5516 | enum pipe pipe; |
| 5517 | |
| 5518 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 5519 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 5520 | connector->base.name); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5521 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5522 | /* there is no real hw state for MST connectors */ |
| 5523 | if (connector->mst_port) |
| 5524 | return; |
| 5525 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5526 | I915_STATE_WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5527 | "wrong connector dpms state\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5528 | I915_STATE_WARN(connector->base.encoder != &encoder->base, |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5529 | "active connector not linked to encoder\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5530 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5531 | if (encoder) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5532 | I915_STATE_WARN(!encoder->connectors_active, |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5533 | "encoder->connectors_active not set\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5534 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5535 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5536 | I915_STATE_WARN(!encoder_enabled, "encoder not enabled\n"); |
| 5537 | if (I915_STATE_WARN_ON(!encoder->base.crtc)) |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5538 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5539 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5540 | crtc = encoder->base.crtc; |
| 5541 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5542 | I915_STATE_WARN(!crtc->state->enable, |
| 5543 | "crtc not enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5544 | I915_STATE_WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
| 5545 | I915_STATE_WARN(pipe != to_intel_crtc(crtc)->pipe, |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5546 | "encoder active on the wrong pipe\n"); |
| 5547 | } |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5548 | } |
| 5549 | } |
| 5550 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5551 | /* Even simpler default implementation, if there's really no special case to |
| 5552 | * consider. */ |
| 5553 | void intel_connector_dpms(struct drm_connector *connector, int mode) |
| 5554 | { |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5555 | /* All the simple cases only support two dpms states. */ |
| 5556 | if (mode != DRM_MODE_DPMS_ON) |
| 5557 | mode = DRM_MODE_DPMS_OFF; |
| 5558 | |
| 5559 | if (mode == connector->dpms) |
| 5560 | return; |
| 5561 | |
| 5562 | connector->dpms = mode; |
| 5563 | |
| 5564 | /* Only need to change hw state when actually enabled */ |
Chris Wilson | c9976dc | 2013-09-29 19:15:07 +0100 | [diff] [blame] | 5565 | if (connector->encoder) |
| 5566 | intel_encoder_dpms(to_intel_encoder(connector->encoder), mode); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5567 | |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5568 | intel_modeset_check_state(connector->dev); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5569 | } |
| 5570 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5571 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 5572 | * one connector and no cloning and hence the encoder state determines the state |
| 5573 | * of the connector. */ |
| 5574 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 5575 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 5576 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5577 | struct intel_encoder *encoder = connector->encoder; |
| 5578 | |
| 5579 | return encoder->get_hw_state(encoder, &pipe); |
| 5580 | } |
| 5581 | |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 5582 | static int pipe_required_fdi_lanes(struct drm_device *dev, enum pipe pipe) |
| 5583 | { |
| 5584 | struct intel_crtc *crtc = |
| 5585 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
| 5586 | |
| 5587 | if (crtc->base.state->enable && |
| 5588 | crtc->config->has_pch_encoder) |
| 5589 | return crtc->config->fdi_lanes; |
| 5590 | |
| 5591 | return 0; |
| 5592 | } |
| 5593 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5594 | static bool ironlake_check_fdi_lanes(struct drm_device *dev, enum pipe pipe, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 5595 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5596 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5597 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 5598 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5599 | if (pipe_config->fdi_lanes > 4) { |
| 5600 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 5601 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5602 | return false; |
| 5603 | } |
| 5604 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 5605 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5606 | if (pipe_config->fdi_lanes > 2) { |
| 5607 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 5608 | pipe_config->fdi_lanes); |
| 5609 | return false; |
| 5610 | } else { |
| 5611 | return true; |
| 5612 | } |
| 5613 | } |
| 5614 | |
| 5615 | if (INTEL_INFO(dev)->num_pipes == 2) |
| 5616 | return true; |
| 5617 | |
| 5618 | /* Ivybridge 3 pipe is really complicated */ |
| 5619 | switch (pipe) { |
| 5620 | case PIPE_A: |
| 5621 | return true; |
| 5622 | case PIPE_B: |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 5623 | if (pipe_config->fdi_lanes > 2 && |
| 5624 | pipe_required_fdi_lanes(dev, PIPE_C) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5625 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 5626 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5627 | return false; |
| 5628 | } |
| 5629 | return true; |
| 5630 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 5631 | if (pipe_config->fdi_lanes > 2) { |
| 5632 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 5633 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5634 | return false; |
| 5635 | } |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 5636 | if (pipe_required_fdi_lanes(dev, PIPE_B) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5637 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
| 5638 | return false; |
| 5639 | } |
| 5640 | return true; |
| 5641 | default: |
| 5642 | BUG(); |
| 5643 | } |
| 5644 | } |
| 5645 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5646 | #define RETRY 1 |
| 5647 | static int ironlake_fdi_compute_config(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 5648 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5649 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5650 | struct drm_device *dev = intel_crtc->base.dev; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 5651 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 5652 | int lane, link_bw, fdi_dotclock; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5653 | bool setup_ok, needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5654 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5655 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5656 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 5657 | * each output octet as 10 bits. The actual frequency |
| 5658 | * is stored as a divider into a 100MHz clock, and the |
| 5659 | * mode pixel clock is stored in units of 1KHz. |
| 5660 | * Hence the bw of each lane in terms of the mode signal |
| 5661 | * is: |
| 5662 | */ |
| 5663 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
| 5664 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5665 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5666 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5667 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5668 | pipe_config->pipe_bpp); |
| 5669 | |
| 5670 | pipe_config->fdi_lanes = lane; |
| 5671 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5672 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5673 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5674 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5675 | setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
| 5676 | intel_crtc->pipe, pipe_config); |
| 5677 | if (!setup_ok && pipe_config->pipe_bpp > 6*3) { |
| 5678 | pipe_config->pipe_bpp -= 2*3; |
| 5679 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 5680 | pipe_config->pipe_bpp); |
| 5681 | needs_recompute = true; |
| 5682 | pipe_config->bw_constrained = true; |
| 5683 | |
| 5684 | goto retry; |
| 5685 | } |
| 5686 | |
| 5687 | if (needs_recompute) |
| 5688 | return RETRY; |
| 5689 | |
| 5690 | return setup_ok ? 0 : -EINVAL; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5691 | } |
| 5692 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5693 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 5694 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5695 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5696 | pipe_config->ips_enabled = i915.enable_ips && |
Paulo Zanoni | 3c4ca58 | 2013-05-31 16:33:23 -0300 | [diff] [blame] | 5697 | hsw_crtc_supports_ips(crtc) && |
Jesse Barnes | b6dfdc9 | 2013-07-25 10:06:50 -0700 | [diff] [blame] | 5698 | pipe_config->pipe_bpp <= 24; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5699 | } |
| 5700 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5701 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 5702 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5703 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5704 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 5705 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 5706 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5707 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5708 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5709 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5710 | int clock_limit = |
| 5711 | dev_priv->display.get_display_clock_speed(dev); |
| 5712 | |
| 5713 | /* |
| 5714 | * Enable pixel doubling when the dot clock |
| 5715 | * is > 90% of the (display) core speed. |
| 5716 | * |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5717 | * GDG double wide on either pipe, |
| 5718 | * otherwise pipe A only. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5719 | */ |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5720 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5721 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5722 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5723 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5724 | } |
| 5725 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5726 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5727 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5728 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5729 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 5730 | /* |
| 5731 | * Pipe horizontal size must be even in: |
| 5732 | * - DVO ganged mode |
| 5733 | * - LVDS dual channel mode |
| 5734 | * - Double wide pipe |
| 5735 | */ |
Ander Conselvan de Oliveira | b4f2bf4 | 2015-02-26 09:44:45 +0200 | [diff] [blame] | 5736 | if ((intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS) && |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 5737 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 5738 | pipe_config->pipe_src_w &= ~1; |
| 5739 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 5740 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 5741 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5742 | */ |
| 5743 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
| 5744 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5745 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5746 | |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5747 | 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] | 5748 | pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */ |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5749 | } 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] | 5750 | /* only a 8bpc pipe, with 6bpc dither through the panel fitter |
| 5751 | * for lvds. */ |
| 5752 | pipe_config->pipe_bpp = 8*3; |
| 5753 | } |
| 5754 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 5755 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5756 | hsw_compute_ips_config(crtc, pipe_config); |
| 5757 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5758 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5759 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5760 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5761 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5762 | } |
| 5763 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 5764 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 5765 | { |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5766 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5767 | u32 val; |
| 5768 | int divider; |
| 5769 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5770 | if (dev_priv->hpll_freq == 0) |
| 5771 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); |
| 5772 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5773 | mutex_lock(&dev_priv->dpio_lock); |
| 5774 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
| 5775 | mutex_unlock(&dev_priv->dpio_lock); |
| 5776 | |
| 5777 | divider = val & DISPLAY_FREQUENCY_VALUES; |
| 5778 | |
Ville Syrjälä | 7d007f4 | 2014-06-13 13:37:53 +0300 | [diff] [blame] | 5779 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
| 5780 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 5781 | "cdclk change in progress\n"); |
| 5782 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5783 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 5784 | } |
| 5785 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5786 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5787 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5788 | return 400000; |
| 5789 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5790 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5791 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 5792 | { |
| 5793 | return 333000; |
| 5794 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5795 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5796 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 5797 | { |
| 5798 | return 200000; |
| 5799 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5800 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 5801 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 5802 | { |
| 5803 | u16 gcfgc = 0; |
| 5804 | |
| 5805 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 5806 | |
| 5807 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 5808 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
| 5809 | return 267000; |
| 5810 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
| 5811 | return 333000; |
| 5812 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
| 5813 | return 444000; |
| 5814 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 5815 | return 200000; |
| 5816 | default: |
| 5817 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 5818 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
| 5819 | return 133000; |
| 5820 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
| 5821 | return 167000; |
| 5822 | } |
| 5823 | } |
| 5824 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5825 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 5826 | { |
| 5827 | u16 gcfgc = 0; |
| 5828 | |
| 5829 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 5830 | |
| 5831 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5832 | return 133000; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5833 | else { |
| 5834 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 5835 | case GC_DISPLAY_CLOCK_333_MHZ: |
| 5836 | return 333000; |
| 5837 | default: |
| 5838 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 5839 | return 190000; |
| 5840 | } |
| 5841 | } |
| 5842 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5843 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5844 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 5845 | { |
| 5846 | return 266000; |
| 5847 | } |
| 5848 | |
| 5849 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 5850 | { |
| 5851 | u16 hpllcc = 0; |
| 5852 | /* Assume that the hardware is in the high speed state. This |
| 5853 | * should be the default. |
| 5854 | */ |
| 5855 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 5856 | case GC_CLOCK_133_200: |
| 5857 | case GC_CLOCK_100_200: |
| 5858 | return 200000; |
| 5859 | case GC_CLOCK_166_250: |
| 5860 | return 250000; |
| 5861 | case GC_CLOCK_100_133: |
| 5862 | return 133000; |
| 5863 | } |
| 5864 | |
| 5865 | /* Shouldn't happen */ |
| 5866 | return 0; |
| 5867 | } |
| 5868 | |
| 5869 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 5870 | { |
| 5871 | return 133000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5872 | } |
| 5873 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5874 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5875 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5876 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5877 | while (*num > DATA_LINK_M_N_MASK || |
| 5878 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5879 | *num >>= 1; |
| 5880 | *den >>= 1; |
| 5881 | } |
| 5882 | } |
| 5883 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5884 | static void compute_m_n(unsigned int m, unsigned int n, |
| 5885 | uint32_t *ret_m, uint32_t *ret_n) |
| 5886 | { |
| 5887 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 5888 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 5889 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 5890 | } |
| 5891 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5892 | void |
| 5893 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 5894 | int pixel_clock, int link_clock, |
| 5895 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5896 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5897 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5898 | |
| 5899 | compute_m_n(bits_per_pixel * pixel_clock, |
| 5900 | link_clock * nlanes * 8, |
| 5901 | &m_n->gmch_m, &m_n->gmch_n); |
| 5902 | |
| 5903 | compute_m_n(pixel_clock, link_clock, |
| 5904 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5905 | } |
| 5906 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 5907 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 5908 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5909 | if (i915.panel_use_ssc >= 0) |
| 5910 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5911 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 5912 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 5913 | } |
| 5914 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5915 | static int i9xx_get_refclk(struct intel_crtc *crtc, int num_connectors) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5916 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5917 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5918 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5919 | int refclk; |
| 5920 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 5921 | if (IS_VALLEYVIEW(dev)) { |
Daniel Vetter | 9a0ea49 | 2013-09-16 11:29:34 +0200 | [diff] [blame] | 5922 | refclk = 100000; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 5923 | } else if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5924 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 5925 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 5926 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5927 | } else if (!IS_GEN2(dev)) { |
| 5928 | refclk = 96000; |
| 5929 | } else { |
| 5930 | refclk = 48000; |
| 5931 | } |
| 5932 | |
| 5933 | return refclk; |
| 5934 | } |
| 5935 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5936 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5937 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 5938 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5939 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5940 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5941 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 5942 | { |
| 5943 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 5944 | } |
| 5945 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5946 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 5947 | struct intel_crtc_state *crtc_state, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5948 | intel_clock_t *reduced_clock) |
| 5949 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5950 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5951 | u32 fp, fp2 = 0; |
| 5952 | |
| 5953 | if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 5954 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5955 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5956 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5957 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 5958 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5959 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 5960 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5961 | } |
| 5962 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 5963 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5964 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5965 | crtc->lowfreq_avail = false; |
Bob Paauwe | e1f234b | 2014-11-11 09:29:18 -0800 | [diff] [blame] | 5966 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS) && |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5967 | reduced_clock && i915.powersave) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 5968 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 5969 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5970 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 5971 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 5972 | } |
| 5973 | } |
| 5974 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 5975 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 5976 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5977 | { |
| 5978 | u32 reg_val; |
| 5979 | |
| 5980 | /* |
| 5981 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 5982 | * and set it to a reasonable value instead. |
| 5983 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5984 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5985 | reg_val &= 0xffffff00; |
| 5986 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5987 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5988 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5989 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5990 | reg_val &= 0x8cffffff; |
| 5991 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5992 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5993 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5994 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5995 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5996 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5997 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 5998 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5999 | reg_val &= 0x00ffffff; |
| 6000 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6001 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6002 | } |
| 6003 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6004 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 6005 | struct intel_link_m_n *m_n) |
| 6006 | { |
| 6007 | struct drm_device *dev = crtc->base.dev; |
| 6008 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6009 | int pipe = crtc->pipe; |
| 6010 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6011 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6012 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 6013 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 6014 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6015 | } |
| 6016 | |
| 6017 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6018 | struct intel_link_m_n *m_n, |
| 6019 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6020 | { |
| 6021 | struct drm_device *dev = crtc->base.dev; |
| 6022 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6023 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6024 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6025 | |
| 6026 | if (INTEL_INFO(dev)->gen >= 5) { |
| 6027 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6028 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 6029 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 6030 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6031 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 6032 | * for gen < 8) and if DRRS is supported (to make sure the |
| 6033 | * registers are not unnecessarily accessed). |
| 6034 | */ |
Durgadoss R | 44395bf | 2015-02-13 15:33:02 +0530 | [diff] [blame] | 6035 | if (m2_n2 && (IS_CHERRYVIEW(dev) || INTEL_INFO(dev)->gen < 8) && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6036 | crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6037 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 6038 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 6039 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 6040 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 6041 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 6042 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6043 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6044 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6045 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 6046 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 6047 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6048 | } |
| 6049 | } |
| 6050 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6051 | void intel_dp_set_m_n(struct intel_crtc *crtc, enum link_m_n_set m_n) |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6052 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6053 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 6054 | |
| 6055 | if (m_n == M1_N1) { |
| 6056 | dp_m_n = &crtc->config->dp_m_n; |
| 6057 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 6058 | } else if (m_n == M2_N2) { |
| 6059 | |
| 6060 | /* |
| 6061 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 6062 | * needs to be programmed into M1_N1. |
| 6063 | */ |
| 6064 | dp_m_n = &crtc->config->dp_m2_n2; |
| 6065 | } else { |
| 6066 | DRM_ERROR("Unsupported divider value\n"); |
| 6067 | return; |
| 6068 | } |
| 6069 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6070 | if (crtc->config->has_pch_encoder) |
| 6071 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6072 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6073 | intel_cpu_transcoder_set_m_n(crtc, dp_m_n, dp_m2_n2); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6074 | } |
| 6075 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6076 | static void vlv_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6077 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6078 | { |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6079 | u32 dpll, dpll_md; |
| 6080 | |
| 6081 | /* |
| 6082 | * Enable DPIO clock input. We should never disable the reference |
| 6083 | * clock for pipe B, since VGA hotplug / manual detection depends |
| 6084 | * on it. |
| 6085 | */ |
| 6086 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | |
| 6087 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; |
| 6088 | /* We should never disable this, set it here for state tracking */ |
| 6089 | if (crtc->pipe == PIPE_B) |
| 6090 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 6091 | dpll |= DPLL_VCO_ENABLE; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6092 | pipe_config->dpll_hw_state.dpll = dpll; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6093 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6094 | dpll_md = (pipe_config->pixel_multiplier - 1) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6095 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6096 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6097 | } |
| 6098 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6099 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6100 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6101 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6102 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6103 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6104 | int pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6105 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6106 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6107 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6108 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6109 | mutex_lock(&dev_priv->dpio_lock); |
| 6110 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6111 | bestn = pipe_config->dpll.n; |
| 6112 | bestm1 = pipe_config->dpll.m1; |
| 6113 | bestm2 = pipe_config->dpll.m2; |
| 6114 | bestp1 = pipe_config->dpll.p1; |
| 6115 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6116 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6117 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 6118 | |
| 6119 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6120 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6121 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6122 | |
| 6123 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6124 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6125 | |
| 6126 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6127 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6128 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6129 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6130 | |
| 6131 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6132 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6133 | |
| 6134 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6135 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 6136 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 6137 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6138 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 6139 | |
| 6140 | /* |
| 6141 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 6142 | * but we don't support that). |
| 6143 | * Note: don't use the DAC post divider as it seems unstable. |
| 6144 | */ |
| 6145 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6146 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6147 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6148 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6149 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6150 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6151 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6152 | if (pipe_config->port_clock == 162000 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6153 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
| 6154 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6155 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 6156 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6157 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6158 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6159 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6160 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 6161 | if (pipe_config->has_dp_encoder) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6162 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6163 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6164 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6165 | 0x0df40000); |
| 6166 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6167 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6168 | 0x0df70000); |
| 6169 | } else { /* HDMI or VGA */ |
| 6170 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6171 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6172 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6173 | 0x0df70000); |
| 6174 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6175 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6176 | 0x0df40000); |
| 6177 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6178 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6179 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6180 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6181 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 6182 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6183 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6184 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6185 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6186 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6187 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6188 | } |
| 6189 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6190 | static void chv_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6191 | struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6192 | { |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6193 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6194 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
| 6195 | DPLL_VCO_ENABLE; |
| 6196 | if (crtc->pipe != PIPE_A) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6197 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6198 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6199 | pipe_config->dpll_hw_state.dpll_md = |
| 6200 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6201 | } |
| 6202 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6203 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6204 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6205 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6206 | struct drm_device *dev = crtc->base.dev; |
| 6207 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6208 | int pipe = crtc->pipe; |
| 6209 | int dpll_reg = DPLL(crtc->pipe); |
| 6210 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6211 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6212 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6213 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6214 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6215 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6216 | bestn = pipe_config->dpll.n; |
| 6217 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 6218 | bestm1 = pipe_config->dpll.m1; |
| 6219 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 6220 | bestp1 = pipe_config->dpll.p1; |
| 6221 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6222 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6223 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6224 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6225 | |
| 6226 | /* |
| 6227 | * Enable Refclk and SSC |
| 6228 | */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 6229 | I915_WRITE(dpll_reg, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6230 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 6231 | |
| 6232 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6233 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6234 | /* p1 and p2 divider */ |
| 6235 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 6236 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 6237 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 6238 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 6239 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 6240 | |
| 6241 | /* Feedback post-divider - m2 */ |
| 6242 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 6243 | |
| 6244 | /* Feedback refclk divider - n and m1 */ |
| 6245 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 6246 | DPIO_CHV_M1_DIV_BY_2 | |
| 6247 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 6248 | |
| 6249 | /* M2 fraction division */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6250 | if (bestm2_frac) |
| 6251 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW2(port), bestm2_frac); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6252 | |
| 6253 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6254 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 6255 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 6256 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 6257 | if (bestm2_frac) |
| 6258 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 6259 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW3(port), dpio_val); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6260 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 6261 | /* Program digital lock detect threshold */ |
| 6262 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 6263 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 6264 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 6265 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 6266 | if (!bestm2_frac) |
| 6267 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 6268 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 6269 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6270 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6271 | if (vco == 5400000) { |
| 6272 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6273 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6274 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6275 | tribuf_calcntr = 0x9; |
| 6276 | } else if (vco <= 6200000) { |
| 6277 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6278 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 6279 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6280 | tribuf_calcntr = 0x9; |
| 6281 | } else if (vco <= 6480000) { |
| 6282 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6283 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6284 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6285 | tribuf_calcntr = 0x8; |
| 6286 | } else { |
| 6287 | /* Not supported. Apply the same limits as in the max case */ |
| 6288 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6289 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6290 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6291 | tribuf_calcntr = 0; |
| 6292 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6293 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 6294 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 6295 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6296 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 6297 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 6298 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 6299 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6300 | /* AFC Recal */ |
| 6301 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 6302 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 6303 | DPIO_AFC_RECAL); |
| 6304 | |
| 6305 | mutex_unlock(&dev_priv->dpio_lock); |
| 6306 | } |
| 6307 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6308 | /** |
| 6309 | * vlv_force_pll_on - forcibly enable just the PLL |
| 6310 | * @dev_priv: i915 private structure |
| 6311 | * @pipe: pipe PLL to enable |
| 6312 | * @dpll: PLL configuration |
| 6313 | * |
| 6314 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 6315 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 6316 | * be enabled. |
| 6317 | */ |
| 6318 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
| 6319 | const struct dpll *dpll) |
| 6320 | { |
| 6321 | struct intel_crtc *crtc = |
| 6322 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6323 | struct intel_crtc_state pipe_config = { |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6324 | .pixel_multiplier = 1, |
| 6325 | .dpll = *dpll, |
| 6326 | }; |
| 6327 | |
| 6328 | if (IS_CHERRYVIEW(dev)) { |
| 6329 | chv_update_pll(crtc, &pipe_config); |
| 6330 | chv_prepare_pll(crtc, &pipe_config); |
| 6331 | chv_enable_pll(crtc, &pipe_config); |
| 6332 | } else { |
| 6333 | vlv_update_pll(crtc, &pipe_config); |
| 6334 | vlv_prepare_pll(crtc, &pipe_config); |
| 6335 | vlv_enable_pll(crtc, &pipe_config); |
| 6336 | } |
| 6337 | } |
| 6338 | |
| 6339 | /** |
| 6340 | * vlv_force_pll_off - forcibly disable just the PLL |
| 6341 | * @dev_priv: i915 private structure |
| 6342 | * @pipe: pipe PLL to disable |
| 6343 | * |
| 6344 | * Disable the PLL for @pipe. To be used in cases where we need |
| 6345 | * the PLL enabled even when @pipe is not going to be enabled. |
| 6346 | */ |
| 6347 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) |
| 6348 | { |
| 6349 | if (IS_CHERRYVIEW(dev)) |
| 6350 | chv_disable_pll(to_i915(dev), pipe); |
| 6351 | else |
| 6352 | vlv_disable_pll(to_i915(dev), pipe); |
| 6353 | } |
| 6354 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6355 | static void i9xx_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6356 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6357 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6358 | int num_connectors) |
| 6359 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6360 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6361 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6362 | u32 dpll; |
| 6363 | bool is_sdvo; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6364 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6365 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6366 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6367 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 6368 | is_sdvo = intel_pipe_will_have_type(crtc, INTEL_OUTPUT_SDVO) || |
| 6369 | intel_pipe_will_have_type(crtc, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6370 | |
| 6371 | dpll = DPLL_VGA_MODE_DIS; |
| 6372 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 6373 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6374 | dpll |= DPLLB_MODE_LVDS; |
| 6375 | else |
| 6376 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 6377 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 6378 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6379 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 6380 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6381 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 6382 | |
| 6383 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 6384 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 6385 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6386 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 6387 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6388 | |
| 6389 | /* compute bitmask from p1 value */ |
| 6390 | if (IS_PINEVIEW(dev)) |
| 6391 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 6392 | else { |
| 6393 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 6394 | if (IS_G4X(dev) && reduced_clock) |
| 6395 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 6396 | } |
| 6397 | switch (clock->p2) { |
| 6398 | case 5: |
| 6399 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 6400 | break; |
| 6401 | case 7: |
| 6402 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 6403 | break; |
| 6404 | case 10: |
| 6405 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 6406 | break; |
| 6407 | case 14: |
| 6408 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 6409 | break; |
| 6410 | } |
| 6411 | if (INTEL_INFO(dev)->gen >= 4) |
| 6412 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 6413 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6414 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6415 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 6416 | else if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6417 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 6418 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 6419 | else |
| 6420 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 6421 | |
| 6422 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6423 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6424 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6425 | if (INTEL_INFO(dev)->gen >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6426 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 6427 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6428 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6429 | } |
| 6430 | } |
| 6431 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6432 | static void i8xx_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6433 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6434 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6435 | int num_connectors) |
| 6436 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6437 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6438 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6439 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6440 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6441 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6442 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6443 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6444 | dpll = DPLL_VGA_MODE_DIS; |
| 6445 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 6446 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6447 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 6448 | } else { |
| 6449 | if (clock->p1 == 2) |
| 6450 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 6451 | else |
| 6452 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 6453 | if (clock->p2 == 4) |
| 6454 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 6455 | } |
| 6456 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 6457 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 6458 | dpll |= DPLL_DVO_2X_MODE; |
| 6459 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 6460 | if (intel_pipe_will_have_type(crtc, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6461 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 6462 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 6463 | else |
| 6464 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 6465 | |
| 6466 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6467 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6468 | } |
| 6469 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 6470 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6471 | { |
| 6472 | struct drm_device *dev = intel_crtc->base.dev; |
| 6473 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6474 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6475 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 6476 | struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6477 | &intel_crtc->config->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 6478 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 6479 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6480 | |
| 6481 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 6482 | * the hw state checker will get angry at the mismatch. */ |
| 6483 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 6484 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6485 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 6486 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6487 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6488 | crtc_vtotal -= 1; |
| 6489 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 6490 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6491 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 6492 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 6493 | else |
| 6494 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 6495 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 6496 | if (vsyncshift < 0) |
| 6497 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6498 | } |
| 6499 | |
| 6500 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6501 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6502 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6503 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6504 | (adjusted_mode->crtc_hdisplay - 1) | |
| 6505 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6506 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6507 | (adjusted_mode->crtc_hblank_start - 1) | |
| 6508 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6509 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6510 | (adjusted_mode->crtc_hsync_start - 1) | |
| 6511 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 6512 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6513 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6514 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6515 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6516 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6517 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6518 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6519 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6520 | (adjusted_mode->crtc_vsync_start - 1) | |
| 6521 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 6522 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 6523 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 6524 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 6525 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 6526 | * bits. */ |
| 6527 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 6528 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 6529 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 6530 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6531 | /* pipesrc controls the size that is scaled from, which should |
| 6532 | * always be the user's requested size. |
| 6533 | */ |
| 6534 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6535 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 6536 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6537 | } |
| 6538 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6539 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6540 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6541 | { |
| 6542 | struct drm_device *dev = crtc->base.dev; |
| 6543 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6544 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 6545 | uint32_t tmp; |
| 6546 | |
| 6547 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6548 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 6549 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6550 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6551 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 6552 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6553 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6554 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 6555 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6556 | |
| 6557 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6558 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 6559 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6560 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6561 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 6562 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6563 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6564 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 6565 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6566 | |
| 6567 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6568 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 6569 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 6570 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6571 | } |
| 6572 | |
| 6573 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 6574 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 6575 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 6576 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6577 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 6578 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6579 | } |
| 6580 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6581 | void intel_mode_from_pipe_config(struct drm_display_mode *mode, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6582 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6583 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6584 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 6585 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 6586 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 6587 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6588 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6589 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 6590 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 6591 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 6592 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6593 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6594 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6595 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6596 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
| 6597 | mode->flags |= pipe_config->base.adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6598 | } |
| 6599 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6600 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 6601 | { |
| 6602 | struct drm_device *dev = intel_crtc->base.dev; |
| 6603 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6604 | uint32_t pipeconf; |
| 6605 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6606 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6607 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 6608 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 6609 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 6610 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 6611 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6612 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6613 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6614 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6615 | /* only g4x and later have fancy bpc/dither controls */ |
| 6616 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6617 | /* Bspec claims that we can't use dithering for 30bpp pipes. */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6618 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6619 | pipeconf |= PIPECONF_DITHER_EN | |
| 6620 | PIPECONF_DITHER_TYPE_SP; |
| 6621 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6622 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6623 | case 18: |
| 6624 | pipeconf |= PIPECONF_6BPC; |
| 6625 | break; |
| 6626 | case 24: |
| 6627 | pipeconf |= PIPECONF_8BPC; |
| 6628 | break; |
| 6629 | case 30: |
| 6630 | pipeconf |= PIPECONF_10BPC; |
| 6631 | break; |
| 6632 | default: |
| 6633 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 6634 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6635 | } |
| 6636 | } |
| 6637 | |
| 6638 | if (HAS_PIPE_CXSR(dev)) { |
| 6639 | if (intel_crtc->lowfreq_avail) { |
| 6640 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 6641 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 6642 | } else { |
| 6643 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6644 | } |
| 6645 | } |
| 6646 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6647 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) { |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 6648 | if (INTEL_INFO(dev)->gen < 4 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6649 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 6650 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 6651 | else |
| 6652 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 6653 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6654 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 6655 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6656 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6657 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 6658 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6659 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 6660 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 6661 | } |
| 6662 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6663 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 6664 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6665 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 6666 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6667 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6668 | int refclk, num_connectors = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6669 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | a16af72 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 6670 | bool ok, has_reduced_clock = false; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6671 | bool is_lvds = false, is_dsi = false; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6672 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 6673 | const intel_limit_t *limit; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6674 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 6675 | for_each_intel_encoder(dev, encoder) { |
| 6676 | if (encoder->new_crtc != crtc) |
| 6677 | continue; |
| 6678 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6679 | switch (encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6680 | case INTEL_OUTPUT_LVDS: |
| 6681 | is_lvds = true; |
| 6682 | break; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6683 | case INTEL_OUTPUT_DSI: |
| 6684 | is_dsi = true; |
| 6685 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 6686 | default: |
| 6687 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6688 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 6689 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6690 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6691 | } |
| 6692 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6693 | if (is_dsi) |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6694 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6695 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6696 | if (!crtc_state->clock_set) { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6697 | refclk = i9xx_get_refclk(crtc, num_connectors); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6698 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6699 | /* |
| 6700 | * Returns a set of divisors for the desired target clock with |
| 6701 | * the given refclk, or FALSE. The returned values represent |
| 6702 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + |
| 6703 | * 2) / p1 / p2. |
| 6704 | */ |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6705 | limit = intel_limit(crtc, refclk); |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 6706 | ok = dev_priv->display.find_dpll(limit, crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6707 | crtc_state->port_clock, |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6708 | refclk, NULL, &clock); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6709 | if (!ok) { |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6710 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 6711 | return -EINVAL; |
| 6712 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6713 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6714 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 6715 | /* |
| 6716 | * Ensure we match the reduced clock's P to the target |
| 6717 | * clock. If the clocks don't match, we can't switch |
| 6718 | * the display clock by using the FP0/FP1. In such case |
| 6719 | * we will disable the LVDS downclock feature. |
| 6720 | */ |
| 6721 | has_reduced_clock = |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 6722 | dev_priv->display.find_dpll(limit, crtc, |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6723 | dev_priv->lvds_downclock, |
| 6724 | refclk, &clock, |
| 6725 | &reduced_clock); |
| 6726 | } |
| 6727 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6728 | crtc_state->dpll.n = clock.n; |
| 6729 | crtc_state->dpll.m1 = clock.m1; |
| 6730 | crtc_state->dpll.m2 = clock.m2; |
| 6731 | crtc_state->dpll.p1 = clock.p1; |
| 6732 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6733 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6734 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6735 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6736 | i8xx_update_pll(crtc, crtc_state, |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6737 | has_reduced_clock ? &reduced_clock : NULL, |
| 6738 | num_connectors); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6739 | } else if (IS_CHERRYVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6740 | chv_update_pll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6741 | } else if (IS_VALLEYVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6742 | vlv_update_pll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6743 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6744 | i9xx_update_pll(crtc, crtc_state, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6745 | has_reduced_clock ? &reduced_clock : NULL, |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 6746 | num_connectors); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6747 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6748 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 6749 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6750 | } |
| 6751 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6752 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6753 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6754 | { |
| 6755 | struct drm_device *dev = crtc->base.dev; |
| 6756 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6757 | uint32_t tmp; |
| 6758 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 6759 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 6760 | return; |
| 6761 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6762 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6763 | if (!(tmp & PFIT_ENABLE)) |
| 6764 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6765 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6766 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6767 | if (INTEL_INFO(dev)->gen < 4) { |
| 6768 | if (crtc->pipe != PIPE_B) |
| 6769 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6770 | } else { |
| 6771 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 6772 | return; |
| 6773 | } |
| 6774 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6775 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6776 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 6777 | if (INTEL_INFO(dev)->gen < 5) |
| 6778 | pipe_config->gmch_pfit.lvds_border_bits = |
| 6779 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 6780 | } |
| 6781 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6782 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6783 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6784 | { |
| 6785 | struct drm_device *dev = crtc->base.dev; |
| 6786 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6787 | int pipe = pipe_config->cpu_transcoder; |
| 6788 | intel_clock_t clock; |
| 6789 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 6790 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6791 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 6792 | /* In case of MIPI DPLL will not even be used */ |
| 6793 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) |
| 6794 | return; |
| 6795 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6796 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6797 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6798 | mutex_unlock(&dev_priv->dpio_lock); |
| 6799 | |
| 6800 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 6801 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 6802 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 6803 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 6804 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 6805 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 6806 | vlv_clock(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6807 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 6808 | /* clock.dot is the fast clock */ |
| 6809 | pipe_config->port_clock = clock.dot / 5; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6810 | } |
| 6811 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 6812 | static void |
| 6813 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 6814 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6815 | { |
| 6816 | struct drm_device *dev = crtc->base.dev; |
| 6817 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6818 | u32 val, base, offset; |
| 6819 | int pipe = crtc->pipe, plane = crtc->plane; |
| 6820 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 6821 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6822 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 6823 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6824 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 6825 | val = I915_READ(DSPCNTR(plane)); |
| 6826 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 6827 | return; |
| 6828 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 6829 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 6830 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6831 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 6832 | return; |
| 6833 | } |
| 6834 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 6835 | fb = &intel_fb->base; |
| 6836 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 6837 | if (INTEL_INFO(dev)->gen >= 4) { |
| 6838 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 6839 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 6840 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 6841 | } |
| 6842 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6843 | |
| 6844 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 6845 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6846 | fb->pixel_format = fourcc; |
| 6847 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6848 | |
| 6849 | if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 6850 | if (plane_config->tiling) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6851 | offset = I915_READ(DSPTILEOFF(plane)); |
| 6852 | else |
| 6853 | offset = I915_READ(DSPLINOFF(plane)); |
| 6854 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 6855 | } else { |
| 6856 | base = I915_READ(DSPADDR(plane)); |
| 6857 | } |
| 6858 | plane_config->base = base; |
| 6859 | |
| 6860 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6861 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 6862 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6863 | |
| 6864 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6865 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6866 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6867 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 6868 | fb->pixel_format, |
| 6869 | fb->modifier[0]); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6870 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 6871 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6872 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 6873 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 6874 | pipe_name(pipe), plane, fb->width, fb->height, |
| 6875 | fb->bits_per_pixel, base, fb->pitches[0], |
| 6876 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6877 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 6878 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6879 | } |
| 6880 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 6881 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6882 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 6883 | { |
| 6884 | struct drm_device *dev = crtc->base.dev; |
| 6885 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6886 | int pipe = pipe_config->cpu_transcoder; |
| 6887 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
| 6888 | intel_clock_t clock; |
| 6889 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2; |
| 6890 | int refclk = 100000; |
| 6891 | |
| 6892 | mutex_lock(&dev_priv->dpio_lock); |
| 6893 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 6894 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 6895 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 6896 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
| 6897 | mutex_unlock(&dev_priv->dpio_lock); |
| 6898 | |
| 6899 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; |
| 6900 | clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff); |
| 6901 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 6902 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 6903 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 6904 | |
| 6905 | chv_clock(refclk, &clock); |
| 6906 | |
| 6907 | /* clock.dot is the fast clock */ |
| 6908 | pipe_config->port_clock = clock.dot / 5; |
| 6909 | } |
| 6910 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6911 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6912 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6913 | { |
| 6914 | struct drm_device *dev = crtc->base.dev; |
| 6915 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6916 | uint32_t tmp; |
| 6917 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 6918 | if (!intel_display_power_is_enabled(dev_priv, |
| 6919 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 6920 | return false; |
| 6921 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 6922 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 6923 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 6924 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6925 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 6926 | if (!(tmp & PIPECONF_ENABLE)) |
| 6927 | return false; |
| 6928 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 6929 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
| 6930 | switch (tmp & PIPECONF_BPC_MASK) { |
| 6931 | case PIPECONF_6BPC: |
| 6932 | pipe_config->pipe_bpp = 18; |
| 6933 | break; |
| 6934 | case PIPECONF_8BPC: |
| 6935 | pipe_config->pipe_bpp = 24; |
| 6936 | break; |
| 6937 | case PIPECONF_10BPC: |
| 6938 | pipe_config->pipe_bpp = 30; |
| 6939 | break; |
| 6940 | default: |
| 6941 | break; |
| 6942 | } |
| 6943 | } |
| 6944 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 6945 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
| 6946 | pipe_config->limited_color_range = true; |
| 6947 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 6948 | if (INTEL_INFO(dev)->gen < 4) |
| 6949 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 6950 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6951 | intel_get_pipe_timings(crtc, pipe_config); |
| 6952 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6953 | i9xx_get_pfit_config(crtc, pipe_config); |
| 6954 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6955 | if (INTEL_INFO(dev)->gen >= 4) { |
| 6956 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
| 6957 | pipe_config->pixel_multiplier = |
| 6958 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 6959 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6960 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6961 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 6962 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 6963 | pipe_config->pixel_multiplier = |
| 6964 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 6965 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 6966 | } else { |
| 6967 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 6968 | * port and will be fixed up in the encoder->get_config |
| 6969 | * function. */ |
| 6970 | pipe_config->pixel_multiplier = 1; |
| 6971 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6972 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
| 6973 | if (!IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 6974 | /* |
| 6975 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 6976 | * on 830. Filter it out here so that we don't |
| 6977 | * report errors due to that. |
| 6978 | */ |
| 6979 | if (IS_I830(dev)) |
| 6980 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 6981 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6982 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 6983 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 6984 | } else { |
| 6985 | /* Mask out read-only status bits. */ |
| 6986 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 6987 | DPLL_PORTC_READY_MASK | |
| 6988 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6989 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 6990 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 6991 | if (IS_CHERRYVIEW(dev)) |
| 6992 | chv_crtc_clock_get(crtc, pipe_config); |
| 6993 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6994 | vlv_crtc_clock_get(crtc, pipe_config); |
| 6995 | else |
| 6996 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 6997 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 6998 | return true; |
| 6999 | } |
| 7000 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7001 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7002 | { |
| 7003 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7004 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7005 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7006 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7007 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7008 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7009 | bool has_ck505 = false; |
| 7010 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7011 | |
| 7012 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 7013 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7014 | switch (encoder->type) { |
| 7015 | case INTEL_OUTPUT_LVDS: |
| 7016 | has_panel = true; |
| 7017 | has_lvds = true; |
| 7018 | break; |
| 7019 | case INTEL_OUTPUT_EDP: |
| 7020 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 7021 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7022 | has_cpu_edp = true; |
| 7023 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7024 | default: |
| 7025 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7026 | } |
| 7027 | } |
| 7028 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7029 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7030 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7031 | can_ssc = has_ck505; |
| 7032 | } else { |
| 7033 | has_ck505 = false; |
| 7034 | can_ssc = true; |
| 7035 | } |
| 7036 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 7037 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 7038 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7039 | |
| 7040 | /* Ironlake: try to setup display ref clock before DPLL |
| 7041 | * enabling. This is only under driver's control after |
| 7042 | * PCH B stepping, previous chipset stepping should be |
| 7043 | * ignoring this setting. |
| 7044 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7045 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7046 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7047 | /* As we must carefully and slowly disable/enable each source in turn, |
| 7048 | * compute the final state we want first and check if we need to |
| 7049 | * make any changes at all. |
| 7050 | */ |
| 7051 | final = val; |
| 7052 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7053 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7054 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7055 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7056 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7057 | |
| 7058 | final &= ~DREF_SSC_SOURCE_MASK; |
| 7059 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 7060 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7061 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7062 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7063 | final |= DREF_SSC_SOURCE_ENABLE; |
| 7064 | |
| 7065 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7066 | final |= DREF_SSC1_ENABLE; |
| 7067 | |
| 7068 | if (has_cpu_edp) { |
| 7069 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7070 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 7071 | else |
| 7072 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 7073 | } else |
| 7074 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 7075 | } else { |
| 7076 | final |= DREF_SSC_SOURCE_DISABLE; |
| 7077 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 7078 | } |
| 7079 | |
| 7080 | if (final == val) |
| 7081 | return; |
| 7082 | |
| 7083 | /* Always enable nonspread source */ |
| 7084 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 7085 | |
| 7086 | if (has_ck505) |
| 7087 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 7088 | else |
| 7089 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7090 | |
| 7091 | if (has_panel) { |
| 7092 | val &= ~DREF_SSC_SOURCE_MASK; |
| 7093 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7094 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7095 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7096 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7097 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7098 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 7099 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7100 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7101 | |
| 7102 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7103 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7104 | POSTING_READ(PCH_DREF_CONTROL); |
| 7105 | udelay(200); |
| 7106 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7107 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7108 | |
| 7109 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7110 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7111 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7112 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7113 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 7114 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7115 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7116 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7117 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7118 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7119 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7120 | POSTING_READ(PCH_DREF_CONTROL); |
| 7121 | udelay(200); |
| 7122 | } else { |
| 7123 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 7124 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7125 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7126 | |
| 7127 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7128 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7129 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7130 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7131 | POSTING_READ(PCH_DREF_CONTROL); |
| 7132 | udelay(200); |
| 7133 | |
| 7134 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7135 | val &= ~DREF_SSC_SOURCE_MASK; |
| 7136 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7137 | |
| 7138 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7139 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7140 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7141 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7142 | POSTING_READ(PCH_DREF_CONTROL); |
| 7143 | udelay(200); |
| 7144 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7145 | |
| 7146 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7147 | } |
| 7148 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7149 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7150 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7151 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7152 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7153 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 7154 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 7155 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7156 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7157 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 7158 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 7159 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7160 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7161 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 7162 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 7163 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7164 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7165 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 7166 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 7167 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7168 | } |
| 7169 | |
| 7170 | /* WaMPhyProgramming:hsw */ |
| 7171 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 7172 | { |
| 7173 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7174 | |
| 7175 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 7176 | tmp &= ~(0xFF << 24); |
| 7177 | tmp |= (0x12 << 24); |
| 7178 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 7179 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7180 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 7181 | tmp |= (1 << 11); |
| 7182 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 7183 | |
| 7184 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 7185 | tmp |= (1 << 11); |
| 7186 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 7187 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7188 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 7189 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 7190 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 7191 | |
| 7192 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 7193 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 7194 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 7195 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7196 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 7197 | tmp &= ~(7 << 13); |
| 7198 | tmp |= (5 << 13); |
| 7199 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7200 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7201 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 7202 | tmp &= ~(7 << 13); |
| 7203 | tmp |= (5 << 13); |
| 7204 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7205 | |
| 7206 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 7207 | tmp &= ~0xFF; |
| 7208 | tmp |= 0x1C; |
| 7209 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 7210 | |
| 7211 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 7212 | tmp &= ~0xFF; |
| 7213 | tmp |= 0x1C; |
| 7214 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 7215 | |
| 7216 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 7217 | tmp &= ~(0xFF << 16); |
| 7218 | tmp |= (0x1C << 16); |
| 7219 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 7220 | |
| 7221 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 7222 | tmp &= ~(0xFF << 16); |
| 7223 | tmp |= (0x1C << 16); |
| 7224 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 7225 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7226 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 7227 | tmp |= (1 << 27); |
| 7228 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7229 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7230 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 7231 | tmp |= (1 << 27); |
| 7232 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7233 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7234 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 7235 | tmp &= ~(0xF << 28); |
| 7236 | tmp |= (4 << 28); |
| 7237 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7238 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7239 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 7240 | tmp &= ~(0xF << 28); |
| 7241 | tmp |= (4 << 28); |
| 7242 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7243 | } |
| 7244 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7245 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 7246 | * Programming" based on the parameters passed: |
| 7247 | * - Sequence to enable CLKOUT_DP |
| 7248 | * - Sequence to enable CLKOUT_DP without spread |
| 7249 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 7250 | */ |
| 7251 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 7252 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7253 | { |
| 7254 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7255 | uint32_t reg, tmp; |
| 7256 | |
| 7257 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 7258 | with_spread = true; |
| 7259 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && |
| 7260 | with_fdi, "LP PCH doesn't have FDI\n")) |
| 7261 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7262 | |
| 7263 | mutex_lock(&dev_priv->dpio_lock); |
| 7264 | |
| 7265 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 7266 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 7267 | tmp |= SBI_SSCCTL_PATHALT; |
| 7268 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 7269 | |
| 7270 | udelay(24); |
| 7271 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7272 | if (with_spread) { |
| 7273 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 7274 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 7275 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7276 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7277 | if (with_fdi) { |
| 7278 | lpt_reset_fdi_mphy(dev_priv); |
| 7279 | lpt_program_fdi_mphy(dev_priv); |
| 7280 | } |
| 7281 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7282 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7283 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 7284 | SBI_GEN0 : SBI_DBUFF0; |
| 7285 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 7286 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 7287 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 7288 | |
| 7289 | mutex_unlock(&dev_priv->dpio_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7290 | } |
| 7291 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 7292 | /* Sequence to disable CLKOUT_DP */ |
| 7293 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 7294 | { |
| 7295 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7296 | uint32_t reg, tmp; |
| 7297 | |
| 7298 | mutex_lock(&dev_priv->dpio_lock); |
| 7299 | |
| 7300 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 7301 | SBI_GEN0 : SBI_DBUFF0; |
| 7302 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 7303 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 7304 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 7305 | |
| 7306 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 7307 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 7308 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 7309 | tmp |= SBI_SSCCTL_PATHALT; |
| 7310 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 7311 | udelay(32); |
| 7312 | } |
| 7313 | tmp |= SBI_SSCCTL_DISABLE; |
| 7314 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 7315 | } |
| 7316 | |
| 7317 | mutex_unlock(&dev_priv->dpio_lock); |
| 7318 | } |
| 7319 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7320 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 7321 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7322 | struct intel_encoder *encoder; |
| 7323 | bool has_vga = false; |
| 7324 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 7325 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7326 | switch (encoder->type) { |
| 7327 | case INTEL_OUTPUT_ANALOG: |
| 7328 | has_vga = true; |
| 7329 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7330 | default: |
| 7331 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7332 | } |
| 7333 | } |
| 7334 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 7335 | if (has_vga) |
| 7336 | lpt_enable_clkout_dp(dev, true, true); |
| 7337 | else |
| 7338 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7339 | } |
| 7340 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7341 | /* |
| 7342 | * Initialize reference clocks when the driver loads |
| 7343 | */ |
| 7344 | void intel_init_pch_refclk(struct drm_device *dev) |
| 7345 | { |
| 7346 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 7347 | ironlake_init_pch_refclk(dev); |
| 7348 | else if (HAS_PCH_LPT(dev)) |
| 7349 | lpt_init_pch_refclk(dev); |
| 7350 | } |
| 7351 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7352 | static int ironlake_get_refclk(struct drm_crtc *crtc) |
| 7353 | { |
| 7354 | struct drm_device *dev = crtc->dev; |
| 7355 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7356 | struct intel_encoder *encoder; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7357 | int num_connectors = 0; |
| 7358 | bool is_lvds = false; |
| 7359 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 7360 | for_each_intel_encoder(dev, encoder) { |
| 7361 | if (encoder->new_crtc != to_intel_crtc(crtc)) |
| 7362 | continue; |
| 7363 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7364 | switch (encoder->type) { |
| 7365 | case INTEL_OUTPUT_LVDS: |
| 7366 | is_lvds = true; |
| 7367 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7368 | default: |
| 7369 | break; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7370 | } |
| 7371 | num_connectors++; |
| 7372 | } |
| 7373 | |
| 7374 | 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] | 7375 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7376 | dev_priv->vbt.lvds_ssc_freq); |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 7377 | return dev_priv->vbt.lvds_ssc_freq; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7378 | } |
| 7379 | |
| 7380 | return 120000; |
| 7381 | } |
| 7382 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 7383 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7384 | { |
| 7385 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 7386 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7387 | int pipe = intel_crtc->pipe; |
| 7388 | uint32_t val; |
| 7389 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 7390 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7391 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7392 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7393 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7394 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7395 | break; |
| 7396 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7397 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7398 | break; |
| 7399 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7400 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7401 | break; |
| 7402 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7403 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7404 | break; |
| 7405 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 7406 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7407 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7408 | } |
| 7409 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7410 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7411 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 7412 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7413 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7414 | val |= PIPECONF_INTERLACED_ILK; |
| 7415 | else |
| 7416 | val |= PIPECONF_PROGRESSIVE; |
| 7417 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7418 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 7419 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 7420 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7421 | I915_WRITE(PIPECONF(pipe), val); |
| 7422 | POSTING_READ(PIPECONF(pipe)); |
| 7423 | } |
| 7424 | |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7425 | /* |
| 7426 | * Set up the pipe CSC unit. |
| 7427 | * |
| 7428 | * Currently only full range RGB to limited range RGB conversion |
| 7429 | * is supported, but eventually this should handle various |
| 7430 | * RGB<->YCbCr scenarios as well. |
| 7431 | */ |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 7432 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7433 | { |
| 7434 | struct drm_device *dev = crtc->dev; |
| 7435 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7436 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7437 | int pipe = intel_crtc->pipe; |
| 7438 | uint16_t coeff = 0x7800; /* 1.0 */ |
| 7439 | |
| 7440 | /* |
| 7441 | * TODO: Check what kind of values actually come out of the pipe |
| 7442 | * with these coeff/postoff values and adjust to get the best |
| 7443 | * accuracy. Perhaps we even need to take the bpc value into |
| 7444 | * consideration. |
| 7445 | */ |
| 7446 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7447 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7448 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
| 7449 | |
| 7450 | /* |
| 7451 | * GY/GU and RY/RU should be the other way around according |
| 7452 | * to BSpec, but reality doesn't agree. Just set them up in |
| 7453 | * a way that results in the correct picture. |
| 7454 | */ |
| 7455 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); |
| 7456 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); |
| 7457 | |
| 7458 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); |
| 7459 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); |
| 7460 | |
| 7461 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); |
| 7462 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); |
| 7463 | |
| 7464 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); |
| 7465 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); |
| 7466 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); |
| 7467 | |
| 7468 | if (INTEL_INFO(dev)->gen > 6) { |
| 7469 | uint16_t postoff = 0; |
| 7470 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7471 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 32cf0cb | 2013-11-28 22:10:38 +0200 | [diff] [blame] | 7472 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7473 | |
| 7474 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); |
| 7475 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); |
| 7476 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); |
| 7477 | |
| 7478 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); |
| 7479 | } else { |
| 7480 | uint32_t mode = CSC_MODE_YUV_TO_RGB; |
| 7481 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7482 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7483 | mode |= CSC_BLACK_SCREEN_OFFSET; |
| 7484 | |
| 7485 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); |
| 7486 | } |
| 7487 | } |
| 7488 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 7489 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7490 | { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7491 | struct drm_device *dev = crtc->dev; |
| 7492 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7493 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7494 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7495 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7496 | uint32_t val; |
| 7497 | |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 7498 | val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7499 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7500 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7501 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 7502 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7503 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7504 | val |= PIPECONF_INTERLACED_ILK; |
| 7505 | else |
| 7506 | val |= PIPECONF_PROGRESSIVE; |
| 7507 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 7508 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 7509 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 7510 | |
| 7511 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); |
| 7512 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7513 | |
Satheeshakrishna M | 3cdf122c | 2014-04-08 15:46:53 +0530 | [diff] [blame] | 7514 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7515 | val = 0; |
| 7516 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7517 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7518 | case 18: |
| 7519 | val |= PIPEMISC_DITHER_6_BPC; |
| 7520 | break; |
| 7521 | case 24: |
| 7522 | val |= PIPEMISC_DITHER_8_BPC; |
| 7523 | break; |
| 7524 | case 30: |
| 7525 | val |= PIPEMISC_DITHER_10_BPC; |
| 7526 | break; |
| 7527 | case 36: |
| 7528 | val |= PIPEMISC_DITHER_12_BPC; |
| 7529 | break; |
| 7530 | default: |
| 7531 | /* Case prevented by pipe_config_set_bpp. */ |
| 7532 | BUG(); |
| 7533 | } |
| 7534 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7535 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7536 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 7537 | |
| 7538 | I915_WRITE(PIPEMISC(pipe), val); |
| 7539 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7540 | } |
| 7541 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7542 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7543 | struct intel_crtc_state *crtc_state, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7544 | intel_clock_t *clock, |
| 7545 | bool *has_reduced_clock, |
| 7546 | intel_clock_t *reduced_clock) |
| 7547 | { |
| 7548 | struct drm_device *dev = crtc->dev; |
| 7549 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 7550 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7551 | int refclk; |
| 7552 | const intel_limit_t *limit; |
Daniel Vetter | a16af72 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 7553 | bool ret, is_lvds = false; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7554 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 7555 | is_lvds = intel_pipe_will_have_type(intel_crtc, INTEL_OUTPUT_LVDS); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7556 | |
| 7557 | refclk = ironlake_get_refclk(crtc); |
| 7558 | |
| 7559 | /* |
| 7560 | * Returns a set of divisors for the desired target clock with the given |
| 7561 | * refclk, or FALSE. The returned values represent the clock equation: |
| 7562 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 7563 | */ |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7564 | limit = intel_limit(intel_crtc, refclk); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 7565 | ret = dev_priv->display.find_dpll(limit, intel_crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7566 | crtc_state->port_clock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7567 | refclk, NULL, clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7568 | if (!ret) |
| 7569 | return false; |
| 7570 | |
| 7571 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 7572 | /* |
| 7573 | * Ensure we match the reduced clock's P to the target clock. |
| 7574 | * If the clocks don't match, we can't switch the display clock |
| 7575 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 7576 | * downclock feature. |
| 7577 | */ |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7578 | *has_reduced_clock = |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 7579 | dev_priv->display.find_dpll(limit, intel_crtc, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7580 | dev_priv->lvds_downclock, |
| 7581 | refclk, clock, |
| 7582 | reduced_clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7583 | } |
| 7584 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7585 | return true; |
| 7586 | } |
| 7587 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7588 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 7589 | { |
| 7590 | /* |
| 7591 | * Account for spread spectrum to avoid |
| 7592 | * oversubscribing the link. Max center spread |
| 7593 | * is 2.5%; use 5% for safety's sake. |
| 7594 | */ |
| 7595 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 7596 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7597 | } |
| 7598 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7599 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 7600 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7601 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 7602 | } |
| 7603 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7604 | static uint32_t ironlake_compute_dpll(struct intel_crtc *intel_crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7605 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7606 | u32 *fp, |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7607 | intel_clock_t *reduced_clock, u32 *fp2) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7608 | { |
| 7609 | struct drm_crtc *crtc = &intel_crtc->base; |
| 7610 | struct drm_device *dev = crtc->dev; |
| 7611 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7612 | struct intel_encoder *intel_encoder; |
| 7613 | uint32_t dpll; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 7614 | int factor, num_connectors = 0; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 7615 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7616 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 7617 | for_each_intel_encoder(dev, intel_encoder) { |
| 7618 | if (intel_encoder->new_crtc != to_intel_crtc(crtc)) |
| 7619 | continue; |
| 7620 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7621 | switch (intel_encoder->type) { |
| 7622 | case INTEL_OUTPUT_LVDS: |
| 7623 | is_lvds = true; |
| 7624 | break; |
| 7625 | case INTEL_OUTPUT_SDVO: |
| 7626 | case INTEL_OUTPUT_HDMI: |
| 7627 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7628 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7629 | default: |
| 7630 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7631 | } |
| 7632 | |
| 7633 | num_connectors++; |
| 7634 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7635 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7636 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7637 | factor = 21; |
| 7638 | if (is_lvds) { |
| 7639 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 7640 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 7641 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7642 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7643 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7644 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7645 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7646 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
Daniel Vetter | 7d0ac5b | 2013-04-04 22:20:32 +0200 | [diff] [blame] | 7647 | *fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7648 | |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7649 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
| 7650 | *fp2 |= FP_CB_TUNE; |
| 7651 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 7652 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7653 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7654 | if (is_lvds) |
| 7655 | dpll |= DPLLB_MODE_LVDS; |
| 7656 | else |
| 7657 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7658 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7659 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7660 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7661 | |
| 7662 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7663 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7664 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7665 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7666 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7667 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7668 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7669 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7670 | dpll |= (1 << (crtc_state->dpll.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7671 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7672 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7673 | case 5: |
| 7674 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7675 | break; |
| 7676 | case 7: |
| 7677 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7678 | break; |
| 7679 | case 10: |
| 7680 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7681 | break; |
| 7682 | case 14: |
| 7683 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7684 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7685 | } |
| 7686 | |
Daniel Vetter | b4c09f3 | 2013-04-30 14:01:42 +0200 | [diff] [blame] | 7687 | 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] | 7688 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7689 | else |
| 7690 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7691 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 7692 | return dpll | DPLL_VCO_ENABLE; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7693 | } |
| 7694 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7695 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 7696 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7697 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7698 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7699 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7700 | u32 dpll = 0, fp = 0, fp2 = 0; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 7701 | bool ok, has_reduced_clock = false; |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 7702 | bool is_lvds = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 7703 | struct intel_shared_dpll *pll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7704 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7705 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7706 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 7707 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 7708 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 7709 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7710 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7711 | &has_reduced_clock, &reduced_clock); |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7712 | if (!ok && !crtc_state->clock_set) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7713 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7714 | return -EINVAL; |
| 7715 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7716 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7717 | if (!crtc_state->clock_set) { |
| 7718 | crtc_state->dpll.n = clock.n; |
| 7719 | crtc_state->dpll.m1 = clock.m1; |
| 7720 | crtc_state->dpll.m2 = clock.m2; |
| 7721 | crtc_state->dpll.p1 = clock.p1; |
| 7722 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7723 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7724 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 7725 | /* CPU eDP is the only output that doesn't need a PCH PLL of its own. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7726 | if (crtc_state->has_pch_encoder) { |
| 7727 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7728 | if (has_reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7729 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7730 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7731 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7732 | &fp, &reduced_clock, |
| 7733 | has_reduced_clock ? &fp2 : NULL); |
| 7734 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7735 | crtc_state->dpll_hw_state.dpll = dpll; |
| 7736 | crtc_state->dpll_hw_state.fp0 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7737 | if (has_reduced_clock) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7738 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7739 | else |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7740 | crtc_state->dpll_hw_state.fp1 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7741 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7742 | pll = intel_get_shared_dpll(crtc, crtc_state); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 7743 | if (pll == NULL) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 7744 | DRM_DEBUG_DRIVER("failed to find PLL for pipe %c\n", |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7745 | pipe_name(crtc->pipe)); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 7746 | return -EINVAL; |
| 7747 | } |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 7748 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7749 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 7750 | if (is_lvds && has_reduced_clock && i915.powersave) |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7751 | crtc->lowfreq_avail = true; |
Daniel Vetter | bcd644e | 2013-06-05 13:34:22 +0200 | [diff] [blame] | 7752 | else |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7753 | crtc->lowfreq_avail = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 7754 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7755 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7756 | } |
| 7757 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7758 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 7759 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7760 | { |
| 7761 | struct drm_device *dev = crtc->base.dev; |
| 7762 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7763 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7764 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7765 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 7766 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 7767 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 7768 | & ~TU_SIZE_MASK; |
| 7769 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 7770 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 7771 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7772 | } |
| 7773 | |
| 7774 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 7775 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7776 | struct intel_link_m_n *m_n, |
| 7777 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7778 | { |
| 7779 | struct drm_device *dev = crtc->base.dev; |
| 7780 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7781 | enum pipe pipe = crtc->pipe; |
| 7782 | |
| 7783 | if (INTEL_INFO(dev)->gen >= 5) { |
| 7784 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 7785 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 7786 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 7787 | & ~TU_SIZE_MASK; |
| 7788 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 7789 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 7790 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7791 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 7792 | * gen < 8) and if DRRS is supported (to make sure the |
| 7793 | * registers are not unnecessarily read). |
| 7794 | */ |
| 7795 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7796 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7797 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 7798 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 7799 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 7800 | & ~TU_SIZE_MASK; |
| 7801 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 7802 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 7803 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7804 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7805 | } else { |
| 7806 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 7807 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 7808 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 7809 | & ~TU_SIZE_MASK; |
| 7810 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 7811 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 7812 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7813 | } |
| 7814 | } |
| 7815 | |
| 7816 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7817 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7818 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 7819 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7820 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 7821 | else |
| 7822 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7823 | &pipe_config->dp_m_n, |
| 7824 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7825 | } |
| 7826 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7827 | static void ironlake_get_fdi_m_n_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7828 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7829 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7830 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7831 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7832 | } |
| 7833 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 7834 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7835 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 7836 | { |
| 7837 | struct drm_device *dev = crtc->base.dev; |
| 7838 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7839 | uint32_t tmp; |
| 7840 | |
| 7841 | tmp = I915_READ(PS_CTL(crtc->pipe)); |
| 7842 | |
| 7843 | if (tmp & PS_ENABLE) { |
| 7844 | pipe_config->pch_pfit.enabled = true; |
| 7845 | pipe_config->pch_pfit.pos = I915_READ(PS_WIN_POS(crtc->pipe)); |
| 7846 | pipe_config->pch_pfit.size = I915_READ(PS_WIN_SZ(crtc->pipe)); |
| 7847 | } |
| 7848 | } |
| 7849 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7850 | static void |
| 7851 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 7852 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7853 | { |
| 7854 | struct drm_device *dev = crtc->base.dev; |
| 7855 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 7856 | u32 val, base, offset, stride_mult, tiling; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7857 | int pipe = crtc->pipe; |
| 7858 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 7859 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7860 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7861 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7862 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7863 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7864 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7865 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7866 | return; |
| 7867 | } |
| 7868 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7869 | fb = &intel_fb->base; |
| 7870 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7871 | val = I915_READ(PLANE_CTL(pipe, 0)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7872 | if (!(val & PLANE_CTL_ENABLE)) |
| 7873 | goto error; |
| 7874 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7875 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
| 7876 | fourcc = skl_format_to_fourcc(pixel_format, |
| 7877 | val & PLANE_CTL_ORDER_RGBX, |
| 7878 | val & PLANE_CTL_ALPHA_MASK); |
| 7879 | fb->pixel_format = fourcc; |
| 7880 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
| 7881 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 7882 | tiling = val & PLANE_CTL_TILED_MASK; |
| 7883 | switch (tiling) { |
| 7884 | case PLANE_CTL_TILED_LINEAR: |
| 7885 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; |
| 7886 | break; |
| 7887 | case PLANE_CTL_TILED_X: |
| 7888 | plane_config->tiling = I915_TILING_X; |
| 7889 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 7890 | break; |
| 7891 | case PLANE_CTL_TILED_Y: |
| 7892 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; |
| 7893 | break; |
| 7894 | case PLANE_CTL_TILED_YF: |
| 7895 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; |
| 7896 | break; |
| 7897 | default: |
| 7898 | MISSING_CASE(tiling); |
| 7899 | goto error; |
| 7900 | } |
| 7901 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7902 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
| 7903 | plane_config->base = base; |
| 7904 | |
| 7905 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); |
| 7906 | |
| 7907 | val = I915_READ(PLANE_SIZE(pipe, 0)); |
| 7908 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 7909 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 7910 | |
| 7911 | val = I915_READ(PLANE_STRIDE(pipe, 0)); |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 7912 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 7913 | fb->pixel_format); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7914 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 7915 | |
| 7916 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 7917 | fb->pixel_format, |
| 7918 | fb->modifier[0]); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7919 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7920 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7921 | |
| 7922 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7923 | pipe_name(pipe), fb->width, fb->height, |
| 7924 | fb->bits_per_pixel, base, fb->pitches[0], |
| 7925 | plane_config->size); |
| 7926 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7927 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7928 | return; |
| 7929 | |
| 7930 | error: |
| 7931 | kfree(fb); |
| 7932 | } |
| 7933 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7934 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7935 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7936 | { |
| 7937 | struct drm_device *dev = crtc->base.dev; |
| 7938 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7939 | uint32_t tmp; |
| 7940 | |
| 7941 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 7942 | |
| 7943 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 7944 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7945 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 7946 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 7947 | |
| 7948 | /* We currently do not free assignements of panel fitters on |
| 7949 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 7950 | * differentiates them) so just WARN about this case for now. */ |
| 7951 | if (IS_GEN7(dev)) { |
| 7952 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 7953 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 7954 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7955 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7956 | } |
| 7957 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7958 | static void |
| 7959 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, |
| 7960 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7961 | { |
| 7962 | struct drm_device *dev = crtc->base.dev; |
| 7963 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7964 | u32 val, base, offset; |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 7965 | int pipe = crtc->pipe; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7966 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 7967 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7968 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7969 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7970 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7971 | val = I915_READ(DSPCNTR(pipe)); |
| 7972 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 7973 | return; |
| 7974 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7975 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7976 | if (!intel_fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7977 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7978 | return; |
| 7979 | } |
| 7980 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7981 | fb = &intel_fb->base; |
| 7982 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7983 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7984 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7985 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7986 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 7987 | } |
| 7988 | } |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7989 | |
| 7990 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7991 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7992 | fb->pixel_format = fourcc; |
| 7993 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7994 | |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 7995 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7996 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 7997 | offset = I915_READ(DSPOFFSET(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 7998 | } else { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7999 | if (plane_config->tiling) |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8000 | offset = I915_READ(DSPTILEOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8001 | else |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8002 | offset = I915_READ(DSPLINOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8003 | } |
| 8004 | plane_config->base = base; |
| 8005 | |
| 8006 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8007 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 8008 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8009 | |
| 8010 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8011 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8012 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8013 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8014 | fb->pixel_format, |
| 8015 | fb->modifier[0]); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8016 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8017 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8018 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 8019 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8020 | pipe_name(pipe), fb->width, fb->height, |
| 8021 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8022 | plane_config->size); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8023 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8024 | plane_config->fb = intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8025 | } |
| 8026 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8027 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8028 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8029 | { |
| 8030 | struct drm_device *dev = crtc->base.dev; |
| 8031 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8032 | uint32_t tmp; |
| 8033 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8034 | if (!intel_display_power_is_enabled(dev_priv, |
| 8035 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 8036 | return false; |
| 8037 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8038 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8039 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8040 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8041 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8042 | if (!(tmp & PIPECONF_ENABLE)) |
| 8043 | return false; |
| 8044 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8045 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8046 | case PIPECONF_6BPC: |
| 8047 | pipe_config->pipe_bpp = 18; |
| 8048 | break; |
| 8049 | case PIPECONF_8BPC: |
| 8050 | pipe_config->pipe_bpp = 24; |
| 8051 | break; |
| 8052 | case PIPECONF_10BPC: |
| 8053 | pipe_config->pipe_bpp = 30; |
| 8054 | break; |
| 8055 | case PIPECONF_12BPC: |
| 8056 | pipe_config->pipe_bpp = 36; |
| 8057 | break; |
| 8058 | default: |
| 8059 | break; |
| 8060 | } |
| 8061 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8062 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 8063 | pipe_config->limited_color_range = true; |
| 8064 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 8065 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8066 | struct intel_shared_dpll *pll; |
| 8067 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8068 | pipe_config->has_pch_encoder = true; |
| 8069 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8070 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 8071 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8072 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8073 | |
| 8074 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8075 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8076 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 8077 | pipe_config->shared_dpll = |
| 8078 | (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8079 | } else { |
| 8080 | tmp = I915_READ(PCH_DPLL_SEL); |
| 8081 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
| 8082 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; |
| 8083 | else |
| 8084 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; |
| 8085 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8086 | |
| 8087 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 8088 | |
| 8089 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 8090 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 8091 | |
| 8092 | tmp = pipe_config->dpll_hw_state.dpll; |
| 8093 | pipe_config->pixel_multiplier = |
| 8094 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 8095 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8096 | |
| 8097 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8098 | } else { |
| 8099 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8100 | } |
| 8101 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8102 | intel_get_pipe_timings(crtc, pipe_config); |
| 8103 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8104 | ironlake_get_pfit_config(crtc, pipe_config); |
| 8105 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8106 | return true; |
| 8107 | } |
| 8108 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8109 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 8110 | { |
| 8111 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8112 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8113 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 8114 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8115 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8116 | pipe_name(crtc->pipe)); |
| 8117 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8118 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
| 8119 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
| 8120 | I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 8121 | I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
| 8122 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 8123 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8124 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 8125 | if (IS_HASWELL(dev)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8126 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 8127 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8128 | I915_STATE_WARN(I915_READ(BLC_PWM_PCH_CTL1) & BLM_PCH_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8129 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8130 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8131 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8132 | I915_STATE_WARN(I915_READ(PCH_GTC_CTL) & PCH_GTC_ENABLE, "PCH GTC enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8133 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 8134 | /* |
| 8135 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 8136 | * interrupts remain enabled. We used to check for that, but since it's |
| 8137 | * gen-specific and since we only disable LCPLL after we fully disable |
| 8138 | * the interrupts, the check below should be enough. |
| 8139 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8140 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8141 | } |
| 8142 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8143 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 8144 | { |
| 8145 | struct drm_device *dev = dev_priv->dev; |
| 8146 | |
| 8147 | if (IS_HASWELL(dev)) |
| 8148 | return I915_READ(D_COMP_HSW); |
| 8149 | else |
| 8150 | return I915_READ(D_COMP_BDW); |
| 8151 | } |
| 8152 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8153 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 8154 | { |
| 8155 | struct drm_device *dev = dev_priv->dev; |
| 8156 | |
| 8157 | if (IS_HASWELL(dev)) { |
| 8158 | mutex_lock(&dev_priv->rps.hw_lock); |
| 8159 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 8160 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 8161 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8162 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 8163 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8164 | I915_WRITE(D_COMP_BDW, val); |
| 8165 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8166 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8167 | } |
| 8168 | |
| 8169 | /* |
| 8170 | * This function implements pieces of two sequences from BSpec: |
| 8171 | * - Sequence for display software to disable LCPLL |
| 8172 | * - Sequence for display software to allow package C8+ |
| 8173 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 8174 | * register. Callers should take care of disabling all the display engine |
| 8175 | * functions, doing the mode unset, fixing interrupts, etc. |
| 8176 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 8177 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 8178 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8179 | { |
| 8180 | uint32_t val; |
| 8181 | |
| 8182 | assert_can_disable_lcpll(dev_priv); |
| 8183 | |
| 8184 | val = I915_READ(LCPLL_CTL); |
| 8185 | |
| 8186 | if (switch_to_fclk) { |
| 8187 | val |= LCPLL_CD_SOURCE_FCLK; |
| 8188 | I915_WRITE(LCPLL_CTL, val); |
| 8189 | |
| 8190 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 8191 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 8192 | DRM_ERROR("Switching to FCLK failed\n"); |
| 8193 | |
| 8194 | val = I915_READ(LCPLL_CTL); |
| 8195 | } |
| 8196 | |
| 8197 | val |= LCPLL_PLL_DISABLE; |
| 8198 | I915_WRITE(LCPLL_CTL, val); |
| 8199 | POSTING_READ(LCPLL_CTL); |
| 8200 | |
| 8201 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 8202 | DRM_ERROR("LCPLL still locked\n"); |
| 8203 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8204 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8205 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8206 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8207 | ndelay(100); |
| 8208 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8209 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 8210 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8211 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 8212 | |
| 8213 | if (allow_power_down) { |
| 8214 | val = I915_READ(LCPLL_CTL); |
| 8215 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 8216 | I915_WRITE(LCPLL_CTL, val); |
| 8217 | POSTING_READ(LCPLL_CTL); |
| 8218 | } |
| 8219 | } |
| 8220 | |
| 8221 | /* |
| 8222 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 8223 | * source. |
| 8224 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 8225 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8226 | { |
| 8227 | uint32_t val; |
| 8228 | |
| 8229 | val = I915_READ(LCPLL_CTL); |
| 8230 | |
| 8231 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 8232 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 8233 | return; |
| 8234 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 8235 | /* |
| 8236 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 8237 | * we'll hang the machine. To prevent PC8 state, just enable force_wake. |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 8238 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 8239 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 8240 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8241 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 8242 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 8243 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 8244 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8245 | } |
| 8246 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8247 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8248 | val |= D_COMP_COMP_FORCE; |
| 8249 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8250 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8251 | |
| 8252 | val = I915_READ(LCPLL_CTL); |
| 8253 | val &= ~LCPLL_PLL_DISABLE; |
| 8254 | I915_WRITE(LCPLL_CTL, val); |
| 8255 | |
| 8256 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 8257 | DRM_ERROR("LCPLL not locked yet\n"); |
| 8258 | |
| 8259 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 8260 | val = I915_READ(LCPLL_CTL); |
| 8261 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 8262 | I915_WRITE(LCPLL_CTL, val); |
| 8263 | |
| 8264 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 8265 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 8266 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 8267 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 8268 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 8269 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8270 | } |
| 8271 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 8272 | /* |
| 8273 | * Package states C8 and deeper are really deep PC states that can only be |
| 8274 | * reached when all the devices on the system allow it, so even if the graphics |
| 8275 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 8276 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 8277 | * |
| 8278 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 8279 | * well is disabled and most interrupts are disabled, and these are also |
| 8280 | * requirements for runtime PM. When these conditions are met, we manually do |
| 8281 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 8282 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 8283 | * hang the machine. |
| 8284 | * |
| 8285 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 8286 | * the state of some registers, so when we come back from PC8+ we need to |
| 8287 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 8288 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 8289 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 8290 | * because of the runtime PM support). |
| 8291 | * |
| 8292 | * For more, read "Display Sequences for Package C8" on the hardware |
| 8293 | * documentation. |
| 8294 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 8295 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8296 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8297 | struct drm_device *dev = dev_priv->dev; |
| 8298 | uint32_t val; |
| 8299 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8300 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 8301 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8302 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 8303 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 8304 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8305 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8306 | } |
| 8307 | |
| 8308 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8309 | hsw_disable_lcpll(dev_priv, true, true); |
| 8310 | } |
| 8311 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 8312 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8313 | { |
| 8314 | struct drm_device *dev = dev_priv->dev; |
| 8315 | uint32_t val; |
| 8316 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8317 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 8318 | |
| 8319 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8320 | lpt_init_pch_refclk(dev); |
| 8321 | |
| 8322 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 8323 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 8324 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8325 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8326 | } |
| 8327 | |
| 8328 | intel_prepare_ddi(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8329 | } |
| 8330 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8331 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 8332 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 8333 | { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8334 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 8335 | return -EINVAL; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 8336 | |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8337 | crtc->lowfreq_avail = false; |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 8338 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8339 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8340 | } |
| 8341 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8342 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 8343 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8344 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8345 | { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 8346 | u32 temp, dpll_ctl1; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8347 | |
| 8348 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
| 8349 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); |
| 8350 | |
| 8351 | switch (pipe_config->ddi_pll_sel) { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 8352 | case SKL_DPLL0: |
| 8353 | /* |
| 8354 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part |
| 8355 | * of the shared DPLL framework and thus needs to be read out |
| 8356 | * separately |
| 8357 | */ |
| 8358 | dpll_ctl1 = I915_READ(DPLL_CTRL1); |
| 8359 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; |
| 8360 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8361 | case SKL_DPLL1: |
| 8362 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; |
| 8363 | break; |
| 8364 | case SKL_DPLL2: |
| 8365 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; |
| 8366 | break; |
| 8367 | case SKL_DPLL3: |
| 8368 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; |
| 8369 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8370 | } |
| 8371 | } |
| 8372 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 8373 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 8374 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8375 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 8376 | { |
| 8377 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 8378 | |
| 8379 | switch (pipe_config->ddi_pll_sel) { |
| 8380 | case PORT_CLK_SEL_WRPLL1: |
| 8381 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; |
| 8382 | break; |
| 8383 | case PORT_CLK_SEL_WRPLL2: |
| 8384 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; |
| 8385 | break; |
| 8386 | } |
| 8387 | } |
| 8388 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8389 | static void haswell_get_ddi_port_state(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8390 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8391 | { |
| 8392 | struct drm_device *dev = crtc->base.dev; |
| 8393 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 8394 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8395 | enum port port; |
| 8396 | uint32_t tmp; |
| 8397 | |
| 8398 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 8399 | |
| 8400 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 8401 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8402 | if (IS_SKYLAKE(dev)) |
| 8403 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
| 8404 | else |
| 8405 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 8406 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 8407 | if (pipe_config->shared_dpll >= 0) { |
| 8408 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 8409 | |
| 8410 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 8411 | &pipe_config->dpll_hw_state)); |
| 8412 | } |
| 8413 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8414 | /* |
| 8415 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 8416 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 8417 | * the PCH transcoder is on. |
| 8418 | */ |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 8419 | if (INTEL_INFO(dev)->gen < 9 && |
| 8420 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8421 | pipe_config->has_pch_encoder = true; |
| 8422 | |
| 8423 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 8424 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8425 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 8426 | |
| 8427 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 8428 | } |
| 8429 | } |
| 8430 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8431 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8432 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8433 | { |
| 8434 | struct drm_device *dev = crtc->base.dev; |
| 8435 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8436 | enum intel_display_power_domain pfit_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8437 | uint32_t tmp; |
| 8438 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8439 | if (!intel_display_power_is_enabled(dev_priv, |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 8440 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 8441 | return false; |
| 8442 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8443 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8444 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
| 8445 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8446 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 8447 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 8448 | enum pipe trans_edp_pipe; |
| 8449 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 8450 | default: |
| 8451 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 8452 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 8453 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 8454 | trans_edp_pipe = PIPE_A; |
| 8455 | break; |
| 8456 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 8457 | trans_edp_pipe = PIPE_B; |
| 8458 | break; |
| 8459 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 8460 | trans_edp_pipe = PIPE_C; |
| 8461 | break; |
| 8462 | } |
| 8463 | |
| 8464 | if (trans_edp_pipe == crtc->pipe) |
| 8465 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 8466 | } |
| 8467 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8468 | if (!intel_display_power_is_enabled(dev_priv, |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8469 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
Paulo Zanoni | 2bfce95 | 2013-04-18 16:35:40 -0300 | [diff] [blame] | 8470 | return false; |
| 8471 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8472 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8473 | if (!(tmp & PIPECONF_ENABLE)) |
| 8474 | return false; |
| 8475 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8476 | haswell_get_ddi_port_state(crtc, pipe_config); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8477 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8478 | intel_get_pipe_timings(crtc, pipe_config); |
| 8479 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8480 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8481 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
| 8482 | if (IS_SKYLAKE(dev)) |
| 8483 | skylake_get_pfit_config(crtc, pipe_config); |
| 8484 | else |
| 8485 | ironlake_get_pfit_config(crtc, pipe_config); |
| 8486 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8487 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 8488 | if (IS_HASWELL(dev)) |
| 8489 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 8490 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 8491 | |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 8492 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
| 8493 | pipe_config->pixel_multiplier = |
| 8494 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 8495 | } else { |
| 8496 | pipe_config->pixel_multiplier = 1; |
| 8497 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8498 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8499 | return true; |
| 8500 | } |
| 8501 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8502 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8503 | { |
| 8504 | struct drm_device *dev = crtc->dev; |
| 8505 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8506 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8507 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8508 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8509 | if (base) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8510 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
| 8511 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8512 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 8513 | |
| 8514 | switch (stride) { |
| 8515 | default: |
| 8516 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 8517 | width, stride); |
| 8518 | stride = 256; |
| 8519 | /* fallthrough */ |
| 8520 | case 256: |
| 8521 | case 512: |
| 8522 | case 1024: |
| 8523 | case 2048: |
| 8524 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8525 | } |
| 8526 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8527 | cntl |= CURSOR_ENABLE | |
| 8528 | CURSOR_GAMMA_ENABLE | |
| 8529 | CURSOR_FORMAT_ARGB | |
| 8530 | CURSOR_STRIDE(stride); |
| 8531 | |
| 8532 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8533 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8534 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8535 | if (intel_crtc->cursor_cntl != 0 && |
| 8536 | (intel_crtc->cursor_base != base || |
| 8537 | intel_crtc->cursor_size != size || |
| 8538 | intel_crtc->cursor_cntl != cntl)) { |
| 8539 | /* On these chipsets we can only modify the base/size/stride |
| 8540 | * whilst the cursor is disabled. |
| 8541 | */ |
| 8542 | I915_WRITE(_CURACNTR, 0); |
| 8543 | POSTING_READ(_CURACNTR); |
| 8544 | intel_crtc->cursor_cntl = 0; |
| 8545 | } |
| 8546 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8547 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8548 | I915_WRITE(_CURABASE, base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8549 | intel_crtc->cursor_base = base; |
| 8550 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8551 | |
| 8552 | if (intel_crtc->cursor_size != size) { |
| 8553 | I915_WRITE(CURSIZE, size); |
| 8554 | intel_crtc->cursor_size = size; |
| 8555 | } |
| 8556 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8557 | if (intel_crtc->cursor_cntl != cntl) { |
| 8558 | I915_WRITE(_CURACNTR, cntl); |
| 8559 | POSTING_READ(_CURACNTR); |
| 8560 | intel_crtc->cursor_cntl = cntl; |
| 8561 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8562 | } |
| 8563 | |
| 8564 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8565 | { |
| 8566 | struct drm_device *dev = crtc->dev; |
| 8567 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8568 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8569 | int pipe = intel_crtc->pipe; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8570 | uint32_t cntl; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8571 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8572 | cntl = 0; |
| 8573 | if (base) { |
| 8574 | cntl = MCURSOR_GAMMA_ENABLE; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8575 | switch (intel_crtc->base.cursor->state->crtc_w) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8576 | case 64: |
| 8577 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 8578 | break; |
| 8579 | case 128: |
| 8580 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 8581 | break; |
| 8582 | case 256: |
| 8583 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 8584 | break; |
| 8585 | default: |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8586 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8587 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8588 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8589 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 8590 | |
| 8591 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 8592 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8593 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8594 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 8595 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 8596 | cntl |= CURSOR_ROTATE_180; |
| 8597 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8598 | if (intel_crtc->cursor_cntl != cntl) { |
| 8599 | I915_WRITE(CURCNTR(pipe), cntl); |
| 8600 | POSTING_READ(CURCNTR(pipe)); |
| 8601 | intel_crtc->cursor_cntl = cntl; |
| 8602 | } |
| 8603 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8604 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8605 | I915_WRITE(CURBASE(pipe), base); |
| 8606 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8607 | |
| 8608 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8609 | } |
| 8610 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8611 | /* 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] | 8612 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 8613 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8614 | { |
| 8615 | struct drm_device *dev = crtc->dev; |
| 8616 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8617 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8618 | int pipe = intel_crtc->pipe; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 8619 | int x = crtc->cursor_x; |
| 8620 | int y = crtc->cursor_y; |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8621 | u32 base = 0, pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8622 | |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8623 | if (on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8624 | base = intel_crtc->cursor_addr; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8625 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8626 | if (x >= intel_crtc->config->pipe_src_w) |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8627 | base = 0; |
| 8628 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8629 | if (y >= intel_crtc->config->pipe_src_h) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8630 | base = 0; |
| 8631 | |
| 8632 | if (x < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8633 | if (x + intel_crtc->base.cursor->state->crtc_w <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8634 | base = 0; |
| 8635 | |
| 8636 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 8637 | x = -x; |
| 8638 | } |
| 8639 | pos |= x << CURSOR_X_SHIFT; |
| 8640 | |
| 8641 | if (y < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8642 | if (y + intel_crtc->base.cursor->state->crtc_h <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8643 | base = 0; |
| 8644 | |
| 8645 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 8646 | y = -y; |
| 8647 | } |
| 8648 | pos |= y << CURSOR_Y_SHIFT; |
| 8649 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8650 | if (base == 0 && intel_crtc->cursor_base == 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8651 | return; |
| 8652 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8653 | I915_WRITE(CURPOS(pipe), pos); |
| 8654 | |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 8655 | /* ILK+ do this automagically */ |
| 8656 | if (HAS_GMCH_DISPLAY(dev) && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 8657 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8658 | base += (intel_crtc->base.cursor->state->crtc_h * |
| 8659 | intel_crtc->base.cursor->state->crtc_w - 1) * 4; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 8660 | } |
| 8661 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 8662 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8663 | i845_update_cursor(crtc, base); |
| 8664 | else |
| 8665 | i9xx_update_cursor(crtc, base); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8666 | } |
| 8667 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8668 | static bool cursor_size_ok(struct drm_device *dev, |
| 8669 | uint32_t width, uint32_t height) |
| 8670 | { |
| 8671 | if (width == 0 || height == 0) |
| 8672 | return false; |
| 8673 | |
| 8674 | /* |
| 8675 | * 845g/865g are special in that they are only limited by |
| 8676 | * the width of their cursors, the height is arbitrary up to |
| 8677 | * the precision of the register. Everything else requires |
| 8678 | * square cursors, limited to a few power-of-two sizes. |
| 8679 | */ |
| 8680 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 8681 | if ((width & 63) != 0) |
| 8682 | return false; |
| 8683 | |
| 8684 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 8685 | return false; |
| 8686 | |
| 8687 | if (height > 1023) |
| 8688 | return false; |
| 8689 | } else { |
| 8690 | switch (width | height) { |
| 8691 | case 256: |
| 8692 | case 128: |
| 8693 | if (IS_GEN2(dev)) |
| 8694 | return false; |
| 8695 | case 64: |
| 8696 | break; |
| 8697 | default: |
| 8698 | return false; |
| 8699 | } |
| 8700 | } |
| 8701 | |
| 8702 | return true; |
| 8703 | } |
| 8704 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8705 | 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] | 8706 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8707 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 8708 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8709 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8710 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 8711 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8712 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 8713 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 8714 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 8715 | } |
| 8716 | |
| 8717 | intel_crtc_load_lut(crtc); |
| 8718 | } |
| 8719 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8720 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 8721 | static struct drm_display_mode load_detect_mode = { |
| 8722 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 8723 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 8724 | }; |
| 8725 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 8726 | struct drm_framebuffer * |
| 8727 | __intel_framebuffer_create(struct drm_device *dev, |
| 8728 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 8729 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8730 | { |
| 8731 | struct intel_framebuffer *intel_fb; |
| 8732 | int ret; |
| 8733 | |
| 8734 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 8735 | if (!intel_fb) { |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 8736 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8737 | return ERR_PTR(-ENOMEM); |
| 8738 | } |
| 8739 | |
| 8740 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8741 | if (ret) |
| 8742 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8743 | |
| 8744 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8745 | err: |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 8746 | drm_gem_object_unreference(&obj->base); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8747 | kfree(intel_fb); |
| 8748 | |
| 8749 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8750 | } |
| 8751 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 8752 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 8753 | intel_framebuffer_create(struct drm_device *dev, |
| 8754 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 8755 | struct drm_i915_gem_object *obj) |
| 8756 | { |
| 8757 | struct drm_framebuffer *fb; |
| 8758 | int ret; |
| 8759 | |
| 8760 | ret = i915_mutex_lock_interruptible(dev); |
| 8761 | if (ret) |
| 8762 | return ERR_PTR(ret); |
| 8763 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 8764 | mutex_unlock(&dev->struct_mutex); |
| 8765 | |
| 8766 | return fb; |
| 8767 | } |
| 8768 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8769 | static u32 |
| 8770 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 8771 | { |
| 8772 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 8773 | return ALIGN(pitch, 64); |
| 8774 | } |
| 8775 | |
| 8776 | static u32 |
| 8777 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 8778 | { |
| 8779 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 8780 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8781 | } |
| 8782 | |
| 8783 | static struct drm_framebuffer * |
| 8784 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 8785 | struct drm_display_mode *mode, |
| 8786 | int depth, int bpp) |
| 8787 | { |
| 8788 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 8789 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8790 | |
| 8791 | obj = i915_gem_alloc_object(dev, |
| 8792 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 8793 | if (obj == NULL) |
| 8794 | return ERR_PTR(-ENOMEM); |
| 8795 | |
| 8796 | mode_cmd.width = mode->hdisplay; |
| 8797 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 8798 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 8799 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 8800 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8801 | |
| 8802 | return intel_framebuffer_create(dev, &mode_cmd, obj); |
| 8803 | } |
| 8804 | |
| 8805 | static struct drm_framebuffer * |
| 8806 | mode_fits_in_fbdev(struct drm_device *dev, |
| 8807 | struct drm_display_mode *mode) |
| 8808 | { |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 8809 | #ifdef CONFIG_DRM_I915_FBDEV |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8810 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8811 | struct drm_i915_gem_object *obj; |
| 8812 | struct drm_framebuffer *fb; |
| 8813 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 8814 | if (!dev_priv->fbdev) |
| 8815 | return NULL; |
| 8816 | |
| 8817 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8818 | return NULL; |
| 8819 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 8820 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 8821 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8822 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 8823 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 8824 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 8825 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8826 | return NULL; |
| 8827 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 8828 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8829 | return NULL; |
| 8830 | |
| 8831 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 8832 | #else |
| 8833 | return NULL; |
| 8834 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8835 | } |
| 8836 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8837 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8838 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8839 | struct intel_load_detect_pipe *old, |
| 8840 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8841 | { |
| 8842 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8843 | struct intel_encoder *intel_encoder = |
| 8844 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8845 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 8846 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8847 | struct drm_crtc *crtc = NULL; |
| 8848 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8849 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8850 | struct drm_mode_config *config = &dev->mode_config; |
| 8851 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8852 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8853 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 8854 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 8855 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8856 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8857 | retry: |
| 8858 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 8859 | if (ret) |
| 8860 | goto fail_unlock; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 8861 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8862 | /* |
| 8863 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 8864 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8865 | * - if the connector already has an assigned crtc, use it (but make |
| 8866 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 8867 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8868 | * - try to find the first unused crtc that can drive this connector, |
| 8869 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8870 | */ |
| 8871 | |
| 8872 | /* See if we already have a CRTC for this connector */ |
| 8873 | if (encoder->crtc) { |
| 8874 | crtc = encoder->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8875 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8876 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 8877 | if (ret) |
| 8878 | goto fail_unlock; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 8879 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 8880 | if (ret) |
| 8881 | goto fail_unlock; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 8882 | |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8883 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8884 | old->load_detect_temp = false; |
| 8885 | |
| 8886 | /* Make sure the crtc and connector are running */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8887 | if (connector->dpms != DRM_MODE_DPMS_ON) |
| 8888 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8889 | |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8890 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8891 | } |
| 8892 | |
| 8893 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 8894 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8895 | i++; |
| 8896 | if (!(encoder->possible_crtcs & (1 << i))) |
| 8897 | continue; |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 8898 | if (possible_crtc->state->enable) |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 8899 | continue; |
| 8900 | /* This can occur when applying the pipe A quirk on resume. */ |
| 8901 | if (to_intel_crtc(possible_crtc)->new_enabled) |
| 8902 | continue; |
| 8903 | |
| 8904 | crtc = possible_crtc; |
| 8905 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8906 | } |
| 8907 | |
| 8908 | /* |
| 8909 | * If we didn't find an unused CRTC, don't use any. |
| 8910 | */ |
| 8911 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8912 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8913 | goto fail_unlock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8914 | } |
| 8915 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8916 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 8917 | if (ret) |
| 8918 | goto fail_unlock; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 8919 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 8920 | if (ret) |
| 8921 | goto fail_unlock; |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 8922 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
| 8923 | to_intel_connector(connector)->new_encoder = intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8924 | |
| 8925 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8926 | intel_crtc->new_enabled = true; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8927 | intel_crtc->new_config = intel_crtc->config; |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 8928 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8929 | old->load_detect_temp = true; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8930 | old->release_fb = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8931 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 8932 | if (!mode) |
| 8933 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8934 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8935 | /* We need a framebuffer large enough to accommodate all accesses |
| 8936 | * that the plane may generate whilst we perform load detection. |
| 8937 | * We can not rely on the fbcon either being present (we get called |
| 8938 | * during its initialisation to detect all boot displays, or it may |
| 8939 | * not even exist) or that it is large enough to satisfy the |
| 8940 | * requested mode. |
| 8941 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8942 | fb = mode_fits_in_fbdev(dev, mode); |
| 8943 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8944 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8945 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
| 8946 | old->release_fb = fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8947 | } else |
| 8948 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8949 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8950 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8951 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8952 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8953 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 8954 | if (intel_set_mode(crtc, mode, 0, 0, fb)) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 8955 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8956 | if (old->release_fb) |
| 8957 | old->release_fb->funcs->destroy(old->release_fb); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8958 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8959 | } |
Daniel Vetter | 9128b04 | 2015-03-03 17:31:21 +0100 | [diff] [blame] | 8960 | crtc->primary->crtc = crtc; |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8961 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8962 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 8963 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8964 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8965 | |
| 8966 | fail: |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 8967 | intel_crtc->new_enabled = crtc->state->enable; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8968 | if (intel_crtc->new_enabled) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8969 | intel_crtc->new_config = intel_crtc->config; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8970 | else |
| 8971 | intel_crtc->new_config = NULL; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8972 | fail_unlock: |
| 8973 | if (ret == -EDEADLK) { |
| 8974 | drm_modeset_backoff(ctx); |
| 8975 | goto retry; |
| 8976 | } |
| 8977 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8978 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8979 | } |
| 8980 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8981 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 8982 | struct intel_load_detect_pipe *old) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8983 | { |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8984 | struct intel_encoder *intel_encoder = |
| 8985 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 8986 | struct drm_encoder *encoder = &intel_encoder->base; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 8987 | struct drm_crtc *crtc = encoder->crtc; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8988 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8989 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8990 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 8991 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 8992 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8993 | |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8994 | if (old->load_detect_temp) { |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 8995 | to_intel_connector(connector)->new_encoder = NULL; |
| 8996 | intel_encoder->new_crtc = NULL; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 8997 | intel_crtc->new_enabled = false; |
| 8998 | intel_crtc->new_config = NULL; |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 8999 | intel_set_mode(crtc, NULL, 0, 0, NULL); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9000 | |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 9001 | if (old->release_fb) { |
| 9002 | drm_framebuffer_unregister_private(old->release_fb); |
| 9003 | drm_framebuffer_unreference(old->release_fb); |
| 9004 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9005 | |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 9006 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9007 | } |
| 9008 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 9009 | /* Switch crtc and encoder back off if necessary */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9010 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
| 9011 | connector->funcs->dpms(connector, old->dpms_mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9012 | } |
| 9013 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9014 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9015 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9016 | { |
| 9017 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9018 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 9019 | |
| 9020 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 9021 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9022 | else if (HAS_PCH_SPLIT(dev)) |
| 9023 | return 120000; |
| 9024 | else if (!IS_GEN2(dev)) |
| 9025 | return 96000; |
| 9026 | else |
| 9027 | return 48000; |
| 9028 | } |
| 9029 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9030 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9031 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9032 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9033 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9034 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9035 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9036 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9037 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9038 | u32 fp; |
| 9039 | intel_clock_t clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9040 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9041 | |
| 9042 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9043 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9044 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9045 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9046 | |
| 9047 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 9048 | if (IS_PINEVIEW(dev)) { |
| 9049 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 9050 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 9051 | } else { |
| 9052 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 9053 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 9054 | } |
| 9055 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 9056 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 9057 | if (IS_PINEVIEW(dev)) |
| 9058 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 9059 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 9060 | else |
| 9061 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9062 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 9063 | |
| 9064 | switch (dpll & DPLL_MODE_MASK) { |
| 9065 | case DPLLB_MODE_DAC_SERIAL: |
| 9066 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 9067 | 5 : 10; |
| 9068 | break; |
| 9069 | case DPLLB_MODE_LVDS: |
| 9070 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 9071 | 7 : 14; |
| 9072 | break; |
| 9073 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 9074 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9075 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9076 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9077 | } |
| 9078 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 9079 | if (IS_PINEVIEW(dev)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9080 | pineview_clock(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 9081 | else |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9082 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9083 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 9084 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 9085 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9086 | |
| 9087 | if (is_lvds) { |
| 9088 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 9089 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 9090 | |
| 9091 | if (lvds & LVDS_CLKB_POWER_UP) |
| 9092 | clock.p2 = 7; |
| 9093 | else |
| 9094 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9095 | } else { |
| 9096 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 9097 | clock.p1 = 2; |
| 9098 | else { |
| 9099 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 9100 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 9101 | } |
| 9102 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 9103 | clock.p2 = 4; |
| 9104 | else |
| 9105 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9106 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9107 | |
| 9108 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9109 | } |
| 9110 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9111 | /* |
| 9112 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 9113 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9114 | * encoder's get_config() function. |
| 9115 | */ |
| 9116 | pipe_config->port_clock = clock.dot; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9117 | } |
| 9118 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9119 | int intel_dotclock_calculate(int link_freq, |
| 9120 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9121 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9122 | /* |
| 9123 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 9124 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9125 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 9126 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9127 | * |
| 9128 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 9129 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9130 | */ |
| 9131 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9132 | if (!m_n->link_n) |
| 9133 | return 0; |
| 9134 | |
| 9135 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 9136 | } |
| 9137 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9138 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9139 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9140 | { |
| 9141 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9142 | |
| 9143 | /* read out port_clock from the DPLL */ |
| 9144 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9145 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9146 | /* |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9147 | * This value does not include pixel_multiplier. |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 9148 | * We will check that port_clock and adjusted_mode.crtc_clock |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9149 | * agree once we know their relationship in the encoder's |
| 9150 | * get_config() function. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9151 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 9152 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9153 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
| 9154 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9155 | } |
| 9156 | |
| 9157 | /** Returns the currently programmed mode of the given pipe. */ |
| 9158 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 9159 | struct drm_crtc *crtc) |
| 9160 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 9161 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9162 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9163 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9164 | struct drm_display_mode *mode; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9165 | struct intel_crtc_state pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 9166 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 9167 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 9168 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 9169 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9170 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9171 | |
| 9172 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 9173 | if (!mode) |
| 9174 | return NULL; |
| 9175 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9176 | /* |
| 9177 | * Construct a pipe_config sufficient for getting the clock info |
| 9178 | * back out of crtc_clock_get. |
| 9179 | * |
| 9180 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 9181 | * to use a real value here instead. |
| 9182 | */ |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9183 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9184 | pipe_config.pixel_multiplier = 1; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9185 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 9186 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 9187 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9188 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
| 9189 | |
Ville Syrjälä | 773ae03 | 2013-09-23 17:48:20 +0300 | [diff] [blame] | 9190 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9191 | mode->hdisplay = (htot & 0xffff) + 1; |
| 9192 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 9193 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 9194 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 9195 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 9196 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 9197 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 9198 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 9199 | |
| 9200 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9201 | |
| 9202 | return mode; |
| 9203 | } |
| 9204 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9205 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 9206 | { |
| 9207 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9208 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9209 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9210 | |
Sonika Jindal | baff296 | 2014-07-22 11:16:35 +0530 | [diff] [blame] | 9211 | if (!HAS_GMCH_DISPLAY(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9212 | return; |
| 9213 | |
| 9214 | if (!dev_priv->lvds_downclock_avail) |
| 9215 | return; |
| 9216 | |
| 9217 | /* |
| 9218 | * Since this is called by a timer, we should never get here in |
| 9219 | * the manual case. |
| 9220 | */ |
| 9221 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9222 | int pipe = intel_crtc->pipe; |
| 9223 | int dpll_reg = DPLL(pipe); |
Daniel Vetter | dc257cf | 2012-05-07 11:30:46 +0200 | [diff] [blame] | 9224 | int dpll; |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9225 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9226 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9227 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 9228 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9229 | |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9230 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9231 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 9232 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 9233 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9234 | dpll = I915_READ(dpll_reg); |
| 9235 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9236 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9237 | } |
| 9238 | |
| 9239 | } |
| 9240 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9241 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9242 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9243 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9244 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9245 | if (dev_priv->mm.busy) |
| 9246 | return; |
| 9247 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 9248 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9249 | i915_update_gfx_val(dev_priv); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 9250 | if (INTEL_INFO(dev)->gen >= 6) |
| 9251 | gen6_rps_busy(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9252 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9253 | } |
| 9254 | |
| 9255 | void intel_mark_idle(struct drm_device *dev) |
| 9256 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9257 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9258 | struct drm_crtc *crtc; |
| 9259 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9260 | if (!dev_priv->mm.busy) |
| 9261 | return; |
| 9262 | |
| 9263 | dev_priv->mm.busy = false; |
| 9264 | |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 9265 | if (!i915.powersave) |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 9266 | goto out; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9267 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 9268 | for_each_crtc(dev, crtc) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9269 | if (!crtc->primary->fb) |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9270 | continue; |
| 9271 | |
| 9272 | intel_decrease_pllclock(crtc); |
| 9273 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9274 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 9275 | if (INTEL_INFO(dev)->gen >= 6) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9276 | gen6_rps_idle(dev->dev_private); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 9277 | |
| 9278 | out: |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 9279 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9280 | } |
| 9281 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 9282 | static void intel_crtc_set_state(struct intel_crtc *crtc, |
| 9283 | struct intel_crtc_state *crtc_state) |
| 9284 | { |
| 9285 | kfree(crtc->config); |
| 9286 | crtc->config = crtc_state; |
Ander Conselvan de Oliveira | 16f3f65 | 2015-01-15 14:55:27 +0200 | [diff] [blame] | 9287 | crtc->base.state = &crtc_state->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 9288 | } |
| 9289 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9290 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 9291 | { |
| 9292 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9293 | struct drm_device *dev = crtc->dev; |
| 9294 | struct intel_unpin_work *work; |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9295 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 9296 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9297 | work = intel_crtc->unpin_work; |
| 9298 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 9299 | spin_unlock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9300 | |
| 9301 | if (work) { |
| 9302 | cancel_work_sync(&work->work); |
| 9303 | kfree(work); |
| 9304 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9305 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 9306 | intel_crtc_set_state(intel_crtc, NULL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9307 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9308 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9309 | kfree(intel_crtc); |
| 9310 | } |
| 9311 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9312 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 9313 | { |
| 9314 | struct intel_unpin_work *work = |
| 9315 | container_of(__work, struct intel_unpin_work, work); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9316 | struct drm_device *dev = work->crtc->dev; |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9317 | enum pipe pipe = to_intel_crtc(work->crtc)->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9318 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9319 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 9320 | intel_unpin_fb_obj(intel_fb_obj(work->old_fb)); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9321 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 9322 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 9323 | intel_fbc_update(dev); |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 9324 | |
| 9325 | if (work->flip_queued_req) |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 9326 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9327 | mutex_unlock(&dev->struct_mutex); |
| 9328 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9329 | intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 9330 | drm_framebuffer_unreference(work->old_fb); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9331 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9332 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
| 9333 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); |
| 9334 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9335 | kfree(work); |
| 9336 | } |
| 9337 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9338 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9339 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9340 | { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9341 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9342 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9343 | unsigned long flags; |
| 9344 | |
| 9345 | /* Ignore early vblank irqs */ |
| 9346 | if (intel_crtc == NULL) |
| 9347 | return; |
| 9348 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 9349 | /* |
| 9350 | * This is called both by irq handlers and the reset code (to complete |
| 9351 | * lost pageflips) so needs the full irqsave spinlocks. |
| 9352 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9353 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9354 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9355 | |
| 9356 | /* Ensure we don't miss a work->pending update ... */ |
| 9357 | smp_rmb(); |
| 9358 | |
| 9359 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9360 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9361 | return; |
| 9362 | } |
| 9363 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9364 | page_flip_completed(intel_crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 9365 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9366 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9367 | } |
| 9368 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9369 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 9370 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9371 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9372 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 9373 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9374 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9375 | } |
| 9376 | |
| 9377 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 9378 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9379 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9380 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 9381 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9382 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9383 | } |
| 9384 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9385 | /* Is 'a' after or equal to 'b'? */ |
| 9386 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 9387 | { |
| 9388 | return !((a - b) & 0x80000000); |
| 9389 | } |
| 9390 | |
| 9391 | static bool page_flip_finished(struct intel_crtc *crtc) |
| 9392 | { |
| 9393 | struct drm_device *dev = crtc->base.dev; |
| 9394 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9395 | |
Ville Syrjälä | bdfa754 | 2014-05-27 21:33:09 +0300 | [diff] [blame] | 9396 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 9397 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 9398 | return true; |
| 9399 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9400 | /* |
| 9401 | * The relevant registers doen't exist on pre-ctg. |
| 9402 | * As the flip done interrupt doesn't trigger for mmio |
| 9403 | * flips on gmch platforms, a flip count check isn't |
| 9404 | * really needed there. But since ctg has the registers, |
| 9405 | * include it in the check anyway. |
| 9406 | */ |
| 9407 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 9408 | return true; |
| 9409 | |
| 9410 | /* |
| 9411 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 9412 | * used the same base address. In that case the mmio flip might |
| 9413 | * have completed, but the CS hasn't even executed the flip yet. |
| 9414 | * |
| 9415 | * A flip count check isn't enough as the CS might have updated |
| 9416 | * the base address just after start of vblank, but before we |
| 9417 | * managed to process the interrupt. This means we'd complete the |
| 9418 | * CS flip too soon. |
| 9419 | * |
| 9420 | * Combining both checks should get us a good enough result. It may |
| 9421 | * still happen that the CS flip has been executed, but has not |
| 9422 | * yet actually completed. But in case the base address is the same |
| 9423 | * anyway, we don't really care. |
| 9424 | */ |
| 9425 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 9426 | crtc->unpin_work->gtt_offset && |
| 9427 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), |
| 9428 | crtc->unpin_work->flip_count); |
| 9429 | } |
| 9430 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9431 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 9432 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9433 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9434 | struct intel_crtc *intel_crtc = |
| 9435 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 9436 | unsigned long flags; |
| 9437 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 9438 | |
| 9439 | /* |
| 9440 | * This is called both by irq handlers and the reset code (to complete |
| 9441 | * lost pageflips) so needs the full irqsave spinlocks. |
| 9442 | * |
| 9443 | * NB: An MMIO update of the plane base pointer will also |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9444 | * generate a page-flip completion irq, i.e. every modeset |
| 9445 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 9446 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9447 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9448 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9449 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9450 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9451 | } |
| 9452 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9453 | 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] | 9454 | { |
| 9455 | /* Ensure that the work item is consistent when activating it ... */ |
| 9456 | smp_wmb(); |
| 9457 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); |
| 9458 | /* and that it is marked active as soon as the irq could fire. */ |
| 9459 | smp_wmb(); |
| 9460 | } |
| 9461 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9462 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 9463 | struct drm_crtc *crtc, |
| 9464 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9465 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9466 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9467 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9468 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9469 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9470 | u32 flip_mask; |
| 9471 | int ret; |
| 9472 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9473 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9474 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9475 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9476 | |
| 9477 | /* Can't queue multiple flips, so wait for the previous |
| 9478 | * one to finish before executing the next. |
| 9479 | */ |
| 9480 | if (intel_crtc->plane) |
| 9481 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9482 | else |
| 9483 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9484 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9485 | intel_ring_emit(ring, MI_NOOP); |
| 9486 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9487 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9488 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9489 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9490 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9491 | |
| 9492 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9493 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9494 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9495 | } |
| 9496 | |
| 9497 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 9498 | struct drm_crtc *crtc, |
| 9499 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9500 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9501 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9502 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9503 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9504 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9505 | u32 flip_mask; |
| 9506 | int ret; |
| 9507 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9508 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9509 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9510 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9511 | |
| 9512 | if (intel_crtc->plane) |
| 9513 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9514 | else |
| 9515 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9516 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9517 | intel_ring_emit(ring, MI_NOOP); |
| 9518 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
| 9519 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9520 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9521 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9522 | intel_ring_emit(ring, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9523 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9524 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9525 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9526 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9527 | } |
| 9528 | |
| 9529 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 9530 | struct drm_crtc *crtc, |
| 9531 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9532 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9533 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9534 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9535 | { |
| 9536 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9537 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9538 | uint32_t pf, pipesrc; |
| 9539 | int ret; |
| 9540 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9541 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9542 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9543 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9544 | |
| 9545 | /* i965+ uses the linear or tiled offsets from the |
| 9546 | * Display Registers (which do not change across a page-flip) |
| 9547 | * so we need only reprogram the base address. |
| 9548 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9549 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9550 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9551 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9552 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 9553 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9554 | |
| 9555 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 9556 | * untested on non-native modes, so ignore it for now. |
| 9557 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 9558 | */ |
| 9559 | pf = 0; |
| 9560 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9561 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9562 | |
| 9563 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9564 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9565 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9566 | } |
| 9567 | |
| 9568 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 9569 | struct drm_crtc *crtc, |
| 9570 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9571 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9572 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9573 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9574 | { |
| 9575 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9576 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9577 | uint32_t pf, pipesrc; |
| 9578 | int ret; |
| 9579 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9580 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9581 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9582 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9583 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9584 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9585 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 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 | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9588 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 9589 | /* Contrary to the suggestions in the documentation, |
| 9590 | * "Enable Panel Fitter" does not seem to be required when page |
| 9591 | * flipping with a non-native mode, and worse causes a normal |
| 9592 | * modeset to fail. |
| 9593 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 9594 | */ |
| 9595 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9596 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9597 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9598 | |
| 9599 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9600 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9601 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9602 | } |
| 9603 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9604 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 9605 | struct drm_crtc *crtc, |
| 9606 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9607 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9608 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9609 | uint32_t flags) |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9610 | { |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9611 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9612 | uint32_t plane_bit = 0; |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9613 | int len, ret; |
| 9614 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9615 | switch (intel_crtc->plane) { |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9616 | case PLANE_A: |
| 9617 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 9618 | break; |
| 9619 | case PLANE_B: |
| 9620 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 9621 | break; |
| 9622 | case PLANE_C: |
| 9623 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 9624 | break; |
| 9625 | default: |
| 9626 | WARN_ONCE(1, "unknown plane in flip command\n"); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9627 | return -ENODEV; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9628 | } |
| 9629 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9630 | len = 4; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9631 | if (ring->id == RCS) { |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9632 | len += 6; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9633 | /* |
| 9634 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 9635 | * 48bits addresses, and we need a NOOP for the batch size to |
| 9636 | * stay even. |
| 9637 | */ |
| 9638 | if (IS_GEN8(dev)) |
| 9639 | len += 2; |
| 9640 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9641 | |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9642 | /* |
| 9643 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 9644 | * "The full packet must be contained within the same cache line." |
| 9645 | * |
| 9646 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 9647 | * cacheline, if we ever start emitting more commands before |
| 9648 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 9649 | * then do the cacheline alignment, and finally emit the |
| 9650 | * MI_DISPLAY_FLIP. |
| 9651 | */ |
| 9652 | ret = intel_ring_cacheline_align(ring); |
| 9653 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9654 | return ret; |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9655 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9656 | ret = intel_ring_begin(ring, len); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9657 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9658 | return ret; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9659 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9660 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 9661 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 9662 | * more than one flip event at any time (or ensure that one flip message |
| 9663 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 9664 | * Experimentation says that BCS works despite DERRMR masking all |
| 9665 | * flip-done completion events and that unmasking all planes at once |
| 9666 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 9667 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 9668 | */ |
| 9669 | if (ring->id == RCS) { |
| 9670 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
| 9671 | intel_ring_emit(ring, DERRMR); |
| 9672 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 9673 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 9674 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9675 | if (IS_GEN8(dev)) |
| 9676 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) | |
| 9677 | MI_SRM_LRM_GLOBAL_GTT); |
| 9678 | else |
| 9679 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | |
| 9680 | MI_SRM_LRM_GLOBAL_GTT); |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9681 | intel_ring_emit(ring, DERRMR); |
| 9682 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9683 | if (IS_GEN8(dev)) { |
| 9684 | intel_ring_emit(ring, 0); |
| 9685 | intel_ring_emit(ring, MI_NOOP); |
| 9686 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9687 | } |
| 9688 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9689 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 9690 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9691 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9692 | intel_ring_emit(ring, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9693 | |
| 9694 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9695 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9696 | return 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9697 | } |
| 9698 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9699 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
| 9700 | struct drm_i915_gem_object *obj) |
| 9701 | { |
| 9702 | /* |
| 9703 | * This is not being used for older platforms, because |
| 9704 | * non-availability of flip done interrupt forces us to use |
| 9705 | * CS flips. Older platforms derive flip done using some clever |
| 9706 | * tricks involving the flip_pending status bits and vblank irqs. |
| 9707 | * So using MMIO flips there would disrupt this mechanism. |
| 9708 | */ |
| 9709 | |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 9710 | if (ring == NULL) |
| 9711 | return true; |
| 9712 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9713 | if (INTEL_INFO(ring->dev)->gen < 5) |
| 9714 | return false; |
| 9715 | |
| 9716 | if (i915.use_mmio_flip < 0) |
| 9717 | return false; |
| 9718 | else if (i915.use_mmio_flip > 0) |
| 9719 | return true; |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 9720 | else if (i915.enable_execlists) |
| 9721 | return true; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9722 | else |
John Harrison | 41c5241 | 2014-11-24 18:49:43 +0000 | [diff] [blame] | 9723 | return ring != i915_gem_request_get_ring(obj->last_read_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9724 | } |
| 9725 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 9726 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 9727 | { |
| 9728 | struct drm_device *dev = intel_crtc->base.dev; |
| 9729 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9730 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
| 9731 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 9732 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 9733 | const enum pipe pipe = intel_crtc->pipe; |
| 9734 | u32 ctl, stride; |
| 9735 | |
| 9736 | ctl = I915_READ(PLANE_CTL(pipe, 0)); |
| 9737 | ctl &= ~PLANE_CTL_TILED_MASK; |
| 9738 | if (obj->tiling_mode == I915_TILING_X) |
| 9739 | ctl |= PLANE_CTL_TILED_X; |
| 9740 | |
| 9741 | /* |
| 9742 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 9743 | * linear buffers or in number of tiles for tiled buffers. |
| 9744 | */ |
| 9745 | stride = fb->pitches[0] >> 6; |
| 9746 | if (obj->tiling_mode == I915_TILING_X) |
| 9747 | stride = fb->pitches[0] >> 9; /* X tiles are 512 bytes wide */ |
| 9748 | |
| 9749 | /* |
| 9750 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on |
| 9751 | * PLANE_SURF updates, the update is then guaranteed to be atomic. |
| 9752 | */ |
| 9753 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); |
| 9754 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
| 9755 | |
| 9756 | I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset); |
| 9757 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 9758 | } |
| 9759 | |
| 9760 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9761 | { |
| 9762 | struct drm_device *dev = intel_crtc->base.dev; |
| 9763 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9764 | struct intel_framebuffer *intel_fb = |
| 9765 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 9766 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 9767 | u32 dspcntr; |
| 9768 | u32 reg; |
| 9769 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9770 | reg = DSPCNTR(intel_crtc->plane); |
| 9771 | dspcntr = I915_READ(reg); |
| 9772 | |
Damien Lespiau | c5d9747 | 2014-10-25 00:11:11 +0100 | [diff] [blame] | 9773 | if (obj->tiling_mode != I915_TILING_NONE) |
| 9774 | dspcntr |= DISPPLANE_TILED; |
| 9775 | else |
| 9776 | dspcntr &= ~DISPPLANE_TILED; |
| 9777 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9778 | I915_WRITE(reg, dspcntr); |
| 9779 | |
| 9780 | I915_WRITE(DSPSURF(intel_crtc->plane), |
| 9781 | intel_crtc->unpin_work->gtt_offset); |
| 9782 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 9783 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 9784 | } |
| 9785 | |
| 9786 | /* |
| 9787 | * XXX: This is the temporary way to update the plane registers until we get |
| 9788 | * around to using the usual plane update functions for MMIO flips |
| 9789 | */ |
| 9790 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 9791 | { |
| 9792 | struct drm_device *dev = intel_crtc->base.dev; |
| 9793 | bool atomic_update; |
| 9794 | u32 start_vbl_count; |
| 9795 | |
| 9796 | intel_mark_page_flip_active(intel_crtc); |
| 9797 | |
| 9798 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 9799 | |
| 9800 | if (INTEL_INFO(dev)->gen >= 9) |
| 9801 | skl_do_mmio_flip(intel_crtc); |
| 9802 | else |
| 9803 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ |
| 9804 | ilk_do_mmio_flip(intel_crtc); |
| 9805 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 9806 | if (atomic_update) |
| 9807 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9808 | } |
| 9809 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 9810 | static void intel_mmio_flip_work_func(struct work_struct *work) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9811 | { |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9812 | struct intel_crtc *crtc = |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 9813 | container_of(work, struct intel_crtc, mmio_flip.work); |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9814 | struct intel_mmio_flip *mmio_flip; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9815 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9816 | mmio_flip = &crtc->mmio_flip; |
| 9817 | if (mmio_flip->req) |
John Harrison | 9c65481 | 2014-11-24 18:49:35 +0000 | [diff] [blame] | 9818 | WARN_ON(__i915_wait_request(mmio_flip->req, |
| 9819 | crtc->reset_counter, |
| 9820 | false, NULL, NULL) != 0); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9821 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9822 | intel_do_mmio_flip(crtc); |
| 9823 | if (mmio_flip->req) { |
| 9824 | mutex_lock(&crtc->base.dev->struct_mutex); |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 9825 | i915_gem_request_assign(&mmio_flip->req, NULL); |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9826 | mutex_unlock(&crtc->base.dev->struct_mutex); |
| 9827 | } |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9828 | } |
| 9829 | |
| 9830 | static int intel_queue_mmio_flip(struct drm_device *dev, |
| 9831 | struct drm_crtc *crtc, |
| 9832 | struct drm_framebuffer *fb, |
| 9833 | struct drm_i915_gem_object *obj, |
| 9834 | struct intel_engine_cs *ring, |
| 9835 | uint32_t flags) |
| 9836 | { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9837 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9838 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9839 | i915_gem_request_assign(&intel_crtc->mmio_flip.req, |
| 9840 | obj->last_write_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9841 | |
Ander Conselvan de Oliveira | 536f5b5 | 2014-11-06 11:03:40 +0200 | [diff] [blame] | 9842 | schedule_work(&intel_crtc->mmio_flip.work); |
| 9843 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9844 | return 0; |
| 9845 | } |
| 9846 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9847 | static int intel_default_queue_flip(struct drm_device *dev, |
| 9848 | struct drm_crtc *crtc, |
| 9849 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9850 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9851 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9852 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9853 | { |
| 9854 | return -ENODEV; |
| 9855 | } |
| 9856 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9857 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
| 9858 | struct drm_crtc *crtc) |
| 9859 | { |
| 9860 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9861 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9862 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 9863 | u32 addr; |
| 9864 | |
| 9865 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) |
| 9866 | return true; |
| 9867 | |
| 9868 | if (!work->enable_stall_check) |
| 9869 | return false; |
| 9870 | |
| 9871 | if (work->flip_ready_vblank == 0) { |
Daniel Vetter | 3a8a946 | 2014-11-26 14:39:48 +0100 | [diff] [blame] | 9872 | if (work->flip_queued_req && |
| 9873 | !i915_gem_request_completed(work->flip_queued_req, true)) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9874 | return false; |
| 9875 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 9876 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9877 | } |
| 9878 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 9879 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9880 | return false; |
| 9881 | |
| 9882 | /* Potential stall - if we see that the flip has happened, |
| 9883 | * assume a missed interrupt. */ |
| 9884 | if (INTEL_INFO(dev)->gen >= 4) |
| 9885 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 9886 | else |
| 9887 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 9888 | |
| 9889 | /* There is a potential issue here with a false positive after a flip |
| 9890 | * to the same address. We could address this by checking for a |
| 9891 | * non-incrementing frame counter. |
| 9892 | */ |
| 9893 | return addr == work->gtt_offset; |
| 9894 | } |
| 9895 | |
| 9896 | void intel_check_page_flip(struct drm_device *dev, int pipe) |
| 9897 | { |
| 9898 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9899 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 9900 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 9901 | |
Dave Gordon | 6c51d46 | 2015-03-06 15:34:26 +0000 | [diff] [blame] | 9902 | WARN_ON(!in_interrupt()); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9903 | |
| 9904 | if (crtc == NULL) |
| 9905 | return; |
| 9906 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 9907 | spin_lock(&dev->event_lock); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9908 | if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) { |
| 9909 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 9910 | intel_crtc->unpin_work->flip_queued_vblank, |
| 9911 | drm_vblank_count(dev, pipe)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9912 | page_flip_completed(intel_crtc); |
| 9913 | } |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 9914 | spin_unlock(&dev->event_lock); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9915 | } |
| 9916 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9917 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 9918 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9919 | struct drm_pending_vblank_event *event, |
| 9920 | uint32_t page_flip_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9921 | { |
| 9922 | struct drm_device *dev = crtc->dev; |
| 9923 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9924 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 9925 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9926 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 9927 | struct drm_plane *primary = crtc->primary; |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 9928 | enum pipe pipe = intel_crtc->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9929 | struct intel_unpin_work *work; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9930 | struct intel_engine_cs *ring; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 9931 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9932 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 9933 | /* |
| 9934 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 9935 | * check to be safe. In the future we may enable pageflipping from |
| 9936 | * a disabled primary plane. |
| 9937 | */ |
| 9938 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 9939 | return -EBUSY; |
| 9940 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 9941 | /* Can't change pixel format via MI display flips. */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9942 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 9943 | return -EINVAL; |
| 9944 | |
| 9945 | /* |
| 9946 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 9947 | * Note that pitch changes could also affect these register. |
| 9948 | */ |
| 9949 | if (INTEL_INFO(dev)->gen > 3 && |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9950 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 9951 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 9952 | return -EINVAL; |
| 9953 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 9954 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 9955 | goto out_hang; |
| 9956 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 9957 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9958 | if (work == NULL) |
| 9959 | return -ENOMEM; |
| 9960 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9961 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9962 | work->crtc = crtc; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 9963 | work->old_fb = old_fb; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9964 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 9965 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 9966 | ret = drm_crtc_vblank_get(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 9967 | if (ret) |
| 9968 | goto free_work; |
| 9969 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9970 | /* We borrow the event spin lock for protecting unpin_work */ |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 9971 | spin_lock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9972 | if (intel_crtc->unpin_work) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9973 | /* Before declaring the flip queue wedged, check if |
| 9974 | * the hardware completed the operation behind our backs. |
| 9975 | */ |
| 9976 | if (__intel_pageflip_stall_check(dev, crtc)) { |
| 9977 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 9978 | page_flip_completed(intel_crtc); |
| 9979 | } else { |
| 9980 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 9981 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 9982 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9983 | drm_crtc_vblank_put(crtc); |
| 9984 | kfree(work); |
| 9985 | return -EBUSY; |
| 9986 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9987 | } |
| 9988 | intel_crtc->unpin_work = work; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 9989 | spin_unlock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9990 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9991 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 9992 | flush_workqueue(dev_priv->wq); |
| 9993 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 9994 | /* Reference the objects for the scheduled work. */ |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 9995 | drm_framebuffer_reference(work->old_fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9996 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9997 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9998 | crtc->primary->fb = fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 9999 | update_state_fb(crtc->primary); |
Matt Roper | 1ed1f96 | 2015-01-30 16:22:36 -0800 | [diff] [blame] | 10000 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10001 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10002 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10003 | ret = i915_mutex_lock_interruptible(dev); |
| 10004 | if (ret) |
| 10005 | goto cleanup; |
| 10006 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10007 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 10008 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10009 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10010 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10011 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10012 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10013 | if (IS_VALLEYVIEW(dev)) { |
| 10014 | ring = &dev_priv->ring[BCS]; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10015 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 10016 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
| 10017 | ring = NULL; |
Chris Wilson | 48bf5b2 | 2014-12-27 09:48:28 +0000 | [diff] [blame] | 10018 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
Chris Wilson | 2a92d5b | 2014-07-08 10:40:29 +0100 | [diff] [blame] | 10019 | ring = &dev_priv->ring[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10020 | } else if (INTEL_INFO(dev)->gen >= 7) { |
John Harrison | 41c5241 | 2014-11-24 18:49:43 +0000 | [diff] [blame] | 10021 | ring = i915_gem_request_get_ring(obj->last_read_req); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10022 | if (ring == NULL || ring->id != RCS) |
| 10023 | ring = &dev_priv->ring[BCS]; |
| 10024 | } else { |
| 10025 | ring = &dev_priv->ring[RCS]; |
| 10026 | } |
| 10027 | |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 10028 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10029 | if (ret) |
| 10030 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10031 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10032 | work->gtt_offset = |
| 10033 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset; |
| 10034 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10035 | if (use_mmio_flip(ring, obj)) { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10036 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
| 10037 | page_flip_flags); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10038 | if (ret) |
| 10039 | goto cleanup_unpin; |
| 10040 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10041 | i915_gem_request_assign(&work->flip_queued_req, |
| 10042 | obj->last_write_req); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10043 | } else { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10044 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring, |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10045 | page_flip_flags); |
| 10046 | if (ret) |
| 10047 | goto cleanup_unpin; |
| 10048 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10049 | i915_gem_request_assign(&work->flip_queued_req, |
| 10050 | intel_ring_get_request(ring)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10051 | } |
| 10052 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 10053 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10054 | work->enable_stall_check = true; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10055 | |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10056 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10057 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 10058 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 10059 | intel_fbc_disable(dev); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10060 | intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10061 | mutex_unlock(&dev->struct_mutex); |
| 10062 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 10063 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 10064 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10065 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10066 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10067 | cleanup_unpin: |
| 10068 | intel_unpin_fb_obj(obj); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10069 | cleanup_pending: |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10070 | atomic_dec(&intel_crtc->unpin_work_count); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10071 | mutex_unlock(&dev->struct_mutex); |
| 10072 | cleanup: |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10073 | crtc->primary->fb = old_fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 10074 | update_state_fb(crtc->primary); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10075 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10076 | drm_gem_object_unreference_unlocked(&obj->base); |
| 10077 | drm_framebuffer_unreference(work->old_fb); |
| 10078 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10079 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10080 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10081 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10082 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 10083 | drm_crtc_vblank_put(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 10084 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10085 | kfree(work); |
| 10086 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10087 | if (ret == -EIO) { |
| 10088 | out_hang: |
Matt Roper | 53a366b | 2014-12-23 10:41:53 -0800 | [diff] [blame] | 10089 | ret = intel_plane_restore(primary); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 10090 | if (ret == 0 && event) { |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10091 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10092 | drm_send_vblank_event(dev, pipe, event); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10093 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 10094 | } |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10095 | } |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10096 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10097 | } |
| 10098 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10099 | static struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10100 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 10101 | .load_lut = intel_crtc_load_lut, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 10102 | .atomic_begin = intel_begin_crtc_commit, |
| 10103 | .atomic_flush = intel_finish_crtc_commit, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10104 | }; |
| 10105 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10106 | /** |
| 10107 | * intel_modeset_update_staged_output_state |
| 10108 | * |
| 10109 | * Updates the staged output configuration state, e.g. after we've read out the |
| 10110 | * current hw state. |
| 10111 | */ |
| 10112 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) |
| 10113 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10114 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10115 | struct intel_encoder *encoder; |
| 10116 | struct intel_connector *connector; |
| 10117 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10118 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10119 | connector->new_encoder = |
| 10120 | to_intel_encoder(connector->base.encoder); |
| 10121 | } |
| 10122 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10123 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10124 | encoder->new_crtc = |
| 10125 | to_intel_crtc(encoder->base.crtc); |
| 10126 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10127 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10128 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10129 | crtc->new_enabled = crtc->base.state->enable; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 10130 | |
| 10131 | if (crtc->new_enabled) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 10132 | crtc->new_config = crtc->config; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 10133 | else |
| 10134 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10135 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10136 | } |
| 10137 | |
| 10138 | /** |
| 10139 | * intel_modeset_commit_output_state |
| 10140 | * |
| 10141 | * This function copies the stage display pipe configuration to the real one. |
| 10142 | */ |
| 10143 | static void intel_modeset_commit_output_state(struct drm_device *dev) |
| 10144 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10145 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10146 | struct intel_encoder *encoder; |
| 10147 | struct intel_connector *connector; |
| 10148 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10149 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10150 | connector->base.encoder = &connector->new_encoder->base; |
| 10151 | } |
| 10152 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10153 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10154 | encoder->base.crtc = &encoder->new_crtc->base; |
| 10155 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10156 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10157 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10158 | crtc->base.state->enable = crtc->new_enabled; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10159 | crtc->base.enabled = crtc->new_enabled; |
| 10160 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10161 | } |
| 10162 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10163 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10164 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10165 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10166 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10167 | int bpp = pipe_config->pipe_bpp; |
| 10168 | |
| 10169 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 10170 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10171 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10172 | |
| 10173 | /* Don't use an invalid EDID bpc value */ |
| 10174 | if (connector->base.display_info.bpc && |
| 10175 | connector->base.display_info.bpc * 3 < bpp) { |
| 10176 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 10177 | bpp, connector->base.display_info.bpc*3); |
| 10178 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 10179 | } |
| 10180 | |
| 10181 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
| 10182 | if (connector->base.display_info.bpc == 0 && bpp > 24) { |
| 10183 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 10184 | bpp); |
| 10185 | pipe_config->pipe_bpp = 24; |
| 10186 | } |
| 10187 | } |
| 10188 | |
| 10189 | static int |
| 10190 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
| 10191 | struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10192 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10193 | { |
| 10194 | struct drm_device *dev = crtc->base.dev; |
| 10195 | struct intel_connector *connector; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10196 | int bpp; |
| 10197 | |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10198 | switch (fb->pixel_format) { |
| 10199 | case DRM_FORMAT_C8: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10200 | bpp = 8*3; /* since we go through a colormap */ |
| 10201 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10202 | case DRM_FORMAT_XRGB1555: |
| 10203 | case DRM_FORMAT_ARGB1555: |
| 10204 | /* checked in intel_framebuffer_init already */ |
| 10205 | if (WARN_ON(INTEL_INFO(dev)->gen > 3)) |
| 10206 | return -EINVAL; |
| 10207 | case DRM_FORMAT_RGB565: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10208 | bpp = 6*3; /* min is 18bpp */ |
| 10209 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10210 | case DRM_FORMAT_XBGR8888: |
| 10211 | case DRM_FORMAT_ABGR8888: |
| 10212 | /* checked in intel_framebuffer_init already */ |
| 10213 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
| 10214 | return -EINVAL; |
| 10215 | case DRM_FORMAT_XRGB8888: |
| 10216 | case DRM_FORMAT_ARGB8888: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10217 | bpp = 8*3; |
| 10218 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10219 | case DRM_FORMAT_XRGB2101010: |
| 10220 | case DRM_FORMAT_ARGB2101010: |
| 10221 | case DRM_FORMAT_XBGR2101010: |
| 10222 | case DRM_FORMAT_ABGR2101010: |
| 10223 | /* checked in intel_framebuffer_init already */ |
| 10224 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10225 | return -EINVAL; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10226 | bpp = 10*3; |
| 10227 | break; |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10228 | /* TODO: gen4+ supports 16 bpc floating point, too. */ |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10229 | default: |
| 10230 | DRM_DEBUG_KMS("unsupported depth\n"); |
| 10231 | return -EINVAL; |
| 10232 | } |
| 10233 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10234 | pipe_config->pipe_bpp = bpp; |
| 10235 | |
| 10236 | /* Clamp display bpp to EDID value */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10237 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 1b829e0 | 2013-06-02 13:26:24 +0200 | [diff] [blame] | 10238 | if (!connector->new_encoder || |
| 10239 | connector->new_encoder->new_crtc != crtc) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10240 | continue; |
| 10241 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10242 | connected_sink_compute_bpp(connector, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10243 | } |
| 10244 | |
| 10245 | return bpp; |
| 10246 | } |
| 10247 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10248 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 10249 | { |
| 10250 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 10251 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 10252 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10253 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 10254 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 10255 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 10256 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 10257 | } |
| 10258 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10259 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10260 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10261 | const char *context) |
| 10262 | { |
| 10263 | DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id, |
| 10264 | context, pipe_name(crtc->pipe)); |
| 10265 | |
| 10266 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); |
| 10267 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 10268 | pipe_config->pipe_bpp, pipe_config->dither); |
| 10269 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10270 | pipe_config->has_pch_encoder, |
| 10271 | pipe_config->fdi_lanes, |
| 10272 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 10273 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 10274 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10275 | DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10276 | pipe_config->has_dp_encoder, |
| 10277 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 10278 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 10279 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10280 | |
| 10281 | DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
| 10282 | pipe_config->has_dp_encoder, |
| 10283 | pipe_config->dp_m2_n2.gmch_m, |
| 10284 | pipe_config->dp_m2_n2.gmch_n, |
| 10285 | pipe_config->dp_m2_n2.link_m, |
| 10286 | pipe_config->dp_m2_n2.link_n, |
| 10287 | pipe_config->dp_m2_n2.tu); |
| 10288 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 10289 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
| 10290 | pipe_config->has_audio, |
| 10291 | pipe_config->has_infoframe); |
| 10292 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10293 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10294 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10295 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10296 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 10297 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 10298 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10299 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 10300 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10301 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 10302 | pipe_config->gmch_pfit.control, |
| 10303 | pipe_config->gmch_pfit.pgm_ratios, |
| 10304 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10305 | 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] | 10306 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10307 | pipe_config->pch_pfit.size, |
| 10308 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10309 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 10310 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10311 | } |
| 10312 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10313 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10314 | const struct intel_encoder *b) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10315 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10316 | /* masks could be asymmetric, so check both ways */ |
| 10317 | return a == b || (a->cloneable & (1 << b->type) && |
| 10318 | b->cloneable & (1 << a->type)); |
| 10319 | } |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10320 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10321 | static bool check_single_encoder_cloning(struct intel_crtc *crtc, |
| 10322 | struct intel_encoder *encoder) |
| 10323 | { |
| 10324 | struct drm_device *dev = crtc->base.dev; |
| 10325 | struct intel_encoder *source_encoder; |
| 10326 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10327 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10328 | if (source_encoder->new_crtc != crtc) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10329 | continue; |
| 10330 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10331 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10332 | return false; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10333 | } |
| 10334 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10335 | return true; |
| 10336 | } |
| 10337 | |
| 10338 | static bool check_encoder_cloning(struct intel_crtc *crtc) |
| 10339 | { |
| 10340 | struct drm_device *dev = crtc->base.dev; |
| 10341 | struct intel_encoder *encoder; |
| 10342 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10343 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10344 | if (encoder->new_crtc != crtc) |
| 10345 | continue; |
| 10346 | |
| 10347 | if (!check_single_encoder_cloning(crtc, encoder)) |
| 10348 | return false; |
| 10349 | } |
| 10350 | |
| 10351 | return true; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10352 | } |
| 10353 | |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10354 | static bool check_digital_port_conflicts(struct drm_device *dev) |
| 10355 | { |
| 10356 | struct intel_connector *connector; |
| 10357 | unsigned int used_ports = 0; |
| 10358 | |
| 10359 | /* |
| 10360 | * Walk the connector list instead of the encoder |
| 10361 | * list to detect the problem on ddi platforms |
| 10362 | * where there's just one encoder per digital port. |
| 10363 | */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10364 | for_each_intel_connector(dev, connector) { |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10365 | struct intel_encoder *encoder = connector->new_encoder; |
| 10366 | |
| 10367 | if (!encoder) |
| 10368 | continue; |
| 10369 | |
| 10370 | WARN_ON(!encoder->new_crtc); |
| 10371 | |
| 10372 | switch (encoder->type) { |
| 10373 | unsigned int port_mask; |
| 10374 | case INTEL_OUTPUT_UNKNOWN: |
| 10375 | if (WARN_ON(!HAS_DDI(dev))) |
| 10376 | break; |
| 10377 | case INTEL_OUTPUT_DISPLAYPORT: |
| 10378 | case INTEL_OUTPUT_HDMI: |
| 10379 | case INTEL_OUTPUT_EDP: |
| 10380 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; |
| 10381 | |
| 10382 | /* the same port mustn't appear more than once */ |
| 10383 | if (used_ports & port_mask) |
| 10384 | return false; |
| 10385 | |
| 10386 | used_ports |= port_mask; |
| 10387 | default: |
| 10388 | break; |
| 10389 | } |
| 10390 | } |
| 10391 | |
| 10392 | return true; |
| 10393 | } |
| 10394 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10395 | static struct intel_crtc_state * |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10396 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10397 | struct drm_framebuffer *fb, |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10398 | struct drm_display_mode *mode) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10399 | { |
| 10400 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10401 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10402 | struct intel_crtc_state *pipe_config; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10403 | int plane_bpp, ret = -EINVAL; |
| 10404 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10405 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10406 | if (!check_encoder_cloning(to_intel_crtc(crtc))) { |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10407 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 10408 | return ERR_PTR(-EINVAL); |
| 10409 | } |
| 10410 | |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10411 | if (!check_digital_port_conflicts(dev)) { |
| 10412 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 10413 | return ERR_PTR(-EINVAL); |
| 10414 | } |
| 10415 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10416 | pipe_config = kzalloc(sizeof(*pipe_config), GFP_KERNEL); |
| 10417 | if (!pipe_config) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10418 | return ERR_PTR(-ENOMEM); |
| 10419 | |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 10420 | pipe_config->base.crtc = crtc; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10421 | drm_mode_copy(&pipe_config->base.adjusted_mode, mode); |
| 10422 | drm_mode_copy(&pipe_config->base.mode, mode); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10423 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 10424 | pipe_config->cpu_transcoder = |
| 10425 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10426 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10427 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10428 | /* |
| 10429 | * Sanitize sync polarity flags based on requested ones. If neither |
| 10430 | * positive or negative polarity is requested, treat this as meaning |
| 10431 | * negative polarity. |
| 10432 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10433 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10434 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10435 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10436 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10437 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10438 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10439 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10440 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10441 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
| 10442 | * plane pixel format and any sink constraints into account. Returns the |
| 10443 | * source plane bpp so that dithering can be selected on mismatches |
| 10444 | * after encoders and crtc also have had their say. */ |
| 10445 | plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 10446 | fb, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10447 | if (plane_bpp < 0) |
| 10448 | goto fail; |
| 10449 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10450 | /* |
| 10451 | * Determine the real pipe dimensions. Note that stereo modes can |
| 10452 | * increase the actual pipe size due to the frame doubling and |
| 10453 | * insertion of additional space for blanks between the frame. This |
| 10454 | * is stored in the crtc timings. We use the requested mode to do this |
| 10455 | * computation to clearly distinguish it from the adjusted mode, which |
| 10456 | * can be changed by the connectors in the below retry loop. |
| 10457 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10458 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 10459 | &pipe_config->pipe_src_w, |
| 10460 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10461 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10462 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10463 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10464 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10465 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10466 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10467 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10468 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 10469 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10470 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10471 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 10472 | * adjust it according to limitations or connector properties, and also |
| 10473 | * a chance to reject the mode entirely. |
| 10474 | */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10475 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10476 | |
| 10477 | if (&encoder->new_crtc->base != crtc) |
| 10478 | continue; |
Daniel Vetter | 7ae8923 | 2013-03-27 00:44:52 +0100 | [diff] [blame] | 10479 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 10480 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 10481 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10482 | goto fail; |
| 10483 | } |
| 10484 | } |
| 10485 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10486 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 10487 | * done afterwards in case the encoder adjusts the mode. */ |
| 10488 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10489 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10490 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10491 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 10492 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10493 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10494 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 10495 | goto fail; |
| 10496 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10497 | |
| 10498 | if (ret == RETRY) { |
| 10499 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 10500 | ret = -EINVAL; |
| 10501 | goto fail; |
| 10502 | } |
| 10503 | |
| 10504 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 10505 | retry = false; |
| 10506 | goto encoder_retry; |
| 10507 | } |
| 10508 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10509 | pipe_config->dither = pipe_config->pipe_bpp != plane_bpp; |
| 10510 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
| 10511 | plane_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
| 10512 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10513 | return pipe_config; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10514 | fail: |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10515 | kfree(pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10516 | return ERR_PTR(ret); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10517 | } |
| 10518 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10519 | /* Computes which crtcs are affected and sets the relevant bits in the mask. For |
| 10520 | * simplicity we use the crtc's pipe number (because it's easier to obtain). */ |
| 10521 | static void |
| 10522 | intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes, |
| 10523 | unsigned *prepare_pipes, unsigned *disable_pipes) |
| 10524 | { |
| 10525 | struct intel_crtc *intel_crtc; |
| 10526 | struct drm_device *dev = crtc->dev; |
| 10527 | struct intel_encoder *encoder; |
| 10528 | struct intel_connector *connector; |
| 10529 | struct drm_crtc *tmp_crtc; |
| 10530 | |
| 10531 | *disable_pipes = *modeset_pipes = *prepare_pipes = 0; |
| 10532 | |
| 10533 | /* Check which crtcs have changed outputs connected to them, these need |
| 10534 | * to be part of the prepare_pipes mask. We don't (yet) support global |
| 10535 | * modeset across multiple crtcs, so modeset_pipes will only have one |
| 10536 | * bit set at most. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10537 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10538 | if (connector->base.encoder == &connector->new_encoder->base) |
| 10539 | continue; |
| 10540 | |
| 10541 | if (connector->base.encoder) { |
| 10542 | tmp_crtc = connector->base.encoder->crtc; |
| 10543 | |
| 10544 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 10545 | } |
| 10546 | |
| 10547 | if (connector->new_encoder) |
| 10548 | *prepare_pipes |= |
| 10549 | 1 << connector->new_encoder->new_crtc->pipe; |
| 10550 | } |
| 10551 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10552 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10553 | if (encoder->base.crtc == &encoder->new_crtc->base) |
| 10554 | continue; |
| 10555 | |
| 10556 | if (encoder->base.crtc) { |
| 10557 | tmp_crtc = encoder->base.crtc; |
| 10558 | |
| 10559 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 10560 | } |
| 10561 | |
| 10562 | if (encoder->new_crtc) |
| 10563 | *prepare_pipes |= 1 << encoder->new_crtc->pipe; |
| 10564 | } |
| 10565 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10566 | /* Check for pipes that will be enabled/disabled ... */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10567 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10568 | if (intel_crtc->base.state->enable == intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10569 | continue; |
| 10570 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10571 | if (!intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10572 | *disable_pipes |= 1 << intel_crtc->pipe; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10573 | else |
| 10574 | *prepare_pipes |= 1 << intel_crtc->pipe; |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10575 | } |
| 10576 | |
| 10577 | |
| 10578 | /* set_mode is also used to update properties on life display pipes. */ |
| 10579 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10580 | if (intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10581 | *prepare_pipes |= 1 << intel_crtc->pipe; |
| 10582 | |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 10583 | /* |
| 10584 | * For simplicity do a full modeset on any pipe where the output routing |
| 10585 | * changed. We could be more clever, but that would require us to be |
| 10586 | * more careful with calling the relevant encoder->mode_set functions. |
| 10587 | */ |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10588 | if (*prepare_pipes) |
| 10589 | *modeset_pipes = *prepare_pipes; |
| 10590 | |
| 10591 | /* ... and mask these out. */ |
| 10592 | *modeset_pipes &= ~(*disable_pipes); |
| 10593 | *prepare_pipes &= ~(*disable_pipes); |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 10594 | |
| 10595 | /* |
| 10596 | * HACK: We don't (yet) fully support global modesets. intel_set_config |
| 10597 | * obies this rule, but the modeset restore mode of |
| 10598 | * intel_modeset_setup_hw_state does not. |
| 10599 | */ |
| 10600 | *modeset_pipes &= 1 << intel_crtc->pipe; |
| 10601 | *prepare_pipes &= 1 << intel_crtc->pipe; |
Daniel Vetter | e3641d3 | 2013-04-11 19:49:07 +0200 | [diff] [blame] | 10602 | |
| 10603 | DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n", |
| 10604 | *modeset_pipes, *prepare_pipes, *disable_pipes); |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10605 | } |
| 10606 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10607 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
| 10608 | { |
| 10609 | struct drm_encoder *encoder; |
| 10610 | struct drm_device *dev = crtc->dev; |
| 10611 | |
| 10612 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 10613 | if (encoder->crtc == crtc) |
| 10614 | return true; |
| 10615 | |
| 10616 | return false; |
| 10617 | } |
| 10618 | |
| 10619 | static void |
| 10620 | intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes) |
| 10621 | { |
Daniel Vetter | ba41c0de | 2014-11-03 15:04:55 +0100 | [diff] [blame] | 10622 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10623 | struct intel_encoder *intel_encoder; |
| 10624 | struct intel_crtc *intel_crtc; |
| 10625 | struct drm_connector *connector; |
| 10626 | |
Daniel Vetter | ba41c0de | 2014-11-03 15:04:55 +0100 | [diff] [blame] | 10627 | intel_shared_dpll_commit(dev_priv); |
| 10628 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10629 | for_each_intel_encoder(dev, intel_encoder) { |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10630 | if (!intel_encoder->base.crtc) |
| 10631 | continue; |
| 10632 | |
| 10633 | intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
| 10634 | |
| 10635 | if (prepare_pipes & (1 << intel_crtc->pipe)) |
| 10636 | intel_encoder->connectors_active = false; |
| 10637 | } |
| 10638 | |
| 10639 | intel_modeset_commit_output_state(dev); |
| 10640 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10641 | /* Double check state. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10642 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10643 | WARN_ON(intel_crtc->base.state->enable != intel_crtc_in_use(&intel_crtc->base)); |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 10644 | WARN_ON(intel_crtc->new_config && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 10645 | intel_crtc->new_config != intel_crtc->config); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10646 | WARN_ON(intel_crtc->base.state->enable != !!intel_crtc->new_config); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10647 | } |
| 10648 | |
| 10649 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 10650 | if (!connector->encoder || !connector->encoder->crtc) |
| 10651 | continue; |
| 10652 | |
| 10653 | intel_crtc = to_intel_crtc(connector->encoder->crtc); |
| 10654 | |
| 10655 | if (prepare_pipes & (1 << intel_crtc->pipe)) { |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 10656 | struct drm_property *dpms_property = |
| 10657 | dev->mode_config.dpms_property; |
| 10658 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10659 | connector->dpms = DRM_MODE_DPMS_ON; |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 10660 | drm_object_property_set_value(&connector->base, |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 10661 | dpms_property, |
| 10662 | DRM_MODE_DPMS_ON); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10663 | |
| 10664 | intel_encoder = to_intel_encoder(connector->encoder); |
| 10665 | intel_encoder->connectors_active = true; |
| 10666 | } |
| 10667 | } |
| 10668 | |
| 10669 | } |
| 10670 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 10671 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10672 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 10673 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10674 | |
| 10675 | if (clock1 == clock2) |
| 10676 | return true; |
| 10677 | |
| 10678 | if (!clock1 || !clock2) |
| 10679 | return false; |
| 10680 | |
| 10681 | diff = abs(clock1 - clock2); |
| 10682 | |
| 10683 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 10684 | return true; |
| 10685 | |
| 10686 | return false; |
| 10687 | } |
| 10688 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10689 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 10690 | list_for_each_entry((intel_crtc), \ |
| 10691 | &(dev)->mode_config.crtc_list, \ |
| 10692 | base.head) \ |
Daniel Vetter | 0973f18 | 2013-04-19 11:25:33 +0200 | [diff] [blame] | 10693 | if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10694 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10695 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 10696 | intel_pipe_config_compare(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10697 | struct intel_crtc_state *current_config, |
| 10698 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10699 | { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10700 | #define PIPE_CONF_CHECK_X(name) \ |
| 10701 | if (current_config->name != pipe_config->name) { \ |
| 10702 | DRM_ERROR("mismatch in " #name " " \ |
| 10703 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 10704 | current_config->name, \ |
| 10705 | pipe_config->name); \ |
| 10706 | return false; \ |
| 10707 | } |
| 10708 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10709 | #define PIPE_CONF_CHECK_I(name) \ |
| 10710 | if (current_config->name != pipe_config->name) { \ |
| 10711 | DRM_ERROR("mismatch in " #name " " \ |
| 10712 | "(expected %i, found %i)\n", \ |
| 10713 | current_config->name, \ |
| 10714 | pipe_config->name); \ |
| 10715 | return false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 10716 | } |
| 10717 | |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10718 | /* This is required for BDW+ where there is only one set of registers for |
| 10719 | * switching between high and low RR. |
| 10720 | * This macro can be used whenever a comparison has to be made between one |
| 10721 | * hw state and multiple sw state variables. |
| 10722 | */ |
| 10723 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ |
| 10724 | if ((current_config->name != pipe_config->name) && \ |
| 10725 | (current_config->alt_name != pipe_config->name)) { \ |
| 10726 | DRM_ERROR("mismatch in " #name " " \ |
| 10727 | "(expected %i or %i, found %i)\n", \ |
| 10728 | current_config->name, \ |
| 10729 | current_config->alt_name, \ |
| 10730 | pipe_config->name); \ |
| 10731 | return false; \ |
| 10732 | } |
| 10733 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10734 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 10735 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Jesse Barnes | 6f02488 | 2013-07-01 10:19:09 -0700 | [diff] [blame] | 10736 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10737 | "(expected %i, found %i)\n", \ |
| 10738 | current_config->name & (mask), \ |
| 10739 | pipe_config->name & (mask)); \ |
| 10740 | return false; \ |
| 10741 | } |
| 10742 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10743 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 10744 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
| 10745 | DRM_ERROR("mismatch in " #name " " \ |
| 10746 | "(expected %i, found %i)\n", \ |
| 10747 | current_config->name, \ |
| 10748 | pipe_config->name); \ |
| 10749 | return false; \ |
| 10750 | } |
| 10751 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10752 | #define PIPE_CONF_QUIRK(quirk) \ |
| 10753 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 10754 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 10755 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 10756 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10757 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 10758 | PIPE_CONF_CHECK_I(fdi_lanes); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 10759 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
| 10760 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); |
| 10761 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); |
| 10762 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); |
| 10763 | PIPE_CONF_CHECK_I(fdi_m_n.tu); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10764 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10765 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10766 | |
| 10767 | if (INTEL_INFO(dev)->gen < 8) { |
| 10768 | PIPE_CONF_CHECK_I(dp_m_n.gmch_m); |
| 10769 | PIPE_CONF_CHECK_I(dp_m_n.gmch_n); |
| 10770 | PIPE_CONF_CHECK_I(dp_m_n.link_m); |
| 10771 | PIPE_CONF_CHECK_I(dp_m_n.link_n); |
| 10772 | PIPE_CONF_CHECK_I(dp_m_n.tu); |
| 10773 | |
| 10774 | if (current_config->has_drrs) { |
| 10775 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m); |
| 10776 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n); |
| 10777 | PIPE_CONF_CHECK_I(dp_m2_n2.link_m); |
| 10778 | PIPE_CONF_CHECK_I(dp_m2_n2.link_n); |
| 10779 | PIPE_CONF_CHECK_I(dp_m2_n2.tu); |
| 10780 | } |
| 10781 | } else { |
| 10782 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m); |
| 10783 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n); |
| 10784 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m); |
| 10785 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n); |
| 10786 | PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu); |
| 10787 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10788 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10789 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 10790 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 10791 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 10792 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 10793 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 10794 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10795 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10796 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 10797 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 10798 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 10799 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 10800 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 10801 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10802 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 10803 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b5 | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 10804 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 10805 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
| 10806 | IS_VALLEYVIEW(dev)) |
| 10807 | PIPE_CONF_CHECK_I(limited_color_range); |
Jesse Barnes | e43823e | 2014-11-05 14:26:08 -0800 | [diff] [blame] | 10808 | PIPE_CONF_CHECK_I(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 10809 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 10810 | PIPE_CONF_CHECK_I(has_audio); |
| 10811 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10812 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10813 | DRM_MODE_FLAG_INTERLACE); |
| 10814 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10815 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10816 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10817 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10818 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10819 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10820 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10821 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10822 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10823 | DRM_MODE_FLAG_NVSYNC); |
| 10824 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 10825 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10826 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 10827 | PIPE_CONF_CHECK_I(pipe_src_h); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10828 | |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 10829 | /* |
| 10830 | * FIXME: BIOS likes to set up a cloned config with lvds+external |
| 10831 | * screen. Since we don't yet re-compute the pipe config when moving |
| 10832 | * just the lvds port away to another pipe the sw tracking won't match. |
| 10833 | * |
| 10834 | * Proper atomic modesets with recomputed global state will fix this. |
| 10835 | * Until then just don't check gmch state for inherited modes. |
| 10836 | */ |
| 10837 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) { |
| 10838 | PIPE_CONF_CHECK_I(gmch_pfit.control); |
| 10839 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 10840 | if (INTEL_INFO(dev)->gen < 4) |
| 10841 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
| 10842 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); |
| 10843 | } |
| 10844 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10845 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 10846 | if (current_config->pch_pfit.enabled) { |
| 10847 | PIPE_CONF_CHECK_I(pch_pfit.pos); |
| 10848 | PIPE_CONF_CHECK_I(pch_pfit.size); |
| 10849 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 10850 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 10851 | /* BDW+ don't expose a synchronous way to read the state */ |
| 10852 | if (IS_HASWELL(dev)) |
| 10853 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10854 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 10855 | PIPE_CONF_CHECK_I(double_wide); |
| 10856 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 10857 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 10858 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10859 | PIPE_CONF_CHECK_I(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10860 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 10861 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10862 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 10863 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 10864 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 10865 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 10866 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 10867 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10868 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 10869 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 10870 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 10871 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10872 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 10873 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10874 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10875 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10876 | #undef PIPE_CONF_CHECK_I |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10877 | #undef PIPE_CONF_CHECK_I_ALT |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10878 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10879 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10880 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 10881 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10882 | return true; |
| 10883 | } |
| 10884 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 10885 | static void check_wm_state(struct drm_device *dev) |
| 10886 | { |
| 10887 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10888 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
| 10889 | struct intel_crtc *intel_crtc; |
| 10890 | int plane; |
| 10891 | |
| 10892 | if (INTEL_INFO(dev)->gen < 9) |
| 10893 | return; |
| 10894 | |
| 10895 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 10896 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 10897 | |
| 10898 | for_each_intel_crtc(dev, intel_crtc) { |
| 10899 | struct skl_ddb_entry *hw_entry, *sw_entry; |
| 10900 | const enum pipe pipe = intel_crtc->pipe; |
| 10901 | |
| 10902 | if (!intel_crtc->active) |
| 10903 | continue; |
| 10904 | |
| 10905 | /* planes */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 10906 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 10907 | hw_entry = &hw_ddb.plane[pipe][plane]; |
| 10908 | sw_entry = &sw_ddb->plane[pipe][plane]; |
| 10909 | |
| 10910 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 10911 | continue; |
| 10912 | |
| 10913 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " |
| 10914 | "(expected (%u,%u), found (%u,%u))\n", |
| 10915 | pipe_name(pipe), plane + 1, |
| 10916 | sw_entry->start, sw_entry->end, |
| 10917 | hw_entry->start, hw_entry->end); |
| 10918 | } |
| 10919 | |
| 10920 | /* cursor */ |
| 10921 | hw_entry = &hw_ddb.cursor[pipe]; |
| 10922 | sw_entry = &sw_ddb->cursor[pipe]; |
| 10923 | |
| 10924 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 10925 | continue; |
| 10926 | |
| 10927 | DRM_ERROR("mismatch in DDB state pipe %c cursor " |
| 10928 | "(expected (%u,%u), found (%u,%u))\n", |
| 10929 | pipe_name(pipe), |
| 10930 | sw_entry->start, sw_entry->end, |
| 10931 | hw_entry->start, hw_entry->end); |
| 10932 | } |
| 10933 | } |
| 10934 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10935 | static void |
| 10936 | check_connector_state(struct drm_device *dev) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10937 | { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10938 | struct intel_connector *connector; |
| 10939 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10940 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10941 | /* This also checks the encoder/connector hw state with the |
| 10942 | * ->get_hw_state callbacks. */ |
| 10943 | intel_connector_check_state(connector); |
| 10944 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10945 | I915_STATE_WARN(&connector->new_encoder->base != connector->base.encoder, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10946 | "connector's staged encoder doesn't match current encoder\n"); |
| 10947 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 10948 | } |
| 10949 | |
| 10950 | static void |
| 10951 | check_encoder_state(struct drm_device *dev) |
| 10952 | { |
| 10953 | struct intel_encoder *encoder; |
| 10954 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10955 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10956 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10957 | bool enabled = false; |
| 10958 | bool active = false; |
| 10959 | enum pipe pipe, tracked_pipe; |
| 10960 | |
| 10961 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 10962 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 10963 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10964 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10965 | I915_STATE_WARN(&encoder->new_crtc->base != encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10966 | "encoder's stage crtc doesn't match current crtc\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10967 | I915_STATE_WARN(encoder->connectors_active && !encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10968 | "encoder's active_connectors set, but no crtc\n"); |
| 10969 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10970 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10971 | if (connector->base.encoder != &encoder->base) |
| 10972 | continue; |
| 10973 | enabled = true; |
| 10974 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) |
| 10975 | active = true; |
| 10976 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 10977 | /* |
| 10978 | * for MST connectors if we unplug the connector is gone |
| 10979 | * away but the encoder is still connected to a crtc |
| 10980 | * until a modeset happens in response to the hotplug. |
| 10981 | */ |
| 10982 | if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST) |
| 10983 | continue; |
| 10984 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10985 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10986 | "encoder's enabled state mismatch " |
| 10987 | "(expected %i, found %i)\n", |
| 10988 | !!encoder->base.crtc, enabled); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10989 | I915_STATE_WARN(active && !encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10990 | "active encoder with no crtc\n"); |
| 10991 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10992 | I915_STATE_WARN(encoder->connectors_active != active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10993 | "encoder's computed active state doesn't match tracked active state " |
| 10994 | "(expected %i, found %i)\n", active, encoder->connectors_active); |
| 10995 | |
| 10996 | active = encoder->get_hw_state(encoder, &pipe); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 10997 | I915_STATE_WARN(active != encoder->connectors_active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 10998 | "encoder's hw state doesn't match sw tracking " |
| 10999 | "(expected %i, found %i)\n", |
| 11000 | encoder->connectors_active, active); |
| 11001 | |
| 11002 | if (!encoder->base.crtc) |
| 11003 | continue; |
| 11004 | |
| 11005 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11006 | I915_STATE_WARN(active && pipe != tracked_pipe, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11007 | "active encoder's pipe doesn't match" |
| 11008 | "(expected %i, found %i)\n", |
| 11009 | tracked_pipe, pipe); |
| 11010 | |
| 11011 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11012 | } |
| 11013 | |
| 11014 | static void |
| 11015 | check_crtc_state(struct drm_device *dev) |
| 11016 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11017 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11018 | struct intel_crtc *crtc; |
| 11019 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11020 | struct intel_crtc_state pipe_config; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11021 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11022 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11023 | bool enabled = false; |
| 11024 | bool active = false; |
| 11025 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11026 | memset(&pipe_config, 0, sizeof(pipe_config)); |
| 11027 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11028 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 11029 | crtc->base.base.id); |
| 11030 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11031 | I915_STATE_WARN(crtc->active && !crtc->base.state->enable, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11032 | "active crtc, but not enabled in sw tracking\n"); |
| 11033 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11034 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11035 | if (encoder->base.crtc != &crtc->base) |
| 11036 | continue; |
| 11037 | enabled = true; |
| 11038 | if (encoder->connectors_active) |
| 11039 | active = true; |
| 11040 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11041 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11042 | I915_STATE_WARN(active != crtc->active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11043 | "crtc's computed active state doesn't match tracked active state " |
| 11044 | "(expected %i, found %i)\n", active, crtc->active); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11045 | I915_STATE_WARN(enabled != crtc->base.state->enable, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11046 | "crtc's computed enabled state doesn't match tracked enabled state " |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11047 | "(expected %i, found %i)\n", enabled, |
| 11048 | crtc->base.state->enable); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11049 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11050 | active = dev_priv->display.get_pipe_config(crtc, |
| 11051 | &pipe_config); |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 11052 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 11053 | /* hw state is inconsistent with the pipe quirk */ |
| 11054 | if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 11055 | (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 11056 | active = crtc->active; |
| 11057 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11058 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 3eaba51 | 2013-08-05 17:57:48 +0300 | [diff] [blame] | 11059 | enum pipe pipe; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11060 | if (encoder->base.crtc != &crtc->base) |
| 11061 | continue; |
Daniel Vetter | 1d37b68 | 2013-11-18 09:00:59 +0100 | [diff] [blame] | 11062 | if (encoder->get_hw_state(encoder, &pipe)) |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11063 | encoder->get_config(encoder, &pipe_config); |
| 11064 | } |
| 11065 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11066 | I915_STATE_WARN(crtc->active != active, |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11067 | "crtc active state doesn't match with hw state " |
| 11068 | "(expected %i, found %i)\n", crtc->active, active); |
| 11069 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11070 | if (active && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11071 | !intel_pipe_config_compare(dev, crtc->config, &pipe_config)) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11072 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11073 | intel_dump_pipe_config(crtc, &pipe_config, |
| 11074 | "[hw state]"); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11075 | intel_dump_pipe_config(crtc, crtc->config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11076 | "[sw state]"); |
| 11077 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11078 | } |
| 11079 | } |
| 11080 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11081 | static void |
| 11082 | check_shared_dpll_state(struct drm_device *dev) |
| 11083 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11084 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11085 | struct intel_crtc *crtc; |
| 11086 | struct intel_dpll_hw_state dpll_hw_state; |
| 11087 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11088 | |
| 11089 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 11090 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 11091 | int enabled_crtcs = 0, active_crtcs = 0; |
| 11092 | bool active; |
| 11093 | |
| 11094 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 11095 | |
| 11096 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 11097 | |
| 11098 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 11099 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11100 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11101 | "more active pll users than references: %i vs %i\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 11102 | pll->active, hweight32(pll->config.crtc_mask)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11103 | I915_STATE_WARN(pll->active && !pll->on, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11104 | "pll in active use but not on in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11105 | I915_STATE_WARN(pll->on && !pll->active, |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 11106 | "pll in on but not on in use in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11107 | I915_STATE_WARN(pll->on != active, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11108 | "pll on state mismatch (expected %i, found %i)\n", |
| 11109 | pll->on, active); |
| 11110 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11111 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11112 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11113 | enabled_crtcs++; |
| 11114 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 11115 | active_crtcs++; |
| 11116 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11117 | I915_STATE_WARN(pll->active != active_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11118 | "pll active crtcs mismatch (expected %i, found %i)\n", |
| 11119 | pll->active, active_crtcs); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11120 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11121 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 11122 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11123 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11124 | I915_STATE_WARN(pll->on && memcmp(&pll->config.hw_state, &dpll_hw_state, |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11125 | sizeof(dpll_hw_state)), |
| 11126 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11127 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11128 | } |
| 11129 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11130 | void |
| 11131 | intel_modeset_check_state(struct drm_device *dev) |
| 11132 | { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11133 | check_wm_state(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11134 | check_connector_state(dev); |
| 11135 | check_encoder_state(dev); |
| 11136 | check_crtc_state(dev); |
| 11137 | check_shared_dpll_state(dev); |
| 11138 | } |
| 11139 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11140 | void ironlake_check_encoder_dotclock(const struct intel_crtc_state *pipe_config, |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11141 | int dotclock) |
| 11142 | { |
| 11143 | /* |
| 11144 | * FDI already provided one idea for the dotclock. |
| 11145 | * Yell if the encoder disagrees. |
| 11146 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11147 | WARN(!intel_fuzzy_clock_check(pipe_config->base.adjusted_mode.crtc_clock, dotclock), |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11148 | "FDI dotclock and encoder dotclock mismatch, fdi: %i, encoder: %i\n", |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11149 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11150 | } |
| 11151 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11152 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 11153 | { |
| 11154 | struct drm_device *dev = crtc->base.dev; |
| 11155 | |
| 11156 | /* |
| 11157 | * The scanline counter increments at the leading edge of hsync. |
| 11158 | * |
| 11159 | * On most platforms it starts counting from vtotal-1 on the |
| 11160 | * first active line. That means the scanline counter value is |
| 11161 | * always one less than what we would expect. Ie. just after |
| 11162 | * start of vblank, which also occurs at start of hsync (on the |
| 11163 | * last active line), the scanline counter will read vblank_start-1. |
| 11164 | * |
| 11165 | * On gen2 the scanline counter starts counting from 1 instead |
| 11166 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 11167 | * to keep the value positive), instead of adding one. |
| 11168 | * |
| 11169 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 11170 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 11171 | * there's an extra 1 line difference. So we need to add two instead of |
| 11172 | * one to the value. |
| 11173 | */ |
| 11174 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11175 | const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11176 | int vtotal; |
| 11177 | |
| 11178 | vtotal = mode->crtc_vtotal; |
| 11179 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 11180 | vtotal /= 2; |
| 11181 | |
| 11182 | crtc->scanline_offset = vtotal - 1; |
| 11183 | } else if (HAS_DDI(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 11184 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11185 | crtc->scanline_offset = 2; |
| 11186 | } else |
| 11187 | crtc->scanline_offset = 1; |
| 11188 | } |
| 11189 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11190 | static struct intel_crtc_state * |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11191 | intel_modeset_compute_config(struct drm_crtc *crtc, |
| 11192 | struct drm_display_mode *mode, |
| 11193 | struct drm_framebuffer *fb, |
| 11194 | unsigned *modeset_pipes, |
| 11195 | unsigned *prepare_pipes, |
| 11196 | unsigned *disable_pipes) |
| 11197 | { |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11198 | struct intel_crtc_state *pipe_config = NULL; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11199 | |
| 11200 | intel_modeset_affected_pipes(crtc, modeset_pipes, |
| 11201 | prepare_pipes, disable_pipes); |
| 11202 | |
| 11203 | if ((*modeset_pipes) == 0) |
| 11204 | goto out; |
| 11205 | |
| 11206 | /* |
| 11207 | * Note this needs changes when we start tracking multiple modes |
| 11208 | * and crtcs. At that point we'll need to compute the whole config |
| 11209 | * (i.e. one pipe_config for each crtc) rather than just the one |
| 11210 | * for this crtc. |
| 11211 | */ |
| 11212 | pipe_config = intel_modeset_pipe_config(crtc, fb, mode); |
| 11213 | if (IS_ERR(pipe_config)) { |
| 11214 | goto out; |
| 11215 | } |
| 11216 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 11217 | "[modeset]"); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11218 | |
| 11219 | out: |
| 11220 | return pipe_config; |
| 11221 | } |
| 11222 | |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11223 | static int __intel_set_mode_setup_plls(struct drm_device *dev, |
| 11224 | unsigned modeset_pipes, |
| 11225 | unsigned disable_pipes) |
| 11226 | { |
| 11227 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 11228 | unsigned clear_pipes = modeset_pipes | disable_pipes; |
| 11229 | struct intel_crtc *intel_crtc; |
| 11230 | int ret = 0; |
| 11231 | |
| 11232 | if (!dev_priv->display.crtc_compute_clock) |
| 11233 | return 0; |
| 11234 | |
| 11235 | ret = intel_shared_dpll_start_config(dev_priv, clear_pipes); |
| 11236 | if (ret) |
| 11237 | goto done; |
| 11238 | |
| 11239 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
| 11240 | struct intel_crtc_state *state = intel_crtc->new_config; |
| 11241 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 11242 | state); |
| 11243 | if (ret) { |
| 11244 | intel_shared_dpll_abort_config(dev_priv); |
| 11245 | goto done; |
| 11246 | } |
| 11247 | } |
| 11248 | |
| 11249 | done: |
| 11250 | return ret; |
| 11251 | } |
| 11252 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11253 | static int __intel_set_mode(struct drm_crtc *crtc, |
| 11254 | struct drm_display_mode *mode, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11255 | int x, int y, struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11256 | struct intel_crtc_state *pipe_config, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11257 | unsigned modeset_pipes, |
| 11258 | unsigned prepare_pipes, |
| 11259 | unsigned disable_pipes) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11260 | { |
| 11261 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11262 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11263 | struct drm_display_mode *saved_mode; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11264 | struct intel_crtc *intel_crtc; |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11265 | int ret = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11266 | |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11267 | saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11268 | if (!saved_mode) |
| 11269 | return -ENOMEM; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11270 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11271 | *saved_mode = crtc->mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11272 | |
Ville Syrjälä | b9950a1 | 2014-11-21 21:00:36 +0200 | [diff] [blame] | 11273 | if (modeset_pipes) |
| 11274 | to_intel_crtc(crtc)->new_config = pipe_config; |
| 11275 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 11276 | /* |
| 11277 | * See if the config requires any additional preparation, e.g. |
| 11278 | * to adjust global state with pipes off. We need to do this |
| 11279 | * here so we can get the modeset_pipe updated config for the new |
| 11280 | * mode set on this crtc. For other crtcs we need to use the |
| 11281 | * adjusted_mode bits in the crtc directly. |
| 11282 | */ |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 11283 | if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 11284 | valleyview_modeset_global_pipes(dev, &prepare_pipes); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 11285 | |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 11286 | /* may have added more to prepare_pipes than we should */ |
| 11287 | prepare_pipes &= ~disable_pipes; |
| 11288 | } |
| 11289 | |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11290 | ret = __intel_set_mode_setup_plls(dev, modeset_pipes, disable_pipes); |
| 11291 | if (ret) |
| 11292 | goto done; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 11293 | |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 11294 | for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc) |
| 11295 | intel_crtc_disable(&intel_crtc->base); |
| 11296 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11297 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11298 | if (intel_crtc->base.state->enable) |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11299 | dev_priv->display.crtc_disable(&intel_crtc->base); |
| 11300 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11301 | |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 11302 | /* crtc->mode is already used by the ->mode_set callbacks, hence we need |
| 11303 | * to set it here already despite that we pass it down the callchain. |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11304 | * |
| 11305 | * Note we'll need to fix this up when we start tracking multiple |
| 11306 | * pipes; here we assume a single modeset_pipe and only track the |
| 11307 | * single crtc and mode. |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 11308 | */ |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11309 | if (modeset_pipes) { |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11310 | crtc->mode = *mode; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11311 | /* mode_set/enable/disable functions rely on a correct pipe |
| 11312 | * config. */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 11313 | intel_crtc_set_state(to_intel_crtc(crtc), pipe_config); |
Ville Syrjälä | c326c0a | 2013-10-28 12:53:41 +0200 | [diff] [blame] | 11314 | |
| 11315 | /* |
| 11316 | * Calculate and store various constants which |
| 11317 | * are later needed by vblank and swap-completion |
| 11318 | * timestamping. They are derived from true hwmode. |
| 11319 | */ |
| 11320 | drm_calc_timestamping_constants(crtc, |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11321 | &pipe_config->base.adjusted_mode); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11322 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11323 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11324 | /* Only after disabling all output pipelines that will be changed can we |
| 11325 | * update the the output configuration. */ |
| 11326 | intel_modeset_update_state(dev, prepare_pipes); |
| 11327 | |
Ville Syrjälä | 50f6e50 | 2014-11-06 14:49:12 +0200 | [diff] [blame] | 11328 | modeset_update_crtc_power_domains(dev); |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 11329 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11330 | /* Set up the DPLL and any encoders state that needs to adjust or depend |
| 11331 | * on the DPLL. |
| 11332 | */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11333 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11334 | struct drm_plane *primary = intel_crtc->base.primary; |
| 11335 | int vdisplay, hdisplay; |
Daniel Vetter | 4c10794 | 2014-04-24 23:55:05 +0200 | [diff] [blame] | 11336 | |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11337 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
| 11338 | ret = primary->funcs->update_plane(primary, &intel_crtc->base, |
| 11339 | fb, 0, 0, |
| 11340 | hdisplay, vdisplay, |
| 11341 | x << 16, y << 16, |
| 11342 | hdisplay << 16, vdisplay << 16); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11343 | } |
| 11344 | |
| 11345 | /* 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] | 11346 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
| 11347 | update_scanline_offset(intel_crtc); |
| 11348 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11349 | dev_priv->display.crtc_enable(&intel_crtc->base); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11350 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11351 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11352 | /* FIXME: add subpixel order */ |
| 11353 | done: |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11354 | if (ret && crtc->state->enable) |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11355 | crtc->mode = *saved_mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11356 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11357 | kfree(saved_mode); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11358 | return ret; |
| 11359 | } |
| 11360 | |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11361 | static int intel_set_mode_pipes(struct drm_crtc *crtc, |
| 11362 | struct drm_display_mode *mode, |
| 11363 | int x, int y, struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11364 | struct intel_crtc_state *pipe_config, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11365 | unsigned modeset_pipes, |
| 11366 | unsigned prepare_pipes, |
| 11367 | unsigned disable_pipes) |
| 11368 | { |
| 11369 | int ret; |
| 11370 | |
| 11371 | ret = __intel_set_mode(crtc, mode, x, y, fb, pipe_config, modeset_pipes, |
| 11372 | prepare_pipes, disable_pipes); |
| 11373 | |
| 11374 | if (ret == 0) |
| 11375 | intel_modeset_check_state(crtc->dev); |
| 11376 | |
| 11377 | return ret; |
| 11378 | } |
| 11379 | |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 11380 | static int intel_set_mode(struct drm_crtc *crtc, |
| 11381 | struct drm_display_mode *mode, |
| 11382 | int x, int y, struct drm_framebuffer *fb) |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11383 | { |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11384 | struct intel_crtc_state *pipe_config; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11385 | unsigned modeset_pipes, prepare_pipes, disable_pipes; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11386 | |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11387 | pipe_config = intel_modeset_compute_config(crtc, mode, fb, |
| 11388 | &modeset_pipes, |
| 11389 | &prepare_pipes, |
| 11390 | &disable_pipes); |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11391 | |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11392 | if (IS_ERR(pipe_config)) |
| 11393 | return PTR_ERR(pipe_config); |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11394 | |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11395 | return intel_set_mode_pipes(crtc, mode, x, y, fb, pipe_config, |
| 11396 | modeset_pipes, prepare_pipes, |
| 11397 | disable_pipes); |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11398 | } |
| 11399 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11400 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 11401 | { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11402 | 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] | 11403 | } |
| 11404 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11405 | #undef for_each_intel_crtc_masked |
| 11406 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11407 | static void intel_set_config_free(struct intel_set_config *config) |
| 11408 | { |
| 11409 | if (!config) |
| 11410 | return; |
| 11411 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11412 | kfree(config->save_connector_encoders); |
| 11413 | kfree(config->save_encoder_crtcs); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11414 | kfree(config->save_crtc_enabled); |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11415 | kfree(config); |
| 11416 | } |
| 11417 | |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11418 | static int intel_set_config_save_state(struct drm_device *dev, |
| 11419 | struct intel_set_config *config) |
| 11420 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11421 | struct drm_crtc *crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11422 | struct drm_encoder *encoder; |
| 11423 | struct drm_connector *connector; |
| 11424 | int count; |
| 11425 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11426 | config->save_crtc_enabled = |
| 11427 | kcalloc(dev->mode_config.num_crtc, |
| 11428 | sizeof(bool), GFP_KERNEL); |
| 11429 | if (!config->save_crtc_enabled) |
| 11430 | return -ENOMEM; |
| 11431 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11432 | config->save_encoder_crtcs = |
| 11433 | kcalloc(dev->mode_config.num_encoder, |
| 11434 | sizeof(struct drm_crtc *), GFP_KERNEL); |
| 11435 | if (!config->save_encoder_crtcs) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11436 | return -ENOMEM; |
| 11437 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11438 | config->save_connector_encoders = |
| 11439 | kcalloc(dev->mode_config.num_connector, |
| 11440 | sizeof(struct drm_encoder *), GFP_KERNEL); |
| 11441 | if (!config->save_connector_encoders) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11442 | return -ENOMEM; |
| 11443 | |
| 11444 | /* Copy data. Note that driver private data is not affected. |
| 11445 | * Should anything bad happen only the expected state is |
| 11446 | * restored, not the drivers personal bookkeeping. |
| 11447 | */ |
| 11448 | count = 0; |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 11449 | for_each_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11450 | config->save_crtc_enabled[count++] = crtc->state->enable; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11451 | } |
| 11452 | |
| 11453 | count = 0; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11454 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11455 | config->save_encoder_crtcs[count++] = encoder->crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11456 | } |
| 11457 | |
| 11458 | count = 0; |
| 11459 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11460 | config->save_connector_encoders[count++] = connector->encoder; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11461 | } |
| 11462 | |
| 11463 | return 0; |
| 11464 | } |
| 11465 | |
| 11466 | static void intel_set_config_restore_state(struct drm_device *dev, |
| 11467 | struct intel_set_config *config) |
| 11468 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11469 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11470 | struct intel_encoder *encoder; |
| 11471 | struct intel_connector *connector; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11472 | int count; |
| 11473 | |
| 11474 | count = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11475 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11476 | crtc->new_enabled = config->save_crtc_enabled[count++]; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11477 | |
| 11478 | if (crtc->new_enabled) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11479 | crtc->new_config = crtc->config; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11480 | else |
| 11481 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11482 | } |
| 11483 | |
| 11484 | count = 0; |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11485 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11486 | encoder->new_crtc = |
| 11487 | to_intel_crtc(config->save_encoder_crtcs[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11488 | } |
| 11489 | |
| 11490 | count = 0; |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11491 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11492 | connector->new_encoder = |
| 11493 | to_intel_encoder(config->save_connector_encoders[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11494 | } |
| 11495 | } |
| 11496 | |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11497 | static bool |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11498 | is_crtc_connector_off(struct drm_mode_set *set) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11499 | { |
| 11500 | int i; |
| 11501 | |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11502 | if (set->num_connectors == 0) |
| 11503 | return false; |
| 11504 | |
| 11505 | if (WARN_ON(set->connectors == NULL)) |
| 11506 | return false; |
| 11507 | |
| 11508 | for (i = 0; i < set->num_connectors; i++) |
| 11509 | if (set->connectors[i]->encoder && |
| 11510 | set->connectors[i]->encoder->crtc == set->crtc && |
| 11511 | set->connectors[i]->dpms != DRM_MODE_DPMS_ON) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11512 | return true; |
| 11513 | |
| 11514 | return false; |
| 11515 | } |
| 11516 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11517 | static void |
| 11518 | intel_set_config_compute_mode_changes(struct drm_mode_set *set, |
| 11519 | struct intel_set_config *config) |
| 11520 | { |
| 11521 | |
| 11522 | /* We should be able to check here if the fb has the same properties |
| 11523 | * and then just flip_or_move it */ |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11524 | if (is_crtc_connector_off(set)) { |
| 11525 | config->mode_changed = true; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11526 | } else if (set->crtc->primary->fb != set->fb) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11527 | /* |
| 11528 | * If we have no fb, we can only flip as long as the crtc is |
| 11529 | * active, otherwise we need a full mode set. The crtc may |
| 11530 | * be active if we've only disabled the primary plane, or |
| 11531 | * in fastboot situations. |
| 11532 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11533 | if (set->crtc->primary->fb == NULL) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 11534 | struct intel_crtc *intel_crtc = |
| 11535 | to_intel_crtc(set->crtc); |
| 11536 | |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11537 | if (intel_crtc->active) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 11538 | DRM_DEBUG_KMS("crtc has no fb, will flip\n"); |
| 11539 | config->fb_changed = true; |
| 11540 | } else { |
| 11541 | DRM_DEBUG_KMS("inactive crtc, full mode set\n"); |
| 11542 | config->mode_changed = true; |
| 11543 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11544 | } else if (set->fb == NULL) { |
| 11545 | config->mode_changed = true; |
Daniel Vetter | 72f4901 | 2013-03-28 16:01:35 +0100 | [diff] [blame] | 11546 | } else if (set->fb->pixel_format != |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11547 | set->crtc->primary->fb->pixel_format) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11548 | config->mode_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11549 | } else { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11550 | config->fb_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11551 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11552 | } |
| 11553 | |
Daniel Vetter | 835c587 | 2012-07-10 18:11:08 +0200 | [diff] [blame] | 11554 | 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] | 11555 | config->fb_changed = true; |
| 11556 | |
| 11557 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
| 11558 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
| 11559 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 11560 | drm_mode_debug_printmodeline(set->mode); |
| 11561 | config->mode_changed = true; |
| 11562 | } |
Chris Wilson | a1d9570 | 2013-08-13 18:48:47 +0100 | [diff] [blame] | 11563 | |
| 11564 | DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n", |
| 11565 | set->crtc->base.id, config->mode_changed, config->fb_changed); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11566 | } |
| 11567 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11568 | static int |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11569 | intel_modeset_stage_output_state(struct drm_device *dev, |
| 11570 | struct drm_mode_set *set, |
| 11571 | struct intel_set_config *config) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11572 | { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11573 | struct intel_connector *connector; |
| 11574 | struct intel_encoder *encoder; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11575 | struct intel_crtc *crtc; |
Paulo Zanoni | f3f0857 | 2013-08-12 14:56:53 -0300 | [diff] [blame] | 11576 | int ro; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11577 | |
Damien Lespiau | 9abdda7 | 2013-02-13 13:29:23 +0000 | [diff] [blame] | 11578 | /* 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] | 11579 | * of connectors. For paranoia, double-check this. */ |
| 11580 | WARN_ON(!set->fb && (set->num_connectors != 0)); |
| 11581 | WARN_ON(set->fb && (set->num_connectors == 0)); |
| 11582 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11583 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11584 | /* Otherwise traverse passed in connector list and get encoders |
| 11585 | * for them. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11586 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11587 | if (set->connectors[ro] == &connector->base) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11588 | 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] | 11589 | break; |
| 11590 | } |
| 11591 | } |
| 11592 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11593 | /* If we disable the crtc, disable all its connectors. Also, if |
| 11594 | * the connector is on the changing crtc but not on the new |
| 11595 | * connector list, disable it. */ |
| 11596 | if ((!set->fb || ro == set->num_connectors) && |
| 11597 | connector->base.encoder && |
| 11598 | connector->base.encoder->crtc == set->crtc) { |
| 11599 | connector->new_encoder = NULL; |
| 11600 | |
| 11601 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", |
| 11602 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11603 | connector->base.name); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11604 | } |
| 11605 | |
| 11606 | |
| 11607 | if (&connector->new_encoder->base != connector->base.encoder) { |
Ander Conselvan de Oliveira | 1063418 | 2015-03-03 15:21:57 +0200 | [diff] [blame] | 11608 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] encoder changed, full mode switch\n", |
| 11609 | connector->base.base.id, |
| 11610 | connector->base.name); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11611 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11612 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11613 | } |
| 11614 | /* connector->new_encoder is now updated for all connectors. */ |
| 11615 | |
| 11616 | /* Update crtc of enabled connectors. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11617 | for_each_intel_connector(dev, connector) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11618 | struct drm_crtc *new_crtc; |
| 11619 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11620 | if (!connector->new_encoder) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11621 | continue; |
| 11622 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11623 | new_crtc = connector->new_encoder->base.crtc; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11624 | |
| 11625 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11626 | if (set->connectors[ro] == &connector->base) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11627 | new_crtc = set->crtc; |
| 11628 | } |
| 11629 | |
| 11630 | /* Make sure the new CRTC will work with the encoder */ |
Thierry Reding | 1450991 | 2014-01-13 12:00:22 +0100 | [diff] [blame] | 11631 | if (!drm_encoder_crtc_ok(&connector->new_encoder->base, |
| 11632 | new_crtc)) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11633 | return -EINVAL; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11634 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11635 | connector->new_encoder->new_crtc = to_intel_crtc(new_crtc); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11636 | |
| 11637 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
| 11638 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11639 | connector->base.name, |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11640 | new_crtc->base.id); |
| 11641 | } |
| 11642 | |
| 11643 | /* Check for any encoders that needs to be disabled. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11644 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11645 | int num_connectors = 0; |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11646 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11647 | if (connector->new_encoder == encoder) { |
| 11648 | WARN_ON(!connector->new_encoder->new_crtc); |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11649 | num_connectors++; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11650 | } |
| 11651 | } |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11652 | |
| 11653 | if (num_connectors == 0) |
| 11654 | encoder->new_crtc = NULL; |
| 11655 | else if (num_connectors > 1) |
| 11656 | return -EINVAL; |
| 11657 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11658 | /* Only now check for crtc changes so we don't miss encoders |
| 11659 | * that will be disabled. */ |
| 11660 | if (&encoder->new_crtc->base != encoder->base.crtc) { |
Ander Conselvan de Oliveira | 1063418 | 2015-03-03 15:21:57 +0200 | [diff] [blame] | 11661 | DRM_DEBUG_KMS("[ENCODER:%d:%s] crtc changed, full mode switch\n", |
| 11662 | encoder->base.base.id, |
| 11663 | encoder->base.name); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11664 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11665 | } |
| 11666 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11667 | /* Now we've also updated encoder->new_crtc for all encoders. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11668 | for_each_intel_connector(dev, connector) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11669 | if (connector->new_encoder) |
| 11670 | if (connector->new_encoder != connector->encoder) |
| 11671 | connector->encoder = connector->new_encoder; |
| 11672 | } |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11673 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11674 | crtc->new_enabled = false; |
| 11675 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11676 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11677 | if (encoder->new_crtc == crtc) { |
| 11678 | crtc->new_enabled = true; |
| 11679 | break; |
| 11680 | } |
| 11681 | } |
| 11682 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11683 | if (crtc->new_enabled != crtc->base.state->enable) { |
Ander Conselvan de Oliveira | 1063418 | 2015-03-03 15:21:57 +0200 | [diff] [blame] | 11684 | DRM_DEBUG_KMS("[CRTC:%d] %sabled, full mode switch\n", |
| 11685 | crtc->base.base.id, |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11686 | crtc->new_enabled ? "en" : "dis"); |
| 11687 | config->mode_changed = true; |
| 11688 | } |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11689 | |
| 11690 | if (crtc->new_enabled) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11691 | crtc->new_config = crtc->config; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11692 | else |
| 11693 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11694 | } |
| 11695 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11696 | return 0; |
| 11697 | } |
| 11698 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11699 | static void disable_crtc_nofb(struct intel_crtc *crtc) |
| 11700 | { |
| 11701 | struct drm_device *dev = crtc->base.dev; |
| 11702 | struct intel_encoder *encoder; |
| 11703 | struct intel_connector *connector; |
| 11704 | |
| 11705 | DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n", |
| 11706 | pipe_name(crtc->pipe)); |
| 11707 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11708 | for_each_intel_connector(dev, connector) { |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11709 | if (connector->new_encoder && |
| 11710 | connector->new_encoder->new_crtc == crtc) |
| 11711 | connector->new_encoder = NULL; |
| 11712 | } |
| 11713 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11714 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11715 | if (encoder->new_crtc == crtc) |
| 11716 | encoder->new_crtc = NULL; |
| 11717 | } |
| 11718 | |
| 11719 | crtc->new_enabled = false; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11720 | crtc->new_config = NULL; |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11721 | } |
| 11722 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11723 | static int intel_crtc_set_config(struct drm_mode_set *set) |
| 11724 | { |
| 11725 | struct drm_device *dev; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11726 | struct drm_mode_set save_set; |
| 11727 | struct intel_set_config *config; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11728 | struct intel_crtc_state *pipe_config; |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 11729 | unsigned modeset_pipes, prepare_pipes, disable_pipes; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11730 | int ret; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11731 | |
Daniel Vetter | 8d3e375 | 2012-07-05 16:09:09 +0200 | [diff] [blame] | 11732 | BUG_ON(!set); |
| 11733 | BUG_ON(!set->crtc); |
| 11734 | BUG_ON(!set->crtc->helper_private); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11735 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 11736 | /* Enforce sane interface api - has been abused by the fb helper. */ |
| 11737 | BUG_ON(!set->mode && set->fb); |
| 11738 | BUG_ON(set->fb && set->num_connectors == 0); |
Daniel Vetter | 431e50f | 2012-07-10 17:53:42 +0200 | [diff] [blame] | 11739 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11740 | if (set->fb) { |
| 11741 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", |
| 11742 | set->crtc->base.id, set->fb->base.id, |
| 11743 | (int)set->num_connectors, set->x, set->y); |
| 11744 | } else { |
| 11745 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11746 | } |
| 11747 | |
| 11748 | dev = set->crtc->dev; |
| 11749 | |
| 11750 | ret = -ENOMEM; |
| 11751 | config = kzalloc(sizeof(*config), GFP_KERNEL); |
| 11752 | if (!config) |
| 11753 | goto out_config; |
| 11754 | |
| 11755 | ret = intel_set_config_save_state(dev, config); |
| 11756 | if (ret) |
| 11757 | goto out_config; |
| 11758 | |
| 11759 | save_set.crtc = set->crtc; |
| 11760 | save_set.mode = &set->crtc->mode; |
| 11761 | save_set.x = set->crtc->x; |
| 11762 | save_set.y = set->crtc->y; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11763 | save_set.fb = set->crtc->primary->fb; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11764 | |
| 11765 | /* Compute whether we need a full modeset, only an fb base update or no |
| 11766 | * change at all. In the future we might also check whether only the |
| 11767 | * mode changed, e.g. for LVDS where we only change the panel fitter in |
| 11768 | * such cases. */ |
| 11769 | intel_set_config_compute_mode_changes(set, config); |
| 11770 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11771 | ret = intel_modeset_stage_output_state(dev, set, config); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11772 | if (ret) |
| 11773 | goto fail; |
| 11774 | |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 11775 | pipe_config = intel_modeset_compute_config(set->crtc, set->mode, |
| 11776 | set->fb, |
| 11777 | &modeset_pipes, |
| 11778 | &prepare_pipes, |
| 11779 | &disable_pipes); |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 11780 | if (IS_ERR(pipe_config)) { |
Matt Roper | 6ac0483 | 2014-11-17 09:59:28 -0800 | [diff] [blame] | 11781 | ret = PTR_ERR(pipe_config); |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 11782 | goto fail; |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 11783 | } else if (pipe_config) { |
Ville Syrjälä | b9950a1 | 2014-11-21 21:00:36 +0200 | [diff] [blame] | 11784 | if (pipe_config->has_audio != |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11785 | to_intel_crtc(set->crtc)->config->has_audio) |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 11786 | config->mode_changed = true; |
| 11787 | |
Jesse Barnes | af15d2c | 2014-12-01 09:54:28 -0800 | [diff] [blame] | 11788 | /* |
| 11789 | * Note we have an issue here with infoframes: current code |
| 11790 | * only updates them on the full mode set path per hw |
| 11791 | * requirements. So here we should be checking for any |
| 11792 | * required changes and forcing a mode set. |
| 11793 | */ |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 11794 | } |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 11795 | |
| 11796 | /* set_mode will free it in the mode_changed case */ |
| 11797 | if (!config->mode_changed) |
| 11798 | kfree(pipe_config); |
| 11799 | |
Jesse Barnes | 1f9954d | 2014-11-05 14:26:10 -0800 | [diff] [blame] | 11800 | intel_update_pipe_size(to_intel_crtc(set->crtc)); |
| 11801 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11802 | if (config->mode_changed) { |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 11803 | ret = intel_set_mode_pipes(set->crtc, set->mode, |
| 11804 | set->x, set->y, set->fb, pipe_config, |
| 11805 | modeset_pipes, prepare_pipes, |
| 11806 | disable_pipes); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11807 | } else if (config->fb_changed) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11808 | struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11809 | struct drm_plane *primary = set->crtc->primary; |
| 11810 | int vdisplay, hdisplay; |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11811 | |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11812 | drm_crtc_get_hv_timing(set->mode, &hdisplay, &vdisplay); |
| 11813 | ret = primary->funcs->update_plane(primary, set->crtc, set->fb, |
| 11814 | 0, 0, hdisplay, vdisplay, |
| 11815 | set->x << 16, set->y << 16, |
| 11816 | hdisplay << 16, vdisplay << 16); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11817 | |
| 11818 | /* |
| 11819 | * We need to make sure the primary plane is re-enabled if it |
| 11820 | * has previously been turned off. |
| 11821 | */ |
| 11822 | if (!intel_crtc->primary_enabled && ret == 0) { |
| 11823 | WARN_ON(!intel_crtc->active); |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 11824 | intel_enable_primary_hw_plane(set->crtc->primary, set->crtc); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11825 | } |
| 11826 | |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 11827 | /* |
| 11828 | * In the fastboot case this may be our only check of the |
| 11829 | * state after boot. It would be better to only do it on |
| 11830 | * the first update, but we don't have a nice way of doing that |
| 11831 | * (and really, set_config isn't used much for high freq page |
| 11832 | * flipping, so increasing its cost here shouldn't be a big |
| 11833 | * deal). |
| 11834 | */ |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 11835 | if (i915.fastboot && ret == 0) |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 11836 | intel_modeset_check_state(set->crtc->dev); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11837 | } |
| 11838 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 11839 | if (ret) { |
Daniel Vetter | bf67dfe | 2013-06-25 11:06:52 +0200 | [diff] [blame] | 11840 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
| 11841 | set->crtc->base.id, ret); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11842 | fail: |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 11843 | intel_set_config_restore_state(dev, config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11844 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 11845 | /* |
| 11846 | * HACK: if the pipe was on, but we didn't have a framebuffer, |
| 11847 | * force the pipe off to avoid oopsing in the modeset code |
| 11848 | * due to fb==NULL. This should only happen during boot since |
| 11849 | * we don't yet reconstruct the FB from the hardware state. |
| 11850 | */ |
| 11851 | if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb) |
| 11852 | disable_crtc_nofb(to_intel_crtc(save_set.crtc)); |
| 11853 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 11854 | /* Try to restore the config */ |
| 11855 | if (config->mode_changed && |
| 11856 | intel_set_mode(save_set.crtc, save_set.mode, |
| 11857 | save_set.x, save_set.y, save_set.fb)) |
| 11858 | DRM_ERROR("failed to restore config after modeset failure\n"); |
| 11859 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11860 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11861 | out_config: |
| 11862 | intel_set_config_free(config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11863 | return ret; |
| 11864 | } |
| 11865 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11866 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11867 | .gamma_set = intel_crtc_gamma_set, |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11868 | .set_config = intel_crtc_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11869 | .destroy = intel_crtc_destroy, |
| 11870 | .page_flip = intel_crtc_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 11871 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 11872 | .atomic_destroy_state = intel_crtc_destroy_state, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 11873 | }; |
| 11874 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11875 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
| 11876 | struct intel_shared_dpll *pll, |
| 11877 | struct intel_dpll_hw_state *hw_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11878 | { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11879 | uint32_t val; |
| 11880 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 11881 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 11882 | return false; |
| 11883 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11884 | val = I915_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11885 | hw_state->dpll = val; |
| 11886 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); |
| 11887 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11888 | |
| 11889 | return val & DPLL_VCO_ENABLE; |
| 11890 | } |
| 11891 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11892 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
| 11893 | struct intel_shared_dpll *pll) |
| 11894 | { |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 11895 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
| 11896 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11897 | } |
| 11898 | |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11899 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
| 11900 | struct intel_shared_dpll *pll) |
| 11901 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11902 | /* PCH refclock must be enabled first */ |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 11903 | ibx_assert_pch_refclk_enabled(dev_priv); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11904 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 11905 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11906 | |
| 11907 | /* Wait for the clocks to stabilize. */ |
| 11908 | POSTING_READ(PCH_DPLL(pll->id)); |
| 11909 | udelay(150); |
| 11910 | |
| 11911 | /* The pixel multiplier can only be updated once the |
| 11912 | * DPLL is enabled and the clocks are stable. |
| 11913 | * |
| 11914 | * So write it again. |
| 11915 | */ |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 11916 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11917 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11918 | udelay(200); |
| 11919 | } |
| 11920 | |
| 11921 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, |
| 11922 | struct intel_shared_dpll *pll) |
| 11923 | { |
| 11924 | struct drm_device *dev = dev_priv->dev; |
| 11925 | struct intel_crtc *crtc; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11926 | |
| 11927 | /* Make sure no transcoder isn't still depending on us. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11928 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11929 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
| 11930 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); |
| 11931 | } |
| 11932 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11933 | I915_WRITE(PCH_DPLL(pll->id), 0); |
| 11934 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11935 | udelay(200); |
| 11936 | } |
| 11937 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 11938 | static char *ibx_pch_dpll_names[] = { |
| 11939 | "PCH DPLL A", |
| 11940 | "PCH DPLL B", |
| 11941 | }; |
| 11942 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11943 | static void ibx_pch_dpll_init(struct drm_device *dev) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11944 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11945 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11946 | int i; |
| 11947 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11948 | dev_priv->num_shared_dpll = 2; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11949 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 11950 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 11951 | dev_priv->shared_dplls[i].id = i; |
| 11952 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 11953 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11954 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
| 11955 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11956 | dev_priv->shared_dplls[i].get_hw_state = |
| 11957 | ibx_pch_dpll_get_hw_state; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 11958 | } |
| 11959 | } |
| 11960 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11961 | static void intel_shared_dpll_init(struct drm_device *dev) |
| 11962 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 11963 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11964 | |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 11965 | if (HAS_DDI(dev)) |
| 11966 | intel_ddi_pll_init(dev); |
| 11967 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11968 | ibx_pch_dpll_init(dev); |
| 11969 | else |
| 11970 | dev_priv->num_shared_dpll = 0; |
| 11971 | |
| 11972 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 11973 | } |
| 11974 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 11975 | /** |
| 11976 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 11977 | * @plane: drm plane to prepare for |
| 11978 | * @fb: framebuffer to prepare for presentation |
| 11979 | * |
| 11980 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 11981 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 11982 | * bits. Some older platforms need special physical address handling for |
| 11983 | * cursor planes. |
| 11984 | * |
| 11985 | * Returns 0 on success, negative error code on failure. |
| 11986 | */ |
| 11987 | int |
| 11988 | intel_prepare_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 11989 | struct drm_framebuffer *fb, |
| 11990 | const struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11991 | { |
| 11992 | struct drm_device *dev = plane->dev; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 11993 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 11994 | enum pipe pipe = intel_plane->pipe; |
| 11995 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 11996 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); |
| 11997 | unsigned frontbuffer_bits = 0; |
| 11998 | int ret = 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 11999 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12000 | if (!obj) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12001 | return 0; |
| 12002 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12003 | switch (plane->type) { |
| 12004 | case DRM_PLANE_TYPE_PRIMARY: |
| 12005 | frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(pipe); |
| 12006 | break; |
| 12007 | case DRM_PLANE_TYPE_CURSOR: |
| 12008 | frontbuffer_bits = INTEL_FRONTBUFFER_CURSOR(pipe); |
| 12009 | break; |
| 12010 | case DRM_PLANE_TYPE_OVERLAY: |
| 12011 | frontbuffer_bits = INTEL_FRONTBUFFER_SPRITE(pipe); |
| 12012 | break; |
| 12013 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12014 | |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 12015 | mutex_lock(&dev->struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12016 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12017 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
| 12018 | INTEL_INFO(dev)->cursor_needs_physical) { |
| 12019 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
| 12020 | ret = i915_gem_object_attach_phys(obj, align); |
| 12021 | if (ret) |
| 12022 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
| 12023 | } else { |
| 12024 | ret = intel_pin_and_fence_fb_obj(plane, fb, NULL); |
| 12025 | } |
| 12026 | |
| 12027 | if (ret == 0) |
| 12028 | i915_gem_track_fb(old_obj, obj, frontbuffer_bits); |
| 12029 | |
| 12030 | mutex_unlock(&dev->struct_mutex); |
| 12031 | |
| 12032 | return ret; |
| 12033 | } |
| 12034 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12035 | /** |
| 12036 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 12037 | * @plane: drm plane to clean up for |
| 12038 | * @fb: old framebuffer that was on plane |
| 12039 | * |
| 12040 | * Cleans up a framebuffer that has just been removed from a plane. |
| 12041 | */ |
| 12042 | void |
| 12043 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 12044 | struct drm_framebuffer *fb, |
| 12045 | const struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12046 | { |
| 12047 | struct drm_device *dev = plane->dev; |
| 12048 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 12049 | |
| 12050 | if (WARN_ON(!obj)) |
| 12051 | return; |
| 12052 | |
| 12053 | if (plane->type != DRM_PLANE_TYPE_CURSOR || |
| 12054 | !INTEL_INFO(dev)->cursor_needs_physical) { |
| 12055 | mutex_lock(&dev->struct_mutex); |
| 12056 | intel_unpin_fb_obj(obj); |
| 12057 | mutex_unlock(&dev->struct_mutex); |
| 12058 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12059 | } |
| 12060 | |
| 12061 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12062 | intel_check_primary_plane(struct drm_plane *plane, |
| 12063 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12064 | { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12065 | struct drm_device *dev = plane->dev; |
| 12066 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12067 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12068 | struct intel_crtc *intel_crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12069 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12070 | struct drm_rect *dest = &state->dst; |
| 12071 | struct drm_rect *src = &state->src; |
| 12072 | const struct drm_rect *clip = &state->clip; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12073 | int ret; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12074 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12075 | crtc = crtc ? crtc : plane->crtc; |
| 12076 | intel_crtc = to_intel_crtc(crtc); |
| 12077 | |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12078 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
| 12079 | src, dest, clip, |
| 12080 | DRM_PLANE_HELPER_NO_SCALING, |
| 12081 | DRM_PLANE_HELPER_NO_SCALING, |
| 12082 | false, true, &state->visible); |
| 12083 | if (ret) |
| 12084 | return ret; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12085 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12086 | if (intel_crtc->active) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12087 | intel_crtc->atomic.wait_for_flips = true; |
| 12088 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12089 | /* |
| 12090 | * FBC does not work on some platforms for rotated |
| 12091 | * planes, so disable it when rotation is not 0 and |
| 12092 | * update it when rotation is set back to 0. |
| 12093 | * |
| 12094 | * FIXME: This is redundant with the fbc update done in |
| 12095 | * the primary plane enable function except that that |
| 12096 | * one is done too late. We eventually need to unify |
| 12097 | * this. |
| 12098 | */ |
| 12099 | if (intel_crtc->primary_enabled && |
| 12100 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
Paulo Zanoni | e35fef2 | 2015-02-09 14:46:29 -0200 | [diff] [blame] | 12101 | dev_priv->fbc.crtc == intel_crtc && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12102 | state->base.rotation != BIT(DRM_ROTATE_0)) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12103 | intel_crtc->atomic.disable_fbc = true; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12104 | } |
| 12105 | |
| 12106 | if (state->visible) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12107 | /* |
| 12108 | * BDW signals flip done immediately if the plane |
| 12109 | * is disabled, even if the plane enable is already |
| 12110 | * armed to occur at the next vblank :( |
| 12111 | */ |
| 12112 | if (IS_BROADWELL(dev) && !intel_crtc->primary_enabled) |
| 12113 | intel_crtc->atomic.wait_vblank = true; |
| 12114 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12115 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12116 | intel_crtc->atomic.fb_bits |= |
| 12117 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
| 12118 | |
| 12119 | intel_crtc->atomic.update_fbc = true; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 12120 | |
| 12121 | /* Update watermarks on tiling changes. */ |
| 12122 | if (!plane->state->fb || !state->base.fb || |
| 12123 | plane->state->fb->modifier[0] != |
| 12124 | state->base.fb->modifier[0]) |
| 12125 | intel_crtc->atomic.update_wm = true; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12126 | } |
| 12127 | |
| 12128 | return 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12129 | } |
| 12130 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12131 | static void |
| 12132 | intel_commit_primary_plane(struct drm_plane *plane, |
| 12133 | struct intel_plane_state *state) |
| 12134 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12135 | struct drm_crtc *crtc = state->base.crtc; |
| 12136 | struct drm_framebuffer *fb = state->base.fb; |
| 12137 | struct drm_device *dev = plane->dev; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12138 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12139 | struct intel_crtc *intel_crtc; |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 12140 | struct drm_rect *src = &state->src; |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12141 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12142 | crtc = crtc ? crtc : plane->crtc; |
| 12143 | intel_crtc = to_intel_crtc(crtc); |
| 12144 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12145 | plane->fb = fb; |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 12146 | crtc->x = src->x1 >> 16; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12147 | crtc->y = src->y1 >> 16; |
| 12148 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12149 | if (intel_crtc->active) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12150 | if (state->visible) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12151 | /* FIXME: kill this fastboot hack */ |
| 12152 | intel_update_pipe_size(intel_crtc); |
| 12153 | |
| 12154 | intel_crtc->primary_enabled = true; |
| 12155 | |
| 12156 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 12157 | crtc->x, crtc->y); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12158 | } else { |
| 12159 | /* |
| 12160 | * If clipping results in a non-visible primary plane, |
| 12161 | * we'll disable the primary plane. Note that this is |
| 12162 | * a bit different than what happens if userspace |
| 12163 | * explicitly disables the plane by passing fb=0 |
| 12164 | * because plane->fb still gets set and pinned. |
| 12165 | */ |
| 12166 | intel_disable_primary_hw_plane(plane, crtc); |
| 12167 | } |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12168 | } |
| 12169 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12170 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12171 | static void intel_begin_crtc_commit(struct drm_crtc *crtc) |
| 12172 | { |
| 12173 | struct drm_device *dev = crtc->dev; |
| 12174 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12175 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12176 | struct intel_plane *intel_plane; |
| 12177 | struct drm_plane *p; |
| 12178 | unsigned fb_bits = 0; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12179 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12180 | /* Track fb's for any planes being disabled */ |
| 12181 | list_for_each_entry(p, &dev->mode_config.plane_list, head) { |
| 12182 | intel_plane = to_intel_plane(p); |
| 12183 | |
| 12184 | if (intel_crtc->atomic.disabled_planes & |
| 12185 | (1 << drm_plane_index(p))) { |
| 12186 | switch (p->type) { |
| 12187 | case DRM_PLANE_TYPE_PRIMARY: |
| 12188 | fb_bits = INTEL_FRONTBUFFER_PRIMARY(intel_plane->pipe); |
| 12189 | break; |
| 12190 | case DRM_PLANE_TYPE_CURSOR: |
| 12191 | fb_bits = INTEL_FRONTBUFFER_CURSOR(intel_plane->pipe); |
| 12192 | break; |
| 12193 | case DRM_PLANE_TYPE_OVERLAY: |
| 12194 | fb_bits = INTEL_FRONTBUFFER_SPRITE(intel_plane->pipe); |
| 12195 | break; |
| 12196 | } |
| 12197 | |
| 12198 | mutex_lock(&dev->struct_mutex); |
| 12199 | i915_gem_track_fb(intel_fb_obj(p->fb), NULL, fb_bits); |
| 12200 | mutex_unlock(&dev->struct_mutex); |
| 12201 | } |
| 12202 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12203 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12204 | if (intel_crtc->atomic.wait_for_flips) |
| 12205 | intel_crtc_wait_for_pending_flips(crtc); |
| 12206 | |
| 12207 | if (intel_crtc->atomic.disable_fbc) |
| 12208 | intel_fbc_disable(dev); |
| 12209 | |
| 12210 | if (intel_crtc->atomic.pre_disable_primary) |
| 12211 | intel_pre_disable_primary(crtc); |
| 12212 | |
| 12213 | if (intel_crtc->atomic.update_wm) |
| 12214 | intel_update_watermarks(crtc); |
| 12215 | |
| 12216 | intel_runtime_pm_get(dev_priv); |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 12217 | |
| 12218 | /* Perform vblank evasion around commit operation */ |
| 12219 | if (intel_crtc->active) |
| 12220 | intel_crtc->atomic.evade = |
| 12221 | intel_pipe_update_start(intel_crtc, |
| 12222 | &intel_crtc->atomic.start_vbl_count); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12223 | } |
| 12224 | |
| 12225 | static void intel_finish_crtc_commit(struct drm_crtc *crtc) |
| 12226 | { |
| 12227 | struct drm_device *dev = crtc->dev; |
| 12228 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12229 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12230 | struct drm_plane *p; |
| 12231 | |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 12232 | if (intel_crtc->atomic.evade) |
| 12233 | intel_pipe_update_end(intel_crtc, |
| 12234 | intel_crtc->atomic.start_vbl_count); |
| 12235 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12236 | intel_runtime_pm_put(dev_priv); |
| 12237 | |
| 12238 | if (intel_crtc->atomic.wait_vblank) |
| 12239 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 12240 | |
| 12241 | intel_frontbuffer_flip(dev, intel_crtc->atomic.fb_bits); |
| 12242 | |
| 12243 | if (intel_crtc->atomic.update_fbc) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12244 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 12245 | intel_fbc_update(dev); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12246 | mutex_unlock(&dev->struct_mutex); |
| 12247 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12248 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12249 | if (intel_crtc->atomic.post_enable_primary) |
| 12250 | intel_post_enable_primary(crtc); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12251 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12252 | drm_for_each_legacy_plane(p, &dev->mode_config.plane_list) |
| 12253 | if (intel_crtc->atomic.update_sprite_watermarks & drm_plane_index(p)) |
| 12254 | intel_update_sprite_watermarks(p, crtc, 0, 0, 0, |
| 12255 | false, false); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12256 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12257 | memset(&intel_crtc->atomic, 0, sizeof(intel_crtc->atomic)); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12258 | } |
| 12259 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12260 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 12261 | * intel_plane_destroy - destroy a plane |
| 12262 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12263 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 12264 | * Common destruction function for all types of planes (primary, cursor, |
| 12265 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12266 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 12267 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12268 | { |
| 12269 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 12270 | drm_plane_cleanup(plane); |
| 12271 | kfree(intel_plane); |
| 12272 | } |
| 12273 | |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 12274 | const struct drm_plane_funcs intel_plane_funcs = { |
Daniel Vetter | ff42e09 | 2015-03-02 16:35:20 +0100 | [diff] [blame] | 12275 | .update_plane = drm_plane_helper_update, |
| 12276 | .disable_plane = drm_plane_helper_disable, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12277 | .destroy = intel_plane_destroy, |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 12278 | .set_property = drm_atomic_helper_plane_set_property, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 12279 | .atomic_get_property = intel_plane_atomic_get_property, |
| 12280 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12281 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 12282 | .atomic_destroy_state = intel_plane_destroy_state, |
| 12283 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12284 | }; |
| 12285 | |
| 12286 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 12287 | int pipe) |
| 12288 | { |
| 12289 | struct intel_plane *primary; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12290 | struct intel_plane_state *state; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12291 | const uint32_t *intel_primary_formats; |
| 12292 | int num_formats; |
| 12293 | |
| 12294 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
| 12295 | if (primary == NULL) |
| 12296 | return NULL; |
| 12297 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12298 | state = intel_create_plane_state(&primary->base); |
| 12299 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12300 | kfree(primary); |
| 12301 | return NULL; |
| 12302 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12303 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12304 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12305 | primary->can_scale = false; |
| 12306 | primary->max_downscale = 1; |
| 12307 | primary->pipe = pipe; |
| 12308 | primary->plane = pipe; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12309 | primary->check_plane = intel_check_primary_plane; |
| 12310 | primary->commit_plane = intel_commit_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12311 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 12312 | primary->plane = !pipe; |
| 12313 | |
| 12314 | if (INTEL_INFO(dev)->gen <= 3) { |
| 12315 | intel_primary_formats = intel_primary_formats_gen2; |
| 12316 | num_formats = ARRAY_SIZE(intel_primary_formats_gen2); |
| 12317 | } else { |
| 12318 | intel_primary_formats = intel_primary_formats_gen4; |
| 12319 | num_formats = ARRAY_SIZE(intel_primary_formats_gen4); |
| 12320 | } |
| 12321 | |
| 12322 | drm_universal_plane_init(dev, &primary->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 12323 | &intel_plane_funcs, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12324 | intel_primary_formats, num_formats, |
| 12325 | DRM_PLANE_TYPE_PRIMARY); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12326 | |
| 12327 | if (INTEL_INFO(dev)->gen >= 4) { |
| 12328 | if (!dev->mode_config.rotation_property) |
| 12329 | dev->mode_config.rotation_property = |
| 12330 | drm_mode_create_rotation_property(dev, |
| 12331 | BIT(DRM_ROTATE_0) | |
| 12332 | BIT(DRM_ROTATE_180)); |
| 12333 | if (dev->mode_config.rotation_property) |
| 12334 | drm_object_attach_property(&primary->base.base, |
| 12335 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12336 | state->base.rotation); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12337 | } |
| 12338 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12339 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 12340 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12341 | return &primary->base; |
| 12342 | } |
| 12343 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12344 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12345 | intel_check_cursor_plane(struct drm_plane *plane, |
| 12346 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12347 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12348 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12349 | struct drm_device *dev = plane->dev; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12350 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12351 | struct drm_rect *dest = &state->dst; |
| 12352 | struct drm_rect *src = &state->src; |
| 12353 | const struct drm_rect *clip = &state->clip; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12354 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12355 | struct intel_crtc *intel_crtc; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12356 | unsigned stride; |
| 12357 | int ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12358 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12359 | crtc = crtc ? crtc : plane->crtc; |
| 12360 | intel_crtc = to_intel_crtc(crtc); |
| 12361 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12362 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12363 | src, dest, clip, |
| 12364 | DRM_PLANE_HELPER_NO_SCALING, |
| 12365 | DRM_PLANE_HELPER_NO_SCALING, |
| 12366 | true, true, &state->visible); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12367 | if (ret) |
| 12368 | return ret; |
| 12369 | |
| 12370 | |
| 12371 | /* if we want to turn off the cursor ignore width and height */ |
| 12372 | if (!obj) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12373 | goto finish; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12374 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12375 | /* Check for which cursor types we support */ |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12376 | if (!cursor_size_ok(dev, state->base.crtc_w, state->base.crtc_h)) { |
| 12377 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 12378 | state->base.crtc_w, state->base.crtc_h); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12379 | return -EINVAL; |
| 12380 | } |
| 12381 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12382 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
| 12383 | if (obj->base.size < stride * state->base.crtc_h) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12384 | DRM_DEBUG_KMS("buffer is too small\n"); |
| 12385 | return -ENOMEM; |
| 12386 | } |
| 12387 | |
Ville Syrjälä | 3a656b5 | 2015-03-09 21:08:37 +0200 | [diff] [blame] | 12388 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12389 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 12390 | ret = -EINVAL; |
| 12391 | } |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12392 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12393 | finish: |
| 12394 | if (intel_crtc->active) { |
Ville Syrjälä | 3749f46 | 2015-03-10 13:15:22 +0200 | [diff] [blame] | 12395 | if (plane->state->crtc_w != state->base.crtc_w) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12396 | intel_crtc->atomic.update_wm = true; |
| 12397 | |
| 12398 | intel_crtc->atomic.fb_bits |= |
| 12399 | INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe); |
| 12400 | } |
| 12401 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12402 | return ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12403 | } |
| 12404 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 12405 | static void |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12406 | intel_commit_cursor_plane(struct drm_plane *plane, |
| 12407 | struct intel_plane_state *state) |
| 12408 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12409 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12410 | struct drm_device *dev = plane->dev; |
| 12411 | struct intel_crtc *intel_crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12412 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12413 | uint32_t addr; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12414 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12415 | crtc = crtc ? crtc : plane->crtc; |
| 12416 | intel_crtc = to_intel_crtc(crtc); |
Sonika Jindal | a919db9 | 2014-10-23 07:41:33 -0700 | [diff] [blame] | 12417 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12418 | plane->fb = state->base.fb; |
| 12419 | crtc->cursor_x = state->base.crtc_x; |
| 12420 | crtc->cursor_y = state->base.crtc_y; |
| 12421 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12422 | if (intel_crtc->cursor_bo == obj) |
| 12423 | goto update; |
| 12424 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 12425 | if (!obj) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12426 | addr = 0; |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 12427 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12428 | addr = i915_gem_obj_ggtt_offset(obj); |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 12429 | else |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12430 | addr = obj->phys_handle->busaddr; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12431 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12432 | intel_crtc->cursor_addr = addr; |
| 12433 | intel_crtc->cursor_bo = obj; |
| 12434 | update: |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12435 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12436 | if (intel_crtc->active) |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12437 | intel_crtc_update_cursor(crtc, state->visible); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12438 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12439 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12440 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 12441 | int pipe) |
| 12442 | { |
| 12443 | struct intel_plane *cursor; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12444 | struct intel_plane_state *state; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12445 | |
| 12446 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
| 12447 | if (cursor == NULL) |
| 12448 | return NULL; |
| 12449 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12450 | state = intel_create_plane_state(&cursor->base); |
| 12451 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12452 | kfree(cursor); |
| 12453 | return NULL; |
| 12454 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12455 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12456 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12457 | cursor->can_scale = false; |
| 12458 | cursor->max_downscale = 1; |
| 12459 | cursor->pipe = pipe; |
| 12460 | cursor->plane = pipe; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12461 | cursor->check_plane = intel_check_cursor_plane; |
| 12462 | cursor->commit_plane = intel_commit_cursor_plane; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12463 | |
| 12464 | drm_universal_plane_init(dev, &cursor->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 12465 | &intel_plane_funcs, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12466 | intel_cursor_formats, |
| 12467 | ARRAY_SIZE(intel_cursor_formats), |
| 12468 | DRM_PLANE_TYPE_CURSOR); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 12469 | |
| 12470 | if (INTEL_INFO(dev)->gen >= 4) { |
| 12471 | if (!dev->mode_config.rotation_property) |
| 12472 | dev->mode_config.rotation_property = |
| 12473 | drm_mode_create_rotation_property(dev, |
| 12474 | BIT(DRM_ROTATE_0) | |
| 12475 | BIT(DRM_ROTATE_180)); |
| 12476 | if (dev->mode_config.rotation_property) |
| 12477 | drm_object_attach_property(&cursor->base.base, |
| 12478 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12479 | state->base.rotation); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 12480 | } |
| 12481 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12482 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 12483 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12484 | return &cursor->base; |
| 12485 | } |
| 12486 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 12487 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12488 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12489 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12490 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 12491 | struct intel_crtc_state *crtc_state = NULL; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12492 | struct drm_plane *primary = NULL; |
| 12493 | struct drm_plane *cursor = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12494 | int i, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12495 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 12496 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12497 | if (intel_crtc == NULL) |
| 12498 | return; |
| 12499 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 12500 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 12501 | if (!crtc_state) |
| 12502 | goto fail; |
| 12503 | intel_crtc_set_state(intel_crtc, crtc_state); |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 12504 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 12505 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12506 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12507 | if (!primary) |
| 12508 | goto fail; |
| 12509 | |
| 12510 | cursor = intel_cursor_plane_create(dev, pipe); |
| 12511 | if (!cursor) |
| 12512 | goto fail; |
| 12513 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12514 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12515 | cursor, &intel_crtc_funcs); |
| 12516 | if (ret) |
| 12517 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12518 | |
| 12519 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12520 | for (i = 0; i < 256; i++) { |
| 12521 | intel_crtc->lut_r[i] = i; |
| 12522 | intel_crtc->lut_g[i] = i; |
| 12523 | intel_crtc->lut_b[i] = i; |
| 12524 | } |
| 12525 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 12526 | /* |
| 12527 | * 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] | 12528 | * 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] | 12529 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 12530 | intel_crtc->pipe = pipe; |
| 12531 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 12532 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 12533 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 12534 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 12535 | } |
| 12536 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 12537 | intel_crtc->cursor_base = ~0; |
| 12538 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 12539 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 12540 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 12541 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 12542 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 12543 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 12544 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 12545 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 12546 | INIT_WORK(&intel_crtc->mmio_flip.work, intel_mmio_flip_work_func); |
| 12547 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12548 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 12549 | |
| 12550 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12551 | return; |
| 12552 | |
| 12553 | fail: |
| 12554 | if (primary) |
| 12555 | drm_plane_cleanup(primary); |
| 12556 | if (cursor) |
| 12557 | drm_plane_cleanup(cursor); |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 12558 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12559 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12560 | } |
| 12561 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12562 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 12563 | { |
| 12564 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 12565 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12566 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 12567 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12568 | |
Ville Syrjälä | d3babd3 | 2014-11-07 11:16:01 +0200 | [diff] [blame] | 12569 | if (!encoder || WARN_ON(!encoder->crtc)) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12570 | return INVALID_PIPE; |
| 12571 | |
| 12572 | return to_intel_crtc(encoder->crtc)->pipe; |
| 12573 | } |
| 12574 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12575 | 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] | 12576 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12577 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12578 | 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] | 12579 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12580 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12581 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12582 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12583 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12584 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12585 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 12586 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12587 | } |
| 12588 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12589 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12590 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12591 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12592 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12593 | } |
| 12594 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12595 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12596 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12597 | struct drm_device *dev = encoder->base.dev; |
| 12598 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12599 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12600 | int entry = 0; |
| 12601 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12602 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 12603 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12604 | index_mask |= (1 << entry); |
| 12605 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12606 | entry++; |
| 12607 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12608 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12609 | return index_mask; |
| 12610 | } |
| 12611 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 12612 | static bool has_edp_a(struct drm_device *dev) |
| 12613 | { |
| 12614 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12615 | |
| 12616 | if (!IS_MOBILE(dev)) |
| 12617 | return false; |
| 12618 | |
| 12619 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 12620 | return false; |
| 12621 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 12622 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 12623 | return false; |
| 12624 | |
| 12625 | return true; |
| 12626 | } |
| 12627 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 12628 | static bool intel_crt_present(struct drm_device *dev) |
| 12629 | { |
| 12630 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12631 | |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 12632 | if (INTEL_INFO(dev)->gen >= 9) |
| 12633 | return false; |
| 12634 | |
Damien Lespiau | cf404ce | 2014-10-01 20:04:15 +0100 | [diff] [blame] | 12635 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 12636 | return false; |
| 12637 | |
| 12638 | if (IS_CHERRYVIEW(dev)) |
| 12639 | return false; |
| 12640 | |
| 12641 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) |
| 12642 | return false; |
| 12643 | |
| 12644 | return true; |
| 12645 | } |
| 12646 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12647 | static void intel_setup_outputs(struct drm_device *dev) |
| 12648 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 12649 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12650 | struct intel_encoder *encoder; |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 12651 | struct drm_connector *connector; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12652 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12653 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 12654 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12655 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 12656 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 12657 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12658 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 12659 | if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 12660 | int found; |
| 12661 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 12662 | /* |
| 12663 | * Haswell uses DDI functions to detect digital outputs. |
| 12664 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 12665 | * it's there. |
| 12666 | */ |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 12667 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 12668 | /* WaIgnoreDDIAStrap: skl */ |
| 12669 | if (found || |
| 12670 | (IS_SKYLAKE(dev) && INTEL_REVID(dev) < SKL_REVID_D0)) |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 12671 | intel_ddi_init(dev, PORT_A); |
| 12672 | |
| 12673 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 12674 | * register */ |
| 12675 | found = I915_READ(SFUSE_STRAP); |
| 12676 | |
| 12677 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 12678 | intel_ddi_init(dev, PORT_B); |
| 12679 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 12680 | intel_ddi_init(dev, PORT_C); |
| 12681 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 12682 | intel_ddi_init(dev, PORT_D); |
| 12683 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12684 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 12685 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 12686 | |
| 12687 | if (has_edp_a(dev)) |
| 12688 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 12689 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 12690 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 12691 | /* PCH SDVOB multiplex with HDMIB */ |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 12692 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12693 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12694 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 12695 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12696 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12697 | } |
| 12698 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 12699 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12700 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12701 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 12702 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12703 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 12704 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 12705 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12706 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 12707 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 12708 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12709 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 12710 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 12711 | /* |
| 12712 | * The DP_DETECTED bit is the latched state of the DDC |
| 12713 | * SDA pin at boot. However since eDP doesn't require DDC |
| 12714 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 12715 | * eDP ports may have been muxed to an alternate function. |
| 12716 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 12717 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 12718 | * detect eDP ports. |
| 12719 | */ |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 12720 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED && |
| 12721 | !intel_dp_is_edp(dev, PORT_B)) |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 12722 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
| 12723 | PORT_B); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 12724 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || |
| 12725 | intel_dp_is_edp(dev, PORT_B)) |
| 12726 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 12727 | |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 12728 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED && |
| 12729 | !intel_dp_is_edp(dev, PORT_C)) |
Jesse Barnes | 6f6005a | 2013-08-09 09:34:35 -0700 | [diff] [blame] | 12730 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
| 12731 | PORT_C); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 12732 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || |
| 12733 | intel_dp_is_edp(dev, PORT_C)) |
| 12734 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 12735 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 12736 | if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 12737 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 12738 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
| 12739 | PORT_D); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 12740 | /* eDP not supported on port D, so don't check VBT */ |
| 12741 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) |
| 12742 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 12743 | } |
| 12744 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 12745 | intel_dsi_init(dev); |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 12746 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12747 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 12748 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12749 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12750 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12751 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12752 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 12753 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12754 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12755 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12756 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 12757 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12758 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 12759 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 12760 | |
| 12761 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 12762 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12763 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12764 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12765 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12766 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12767 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12768 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12769 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12770 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 12771 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 12772 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12773 | } |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 12774 | if (SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12775 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 12776 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 12777 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 12778 | if (SUPPORTS_INTEGRATED_DP(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 12779 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 12780 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 12781 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12782 | intel_dvo_init(dev); |
| 12783 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 12784 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12785 | intel_tv_init(dev); |
| 12786 | |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 12787 | /* |
| 12788 | * FIXME: We don't have full atomic support yet, but we want to be |
| 12789 | * able to enable/test plane updates via the atomic interface in the |
| 12790 | * meantime. However as soon as we flip DRIVER_ATOMIC on, the DRM core |
| 12791 | * will take some atomic codepaths to lookup properties during |
| 12792 | * drmModeGetConnector() that unconditionally dereference |
| 12793 | * connector->state. |
| 12794 | * |
| 12795 | * We create a dummy connector state here for each connector to ensure |
| 12796 | * the DRM core doesn't try to dereference a NULL connector->state. |
| 12797 | * The actual connector properties will never be updated or contain |
| 12798 | * useful information, but since we're doing this specifically for |
| 12799 | * testing/debug of the plane operations (and only when a specific |
| 12800 | * kernel module option is given), that shouldn't really matter. |
| 12801 | * |
| 12802 | * Once atomic support for crtc's + connectors lands, this loop should |
| 12803 | * be removed since we'll be setting up real connector state, which |
| 12804 | * will contain Intel-specific properties. |
| 12805 | */ |
| 12806 | if (drm_core_check_feature(dev, DRIVER_ATOMIC)) { |
| 12807 | list_for_each_entry(connector, |
| 12808 | &dev->mode_config.connector_list, |
| 12809 | head) { |
| 12810 | if (!WARN_ON(connector->state)) { |
| 12811 | connector->state = |
| 12812 | kzalloc(sizeof(*connector->state), |
| 12813 | GFP_KERNEL); |
| 12814 | } |
| 12815 | } |
| 12816 | } |
| 12817 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 12818 | intel_psr_init(dev); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 12819 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12820 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12821 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 12822 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12823 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12824 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 12825 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 12826 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 12827 | |
| 12828 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12829 | } |
| 12830 | |
| 12831 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 12832 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 12833 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12834 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12835 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 12836 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 12837 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 12838 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 12839 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 12840 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12841 | kfree(intel_fb); |
| 12842 | } |
| 12843 | |
| 12844 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12845 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12846 | unsigned int *handle) |
| 12847 | { |
| 12848 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12849 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12850 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 12851 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12852 | } |
| 12853 | |
| 12854 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 12855 | .destroy = intel_user_framebuffer_destroy, |
| 12856 | .create_handle = intel_user_framebuffer_create_handle, |
| 12857 | }; |
| 12858 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 12859 | static |
| 12860 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, |
| 12861 | uint32_t pixel_format) |
| 12862 | { |
| 12863 | u32 gen = INTEL_INFO(dev)->gen; |
| 12864 | |
| 12865 | if (gen >= 9) { |
| 12866 | /* "The stride in bytes must not exceed the of the size of 8K |
| 12867 | * pixels and 32K bytes." |
| 12868 | */ |
| 12869 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); |
| 12870 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { |
| 12871 | return 32*1024; |
| 12872 | } else if (gen >= 4) { |
| 12873 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 12874 | return 16*1024; |
| 12875 | else |
| 12876 | return 32*1024; |
| 12877 | } else if (gen >= 3) { |
| 12878 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 12879 | return 8*1024; |
| 12880 | else |
| 12881 | return 16*1024; |
| 12882 | } else { |
| 12883 | /* XXX DSPC is limited to 4k tiled */ |
| 12884 | return 8*1024; |
| 12885 | } |
| 12886 | } |
| 12887 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 12888 | static int intel_framebuffer_init(struct drm_device *dev, |
| 12889 | struct intel_framebuffer *intel_fb, |
| 12890 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 12891 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12892 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame^] | 12893 | unsigned int aligned_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12894 | int ret; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 12895 | u32 pitch_limit, stride_alignment; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12896 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 12897 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 12898 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 12899 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
| 12900 | /* Enforce that fb modifier and tiling mode match, but only for |
| 12901 | * X-tiled. This is needed for FBC. */ |
| 12902 | if (!!(obj->tiling_mode == I915_TILING_X) != |
| 12903 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { |
| 12904 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); |
| 12905 | return -EINVAL; |
| 12906 | } |
| 12907 | } else { |
| 12908 | if (obj->tiling_mode == I915_TILING_X) |
| 12909 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 12910 | else if (obj->tiling_mode == I915_TILING_Y) { |
| 12911 | DRM_DEBUG("No Y tiling for legacy addfb\n"); |
| 12912 | return -EINVAL; |
| 12913 | } |
| 12914 | } |
| 12915 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 12916 | /* Passed in modifier sanity checking. */ |
| 12917 | switch (mode_cmd->modifier[0]) { |
| 12918 | case I915_FORMAT_MOD_Y_TILED: |
| 12919 | case I915_FORMAT_MOD_Yf_TILED: |
| 12920 | if (INTEL_INFO(dev)->gen < 9) { |
| 12921 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", |
| 12922 | mode_cmd->modifier[0]); |
| 12923 | return -EINVAL; |
| 12924 | } |
| 12925 | case DRM_FORMAT_MOD_NONE: |
| 12926 | case I915_FORMAT_MOD_X_TILED: |
| 12927 | break; |
| 12928 | default: |
| 12929 | DRM_ERROR("Unsupported fb modifier 0x%llx!\n", |
| 12930 | mode_cmd->modifier[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12931 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12932 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12933 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 12934 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
| 12935 | mode_cmd->pixel_format); |
| 12936 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { |
| 12937 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", |
| 12938 | mode_cmd->pitches[0], stride_alignment); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12939 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12940 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12941 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 12942 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
| 12943 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 12944 | if (mode_cmd->pitches[0] > pitch_limit) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 12945 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
| 12946 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 12947 | "tiled" : "linear", |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 12948 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12949 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12950 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12951 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 12952 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12953 | mode_cmd->pitches[0] != obj->stride) { |
| 12954 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 12955 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12956 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12957 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 12958 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12959 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 12960 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12961 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 12962 | case DRM_FORMAT_RGB565: |
| 12963 | case DRM_FORMAT_XRGB8888: |
| 12964 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12965 | break; |
| 12966 | case DRM_FORMAT_XRGB1555: |
| 12967 | case DRM_FORMAT_ARGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12968 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12969 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12970 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12971 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12972 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12973 | break; |
| 12974 | case DRM_FORMAT_XBGR8888: |
| 12975 | case DRM_FORMAT_ABGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 12976 | case DRM_FORMAT_XRGB2101010: |
| 12977 | case DRM_FORMAT_ARGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12978 | case DRM_FORMAT_XBGR2101010: |
| 12979 | case DRM_FORMAT_ABGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12980 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12981 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12982 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12983 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12984 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 12985 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 12986 | case DRM_FORMAT_YUYV: |
| 12987 | case DRM_FORMAT_UYVY: |
| 12988 | case DRM_FORMAT_YVYU: |
| 12989 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12990 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12991 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12992 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 12993 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 12994 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12995 | break; |
| 12996 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 12997 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 12998 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 12999 | return -EINVAL; |
| 13000 | } |
| 13001 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 13002 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 13003 | if (mode_cmd->offsets[0] != 0) |
| 13004 | return -EINVAL; |
| 13005 | |
Damien Lespiau | ec2c981 | 2015-01-20 12:51:45 +0000 | [diff] [blame] | 13006 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 13007 | mode_cmd->pixel_format, |
| 13008 | mode_cmd->modifier[0]); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 13009 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 13010 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 13011 | return -EINVAL; |
| 13012 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 13013 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 13014 | intel_fb->obj = obj; |
Daniel Vetter | 80075d4 | 2013-10-09 21:23:52 +0200 | [diff] [blame] | 13015 | intel_fb->obj->framebuffer_references++; |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 13016 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13017 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 13018 | if (ret) { |
| 13019 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 13020 | return ret; |
| 13021 | } |
| 13022 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13023 | return 0; |
| 13024 | } |
| 13025 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13026 | static struct drm_framebuffer * |
| 13027 | intel_user_framebuffer_create(struct drm_device *dev, |
| 13028 | struct drm_file *filp, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 13029 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13030 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13031 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13032 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 13033 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
| 13034 | mode_cmd->handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 13035 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 13036 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13037 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 13038 | return intel_framebuffer_create(dev, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13039 | } |
| 13040 | |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 13041 | #ifndef CONFIG_DRM_I915_FBDEV |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 13042 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 13043 | { |
| 13044 | } |
| 13045 | #endif |
| 13046 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13047 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13048 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 13049 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 13050 | .atomic_check = intel_atomic_check, |
| 13051 | .atomic_commit = intel_atomic_commit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13052 | }; |
| 13053 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13054 | /* Set up chip specific display functions */ |
| 13055 | static void intel_init_display(struct drm_device *dev) |
| 13056 | { |
| 13057 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13058 | |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 13059 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
| 13060 | dev_priv->display.find_dpll = g4x_find_best_dpll; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 13061 | else if (IS_CHERRYVIEW(dev)) |
| 13062 | dev_priv->display.find_dpll = chv_find_best_dpll; |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 13063 | else if (IS_VALLEYVIEW(dev)) |
| 13064 | dev_priv->display.find_dpll = vlv_find_best_dpll; |
| 13065 | else if (IS_PINEVIEW(dev)) |
| 13066 | dev_priv->display.find_dpll = pnv_find_best_dpll; |
| 13067 | else |
| 13068 | dev_priv->display.find_dpll = i9xx_find_best_dpll; |
| 13069 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 13070 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13071 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13072 | dev_priv->display.get_initial_plane_config = |
| 13073 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 13074 | dev_priv->display.crtc_compute_clock = |
| 13075 | haswell_crtc_compute_clock; |
| 13076 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 13077 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
| 13078 | dev_priv->display.off = ironlake_crtc_off; |
| 13079 | dev_priv->display.update_primary_plane = |
| 13080 | skylake_update_primary_plane; |
| 13081 | } else if (HAS_DDI(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13082 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13083 | dev_priv->display.get_initial_plane_config = |
| 13084 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 13085 | dev_priv->display.crtc_compute_clock = |
| 13086 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 13087 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 13088 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 13089 | dev_priv->display.off = ironlake_crtc_off; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 13090 | dev_priv->display.update_primary_plane = |
| 13091 | ironlake_update_primary_plane; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 13092 | } else if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13093 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13094 | dev_priv->display.get_initial_plane_config = |
| 13095 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 13096 | dev_priv->display.crtc_compute_clock = |
| 13097 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 13098 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 13099 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13100 | dev_priv->display.off = ironlake_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 13101 | dev_priv->display.update_primary_plane = |
| 13102 | ironlake_update_primary_plane; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 13103 | } else if (IS_VALLEYVIEW(dev)) { |
| 13104 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13105 | dev_priv->display.get_initial_plane_config = |
| 13106 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 13107 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 13108 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 13109 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 13110 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 13111 | dev_priv->display.update_primary_plane = |
| 13112 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 13113 | } else { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13114 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13115 | dev_priv->display.get_initial_plane_config = |
| 13116 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 13117 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 13118 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 13119 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13120 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 13121 | dev_priv->display.update_primary_plane = |
| 13122 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 13123 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13124 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13125 | /* Returns the core display clock speed */ |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 13126 | if (IS_VALLEYVIEW(dev)) |
| 13127 | dev_priv->display.get_display_clock_speed = |
| 13128 | valleyview_get_display_clock_speed; |
| 13129 | else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev))) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13130 | dev_priv->display.get_display_clock_speed = |
| 13131 | i945_get_display_clock_speed; |
| 13132 | else if (IS_I915G(dev)) |
| 13133 | dev_priv->display.get_display_clock_speed = |
| 13134 | i915_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 13135 | else if (IS_I945GM(dev) || IS_845G(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13136 | dev_priv->display.get_display_clock_speed = |
| 13137 | i9xx_misc_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 13138 | else if (IS_PINEVIEW(dev)) |
| 13139 | dev_priv->display.get_display_clock_speed = |
| 13140 | pnv_get_display_clock_speed; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13141 | else if (IS_I915GM(dev)) |
| 13142 | dev_priv->display.get_display_clock_speed = |
| 13143 | i915gm_get_display_clock_speed; |
| 13144 | else if (IS_I865G(dev)) |
| 13145 | dev_priv->display.get_display_clock_speed = |
| 13146 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 13147 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13148 | dev_priv->display.get_display_clock_speed = |
| 13149 | i855_get_display_clock_speed; |
| 13150 | else /* 852, 830 */ |
| 13151 | dev_priv->display.get_display_clock_speed = |
| 13152 | i830_get_display_clock_speed; |
| 13153 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 13154 | if (IS_GEN5(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13155 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13156 | } else if (IS_GEN6(dev)) { |
| 13157 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13158 | } else if (IS_IVYBRIDGE(dev)) { |
| 13159 | /* FIXME: detect B0+ stepping and use auto training */ |
| 13160 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Paulo Zanoni | 059b2fe | 2014-09-02 16:53:57 -0300 | [diff] [blame] | 13161 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13162 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 13163 | } else if (IS_VALLEYVIEW(dev)) { |
| 13164 | dev_priv->display.modeset_global_resources = |
| 13165 | valleyview_modeset_global_resources; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13166 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 13167 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 13168 | switch (INTEL_INFO(dev)->gen) { |
| 13169 | case 2: |
| 13170 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 13171 | break; |
| 13172 | |
| 13173 | case 3: |
| 13174 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 13175 | break; |
| 13176 | |
| 13177 | case 4: |
| 13178 | case 5: |
| 13179 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 13180 | break; |
| 13181 | |
| 13182 | case 6: |
| 13183 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 13184 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 13185 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 13186 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 13187 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 13188 | break; |
Damien Lespiau | 830c81d | 2014-11-13 17:51:46 +0000 | [diff] [blame] | 13189 | case 9: |
Tvrtko Ursulin | ba343e0 | 2015-02-10 17:16:12 +0000 | [diff] [blame] | 13190 | /* Drop through - unsupported since execlist only. */ |
| 13191 | default: |
| 13192 | /* Default just returns -ENODEV to indicate unsupported */ |
| 13193 | dev_priv->display.queue_flip = intel_default_queue_flip; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 13194 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 13195 | |
| 13196 | intel_panel_init_backlight_funcs(dev); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 13197 | |
| 13198 | mutex_init(&dev_priv->pps_mutex); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13199 | } |
| 13200 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13201 | /* |
| 13202 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 13203 | * resume, or other times. This quirk makes sure that's the case for |
| 13204 | * affected systems. |
| 13205 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 13206 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13207 | { |
| 13208 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13209 | |
| 13210 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 13211 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13212 | } |
| 13213 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 13214 | static void quirk_pipeb_force(struct drm_device *dev) |
| 13215 | { |
| 13216 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13217 | |
| 13218 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 13219 | DRM_INFO("applying pipe b force quirk\n"); |
| 13220 | } |
| 13221 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 13222 | /* |
| 13223 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 13224 | */ |
| 13225 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 13226 | { |
| 13227 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13228 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 13229 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 13230 | } |
| 13231 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 13232 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 13233 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 13234 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 13235 | */ |
| 13236 | static void quirk_invert_brightness(struct drm_device *dev) |
| 13237 | { |
| 13238 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13239 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 13240 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13241 | } |
| 13242 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 13243 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 13244 | static void quirk_backlight_present(struct drm_device *dev) |
| 13245 | { |
| 13246 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13247 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 13248 | DRM_INFO("applying backlight present quirk\n"); |
| 13249 | } |
| 13250 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13251 | struct intel_quirk { |
| 13252 | int device; |
| 13253 | int subsystem_vendor; |
| 13254 | int subsystem_device; |
| 13255 | void (*hook)(struct drm_device *dev); |
| 13256 | }; |
| 13257 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 13258 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 13259 | struct intel_dmi_quirk { |
| 13260 | void (*hook)(struct drm_device *dev); |
| 13261 | const struct dmi_system_id (*dmi_id_list)[]; |
| 13262 | }; |
| 13263 | |
| 13264 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 13265 | { |
| 13266 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 13267 | return 1; |
| 13268 | } |
| 13269 | |
| 13270 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 13271 | { |
| 13272 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 13273 | { |
| 13274 | .callback = intel_dmi_reverse_brightness, |
| 13275 | .ident = "NCR Corporation", |
| 13276 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 13277 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 13278 | }, |
| 13279 | }, |
| 13280 | { } /* terminating entry */ |
| 13281 | }, |
| 13282 | .hook = quirk_invert_brightness, |
| 13283 | }, |
| 13284 | }; |
| 13285 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 13286 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13287 | /* HP Mini needs pipe A force quirk (LP: #322104) */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 13288 | { 0x27ae, 0x103c, 0x361a, quirk_pipea_force }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13289 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13290 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 13291 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 13292 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13293 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 13294 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 13295 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 13296 | /* 830 needs to leave pipe A & dpll A up */ |
| 13297 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 13298 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 13299 | /* 830 needs to leave pipe B & dpll B up */ |
| 13300 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 13301 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 13302 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 13303 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 13304 | |
| 13305 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 13306 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 13307 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 13308 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 13309 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 13310 | |
| 13311 | /* Acer/eMachines G725 */ |
| 13312 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 13313 | |
| 13314 | /* Acer/eMachines e725 */ |
| 13315 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 13316 | |
| 13317 | /* Acer/Packard Bell NCL20 */ |
| 13318 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 13319 | |
| 13320 | /* Acer Aspire 4736Z */ |
| 13321 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 13322 | |
| 13323 | /* Acer Aspire 5336 */ |
| 13324 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 13325 | |
| 13326 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 13327 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 13328 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 13329 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 13330 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 13331 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 13332 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 13333 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 13334 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 13335 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 13336 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 13337 | |
| 13338 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 13339 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 13340 | |
| 13341 | /* Dell Chromebook 11 */ |
| 13342 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13343 | }; |
| 13344 | |
| 13345 | static void intel_init_quirks(struct drm_device *dev) |
| 13346 | { |
| 13347 | struct pci_dev *d = dev->pdev; |
| 13348 | int i; |
| 13349 | |
| 13350 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 13351 | struct intel_quirk *q = &intel_quirks[i]; |
| 13352 | |
| 13353 | if (d->device == q->device && |
| 13354 | (d->subsystem_vendor == q->subsystem_vendor || |
| 13355 | q->subsystem_vendor == PCI_ANY_ID) && |
| 13356 | (d->subsystem_device == q->subsystem_device || |
| 13357 | q->subsystem_device == PCI_ANY_ID)) |
| 13358 | q->hook(dev); |
| 13359 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 13360 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 13361 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 13362 | intel_dmi_quirks[i].hook(dev); |
| 13363 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13364 | } |
| 13365 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13366 | /* Disable the VGA plane that we never use */ |
| 13367 | static void i915_disable_vga(struct drm_device *dev) |
| 13368 | { |
| 13369 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13370 | u8 sr1; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 13371 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13372 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 13373 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13374 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 13375 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13376 | sr1 = inb(VGA_SR_DATA); |
| 13377 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 13378 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 13379 | udelay(300); |
| 13380 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 13381 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13382 | POSTING_READ(vga_reg); |
| 13383 | } |
| 13384 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 13385 | void intel_modeset_init_hw(struct drm_device *dev) |
| 13386 | { |
Eugeni Dodonov | a8f78b5 | 2012-06-28 15:55:35 -0300 | [diff] [blame] | 13387 | intel_prepare_ddi(dev); |
| 13388 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 13389 | if (IS_VALLEYVIEW(dev)) |
| 13390 | vlv_update_cdclk(dev); |
| 13391 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 13392 | intel_init_clock_gating(dev); |
| 13393 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 13394 | intel_enable_gt_powersave(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 13395 | } |
| 13396 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13397 | void intel_modeset_init(struct drm_device *dev) |
| 13398 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13399 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 13400 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 13401 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13402 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13403 | |
| 13404 | drm_mode_config_init(dev); |
| 13405 | |
| 13406 | dev->mode_config.min_width = 0; |
| 13407 | dev->mode_config.min_height = 0; |
| 13408 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 13409 | dev->mode_config.preferred_depth = 24; |
| 13410 | dev->mode_config.prefer_shadow = 1; |
| 13411 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 13412 | dev->mode_config.allow_fb_modifiers = true; |
| 13413 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 13414 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13415 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13416 | intel_init_quirks(dev); |
| 13417 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 13418 | intel_init_pm(dev); |
| 13419 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 13420 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 13421 | return; |
| 13422 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13423 | intel_init_display(dev); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 13424 | intel_init_audio(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13425 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 13426 | if (IS_GEN2(dev)) { |
| 13427 | dev->mode_config.max_width = 2048; |
| 13428 | dev->mode_config.max_height = 2048; |
| 13429 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 13430 | dev->mode_config.max_width = 4096; |
| 13431 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13432 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 13433 | dev->mode_config.max_width = 8192; |
| 13434 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13435 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 13436 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 13437 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 13438 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 13439 | dev->mode_config.cursor_height = 1023; |
| 13440 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 13441 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 13442 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 13443 | } else { |
| 13444 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 13445 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 13446 | } |
| 13447 | |
Ben Widawsky | 5d4545a | 2013-01-17 12:45:15 -0800 | [diff] [blame] | 13448 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13449 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 13450 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 13451 | INTEL_INFO(dev)->num_pipes, |
| 13452 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13453 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13454 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 13455 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 13456 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 13457 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 13458 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 13459 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 13460 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 13461 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13462 | } |
| 13463 | |
Jesse Barnes | f42bb70 | 2013-12-16 16:34:23 -0800 | [diff] [blame] | 13464 | intel_init_dpio(dev); |
| 13465 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 13466 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13467 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13468 | /* Just disable it once at startup */ |
| 13469 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13470 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 13471 | |
| 13472 | /* Just in case the BIOS is doing something questionable. */ |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 13473 | intel_fbc_disable(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 13474 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13475 | drm_modeset_lock_all(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 13476 | intel_modeset_setup_hw_state(dev, false); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13477 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13478 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13479 | for_each_intel_crtc(dev, crtc) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13480 | if (!crtc->active) |
| 13481 | continue; |
| 13482 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13483 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13484 | * Note that reserving the BIOS fb up front prevents us |
| 13485 | * from stuffing other stolen allocations like the ring |
| 13486 | * on top. This prevents some ugliness at boot time, and |
| 13487 | * can even allow for smooth boot transitions if the BIOS |
| 13488 | * fb is large enough for the active pipe configuration. |
| 13489 | */ |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13490 | if (dev_priv->display.get_initial_plane_config) { |
| 13491 | dev_priv->display.get_initial_plane_config(crtc, |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13492 | &crtc->plane_config); |
| 13493 | /* |
| 13494 | * If the fb is shared between multiple heads, we'll |
| 13495 | * just get the first one. |
| 13496 | */ |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13497 | intel_find_plane_obj(crtc, &crtc->plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13498 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13499 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 13500 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 13501 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13502 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 13503 | { |
| 13504 | struct intel_connector *connector; |
| 13505 | struct drm_connector *crt = NULL; |
| 13506 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 13507 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13508 | |
| 13509 | /* We can't just switch on the pipe A, we need to set things up with a |
| 13510 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 13511 | * by enabling the load detect pipe once. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13512 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13513 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 13514 | crt = &connector->base; |
| 13515 | break; |
| 13516 | } |
| 13517 | } |
| 13518 | |
| 13519 | if (!crt) |
| 13520 | return; |
| 13521 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 13522 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
| 13523 | intel_release_load_detect_pipe(crt, &load_detect_temp); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13524 | } |
| 13525 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13526 | static bool |
| 13527 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 13528 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 13529 | struct drm_device *dev = crtc->base.dev; |
| 13530 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13531 | u32 reg, val; |
| 13532 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 13533 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13534 | return true; |
| 13535 | |
| 13536 | reg = DSPCNTR(!crtc->plane); |
| 13537 | val = I915_READ(reg); |
| 13538 | |
| 13539 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 13540 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 13541 | return false; |
| 13542 | |
| 13543 | return true; |
| 13544 | } |
| 13545 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13546 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 13547 | { |
| 13548 | struct drm_device *dev = crtc->base.dev; |
| 13549 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13550 | u32 reg; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13551 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13552 | /* Clear any frame start delays used for debugging left by the BIOS */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 13553 | reg = PIPECONF(crtc->config->cpu_transcoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13554 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 13555 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 13556 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 13557 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 13558 | if (crtc->active) { |
| 13559 | update_scanline_offset(crtc); |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 13560 | drm_crtc_vblank_on(&crtc->base); |
| 13561 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 13562 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13563 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13564 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 13565 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 13566 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13567 | struct intel_connector *connector; |
| 13568 | bool plane; |
| 13569 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13570 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 13571 | crtc->base.base.id); |
| 13572 | |
| 13573 | /* Pipe has the wrong plane attached and the plane is active. |
| 13574 | * Temporarily change the plane mapping and disable everything |
| 13575 | * ... */ |
| 13576 | plane = crtc->plane; |
| 13577 | crtc->plane = !plane; |
Daniel Vetter | 9c8958b | 2014-07-14 19:35:31 +0200 | [diff] [blame] | 13578 | crtc->primary_enabled = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13579 | dev_priv->display.crtc_disable(&crtc->base); |
| 13580 | crtc->plane = plane; |
| 13581 | |
| 13582 | /* ... and break all links. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13583 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13584 | if (connector->encoder->base.crtc != &crtc->base) |
| 13585 | continue; |
| 13586 | |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13587 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 13588 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13589 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13590 | /* multiple connectors may have the same encoder: |
| 13591 | * handle them and break crtc link separately */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13592 | for_each_intel_connector(dev, connector) |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13593 | if (connector->encoder->base.crtc == &crtc->base) { |
| 13594 | connector->encoder->base.crtc = NULL; |
| 13595 | connector->encoder->connectors_active = false; |
| 13596 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13597 | |
| 13598 | WARN_ON(crtc->active); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 13599 | crtc->base.state->enable = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13600 | crtc->base.enabled = false; |
| 13601 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13602 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13603 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 13604 | crtc->pipe == PIPE_A && !crtc->active) { |
| 13605 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 13606 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 13607 | * call below we restore the pipe to the right state, but leave |
| 13608 | * the required bits on. */ |
| 13609 | intel_enable_pipe_a(dev); |
| 13610 | } |
| 13611 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13612 | /* Adjust the state of the output pipe according to whether we |
| 13613 | * have active connectors/encoders. */ |
| 13614 | intel_crtc_update_dpms(&crtc->base); |
| 13615 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 13616 | if (crtc->active != crtc->base.state->enable) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13617 | struct intel_encoder *encoder; |
| 13618 | |
| 13619 | /* This can happen either due to bugs in the get_hw_state |
| 13620 | * functions or because the pipe is force-enabled due to the |
| 13621 | * pipe A quirk. */ |
| 13622 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", |
| 13623 | crtc->base.base.id, |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 13624 | crtc->base.state->enable ? "enabled" : "disabled", |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13625 | crtc->active ? "enabled" : "disabled"); |
| 13626 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 13627 | crtc->base.state->enable = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13628 | crtc->base.enabled = crtc->active; |
| 13629 | |
| 13630 | /* Because we only establish the connector -> encoder -> |
| 13631 | * crtc links if something is active, this means the |
| 13632 | * crtc is now deactivated. Break the links. connector |
| 13633 | * -> encoder links are only establish when things are |
| 13634 | * actually up, hence no need to break them. */ |
| 13635 | WARN_ON(crtc->active); |
| 13636 | |
| 13637 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
| 13638 | WARN_ON(encoder->connectors_active); |
| 13639 | encoder->base.crtc = NULL; |
| 13640 | } |
| 13641 | } |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 13642 | |
Ville Syrjälä | a3ed6aa | 2014-09-03 14:09:52 +0300 | [diff] [blame] | 13643 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 13644 | /* |
| 13645 | * We start out with underrun reporting disabled to avoid races. |
| 13646 | * For correct bookkeeping mark this on active crtcs. |
| 13647 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 13648 | * Also on gmch platforms we dont have any hardware bits to |
| 13649 | * disable the underrun reporting. Which means we need to start |
| 13650 | * out with underrun reporting disabled also on inactive pipes, |
| 13651 | * since otherwise we'll complain about the garbage we read when |
| 13652 | * e.g. coming up after runtime pm. |
| 13653 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 13654 | * No protection against concurrent access is required - at |
| 13655 | * worst a fifo underrun happens which also sets this to false. |
| 13656 | */ |
| 13657 | crtc->cpu_fifo_underrun_disabled = true; |
| 13658 | crtc->pch_fifo_underrun_disabled = true; |
| 13659 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13660 | } |
| 13661 | |
| 13662 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 13663 | { |
| 13664 | struct intel_connector *connector; |
| 13665 | struct drm_device *dev = encoder->base.dev; |
| 13666 | |
| 13667 | /* We need to check both for a crtc link (meaning that the |
| 13668 | * encoder is active and trying to read from a pipe) and the |
| 13669 | * pipe itself being active. */ |
| 13670 | bool has_active_crtc = encoder->base.crtc && |
| 13671 | to_intel_crtc(encoder->base.crtc)->active; |
| 13672 | |
| 13673 | if (encoder->connectors_active && !has_active_crtc) { |
| 13674 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 13675 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13676 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13677 | |
| 13678 | /* Connector is active, but has no active pipe. This is |
| 13679 | * fallout from our resume register restoring. Disable |
| 13680 | * the encoder manually again. */ |
| 13681 | if (encoder->base.crtc) { |
| 13682 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 13683 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13684 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13685 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 13686 | if (encoder->post_disable) |
| 13687 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13688 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13689 | encoder->base.crtc = NULL; |
| 13690 | encoder->connectors_active = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13691 | |
| 13692 | /* Inconsistent output/port/pipe state happens presumably due to |
| 13693 | * a bug in one of the get_hw_state functions. Or someplace else |
| 13694 | * in our code, like the register restore mess on resume. Clamp |
| 13695 | * things to off as a safer default. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13696 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13697 | if (connector->encoder != encoder) |
| 13698 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13699 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 13700 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13701 | } |
| 13702 | } |
| 13703 | /* Enabled encoders without active connectors will be fixed in |
| 13704 | * the crtc fixup. */ |
| 13705 | } |
| 13706 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13707 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 13708 | { |
| 13709 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 13710 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 13711 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13712 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 13713 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 13714 | i915_disable_vga(dev); |
| 13715 | } |
| 13716 | } |
| 13717 | |
| 13718 | void i915_redisable_vga(struct drm_device *dev) |
| 13719 | { |
| 13720 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13721 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 13722 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 13723 | * at a very early point in our resume sequence, where the power well |
| 13724 | * structures are not yet restored. Since this function is at a very |
| 13725 | * paranoid "someone might have enabled VGA while we were not looking" |
| 13726 | * level, just check if the power well is enabled instead of trying to |
| 13727 | * follow the "don't touch the power well if we don't need it" policy |
| 13728 | * the rest of the driver uses. */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 13729 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 13730 | return; |
| 13731 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 13732 | i915_redisable_vga_power_on(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 13733 | } |
| 13734 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 13735 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
| 13736 | { |
| 13737 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 13738 | |
| 13739 | if (!crtc->active) |
| 13740 | return false; |
| 13741 | |
| 13742 | return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE; |
| 13743 | } |
| 13744 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13745 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13746 | { |
| 13747 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13748 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13749 | struct intel_crtc *crtc; |
| 13750 | struct intel_encoder *encoder; |
| 13751 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13752 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13753 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13754 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 13755 | memset(crtc->config, 0, sizeof(*crtc->config)); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 13756 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 13757 | crtc->config->quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE; |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 13758 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13759 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 13760 | crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13761 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 13762 | crtc->base.state->enable = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13763 | crtc->base.enabled = crtc->active; |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 13764 | crtc->primary_enabled = primary_get_hw_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13765 | |
| 13766 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 13767 | crtc->base.base.id, |
| 13768 | crtc->active ? "enabled" : "disabled"); |
| 13769 | } |
| 13770 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13771 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 13772 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 13773 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 13774 | pll->on = pll->get_hw_state(dev_priv, pll, |
| 13775 | &pll->config.hw_state); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13776 | pll->active = 0; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 13777 | pll->config.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13778 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 13779 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13780 | pll->active++; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 13781 | pll->config.crtc_mask |= 1 << crtc->pipe; |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 13782 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13783 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13784 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 13785 | DRM_DEBUG_KMS("%s hw state readout: crtc_mask 0x%08x, on %i\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 13786 | pll->name, pll->config.crtc_mask, pll->on); |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 13787 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 13788 | if (pll->config.crtc_mask) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 13789 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 13790 | } |
| 13791 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13792 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13793 | pipe = 0; |
| 13794 | |
| 13795 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 13796 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 13797 | encoder->base.crtc = &crtc->base; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 13798 | encoder->get_config(encoder, crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13799 | } else { |
| 13800 | encoder->base.crtc = NULL; |
| 13801 | } |
| 13802 | |
| 13803 | encoder->connectors_active = false; |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 13804 | 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] | 13805 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 13806 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13807 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 13808 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13809 | } |
| 13810 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13811 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13812 | if (connector->get_hw_state(connector)) { |
| 13813 | connector->base.dpms = DRM_MODE_DPMS_ON; |
| 13814 | connector->encoder->connectors_active = true; |
| 13815 | connector->base.encoder = &connector->encoder->base; |
| 13816 | } else { |
| 13817 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 13818 | connector->base.encoder = NULL; |
| 13819 | } |
| 13820 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 13821 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 13822 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13823 | connector->base.encoder ? "enabled" : "disabled"); |
| 13824 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13825 | } |
| 13826 | |
| 13827 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm |
| 13828 | * and i915 state tracking structures. */ |
| 13829 | void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 13830 | bool force_restore) |
| 13831 | { |
| 13832 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13833 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13834 | struct intel_crtc *crtc; |
| 13835 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 13836 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 13837 | |
| 13838 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13839 | |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 13840 | /* |
| 13841 | * Now that we have the config, copy it to each CRTC struct |
| 13842 | * Note that this could go away if we move to using crtc_config |
| 13843 | * checking everywhere. |
| 13844 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13845 | for_each_intel_crtc(dev, crtc) { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 13846 | if (crtc->active && i915.fastboot) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 13847 | intel_mode_from_pipe_config(&crtc->base.mode, |
| 13848 | crtc->config); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 13849 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
| 13850 | crtc->base.base.id); |
| 13851 | drm_mode_debug_printmodeline(&crtc->base.mode); |
| 13852 | } |
| 13853 | } |
| 13854 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13855 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13856 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13857 | intel_sanitize_encoder(encoder); |
| 13858 | } |
| 13859 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13860 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13861 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 13862 | intel_sanitize_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 13863 | intel_dump_pipe_config(crtc, crtc->config, |
| 13864 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13865 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 13866 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 13867 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 13868 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 13869 | |
| 13870 | if (!pll->on || pll->active) |
| 13871 | continue; |
| 13872 | |
| 13873 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 13874 | |
| 13875 | pll->disable(dev_priv, pll); |
| 13876 | pll->on = false; |
| 13877 | } |
| 13878 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 13879 | if (IS_GEN9(dev)) |
| 13880 | skl_wm_get_hw_state(dev); |
| 13881 | else if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 13882 | ilk_wm_get_hw_state(dev); |
| 13883 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 13884 | if (force_restore) { |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 13885 | i915_redisable_vga(dev); |
| 13886 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13887 | /* |
| 13888 | * We need to use raw interfaces for restoring state to avoid |
| 13889 | * checking (bogus) intermediate states. |
| 13890 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13891 | for_each_pipe(dev_priv, pipe) { |
Jesse Barnes | b5644d0 | 2013-03-26 13:25:27 -0700 | [diff] [blame] | 13892 | struct drm_crtc *crtc = |
| 13893 | dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 13894 | |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 13895 | intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, |
| 13896 | crtc->primary->fb); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 13897 | } |
| 13898 | } else { |
| 13899 | intel_modeset_update_staged_output_state(dev); |
| 13900 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 13901 | |
| 13902 | intel_modeset_check_state(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 13903 | } |
| 13904 | |
| 13905 | void intel_modeset_gem_init(struct drm_device *dev) |
| 13906 | { |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 13907 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13908 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 13909 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13910 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 13911 | mutex_lock(&dev->struct_mutex); |
| 13912 | intel_init_gt_powersave(dev); |
| 13913 | mutex_unlock(&dev->struct_mutex); |
| 13914 | |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 13915 | /* |
| 13916 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 13917 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 13918 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 13919 | * indicates as much. |
| 13920 | */ |
| 13921 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 13922 | dev_priv->vbt.lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 13923 | DREF_SSC1_ENABLE); |
| 13924 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 13925 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 13926 | |
| 13927 | intel_setup_overlay(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13928 | |
| 13929 | /* |
| 13930 | * Make sure any fbs we allocated at startup are properly |
| 13931 | * pinned & fenced. When we do the allocation it's too early |
| 13932 | * for this. |
| 13933 | */ |
| 13934 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 13935 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 13936 | obj = intel_fb_obj(c->primary->fb); |
| 13937 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13938 | continue; |
| 13939 | |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 13940 | if (intel_pin_and_fence_fb_obj(c->primary, |
| 13941 | c->primary->fb, |
| 13942 | NULL)) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13943 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 13944 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 13945 | drm_framebuffer_unreference(c->primary->fb); |
| 13946 | c->primary->fb = NULL; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 13947 | update_state_fb(c->primary); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 13948 | } |
| 13949 | } |
| 13950 | mutex_unlock(&dev->struct_mutex); |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 13951 | |
| 13952 | intel_backlight_register(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13953 | } |
| 13954 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 13955 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 13956 | { |
| 13957 | struct drm_connector *connector = &intel_connector->base; |
| 13958 | |
| 13959 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 13960 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 13961 | } |
| 13962 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13963 | void intel_modeset_cleanup(struct drm_device *dev) |
| 13964 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13965 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 13966 | struct drm_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13967 | |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 13968 | intel_disable_gt_powersave(dev); |
| 13969 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 13970 | intel_backlight_unregister(dev); |
| 13971 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13972 | /* |
| 13973 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 13974 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13975 | * experience fancy races otherwise. |
| 13976 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 13977 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 13978 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13979 | /* |
| 13980 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 13981 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 13982 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 13983 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 13984 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13985 | mutex_lock(&dev->struct_mutex); |
| 13986 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 13987 | intel_unregister_dsm_handler(); |
| 13988 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 13989 | intel_fbc_disable(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13990 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 13991 | mutex_unlock(&dev->struct_mutex); |
| 13992 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 13993 | /* flush any delayed tasks or pending work */ |
| 13994 | flush_scheduled_work(); |
| 13995 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 13996 | /* destroy the backlight and sysfs files before encoders/connectors */ |
| 13997 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 13998 | struct intel_connector *intel_connector; |
| 13999 | |
| 14000 | intel_connector = to_intel_connector(connector); |
| 14001 | intel_connector->unregister(intel_connector); |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 14002 | } |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 14003 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14004 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 14005 | |
| 14006 | intel_cleanup_overlay(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 14007 | |
| 14008 | mutex_lock(&dev->struct_mutex); |
| 14009 | intel_cleanup_gt_powersave(dev); |
| 14010 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14011 | } |
| 14012 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14013 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 14014 | * Return which encoder is currently attached for connector. |
| 14015 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 14016 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14017 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 14018 | return &intel_attached_encoder(connector)->base; |
| 14019 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14020 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 14021 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 14022 | struct intel_encoder *encoder) |
| 14023 | { |
| 14024 | connector->encoder = encoder; |
| 14025 | drm_mode_connector_attach_encoder(&connector->base, |
| 14026 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14027 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14028 | |
| 14029 | /* |
| 14030 | * set vga decode state - true == enable VGA decode |
| 14031 | */ |
| 14032 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 14033 | { |
| 14034 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 14035 | 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] | 14036 | u16 gmch_ctrl; |
| 14037 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 14038 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 14039 | DRM_ERROR("failed to read control word\n"); |
| 14040 | return -EIO; |
| 14041 | } |
| 14042 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 14043 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 14044 | return 0; |
| 14045 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14046 | if (state) |
| 14047 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 14048 | else |
| 14049 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 14050 | |
| 14051 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 14052 | DRM_ERROR("failed to write control word\n"); |
| 14053 | return -EIO; |
| 14054 | } |
| 14055 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14056 | return 0; |
| 14057 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14058 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14059 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 14060 | |
| 14061 | u32 power_well_driver; |
| 14062 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14063 | int num_transcoders; |
| 14064 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14065 | struct intel_cursor_error_state { |
| 14066 | u32 control; |
| 14067 | u32 position; |
| 14068 | u32 base; |
| 14069 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 14070 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14071 | |
| 14072 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14073 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14074 | u32 source; |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14075 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 14076 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14077 | |
| 14078 | struct intel_plane_error_state { |
| 14079 | u32 control; |
| 14080 | u32 stride; |
| 14081 | u32 size; |
| 14082 | u32 pos; |
| 14083 | u32 addr; |
| 14084 | u32 surface; |
| 14085 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 14086 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14087 | |
| 14088 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14089 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14090 | enum transcoder cpu_transcoder; |
| 14091 | |
| 14092 | u32 conf; |
| 14093 | |
| 14094 | u32 htotal; |
| 14095 | u32 hblank; |
| 14096 | u32 hsync; |
| 14097 | u32 vtotal; |
| 14098 | u32 vblank; |
| 14099 | u32 vsync; |
| 14100 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14101 | }; |
| 14102 | |
| 14103 | struct intel_display_error_state * |
| 14104 | intel_display_capture_error_state(struct drm_device *dev) |
| 14105 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 14106 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14107 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14108 | int transcoders[] = { |
| 14109 | TRANSCODER_A, |
| 14110 | TRANSCODER_B, |
| 14111 | TRANSCODER_C, |
| 14112 | TRANSCODER_EDP, |
| 14113 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14114 | int i; |
| 14115 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14116 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 14117 | return NULL; |
| 14118 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 14119 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14120 | if (error == NULL) |
| 14121 | return NULL; |
| 14122 | |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 14123 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 14124 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 14125 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14126 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14127 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14128 | __intel_display_power_is_enabled(dev_priv, |
| 14129 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14130 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 14131 | continue; |
| 14132 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 14133 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 14134 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 14135 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14136 | |
| 14137 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 14138 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14139 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 14140 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14141 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 14142 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 14143 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 14144 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14145 | if (INTEL_INFO(dev)->gen >= 4) { |
| 14146 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 14147 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 14148 | } |
| 14149 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14150 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14151 | |
Sonika Jindal | 3abfce7 | 2014-07-21 15:23:43 +0530 | [diff] [blame] | 14152 | if (HAS_GMCH_DISPLAY(dev)) |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14153 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14154 | } |
| 14155 | |
| 14156 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; |
| 14157 | if (HAS_DDI(dev_priv->dev)) |
| 14158 | error->num_transcoders++; /* Account for eDP. */ |
| 14159 | |
| 14160 | for (i = 0; i < error->num_transcoders; i++) { |
| 14161 | enum transcoder cpu_transcoder = transcoders[i]; |
| 14162 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14163 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14164 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 14165 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14166 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 14167 | continue; |
| 14168 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14169 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 14170 | |
| 14171 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 14172 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 14173 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 14174 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 14175 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 14176 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 14177 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14178 | } |
| 14179 | |
| 14180 | return error; |
| 14181 | } |
| 14182 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14183 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 14184 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14185 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14186 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14187 | struct drm_device *dev, |
| 14188 | struct intel_display_error_state *error) |
| 14189 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14190 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14191 | int i; |
| 14192 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14193 | if (!error) |
| 14194 | return; |
| 14195 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14196 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 14197 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14198 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 14199 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14200 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14201 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14202 | err_printf(m, " Power: %s\n", |
| 14203 | error->pipe[i].power_domain_on ? "on" : "off"); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14204 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e1 | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14205 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14206 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14207 | err_printf(m, "Plane [%d]:\n", i); |
| 14208 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 14209 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14210 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14211 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 14212 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14213 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 14214 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14215 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14216 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14217 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 14218 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14219 | } |
| 14220 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14221 | err_printf(m, "Cursor [%d]:\n", i); |
| 14222 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 14223 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 14224 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14225 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14226 | |
| 14227 | for (i = 0; i < error->num_transcoders; i++) { |
Chris Wilson | 1cf84bb | 2013-10-21 09:10:33 +0100 | [diff] [blame] | 14228 | err_printf(m, "CPU transcoder: %c\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14229 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14230 | err_printf(m, " Power: %s\n", |
| 14231 | error->transcoder[i].power_domain_on ? "on" : "off"); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14232 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 14233 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 14234 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 14235 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 14236 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 14237 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 14238 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 14239 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14240 | } |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14241 | |
| 14242 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) |
| 14243 | { |
| 14244 | struct intel_crtc *crtc; |
| 14245 | |
| 14246 | for_each_intel_crtc(dev, crtc) { |
| 14247 | struct intel_unpin_work *work; |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14248 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 14249 | spin_lock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14250 | |
| 14251 | work = crtc->unpin_work; |
| 14252 | |
| 14253 | if (work && work->event && |
| 14254 | work->event->base.file_priv == file) { |
| 14255 | kfree(work->event); |
| 14256 | work->event = NULL; |
| 14257 | } |
| 14258 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 14259 | spin_unlock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14260 | } |
| 14261 | } |