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, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 86 | int x, int y, struct drm_framebuffer *old_fb, |
| 87 | struct drm_atomic_state *state); |
Jesse Barnes | eb1bfe8 | 2014-02-12 12:26:25 -0800 | [diff] [blame] | 88 | static int intel_framebuffer_init(struct drm_device *dev, |
| 89 | struct intel_framebuffer *ifb, |
| 90 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 91 | struct drm_i915_gem_object *obj); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 92 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc); |
| 93 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 94 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 95 | struct intel_link_m_n *m_n, |
| 96 | struct intel_link_m_n *m2_n2); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 97 | static void ironlake_set_pipeconf(struct drm_crtc *crtc); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 98 | static void haswell_set_pipeconf(struct drm_crtc *crtc); |
| 99 | static void intel_set_pipe_csc(struct drm_crtc *crtc); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 100 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 101 | const struct intel_crtc_state *pipe_config); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 102 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 103 | const struct intel_crtc_state *pipe_config); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 104 | static void intel_begin_crtc_commit(struct drm_crtc *crtc); |
| 105 | static void intel_finish_crtc_commit(struct drm_crtc *crtc); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 106 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 107 | static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe) |
| 108 | { |
| 109 | if (!connector->mst_port) |
| 110 | return connector->encoder; |
| 111 | else |
| 112 | return &connector->mst_port->mst_encoders[pipe]->base; |
| 113 | } |
| 114 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 115 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 116 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 117 | } intel_range_t; |
| 118 | |
| 119 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 120 | int dot_limit; |
| 121 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 122 | } intel_p2_t; |
| 123 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 124 | typedef struct intel_limit intel_limit_t; |
| 125 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 126 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 127 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 128 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 129 | |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 130 | int |
| 131 | intel_pch_rawclk(struct drm_device *dev) |
| 132 | { |
| 133 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 134 | |
| 135 | WARN_ON(!HAS_PCH_SPLIT(dev)); |
| 136 | |
| 137 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; |
| 138 | } |
| 139 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 140 | static inline u32 /* units of 100MHz */ |
| 141 | intel_fdi_link_freq(struct drm_device *dev) |
| 142 | { |
Chris Wilson | 8b99e68 | 2010-10-13 09:59:17 +0100 | [diff] [blame] | 143 | if (IS_GEN5(dev)) { |
| 144 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 145 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; |
| 146 | } else |
| 147 | return 27; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 150 | static const intel_limit_t intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 151 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 152 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 153 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 154 | .m = { .min = 96, .max = 140 }, |
| 155 | .m1 = { .min = 18, .max = 26 }, |
| 156 | .m2 = { .min = 6, .max = 16 }, |
| 157 | .p = { .min = 4, .max = 128 }, |
| 158 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 159 | .p2 = { .dot_limit = 165000, |
| 160 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 161 | }; |
| 162 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 163 | static const intel_limit_t intel_limits_i8xx_dvo = { |
| 164 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 165 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 166 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 167 | .m = { .min = 96, .max = 140 }, |
| 168 | .m1 = { .min = 18, .max = 26 }, |
| 169 | .m2 = { .min = 6, .max = 16 }, |
| 170 | .p = { .min = 4, .max = 128 }, |
| 171 | .p1 = { .min = 2, .max = 33 }, |
| 172 | .p2 = { .dot_limit = 165000, |
| 173 | .p2_slow = 4, .p2_fast = 4 }, |
| 174 | }; |
| 175 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 176 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 177 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 178 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 179 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 180 | .m = { .min = 96, .max = 140 }, |
| 181 | .m1 = { .min = 18, .max = 26 }, |
| 182 | .m2 = { .min = 6, .max = 16 }, |
| 183 | .p = { .min = 4, .max = 128 }, |
| 184 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 185 | .p2 = { .dot_limit = 165000, |
| 186 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 187 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 188 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 189 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 190 | .dot = { .min = 20000, .max = 400000 }, |
| 191 | .vco = { .min = 1400000, .max = 2800000 }, |
| 192 | .n = { .min = 1, .max = 6 }, |
| 193 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 194 | .m1 = { .min = 8, .max = 18 }, |
| 195 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 196 | .p = { .min = 5, .max = 80 }, |
| 197 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 198 | .p2 = { .dot_limit = 200000, |
| 199 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 203 | .dot = { .min = 20000, .max = 400000 }, |
| 204 | .vco = { .min = 1400000, .max = 2800000 }, |
| 205 | .n = { .min = 1, .max = 6 }, |
| 206 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 207 | .m1 = { .min = 8, .max = 18 }, |
| 208 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 209 | .p = { .min = 7, .max = 98 }, |
| 210 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 211 | .p2 = { .dot_limit = 112000, |
| 212 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 213 | }; |
| 214 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 215 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 216 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 217 | .dot = { .min = 25000, .max = 270000 }, |
| 218 | .vco = { .min = 1750000, .max = 3500000}, |
| 219 | .n = { .min = 1, .max = 4 }, |
| 220 | .m = { .min = 104, .max = 138 }, |
| 221 | .m1 = { .min = 17, .max = 23 }, |
| 222 | .m2 = { .min = 5, .max = 11 }, |
| 223 | .p = { .min = 10, .max = 30 }, |
| 224 | .p1 = { .min = 1, .max = 3}, |
| 225 | .p2 = { .dot_limit = 270000, |
| 226 | .p2_slow = 10, |
| 227 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 228 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 229 | }; |
| 230 | |
| 231 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 232 | .dot = { .min = 22000, .max = 400000 }, |
| 233 | .vco = { .min = 1750000, .max = 3500000}, |
| 234 | .n = { .min = 1, .max = 4 }, |
| 235 | .m = { .min = 104, .max = 138 }, |
| 236 | .m1 = { .min = 16, .max = 23 }, |
| 237 | .m2 = { .min = 5, .max = 11 }, |
| 238 | .p = { .min = 5, .max = 80 }, |
| 239 | .p1 = { .min = 1, .max = 8}, |
| 240 | .p2 = { .dot_limit = 165000, |
| 241 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 245 | .dot = { .min = 20000, .max = 115000 }, |
| 246 | .vco = { .min = 1750000, .max = 3500000 }, |
| 247 | .n = { .min = 1, .max = 3 }, |
| 248 | .m = { .min = 104, .max = 138 }, |
| 249 | .m1 = { .min = 17, .max = 23 }, |
| 250 | .m2 = { .min = 5, .max = 11 }, |
| 251 | .p = { .min = 28, .max = 112 }, |
| 252 | .p1 = { .min = 2, .max = 8 }, |
| 253 | .p2 = { .dot_limit = 0, |
| 254 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 255 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 256 | }; |
| 257 | |
| 258 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 259 | .dot = { .min = 80000, .max = 224000 }, |
| 260 | .vco = { .min = 1750000, .max = 3500000 }, |
| 261 | .n = { .min = 1, .max = 3 }, |
| 262 | .m = { .min = 104, .max = 138 }, |
| 263 | .m1 = { .min = 17, .max = 23 }, |
| 264 | .m2 = { .min = 5, .max = 11 }, |
| 265 | .p = { .min = 14, .max = 42 }, |
| 266 | .p1 = { .min = 2, .max = 6 }, |
| 267 | .p2 = { .dot_limit = 0, |
| 268 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 269 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 270 | }; |
| 271 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 272 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 273 | .dot = { .min = 20000, .max = 400000}, |
| 274 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 275 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 276 | .n = { .min = 3, .max = 6 }, |
| 277 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 278 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 279 | .m1 = { .min = 0, .max = 0 }, |
| 280 | .m2 = { .min = 0, .max = 254 }, |
| 281 | .p = { .min = 5, .max = 80 }, |
| 282 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 283 | .p2 = { .dot_limit = 200000, |
| 284 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 285 | }; |
| 286 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 287 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 288 | .dot = { .min = 20000, .max = 400000 }, |
| 289 | .vco = { .min = 1700000, .max = 3500000 }, |
| 290 | .n = { .min = 3, .max = 6 }, |
| 291 | .m = { .min = 2, .max = 256 }, |
| 292 | .m1 = { .min = 0, .max = 0 }, |
| 293 | .m2 = { .min = 0, .max = 254 }, |
| 294 | .p = { .min = 7, .max = 112 }, |
| 295 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 296 | .p2 = { .dot_limit = 112000, |
| 297 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 298 | }; |
| 299 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 300 | /* Ironlake / Sandybridge |
| 301 | * |
| 302 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 303 | * the range value for them is (actual_value - 2). |
| 304 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 305 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 306 | .dot = { .min = 25000, .max = 350000 }, |
| 307 | .vco = { .min = 1760000, .max = 3510000 }, |
| 308 | .n = { .min = 1, .max = 5 }, |
| 309 | .m = { .min = 79, .max = 127 }, |
| 310 | .m1 = { .min = 12, .max = 22 }, |
| 311 | .m2 = { .min = 5, .max = 9 }, |
| 312 | .p = { .min = 5, .max = 80 }, |
| 313 | .p1 = { .min = 1, .max = 8 }, |
| 314 | .p2 = { .dot_limit = 225000, |
| 315 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 316 | }; |
| 317 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 318 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 319 | .dot = { .min = 25000, .max = 350000 }, |
| 320 | .vco = { .min = 1760000, .max = 3510000 }, |
| 321 | .n = { .min = 1, .max = 3 }, |
| 322 | .m = { .min = 79, .max = 118 }, |
| 323 | .m1 = { .min = 12, .max = 22 }, |
| 324 | .m2 = { .min = 5, .max = 9 }, |
| 325 | .p = { .min = 28, .max = 112 }, |
| 326 | .p1 = { .min = 2, .max = 8 }, |
| 327 | .p2 = { .dot_limit = 225000, |
| 328 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 329 | }; |
| 330 | |
| 331 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 332 | .dot = { .min = 25000, .max = 350000 }, |
| 333 | .vco = { .min = 1760000, .max = 3510000 }, |
| 334 | .n = { .min = 1, .max = 3 }, |
| 335 | .m = { .min = 79, .max = 127 }, |
| 336 | .m1 = { .min = 12, .max = 22 }, |
| 337 | .m2 = { .min = 5, .max = 9 }, |
| 338 | .p = { .min = 14, .max = 56 }, |
| 339 | .p1 = { .min = 2, .max = 8 }, |
| 340 | .p2 = { .dot_limit = 225000, |
| 341 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 342 | }; |
| 343 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 344 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 345 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 346 | .dot = { .min = 25000, .max = 350000 }, |
| 347 | .vco = { .min = 1760000, .max = 3510000 }, |
| 348 | .n = { .min = 1, .max = 2 }, |
| 349 | .m = { .min = 79, .max = 126 }, |
| 350 | .m1 = { .min = 12, .max = 22 }, |
| 351 | .m2 = { .min = 5, .max = 9 }, |
| 352 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 353 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 354 | .p2 = { .dot_limit = 225000, |
| 355 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 356 | }; |
| 357 | |
| 358 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 359 | .dot = { .min = 25000, .max = 350000 }, |
| 360 | .vco = { .min = 1760000, .max = 3510000 }, |
| 361 | .n = { .min = 1, .max = 3 }, |
| 362 | .m = { .min = 79, .max = 126 }, |
| 363 | .m1 = { .min = 12, .max = 22 }, |
| 364 | .m2 = { .min = 5, .max = 9 }, |
| 365 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 366 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 367 | .p2 = { .dot_limit = 225000, |
| 368 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 369 | }; |
| 370 | |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 371 | static const intel_limit_t intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 372 | /* |
| 373 | * These are the data rate limits (measured in fast clocks) |
| 374 | * since those are the strictest limits we have. The fast |
| 375 | * clock and actual rate limits are more relaxed, so checking |
| 376 | * them would make no difference. |
| 377 | */ |
| 378 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 379 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 380 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 381 | .m1 = { .min = 2, .max = 3 }, |
| 382 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 383 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 384 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 385 | }; |
| 386 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 387 | static const intel_limit_t intel_limits_chv = { |
| 388 | /* |
| 389 | * These are the data rate limits (measured in fast clocks) |
| 390 | * since those are the strictest limits we have. The fast |
| 391 | * clock and actual rate limits are more relaxed, so checking |
| 392 | * them would make no difference. |
| 393 | */ |
| 394 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 395 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 396 | .n = { .min = 1, .max = 1 }, |
| 397 | .m1 = { .min = 2, .max = 2 }, |
| 398 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 399 | .p1 = { .min = 2, .max = 4 }, |
| 400 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 401 | }; |
| 402 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 403 | static void vlv_clock(int refclk, intel_clock_t *clock) |
| 404 | { |
| 405 | clock->m = clock->m1 * clock->m2; |
| 406 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 407 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 408 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 409 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 410 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 411 | } |
| 412 | |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 413 | /** |
| 414 | * Returns whether any output on the specified pipe is of the specified type |
| 415 | */ |
Damien Lespiau | 4093561 | 2014-10-29 11:16:59 +0000 | [diff] [blame] | 416 | 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] | 417 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 418 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 419 | struct intel_encoder *encoder; |
| 420 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 421 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 422 | if (encoder->type == type) |
| 423 | return true; |
| 424 | |
| 425 | return false; |
| 426 | } |
| 427 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 428 | /** |
| 429 | * Returns whether any output on the specified pipe will have the specified |
| 430 | * type after a staged modeset is complete, i.e., the same as |
| 431 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of |
| 432 | * encoder->crtc. |
| 433 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 434 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
| 435 | int type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 436 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 437 | struct drm_atomic_state *state = crtc_state->base.state; |
| 438 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 439 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 440 | int i, num_connectors = 0; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 441 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 442 | for (i = 0; i < state->num_connector; i++) { |
| 443 | if (!state->connectors[i]) |
| 444 | continue; |
| 445 | |
| 446 | connector_state = state->connector_states[i]; |
| 447 | if (connector_state->crtc != crtc_state->base.crtc) |
| 448 | continue; |
| 449 | |
| 450 | num_connectors++; |
| 451 | |
| 452 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 453 | if (encoder->type == type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 454 | return true; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | WARN_ON(num_connectors == 0); |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 458 | |
| 459 | return false; |
| 460 | } |
| 461 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 462 | static const intel_limit_t * |
| 463 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 464 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 465 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 466 | const intel_limit_t *limit; |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 467 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 468 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 469 | if (intel_is_dual_link_lvds(dev)) { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 470 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 471 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 472 | else |
| 473 | limit = &intel_limits_ironlake_dual_lvds; |
| 474 | } else { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 475 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 476 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 477 | else |
| 478 | limit = &intel_limits_ironlake_single_lvds; |
| 479 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 480 | } else |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 481 | limit = &intel_limits_ironlake_dac; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 482 | |
| 483 | return limit; |
| 484 | } |
| 485 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 486 | static const intel_limit_t * |
| 487 | intel_g4x_limit(struct intel_crtc_state *crtc_state) |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 488 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 489 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 490 | const intel_limit_t *limit; |
| 491 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 492 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 493 | if (intel_is_dual_link_lvds(dev)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 494 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 495 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 496 | limit = &intel_limits_g4x_single_channel_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 497 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 498 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 499 | limit = &intel_limits_g4x_hdmi; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 500 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 501 | limit = &intel_limits_g4x_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 502 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 503 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 504 | |
| 505 | return limit; |
| 506 | } |
| 507 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 508 | static const intel_limit_t * |
| 509 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 510 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 511 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 512 | const intel_limit_t *limit; |
| 513 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 514 | if (HAS_PCH_SPLIT(dev)) |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 515 | limit = intel_ironlake_limit(crtc_state, refclk); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 516 | else if (IS_G4X(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 517 | limit = intel_g4x_limit(crtc_state); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 518 | } else if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 519 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 520 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 521 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 522 | limit = &intel_limits_pineview_sdvo; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 523 | } else if (IS_CHERRYVIEW(dev)) { |
| 524 | limit = &intel_limits_chv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 525 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 526 | limit = &intel_limits_vlv; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 527 | } else if (!IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 528 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 529 | limit = &intel_limits_i9xx_lvds; |
| 530 | else |
| 531 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 532 | } else { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 533 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 534 | limit = &intel_limits_i8xx_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 535 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 536 | limit = &intel_limits_i8xx_dvo; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 537 | else |
| 538 | limit = &intel_limits_i8xx_dac; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 539 | } |
| 540 | return limit; |
| 541 | } |
| 542 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 543 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
| 544 | static void pineview_clock(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 545 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 546 | clock->m = clock->m2 + 2; |
| 547 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 548 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 549 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 550 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 551 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 552 | } |
| 553 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 554 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 555 | { |
| 556 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 557 | } |
| 558 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 559 | static void i9xx_clock(int refclk, intel_clock_t *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 560 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 561 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 562 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 563 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
| 564 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 565 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 566 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 567 | } |
| 568 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 569 | static void chv_clock(int refclk, intel_clock_t *clock) |
| 570 | { |
| 571 | clock->m = clock->m1 * clock->m2; |
| 572 | clock->p = clock->p1 * clock->p2; |
| 573 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 574 | return; |
| 575 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 576 | clock->n << 22); |
| 577 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
| 578 | } |
| 579 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 580 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 581 | /** |
| 582 | * Returns whether the given set of divisors are valid for a given refclk with |
| 583 | * the given connectors. |
| 584 | */ |
| 585 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 586 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 587 | const intel_limit_t *limit, |
| 588 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 589 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 590 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 591 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 592 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 593 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 594 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 595 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 596 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 597 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 598 | |
| 599 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev)) |
| 600 | if (clock->m1 <= clock->m2) |
| 601 | INTELPllInvalid("m1 <= m2\n"); |
| 602 | |
| 603 | if (!IS_VALLEYVIEW(dev)) { |
| 604 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 605 | INTELPllInvalid("p out of range\n"); |
| 606 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 607 | INTELPllInvalid("m out of range\n"); |
| 608 | } |
| 609 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 610 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 611 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 612 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 613 | * connector, etc., rather than just a single range. |
| 614 | */ |
| 615 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 616 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 617 | |
| 618 | return true; |
| 619 | } |
| 620 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 621 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 622 | i9xx_find_best_dpll(const intel_limit_t *limit, |
| 623 | struct intel_crtc_state *crtc_state, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 624 | int target, int refclk, intel_clock_t *match_clock, |
| 625 | intel_clock_t *best_clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 626 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 627 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 628 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 629 | intel_clock_t clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 630 | int err = target; |
| 631 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 632 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 633 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 634 | * For LVDS just rely on its current settings for dual-channel. |
| 635 | * We haven't figured out how to reliably set up different |
| 636 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 637 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 638 | if (intel_is_dual_link_lvds(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 639 | clock.p2 = limit->p2.p2_fast; |
| 640 | else |
| 641 | clock.p2 = limit->p2.p2_slow; |
| 642 | } else { |
| 643 | if (target < limit->p2.dot_limit) |
| 644 | clock.p2 = limit->p2.p2_slow; |
| 645 | else |
| 646 | clock.p2 = limit->p2.p2_fast; |
| 647 | } |
| 648 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 649 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 650 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 651 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 652 | clock.m1++) { |
| 653 | for (clock.m2 = limit->m2.min; |
| 654 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 655 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 656 | break; |
| 657 | for (clock.n = limit->n.min; |
| 658 | clock.n <= limit->n.max; clock.n++) { |
| 659 | for (clock.p1 = limit->p1.min; |
| 660 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 661 | int this_err; |
| 662 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 663 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 664 | if (!intel_PLL_is_valid(dev, limit, |
| 665 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 666 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 667 | if (match_clock && |
| 668 | clock.p != match_clock->p) |
| 669 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 670 | |
| 671 | this_err = abs(clock.dot - target); |
| 672 | if (this_err < err) { |
| 673 | *best_clock = clock; |
| 674 | err = this_err; |
| 675 | } |
| 676 | } |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | return (err != target); |
| 682 | } |
| 683 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 684 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 685 | pnv_find_best_dpll(const intel_limit_t *limit, |
| 686 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 687 | int target, int refclk, intel_clock_t *match_clock, |
| 688 | intel_clock_t *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 689 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 690 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 691 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 692 | intel_clock_t clock; |
| 693 | int err = target; |
| 694 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 695 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 696 | /* |
| 697 | * For LVDS just rely on its current settings for dual-channel. |
| 698 | * We haven't figured out how to reliably set up different |
| 699 | * single/dual channel state, if we even can. |
| 700 | */ |
| 701 | if (intel_is_dual_link_lvds(dev)) |
| 702 | clock.p2 = limit->p2.p2_fast; |
| 703 | else |
| 704 | clock.p2 = limit->p2.p2_slow; |
| 705 | } else { |
| 706 | if (target < limit->p2.dot_limit) |
| 707 | clock.p2 = limit->p2.p2_slow; |
| 708 | else |
| 709 | clock.p2 = limit->p2.p2_fast; |
| 710 | } |
| 711 | |
| 712 | memset(best_clock, 0, sizeof(*best_clock)); |
| 713 | |
| 714 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 715 | clock.m1++) { |
| 716 | for (clock.m2 = limit->m2.min; |
| 717 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 718 | for (clock.n = limit->n.min; |
| 719 | clock.n <= limit->n.max; clock.n++) { |
| 720 | for (clock.p1 = limit->p1.min; |
| 721 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 722 | int this_err; |
| 723 | |
| 724 | pineview_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 725 | if (!intel_PLL_is_valid(dev, limit, |
| 726 | &clock)) |
| 727 | continue; |
| 728 | if (match_clock && |
| 729 | clock.p != match_clock->p) |
| 730 | continue; |
| 731 | |
| 732 | this_err = abs(clock.dot - target); |
| 733 | if (this_err < err) { |
| 734 | *best_clock = clock; |
| 735 | err = this_err; |
| 736 | } |
| 737 | } |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | |
| 742 | return (err != target); |
| 743 | } |
| 744 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 745 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 746 | g4x_find_best_dpll(const intel_limit_t *limit, |
| 747 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 748 | int target, int refclk, intel_clock_t *match_clock, |
| 749 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 750 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 751 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 752 | struct drm_device *dev = crtc->base.dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 753 | intel_clock_t clock; |
| 754 | int max_n; |
| 755 | bool found; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 756 | /* approximately equals target * 0.00585 */ |
| 757 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 758 | found = false; |
| 759 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 760 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 761 | if (intel_is_dual_link_lvds(dev)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 762 | clock.p2 = limit->p2.p2_fast; |
| 763 | else |
| 764 | clock.p2 = limit->p2.p2_slow; |
| 765 | } else { |
| 766 | if (target < limit->p2.dot_limit) |
| 767 | clock.p2 = limit->p2.p2_slow; |
| 768 | else |
| 769 | clock.p2 = limit->p2.p2_fast; |
| 770 | } |
| 771 | |
| 772 | memset(best_clock, 0, sizeof(*best_clock)); |
| 773 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 774 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 775 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 776 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 777 | for (clock.m1 = limit->m1.max; |
| 778 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 779 | for (clock.m2 = limit->m2.max; |
| 780 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 781 | for (clock.p1 = limit->p1.max; |
| 782 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 783 | int this_err; |
| 784 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 785 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 786 | if (!intel_PLL_is_valid(dev, limit, |
| 787 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 788 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 789 | |
| 790 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 791 | if (this_err < err_most) { |
| 792 | *best_clock = clock; |
| 793 | err_most = this_err; |
| 794 | max_n = clock.n; |
| 795 | found = true; |
| 796 | } |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 801 | return found; |
| 802 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 803 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 804 | /* |
| 805 | * Check if the calculated PLL configuration is more optimal compared to the |
| 806 | * best configuration and error found so far. Return the calculated error. |
| 807 | */ |
| 808 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
| 809 | const intel_clock_t *calculated_clock, |
| 810 | const intel_clock_t *best_clock, |
| 811 | unsigned int best_error_ppm, |
| 812 | unsigned int *error_ppm) |
| 813 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 814 | /* |
| 815 | * For CHV ignore the error and consider only the P value. |
| 816 | * Prefer a bigger P value based on HW requirements. |
| 817 | */ |
| 818 | if (IS_CHERRYVIEW(dev)) { |
| 819 | *error_ppm = 0; |
| 820 | |
| 821 | return calculated_clock->p > best_clock->p; |
| 822 | } |
| 823 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 824 | if (WARN_ON_ONCE(!target_freq)) |
| 825 | return false; |
| 826 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 827 | *error_ppm = div_u64(1000000ULL * |
| 828 | abs(target_freq - calculated_clock->dot), |
| 829 | target_freq); |
| 830 | /* |
| 831 | * Prefer a better P value over a better (smaller) error if the error |
| 832 | * is small. Ensure this preference for future configurations too by |
| 833 | * setting the error to 0. |
| 834 | */ |
| 835 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 836 | *error_ppm = 0; |
| 837 | |
| 838 | return true; |
| 839 | } |
| 840 | |
| 841 | return *error_ppm + 10 < best_error_ppm; |
| 842 | } |
| 843 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 844 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 845 | vlv_find_best_dpll(const intel_limit_t *limit, |
| 846 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 847 | int target, int refclk, intel_clock_t *match_clock, |
| 848 | intel_clock_t *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 849 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 850 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 851 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 852 | intel_clock_t clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 853 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 854 | /* min update 19.2 MHz */ |
| 855 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 856 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 857 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 858 | target *= 5; /* fast clock */ |
| 859 | |
| 860 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 861 | |
| 862 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 863 | 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] | 864 | 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] | 865 | 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] | 866 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 867 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 868 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 869 | 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] | 870 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 871 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 872 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 873 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 874 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 875 | vlv_clock(refclk, &clock); |
| 876 | |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 877 | if (!intel_PLL_is_valid(dev, limit, |
| 878 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 879 | continue; |
| 880 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 881 | if (!vlv_PLL_is_optimal(dev, target, |
| 882 | &clock, |
| 883 | best_clock, |
| 884 | bestppm, &ppm)) |
| 885 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 886 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 887 | *best_clock = clock; |
| 888 | bestppm = ppm; |
| 889 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | } |
| 893 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 894 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 895 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 896 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 897 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 898 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 899 | chv_find_best_dpll(const intel_limit_t *limit, |
| 900 | struct intel_crtc_state *crtc_state, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 901 | int target, int refclk, intel_clock_t *match_clock, |
| 902 | intel_clock_t *best_clock) |
| 903 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 904 | struct intel_crtc *crtc = to_intel_crtc(crtc_state->base.crtc); |
Ander Conselvan de Oliveira | a919ff1 | 2014-10-20 13:46:43 +0300 | [diff] [blame] | 905 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 906 | unsigned int best_error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 907 | intel_clock_t clock; |
| 908 | uint64_t m2; |
| 909 | int found = false; |
| 910 | |
| 911 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 912 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 913 | |
| 914 | /* |
| 915 | * Based on hardware doc, the n always set to 1, and m1 always |
| 916 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 917 | * revisit this because n may not 1 anymore. |
| 918 | */ |
| 919 | clock.n = 1, clock.m1 = 2; |
| 920 | target *= 5; /* fast clock */ |
| 921 | |
| 922 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 923 | for (clock.p2 = limit->p2.p2_fast; |
| 924 | clock.p2 >= limit->p2.p2_slow; |
| 925 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 926 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 927 | |
| 928 | clock.p = clock.p1 * clock.p2; |
| 929 | |
| 930 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 931 | clock.n) << 22, refclk * clock.m1); |
| 932 | |
| 933 | if (m2 > INT_MAX/clock.m1) |
| 934 | continue; |
| 935 | |
| 936 | clock.m2 = m2; |
| 937 | |
| 938 | chv_clock(refclk, &clock); |
| 939 | |
| 940 | if (!intel_PLL_is_valid(dev, limit, &clock)) |
| 941 | continue; |
| 942 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 943 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 944 | best_error_ppm, &error_ppm)) |
| 945 | continue; |
| 946 | |
| 947 | *best_clock = clock; |
| 948 | best_error_ppm = error_ppm; |
| 949 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 950 | } |
| 951 | } |
| 952 | |
| 953 | return found; |
| 954 | } |
| 955 | |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 956 | bool intel_crtc_active(struct drm_crtc *crtc) |
| 957 | { |
| 958 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 959 | |
| 960 | /* Be paranoid as we can arrive here with only partial |
| 961 | * state retrieved from the hardware during setup. |
| 962 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 963 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 964 | * as Haswell has gained clock readout/fastboot support. |
| 965 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 966 | * 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] | 967 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 968 | * |
| 969 | * FIXME: The intel_crtc->active here should be switched to |
| 970 | * crtc->state->active once we have proper CRTC states wired up |
| 971 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 972 | */ |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 973 | return intel_crtc->active && crtc->primary->state->fb && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 974 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 975 | } |
| 976 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 977 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 978 | enum pipe pipe) |
| 979 | { |
| 980 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 981 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 982 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 983 | return intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 984 | } |
| 985 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 986 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 987 | { |
| 988 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 989 | u32 reg = PIPEDSL(pipe); |
| 990 | u32 line1, line2; |
| 991 | u32 line_mask; |
| 992 | |
| 993 | if (IS_GEN2(dev)) |
| 994 | line_mask = DSL_LINEMASK_GEN2; |
| 995 | else |
| 996 | line_mask = DSL_LINEMASK_GEN3; |
| 997 | |
| 998 | line1 = I915_READ(reg) & line_mask; |
| 999 | mdelay(5); |
| 1000 | line2 = I915_READ(reg) & line_mask; |
| 1001 | |
| 1002 | return line1 == line2; |
| 1003 | } |
| 1004 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1005 | /* |
| 1006 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1007 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1008 | * |
| 1009 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 1010 | * spinning on the vblank interrupt status bit, since we won't actually |
| 1011 | * see an interrupt when the pipe is disabled. |
| 1012 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1013 | * On Gen4 and above: |
| 1014 | * wait for the pipe register state bit to turn off |
| 1015 | * |
| 1016 | * Otherwise: |
| 1017 | * wait for the display line value to settle (it usually |
| 1018 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1019 | * |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1020 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1021 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1022 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1023 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1024 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1025 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1026 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1027 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1028 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1029 | int reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1030 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1031 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1032 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 1033 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1034 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1035 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1036 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1037 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1038 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1039 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1040 | } |
| 1041 | |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1042 | /* |
| 1043 | * ibx_digital_port_connected - is the specified port connected? |
| 1044 | * @dev_priv: i915 private structure |
| 1045 | * @port: the port to test |
| 1046 | * |
| 1047 | * Returns true if @port is connected, false otherwise. |
| 1048 | */ |
| 1049 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 1050 | struct intel_digital_port *port) |
| 1051 | { |
| 1052 | u32 bit; |
| 1053 | |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1054 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1055 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1056 | case PORT_B: |
| 1057 | bit = SDE_PORTB_HOTPLUG; |
| 1058 | break; |
| 1059 | case PORT_C: |
| 1060 | bit = SDE_PORTC_HOTPLUG; |
| 1061 | break; |
| 1062 | case PORT_D: |
| 1063 | bit = SDE_PORTD_HOTPLUG; |
| 1064 | break; |
| 1065 | default: |
| 1066 | return true; |
| 1067 | } |
| 1068 | } else { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1069 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1070 | case PORT_B: |
| 1071 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 1072 | break; |
| 1073 | case PORT_C: |
| 1074 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 1075 | break; |
| 1076 | case PORT_D: |
| 1077 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 1078 | break; |
| 1079 | default: |
| 1080 | return true; |
| 1081 | } |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | return I915_READ(SDEISR) & bit; |
| 1085 | } |
| 1086 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1087 | static const char *state_string(bool enabled) |
| 1088 | { |
| 1089 | return enabled ? "on" : "off"; |
| 1090 | } |
| 1091 | |
| 1092 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1093 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1094 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1095 | { |
| 1096 | int reg; |
| 1097 | u32 val; |
| 1098 | bool cur_state; |
| 1099 | |
| 1100 | reg = DPLL(pipe); |
| 1101 | val = I915_READ(reg); |
| 1102 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1103 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1104 | "PLL state assertion failure (expected %s, current %s)\n", |
| 1105 | state_string(state), state_string(cur_state)); |
| 1106 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1107 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1108 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
| 1109 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
| 1110 | { |
| 1111 | u32 val; |
| 1112 | bool cur_state; |
| 1113 | |
| 1114 | mutex_lock(&dev_priv->dpio_lock); |
| 1115 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
| 1116 | mutex_unlock(&dev_priv->dpio_lock); |
| 1117 | |
| 1118 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1119 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1120 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
| 1121 | state_string(state), state_string(cur_state)); |
| 1122 | } |
| 1123 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) |
| 1124 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) |
| 1125 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1126 | struct intel_shared_dpll * |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1127 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1128 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1129 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 1130 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1131 | if (crtc->config->shared_dpll < 0) |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1132 | return NULL; |
| 1133 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1134 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1135 | } |
| 1136 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1137 | /* For ILK+ */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1138 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
| 1139 | struct intel_shared_dpll *pll, |
| 1140 | bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1141 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1142 | bool cur_state; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1143 | struct intel_dpll_hw_state hw_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1144 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1145 | if (WARN (!pll, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1146 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1147 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1148 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1149 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1150 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1151 | "%s assertion failure (expected %s, current %s)\n", |
| 1152 | pll->name, state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1153 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1154 | |
| 1155 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1156 | enum pipe pipe, bool state) |
| 1157 | { |
| 1158 | int reg; |
| 1159 | u32 val; |
| 1160 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1161 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1162 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1163 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1164 | if (HAS_DDI(dev_priv->dev)) { |
| 1165 | /* DDI does not have a specific FDI_TX register */ |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1166 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1167 | val = I915_READ(reg); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1168 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1169 | } else { |
| 1170 | reg = FDI_TX_CTL(pipe); |
| 1171 | val = I915_READ(reg); |
| 1172 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1173 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1174 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1175 | "FDI TX state assertion failure (expected %s, current %s)\n", |
| 1176 | state_string(state), state_string(cur_state)); |
| 1177 | } |
| 1178 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1179 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1180 | |
| 1181 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1182 | enum pipe pipe, bool state) |
| 1183 | { |
| 1184 | int reg; |
| 1185 | u32 val; |
| 1186 | bool cur_state; |
| 1187 | |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1188 | reg = FDI_RX_CTL(pipe); |
| 1189 | val = I915_READ(reg); |
| 1190 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1191 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1192 | "FDI RX state assertion failure (expected %s, current %s)\n", |
| 1193 | state_string(state), state_string(cur_state)); |
| 1194 | } |
| 1195 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1196 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1197 | |
| 1198 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1199 | enum pipe pipe) |
| 1200 | { |
| 1201 | int reg; |
| 1202 | u32 val; |
| 1203 | |
| 1204 | /* ILK FDI PLL is always enabled */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1205 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1206 | return; |
| 1207 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1208 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1209 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1210 | return; |
| 1211 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1212 | reg = FDI_TX_CTL(pipe); |
| 1213 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1214 | 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] | 1215 | } |
| 1216 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1217 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1218 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1219 | { |
| 1220 | int reg; |
| 1221 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1222 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1223 | |
| 1224 | reg = FDI_RX_CTL(pipe); |
| 1225 | val = I915_READ(reg); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1226 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1227 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1228 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
| 1229 | state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1230 | } |
| 1231 | |
Daniel Vetter | b680c37 | 2014-09-19 18:27:27 +0200 | [diff] [blame] | 1232 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1233 | enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1234 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1235 | struct drm_device *dev = dev_priv->dev; |
| 1236 | int pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1237 | u32 val; |
| 1238 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1239 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1240 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1241 | if (WARN_ON(HAS_DDI(dev))) |
| 1242 | return; |
| 1243 | |
| 1244 | if (HAS_PCH_SPLIT(dev)) { |
| 1245 | u32 port_sel; |
| 1246 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1247 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1248 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1249 | |
| 1250 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1251 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1252 | panel_pipe = PIPE_B; |
| 1253 | /* XXX: else fix for eDP */ |
| 1254 | } else if (IS_VALLEYVIEW(dev)) { |
| 1255 | /* presumably write lock depends on pipe, not port select */ |
| 1256 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1257 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1258 | } else { |
| 1259 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1260 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1261 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | val = I915_READ(pp_reg); |
| 1265 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1266 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1267 | locked = false; |
| 1268 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1269 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1270 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1271 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1272 | } |
| 1273 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1274 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1275 | enum pipe pipe, bool state) |
| 1276 | { |
| 1277 | struct drm_device *dev = dev_priv->dev; |
| 1278 | bool cur_state; |
| 1279 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1280 | if (IS_845G(dev) || IS_I865G(dev)) |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1281 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1282 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1283 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1284 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1285 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1286 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
| 1287 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
| 1288 | } |
| 1289 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1290 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1291 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1292 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1293 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1294 | { |
| 1295 | int reg; |
| 1296 | u32 val; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1297 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1298 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1299 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1300 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1301 | /* if we need the pipe quirk it must be always on */ |
| 1302 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1303 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1304 | state = true; |
| 1305 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1306 | if (!intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 1307 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1308 | cur_state = false; |
| 1309 | } else { |
| 1310 | reg = PIPECONF(cpu_transcoder); |
| 1311 | val = I915_READ(reg); |
| 1312 | cur_state = !!(val & PIPECONF_ENABLE); |
| 1313 | } |
| 1314 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1315 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1316 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1317 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1318 | } |
| 1319 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1320 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1321 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1322 | { |
| 1323 | int reg; |
| 1324 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1325 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1326 | |
| 1327 | reg = DSPCNTR(plane); |
| 1328 | val = I915_READ(reg); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1329 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1330 | I915_STATE_WARN(cur_state != state, |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1331 | "plane %c assertion failure (expected %s, current %s)\n", |
| 1332 | plane_name(plane), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1333 | } |
| 1334 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1335 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1336 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1337 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1338 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1339 | enum pipe pipe) |
| 1340 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1341 | struct drm_device *dev = dev_priv->dev; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1342 | int reg, i; |
| 1343 | u32 val; |
| 1344 | int cur_pipe; |
| 1345 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1346 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1347 | if (INTEL_INFO(dev)->gen >= 4) { |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1348 | reg = DSPCNTR(pipe); |
| 1349 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1350 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1351 | "plane %c assertion failure, should be disabled but not\n", |
| 1352 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1353 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1354 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1355 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1356 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1357 | for_each_pipe(dev_priv, i) { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1358 | reg = DSPCNTR(i); |
| 1359 | val = I915_READ(reg); |
| 1360 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 1361 | DISPPLANE_SEL_PIPE_SHIFT; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1362 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1363 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1364 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1365 | } |
| 1366 | } |
| 1367 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1368 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1369 | enum pipe pipe) |
| 1370 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1371 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1372 | int reg, sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1373 | u32 val; |
| 1374 | |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1375 | if (INTEL_INFO(dev)->gen >= 9) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1376 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1377 | val = I915_READ(PLANE_CTL(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1378 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1379 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
| 1380 | sprite, pipe_name(pipe)); |
| 1381 | } |
| 1382 | } else if (IS_VALLEYVIEW(dev)) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1383 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1384 | reg = SPCNTR(pipe, sprite); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1385 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1386 | I915_STATE_WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1387 | "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] | 1388 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1389 | } |
| 1390 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 1391 | reg = SPRCTL(pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1392 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1393 | I915_STATE_WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1394 | "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] | 1395 | plane_name(pipe), pipe_name(pipe)); |
| 1396 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1397 | reg = DVSCNTR(pipe); |
| 1398 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1399 | I915_STATE_WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1400 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1401 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1402 | } |
| 1403 | } |
| 1404 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1405 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1406 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1407 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1408 | drm_crtc_vblank_put(crtc); |
| 1409 | } |
| 1410 | |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 1411 | 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] | 1412 | { |
| 1413 | u32 val; |
| 1414 | bool enabled; |
| 1415 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1416 | 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] | 1417 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1418 | val = I915_READ(PCH_DREF_CONTROL); |
| 1419 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | |
| 1420 | DREF_SUPERSPREAD_SOURCE_MASK)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1421 | 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] | 1422 | } |
| 1423 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1424 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1425 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1426 | { |
| 1427 | int reg; |
| 1428 | u32 val; |
| 1429 | bool enabled; |
| 1430 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1431 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1432 | val = I915_READ(reg); |
| 1433 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1434 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1435 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1436 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1437 | } |
| 1438 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1439 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1440 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1441 | { |
| 1442 | if ((val & DP_PORT_EN) == 0) |
| 1443 | return false; |
| 1444 | |
| 1445 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1446 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); |
| 1447 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); |
| 1448 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1449 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1450 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1451 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1452 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1453 | } else { |
| 1454 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1455 | return false; |
| 1456 | } |
| 1457 | return true; |
| 1458 | } |
| 1459 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1460 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1461 | enum pipe pipe, u32 val) |
| 1462 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1463 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1464 | return false; |
| 1465 | |
| 1466 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1467 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1468 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1469 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1470 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1471 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1472 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1473 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1474 | return false; |
| 1475 | } |
| 1476 | return true; |
| 1477 | } |
| 1478 | |
| 1479 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1480 | enum pipe pipe, u32 val) |
| 1481 | { |
| 1482 | if ((val & LVDS_PORT_EN) == 0) |
| 1483 | return false; |
| 1484 | |
| 1485 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1486 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1487 | return false; |
| 1488 | } else { |
| 1489 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1490 | return false; |
| 1491 | } |
| 1492 | return true; |
| 1493 | } |
| 1494 | |
| 1495 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1496 | enum pipe pipe, u32 val) |
| 1497 | { |
| 1498 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1499 | return false; |
| 1500 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1501 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1502 | return false; |
| 1503 | } else { |
| 1504 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1505 | return false; |
| 1506 | } |
| 1507 | return true; |
| 1508 | } |
| 1509 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1510 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1511 | enum pipe pipe, int reg, u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1512 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1513 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1514 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1515 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1516 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1517 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1518 | 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] | 1519 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1520 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1521 | } |
| 1522 | |
| 1523 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
| 1524 | enum pipe pipe, int reg) |
| 1525 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1526 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1527 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1528 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1529 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1530 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1531 | 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] | 1532 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1533 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1534 | } |
| 1535 | |
| 1536 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1537 | enum pipe pipe) |
| 1538 | { |
| 1539 | int reg; |
| 1540 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1541 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1542 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1543 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1544 | 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] | 1545 | |
| 1546 | reg = PCH_ADPA; |
| 1547 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1548 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1549 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1550 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1551 | |
| 1552 | reg = PCH_LVDS; |
| 1553 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1554 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1555 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1556 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1557 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1558 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1559 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1560 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1561 | } |
| 1562 | |
Jesse Barnes | 40e9cf6 | 2013-10-03 11:35:46 -0700 | [diff] [blame] | 1563 | static void intel_init_dpio(struct drm_device *dev) |
| 1564 | { |
| 1565 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1566 | |
| 1567 | if (!IS_VALLEYVIEW(dev)) |
| 1568 | return; |
| 1569 | |
Chon Ming Lee | a09cadd | 2014-04-09 13:28:14 +0300 | [diff] [blame] | 1570 | /* |
| 1571 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), |
| 1572 | * CHV x1 PHY (DP/HDMI D) |
| 1573 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) |
| 1574 | */ |
| 1575 | if (IS_CHERRYVIEW(dev)) { |
| 1576 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; |
| 1577 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; |
| 1578 | } else { |
| 1579 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; |
| 1580 | } |
Jesse Barnes | 5382f5f35 | 2013-12-16 16:34:24 -0800 | [diff] [blame] | 1581 | } |
| 1582 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1583 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1584 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1585 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1586 | struct drm_device *dev = crtc->base.dev; |
| 1587 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1588 | int reg = DPLL(crtc->pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1589 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1590 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1591 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1592 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1593 | /* No really, not for ILK+ */ |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1594 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); |
| 1595 | |
| 1596 | /* PLL is protected by panel, make sure we can write it */ |
Jani Nikula | 6a9e736 | 2014-08-22 15:06:35 +0300 | [diff] [blame] | 1597 | if (IS_MOBILE(dev_priv->dev)) |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1598 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1599 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1600 | I915_WRITE(reg, dpll); |
| 1601 | POSTING_READ(reg); |
| 1602 | udelay(150); |
| 1603 | |
| 1604 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1605 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); |
| 1606 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1607 | 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] | 1608 | POSTING_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1609 | |
| 1610 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1611 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1612 | POSTING_READ(reg); |
| 1613 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1614 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1615 | POSTING_READ(reg); |
| 1616 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1617 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1618 | POSTING_READ(reg); |
| 1619 | udelay(150); /* wait for warmup */ |
| 1620 | } |
| 1621 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1622 | static void chv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1623 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1624 | { |
| 1625 | struct drm_device *dev = crtc->base.dev; |
| 1626 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1627 | int pipe = crtc->pipe; |
| 1628 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1629 | u32 tmp; |
| 1630 | |
| 1631 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 1632 | |
| 1633 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); |
| 1634 | |
| 1635 | mutex_lock(&dev_priv->dpio_lock); |
| 1636 | |
| 1637 | /* Enable back the 10bit clock to display controller */ |
| 1638 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1639 | tmp |= DPIO_DCLKP_EN; |
| 1640 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1641 | |
| 1642 | /* |
| 1643 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1644 | */ |
| 1645 | udelay(1); |
| 1646 | |
| 1647 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1648 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1649 | |
| 1650 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1651 | 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] | 1652 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
| 1653 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1654 | /* not sure when this should be written */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1655 | 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] | 1656 | POSTING_READ(DPLL_MD(pipe)); |
| 1657 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1658 | mutex_unlock(&dev_priv->dpio_lock); |
| 1659 | } |
| 1660 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1661 | static int intel_num_dvo_pipes(struct drm_device *dev) |
| 1662 | { |
| 1663 | struct intel_crtc *crtc; |
| 1664 | int count = 0; |
| 1665 | |
| 1666 | for_each_intel_crtc(dev, crtc) |
| 1667 | count += crtc->active && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1668 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1669 | |
| 1670 | return count; |
| 1671 | } |
| 1672 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1673 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1674 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1675 | struct drm_device *dev = crtc->base.dev; |
| 1676 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1677 | int reg = DPLL(crtc->pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1678 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1679 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1680 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1681 | |
| 1682 | /* No really, not for ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1683 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1684 | |
| 1685 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1686 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1687 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1688 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1689 | /* Enable DVO 2x clock on both PLLs if necessary */ |
| 1690 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { |
| 1691 | /* |
| 1692 | * It appears to be important that we don't enable this |
| 1693 | * for the current pipe before otherwise configuring the |
| 1694 | * PLL. No idea how this should be handled if multiple |
| 1695 | * DVO outputs are enabled simultaneosly. |
| 1696 | */ |
| 1697 | dpll |= DPLL_DVO_2X_MODE; |
| 1698 | I915_WRITE(DPLL(!crtc->pipe), |
| 1699 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1700 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1701 | |
| 1702 | /* Wait for the clocks to stabilize. */ |
| 1703 | POSTING_READ(reg); |
| 1704 | udelay(150); |
| 1705 | |
| 1706 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1707 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1708 | crtc->config->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1709 | } else { |
| 1710 | /* The pixel multiplier can only be updated once the |
| 1711 | * DPLL is enabled and the clocks are stable. |
| 1712 | * |
| 1713 | * So write it again. |
| 1714 | */ |
| 1715 | I915_WRITE(reg, dpll); |
| 1716 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1717 | |
| 1718 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1719 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1720 | POSTING_READ(reg); |
| 1721 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1722 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1723 | POSTING_READ(reg); |
| 1724 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1725 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1726 | POSTING_READ(reg); |
| 1727 | udelay(150); /* wait for warmup */ |
| 1728 | } |
| 1729 | |
| 1730 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1731 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1732 | * @dev_priv: i915 private structure |
| 1733 | * @pipe: pipe PLL to disable |
| 1734 | * |
| 1735 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1736 | * |
| 1737 | * Note! This is for pre-ILK only. |
| 1738 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1739 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1740 | { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1741 | struct drm_device *dev = crtc->base.dev; |
| 1742 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1743 | enum pipe pipe = crtc->pipe; |
| 1744 | |
| 1745 | /* Disable DVO 2x clock on both PLLs if necessary */ |
| 1746 | if (IS_I830(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1747 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1748 | intel_num_dvo_pipes(dev) == 1) { |
| 1749 | I915_WRITE(DPLL(PIPE_B), |
| 1750 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1751 | I915_WRITE(DPLL(PIPE_A), |
| 1752 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1753 | } |
| 1754 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1755 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1756 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1757 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1758 | return; |
| 1759 | |
| 1760 | /* Make sure the pipe isn't still relying on us */ |
| 1761 | assert_pipe_disabled(dev_priv, pipe); |
| 1762 | |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1763 | I915_WRITE(DPLL(pipe), 0); |
| 1764 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1765 | } |
| 1766 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1767 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1768 | { |
| 1769 | u32 val = 0; |
| 1770 | |
| 1771 | /* Make sure the pipe isn't still relying on us */ |
| 1772 | assert_pipe_disabled(dev_priv, pipe); |
| 1773 | |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1774 | /* |
| 1775 | * Leave integrated clock source and reference clock enabled for pipe B. |
| 1776 | * The latter is needed for VGA hotplug / manual detection. |
| 1777 | */ |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1778 | if (pipe == PIPE_B) |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1779 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1780 | I915_WRITE(DPLL(pipe), val); |
| 1781 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1782 | |
| 1783 | } |
| 1784 | |
| 1785 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1786 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1787 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1788 | u32 val; |
| 1789 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1790 | /* Make sure the pipe isn't still relying on us */ |
| 1791 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1792 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1793 | /* Set PLL en = 0 */ |
Ville Syrjälä | d17ec4c | 2014-06-28 02:03:59 +0300 | [diff] [blame] | 1794 | val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1795 | if (pipe != PIPE_A) |
| 1796 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1797 | I915_WRITE(DPLL(pipe), val); |
| 1798 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1799 | |
| 1800 | mutex_lock(&dev_priv->dpio_lock); |
| 1801 | |
| 1802 | /* Disable 10bit clock to display controller */ |
| 1803 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1804 | val &= ~DPIO_DCLKP_EN; |
| 1805 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1806 | |
Ville Syrjälä | 61407f6 | 2014-05-27 16:32:55 +0300 | [diff] [blame] | 1807 | /* disable left/right clock distribution */ |
| 1808 | if (pipe != PIPE_B) { |
| 1809 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); |
| 1810 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); |
| 1811 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); |
| 1812 | } else { |
| 1813 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); |
| 1814 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); |
| 1815 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); |
| 1816 | } |
| 1817 | |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1818 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1821 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
| 1822 | struct intel_digital_port *dport) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1823 | { |
| 1824 | u32 port_mask; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1825 | int dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1826 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1827 | switch (dport->port) { |
| 1828 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1829 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1830 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1831 | break; |
| 1832 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1833 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1834 | dpll_reg = DPLL(0); |
| 1835 | break; |
| 1836 | case PORT_D: |
| 1837 | port_mask = DPLL_PORTD_READY_MASK; |
| 1838 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1839 | break; |
| 1840 | default: |
| 1841 | BUG(); |
| 1842 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1843 | |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1844 | if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1845 | 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] | 1846 | port_name(dport->port), I915_READ(dpll_reg)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1849 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
| 1850 | { |
| 1851 | struct drm_device *dev = crtc->base.dev; |
| 1852 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1853 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 1854 | |
Chris Wilson | be19f0f | 2014-05-28 16:16:42 +0100 | [diff] [blame] | 1855 | if (WARN_ON(pll == NULL)) |
| 1856 | return; |
| 1857 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1858 | WARN_ON(!pll->config.crtc_mask); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1859 | if (pll->active == 0) { |
| 1860 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); |
| 1861 | WARN_ON(pll->on); |
| 1862 | assert_shared_dpll_disabled(dev_priv, pll); |
| 1863 | |
| 1864 | pll->mode_set(dev_priv, pll); |
| 1865 | } |
| 1866 | } |
| 1867 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1868 | /** |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1869 | * intel_enable_shared_dpll - enable PCH PLL |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1870 | * @dev_priv: i915 private structure |
| 1871 | * @pipe: pipe PLL to enable |
| 1872 | * |
| 1873 | * The PCH PLL needs to be enabled before the PCH transcoder, since it |
| 1874 | * drives the transcoder clock. |
| 1875 | */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1876 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1877 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1878 | struct drm_device *dev = crtc->base.dev; |
| 1879 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1880 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1881 | |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1882 | if (WARN_ON(pll == NULL)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1883 | return; |
| 1884 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1885 | if (WARN_ON(pll->config.crtc_mask == 0)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1886 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1887 | |
Damien Lespiau | 74dd692 | 2014-07-29 18:06:17 +0100 | [diff] [blame] | 1888 | 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] | 1889 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1890 | crtc->base.base.id); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1891 | |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1892 | if (pll->active++) { |
| 1893 | WARN_ON(!pll->on); |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1894 | assert_shared_dpll_enabled(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1895 | return; |
| 1896 | } |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1897 | WARN_ON(pll->on); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1898 | |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1899 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 1900 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1901 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1902 | pll->enable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1903 | pll->on = true; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1904 | } |
| 1905 | |
Damien Lespiau | f6daaec | 2014-08-09 23:00:56 +0100 | [diff] [blame] | 1906 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1907 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1908 | struct drm_device *dev = crtc->base.dev; |
| 1909 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1910 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 4c609cb | 2011-09-02 12:52:11 -0700 | [diff] [blame] | 1911 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1912 | /* PCH only available on ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1913 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1914 | if (WARN_ON(pll == NULL)) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1915 | return; |
| 1916 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1917 | if (WARN_ON(pll->config.crtc_mask == 0)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1918 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1919 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1920 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
| 1921 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1922 | crtc->base.base.id); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1923 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1924 | if (WARN_ON(pll->active == 0)) { |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1925 | assert_shared_dpll_disabled(dev_priv, pll); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1926 | return; |
| 1927 | } |
| 1928 | |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1929 | assert_shared_dpll_enabled(dev_priv, pll); |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1930 | WARN_ON(!pll->on); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1931 | if (--pll->active) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1932 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1933 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1934 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1935 | pll->disable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1936 | pll->on = false; |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1937 | |
| 1938 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1939 | } |
| 1940 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1941 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1942 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1943 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1944 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1945 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1946 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1947 | uint32_t reg, val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1948 | |
| 1949 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1950 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1951 | |
| 1952 | /* Make sure PCH DPLL is enabled */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 1953 | assert_shared_dpll_enabled(dev_priv, |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1954 | intel_crtc_to_shared_dpll(intel_crtc)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1955 | |
| 1956 | /* FDI must be feeding us bits for PCH ports */ |
| 1957 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1958 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1959 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1960 | if (HAS_PCH_CPT(dev)) { |
| 1961 | /* Workaround: Set the timing override bit before enabling the |
| 1962 | * pch transcoder. */ |
| 1963 | reg = TRANS_CHICKEN2(pipe); |
| 1964 | val = I915_READ(reg); |
| 1965 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1966 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1967 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1968 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1969 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1970 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1971 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1972 | |
| 1973 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1974 | /* |
| 1975 | * make the BPC in transcoder be consistent with |
| 1976 | * that in pipeconf reg. |
| 1977 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1978 | val &= ~PIPECONF_BPC_MASK; |
| 1979 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1980 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1981 | |
| 1982 | val &= ~TRANS_INTERLACE_MASK; |
| 1983 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1984 | if (HAS_PCH_IBX(dev_priv->dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1985 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1986 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1987 | else |
| 1988 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1989 | else |
| 1990 | val |= TRANS_PROGRESSIVE; |
| 1991 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1992 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1993 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1994 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1995 | } |
| 1996 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1997 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 1998 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1999 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2000 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2001 | |
| 2002 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 2003 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2004 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2005 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2006 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2007 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2008 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2009 | /* Workaround: set timing override bit. */ |
| 2010 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2011 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2012 | I915_WRITE(_TRANSA_CHICKEN2, val); |
| 2013 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 2014 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2015 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2016 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 2017 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 2018 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 2019 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2020 | else |
| 2021 | val |= TRANS_PROGRESSIVE; |
| 2022 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2023 | I915_WRITE(LPT_TRANSCONF, val); |
| 2024 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2025 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2026 | } |
| 2027 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 2028 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 2029 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2030 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2031 | struct drm_device *dev = dev_priv->dev; |
| 2032 | uint32_t reg, val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2033 | |
| 2034 | /* FDI relies on the transcoder */ |
| 2035 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 2036 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 2037 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 2038 | /* Ports must be off as well */ |
| 2039 | assert_pch_ports_disabled(dev_priv, pipe); |
| 2040 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2041 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2042 | val = I915_READ(reg); |
| 2043 | val &= ~TRANS_ENABLE; |
| 2044 | I915_WRITE(reg, val); |
| 2045 | /* wait for PCH transcoder off, transcoder state */ |
| 2046 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 2047 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2048 | |
| 2049 | if (!HAS_PCH_IBX(dev)) { |
| 2050 | /* Workaround: Clear the timing override chicken bit again. */ |
| 2051 | reg = TRANS_CHICKEN2(pipe); |
| 2052 | val = I915_READ(reg); |
| 2053 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 2054 | I915_WRITE(reg, val); |
| 2055 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2056 | } |
| 2057 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 2058 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2059 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2060 | u32 val; |
| 2061 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2062 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2063 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2064 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2065 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2066 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 2067 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2068 | |
| 2069 | /* Workaround: clear timing override bit. */ |
| 2070 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2071 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2072 | I915_WRITE(_TRANSA_CHICKEN2, val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2076 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2077 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2078 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2079 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2080 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2081 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 2082 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2083 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2084 | struct drm_device *dev = crtc->base.dev; |
| 2085 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2086 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2087 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 2088 | pipe); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2089 | enum pipe pch_transcoder; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2090 | int reg; |
| 2091 | u32 val; |
| 2092 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2093 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2094 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2095 | assert_sprites_disabled(dev_priv, pipe); |
| 2096 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 2097 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2098 | pch_transcoder = TRANSCODER_A; |
| 2099 | else |
| 2100 | pch_transcoder = pipe; |
| 2101 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2102 | /* |
| 2103 | * A pipe without a PLL won't actually be able to drive bits from |
| 2104 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 2105 | * need the check. |
| 2106 | */ |
| 2107 | if (!HAS_PCH_SPLIT(dev_priv->dev)) |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 2108 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 2109 | assert_dsi_pll_enabled(dev_priv); |
| 2110 | else |
| 2111 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2112 | else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2113 | if (crtc->config->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2114 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2115 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2116 | assert_fdi_tx_pll_enabled(dev_priv, |
| 2117 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2118 | } |
| 2119 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 2120 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2121 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2122 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2123 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2124 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2125 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 2126 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2127 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2128 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2129 | |
| 2130 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 2131 | POSTING_READ(reg); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2132 | } |
| 2133 | |
| 2134 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2135 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2136 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2137 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2138 | * Disable the pipe of @crtc, making sure that various hardware |
| 2139 | * specific requirements are met, if applicable, e.g. plane |
| 2140 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2141 | * |
| 2142 | * Will wait until the pipe has shut down before returning. |
| 2143 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2144 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2145 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2146 | 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] | 2147 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2148 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2149 | int reg; |
| 2150 | u32 val; |
| 2151 | |
| 2152 | /* |
| 2153 | * Make sure planes won't keep trying to pump pixels to us, |
| 2154 | * or we might hang the display. |
| 2155 | */ |
| 2156 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2157 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2158 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2159 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2160 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2161 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2162 | if ((val & PIPECONF_ENABLE) == 0) |
| 2163 | return; |
| 2164 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2165 | /* |
| 2166 | * Double wide has implications for planes |
| 2167 | * so best keep it disabled when not needed. |
| 2168 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2169 | if (crtc->config->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2170 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2171 | |
| 2172 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2173 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2174 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2175 | val &= ~PIPECONF_ENABLE; |
| 2176 | |
| 2177 | I915_WRITE(reg, val); |
| 2178 | if ((val & PIPECONF_ENABLE) == 0) |
| 2179 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2180 | } |
| 2181 | |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2182 | /* |
| 2183 | * Plane regs are double buffered, going from enabled->disabled needs a |
| 2184 | * trigger in order to latch. The display address reg provides this. |
| 2185 | */ |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2186 | void intel_flush_primary_plane(struct drm_i915_private *dev_priv, |
| 2187 | enum plane plane) |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2188 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 2189 | struct drm_device *dev = dev_priv->dev; |
| 2190 | u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2191 | |
| 2192 | I915_WRITE(reg, I915_READ(reg)); |
| 2193 | POSTING_READ(reg); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2194 | } |
| 2195 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2196 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2197 | * 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] | 2198 | * @plane: plane to be enabled |
| 2199 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2200 | * |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2201 | * Enable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2202 | */ |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2203 | static void intel_enable_primary_hw_plane(struct drm_plane *plane, |
| 2204 | struct drm_crtc *crtc) |
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 | struct drm_device *dev = plane->dev; |
| 2207 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2208 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2209 | |
| 2210 | /* 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] | 2211 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2212 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2213 | if (intel_crtc->primary_enabled) |
| 2214 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2215 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2216 | intel_crtc->primary_enabled = true; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2217 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2218 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2219 | crtc->x, crtc->y); |
Ville Syrjälä | 33c3b0d | 2014-06-24 13:59:28 +0300 | [diff] [blame] | 2220 | |
| 2221 | /* |
| 2222 | * BDW signals flip done immediately if the plane |
| 2223 | * is disabled, even if the plane enable is already |
| 2224 | * armed to occur at the next vblank :( |
| 2225 | */ |
| 2226 | if (IS_BROADWELL(dev)) |
| 2227 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2228 | } |
| 2229 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2230 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2231 | * intel_disable_primary_hw_plane - disable the primary hardware plane |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2232 | * @plane: plane to be disabled |
| 2233 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2234 | * |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2235 | * Disable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2236 | */ |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2237 | static void intel_disable_primary_hw_plane(struct drm_plane *plane, |
| 2238 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2239 | { |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2240 | struct drm_device *dev = plane->dev; |
| 2241 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2242 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2243 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 2244 | if (WARN_ON(!intel_crtc->active)) |
| 2245 | return; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2246 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2247 | if (!intel_crtc->primary_enabled) |
| 2248 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2249 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2250 | intel_crtc->primary_enabled = false; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2251 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2252 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2253 | crtc->x, crtc->y); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2254 | } |
| 2255 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2256 | static bool need_vtd_wa(struct drm_device *dev) |
| 2257 | { |
| 2258 | #ifdef CONFIG_INTEL_IOMMU |
| 2259 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2260 | return true; |
| 2261 | #endif |
| 2262 | return false; |
| 2263 | } |
| 2264 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2265 | unsigned int |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2266 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
| 2267 | uint64_t fb_format_modifier) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2268 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2269 | unsigned int tile_height; |
| 2270 | uint32_t pixel_bytes; |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2271 | |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2272 | switch (fb_format_modifier) { |
| 2273 | case DRM_FORMAT_MOD_NONE: |
| 2274 | tile_height = 1; |
| 2275 | break; |
| 2276 | case I915_FORMAT_MOD_X_TILED: |
| 2277 | tile_height = IS_GEN2(dev) ? 16 : 8; |
| 2278 | break; |
| 2279 | case I915_FORMAT_MOD_Y_TILED: |
| 2280 | tile_height = 32; |
| 2281 | break; |
| 2282 | case I915_FORMAT_MOD_Yf_TILED: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2283 | pixel_bytes = drm_format_plane_cpp(pixel_format, 0); |
| 2284 | switch (pixel_bytes) { |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2285 | default: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2286 | case 1: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2287 | tile_height = 64; |
| 2288 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2289 | case 2: |
| 2290 | case 4: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2291 | tile_height = 32; |
| 2292 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2293 | case 8: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2294 | tile_height = 16; |
| 2295 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2296 | case 16: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2297 | WARN_ONCE(1, |
| 2298 | "128-bit pixels are not supported for display!"); |
| 2299 | tile_height = 16; |
| 2300 | break; |
| 2301 | } |
| 2302 | break; |
| 2303 | default: |
| 2304 | MISSING_CASE(fb_format_modifier); |
| 2305 | tile_height = 1; |
| 2306 | break; |
| 2307 | } |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 2308 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2309 | return tile_height; |
| 2310 | } |
| 2311 | |
| 2312 | unsigned int |
| 2313 | intel_fb_align_height(struct drm_device *dev, unsigned int height, |
| 2314 | uint32_t pixel_format, uint64_t fb_format_modifier) |
| 2315 | { |
| 2316 | return ALIGN(height, intel_tile_height(dev, pixel_format, |
| 2317 | fb_format_modifier)); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2318 | } |
| 2319 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2320 | static int |
| 2321 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, |
| 2322 | const struct drm_plane_state *plane_state) |
| 2323 | { |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2324 | struct intel_rotation_info *info = &view->rotation_info; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2325 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2326 | *view = i915_ggtt_view_normal; |
| 2327 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2328 | if (!plane_state) |
| 2329 | return 0; |
| 2330 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2331 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2332 | return 0; |
| 2333 | |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2334 | *view = i915_ggtt_view_rotated; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2335 | |
| 2336 | info->height = fb->height; |
| 2337 | info->pixel_format = fb->pixel_format; |
| 2338 | info->pitch = fb->pitches[0]; |
| 2339 | info->fb_modifier = fb->modifier[0]; |
| 2340 | |
| 2341 | if (!(info->fb_modifier == I915_FORMAT_MOD_Y_TILED || |
| 2342 | info->fb_modifier == I915_FORMAT_MOD_Yf_TILED)) { |
| 2343 | DRM_DEBUG_KMS( |
| 2344 | "Y or Yf tiling is needed for 90/270 rotation!\n"); |
| 2345 | return -EINVAL; |
| 2346 | } |
| 2347 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2348 | return 0; |
| 2349 | } |
| 2350 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2351 | int |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2352 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
| 2353 | struct drm_framebuffer *fb, |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2354 | const struct drm_plane_state *plane_state, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2355 | struct intel_engine_cs *pipelined) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2356 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2357 | struct drm_device *dev = fb->dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2358 | struct drm_i915_private *dev_priv = dev->dev_private; |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2359 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2360 | struct i915_ggtt_view view; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2361 | u32 alignment; |
| 2362 | int ret; |
| 2363 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2364 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2365 | |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2366 | switch (fb->modifier[0]) { |
| 2367 | case DRM_FORMAT_MOD_NONE: |
Damien Lespiau | 1fada4c | 2013-07-03 21:06:02 +0100 | [diff] [blame] | 2368 | if (INTEL_INFO(dev)->gen >= 9) |
| 2369 | alignment = 256 * 1024; |
| 2370 | else if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2371 | alignment = 128 * 1024; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2372 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2373 | alignment = 4 * 1024; |
| 2374 | else |
| 2375 | alignment = 64 * 1024; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2376 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2377 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | 1fada4c | 2013-07-03 21:06:02 +0100 | [diff] [blame] | 2378 | if (INTEL_INFO(dev)->gen >= 9) |
| 2379 | alignment = 256 * 1024; |
| 2380 | else { |
| 2381 | /* pin() will align the object as required by fence */ |
| 2382 | alignment = 0; |
| 2383 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2384 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2385 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | 1327b9a | 2015-02-27 11:15:20 +0000 | [diff] [blame] | 2386 | case I915_FORMAT_MOD_Yf_TILED: |
| 2387 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, |
| 2388 | "Y tiling bo slipped through, driver bug!\n")) |
| 2389 | return -EINVAL; |
| 2390 | alignment = 1 * 1024 * 1024; |
| 2391 | break; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2392 | default: |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2393 | MISSING_CASE(fb->modifier[0]); |
| 2394 | return -EINVAL; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2395 | } |
| 2396 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2397 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
| 2398 | if (ret) |
| 2399 | return ret; |
| 2400 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2401 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2402 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2403 | * we should always have valid PTE following the scanout preventing |
| 2404 | * the VT-d warning. |
| 2405 | */ |
| 2406 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2407 | alignment = 256 * 1024; |
| 2408 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2409 | /* |
| 2410 | * Global gtt pte registers are special registers which actually forward |
| 2411 | * writes to a chunk of system memory. Which means that there is no risk |
| 2412 | * that the register values disappear as soon as we call |
| 2413 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2414 | * pin/unpin/fence and not more. |
| 2415 | */ |
| 2416 | intel_runtime_pm_get(dev_priv); |
| 2417 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2418 | dev_priv->mm.interruptible = false; |
Tvrtko Ursulin | e661733 | 2015-03-23 11:10:33 +0000 | [diff] [blame] | 2419 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined, |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2420 | &view); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2421 | if (ret) |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2422 | goto err_interruptible; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2423 | |
| 2424 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2425 | * fence, whereas 965+ only requires a fence if using |
| 2426 | * framebuffer compression. For simplicity, we always install |
| 2427 | * a fence as the cost is not that onerous. |
| 2428 | */ |
Chris Wilson | 06d9813 | 2012-04-17 15:31:24 +0100 | [diff] [blame] | 2429 | ret = i915_gem_object_get_fence(obj); |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2430 | if (ret) |
| 2431 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2432 | |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2433 | i915_gem_object_pin_fence(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2434 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2435 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2436 | intel_runtime_pm_put(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2437 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2438 | |
| 2439 | err_unpin: |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2440 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2441 | err_interruptible: |
| 2442 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2443 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2444 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2445 | } |
| 2446 | |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2447 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
| 2448 | const struct drm_plane_state *plane_state) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2449 | { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2450 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2451 | struct i915_ggtt_view view; |
| 2452 | int ret; |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2453 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2454 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2455 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2456 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
| 2457 | WARN_ONCE(ret, "Couldn't get view from plane state!"); |
| 2458 | |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2459 | i915_gem_object_unpin_fence(obj); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2460 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2461 | } |
| 2462 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2463 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
| 2464 | * is assumed to be a power-of-two. */ |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2465 | unsigned long intel_gen4_compute_page_offset(int *x, int *y, |
| 2466 | unsigned int tiling_mode, |
| 2467 | unsigned int cpp, |
| 2468 | unsigned int pitch) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2469 | { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2470 | if (tiling_mode != I915_TILING_NONE) { |
| 2471 | unsigned int tile_rows, tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2472 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2473 | tile_rows = *y / 8; |
| 2474 | *y %= 8; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2475 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2476 | tiles = *x / (512/cpp); |
| 2477 | *x %= 512/cpp; |
| 2478 | |
| 2479 | return tile_rows * pitch * 8 + tiles * 4096; |
| 2480 | } else { |
| 2481 | unsigned int offset; |
| 2482 | |
| 2483 | offset = *y * pitch + *x * cpp; |
| 2484 | *y = 0; |
| 2485 | *x = (offset & 4095) / cpp; |
| 2486 | return offset & -4096; |
| 2487 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2488 | } |
| 2489 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2490 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2491 | { |
| 2492 | switch (format) { |
| 2493 | case DISPPLANE_8BPP: |
| 2494 | return DRM_FORMAT_C8; |
| 2495 | case DISPPLANE_BGRX555: |
| 2496 | return DRM_FORMAT_XRGB1555; |
| 2497 | case DISPPLANE_BGRX565: |
| 2498 | return DRM_FORMAT_RGB565; |
| 2499 | default: |
| 2500 | case DISPPLANE_BGRX888: |
| 2501 | return DRM_FORMAT_XRGB8888; |
| 2502 | case DISPPLANE_RGBX888: |
| 2503 | return DRM_FORMAT_XBGR8888; |
| 2504 | case DISPPLANE_BGRX101010: |
| 2505 | return DRM_FORMAT_XRGB2101010; |
| 2506 | case DISPPLANE_RGBX101010: |
| 2507 | return DRM_FORMAT_XBGR2101010; |
| 2508 | } |
| 2509 | } |
| 2510 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2511 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
| 2512 | { |
| 2513 | switch (format) { |
| 2514 | case PLANE_CTL_FORMAT_RGB_565: |
| 2515 | return DRM_FORMAT_RGB565; |
| 2516 | default: |
| 2517 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2518 | if (rgb_order) { |
| 2519 | if (alpha) |
| 2520 | return DRM_FORMAT_ABGR8888; |
| 2521 | else |
| 2522 | return DRM_FORMAT_XBGR8888; |
| 2523 | } else { |
| 2524 | if (alpha) |
| 2525 | return DRM_FORMAT_ARGB8888; |
| 2526 | else |
| 2527 | return DRM_FORMAT_XRGB8888; |
| 2528 | } |
| 2529 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2530 | if (rgb_order) |
| 2531 | return DRM_FORMAT_XBGR2101010; |
| 2532 | else |
| 2533 | return DRM_FORMAT_XRGB2101010; |
| 2534 | } |
| 2535 | } |
| 2536 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2537 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2538 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2539 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2540 | { |
| 2541 | struct drm_device *dev = crtc->base.dev; |
| 2542 | struct drm_i915_gem_object *obj = NULL; |
| 2543 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2544 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2545 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2546 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2547 | PAGE_SIZE); |
| 2548 | |
| 2549 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2550 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2551 | if (plane_config->size == 0) |
| 2552 | return false; |
| 2553 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2554 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
| 2555 | base_aligned, |
| 2556 | base_aligned, |
| 2557 | size_aligned); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2558 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2559 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2560 | |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 2561 | obj->tiling_mode = plane_config->tiling; |
| 2562 | if (obj->tiling_mode == I915_TILING_X) |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2563 | obj->stride = fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2564 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2565 | mode_cmd.pixel_format = fb->pixel_format; |
| 2566 | mode_cmd.width = fb->width; |
| 2567 | mode_cmd.height = fb->height; |
| 2568 | mode_cmd.pitches[0] = fb->pitches[0]; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2569 | mode_cmd.modifier[0] = fb->modifier[0]; |
| 2570 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2571 | |
| 2572 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2573 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2574 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2575 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2576 | goto out_unref_obj; |
| 2577 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2578 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2579 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2580 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2581 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2582 | |
| 2583 | out_unref_obj: |
| 2584 | drm_gem_object_unreference(&obj->base); |
| 2585 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2586 | return false; |
| 2587 | } |
| 2588 | |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 2589 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
| 2590 | static void |
| 2591 | update_state_fb(struct drm_plane *plane) |
| 2592 | { |
| 2593 | if (plane->fb == plane->state->fb) |
| 2594 | return; |
| 2595 | |
| 2596 | if (plane->state->fb) |
| 2597 | drm_framebuffer_unreference(plane->state->fb); |
| 2598 | plane->state->fb = plane->fb; |
| 2599 | if (plane->state->fb) |
| 2600 | drm_framebuffer_reference(plane->state->fb); |
| 2601 | } |
| 2602 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2603 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2604 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2605 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2606 | { |
| 2607 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | d9ceb81 | 2014-10-09 12:57:43 -0700 | [diff] [blame] | 2608 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2609 | struct drm_crtc *c; |
| 2610 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2611 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2612 | struct drm_plane *primary = intel_crtc->base.primary; |
| 2613 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2614 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2615 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2616 | return; |
| 2617 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2618 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2619 | fb = &plane_config->fb->base; |
| 2620 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2621 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2622 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2623 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2624 | |
| 2625 | /* |
| 2626 | * Failed to alloc the obj, check to see if we should share |
| 2627 | * an fb with another CRTC instead |
| 2628 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2629 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2630 | i = to_intel_crtc(c); |
| 2631 | |
| 2632 | if (c == &intel_crtc->base) |
| 2633 | continue; |
| 2634 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2635 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2636 | continue; |
| 2637 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2638 | fb = c->primary->fb; |
| 2639 | if (!fb) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2640 | continue; |
| 2641 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2642 | obj = intel_fb_obj(fb); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2643 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2644 | drm_framebuffer_reference(fb); |
| 2645 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2646 | } |
| 2647 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2648 | |
| 2649 | return; |
| 2650 | |
| 2651 | valid_fb: |
| 2652 | obj = intel_fb_obj(fb); |
| 2653 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2654 | dev_priv->preserve_bios_swizzle = true; |
| 2655 | |
| 2656 | primary->fb = fb; |
| 2657 | primary->state->crtc = &intel_crtc->base; |
| 2658 | primary->crtc = &intel_crtc->base; |
| 2659 | update_state_fb(primary); |
| 2660 | obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2661 | } |
| 2662 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2663 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
| 2664 | struct drm_framebuffer *fb, |
| 2665 | int x, int y) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2666 | { |
| 2667 | struct drm_device *dev = crtc->dev; |
| 2668 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2669 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2670 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2671 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2672 | unsigned long linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2673 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2674 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2675 | int pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2676 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2677 | if (!intel_crtc->primary_enabled) { |
| 2678 | I915_WRITE(reg, 0); |
| 2679 | if (INTEL_INFO(dev)->gen >= 4) |
| 2680 | I915_WRITE(DSPSURF(plane), 0); |
| 2681 | else |
| 2682 | I915_WRITE(DSPADDR(plane), 0); |
| 2683 | POSTING_READ(reg); |
| 2684 | return; |
| 2685 | } |
| 2686 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2687 | obj = intel_fb_obj(fb); |
| 2688 | if (WARN_ON(obj == NULL)) |
| 2689 | return; |
| 2690 | |
| 2691 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2692 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2693 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2694 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2695 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2696 | |
| 2697 | if (INTEL_INFO(dev)->gen < 4) { |
| 2698 | if (intel_crtc->pipe == PIPE_B) |
| 2699 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 2700 | |
| 2701 | /* pipesrc and dspsize control the size that is scaled from, |
| 2702 | * which should always be the user's requested size. |
| 2703 | */ |
| 2704 | I915_WRITE(DSPSIZE(plane), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2705 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
| 2706 | (intel_crtc->config->pipe_src_w - 1)); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2707 | I915_WRITE(DSPPOS(plane), 0); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2708 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
| 2709 | I915_WRITE(PRIMSIZE(plane), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2710 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
| 2711 | (intel_crtc->config->pipe_src_w - 1)); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2712 | I915_WRITE(PRIMPOS(plane), 0); |
| 2713 | I915_WRITE(PRIMCNSTALPHA(plane), 0); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2714 | } |
| 2715 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2716 | switch (fb->pixel_format) { |
| 2717 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2718 | dspcntr |= DISPPLANE_8BPP; |
| 2719 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2720 | case DRM_FORMAT_XRGB1555: |
| 2721 | case DRM_FORMAT_ARGB1555: |
| 2722 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2723 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2724 | case DRM_FORMAT_RGB565: |
| 2725 | dspcntr |= DISPPLANE_BGRX565; |
| 2726 | break; |
| 2727 | case DRM_FORMAT_XRGB8888: |
| 2728 | case DRM_FORMAT_ARGB8888: |
| 2729 | dspcntr |= DISPPLANE_BGRX888; |
| 2730 | break; |
| 2731 | case DRM_FORMAT_XBGR8888: |
| 2732 | case DRM_FORMAT_ABGR8888: |
| 2733 | dspcntr |= DISPPLANE_RGBX888; |
| 2734 | break; |
| 2735 | case DRM_FORMAT_XRGB2101010: |
| 2736 | case DRM_FORMAT_ARGB2101010: |
| 2737 | dspcntr |= DISPPLANE_BGRX101010; |
| 2738 | break; |
| 2739 | case DRM_FORMAT_XBGR2101010: |
| 2740 | case DRM_FORMAT_ABGR2101010: |
| 2741 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2742 | break; |
| 2743 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2744 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2745 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2746 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2747 | if (INTEL_INFO(dev)->gen >= 4 && |
| 2748 | obj->tiling_mode != I915_TILING_NONE) |
| 2749 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2750 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 2751 | if (IS_G4X(dev)) |
| 2752 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2753 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2754 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2755 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2756 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2757 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2758 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2759 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2760 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2761 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2762 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2763 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2764 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2765 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2766 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2767 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2768 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2769 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2770 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2771 | |
| 2772 | /* Finding the last pixel of the last line of the display |
| 2773 | data and adding to linear_offset*/ |
| 2774 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2775 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2776 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2777 | } |
| 2778 | |
| 2779 | I915_WRITE(reg, dspcntr); |
| 2780 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2781 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2782 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2783 | I915_WRITE(DSPSURF(plane), |
| 2784 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2785 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2786 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2787 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2788 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2789 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2790 | } |
| 2791 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2792 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
| 2793 | struct drm_framebuffer *fb, |
| 2794 | int x, int y) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2795 | { |
| 2796 | struct drm_device *dev = crtc->dev; |
| 2797 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2798 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2799 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2800 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2801 | unsigned long linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2802 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2803 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2804 | int pixel_size; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2805 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2806 | if (!intel_crtc->primary_enabled) { |
| 2807 | I915_WRITE(reg, 0); |
| 2808 | I915_WRITE(DSPSURF(plane), 0); |
| 2809 | POSTING_READ(reg); |
| 2810 | return; |
| 2811 | } |
| 2812 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2813 | obj = intel_fb_obj(fb); |
| 2814 | if (WARN_ON(obj == NULL)) |
| 2815 | return; |
| 2816 | |
| 2817 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2818 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2819 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2820 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2821 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2822 | |
| 2823 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 2824 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 2825 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2826 | switch (fb->pixel_format) { |
| 2827 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2828 | dspcntr |= DISPPLANE_8BPP; |
| 2829 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2830 | case DRM_FORMAT_RGB565: |
| 2831 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2832 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2833 | case DRM_FORMAT_XRGB8888: |
| 2834 | case DRM_FORMAT_ARGB8888: |
| 2835 | dspcntr |= DISPPLANE_BGRX888; |
| 2836 | break; |
| 2837 | case DRM_FORMAT_XBGR8888: |
| 2838 | case DRM_FORMAT_ABGR8888: |
| 2839 | dspcntr |= DISPPLANE_RGBX888; |
| 2840 | break; |
| 2841 | case DRM_FORMAT_XRGB2101010: |
| 2842 | case DRM_FORMAT_ARGB2101010: |
| 2843 | dspcntr |= DISPPLANE_BGRX101010; |
| 2844 | break; |
| 2845 | case DRM_FORMAT_XBGR2101010: |
| 2846 | case DRM_FORMAT_ABGR2101010: |
| 2847 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2848 | break; |
| 2849 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2850 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2854 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2855 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2856 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 2857 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2858 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2859 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2860 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2861 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2862 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2863 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2864 | linear_offset -= intel_crtc->dspaddr_offset; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2865 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2866 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2867 | |
| 2868 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2869 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2870 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2871 | |
| 2872 | /* Finding the last pixel of the last line of the display |
| 2873 | data and adding to linear_offset*/ |
| 2874 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2875 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2876 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2877 | } |
| 2878 | } |
| 2879 | |
| 2880 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2881 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2882 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2883 | I915_WRITE(DSPSURF(plane), |
| 2884 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 2885 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2886 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2887 | } else { |
| 2888 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2889 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2890 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2891 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2892 | } |
| 2893 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2894 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
| 2895 | uint32_t pixel_format) |
| 2896 | { |
| 2897 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; |
| 2898 | |
| 2899 | /* |
| 2900 | * The stride is either expressed as a multiple of 64 bytes |
| 2901 | * chunks for linear buffers or in number of tiles for tiled |
| 2902 | * buffers. |
| 2903 | */ |
| 2904 | switch (fb_modifier) { |
| 2905 | case DRM_FORMAT_MOD_NONE: |
| 2906 | return 64; |
| 2907 | case I915_FORMAT_MOD_X_TILED: |
| 2908 | if (INTEL_INFO(dev)->gen == 2) |
| 2909 | return 128; |
| 2910 | return 512; |
| 2911 | case I915_FORMAT_MOD_Y_TILED: |
| 2912 | /* No need to check for old gens and Y tiling since this is |
| 2913 | * about the display engine and those will be blocked before |
| 2914 | * we get here. |
| 2915 | */ |
| 2916 | return 128; |
| 2917 | case I915_FORMAT_MOD_Yf_TILED: |
| 2918 | if (bits_per_pixel == 8) |
| 2919 | return 64; |
| 2920 | else |
| 2921 | return 128; |
| 2922 | default: |
| 2923 | MISSING_CASE(fb_modifier); |
| 2924 | return 64; |
| 2925 | } |
| 2926 | } |
| 2927 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2928 | unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane, |
| 2929 | struct drm_i915_gem_object *obj) |
| 2930 | { |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2931 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2932 | |
| 2933 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2934 | view = &i915_ggtt_view_rotated; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2935 | |
| 2936 | return i915_gem_obj_ggtt_offset_view(obj, view); |
| 2937 | } |
| 2938 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2939 | static void skylake_update_primary_plane(struct drm_crtc *crtc, |
| 2940 | struct drm_framebuffer *fb, |
| 2941 | int x, int y) |
| 2942 | { |
| 2943 | struct drm_device *dev = crtc->dev; |
| 2944 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2945 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2946 | struct drm_i915_gem_object *obj; |
| 2947 | int pipe = intel_crtc->pipe; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2948 | u32 plane_ctl, stride_div; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2949 | unsigned long surf_addr; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2950 | |
| 2951 | if (!intel_crtc->primary_enabled) { |
| 2952 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
| 2953 | I915_WRITE(PLANE_SURF(pipe, 0), 0); |
| 2954 | POSTING_READ(PLANE_CTL(pipe, 0)); |
| 2955 | return; |
| 2956 | } |
| 2957 | |
| 2958 | plane_ctl = PLANE_CTL_ENABLE | |
| 2959 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 2960 | PLANE_CTL_PIPE_CSC_ENABLE; |
| 2961 | |
| 2962 | switch (fb->pixel_format) { |
| 2963 | case DRM_FORMAT_RGB565: |
| 2964 | plane_ctl |= PLANE_CTL_FORMAT_RGB_565; |
| 2965 | break; |
| 2966 | case DRM_FORMAT_XRGB8888: |
| 2967 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2968 | break; |
Jani Nikula | f75fb42 | 2015-02-10 13:15:49 +0200 | [diff] [blame] | 2969 | case DRM_FORMAT_ARGB8888: |
| 2970 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2971 | plane_ctl |= PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 2972 | break; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2973 | case DRM_FORMAT_XBGR8888: |
| 2974 | plane_ctl |= PLANE_CTL_ORDER_RGBX; |
| 2975 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2976 | break; |
Jani Nikula | f75fb42 | 2015-02-10 13:15:49 +0200 | [diff] [blame] | 2977 | case DRM_FORMAT_ABGR8888: |
| 2978 | plane_ctl |= PLANE_CTL_ORDER_RGBX; |
| 2979 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2980 | plane_ctl |= PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 2981 | break; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2982 | case DRM_FORMAT_XRGB2101010: |
| 2983 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_2101010; |
| 2984 | break; |
| 2985 | case DRM_FORMAT_XBGR2101010: |
| 2986 | plane_ctl |= PLANE_CTL_ORDER_RGBX; |
| 2987 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_2101010; |
| 2988 | break; |
| 2989 | default: |
| 2990 | BUG(); |
| 2991 | } |
| 2992 | |
Daniel Vetter | 30af77c | 2015-02-10 17:16:11 +0000 | [diff] [blame] | 2993 | switch (fb->modifier[0]) { |
| 2994 | case DRM_FORMAT_MOD_NONE: |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2995 | break; |
Daniel Vetter | 30af77c | 2015-02-10 17:16:11 +0000 | [diff] [blame] | 2996 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2997 | plane_ctl |= PLANE_CTL_TILED_X; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2998 | break; |
| 2999 | case I915_FORMAT_MOD_Y_TILED: |
| 3000 | plane_ctl |= PLANE_CTL_TILED_Y; |
| 3001 | break; |
| 3002 | case I915_FORMAT_MOD_Yf_TILED: |
| 3003 | plane_ctl |= PLANE_CTL_TILED_YF; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3004 | break; |
| 3005 | default: |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3006 | MISSING_CASE(fb->modifier[0]); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3007 | } |
| 3008 | |
| 3009 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 3010 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) |
Sonika Jindal | 1447dde | 2014-10-04 10:53:31 +0100 | [diff] [blame] | 3011 | plane_ctl |= PLANE_CTL_ROTATE_180; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3012 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3013 | obj = intel_fb_obj(fb); |
| 3014 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 3015 | fb->pixel_format); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3016 | surf_addr = intel_plane_obj_offset(to_intel_plane(crtc->primary), obj); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3017 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3018 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3019 | I915_WRITE(PLANE_POS(pipe, 0), 0); |
| 3020 | I915_WRITE(PLANE_OFFSET(pipe, 0), (y << 16) | x); |
| 3021 | I915_WRITE(PLANE_SIZE(pipe, 0), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3022 | (intel_crtc->config->pipe_src_h - 1) << 16 | |
| 3023 | (intel_crtc->config->pipe_src_w - 1)); |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3024 | I915_WRITE(PLANE_STRIDE(pipe, 0), fb->pitches[0] / stride_div); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3025 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3026 | |
| 3027 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3028 | } |
| 3029 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3030 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 3031 | static int |
| 3032 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 3033 | int x, int y, enum mode_set_atomic state) |
| 3034 | { |
| 3035 | struct drm_device *dev = crtc->dev; |
| 3036 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3037 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 3038 | if (dev_priv->display.disable_fbc) |
| 3039 | dev_priv->display.disable_fbc(dev); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3040 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 3041 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
| 3042 | |
| 3043 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3044 | } |
| 3045 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3046 | static void intel_complete_page_flips(struct drm_device *dev) |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3047 | { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3048 | struct drm_crtc *crtc; |
| 3049 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3050 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3051 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3052 | enum plane plane = intel_crtc->plane; |
| 3053 | |
| 3054 | intel_prepare_page_flip(dev, plane); |
| 3055 | intel_finish_page_flip_plane(dev, plane); |
| 3056 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3057 | } |
| 3058 | |
| 3059 | static void intel_update_primary_planes(struct drm_device *dev) |
| 3060 | { |
| 3061 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3062 | struct drm_crtc *crtc; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3063 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3064 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3065 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3066 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 3067 | drm_modeset_lock(&crtc->mutex, NULL); |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 3068 | /* |
| 3069 | * FIXME: Once we have proper support for primary planes (and |
| 3070 | * disabling them without disabling the entire crtc) allow again |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 3071 | * a NULL crtc->primary->fb. |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 3072 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 3073 | if (intel_crtc->active && crtc->primary->fb) |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 3074 | dev_priv->display.update_primary_plane(crtc, |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 3075 | crtc->primary->fb, |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 3076 | crtc->x, |
| 3077 | crtc->y); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 3078 | drm_modeset_unlock(&crtc->mutex); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3079 | } |
| 3080 | } |
| 3081 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3082 | void intel_prepare_reset(struct drm_device *dev) |
| 3083 | { |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3084 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3085 | struct intel_crtc *crtc; |
| 3086 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3087 | /* no reset support for gen2 */ |
| 3088 | if (IS_GEN2(dev)) |
| 3089 | return; |
| 3090 | |
| 3091 | /* reset doesn't touch the display */ |
| 3092 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
| 3093 | return; |
| 3094 | |
| 3095 | drm_modeset_lock_all(dev); |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3096 | |
| 3097 | /* |
| 3098 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3099 | * g33 docs say we should at least disable all the planes. |
| 3100 | */ |
| 3101 | for_each_intel_crtc(dev, crtc) { |
| 3102 | if (crtc->active) |
| 3103 | dev_priv->display.crtc_disable(&crtc->base); |
| 3104 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | void intel_finish_reset(struct drm_device *dev) |
| 3108 | { |
| 3109 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3110 | |
| 3111 | /* |
| 3112 | * Flips in the rings will be nuked by the reset, |
| 3113 | * so complete all pending flips so that user space |
| 3114 | * will get its events and not get stuck. |
| 3115 | */ |
| 3116 | intel_complete_page_flips(dev); |
| 3117 | |
| 3118 | /* no reset support for gen2 */ |
| 3119 | if (IS_GEN2(dev)) |
| 3120 | return; |
| 3121 | |
| 3122 | /* reset doesn't touch the display */ |
| 3123 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { |
| 3124 | /* |
| 3125 | * Flips in the rings have been nuked by the reset, |
| 3126 | * so update the base address of all primary |
| 3127 | * planes to the the last fb to make sure we're |
| 3128 | * showing the correct fb after a reset. |
| 3129 | */ |
| 3130 | intel_update_primary_planes(dev); |
| 3131 | return; |
| 3132 | } |
| 3133 | |
| 3134 | /* |
| 3135 | * The display has been reset as well, |
| 3136 | * so need a full re-initialization. |
| 3137 | */ |
| 3138 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3139 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3140 | |
| 3141 | intel_modeset_init_hw(dev); |
| 3142 | |
| 3143 | spin_lock_irq(&dev_priv->irq_lock); |
| 3144 | if (dev_priv->display.hpd_irq_setup) |
| 3145 | dev_priv->display.hpd_irq_setup(dev); |
| 3146 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3147 | |
| 3148 | intel_modeset_setup_hw_state(dev, true); |
| 3149 | |
| 3150 | intel_hpd_init(dev_priv); |
| 3151 | |
| 3152 | drm_modeset_unlock_all(dev); |
| 3153 | } |
| 3154 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 3155 | static int |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3156 | intel_finish_fb(struct drm_framebuffer *old_fb) |
| 3157 | { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 3158 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3159 | struct drm_i915_private *dev_priv = obj->base.dev->dev_private; |
| 3160 | bool was_interruptible = dev_priv->mm.interruptible; |
| 3161 | int ret; |
| 3162 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3163 | /* Big Hammer, we also need to ensure that any pending |
| 3164 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 3165 | * current scanout is retired before unpinning the old |
| 3166 | * framebuffer. |
| 3167 | * |
| 3168 | * This should only fail upon a hung GPU, in which case we |
| 3169 | * can safely continue. |
| 3170 | */ |
| 3171 | dev_priv->mm.interruptible = false; |
| 3172 | ret = i915_gem_object_finish_gpu(obj); |
| 3173 | dev_priv->mm.interruptible = was_interruptible; |
| 3174 | |
| 3175 | return ret; |
| 3176 | } |
| 3177 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3178 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 3179 | { |
| 3180 | struct drm_device *dev = crtc->dev; |
| 3181 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3182 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3183 | bool pending; |
| 3184 | |
| 3185 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 3186 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 3187 | return false; |
| 3188 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3189 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3190 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3191 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3192 | |
| 3193 | return pending; |
| 3194 | } |
| 3195 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3196 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
| 3197 | { |
| 3198 | struct drm_device *dev = crtc->base.dev; |
| 3199 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3200 | const struct drm_display_mode *adjusted_mode; |
| 3201 | |
| 3202 | if (!i915.fastboot) |
| 3203 | return; |
| 3204 | |
| 3205 | /* |
| 3206 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3207 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3208 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3209 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3210 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3211 | * sized surface. |
| 3212 | * |
| 3213 | * To fix this properly, we need to hoist the checks up into |
| 3214 | * compute_mode_changes (or above), check the actual pfit state and |
| 3215 | * whether the platform allows pfit disable with pipe active, and only |
| 3216 | * then update the pipesrc and pfit state, even on the flip path. |
| 3217 | */ |
| 3218 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3219 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3220 | |
| 3221 | I915_WRITE(PIPESRC(crtc->pipe), |
| 3222 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | |
| 3223 | (adjusted_mode->crtc_vdisplay - 1)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3224 | if (!crtc->config->pch_pfit.enabled && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 3225 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
| 3226 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3227 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
| 3228 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); |
| 3229 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); |
| 3230 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3231 | crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay; |
| 3232 | crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3233 | } |
| 3234 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3235 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 3236 | { |
| 3237 | struct drm_device *dev = crtc->dev; |
| 3238 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3239 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3240 | int pipe = intel_crtc->pipe; |
| 3241 | u32 reg, temp; |
| 3242 | |
| 3243 | /* enable normal train */ |
| 3244 | reg = FDI_TX_CTL(pipe); |
| 3245 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3246 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3247 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3248 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3249 | } else { |
| 3250 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3251 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3252 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3253 | I915_WRITE(reg, temp); |
| 3254 | |
| 3255 | reg = FDI_RX_CTL(pipe); |
| 3256 | temp = I915_READ(reg); |
| 3257 | if (HAS_PCH_CPT(dev)) { |
| 3258 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3259 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3260 | } else { |
| 3261 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3262 | temp |= FDI_LINK_TRAIN_NONE; |
| 3263 | } |
| 3264 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3265 | |
| 3266 | /* wait one idle pattern time */ |
| 3267 | POSTING_READ(reg); |
| 3268 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3269 | |
| 3270 | /* IVB wants error correction enabled */ |
| 3271 | if (IS_IVYBRIDGE(dev)) |
| 3272 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3273 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3274 | } |
| 3275 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3276 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 3277 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 3278 | { |
| 3279 | struct drm_device *dev = crtc->dev; |
| 3280 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3281 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3282 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3283 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3284 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3285 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3286 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3287 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3288 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3289 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3290 | reg = FDI_RX_IMR(pipe); |
| 3291 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3292 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3293 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3294 | I915_WRITE(reg, temp); |
| 3295 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3296 | udelay(150); |
| 3297 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3298 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3299 | reg = FDI_TX_CTL(pipe); |
| 3300 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3301 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3302 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3303 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3304 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3305 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3306 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3307 | reg = FDI_RX_CTL(pipe); |
| 3308 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3309 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3310 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3311 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3312 | |
| 3313 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3314 | udelay(150); |
| 3315 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3316 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3317 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3318 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3319 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3320 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3321 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3322 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3323 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3324 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3325 | |
| 3326 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3327 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3328 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3329 | break; |
| 3330 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3331 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3332 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3333 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3334 | |
| 3335 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3336 | reg = FDI_TX_CTL(pipe); |
| 3337 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3338 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3339 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3340 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3341 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3342 | reg = FDI_RX_CTL(pipe); |
| 3343 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3344 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3345 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3346 | I915_WRITE(reg, temp); |
| 3347 | |
| 3348 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3349 | udelay(150); |
| 3350 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3351 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3352 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3353 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3354 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3355 | |
| 3356 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3357 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3358 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3359 | break; |
| 3360 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3361 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3362 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3363 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3364 | |
| 3365 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3366 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3367 | } |
| 3368 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3369 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3370 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3371 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3372 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3373 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3374 | }; |
| 3375 | |
| 3376 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3377 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3378 | { |
| 3379 | struct drm_device *dev = crtc->dev; |
| 3380 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3381 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3382 | int pipe = intel_crtc->pipe; |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3383 | u32 reg, temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3384 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3385 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3386 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3387 | reg = FDI_RX_IMR(pipe); |
| 3388 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3389 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3390 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3391 | I915_WRITE(reg, temp); |
| 3392 | |
| 3393 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3394 | udelay(150); |
| 3395 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3396 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3397 | reg = FDI_TX_CTL(pipe); |
| 3398 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3399 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3400 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3401 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3402 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3403 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3404 | /* SNB-B */ |
| 3405 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3406 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3407 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3408 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3409 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3410 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3411 | reg = FDI_RX_CTL(pipe); |
| 3412 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3413 | if (HAS_PCH_CPT(dev)) { |
| 3414 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3415 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3416 | } else { |
| 3417 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3418 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3419 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3420 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3421 | |
| 3422 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3423 | udelay(150); |
| 3424 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3425 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3426 | reg = FDI_TX_CTL(pipe); |
| 3427 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3428 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3429 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3430 | I915_WRITE(reg, temp); |
| 3431 | |
| 3432 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3433 | udelay(500); |
| 3434 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3435 | for (retry = 0; retry < 5; retry++) { |
| 3436 | reg = FDI_RX_IIR(pipe); |
| 3437 | temp = I915_READ(reg); |
| 3438 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3439 | if (temp & FDI_RX_BIT_LOCK) { |
| 3440 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3441 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3442 | break; |
| 3443 | } |
| 3444 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3445 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3446 | if (retry < 5) |
| 3447 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3448 | } |
| 3449 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3450 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3451 | |
| 3452 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3453 | reg = FDI_TX_CTL(pipe); |
| 3454 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3455 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3456 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3457 | if (IS_GEN6(dev)) { |
| 3458 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3459 | /* SNB-B */ |
| 3460 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3461 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3462 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3463 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3464 | reg = FDI_RX_CTL(pipe); |
| 3465 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3466 | if (HAS_PCH_CPT(dev)) { |
| 3467 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3468 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3469 | } else { |
| 3470 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3471 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3472 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3473 | I915_WRITE(reg, temp); |
| 3474 | |
| 3475 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3476 | udelay(150); |
| 3477 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3478 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3479 | reg = FDI_TX_CTL(pipe); |
| 3480 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3481 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3482 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3483 | I915_WRITE(reg, temp); |
| 3484 | |
| 3485 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3486 | udelay(500); |
| 3487 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3488 | for (retry = 0; retry < 5; retry++) { |
| 3489 | reg = FDI_RX_IIR(pipe); |
| 3490 | temp = I915_READ(reg); |
| 3491 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3492 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3493 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3494 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3495 | break; |
| 3496 | } |
| 3497 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3498 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3499 | if (retry < 5) |
| 3500 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3501 | } |
| 3502 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3503 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3504 | |
| 3505 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3506 | } |
| 3507 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3508 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3509 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3510 | { |
| 3511 | struct drm_device *dev = crtc->dev; |
| 3512 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3513 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3514 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3515 | u32 reg, temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3516 | |
| 3517 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3518 | for train result */ |
| 3519 | reg = FDI_RX_IMR(pipe); |
| 3520 | temp = I915_READ(reg); |
| 3521 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3522 | temp &= ~FDI_RX_BIT_LOCK; |
| 3523 | I915_WRITE(reg, temp); |
| 3524 | |
| 3525 | POSTING_READ(reg); |
| 3526 | udelay(150); |
| 3527 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3528 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3529 | I915_READ(FDI_RX_IIR(pipe))); |
| 3530 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3531 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3532 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3533 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3534 | reg = FDI_TX_CTL(pipe); |
| 3535 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3536 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3537 | temp &= ~FDI_TX_ENABLE; |
| 3538 | I915_WRITE(reg, temp); |
| 3539 | |
| 3540 | reg = FDI_RX_CTL(pipe); |
| 3541 | temp = I915_READ(reg); |
| 3542 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3543 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3544 | temp &= ~FDI_RX_ENABLE; |
| 3545 | I915_WRITE(reg, temp); |
| 3546 | |
| 3547 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3548 | reg = FDI_TX_CTL(pipe); |
| 3549 | temp = I915_READ(reg); |
| 3550 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3551 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3552 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3553 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3554 | temp |= snb_b_fdi_train_param[j/2]; |
| 3555 | temp |= FDI_COMPOSITE_SYNC; |
| 3556 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3557 | |
| 3558 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3559 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3560 | |
| 3561 | reg = FDI_RX_CTL(pipe); |
| 3562 | temp = I915_READ(reg); |
| 3563 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3564 | temp |= FDI_COMPOSITE_SYNC; |
| 3565 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3566 | |
| 3567 | POSTING_READ(reg); |
| 3568 | udelay(1); /* should be 0.5us */ |
| 3569 | |
| 3570 | for (i = 0; i < 4; i++) { |
| 3571 | reg = FDI_RX_IIR(pipe); |
| 3572 | temp = I915_READ(reg); |
| 3573 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3574 | |
| 3575 | if (temp & FDI_RX_BIT_LOCK || |
| 3576 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3577 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3578 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3579 | i); |
| 3580 | break; |
| 3581 | } |
| 3582 | udelay(1); /* should be 0.5us */ |
| 3583 | } |
| 3584 | if (i == 4) { |
| 3585 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3586 | continue; |
| 3587 | } |
| 3588 | |
| 3589 | /* Train 2 */ |
| 3590 | reg = FDI_TX_CTL(pipe); |
| 3591 | temp = I915_READ(reg); |
| 3592 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3593 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3594 | I915_WRITE(reg, temp); |
| 3595 | |
| 3596 | reg = FDI_RX_CTL(pipe); |
| 3597 | temp = I915_READ(reg); |
| 3598 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3599 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3600 | I915_WRITE(reg, temp); |
| 3601 | |
| 3602 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3603 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3604 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3605 | for (i = 0; i < 4; i++) { |
| 3606 | reg = FDI_RX_IIR(pipe); |
| 3607 | temp = I915_READ(reg); |
| 3608 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3609 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3610 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3611 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3612 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3613 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3614 | i); |
| 3615 | goto train_done; |
| 3616 | } |
| 3617 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3618 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3619 | if (i == 4) |
| 3620 | 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] | 3621 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3622 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3623 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3624 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3625 | } |
| 3626 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3627 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3628 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3629 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3630 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3631 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3632 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3633 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3634 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3635 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3636 | reg = FDI_RX_CTL(pipe); |
| 3637 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3638 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3639 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3640 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3641 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3642 | |
| 3643 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3644 | udelay(200); |
| 3645 | |
| 3646 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3647 | temp = I915_READ(reg); |
| 3648 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3649 | |
| 3650 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3651 | udelay(200); |
| 3652 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3653 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3654 | reg = FDI_TX_CTL(pipe); |
| 3655 | temp = I915_READ(reg); |
| 3656 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3657 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3658 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3659 | POSTING_READ(reg); |
| 3660 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3661 | } |
| 3662 | } |
| 3663 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3664 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3665 | { |
| 3666 | struct drm_device *dev = intel_crtc->base.dev; |
| 3667 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3668 | int pipe = intel_crtc->pipe; |
| 3669 | u32 reg, temp; |
| 3670 | |
| 3671 | /* Switch from PCDclk to Rawclk */ |
| 3672 | reg = FDI_RX_CTL(pipe); |
| 3673 | temp = I915_READ(reg); |
| 3674 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3675 | |
| 3676 | /* Disable CPU FDI TX PLL */ |
| 3677 | reg = FDI_TX_CTL(pipe); |
| 3678 | temp = I915_READ(reg); |
| 3679 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3680 | |
| 3681 | POSTING_READ(reg); |
| 3682 | udelay(100); |
| 3683 | |
| 3684 | reg = FDI_RX_CTL(pipe); |
| 3685 | temp = I915_READ(reg); |
| 3686 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3687 | |
| 3688 | /* Wait for the clocks to turn off. */ |
| 3689 | POSTING_READ(reg); |
| 3690 | udelay(100); |
| 3691 | } |
| 3692 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3693 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3694 | { |
| 3695 | struct drm_device *dev = crtc->dev; |
| 3696 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3697 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3698 | int pipe = intel_crtc->pipe; |
| 3699 | u32 reg, temp; |
| 3700 | |
| 3701 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3702 | reg = FDI_TX_CTL(pipe); |
| 3703 | temp = I915_READ(reg); |
| 3704 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3705 | POSTING_READ(reg); |
| 3706 | |
| 3707 | reg = FDI_RX_CTL(pipe); |
| 3708 | temp = I915_READ(reg); |
| 3709 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3710 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3711 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3712 | |
| 3713 | POSTING_READ(reg); |
| 3714 | udelay(100); |
| 3715 | |
| 3716 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3717 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3718 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3719 | |
| 3720 | /* still set train pattern 1 */ |
| 3721 | reg = FDI_TX_CTL(pipe); |
| 3722 | temp = I915_READ(reg); |
| 3723 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3724 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3725 | I915_WRITE(reg, temp); |
| 3726 | |
| 3727 | reg = FDI_RX_CTL(pipe); |
| 3728 | temp = I915_READ(reg); |
| 3729 | if (HAS_PCH_CPT(dev)) { |
| 3730 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3731 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3732 | } else { |
| 3733 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3734 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3735 | } |
| 3736 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3737 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3738 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3739 | I915_WRITE(reg, temp); |
| 3740 | |
| 3741 | POSTING_READ(reg); |
| 3742 | udelay(100); |
| 3743 | } |
| 3744 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3745 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3746 | { |
| 3747 | struct intel_crtc *crtc; |
| 3748 | |
| 3749 | /* Note that we don't need to be called with mode_config.lock here |
| 3750 | * as our list of CRTC objects is static for the lifetime of the |
| 3751 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3752 | * happily treat the predicates as racy, atomic checks as userspace |
| 3753 | * cannot claim and pin a new fb without at least acquring the |
| 3754 | * struct_mutex and so serialising with us. |
| 3755 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3756 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3757 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3758 | continue; |
| 3759 | |
| 3760 | if (crtc->unpin_work) |
| 3761 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3762 | |
| 3763 | return true; |
| 3764 | } |
| 3765 | |
| 3766 | return false; |
| 3767 | } |
| 3768 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3769 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
| 3770 | { |
| 3771 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 3772 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 3773 | |
| 3774 | /* ensure that the unpin work is consistent wrt ->pending. */ |
| 3775 | smp_rmb(); |
| 3776 | intel_crtc->unpin_work = NULL; |
| 3777 | |
| 3778 | if (work->event) |
| 3779 | drm_send_vblank_event(intel_crtc->base.dev, |
| 3780 | intel_crtc->pipe, |
| 3781 | work->event); |
| 3782 | |
| 3783 | drm_crtc_vblank_put(&intel_crtc->base); |
| 3784 | |
| 3785 | wake_up_all(&dev_priv->pending_flip_queue); |
| 3786 | queue_work(dev_priv->wq, &work->work); |
| 3787 | |
| 3788 | trace_i915_flip_complete(intel_crtc->plane, |
| 3789 | work->pending_flip_obj); |
| 3790 | } |
| 3791 | |
Ville Syrjälä | 46a55d3 | 2014-05-21 14:04:46 +0300 | [diff] [blame] | 3792 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3793 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3794 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3795 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3796 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3797 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3798 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
| 3799 | !intel_crtc_has_pending_flip(crtc), |
| 3800 | 60*HZ) == 0)) { |
| 3801 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3802 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3803 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3804 | if (intel_crtc->unpin_work) { |
| 3805 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 3806 | page_flip_completed(intel_crtc); |
| 3807 | } |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3808 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3809 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3810 | |
Chris Wilson | 975d568 | 2014-08-20 13:13:34 +0100 | [diff] [blame] | 3811 | if (crtc->primary->fb) { |
| 3812 | mutex_lock(&dev->struct_mutex); |
| 3813 | intel_finish_fb(crtc->primary->fb); |
| 3814 | mutex_unlock(&dev->struct_mutex); |
| 3815 | } |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3816 | } |
| 3817 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3818 | /* Program iCLKIP clock to the desired frequency */ |
| 3819 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3820 | { |
| 3821 | struct drm_device *dev = crtc->dev; |
| 3822 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3823 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3824 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3825 | u32 temp; |
| 3826 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3827 | mutex_lock(&dev_priv->dpio_lock); |
| 3828 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3829 | /* It is necessary to ungate the pixclk gate prior to programming |
| 3830 | * the divisors, and gate it back when it is done. |
| 3831 | */ |
| 3832 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3833 | |
| 3834 | /* Disable SSCCTL */ |
| 3835 | intel_sbi_write(dev_priv, SBI_SSCCTL6, |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3836 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
| 3837 | SBI_SSCCTL_DISABLE, |
| 3838 | SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3839 | |
| 3840 | /* 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] | 3841 | if (clock == 20000) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3842 | auxdiv = 1; |
| 3843 | divsel = 0x41; |
| 3844 | phaseinc = 0x20; |
| 3845 | } else { |
| 3846 | /* The iCLK virtual clock root frequency is in MHz, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 3847 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3848 | * divisors, it is necessary to divide one by another, so we |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3849 | * convert the virtual clock precision to KHz here for higher |
| 3850 | * precision. |
| 3851 | */ |
| 3852 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3853 | u32 iclk_pi_range = 64; |
| 3854 | u32 desired_divisor, msb_divisor_value, pi_value; |
| 3855 | |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 3856 | desired_divisor = (iclk_virtual_root_freq / clock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3857 | msb_divisor_value = desired_divisor / iclk_pi_range; |
| 3858 | pi_value = desired_divisor % iclk_pi_range; |
| 3859 | |
| 3860 | auxdiv = 0; |
| 3861 | divsel = msb_divisor_value - 2; |
| 3862 | phaseinc = pi_value; |
| 3863 | } |
| 3864 | |
| 3865 | /* This should not happen with any sane values */ |
| 3866 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 3867 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 3868 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 3869 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 3870 | |
| 3871 | 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] | 3872 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3873 | auxdiv, |
| 3874 | divsel, |
| 3875 | phasedir, |
| 3876 | phaseinc); |
| 3877 | |
| 3878 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3879 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3880 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3881 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3882 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3883 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3884 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3885 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3886 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3887 | |
| 3888 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3889 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3890 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3891 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3892 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3893 | |
| 3894 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3895 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3896 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3897 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3898 | |
| 3899 | /* Wait for initialization time */ |
| 3900 | udelay(24); |
| 3901 | |
| 3902 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3903 | |
| 3904 | mutex_unlock(&dev_priv->dpio_lock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3905 | } |
| 3906 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3907 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 3908 | enum pipe pch_transcoder) |
| 3909 | { |
| 3910 | struct drm_device *dev = crtc->base.dev; |
| 3911 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3912 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3913 | |
| 3914 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 3915 | I915_READ(HTOTAL(cpu_transcoder))); |
| 3916 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 3917 | I915_READ(HBLANK(cpu_transcoder))); |
| 3918 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 3919 | I915_READ(HSYNC(cpu_transcoder))); |
| 3920 | |
| 3921 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 3922 | I915_READ(VTOTAL(cpu_transcoder))); |
| 3923 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 3924 | I915_READ(VBLANK(cpu_transcoder))); |
| 3925 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 3926 | I915_READ(VSYNC(cpu_transcoder))); |
| 3927 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 3928 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 3929 | } |
| 3930 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3931 | 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] | 3932 | { |
| 3933 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3934 | uint32_t temp; |
| 3935 | |
| 3936 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3937 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3938 | return; |
| 3939 | |
| 3940 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 3941 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 3942 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3943 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 3944 | if (enable) |
| 3945 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 3946 | |
| 3947 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3948 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 3949 | POSTING_READ(SOUTH_CHICKEN1); |
| 3950 | } |
| 3951 | |
| 3952 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 3953 | { |
| 3954 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3955 | |
| 3956 | switch (intel_crtc->pipe) { |
| 3957 | case PIPE_A: |
| 3958 | break; |
| 3959 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3960 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3961 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3962 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3963 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3964 | |
| 3965 | break; |
| 3966 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3967 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3968 | |
| 3969 | break; |
| 3970 | default: |
| 3971 | BUG(); |
| 3972 | } |
| 3973 | } |
| 3974 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 3975 | /* |
| 3976 | * Enable PCH resources required for PCH ports: |
| 3977 | * - PCH PLLs |
| 3978 | * - FDI training & RX/TX |
| 3979 | * - update transcoder timings |
| 3980 | * - DP transcoding bits |
| 3981 | * - transcoder |
| 3982 | */ |
| 3983 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 3984 | { |
| 3985 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 3986 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3987 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3988 | int pipe = intel_crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 3989 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 3990 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 3991 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 3992 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3993 | if (IS_IVYBRIDGE(dev)) |
| 3994 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 3995 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 3996 | /* Write the TU size bits before fdi link training, so that error |
| 3997 | * detection works. */ |
| 3998 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 3999 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4000 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4001 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 4002 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4003 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4004 | /* We need to program the right clock selection before writing the pixel |
| 4005 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4006 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4007 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4008 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4009 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4010 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4011 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4012 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4013 | temp |= sel; |
| 4014 | else |
| 4015 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4016 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4017 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4018 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4019 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4020 | * transcoder, and we actually should do this to not upset any PCH |
| 4021 | * transcoder that already use the clock when we share it. |
| 4022 | * |
| 4023 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4024 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4025 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 4026 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4027 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4028 | /* set transcoder timing, panel must allow it */ |
| 4029 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4030 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4031 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4032 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4033 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4034 | /* For PCH DP, enable TRANS_DP_CTL */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4035 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4036 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4037 | reg = TRANS_DP_CTL(pipe); |
| 4038 | temp = I915_READ(reg); |
| 4039 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4040 | TRANS_DP_SYNC_MASK | |
| 4041 | TRANS_DP_BPC_MASK); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4042 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
| 4043 | TRANS_DP_ENH_FRAMING); |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4044 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4045 | |
| 4046 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4047 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4048 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4049 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4050 | |
| 4051 | switch (intel_trans_dp_port_sel(crtc)) { |
| 4052 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4053 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4054 | break; |
| 4055 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4056 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4057 | break; |
| 4058 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4059 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4060 | break; |
| 4061 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 4062 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4063 | } |
| 4064 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4065 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4066 | } |
| 4067 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 4068 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4069 | } |
| 4070 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4071 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 4072 | { |
| 4073 | struct drm_device *dev = crtc->dev; |
| 4074 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4075 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4076 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4077 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4078 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4079 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4080 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4081 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4082 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4083 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4084 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4085 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4086 | } |
| 4087 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 4088 | void intel_put_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4089 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4090 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4091 | |
| 4092 | if (pll == NULL) |
| 4093 | return; |
| 4094 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 4095 | if (!(pll->config.crtc_mask & (1 << crtc->pipe))) { |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 4096 | WARN(1, "bad %s crtc mask\n", pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4097 | return; |
| 4098 | } |
| 4099 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 4100 | pll->config.crtc_mask &= ~(1 << crtc->pipe); |
| 4101 | if (pll->config.crtc_mask == 0) { |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 4102 | WARN_ON(pll->on); |
| 4103 | WARN_ON(pll->active); |
| 4104 | } |
| 4105 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4106 | crtc->config->shared_dpll = DPLL_ID_PRIVATE; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4107 | } |
| 4108 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4109 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
| 4110 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4111 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4112 | 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] | 4113 | struct intel_shared_dpll *pll; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4114 | enum intel_dpll_id i; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4115 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4116 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 4117 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 4118 | i = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4119 | pll = &dev_priv->shared_dplls[i]; |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4120 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4121 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 4122 | crtc->base.base.id, pll->name); |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4123 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4124 | WARN_ON(pll->new_config->crtc_mask); |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4125 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4126 | goto found; |
| 4127 | } |
| 4128 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4129 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4130 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4131 | |
| 4132 | /* Only want to check enabled timings first */ |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4133 | if (pll->new_config->crtc_mask == 0) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4134 | continue; |
| 4135 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4136 | if (memcmp(&crtc_state->dpll_hw_state, |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4137 | &pll->new_config->hw_state, |
| 4138 | sizeof(pll->new_config->hw_state)) == 0) { |
| 4139 | 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] | 4140 | crtc->base.base.id, pll->name, |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4141 | pll->new_config->crtc_mask, |
| 4142 | pll->active); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4143 | goto found; |
| 4144 | } |
| 4145 | } |
| 4146 | |
| 4147 | /* Ok no matching timings, maybe there's a free one? */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4148 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4149 | pll = &dev_priv->shared_dplls[i]; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4150 | if (pll->new_config->crtc_mask == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4151 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
| 4152 | crtc->base.base.id, pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4153 | goto found; |
| 4154 | } |
| 4155 | } |
| 4156 | |
| 4157 | return NULL; |
| 4158 | |
| 4159 | found: |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4160 | if (pll->new_config->crtc_mask == 0) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4161 | pll->new_config->hw_state = crtc_state->dpll_hw_state; |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4162 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4163 | crtc_state->shared_dpll = i; |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4164 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
| 4165 | pipe_name(crtc->pipe)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 4166 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4167 | pll->new_config->crtc_mask |= 1 << crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4168 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4169 | return pll; |
| 4170 | } |
| 4171 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4172 | /** |
| 4173 | * intel_shared_dpll_start_config - start a new PLL staged config |
| 4174 | * @dev_priv: DRM device |
| 4175 | * @clear_pipes: mask of pipes that will have their PLLs freed |
| 4176 | * |
| 4177 | * Starts a new PLL staged config, copying the current config but |
| 4178 | * releasing the references of pipes specified in clear_pipes. |
| 4179 | */ |
| 4180 | static int intel_shared_dpll_start_config(struct drm_i915_private *dev_priv, |
| 4181 | unsigned clear_pipes) |
| 4182 | { |
| 4183 | struct intel_shared_dpll *pll; |
| 4184 | enum intel_dpll_id i; |
| 4185 | |
| 4186 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4187 | pll = &dev_priv->shared_dplls[i]; |
| 4188 | |
| 4189 | pll->new_config = kmemdup(&pll->config, sizeof pll->config, |
| 4190 | GFP_KERNEL); |
| 4191 | if (!pll->new_config) |
| 4192 | goto cleanup; |
| 4193 | |
| 4194 | pll->new_config->crtc_mask &= ~clear_pipes; |
| 4195 | } |
| 4196 | |
| 4197 | return 0; |
| 4198 | |
| 4199 | cleanup: |
| 4200 | while (--i >= 0) { |
| 4201 | pll = &dev_priv->shared_dplls[i]; |
Ander Conselvan de Oliveira | f354d73 | 2014-11-07 14:07:41 +0200 | [diff] [blame] | 4202 | kfree(pll->new_config); |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4203 | pll->new_config = NULL; |
| 4204 | } |
| 4205 | |
| 4206 | return -ENOMEM; |
| 4207 | } |
| 4208 | |
| 4209 | static void intel_shared_dpll_commit(struct drm_i915_private *dev_priv) |
| 4210 | { |
| 4211 | struct intel_shared_dpll *pll; |
| 4212 | enum intel_dpll_id i; |
| 4213 | |
| 4214 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4215 | pll = &dev_priv->shared_dplls[i]; |
| 4216 | |
| 4217 | WARN_ON(pll->new_config == &pll->config); |
| 4218 | |
| 4219 | pll->config = *pll->new_config; |
| 4220 | kfree(pll->new_config); |
| 4221 | pll->new_config = NULL; |
| 4222 | } |
| 4223 | } |
| 4224 | |
| 4225 | static void intel_shared_dpll_abort_config(struct drm_i915_private *dev_priv) |
| 4226 | { |
| 4227 | struct intel_shared_dpll *pll; |
| 4228 | enum intel_dpll_id i; |
| 4229 | |
| 4230 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4231 | pll = &dev_priv->shared_dplls[i]; |
| 4232 | |
| 4233 | WARN_ON(pll->new_config == &pll->config); |
| 4234 | |
| 4235 | kfree(pll->new_config); |
| 4236 | pll->new_config = NULL; |
| 4237 | } |
| 4238 | } |
| 4239 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4240 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4241 | { |
| 4242 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 4243 | int dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4244 | u32 temp; |
| 4245 | |
| 4246 | temp = I915_READ(dslreg); |
| 4247 | udelay(500); |
| 4248 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4249 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4250 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4251 | } |
| 4252 | } |
| 4253 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4254 | static void skylake_pfit_enable(struct intel_crtc *crtc) |
| 4255 | { |
| 4256 | struct drm_device *dev = crtc->base.dev; |
| 4257 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4258 | int pipe = crtc->pipe; |
| 4259 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4260 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4261 | I915_WRITE(PS_CTL(pipe), PS_ENABLE); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4262 | I915_WRITE(PS_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4263 | I915_WRITE(PS_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4264 | } |
| 4265 | } |
| 4266 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4267 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4268 | { |
| 4269 | struct drm_device *dev = crtc->base.dev; |
| 4270 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4271 | int pipe = crtc->pipe; |
| 4272 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4273 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4274 | /* Force use of hard-coded filter coefficients |
| 4275 | * as some pre-programmed values are broken, |
| 4276 | * e.g. x201. |
| 4277 | */ |
| 4278 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 4279 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4280 | PF_PIPE_SEL_IVB(pipe)); |
| 4281 | else |
| 4282 | 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] | 4283 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4284 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4285 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4286 | } |
| 4287 | |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4288 | static void intel_enable_sprite_planes(struct drm_crtc *crtc) |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4289 | { |
| 4290 | struct drm_device *dev = crtc->dev; |
| 4291 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4292 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4293 | struct intel_plane *intel_plane; |
| 4294 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4295 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 4296 | intel_plane = to_intel_plane(plane); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4297 | if (intel_plane->pipe == pipe) |
| 4298 | intel_plane_restore(&intel_plane->base); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4299 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4300 | } |
| 4301 | |
Matt Roper | 0d703d4 | 2015-03-04 10:49:04 -0800 | [diff] [blame] | 4302 | /* |
| 4303 | * Disable a plane internally without actually modifying the plane's state. |
| 4304 | * This will allow us to easily restore the plane later by just reprogramming |
| 4305 | * its state. |
| 4306 | */ |
| 4307 | static void disable_plane_internal(struct drm_plane *plane) |
| 4308 | { |
| 4309 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 4310 | struct drm_plane_state *state = |
| 4311 | plane->funcs->atomic_duplicate_state(plane); |
| 4312 | struct intel_plane_state *intel_state = to_intel_plane_state(state); |
| 4313 | |
| 4314 | intel_state->visible = false; |
| 4315 | intel_plane->commit_plane(plane, intel_state); |
| 4316 | |
| 4317 | intel_plane_destroy_state(plane, state); |
| 4318 | } |
| 4319 | |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4320 | static void intel_disable_sprite_planes(struct drm_crtc *crtc) |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4321 | { |
| 4322 | struct drm_device *dev = crtc->dev; |
| 4323 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4324 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4325 | struct intel_plane *intel_plane; |
| 4326 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4327 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 4328 | intel_plane = to_intel_plane(plane); |
Matt Roper | 0d703d4 | 2015-03-04 10:49:04 -0800 | [diff] [blame] | 4329 | if (plane->fb && intel_plane->pipe == pipe) |
| 4330 | disable_plane_internal(plane); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4331 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4332 | } |
| 4333 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4334 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4335 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4336 | struct drm_device *dev = crtc->base.dev; |
| 4337 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4338 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4339 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4340 | return; |
| 4341 | |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4342 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
| 4343 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4344 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4345 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4346 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4347 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4348 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 4349 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4350 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4351 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4352 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4353 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4354 | */ |
| 4355 | } else { |
| 4356 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4357 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4358 | * is essentially intel_wait_for_vblank. If we don't have this |
| 4359 | * and don't wait for vblanks until the end of crtc_enable, then |
| 4360 | * the HW state readout code will complain that the expected |
| 4361 | * IPS_CTL value is not the one we read. */ |
| 4362 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 4363 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 4364 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4365 | } |
| 4366 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4367 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4368 | { |
| 4369 | struct drm_device *dev = crtc->base.dev; |
| 4370 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4371 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4372 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4373 | return; |
| 4374 | |
| 4375 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4376 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4377 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4378 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 4379 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4380 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 4381 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 4382 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4383 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4384 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4385 | POSTING_READ(IPS_CTL); |
| 4386 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4387 | |
| 4388 | /* We need to wait for a vblank before we can disable the plane. */ |
| 4389 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4390 | } |
| 4391 | |
| 4392 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 4393 | static void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 4394 | { |
| 4395 | struct drm_device *dev = crtc->dev; |
| 4396 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4397 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4398 | enum pipe pipe = intel_crtc->pipe; |
| 4399 | int palreg = PALETTE(pipe); |
| 4400 | int i; |
| 4401 | bool reenable_ips = false; |
| 4402 | |
| 4403 | /* The clocks have to be on to load the palette. */ |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4404 | if (!crtc->state->enable || !intel_crtc->active) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4405 | return; |
| 4406 | |
| 4407 | if (!HAS_PCH_SPLIT(dev_priv->dev)) { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 4408 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4409 | assert_dsi_pll_enabled(dev_priv); |
| 4410 | else |
| 4411 | assert_pll_enabled(dev_priv, pipe); |
| 4412 | } |
| 4413 | |
| 4414 | /* use legacy palette for Ironlake */ |
Sonika Jindal | 7a1db49 | 2014-07-22 11:18:27 +0530 | [diff] [blame] | 4415 | if (!HAS_GMCH_DISPLAY(dev)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4416 | palreg = LGC_PALETTE(pipe); |
| 4417 | |
| 4418 | /* Workaround : Do not read or write the pipe palette/gamma data while |
| 4419 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 4420 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4421 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4422 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
| 4423 | GAMMA_MODE_MODE_SPLIT)) { |
| 4424 | hsw_disable_ips(intel_crtc); |
| 4425 | reenable_ips = true; |
| 4426 | } |
| 4427 | |
| 4428 | for (i = 0; i < 256; i++) { |
| 4429 | I915_WRITE(palreg + 4 * i, |
| 4430 | (intel_crtc->lut_r[i] << 16) | |
| 4431 | (intel_crtc->lut_g[i] << 8) | |
| 4432 | intel_crtc->lut_b[i]); |
| 4433 | } |
| 4434 | |
| 4435 | if (reenable_ips) |
| 4436 | hsw_enable_ips(intel_crtc); |
| 4437 | } |
| 4438 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4439 | static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable) |
| 4440 | { |
| 4441 | if (!enable && intel_crtc->overlay) { |
| 4442 | struct drm_device *dev = intel_crtc->base.dev; |
| 4443 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4444 | |
| 4445 | mutex_lock(&dev->struct_mutex); |
| 4446 | dev_priv->mm.interruptible = false; |
| 4447 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 4448 | dev_priv->mm.interruptible = true; |
| 4449 | mutex_unlock(&dev->struct_mutex); |
| 4450 | } |
| 4451 | |
| 4452 | /* Let userspace switch the overlay on again. In most cases userspace |
| 4453 | * has to recompute where to put it anyway. |
| 4454 | */ |
| 4455 | } |
| 4456 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4457 | static void intel_crtc_enable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4458 | { |
| 4459 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4460 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4461 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4462 | |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 4463 | intel_enable_primary_hw_plane(crtc->primary, crtc); |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4464 | intel_enable_sprite_planes(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4465 | intel_crtc_update_cursor(crtc, true); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4466 | intel_crtc_dpms_overlay(intel_crtc, true); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4467 | |
| 4468 | hsw_enable_ips(intel_crtc); |
| 4469 | |
| 4470 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4471 | intel_fbc_update(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4472 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4473 | |
| 4474 | /* |
| 4475 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4476 | * to compute the mask of flip planes precisely. For the time being |
| 4477 | * consider this a flip from a NULL plane. |
| 4478 | */ |
| 4479 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4480 | } |
| 4481 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4482 | static void intel_crtc_disable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4483 | { |
| 4484 | struct drm_device *dev = crtc->dev; |
| 4485 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4486 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4487 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4488 | |
| 4489 | intel_crtc_wait_for_pending_flips(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4490 | |
Paulo Zanoni | e35fef2 | 2015-02-09 14:46:29 -0200 | [diff] [blame] | 4491 | if (dev_priv->fbc.crtc == intel_crtc) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4492 | intel_fbc_disable(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4493 | |
| 4494 | hsw_disable_ips(intel_crtc); |
| 4495 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4496 | intel_crtc_dpms_overlay(intel_crtc, false); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4497 | intel_crtc_update_cursor(crtc, false); |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4498 | intel_disable_sprite_planes(crtc); |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 4499 | intel_disable_primary_hw_plane(crtc->primary, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4500 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4501 | /* |
| 4502 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4503 | * to compute the mask of flip planes precisely. For the time being |
| 4504 | * consider this a flip to a NULL plane. |
| 4505 | */ |
| 4506 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4507 | } |
| 4508 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4509 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4510 | { |
| 4511 | struct drm_device *dev = crtc->dev; |
| 4512 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4513 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4514 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4515 | int pipe = intel_crtc->pipe; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4516 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4517 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 4518 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4519 | if (intel_crtc->active) |
| 4520 | return; |
| 4521 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4522 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4523 | intel_prepare_shared_dpll(intel_crtc); |
| 4524 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4525 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4526 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4527 | |
| 4528 | intel_set_pipe_timings(intel_crtc); |
| 4529 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4530 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4531 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4532 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4533 | } |
| 4534 | |
| 4535 | ironlake_set_pipeconf(crtc); |
| 4536 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4537 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4538 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4539 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4540 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4541 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4542 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4543 | if (encoder->pre_enable) |
| 4544 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4545 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4546 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4547 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4548 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4549 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4550 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4551 | } else { |
| 4552 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4553 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4554 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4555 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4556 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4557 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4558 | /* |
| 4559 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4560 | * clocks enabled |
| 4561 | */ |
| 4562 | intel_crtc_load_lut(crtc); |
| 4563 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4564 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4565 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4566 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4567 | if (intel_crtc->config->has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4568 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4569 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4570 | assert_vblank_disabled(crtc); |
| 4571 | drm_crtc_vblank_on(crtc); |
| 4572 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4573 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4574 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4575 | |
| 4576 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4577 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Daniel Vetter | 6ce9410 | 2012-10-04 19:20:03 +0200 | [diff] [blame] | 4578 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4579 | intel_crtc_enable_planes(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4580 | } |
| 4581 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4582 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4583 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4584 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4585 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4586 | } |
| 4587 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4588 | /* |
| 4589 | * This implements the workaround described in the "notes" section of the mode |
| 4590 | * set sequence documentation. When going from no pipes or single pipe to |
| 4591 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 4592 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 4593 | */ |
| 4594 | static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc) |
| 4595 | { |
| 4596 | struct drm_device *dev = crtc->base.dev; |
| 4597 | struct intel_crtc *crtc_it, *other_active_crtc = NULL; |
| 4598 | |
| 4599 | /* We want to get the other_active_crtc only if there's only 1 other |
| 4600 | * active crtc. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4601 | for_each_intel_crtc(dev, crtc_it) { |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4602 | if (!crtc_it->active || crtc_it == crtc) |
| 4603 | continue; |
| 4604 | |
| 4605 | if (other_active_crtc) |
| 4606 | return; |
| 4607 | |
| 4608 | other_active_crtc = crtc_it; |
| 4609 | } |
| 4610 | if (!other_active_crtc) |
| 4611 | return; |
| 4612 | |
| 4613 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4614 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4615 | } |
| 4616 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4617 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 4618 | { |
| 4619 | struct drm_device *dev = crtc->dev; |
| 4620 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4621 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4622 | struct intel_encoder *encoder; |
| 4623 | int pipe = intel_crtc->pipe; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4624 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4625 | WARN_ON(!crtc->state->enable); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4626 | |
| 4627 | if (intel_crtc->active) |
| 4628 | return; |
| 4629 | |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4630 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4631 | intel_enable_shared_dpll(intel_crtc); |
| 4632 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4633 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4634 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4635 | |
| 4636 | intel_set_pipe_timings(intel_crtc); |
| 4637 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4638 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
| 4639 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), |
| 4640 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 4641 | } |
| 4642 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4643 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4644 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4645 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4646 | } |
| 4647 | |
| 4648 | haswell_set_pipeconf(crtc); |
| 4649 | |
| 4650 | intel_set_pipe_csc(crtc); |
| 4651 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4652 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4653 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4654 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4655 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4656 | if (encoder->pre_enable) |
| 4657 | encoder->pre_enable(encoder); |
| 4658 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4659 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4660 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4661 | true); |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4662 | dev_priv->display.fdi_link_train(crtc); |
| 4663 | } |
| 4664 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4665 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4666 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4667 | if (IS_SKYLAKE(dev)) |
| 4668 | skylake_pfit_enable(intel_crtc); |
| 4669 | else |
| 4670 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4671 | |
| 4672 | /* |
| 4673 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4674 | * clocks enabled |
| 4675 | */ |
| 4676 | intel_crtc_load_lut(crtc); |
| 4677 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4678 | intel_ddi_set_pipe_settings(crtc); |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 4679 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4680 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4681 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4682 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4683 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4684 | if (intel_crtc->config->has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4685 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4686 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4687 | if (intel_crtc->config->dp_encoder_is_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4688 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 4689 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4690 | assert_vblank_disabled(crtc); |
| 4691 | drm_crtc_vblank_on(crtc); |
| 4692 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4693 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4694 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4695 | intel_opregion_notify_encoder(encoder, true); |
| 4696 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4697 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4698 | /* If we change the relative order between pipe/planes enabling, we need |
| 4699 | * to change the workaround. */ |
| 4700 | haswell_mode_set_planes_workaround(intel_crtc); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4701 | intel_crtc_enable_planes(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4702 | } |
| 4703 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4704 | static void skylake_pfit_disable(struct intel_crtc *crtc) |
| 4705 | { |
| 4706 | struct drm_device *dev = crtc->base.dev; |
| 4707 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4708 | int pipe = crtc->pipe; |
| 4709 | |
| 4710 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4711 | * 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] | 4712 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4713 | I915_WRITE(PS_CTL(pipe), 0); |
| 4714 | I915_WRITE(PS_WIN_POS(pipe), 0); |
| 4715 | I915_WRITE(PS_WIN_SZ(pipe), 0); |
| 4716 | } |
| 4717 | } |
| 4718 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4719 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
| 4720 | { |
| 4721 | struct drm_device *dev = crtc->base.dev; |
| 4722 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4723 | int pipe = crtc->pipe; |
| 4724 | |
| 4725 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4726 | * 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] | 4727 | if (crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4728 | I915_WRITE(PF_CTL(pipe), 0); |
| 4729 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 4730 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 4731 | } |
| 4732 | } |
| 4733 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4734 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 4735 | { |
| 4736 | struct drm_device *dev = crtc->dev; |
| 4737 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4738 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4739 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4740 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4741 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4742 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4743 | if (!intel_crtc->active) |
| 4744 | return; |
| 4745 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4746 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4747 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4748 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4749 | encoder->disable(encoder); |
| 4750 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4751 | drm_crtc_vblank_off(crtc); |
| 4752 | assert_vblank_disabled(crtc); |
| 4753 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4754 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4755 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4756 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4757 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4758 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4759 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4760 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 4761 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4762 | if (encoder->post_disable) |
| 4763 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4764 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4765 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4766 | ironlake_fdi_disable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4767 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4768 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4769 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4770 | if (HAS_PCH_CPT(dev)) { |
| 4771 | /* disable TRANS_DP_CTL */ |
| 4772 | reg = TRANS_DP_CTL(pipe); |
| 4773 | temp = I915_READ(reg); |
| 4774 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 4775 | TRANS_DP_PORT_SEL_MASK); |
| 4776 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 4777 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4778 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4779 | /* disable DPLL_SEL */ |
| 4780 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4781 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4782 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 4783 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4784 | |
| 4785 | /* disable PCH DPLL */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4786 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4787 | |
| 4788 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4789 | } |
| 4790 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4791 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4792 | intel_update_watermarks(crtc); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4793 | |
| 4794 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4795 | intel_fbc_update(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4796 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4797 | } |
| 4798 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4799 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 4800 | { |
| 4801 | struct drm_device *dev = crtc->dev; |
| 4802 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4803 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4804 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4805 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4806 | |
| 4807 | if (!intel_crtc->active) |
| 4808 | return; |
| 4809 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4810 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | dda9a66 | 2013-09-19 17:00:37 -0300 | [diff] [blame] | 4811 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4812 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 4813 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4814 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4815 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4816 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4817 | drm_crtc_vblank_off(crtc); |
| 4818 | assert_vblank_disabled(crtc); |
| 4819 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4820 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4821 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4822 | false); |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4823 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4824 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4825 | if (intel_crtc->config->dp_encoder_is_mst) |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 4826 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 4827 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 4828 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4829 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4830 | if (IS_SKYLAKE(dev)) |
| 4831 | skylake_pfit_disable(intel_crtc); |
| 4832 | else |
| 4833 | ironlake_pfit_disable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4834 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4835 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4836 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4837 | if (intel_crtc->config->has_pch_encoder) { |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 4838 | lpt_disable_pch_transcoder(dev_priv); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 4839 | intel_ddi_fdi_disable(crtc); |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 4840 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4841 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 4842 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4843 | if (encoder->post_disable) |
| 4844 | encoder->post_disable(encoder); |
| 4845 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4846 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4847 | intel_update_watermarks(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4848 | |
| 4849 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4850 | intel_fbc_update(dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4851 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4852 | |
| 4853 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4854 | intel_disable_shared_dpll(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4855 | } |
| 4856 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4857 | static void ironlake_crtc_off(struct drm_crtc *crtc) |
| 4858 | { |
| 4859 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4860 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4861 | } |
| 4862 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 4863 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4864 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 4865 | { |
| 4866 | struct drm_device *dev = crtc->base.dev; |
| 4867 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4868 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4869 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 4870 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4871 | return; |
| 4872 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 4873 | /* |
| 4874 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 4875 | * according to register description and PRM. |
| 4876 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4877 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 4878 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 4879 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4880 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 4881 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 4882 | |
| 4883 | /* Border color in case we don't scale up to the full screen. Black by |
| 4884 | * default, change to something else for debugging. */ |
| 4885 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4886 | } |
| 4887 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4888 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 4889 | { |
| 4890 | switch (port) { |
| 4891 | case PORT_A: |
| 4892 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; |
| 4893 | case PORT_B: |
| 4894 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; |
| 4895 | case PORT_C: |
| 4896 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; |
| 4897 | case PORT_D: |
| 4898 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; |
| 4899 | default: |
| 4900 | WARN_ON_ONCE(1); |
| 4901 | return POWER_DOMAIN_PORT_OTHER; |
| 4902 | } |
| 4903 | } |
| 4904 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4905 | #define for_each_power_domain(domain, mask) \ |
| 4906 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ |
| 4907 | if ((1 << (domain)) & (mask)) |
| 4908 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4909 | enum intel_display_power_domain |
| 4910 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4911 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4912 | struct drm_device *dev = intel_encoder->base.dev; |
| 4913 | struct intel_digital_port *intel_dig_port; |
| 4914 | |
| 4915 | switch (intel_encoder->type) { |
| 4916 | case INTEL_OUTPUT_UNKNOWN: |
| 4917 | /* Only DDI platforms should ever use this output type */ |
| 4918 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 4919 | case INTEL_OUTPUT_DISPLAYPORT: |
| 4920 | case INTEL_OUTPUT_HDMI: |
| 4921 | case INTEL_OUTPUT_EDP: |
| 4922 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4923 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4924 | case INTEL_OUTPUT_DP_MST: |
| 4925 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 4926 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4927 | case INTEL_OUTPUT_ANALOG: |
| 4928 | return POWER_DOMAIN_PORT_CRT; |
| 4929 | case INTEL_OUTPUT_DSI: |
| 4930 | return POWER_DOMAIN_PORT_DSI; |
| 4931 | default: |
| 4932 | return POWER_DOMAIN_PORT_OTHER; |
| 4933 | } |
| 4934 | } |
| 4935 | |
| 4936 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) |
| 4937 | { |
| 4938 | struct drm_device *dev = crtc->dev; |
| 4939 | struct intel_encoder *intel_encoder; |
| 4940 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4941 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4942 | unsigned long mask; |
| 4943 | enum transcoder transcoder; |
| 4944 | |
| 4945 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); |
| 4946 | |
| 4947 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 4948 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4949 | if (intel_crtc->config->pch_pfit.enabled || |
| 4950 | intel_crtc->config->pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4951 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 4952 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4953 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 4954 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
| 4955 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4956 | return mask; |
| 4957 | } |
| 4958 | |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 4959 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4960 | { |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 4961 | struct drm_device *dev = state->dev; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4962 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4963 | unsigned long pipe_domains[I915_MAX_PIPES] = { 0, }; |
| 4964 | struct intel_crtc *crtc; |
| 4965 | |
| 4966 | /* |
| 4967 | * First get all needed power domains, then put all unneeded, to avoid |
| 4968 | * any unnecessary toggling of the power wells. |
| 4969 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4970 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4971 | enum intel_display_power_domain domain; |
| 4972 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4973 | if (!crtc->base.state->enable) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4974 | continue; |
| 4975 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4976 | pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4977 | |
| 4978 | for_each_power_domain(domain, pipe_domains[crtc->pipe]) |
| 4979 | intel_display_power_get(dev_priv, domain); |
| 4980 | } |
| 4981 | |
Ville Syrjälä | 50f6e50 | 2014-11-06 14:49:12 +0200 | [diff] [blame] | 4982 | if (dev_priv->display.modeset_global_resources) |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 4983 | dev_priv->display.modeset_global_resources(state); |
Ville Syrjälä | 50f6e50 | 2014-11-06 14:49:12 +0200 | [diff] [blame] | 4984 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4985 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4986 | enum intel_display_power_domain domain; |
| 4987 | |
| 4988 | for_each_power_domain(domain, crtc->enabled_power_domains) |
| 4989 | intel_display_power_put(dev_priv, domain); |
| 4990 | |
| 4991 | crtc->enabled_power_domains = pipe_domains[crtc->pipe]; |
| 4992 | } |
| 4993 | |
| 4994 | intel_display_set_init_power(dev_priv, false); |
| 4995 | } |
| 4996 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 4997 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 4998 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 4999 | { |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 5000 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5001 | |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 5002 | /* Obtain SKU information */ |
| 5003 | mutex_lock(&dev_priv->dpio_lock); |
| 5004 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 5005 | CCK_FUSE_HPLL_FREQ_MASK; |
| 5006 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5007 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5008 | return vco_freq[hpll_freq] * 1000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5009 | } |
| 5010 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5011 | static void vlv_update_cdclk(struct drm_device *dev) |
| 5012 | { |
| 5013 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5014 | |
| 5015 | 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] | 5016 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5017 | dev_priv->vlv_cdclk_freq); |
| 5018 | |
| 5019 | /* |
| 5020 | * Program the gmbus_freq based on the cdclk frequency. |
| 5021 | * BSpec erroneously claims we should aim for 4MHz, but |
| 5022 | * in fact 1MHz is the correct frequency. |
| 5023 | */ |
Ville Syrjälä | 6be1e3d | 2014-10-16 20:52:31 +0300 | [diff] [blame] | 5024 | 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] | 5025 | } |
| 5026 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5027 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 5028 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5029 | { |
| 5030 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5031 | u32 val, cmd; |
| 5032 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5033 | 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] | 5034 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5035 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5036 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5037 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5038 | cmd = 1; |
| 5039 | else |
| 5040 | cmd = 0; |
| 5041 | |
| 5042 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5043 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5044 | val &= ~DSPFREQGUAR_MASK; |
| 5045 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 5046 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5047 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5048 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 5049 | 50)) { |
| 5050 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5051 | } |
| 5052 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5053 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5054 | if (cdclk == 400000) { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5055 | u32 divider; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5056 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5057 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5058 | |
| 5059 | mutex_lock(&dev_priv->dpio_lock); |
| 5060 | /* adjust cdclk divider */ |
| 5061 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Ville Syrjälä | 9cf33db | 2014-06-13 13:37:48 +0300 | [diff] [blame] | 5062 | val &= ~DISPLAY_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5063 | val |= divider; |
| 5064 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5065 | |
| 5066 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
| 5067 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 5068 | 50)) |
| 5069 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5070 | mutex_unlock(&dev_priv->dpio_lock); |
| 5071 | } |
| 5072 | |
| 5073 | mutex_lock(&dev_priv->dpio_lock); |
| 5074 | /* adjust self-refresh exit latency value */ |
| 5075 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 5076 | val &= ~0x7f; |
| 5077 | |
| 5078 | /* |
| 5079 | * For high bandwidth configs, we set a higher latency in the bunit |
| 5080 | * so that the core display fetch happens in time to avoid underruns. |
| 5081 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5082 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5083 | val |= 4500 / 250; /* 4.5 usec */ |
| 5084 | else |
| 5085 | val |= 3000 / 250; /* 3.0 usec */ |
| 5086 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
| 5087 | mutex_unlock(&dev_priv->dpio_lock); |
| 5088 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5089 | vlv_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5090 | } |
| 5091 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5092 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5093 | { |
| 5094 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5095 | u32 val, cmd; |
| 5096 | |
| 5097 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq); |
| 5098 | |
| 5099 | switch (cdclk) { |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5100 | case 333333: |
| 5101 | case 320000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5102 | case 266667: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5103 | case 200000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5104 | break; |
| 5105 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 5106 | MISSING_CASE(cdclk); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5107 | return; |
| 5108 | } |
| 5109 | |
Ville Syrjälä | 9d0d3fd | 2015-03-02 20:07:17 +0200 | [diff] [blame] | 5110 | /* |
| 5111 | * Specs are full of misinformation, but testing on actual |
| 5112 | * hardware has shown that we just need to write the desired |
| 5113 | * CCK divider into the Punit register. |
| 5114 | */ |
| 5115 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
| 5116 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5117 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5118 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5119 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 5120 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 5121 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5122 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5123 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 5124 | 50)) { |
| 5125 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5126 | } |
| 5127 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5128 | |
| 5129 | vlv_update_cdclk(dev); |
| 5130 | } |
| 5131 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5132 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5133 | int max_pixclk) |
| 5134 | { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5135 | 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] | 5136 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5137 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5138 | /* |
| 5139 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 5140 | * 200MHz |
| 5141 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5142 | * 320/333MHz (depends on HPLL freq) |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5143 | * 400MHz (VLV only) |
| 5144 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) |
| 5145 | * of the lower bin and adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5146 | * |
| 5147 | * We seem to get an unstable or solid color picture at 200MHz. |
| 5148 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 5149 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5150 | */ |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5151 | if (!IS_CHERRYVIEW(dev_priv) && |
| 5152 | max_pixclk > freq_320*limit/100) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5153 | return 400000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5154 | else if (max_pixclk > 266667*limit/100) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5155 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5156 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5157 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5158 | else |
| 5159 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5160 | } |
| 5161 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5162 | /* compute the max pixel clock for new configuration */ |
| 5163 | static int intel_mode_max_pixclk(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5164 | { |
| 5165 | struct drm_device *dev = dev_priv->dev; |
| 5166 | struct intel_crtc *intel_crtc; |
| 5167 | int max_pixclk = 0; |
| 5168 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5169 | for_each_intel_crtc(dev, intel_crtc) { |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5170 | if (intel_crtc->new_enabled) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5171 | max_pixclk = max(max_pixclk, |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 5172 | intel_crtc->new_config->base.adjusted_mode.crtc_clock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5173 | } |
| 5174 | |
| 5175 | return max_pixclk; |
| 5176 | } |
| 5177 | |
| 5178 | static void valleyview_modeset_global_pipes(struct drm_device *dev, |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5179 | unsigned *prepare_pipes) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5180 | { |
| 5181 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5182 | struct intel_crtc *intel_crtc; |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5183 | int max_pixclk = intel_mode_max_pixclk(dev_priv); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5184 | |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 5185 | if (valleyview_calc_cdclk(dev_priv, max_pixclk) == |
| 5186 | dev_priv->vlv_cdclk_freq) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5187 | return; |
| 5188 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5189 | /* disable/enable all currently active pipes while we change cdclk */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5190 | for_each_intel_crtc(dev, intel_crtc) |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5191 | if (intel_crtc->base.state->enable) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5192 | *prepare_pipes |= (1 << intel_crtc->pipe); |
| 5193 | } |
| 5194 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5195 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
| 5196 | { |
| 5197 | unsigned int credits, default_credits; |
| 5198 | |
| 5199 | if (IS_CHERRYVIEW(dev_priv)) |
| 5200 | default_credits = PFI_CREDIT(12); |
| 5201 | else |
| 5202 | default_credits = PFI_CREDIT(8); |
| 5203 | |
| 5204 | if (DIV_ROUND_CLOSEST(dev_priv->vlv_cdclk_freq, 1000) >= dev_priv->rps.cz_freq) { |
| 5205 | /* CHV suggested value is 31 or 63 */ |
| 5206 | if (IS_CHERRYVIEW(dev_priv)) |
| 5207 | credits = PFI_CREDIT_31; |
| 5208 | else |
| 5209 | credits = PFI_CREDIT(15); |
| 5210 | } else { |
| 5211 | credits = default_credits; |
| 5212 | } |
| 5213 | |
| 5214 | /* |
| 5215 | * WA - write default credits before re-programming |
| 5216 | * FIXME: should we also set the resend bit here? |
| 5217 | */ |
| 5218 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5219 | default_credits); |
| 5220 | |
| 5221 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5222 | credits | PFI_CREDIT_RESEND); |
| 5223 | |
| 5224 | /* |
| 5225 | * FIXME is this guaranteed to clear |
| 5226 | * immediately or should we poll for it? |
| 5227 | */ |
| 5228 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); |
| 5229 | } |
| 5230 | |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5231 | static void valleyview_modeset_global_resources(struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5232 | { |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5233 | struct drm_device *dev = state->dev; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5234 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5235 | int max_pixclk = intel_mode_max_pixclk(dev_priv); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5236 | int req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
| 5237 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5238 | if (req_cdclk != dev_priv->vlv_cdclk_freq) { |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5239 | /* |
| 5240 | * FIXME: We can end up here with all power domains off, yet |
| 5241 | * with a CDCLK frequency other than the minimum. To account |
| 5242 | * for this take the PIPE-A power domain, which covers the HW |
| 5243 | * blocks needed for the following programming. This can be |
| 5244 | * removed once it's guaranteed that we get here either with |
| 5245 | * the minimum CDCLK set, or the required power domains |
| 5246 | * enabled. |
| 5247 | */ |
| 5248 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); |
| 5249 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5250 | if (IS_CHERRYVIEW(dev)) |
| 5251 | cherryview_set_cdclk(dev, req_cdclk); |
| 5252 | else |
| 5253 | valleyview_set_cdclk(dev, req_cdclk); |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5254 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5255 | vlv_program_pfi_credits(dev_priv); |
| 5256 | |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5257 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5258 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5259 | } |
| 5260 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5261 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 5262 | { |
| 5263 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5264 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5265 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5266 | struct intel_encoder *encoder; |
| 5267 | int pipe = intel_crtc->pipe; |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 5268 | bool is_dsi; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5269 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5270 | WARN_ON(!crtc->state->enable); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5271 | |
| 5272 | if (intel_crtc->active) |
| 5273 | return; |
| 5274 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5275 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
Shobhit Kumar | 8525a23 | 2014-06-25 12:20:39 +0530 | [diff] [blame] | 5276 | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5277 | if (!is_dsi) { |
| 5278 | if (IS_CHERRYVIEW(dev)) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5279 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5280 | else |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5281 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5282 | } |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5283 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5284 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5285 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5286 | |
| 5287 | intel_set_pipe_timings(intel_crtc); |
| 5288 | |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 5289 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
| 5290 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5291 | |
| 5292 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 5293 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 5294 | } |
| 5295 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5296 | i9xx_set_pipeconf(intel_crtc); |
| 5297 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5298 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5299 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5300 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5301 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5302 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5303 | if (encoder->pre_pll_enable) |
| 5304 | encoder->pre_pll_enable(encoder); |
| 5305 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5306 | if (!is_dsi) { |
| 5307 | if (IS_CHERRYVIEW(dev)) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5308 | chv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5309 | else |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5310 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5311 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5312 | |
| 5313 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5314 | if (encoder->pre_enable) |
| 5315 | encoder->pre_enable(encoder); |
| 5316 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5317 | i9xx_pfit_enable(intel_crtc); |
| 5318 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 5319 | intel_crtc_load_lut(crtc); |
| 5320 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5321 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5322 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 5323 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5324 | assert_vblank_disabled(crtc); |
| 5325 | drm_crtc_vblank_on(crtc); |
| 5326 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5327 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5328 | encoder->enable(encoder); |
| 5329 | |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 5330 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 5331 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 5332 | /* Underruns don't raise interrupts, so check manually. */ |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5333 | i9xx_check_fifo_underruns(dev_priv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5334 | } |
| 5335 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5336 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 5337 | { |
| 5338 | struct drm_device *dev = crtc->base.dev; |
| 5339 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5340 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5341 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 5342 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5343 | } |
| 5344 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5345 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5346 | { |
| 5347 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5348 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5349 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5350 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5351 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5352 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5353 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 5354 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5355 | if (intel_crtc->active) |
| 5356 | return; |
| 5357 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5358 | i9xx_set_pll_dividers(intel_crtc); |
| 5359 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5360 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5361 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5362 | |
| 5363 | intel_set_pipe_timings(intel_crtc); |
| 5364 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5365 | i9xx_set_pipeconf(intel_crtc); |
| 5366 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5367 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 5368 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5369 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5370 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5371 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 5372 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 5373 | if (encoder->pre_enable) |
| 5374 | encoder->pre_enable(encoder); |
| 5375 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 5376 | i9xx_enable_pll(intel_crtc); |
| 5377 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5378 | i9xx_pfit_enable(intel_crtc); |
| 5379 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 5380 | intel_crtc_load_lut(crtc); |
| 5381 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5382 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5383 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 5384 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5385 | assert_vblank_disabled(crtc); |
| 5386 | drm_crtc_vblank_on(crtc); |
| 5387 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5388 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5389 | encoder->enable(encoder); |
| 5390 | |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 5391 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 5392 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5393 | /* |
| 5394 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5395 | * So don't enable underrun reporting before at least some planes |
| 5396 | * are enabled. |
| 5397 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5398 | * but leave the pipe running. |
| 5399 | */ |
| 5400 | if (IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5401 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5402 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 5403 | /* Underruns don't raise interrupts, so check manually. */ |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5404 | i9xx_check_fifo_underruns(dev_priv); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5405 | } |
| 5406 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5407 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 5408 | { |
| 5409 | struct drm_device *dev = crtc->base.dev; |
| 5410 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5411 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5412 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5413 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5414 | |
| 5415 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5416 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5417 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 5418 | I915_READ(PFIT_CONTROL)); |
| 5419 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5420 | } |
| 5421 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5422 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 5423 | { |
| 5424 | struct drm_device *dev = crtc->dev; |
| 5425 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5426 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5427 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5428 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5429 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5430 | if (!intel_crtc->active) |
| 5431 | return; |
| 5432 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5433 | /* |
| 5434 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5435 | * So diasble underrun reporting before all the planes get disabled. |
| 5436 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5437 | * but leave the pipe running. |
| 5438 | */ |
| 5439 | if (IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5440 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5441 | |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 5442 | /* |
| 5443 | * Vblank time updates from the shadow to live plane control register |
| 5444 | * are blocked if the memory self-refresh mode is active at that |
| 5445 | * moment. So to make sure the plane gets truly disabled, disable |
| 5446 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5447 | * will be checked/applied by the HW only at the next frame start |
| 5448 | * event which is after the vblank start event, so we need to have a |
| 5449 | * wait-for-vblank between disabling the plane and the pipe. |
| 5450 | */ |
| 5451 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 5452 | intel_crtc_disable_planes(crtc); |
| 5453 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 5454 | /* |
| 5455 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 5456 | * wait for planes to fully turn off before disabling the pipe. |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 5457 | * We also need to wait on all gmch platforms because of the |
| 5458 | * self-refresh mode constraint explained above. |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 5459 | */ |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 5460 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 5461 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5462 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5463 | encoder->disable(encoder); |
| 5464 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5465 | drm_crtc_vblank_off(crtc); |
| 5466 | assert_vblank_disabled(crtc); |
| 5467 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 5468 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 5469 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5470 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 5471 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5472 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5473 | if (encoder->post_disable) |
| 5474 | encoder->post_disable(encoder); |
| 5475 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5476 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 5477 | if (IS_CHERRYVIEW(dev)) |
| 5478 | chv_disable_pll(dev_priv, pipe); |
| 5479 | else if (IS_VALLEYVIEW(dev)) |
| 5480 | vlv_disable_pll(dev_priv, pipe); |
| 5481 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 5482 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 5483 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5484 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5485 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5486 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5487 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5488 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 5489 | intel_update_watermarks(crtc); |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5490 | |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 5491 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 5492 | intel_fbc_update(dev); |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 5493 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5494 | } |
| 5495 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5496 | static void i9xx_crtc_off(struct drm_crtc *crtc) |
| 5497 | { |
| 5498 | } |
| 5499 | |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 5500 | /* Master function to enable/disable CRTC and corresponding power wells */ |
| 5501 | void intel_crtc_control(struct drm_crtc *crtc, bool enable) |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5502 | { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5503 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5504 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5505 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5506 | enum intel_display_power_domain domain; |
| 5507 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5508 | |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5509 | if (enable) { |
| 5510 | if (!intel_crtc->active) { |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 5511 | domains = get_crtc_power_domains(crtc); |
| 5512 | for_each_power_domain(domain, domains) |
| 5513 | intel_display_power_get(dev_priv, domain); |
| 5514 | intel_crtc->enabled_power_domains = domains; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5515 | |
| 5516 | dev_priv->display.crtc_enable(crtc); |
| 5517 | } |
| 5518 | } else { |
| 5519 | if (intel_crtc->active) { |
| 5520 | dev_priv->display.crtc_disable(crtc); |
| 5521 | |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 5522 | domains = intel_crtc->enabled_power_domains; |
| 5523 | for_each_power_domain(domain, domains) |
| 5524 | intel_display_power_put(dev_priv, domain); |
| 5525 | intel_crtc->enabled_power_domains = 0; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5526 | } |
| 5527 | } |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 5528 | } |
| 5529 | |
| 5530 | /** |
| 5531 | * Sets the power management mode of the pipe and plane. |
| 5532 | */ |
| 5533 | void intel_crtc_update_dpms(struct drm_crtc *crtc) |
| 5534 | { |
| 5535 | struct drm_device *dev = crtc->dev; |
| 5536 | struct intel_encoder *intel_encoder; |
| 5537 | bool enable = false; |
| 5538 | |
| 5539 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 5540 | enable |= intel_encoder->connectors_active; |
| 5541 | |
| 5542 | intel_crtc_control(crtc, enable); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5543 | } |
| 5544 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5545 | static void intel_crtc_disable(struct drm_crtc *crtc) |
| 5546 | { |
| 5547 | struct drm_device *dev = crtc->dev; |
| 5548 | struct drm_connector *connector; |
| 5549 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5550 | |
| 5551 | /* crtc should still be enabled when we disable it. */ |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5552 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5553 | |
| 5554 | dev_priv->display.crtc_disable(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5555 | dev_priv->display.off(crtc); |
| 5556 | |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 5557 | crtc->primary->funcs->disable_plane(crtc->primary); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5558 | |
| 5559 | /* Update computed state. */ |
| 5560 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 5561 | if (!connector->encoder || !connector->encoder->crtc) |
| 5562 | continue; |
| 5563 | |
| 5564 | if (connector->encoder->crtc != crtc) |
| 5565 | continue; |
| 5566 | |
| 5567 | connector->dpms = DRM_MODE_DPMS_OFF; |
| 5568 | to_intel_encoder(connector->encoder)->connectors_active = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5569 | } |
| 5570 | } |
| 5571 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5572 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 5573 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5574 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5575 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5576 | drm_encoder_cleanup(encoder); |
| 5577 | kfree(intel_encoder); |
| 5578 | } |
| 5579 | |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5580 | /* 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] | 5581 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
| 5582 | * state of the entire output pipe. */ |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5583 | static void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5584 | { |
| 5585 | if (mode == DRM_MODE_DPMS_ON) { |
| 5586 | encoder->connectors_active = true; |
| 5587 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5588 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5589 | } else { |
| 5590 | encoder->connectors_active = false; |
| 5591 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5592 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5593 | } |
| 5594 | } |
| 5595 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5596 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 5597 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5598 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5599 | { |
| 5600 | if (connector->get_hw_state(connector)) { |
| 5601 | struct intel_encoder *encoder = connector->encoder; |
| 5602 | struct drm_crtc *crtc; |
| 5603 | bool encoder_enabled; |
| 5604 | enum pipe pipe; |
| 5605 | |
| 5606 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 5607 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 5608 | connector->base.name); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5609 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5610 | /* there is no real hw state for MST connectors */ |
| 5611 | if (connector->mst_port) |
| 5612 | return; |
| 5613 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5614 | I915_STATE_WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5615 | "wrong connector dpms state\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5616 | I915_STATE_WARN(connector->base.encoder != &encoder->base, |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5617 | "active connector not linked to encoder\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5618 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5619 | if (encoder) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5620 | I915_STATE_WARN(!encoder->connectors_active, |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5621 | "encoder->connectors_active not set\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5622 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5623 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5624 | I915_STATE_WARN(!encoder_enabled, "encoder not enabled\n"); |
| 5625 | if (I915_STATE_WARN_ON(!encoder->base.crtc)) |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5626 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5627 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5628 | crtc = encoder->base.crtc; |
| 5629 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5630 | I915_STATE_WARN(!crtc->state->enable, |
| 5631 | "crtc not enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5632 | I915_STATE_WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
| 5633 | I915_STATE_WARN(pipe != to_intel_crtc(crtc)->pipe, |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5634 | "encoder active on the wrong pipe\n"); |
| 5635 | } |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5636 | } |
| 5637 | } |
| 5638 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5639 | /* Even simpler default implementation, if there's really no special case to |
| 5640 | * consider. */ |
| 5641 | void intel_connector_dpms(struct drm_connector *connector, int mode) |
| 5642 | { |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5643 | /* All the simple cases only support two dpms states. */ |
| 5644 | if (mode != DRM_MODE_DPMS_ON) |
| 5645 | mode = DRM_MODE_DPMS_OFF; |
| 5646 | |
| 5647 | if (mode == connector->dpms) |
| 5648 | return; |
| 5649 | |
| 5650 | connector->dpms = mode; |
| 5651 | |
| 5652 | /* Only need to change hw state when actually enabled */ |
Chris Wilson | c9976dc | 2013-09-29 19:15:07 +0100 | [diff] [blame] | 5653 | if (connector->encoder) |
| 5654 | intel_encoder_dpms(to_intel_encoder(connector->encoder), mode); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5655 | |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5656 | intel_modeset_check_state(connector->dev); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5657 | } |
| 5658 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5659 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 5660 | * one connector and no cloning and hence the encoder state determines the state |
| 5661 | * of the connector. */ |
| 5662 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 5663 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 5664 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5665 | struct intel_encoder *encoder = connector->encoder; |
| 5666 | |
| 5667 | return encoder->get_hw_state(encoder, &pipe); |
| 5668 | } |
| 5669 | |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 5670 | static int pipe_required_fdi_lanes(struct drm_device *dev, enum pipe pipe) |
| 5671 | { |
| 5672 | struct intel_crtc *crtc = |
| 5673 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
| 5674 | |
| 5675 | if (crtc->base.state->enable && |
| 5676 | crtc->config->has_pch_encoder) |
| 5677 | return crtc->config->fdi_lanes; |
| 5678 | |
| 5679 | return 0; |
| 5680 | } |
| 5681 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5682 | 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] | 5683 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5684 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5685 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 5686 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5687 | if (pipe_config->fdi_lanes > 4) { |
| 5688 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 5689 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5690 | return false; |
| 5691 | } |
| 5692 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 5693 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5694 | if (pipe_config->fdi_lanes > 2) { |
| 5695 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 5696 | pipe_config->fdi_lanes); |
| 5697 | return false; |
| 5698 | } else { |
| 5699 | return true; |
| 5700 | } |
| 5701 | } |
| 5702 | |
| 5703 | if (INTEL_INFO(dev)->num_pipes == 2) |
| 5704 | return true; |
| 5705 | |
| 5706 | /* Ivybridge 3 pipe is really complicated */ |
| 5707 | switch (pipe) { |
| 5708 | case PIPE_A: |
| 5709 | return true; |
| 5710 | case PIPE_B: |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 5711 | if (pipe_config->fdi_lanes > 2 && |
| 5712 | pipe_required_fdi_lanes(dev, PIPE_C) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5713 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 5714 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5715 | return false; |
| 5716 | } |
| 5717 | return true; |
| 5718 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 5719 | if (pipe_config->fdi_lanes > 2) { |
| 5720 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 5721 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5722 | return false; |
| 5723 | } |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 5724 | if (pipe_required_fdi_lanes(dev, PIPE_B) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5725 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
| 5726 | return false; |
| 5727 | } |
| 5728 | return true; |
| 5729 | default: |
| 5730 | BUG(); |
| 5731 | } |
| 5732 | } |
| 5733 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5734 | #define RETRY 1 |
| 5735 | 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] | 5736 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5737 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5738 | struct drm_device *dev = intel_crtc->base.dev; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 5739 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 5740 | int lane, link_bw, fdi_dotclock; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5741 | bool setup_ok, needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5742 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5743 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5744 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 5745 | * each output octet as 10 bits. The actual frequency |
| 5746 | * is stored as a divider into a 100MHz clock, and the |
| 5747 | * mode pixel clock is stored in units of 1KHz. |
| 5748 | * Hence the bw of each lane in terms of the mode signal |
| 5749 | * is: |
| 5750 | */ |
| 5751 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
| 5752 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5753 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5754 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5755 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5756 | pipe_config->pipe_bpp); |
| 5757 | |
| 5758 | pipe_config->fdi_lanes = lane; |
| 5759 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5760 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5761 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5762 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5763 | setup_ok = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
| 5764 | intel_crtc->pipe, pipe_config); |
| 5765 | if (!setup_ok && pipe_config->pipe_bpp > 6*3) { |
| 5766 | pipe_config->pipe_bpp -= 2*3; |
| 5767 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 5768 | pipe_config->pipe_bpp); |
| 5769 | needs_recompute = true; |
| 5770 | pipe_config->bw_constrained = true; |
| 5771 | |
| 5772 | goto retry; |
| 5773 | } |
| 5774 | |
| 5775 | if (needs_recompute) |
| 5776 | return RETRY; |
| 5777 | |
| 5778 | return setup_ok ? 0 : -EINVAL; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5779 | } |
| 5780 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5781 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 5782 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5783 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5784 | pipe_config->ips_enabled = i915.enable_ips && |
Paulo Zanoni | 3c4ca58 | 2013-05-31 16:33:23 -0300 | [diff] [blame] | 5785 | hsw_crtc_supports_ips(crtc) && |
Jesse Barnes | b6dfdc9 | 2013-07-25 10:06:50 -0700 | [diff] [blame] | 5786 | pipe_config->pipe_bpp <= 24; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5787 | } |
| 5788 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5789 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 5790 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5791 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5792 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 5793 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 5794 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5795 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5796 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5797 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5798 | int clock_limit = |
| 5799 | dev_priv->display.get_display_clock_speed(dev); |
| 5800 | |
| 5801 | /* |
| 5802 | * Enable pixel doubling when the dot clock |
| 5803 | * is > 90% of the (display) core speed. |
| 5804 | * |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5805 | * GDG double wide on either pipe, |
| 5806 | * otherwise pipe A only. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5807 | */ |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5808 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5809 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5810 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5811 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5812 | } |
| 5813 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5814 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5815 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5816 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5817 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 5818 | /* |
| 5819 | * Pipe horizontal size must be even in: |
| 5820 | * - DVO ganged mode |
| 5821 | * - LVDS dual channel mode |
| 5822 | * - Double wide pipe |
| 5823 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 5824 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 5825 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 5826 | pipe_config->pipe_src_w &= ~1; |
| 5827 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 5828 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 5829 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5830 | */ |
| 5831 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
| 5832 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5833 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5834 | |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5835 | 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] | 5836 | pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */ |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5837 | } 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] | 5838 | /* only a 8bpc pipe, with 6bpc dither through the panel fitter |
| 5839 | * for lvds. */ |
| 5840 | pipe_config->pipe_bpp = 8*3; |
| 5841 | } |
| 5842 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 5843 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5844 | hsw_compute_ips_config(crtc, pipe_config); |
| 5845 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5846 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5847 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5848 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5849 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5850 | } |
| 5851 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 5852 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 5853 | { |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5854 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5855 | u32 val; |
| 5856 | int divider; |
| 5857 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5858 | if (dev_priv->hpll_freq == 0) |
| 5859 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); |
| 5860 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5861 | mutex_lock(&dev_priv->dpio_lock); |
| 5862 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
| 5863 | mutex_unlock(&dev_priv->dpio_lock); |
| 5864 | |
| 5865 | divider = val & DISPLAY_FREQUENCY_VALUES; |
| 5866 | |
Ville Syrjälä | 7d007f4 | 2014-06-13 13:37:53 +0300 | [diff] [blame] | 5867 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
| 5868 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 5869 | "cdclk change in progress\n"); |
| 5870 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5871 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 5872 | } |
| 5873 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5874 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5875 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5876 | return 400000; |
| 5877 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5878 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5879 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 5880 | { |
| 5881 | return 333000; |
| 5882 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5883 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5884 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 5885 | { |
| 5886 | return 200000; |
| 5887 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5888 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 5889 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 5890 | { |
| 5891 | u16 gcfgc = 0; |
| 5892 | |
| 5893 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 5894 | |
| 5895 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 5896 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
| 5897 | return 267000; |
| 5898 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
| 5899 | return 333000; |
| 5900 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
| 5901 | return 444000; |
| 5902 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 5903 | return 200000; |
| 5904 | default: |
| 5905 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 5906 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
| 5907 | return 133000; |
| 5908 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
| 5909 | return 167000; |
| 5910 | } |
| 5911 | } |
| 5912 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5913 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 5914 | { |
| 5915 | u16 gcfgc = 0; |
| 5916 | |
| 5917 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 5918 | |
| 5919 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5920 | return 133000; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5921 | else { |
| 5922 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 5923 | case GC_DISPLAY_CLOCK_333_MHZ: |
| 5924 | return 333000; |
| 5925 | default: |
| 5926 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 5927 | return 190000; |
| 5928 | } |
| 5929 | } |
| 5930 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5931 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 5932 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 5933 | { |
| 5934 | return 266000; |
| 5935 | } |
| 5936 | |
| 5937 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 5938 | { |
| 5939 | u16 hpllcc = 0; |
| 5940 | /* Assume that the hardware is in the high speed state. This |
| 5941 | * should be the default. |
| 5942 | */ |
| 5943 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 5944 | case GC_CLOCK_133_200: |
| 5945 | case GC_CLOCK_100_200: |
| 5946 | return 200000; |
| 5947 | case GC_CLOCK_166_250: |
| 5948 | return 250000; |
| 5949 | case GC_CLOCK_100_133: |
| 5950 | return 133000; |
| 5951 | } |
| 5952 | |
| 5953 | /* Shouldn't happen */ |
| 5954 | return 0; |
| 5955 | } |
| 5956 | |
| 5957 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 5958 | { |
| 5959 | return 133000; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5960 | } |
| 5961 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5962 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5963 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5964 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5965 | while (*num > DATA_LINK_M_N_MASK || |
| 5966 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5967 | *num >>= 1; |
| 5968 | *den >>= 1; |
| 5969 | } |
| 5970 | } |
| 5971 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5972 | static void compute_m_n(unsigned int m, unsigned int n, |
| 5973 | uint32_t *ret_m, uint32_t *ret_n) |
| 5974 | { |
| 5975 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 5976 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 5977 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 5978 | } |
| 5979 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5980 | void |
| 5981 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 5982 | int pixel_clock, int link_clock, |
| 5983 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5984 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 5985 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 5986 | |
| 5987 | compute_m_n(bits_per_pixel * pixel_clock, |
| 5988 | link_clock * nlanes * 8, |
| 5989 | &m_n->gmch_m, &m_n->gmch_n); |
| 5990 | |
| 5991 | compute_m_n(pixel_clock, link_clock, |
| 5992 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5993 | } |
| 5994 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 5995 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 5996 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5997 | if (i915.panel_use_ssc >= 0) |
| 5998 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 5999 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6000 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6001 | } |
| 6002 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6003 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
| 6004 | int num_connectors) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6005 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6006 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6007 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6008 | int refclk; |
| 6009 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6010 | WARN_ON(!crtc_state->base.state); |
| 6011 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6012 | if (IS_VALLEYVIEW(dev)) { |
Daniel Vetter | 9a0ea49 | 2013-09-16 11:29:34 +0200 | [diff] [blame] | 6013 | refclk = 100000; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6014 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6015 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 6016 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 6017 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6018 | } else if (!IS_GEN2(dev)) { |
| 6019 | refclk = 96000; |
| 6020 | } else { |
| 6021 | refclk = 48000; |
| 6022 | } |
| 6023 | |
| 6024 | return refclk; |
| 6025 | } |
| 6026 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6027 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6028 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6029 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6030 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6031 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6032 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 6033 | { |
| 6034 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6035 | } |
| 6036 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6037 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6038 | struct intel_crtc_state *crtc_state, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6039 | intel_clock_t *reduced_clock) |
| 6040 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6041 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6042 | u32 fp, fp2 = 0; |
| 6043 | |
| 6044 | if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6045 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6046 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6047 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6048 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6049 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6050 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6051 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6052 | } |
| 6053 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6054 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6055 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6056 | crtc->lowfreq_avail = false; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6057 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6058 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6059 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6060 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6061 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6062 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6063 | } |
| 6064 | } |
| 6065 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6066 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6067 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6068 | { |
| 6069 | u32 reg_val; |
| 6070 | |
| 6071 | /* |
| 6072 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6073 | * and set it to a reasonable value instead. |
| 6074 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6075 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6076 | reg_val &= 0xffffff00; |
| 6077 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6078 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6079 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6080 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6081 | reg_val &= 0x8cffffff; |
| 6082 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6083 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6084 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6085 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6086 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6087 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6088 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6089 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6090 | reg_val &= 0x00ffffff; |
| 6091 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6092 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6093 | } |
| 6094 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6095 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 6096 | struct intel_link_m_n *m_n) |
| 6097 | { |
| 6098 | struct drm_device *dev = crtc->base.dev; |
| 6099 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6100 | int pipe = crtc->pipe; |
| 6101 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6102 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6103 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 6104 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 6105 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6106 | } |
| 6107 | |
| 6108 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6109 | struct intel_link_m_n *m_n, |
| 6110 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6111 | { |
| 6112 | struct drm_device *dev = crtc->base.dev; |
| 6113 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6114 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6115 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6116 | |
| 6117 | if (INTEL_INFO(dev)->gen >= 5) { |
| 6118 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6119 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 6120 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 6121 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6122 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 6123 | * for gen < 8) and if DRRS is supported (to make sure the |
| 6124 | * registers are not unnecessarily accessed). |
| 6125 | */ |
Durgadoss R | 44395bf | 2015-02-13 15:33:02 +0530 | [diff] [blame] | 6126 | 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] | 6127 | crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6128 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 6129 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 6130 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 6131 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 6132 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 6133 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6134 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6135 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6136 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 6137 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 6138 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6139 | } |
| 6140 | } |
| 6141 | |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6142 | 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] | 6143 | { |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6144 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 6145 | |
| 6146 | if (m_n == M1_N1) { |
| 6147 | dp_m_n = &crtc->config->dp_m_n; |
| 6148 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 6149 | } else if (m_n == M2_N2) { |
| 6150 | |
| 6151 | /* |
| 6152 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 6153 | * needs to be programmed into M1_N1. |
| 6154 | */ |
| 6155 | dp_m_n = &crtc->config->dp_m2_n2; |
| 6156 | } else { |
| 6157 | DRM_ERROR("Unsupported divider value\n"); |
| 6158 | return; |
| 6159 | } |
| 6160 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6161 | if (crtc->config->has_pch_encoder) |
| 6162 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6163 | else |
Ramalingam C | fe3cd48 | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6164 | 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] | 6165 | } |
| 6166 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6167 | static void vlv_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6168 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6169 | { |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6170 | u32 dpll, dpll_md; |
| 6171 | |
| 6172 | /* |
| 6173 | * Enable DPIO clock input. We should never disable the reference |
| 6174 | * clock for pipe B, since VGA hotplug / manual detection depends |
| 6175 | * on it. |
| 6176 | */ |
| 6177 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | |
| 6178 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; |
| 6179 | /* We should never disable this, set it here for state tracking */ |
| 6180 | if (crtc->pipe == PIPE_B) |
| 6181 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 6182 | dpll |= DPLL_VCO_ENABLE; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6183 | pipe_config->dpll_hw_state.dpll = dpll; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6184 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6185 | dpll_md = (pipe_config->pixel_multiplier - 1) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6186 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6187 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6188 | } |
| 6189 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6190 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6191 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6192 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6193 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6194 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6195 | int pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6196 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6197 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6198 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6199 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6200 | mutex_lock(&dev_priv->dpio_lock); |
| 6201 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6202 | bestn = pipe_config->dpll.n; |
| 6203 | bestm1 = pipe_config->dpll.m1; |
| 6204 | bestm2 = pipe_config->dpll.m2; |
| 6205 | bestp1 = pipe_config->dpll.p1; |
| 6206 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6207 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6208 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 6209 | |
| 6210 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6211 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6212 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6213 | |
| 6214 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6215 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6216 | |
| 6217 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6218 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6219 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6220 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6221 | |
| 6222 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6223 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6224 | |
| 6225 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6226 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 6227 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 6228 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6229 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 6230 | |
| 6231 | /* |
| 6232 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 6233 | * but we don't support that). |
| 6234 | * Note: don't use the DAC post divider as it seems unstable. |
| 6235 | */ |
| 6236 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6237 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6238 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6239 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6240 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6241 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6242 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6243 | if (pipe_config->port_clock == 162000 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6244 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
| 6245 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6246 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b0120 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 6247 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6248 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6249 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6250 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6251 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 6252 | if (pipe_config->has_dp_encoder) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6253 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6254 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6255 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6256 | 0x0df40000); |
| 6257 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6258 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6259 | 0x0df70000); |
| 6260 | } else { /* HDMI or VGA */ |
| 6261 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6262 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6263 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6264 | 0x0df70000); |
| 6265 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6266 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6267 | 0x0df40000); |
| 6268 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6269 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6270 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6271 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6272 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 6273 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6274 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6275 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6276 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6277 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6278 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6279 | } |
| 6280 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6281 | static void chv_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6282 | struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6283 | { |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6284 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6285 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
| 6286 | DPLL_VCO_ENABLE; |
| 6287 | if (crtc->pipe != PIPE_A) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6288 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6289 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6290 | pipe_config->dpll_hw_state.dpll_md = |
| 6291 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6292 | } |
| 6293 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6294 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6295 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6296 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6297 | struct drm_device *dev = crtc->base.dev; |
| 6298 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6299 | int pipe = crtc->pipe; |
| 6300 | int dpll_reg = DPLL(crtc->pipe); |
| 6301 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6302 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6303 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6304 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6305 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6306 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6307 | bestn = pipe_config->dpll.n; |
| 6308 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 6309 | bestm1 = pipe_config->dpll.m1; |
| 6310 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 6311 | bestp1 = pipe_config->dpll.p1; |
| 6312 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6313 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6314 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6315 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6316 | |
| 6317 | /* |
| 6318 | * Enable Refclk and SSC |
| 6319 | */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 6320 | I915_WRITE(dpll_reg, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6321 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 6322 | |
| 6323 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6324 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6325 | /* p1 and p2 divider */ |
| 6326 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 6327 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 6328 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 6329 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 6330 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 6331 | |
| 6332 | /* Feedback post-divider - m2 */ |
| 6333 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 6334 | |
| 6335 | /* Feedback refclk divider - n and m1 */ |
| 6336 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 6337 | DPIO_CHV_M1_DIV_BY_2 | |
| 6338 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 6339 | |
| 6340 | /* M2 fraction division */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6341 | if (bestm2_frac) |
| 6342 | 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] | 6343 | |
| 6344 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6345 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 6346 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 6347 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 6348 | if (bestm2_frac) |
| 6349 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 6350 | 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] | 6351 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 6352 | /* Program digital lock detect threshold */ |
| 6353 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 6354 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 6355 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 6356 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 6357 | if (!bestm2_frac) |
| 6358 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 6359 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 6360 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6361 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6362 | if (vco == 5400000) { |
| 6363 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6364 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6365 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6366 | tribuf_calcntr = 0x9; |
| 6367 | } else if (vco <= 6200000) { |
| 6368 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6369 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 6370 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6371 | tribuf_calcntr = 0x9; |
| 6372 | } else if (vco <= 6480000) { |
| 6373 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6374 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6375 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6376 | tribuf_calcntr = 0x8; |
| 6377 | } else { |
| 6378 | /* Not supported. Apply the same limits as in the max case */ |
| 6379 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6380 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6381 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6382 | tribuf_calcntr = 0; |
| 6383 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6384 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 6385 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 6386 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6387 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 6388 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 6389 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 6390 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6391 | /* AFC Recal */ |
| 6392 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 6393 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 6394 | DPIO_AFC_RECAL); |
| 6395 | |
| 6396 | mutex_unlock(&dev_priv->dpio_lock); |
| 6397 | } |
| 6398 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6399 | /** |
| 6400 | * vlv_force_pll_on - forcibly enable just the PLL |
| 6401 | * @dev_priv: i915 private structure |
| 6402 | * @pipe: pipe PLL to enable |
| 6403 | * @dpll: PLL configuration |
| 6404 | * |
| 6405 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 6406 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 6407 | * be enabled. |
| 6408 | */ |
| 6409 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
| 6410 | const struct dpll *dpll) |
| 6411 | { |
| 6412 | struct intel_crtc *crtc = |
| 6413 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6414 | struct intel_crtc_state pipe_config = { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6415 | .base.crtc = &crtc->base, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6416 | .pixel_multiplier = 1, |
| 6417 | .dpll = *dpll, |
| 6418 | }; |
| 6419 | |
| 6420 | if (IS_CHERRYVIEW(dev)) { |
| 6421 | chv_update_pll(crtc, &pipe_config); |
| 6422 | chv_prepare_pll(crtc, &pipe_config); |
| 6423 | chv_enable_pll(crtc, &pipe_config); |
| 6424 | } else { |
| 6425 | vlv_update_pll(crtc, &pipe_config); |
| 6426 | vlv_prepare_pll(crtc, &pipe_config); |
| 6427 | vlv_enable_pll(crtc, &pipe_config); |
| 6428 | } |
| 6429 | } |
| 6430 | |
| 6431 | /** |
| 6432 | * vlv_force_pll_off - forcibly disable just the PLL |
| 6433 | * @dev_priv: i915 private structure |
| 6434 | * @pipe: pipe PLL to disable |
| 6435 | * |
| 6436 | * Disable the PLL for @pipe. To be used in cases where we need |
| 6437 | * the PLL enabled even when @pipe is not going to be enabled. |
| 6438 | */ |
| 6439 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) |
| 6440 | { |
| 6441 | if (IS_CHERRYVIEW(dev)) |
| 6442 | chv_disable_pll(to_i915(dev), pipe); |
| 6443 | else |
| 6444 | vlv_disable_pll(to_i915(dev), pipe); |
| 6445 | } |
| 6446 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6447 | static void i9xx_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6448 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6449 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6450 | int num_connectors) |
| 6451 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6452 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6453 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6454 | u32 dpll; |
| 6455 | bool is_sdvo; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6456 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6457 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6458 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6459 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6460 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 6461 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6462 | |
| 6463 | dpll = DPLL_VGA_MODE_DIS; |
| 6464 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6465 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6466 | dpll |= DPLLB_MODE_LVDS; |
| 6467 | else |
| 6468 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 6469 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 6470 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6471 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 6472 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6473 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 6474 | |
| 6475 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 6476 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 6477 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6478 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 6479 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6480 | |
| 6481 | /* compute bitmask from p1 value */ |
| 6482 | if (IS_PINEVIEW(dev)) |
| 6483 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 6484 | else { |
| 6485 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 6486 | if (IS_G4X(dev) && reduced_clock) |
| 6487 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 6488 | } |
| 6489 | switch (clock->p2) { |
| 6490 | case 5: |
| 6491 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 6492 | break; |
| 6493 | case 7: |
| 6494 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 6495 | break; |
| 6496 | case 10: |
| 6497 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 6498 | break; |
| 6499 | case 14: |
| 6500 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 6501 | break; |
| 6502 | } |
| 6503 | if (INTEL_INFO(dev)->gen >= 4) |
| 6504 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 6505 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6506 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6507 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6508 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6509 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 6510 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 6511 | else |
| 6512 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 6513 | |
| 6514 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6515 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6516 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6517 | if (INTEL_INFO(dev)->gen >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6518 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 6519 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6520 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6521 | } |
| 6522 | } |
| 6523 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6524 | static void i8xx_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6525 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6526 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6527 | int num_connectors) |
| 6528 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6529 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6530 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6531 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6532 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6533 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6534 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6535 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6536 | dpll = DPLL_VGA_MODE_DIS; |
| 6537 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6538 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6539 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 6540 | } else { |
| 6541 | if (clock->p1 == 2) |
| 6542 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 6543 | else |
| 6544 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 6545 | if (clock->p2 == 4) |
| 6546 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 6547 | } |
| 6548 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6549 | if (!IS_I830(dev) && intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 6550 | dpll |= DPLL_DVO_2X_MODE; |
| 6551 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6552 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6553 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 6554 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 6555 | else |
| 6556 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 6557 | |
| 6558 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6559 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6560 | } |
| 6561 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 6562 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6563 | { |
| 6564 | struct drm_device *dev = intel_crtc->base.dev; |
| 6565 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6566 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6567 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 6568 | struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6569 | &intel_crtc->config->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 6570 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 6571 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6572 | |
| 6573 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 6574 | * the hw state checker will get angry at the mismatch. */ |
| 6575 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 6576 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6577 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 6578 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6579 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6580 | crtc_vtotal -= 1; |
| 6581 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 6582 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6583 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 6584 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 6585 | else |
| 6586 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 6587 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 6588 | if (vsyncshift < 0) |
| 6589 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6590 | } |
| 6591 | |
| 6592 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6593 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6594 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6595 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6596 | (adjusted_mode->crtc_hdisplay - 1) | |
| 6597 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6598 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6599 | (adjusted_mode->crtc_hblank_start - 1) | |
| 6600 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6601 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6602 | (adjusted_mode->crtc_hsync_start - 1) | |
| 6603 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 6604 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6605 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6606 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6607 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6608 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6609 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6610 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6611 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6612 | (adjusted_mode->crtc_vsync_start - 1) | |
| 6613 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 6614 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 6615 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 6616 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 6617 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 6618 | * bits. */ |
| 6619 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 6620 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 6621 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 6622 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6623 | /* pipesrc controls the size that is scaled from, which should |
| 6624 | * always be the user's requested size. |
| 6625 | */ |
| 6626 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6627 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 6628 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6629 | } |
| 6630 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6631 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6632 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6633 | { |
| 6634 | struct drm_device *dev = crtc->base.dev; |
| 6635 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6636 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 6637 | uint32_t tmp; |
| 6638 | |
| 6639 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6640 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 6641 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6642 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6643 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 6644 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6645 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6646 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 6647 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6648 | |
| 6649 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6650 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 6651 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6652 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6653 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 6654 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6655 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6656 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 6657 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6658 | |
| 6659 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6660 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 6661 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 6662 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6663 | } |
| 6664 | |
| 6665 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 6666 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 6667 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 6668 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6669 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 6670 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6671 | } |
| 6672 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6673 | 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] | 6674 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6675 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6676 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 6677 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 6678 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 6679 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6680 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6681 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 6682 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 6683 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 6684 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6685 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6686 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6687 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6688 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
| 6689 | mode->flags |= pipe_config->base.adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6690 | } |
| 6691 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6692 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 6693 | { |
| 6694 | struct drm_device *dev = intel_crtc->base.dev; |
| 6695 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6696 | uint32_t pipeconf; |
| 6697 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6698 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6699 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 6700 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 6701 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 6702 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 6703 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6704 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6705 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6706 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6707 | /* only g4x and later have fancy bpc/dither controls */ |
| 6708 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6709 | /* 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] | 6710 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6711 | pipeconf |= PIPECONF_DITHER_EN | |
| 6712 | PIPECONF_DITHER_TYPE_SP; |
| 6713 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6714 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6715 | case 18: |
| 6716 | pipeconf |= PIPECONF_6BPC; |
| 6717 | break; |
| 6718 | case 24: |
| 6719 | pipeconf |= PIPECONF_8BPC; |
| 6720 | break; |
| 6721 | case 30: |
| 6722 | pipeconf |= PIPECONF_10BPC; |
| 6723 | break; |
| 6724 | default: |
| 6725 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 6726 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6727 | } |
| 6728 | } |
| 6729 | |
| 6730 | if (HAS_PIPE_CXSR(dev)) { |
| 6731 | if (intel_crtc->lowfreq_avail) { |
| 6732 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 6733 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 6734 | } else { |
| 6735 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6736 | } |
| 6737 | } |
| 6738 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6739 | 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] | 6740 | if (INTEL_INFO(dev)->gen < 4 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6741 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 6742 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 6743 | else |
| 6744 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 6745 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6746 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 6747 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6748 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6749 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 6750 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6751 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 6752 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 6753 | } |
| 6754 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6755 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 6756 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6757 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 6758 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6759 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6760 | int refclk, num_connectors = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6761 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | a16af72 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 6762 | bool ok, has_reduced_clock = false; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6763 | bool is_lvds = false, is_dsi = false; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6764 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 6765 | const intel_limit_t *limit; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 6766 | struct drm_atomic_state *state = crtc_state->base.state; |
| 6767 | struct drm_connector_state *connector_state; |
| 6768 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6769 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 6770 | for (i = 0; i < state->num_connector; i++) { |
| 6771 | if (!state->connectors[i]) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 6772 | continue; |
| 6773 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 6774 | connector_state = state->connector_states[i]; |
| 6775 | if (connector_state->crtc != &crtc->base) |
| 6776 | continue; |
| 6777 | |
| 6778 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 6779 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6780 | switch (encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6781 | case INTEL_OUTPUT_LVDS: |
| 6782 | is_lvds = true; |
| 6783 | break; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6784 | case INTEL_OUTPUT_DSI: |
| 6785 | is_dsi = true; |
| 6786 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 6787 | default: |
| 6788 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6789 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 6790 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6791 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6792 | } |
| 6793 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6794 | if (is_dsi) |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6795 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6796 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6797 | if (!crtc_state->clock_set) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6798 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6799 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6800 | /* |
| 6801 | * Returns a set of divisors for the desired target clock with |
| 6802 | * the given refclk, or FALSE. The returned values represent |
| 6803 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + |
| 6804 | * 2) / p1 / p2. |
| 6805 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6806 | limit = intel_limit(crtc_state, refclk); |
| 6807 | ok = dev_priv->display.find_dpll(limit, crtc_state, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6808 | crtc_state->port_clock, |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6809 | refclk, NULL, &clock); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6810 | if (!ok) { |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6811 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 6812 | return -EINVAL; |
| 6813 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6814 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6815 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 6816 | /* |
| 6817 | * Ensure we match the reduced clock's P to the target |
| 6818 | * clock. If the clocks don't match, we can't switch |
| 6819 | * the display clock by using the FP0/FP1. In such case |
| 6820 | * we will disable the LVDS downclock feature. |
| 6821 | */ |
| 6822 | has_reduced_clock = |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6823 | dev_priv->display.find_dpll(limit, crtc_state, |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6824 | dev_priv->lvds_downclock, |
| 6825 | refclk, &clock, |
| 6826 | &reduced_clock); |
| 6827 | } |
| 6828 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6829 | crtc_state->dpll.n = clock.n; |
| 6830 | crtc_state->dpll.m1 = clock.m1; |
| 6831 | crtc_state->dpll.m2 = clock.m2; |
| 6832 | crtc_state->dpll.p1 = clock.p1; |
| 6833 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6834 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6835 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6836 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6837 | i8xx_update_pll(crtc, crtc_state, |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6838 | has_reduced_clock ? &reduced_clock : NULL, |
| 6839 | num_connectors); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6840 | } else if (IS_CHERRYVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6841 | chv_update_pll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6842 | } else if (IS_VALLEYVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6843 | vlv_update_pll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6844 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6845 | i9xx_update_pll(crtc, crtc_state, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6846 | has_reduced_clock ? &reduced_clock : NULL, |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 6847 | num_connectors); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6848 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6849 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 6850 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 6851 | } |
| 6852 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6853 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6854 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6855 | { |
| 6856 | struct drm_device *dev = crtc->base.dev; |
| 6857 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6858 | uint32_t tmp; |
| 6859 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 6860 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 6861 | return; |
| 6862 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6863 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6864 | if (!(tmp & PFIT_ENABLE)) |
| 6865 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6866 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6867 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6868 | if (INTEL_INFO(dev)->gen < 4) { |
| 6869 | if (crtc->pipe != PIPE_B) |
| 6870 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6871 | } else { |
| 6872 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 6873 | return; |
| 6874 | } |
| 6875 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 6876 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 6877 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 6878 | if (INTEL_INFO(dev)->gen < 5) |
| 6879 | pipe_config->gmch_pfit.lvds_border_bits = |
| 6880 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 6881 | } |
| 6882 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6883 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6884 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6885 | { |
| 6886 | struct drm_device *dev = crtc->base.dev; |
| 6887 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6888 | int pipe = pipe_config->cpu_transcoder; |
| 6889 | intel_clock_t clock; |
| 6890 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 6891 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6892 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 6893 | /* In case of MIPI DPLL will not even be used */ |
| 6894 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) |
| 6895 | return; |
| 6896 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6897 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6898 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6899 | mutex_unlock(&dev_priv->dpio_lock); |
| 6900 | |
| 6901 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 6902 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 6903 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 6904 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 6905 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 6906 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 6907 | vlv_clock(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6908 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 6909 | /* clock.dot is the fast clock */ |
| 6910 | pipe_config->port_clock = clock.dot / 5; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 6911 | } |
| 6912 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 6913 | static void |
| 6914 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 6915 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6916 | { |
| 6917 | struct drm_device *dev = crtc->base.dev; |
| 6918 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6919 | u32 val, base, offset; |
| 6920 | int pipe = crtc->pipe, plane = crtc->plane; |
| 6921 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 6922 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6923 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 6924 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6925 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 6926 | val = I915_READ(DSPCNTR(plane)); |
| 6927 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 6928 | return; |
| 6929 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 6930 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 6931 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6932 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 6933 | return; |
| 6934 | } |
| 6935 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 6936 | fb = &intel_fb->base; |
| 6937 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 6938 | if (INTEL_INFO(dev)->gen >= 4) { |
| 6939 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 6940 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 6941 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 6942 | } |
| 6943 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6944 | |
| 6945 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 6946 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6947 | fb->pixel_format = fourcc; |
| 6948 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6949 | |
| 6950 | if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 6951 | if (plane_config->tiling) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6952 | offset = I915_READ(DSPTILEOFF(plane)); |
| 6953 | else |
| 6954 | offset = I915_READ(DSPLINOFF(plane)); |
| 6955 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 6956 | } else { |
| 6957 | base = I915_READ(DSPADDR(plane)); |
| 6958 | } |
| 6959 | plane_config->base = base; |
| 6960 | |
| 6961 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6962 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 6963 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6964 | |
| 6965 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6966 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6967 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 6968 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 6969 | fb->pixel_format, |
| 6970 | fb->modifier[0]); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6971 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 6972 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6973 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 6974 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 6975 | pipe_name(pipe), plane, fb->width, fb->height, |
| 6976 | fb->bits_per_pixel, base, fb->pitches[0], |
| 6977 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6978 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 6979 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 6980 | } |
| 6981 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 6982 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6983 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 6984 | { |
| 6985 | struct drm_device *dev = crtc->base.dev; |
| 6986 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6987 | int pipe = pipe_config->cpu_transcoder; |
| 6988 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
| 6989 | intel_clock_t clock; |
| 6990 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2; |
| 6991 | int refclk = 100000; |
| 6992 | |
| 6993 | mutex_lock(&dev_priv->dpio_lock); |
| 6994 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 6995 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 6996 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 6997 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
| 6998 | mutex_unlock(&dev_priv->dpio_lock); |
| 6999 | |
| 7000 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; |
| 7001 | clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff); |
| 7002 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 7003 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 7004 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 7005 | |
| 7006 | chv_clock(refclk, &clock); |
| 7007 | |
| 7008 | /* clock.dot is the fast clock */ |
| 7009 | pipe_config->port_clock = clock.dot / 5; |
| 7010 | } |
| 7011 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7012 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7013 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7014 | { |
| 7015 | struct drm_device *dev = crtc->base.dev; |
| 7016 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7017 | uint32_t tmp; |
| 7018 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 7019 | if (!intel_display_power_is_enabled(dev_priv, |
| 7020 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7021 | return false; |
| 7022 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7023 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7024 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7025 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7026 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7027 | if (!(tmp & PIPECONF_ENABLE)) |
| 7028 | return false; |
| 7029 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7030 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
| 7031 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7032 | case PIPECONF_6BPC: |
| 7033 | pipe_config->pipe_bpp = 18; |
| 7034 | break; |
| 7035 | case PIPECONF_8BPC: |
| 7036 | pipe_config->pipe_bpp = 24; |
| 7037 | break; |
| 7038 | case PIPECONF_10BPC: |
| 7039 | pipe_config->pipe_bpp = 30; |
| 7040 | break; |
| 7041 | default: |
| 7042 | break; |
| 7043 | } |
| 7044 | } |
| 7045 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 7046 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
| 7047 | pipe_config->limited_color_range = true; |
| 7048 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 7049 | if (INTEL_INFO(dev)->gen < 4) |
| 7050 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 7051 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7052 | intel_get_pipe_timings(crtc, pipe_config); |
| 7053 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7054 | i9xx_get_pfit_config(crtc, pipe_config); |
| 7055 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7056 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7057 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
| 7058 | pipe_config->pixel_multiplier = |
| 7059 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 7060 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7061 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7062 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 7063 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 7064 | pipe_config->pixel_multiplier = |
| 7065 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 7066 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 7067 | } else { |
| 7068 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 7069 | * port and will be fixed up in the encoder->get_config |
| 7070 | * function. */ |
| 7071 | pipe_config->pixel_multiplier = 1; |
| 7072 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7073 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
| 7074 | if (!IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 7075 | /* |
| 7076 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 7077 | * on 830. Filter it out here so that we don't |
| 7078 | * report errors due to that. |
| 7079 | */ |
| 7080 | if (IS_I830(dev)) |
| 7081 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 7082 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7083 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 7084 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 7085 | } else { |
| 7086 | /* Mask out read-only status bits. */ |
| 7087 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 7088 | DPLL_PORTC_READY_MASK | |
| 7089 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7090 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7091 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7092 | if (IS_CHERRYVIEW(dev)) |
| 7093 | chv_crtc_clock_get(crtc, pipe_config); |
| 7094 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7095 | vlv_crtc_clock_get(crtc, pipe_config); |
| 7096 | else |
| 7097 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 7098 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7099 | return true; |
| 7100 | } |
| 7101 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7102 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7103 | { |
| 7104 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7105 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7106 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7107 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7108 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7109 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7110 | bool has_ck505 = false; |
| 7111 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7112 | |
| 7113 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 7114 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7115 | switch (encoder->type) { |
| 7116 | case INTEL_OUTPUT_LVDS: |
| 7117 | has_panel = true; |
| 7118 | has_lvds = true; |
| 7119 | break; |
| 7120 | case INTEL_OUTPUT_EDP: |
| 7121 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 7122 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7123 | has_cpu_edp = true; |
| 7124 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7125 | default: |
| 7126 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7127 | } |
| 7128 | } |
| 7129 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7130 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7131 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7132 | can_ssc = has_ck505; |
| 7133 | } else { |
| 7134 | has_ck505 = false; |
| 7135 | can_ssc = true; |
| 7136 | } |
| 7137 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 7138 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 7139 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7140 | |
| 7141 | /* Ironlake: try to setup display ref clock before DPLL |
| 7142 | * enabling. This is only under driver's control after |
| 7143 | * PCH B stepping, previous chipset stepping should be |
| 7144 | * ignoring this setting. |
| 7145 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7146 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7147 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7148 | /* As we must carefully and slowly disable/enable each source in turn, |
| 7149 | * compute the final state we want first and check if we need to |
| 7150 | * make any changes at all. |
| 7151 | */ |
| 7152 | final = val; |
| 7153 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7154 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7155 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7156 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7157 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7158 | |
| 7159 | final &= ~DREF_SSC_SOURCE_MASK; |
| 7160 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 7161 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7162 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7163 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7164 | final |= DREF_SSC_SOURCE_ENABLE; |
| 7165 | |
| 7166 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7167 | final |= DREF_SSC1_ENABLE; |
| 7168 | |
| 7169 | if (has_cpu_edp) { |
| 7170 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7171 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 7172 | else |
| 7173 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 7174 | } else |
| 7175 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 7176 | } else { |
| 7177 | final |= DREF_SSC_SOURCE_DISABLE; |
| 7178 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 7179 | } |
| 7180 | |
| 7181 | if (final == val) |
| 7182 | return; |
| 7183 | |
| 7184 | /* Always enable nonspread source */ |
| 7185 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 7186 | |
| 7187 | if (has_ck505) |
| 7188 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 7189 | else |
| 7190 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7191 | |
| 7192 | if (has_panel) { |
| 7193 | val &= ~DREF_SSC_SOURCE_MASK; |
| 7194 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7195 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7196 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7197 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7198 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7199 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 7200 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7201 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7202 | |
| 7203 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7204 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7205 | POSTING_READ(PCH_DREF_CONTROL); |
| 7206 | udelay(200); |
| 7207 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7208 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7209 | |
| 7210 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7211 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7212 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7213 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7214 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 7215 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7216 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7217 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7218 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7219 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7220 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7221 | POSTING_READ(PCH_DREF_CONTROL); |
| 7222 | udelay(200); |
| 7223 | } else { |
| 7224 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 7225 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7226 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7227 | |
| 7228 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7229 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7230 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7231 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7232 | POSTING_READ(PCH_DREF_CONTROL); |
| 7233 | udelay(200); |
| 7234 | |
| 7235 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7236 | val &= ~DREF_SSC_SOURCE_MASK; |
| 7237 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7238 | |
| 7239 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7240 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7241 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7242 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7243 | POSTING_READ(PCH_DREF_CONTROL); |
| 7244 | udelay(200); |
| 7245 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7246 | |
| 7247 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7248 | } |
| 7249 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7250 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7251 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7252 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7253 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7254 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 7255 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 7256 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7257 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7258 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 7259 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 7260 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7261 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7262 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 7263 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 7264 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7265 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7266 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 7267 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 7268 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7269 | } |
| 7270 | |
| 7271 | /* WaMPhyProgramming:hsw */ |
| 7272 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 7273 | { |
| 7274 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7275 | |
| 7276 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 7277 | tmp &= ~(0xFF << 24); |
| 7278 | tmp |= (0x12 << 24); |
| 7279 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 7280 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7281 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 7282 | tmp |= (1 << 11); |
| 7283 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 7284 | |
| 7285 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 7286 | tmp |= (1 << 11); |
| 7287 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 7288 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7289 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 7290 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 7291 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 7292 | |
| 7293 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 7294 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 7295 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 7296 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7297 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 7298 | tmp &= ~(7 << 13); |
| 7299 | tmp |= (5 << 13); |
| 7300 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7301 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7302 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 7303 | tmp &= ~(7 << 13); |
| 7304 | tmp |= (5 << 13); |
| 7305 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7306 | |
| 7307 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 7308 | tmp &= ~0xFF; |
| 7309 | tmp |= 0x1C; |
| 7310 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 7311 | |
| 7312 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 7313 | tmp &= ~0xFF; |
| 7314 | tmp |= 0x1C; |
| 7315 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 7316 | |
| 7317 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 7318 | tmp &= ~(0xFF << 16); |
| 7319 | tmp |= (0x1C << 16); |
| 7320 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 7321 | |
| 7322 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 7323 | tmp &= ~(0xFF << 16); |
| 7324 | tmp |= (0x1C << 16); |
| 7325 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 7326 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7327 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 7328 | tmp |= (1 << 27); |
| 7329 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7330 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7331 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 7332 | tmp |= (1 << 27); |
| 7333 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7334 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7335 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 7336 | tmp &= ~(0xF << 28); |
| 7337 | tmp |= (4 << 28); |
| 7338 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7339 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7340 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 7341 | tmp &= ~(0xF << 28); |
| 7342 | tmp |= (4 << 28); |
| 7343 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7344 | } |
| 7345 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7346 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 7347 | * Programming" based on the parameters passed: |
| 7348 | * - Sequence to enable CLKOUT_DP |
| 7349 | * - Sequence to enable CLKOUT_DP without spread |
| 7350 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 7351 | */ |
| 7352 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 7353 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7354 | { |
| 7355 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7356 | uint32_t reg, tmp; |
| 7357 | |
| 7358 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 7359 | with_spread = true; |
| 7360 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && |
| 7361 | with_fdi, "LP PCH doesn't have FDI\n")) |
| 7362 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7363 | |
| 7364 | mutex_lock(&dev_priv->dpio_lock); |
| 7365 | |
| 7366 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 7367 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 7368 | tmp |= SBI_SSCCTL_PATHALT; |
| 7369 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 7370 | |
| 7371 | udelay(24); |
| 7372 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7373 | if (with_spread) { |
| 7374 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 7375 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 7376 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7377 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7378 | if (with_fdi) { |
| 7379 | lpt_reset_fdi_mphy(dev_priv); |
| 7380 | lpt_program_fdi_mphy(dev_priv); |
| 7381 | } |
| 7382 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7383 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7384 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 7385 | SBI_GEN0 : SBI_DBUFF0; |
| 7386 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 7387 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 7388 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 7389 | |
| 7390 | mutex_unlock(&dev_priv->dpio_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7391 | } |
| 7392 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 7393 | /* Sequence to disable CLKOUT_DP */ |
| 7394 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 7395 | { |
| 7396 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7397 | uint32_t reg, tmp; |
| 7398 | |
| 7399 | mutex_lock(&dev_priv->dpio_lock); |
| 7400 | |
| 7401 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 7402 | SBI_GEN0 : SBI_DBUFF0; |
| 7403 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 7404 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 7405 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 7406 | |
| 7407 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 7408 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 7409 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 7410 | tmp |= SBI_SSCCTL_PATHALT; |
| 7411 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 7412 | udelay(32); |
| 7413 | } |
| 7414 | tmp |= SBI_SSCCTL_DISABLE; |
| 7415 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 7416 | } |
| 7417 | |
| 7418 | mutex_unlock(&dev_priv->dpio_lock); |
| 7419 | } |
| 7420 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7421 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 7422 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7423 | struct intel_encoder *encoder; |
| 7424 | bool has_vga = false; |
| 7425 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 7426 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7427 | switch (encoder->type) { |
| 7428 | case INTEL_OUTPUT_ANALOG: |
| 7429 | has_vga = true; |
| 7430 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7431 | default: |
| 7432 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7433 | } |
| 7434 | } |
| 7435 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 7436 | if (has_vga) |
| 7437 | lpt_enable_clkout_dp(dev, true, true); |
| 7438 | else |
| 7439 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7440 | } |
| 7441 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7442 | /* |
| 7443 | * Initialize reference clocks when the driver loads |
| 7444 | */ |
| 7445 | void intel_init_pch_refclk(struct drm_device *dev) |
| 7446 | { |
| 7447 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 7448 | ironlake_init_pch_refclk(dev); |
| 7449 | else if (HAS_PCH_LPT(dev)) |
| 7450 | lpt_init_pch_refclk(dev); |
| 7451 | } |
| 7452 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7453 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7454 | { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7455 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7456 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7457 | struct drm_atomic_state *state = crtc_state->base.state; |
| 7458 | struct drm_connector_state *connector_state; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7459 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7460 | int num_connectors = 0, i; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7461 | bool is_lvds = false; |
| 7462 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7463 | for (i = 0; i < state->num_connector; i++) { |
| 7464 | if (!state->connectors[i]) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 7465 | continue; |
| 7466 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7467 | connector_state = state->connector_states[i]; |
| 7468 | if (connector_state->crtc != crtc_state->base.crtc) |
| 7469 | continue; |
| 7470 | |
| 7471 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 7472 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7473 | switch (encoder->type) { |
| 7474 | case INTEL_OUTPUT_LVDS: |
| 7475 | is_lvds = true; |
| 7476 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7477 | default: |
| 7478 | break; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7479 | } |
| 7480 | num_connectors++; |
| 7481 | } |
| 7482 | |
| 7483 | 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] | 7484 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7485 | dev_priv->vbt.lvds_ssc_freq); |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 7486 | return dev_priv->vbt.lvds_ssc_freq; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7487 | } |
| 7488 | |
| 7489 | return 120000; |
| 7490 | } |
| 7491 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 7492 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7493 | { |
| 7494 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 7495 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7496 | int pipe = intel_crtc->pipe; |
| 7497 | uint32_t val; |
| 7498 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 7499 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7500 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7501 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7502 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7503 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7504 | break; |
| 7505 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7506 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7507 | break; |
| 7508 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7509 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7510 | break; |
| 7511 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7512 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7513 | break; |
| 7514 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 7515 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7516 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7517 | } |
| 7518 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7519 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7520 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 7521 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7522 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7523 | val |= PIPECONF_INTERLACED_ILK; |
| 7524 | else |
| 7525 | val |= PIPECONF_PROGRESSIVE; |
| 7526 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7527 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 7528 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 7529 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7530 | I915_WRITE(PIPECONF(pipe), val); |
| 7531 | POSTING_READ(PIPECONF(pipe)); |
| 7532 | } |
| 7533 | |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7534 | /* |
| 7535 | * Set up the pipe CSC unit. |
| 7536 | * |
| 7537 | * Currently only full range RGB to limited range RGB conversion |
| 7538 | * is supported, but eventually this should handle various |
| 7539 | * RGB<->YCbCr scenarios as well. |
| 7540 | */ |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 7541 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7542 | { |
| 7543 | struct drm_device *dev = crtc->dev; |
| 7544 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7545 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7546 | int pipe = intel_crtc->pipe; |
| 7547 | uint16_t coeff = 0x7800; /* 1.0 */ |
| 7548 | |
| 7549 | /* |
| 7550 | * TODO: Check what kind of values actually come out of the pipe |
| 7551 | * with these coeff/postoff values and adjust to get the best |
| 7552 | * accuracy. Perhaps we even need to take the bpc value into |
| 7553 | * consideration. |
| 7554 | */ |
| 7555 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7556 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7557 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
| 7558 | |
| 7559 | /* |
| 7560 | * GY/GU and RY/RU should be the other way around according |
| 7561 | * to BSpec, but reality doesn't agree. Just set them up in |
| 7562 | * a way that results in the correct picture. |
| 7563 | */ |
| 7564 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); |
| 7565 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); |
| 7566 | |
| 7567 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); |
| 7568 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); |
| 7569 | |
| 7570 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); |
| 7571 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); |
| 7572 | |
| 7573 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); |
| 7574 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); |
| 7575 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); |
| 7576 | |
| 7577 | if (INTEL_INFO(dev)->gen > 6) { |
| 7578 | uint16_t postoff = 0; |
| 7579 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7580 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 32cf0cb | 2013-11-28 22:10:38 +0200 | [diff] [blame] | 7581 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7582 | |
| 7583 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); |
| 7584 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); |
| 7585 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); |
| 7586 | |
| 7587 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); |
| 7588 | } else { |
| 7589 | uint32_t mode = CSC_MODE_YUV_TO_RGB; |
| 7590 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7591 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7592 | mode |= CSC_BLACK_SCREEN_OFFSET; |
| 7593 | |
| 7594 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); |
| 7595 | } |
| 7596 | } |
| 7597 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 7598 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7599 | { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7600 | struct drm_device *dev = crtc->dev; |
| 7601 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7602 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7603 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7604 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7605 | uint32_t val; |
| 7606 | |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 7607 | val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7608 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7609 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7610 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 7611 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7612 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7613 | val |= PIPECONF_INTERLACED_ILK; |
| 7614 | else |
| 7615 | val |= PIPECONF_PROGRESSIVE; |
| 7616 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 7617 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 7618 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 7619 | |
| 7620 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); |
| 7621 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7622 | |
Satheeshakrishna M | 3cdf122c | 2014-04-08 15:46:53 +0530 | [diff] [blame] | 7623 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7624 | val = 0; |
| 7625 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7626 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7627 | case 18: |
| 7628 | val |= PIPEMISC_DITHER_6_BPC; |
| 7629 | break; |
| 7630 | case 24: |
| 7631 | val |= PIPEMISC_DITHER_8_BPC; |
| 7632 | break; |
| 7633 | case 30: |
| 7634 | val |= PIPEMISC_DITHER_10_BPC; |
| 7635 | break; |
| 7636 | case 36: |
| 7637 | val |= PIPEMISC_DITHER_12_BPC; |
| 7638 | break; |
| 7639 | default: |
| 7640 | /* Case prevented by pipe_config_set_bpp. */ |
| 7641 | BUG(); |
| 7642 | } |
| 7643 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7644 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7645 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 7646 | |
| 7647 | I915_WRITE(PIPEMISC(pipe), val); |
| 7648 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7649 | } |
| 7650 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7651 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7652 | struct intel_crtc_state *crtc_state, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7653 | intel_clock_t *clock, |
| 7654 | bool *has_reduced_clock, |
| 7655 | intel_clock_t *reduced_clock) |
| 7656 | { |
| 7657 | struct drm_device *dev = crtc->dev; |
| 7658 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7659 | int refclk; |
| 7660 | const intel_limit_t *limit; |
Daniel Vetter | a16af72 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 7661 | bool ret, is_lvds = false; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7662 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7663 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7664 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7665 | refclk = ironlake_get_refclk(crtc_state); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7666 | |
| 7667 | /* |
| 7668 | * Returns a set of divisors for the desired target clock with the given |
| 7669 | * refclk, or FALSE. The returned values represent the clock equation: |
| 7670 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 7671 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7672 | limit = intel_limit(crtc_state, refclk); |
| 7673 | ret = dev_priv->display.find_dpll(limit, crtc_state, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7674 | crtc_state->port_clock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7675 | refclk, NULL, clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7676 | if (!ret) |
| 7677 | return false; |
| 7678 | |
| 7679 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 7680 | /* |
| 7681 | * Ensure we match the reduced clock's P to the target clock. |
| 7682 | * If the clocks don't match, we can't switch the display clock |
| 7683 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 7684 | * downclock feature. |
| 7685 | */ |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7686 | *has_reduced_clock = |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7687 | dev_priv->display.find_dpll(limit, crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7688 | dev_priv->lvds_downclock, |
| 7689 | refclk, clock, |
| 7690 | reduced_clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7691 | } |
| 7692 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7693 | return true; |
| 7694 | } |
| 7695 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7696 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 7697 | { |
| 7698 | /* |
| 7699 | * Account for spread spectrum to avoid |
| 7700 | * oversubscribing the link. Max center spread |
| 7701 | * is 2.5%; use 5% for safety's sake. |
| 7702 | */ |
| 7703 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 7704 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7705 | } |
| 7706 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7707 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 7708 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7709 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 7710 | } |
| 7711 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7712 | 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] | 7713 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7714 | u32 *fp, |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7715 | intel_clock_t *reduced_clock, u32 *fp2) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7716 | { |
| 7717 | struct drm_crtc *crtc = &intel_crtc->base; |
| 7718 | struct drm_device *dev = crtc->dev; |
| 7719 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7720 | struct drm_atomic_state *state = crtc_state->base.state; |
| 7721 | struct drm_connector_state *connector_state; |
| 7722 | struct intel_encoder *encoder; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7723 | uint32_t dpll; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7724 | int factor, num_connectors = 0, i; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 7725 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7726 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7727 | for (i = 0; i < state->num_connector; i++) { |
| 7728 | if (!state->connectors[i]) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 7729 | continue; |
| 7730 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7731 | connector_state = state->connector_states[i]; |
| 7732 | if (connector_state->crtc != crtc_state->base.crtc) |
| 7733 | continue; |
| 7734 | |
| 7735 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 7736 | |
| 7737 | switch (encoder->type) { |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7738 | case INTEL_OUTPUT_LVDS: |
| 7739 | is_lvds = true; |
| 7740 | break; |
| 7741 | case INTEL_OUTPUT_SDVO: |
| 7742 | case INTEL_OUTPUT_HDMI: |
| 7743 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7744 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7745 | default: |
| 7746 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7747 | } |
| 7748 | |
| 7749 | num_connectors++; |
| 7750 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7751 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7752 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7753 | factor = 21; |
| 7754 | if (is_lvds) { |
| 7755 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 7756 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 7757 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7758 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7759 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7760 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7761 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7762 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
Daniel Vetter | 7d0ac5b | 2013-04-04 22:20:32 +0200 | [diff] [blame] | 7763 | *fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7764 | |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7765 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
| 7766 | *fp2 |= FP_CB_TUNE; |
| 7767 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 7768 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7769 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7770 | if (is_lvds) |
| 7771 | dpll |= DPLLB_MODE_LVDS; |
| 7772 | else |
| 7773 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7774 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7775 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7776 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7777 | |
| 7778 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7779 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7780 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7781 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7782 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7783 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7784 | 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] | 7785 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7786 | 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] | 7787 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7788 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7789 | case 5: |
| 7790 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7791 | break; |
| 7792 | case 7: |
| 7793 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7794 | break; |
| 7795 | case 10: |
| 7796 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7797 | break; |
| 7798 | case 14: |
| 7799 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7800 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7801 | } |
| 7802 | |
Daniel Vetter | b4c09f3 | 2013-04-30 14:01:42 +0200 | [diff] [blame] | 7803 | 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] | 7804 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7805 | else |
| 7806 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7807 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 7808 | return dpll | DPLL_VCO_ENABLE; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7809 | } |
| 7810 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7811 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 7812 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7813 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7814 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7815 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7816 | u32 dpll = 0, fp = 0, fp2 = 0; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 7817 | bool ok, has_reduced_clock = false; |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 7818 | bool is_lvds = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 7819 | struct intel_shared_dpll *pll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7820 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 7821 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7822 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 7823 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 7824 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 7825 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7826 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7827 | &has_reduced_clock, &reduced_clock); |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7828 | if (!ok && !crtc_state->clock_set) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7829 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 7830 | return -EINVAL; |
| 7831 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7832 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7833 | if (!crtc_state->clock_set) { |
| 7834 | crtc_state->dpll.n = clock.n; |
| 7835 | crtc_state->dpll.m1 = clock.m1; |
| 7836 | crtc_state->dpll.m2 = clock.m2; |
| 7837 | crtc_state->dpll.p1 = clock.p1; |
| 7838 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7839 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7840 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 7841 | /* 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] | 7842 | if (crtc_state->has_pch_encoder) { |
| 7843 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7844 | if (has_reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7845 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7846 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7847 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 7848 | &fp, &reduced_clock, |
| 7849 | has_reduced_clock ? &fp2 : NULL); |
| 7850 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7851 | crtc_state->dpll_hw_state.dpll = dpll; |
| 7852 | crtc_state->dpll_hw_state.fp0 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7853 | if (has_reduced_clock) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7854 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7855 | else |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7856 | crtc_state->dpll_hw_state.fp1 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 7857 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7858 | pll = intel_get_shared_dpll(crtc, crtc_state); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 7859 | if (pll == NULL) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 7860 | 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] | 7861 | pipe_name(crtc->pipe)); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 7862 | return -EINVAL; |
| 7863 | } |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 7864 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7865 | |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 7866 | if (is_lvds && has_reduced_clock) |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7867 | crtc->lowfreq_avail = true; |
Daniel Vetter | bcd644e | 2013-06-05 13:34:22 +0200 | [diff] [blame] | 7868 | else |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 7869 | crtc->lowfreq_avail = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 7870 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7871 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7872 | } |
| 7873 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7874 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 7875 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7876 | { |
| 7877 | struct drm_device *dev = crtc->base.dev; |
| 7878 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7879 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7880 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7881 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 7882 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 7883 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 7884 | & ~TU_SIZE_MASK; |
| 7885 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 7886 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 7887 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7888 | } |
| 7889 | |
| 7890 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 7891 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7892 | struct intel_link_m_n *m_n, |
| 7893 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7894 | { |
| 7895 | struct drm_device *dev = crtc->base.dev; |
| 7896 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7897 | enum pipe pipe = crtc->pipe; |
| 7898 | |
| 7899 | if (INTEL_INFO(dev)->gen >= 5) { |
| 7900 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 7901 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 7902 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 7903 | & ~TU_SIZE_MASK; |
| 7904 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 7905 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 7906 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7907 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 7908 | * gen < 8) and if DRRS is supported (to make sure the |
| 7909 | * registers are not unnecessarily read). |
| 7910 | */ |
| 7911 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7912 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7913 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 7914 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 7915 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 7916 | & ~TU_SIZE_MASK; |
| 7917 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 7918 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 7919 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7920 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7921 | } else { |
| 7922 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 7923 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 7924 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 7925 | & ~TU_SIZE_MASK; |
| 7926 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 7927 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 7928 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 7929 | } |
| 7930 | } |
| 7931 | |
| 7932 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7933 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7934 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 7935 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7936 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 7937 | else |
| 7938 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7939 | &pipe_config->dp_m_n, |
| 7940 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7941 | } |
| 7942 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7943 | 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] | 7944 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7945 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 7946 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 7947 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 7948 | } |
| 7949 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 7950 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7951 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 7952 | { |
| 7953 | struct drm_device *dev = crtc->base.dev; |
| 7954 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7955 | uint32_t tmp; |
| 7956 | |
| 7957 | tmp = I915_READ(PS_CTL(crtc->pipe)); |
| 7958 | |
| 7959 | if (tmp & PS_ENABLE) { |
| 7960 | pipe_config->pch_pfit.enabled = true; |
| 7961 | pipe_config->pch_pfit.pos = I915_READ(PS_WIN_POS(crtc->pipe)); |
| 7962 | pipe_config->pch_pfit.size = I915_READ(PS_WIN_SZ(crtc->pipe)); |
| 7963 | } |
| 7964 | } |
| 7965 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7966 | static void |
| 7967 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 7968 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7969 | { |
| 7970 | struct drm_device *dev = crtc->base.dev; |
| 7971 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 7972 | u32 val, base, offset, stride_mult, tiling; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7973 | int pipe = crtc->pipe; |
| 7974 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7975 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7976 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7977 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7978 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7979 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7980 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7981 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7982 | return; |
| 7983 | } |
| 7984 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7985 | fb = &intel_fb->base; |
| 7986 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7987 | val = I915_READ(PLANE_CTL(pipe, 0)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7988 | if (!(val & PLANE_CTL_ENABLE)) |
| 7989 | goto error; |
| 7990 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 7991 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
| 7992 | fourcc = skl_format_to_fourcc(pixel_format, |
| 7993 | val & PLANE_CTL_ORDER_RGBX, |
| 7994 | val & PLANE_CTL_ALPHA_MASK); |
| 7995 | fb->pixel_format = fourcc; |
| 7996 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
| 7997 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 7998 | tiling = val & PLANE_CTL_TILED_MASK; |
| 7999 | switch (tiling) { |
| 8000 | case PLANE_CTL_TILED_LINEAR: |
| 8001 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; |
| 8002 | break; |
| 8003 | case PLANE_CTL_TILED_X: |
| 8004 | plane_config->tiling = I915_TILING_X; |
| 8005 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 8006 | break; |
| 8007 | case PLANE_CTL_TILED_Y: |
| 8008 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; |
| 8009 | break; |
| 8010 | case PLANE_CTL_TILED_YF: |
| 8011 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; |
| 8012 | break; |
| 8013 | default: |
| 8014 | MISSING_CASE(tiling); |
| 8015 | goto error; |
| 8016 | } |
| 8017 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8018 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
| 8019 | plane_config->base = base; |
| 8020 | |
| 8021 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); |
| 8022 | |
| 8023 | val = I915_READ(PLANE_SIZE(pipe, 0)); |
| 8024 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 8025 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 8026 | |
| 8027 | val = I915_READ(PLANE_STRIDE(pipe, 0)); |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8028 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 8029 | fb->pixel_format); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8030 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 8031 | |
| 8032 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8033 | fb->pixel_format, |
| 8034 | fb->modifier[0]); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8035 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8036 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8037 | |
| 8038 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8039 | pipe_name(pipe), fb->width, fb->height, |
| 8040 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8041 | plane_config->size); |
| 8042 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8043 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8044 | return; |
| 8045 | |
| 8046 | error: |
| 8047 | kfree(fb); |
| 8048 | } |
| 8049 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8050 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8051 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8052 | { |
| 8053 | struct drm_device *dev = crtc->base.dev; |
| 8054 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8055 | uint32_t tmp; |
| 8056 | |
| 8057 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 8058 | |
| 8059 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 8060 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8061 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 8062 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 8063 | |
| 8064 | /* We currently do not free assignements of panel fitters on |
| 8065 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 8066 | * differentiates them) so just WARN about this case for now. */ |
| 8067 | if (IS_GEN7(dev)) { |
| 8068 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 8069 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 8070 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8071 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8072 | } |
| 8073 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8074 | static void |
| 8075 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8076 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8077 | { |
| 8078 | struct drm_device *dev = crtc->base.dev; |
| 8079 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8080 | u32 val, base, offset; |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8081 | int pipe = crtc->pipe; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8082 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8083 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8084 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8085 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8086 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8087 | val = I915_READ(DSPCNTR(pipe)); |
| 8088 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 8089 | return; |
| 8090 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8091 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8092 | if (!intel_fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8093 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8094 | return; |
| 8095 | } |
| 8096 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8097 | fb = &intel_fb->base; |
| 8098 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8099 | if (INTEL_INFO(dev)->gen >= 4) { |
| 8100 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8101 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8102 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 8103 | } |
| 8104 | } |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8105 | |
| 8106 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 8107 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8108 | fb->pixel_format = fourcc; |
| 8109 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8110 | |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8111 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8112 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8113 | offset = I915_READ(DSPOFFSET(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8114 | } else { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8115 | if (plane_config->tiling) |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8116 | offset = I915_READ(DSPTILEOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8117 | else |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8118 | offset = I915_READ(DSPLINOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8119 | } |
| 8120 | plane_config->base = base; |
| 8121 | |
| 8122 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8123 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 8124 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8125 | |
| 8126 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8127 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8128 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8129 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8130 | fb->pixel_format, |
| 8131 | fb->modifier[0]); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8132 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8133 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8134 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 8135 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8136 | pipe_name(pipe), fb->width, fb->height, |
| 8137 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8138 | plane_config->size); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8139 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8140 | plane_config->fb = intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8141 | } |
| 8142 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8143 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8144 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8145 | { |
| 8146 | struct drm_device *dev = crtc->base.dev; |
| 8147 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8148 | uint32_t tmp; |
| 8149 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8150 | if (!intel_display_power_is_enabled(dev_priv, |
| 8151 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 8152 | return false; |
| 8153 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8154 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8155 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8156 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8157 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8158 | if (!(tmp & PIPECONF_ENABLE)) |
| 8159 | return false; |
| 8160 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8161 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8162 | case PIPECONF_6BPC: |
| 8163 | pipe_config->pipe_bpp = 18; |
| 8164 | break; |
| 8165 | case PIPECONF_8BPC: |
| 8166 | pipe_config->pipe_bpp = 24; |
| 8167 | break; |
| 8168 | case PIPECONF_10BPC: |
| 8169 | pipe_config->pipe_bpp = 30; |
| 8170 | break; |
| 8171 | case PIPECONF_12BPC: |
| 8172 | pipe_config->pipe_bpp = 36; |
| 8173 | break; |
| 8174 | default: |
| 8175 | break; |
| 8176 | } |
| 8177 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8178 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 8179 | pipe_config->limited_color_range = true; |
| 8180 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 8181 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8182 | struct intel_shared_dpll *pll; |
| 8183 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8184 | pipe_config->has_pch_encoder = true; |
| 8185 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8186 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 8187 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8188 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8189 | |
| 8190 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8191 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8192 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 8193 | pipe_config->shared_dpll = |
| 8194 | (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8195 | } else { |
| 8196 | tmp = I915_READ(PCH_DPLL_SEL); |
| 8197 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
| 8198 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; |
| 8199 | else |
| 8200 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; |
| 8201 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8202 | |
| 8203 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 8204 | |
| 8205 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 8206 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 8207 | |
| 8208 | tmp = pipe_config->dpll_hw_state.dpll; |
| 8209 | pipe_config->pixel_multiplier = |
| 8210 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 8211 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8212 | |
| 8213 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8214 | } else { |
| 8215 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8216 | } |
| 8217 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8218 | intel_get_pipe_timings(crtc, pipe_config); |
| 8219 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8220 | ironlake_get_pfit_config(crtc, pipe_config); |
| 8221 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8222 | return true; |
| 8223 | } |
| 8224 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8225 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 8226 | { |
| 8227 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8228 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8229 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 8230 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8231 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8232 | pipe_name(crtc->pipe)); |
| 8233 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8234 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
| 8235 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
| 8236 | I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 8237 | I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
| 8238 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 8239 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8240 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 8241 | if (IS_HASWELL(dev)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8242 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 8243 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8244 | 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] | 8245 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8246 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8247 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8248 | 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] | 8249 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 8250 | /* |
| 8251 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 8252 | * interrupts remain enabled. We used to check for that, but since it's |
| 8253 | * gen-specific and since we only disable LCPLL after we fully disable |
| 8254 | * the interrupts, the check below should be enough. |
| 8255 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8256 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8257 | } |
| 8258 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8259 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 8260 | { |
| 8261 | struct drm_device *dev = dev_priv->dev; |
| 8262 | |
| 8263 | if (IS_HASWELL(dev)) |
| 8264 | return I915_READ(D_COMP_HSW); |
| 8265 | else |
| 8266 | return I915_READ(D_COMP_BDW); |
| 8267 | } |
| 8268 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8269 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 8270 | { |
| 8271 | struct drm_device *dev = dev_priv->dev; |
| 8272 | |
| 8273 | if (IS_HASWELL(dev)) { |
| 8274 | mutex_lock(&dev_priv->rps.hw_lock); |
| 8275 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 8276 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 8277 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8278 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 8279 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8280 | I915_WRITE(D_COMP_BDW, val); |
| 8281 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8282 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8283 | } |
| 8284 | |
| 8285 | /* |
| 8286 | * This function implements pieces of two sequences from BSpec: |
| 8287 | * - Sequence for display software to disable LCPLL |
| 8288 | * - Sequence for display software to allow package C8+ |
| 8289 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 8290 | * register. Callers should take care of disabling all the display engine |
| 8291 | * functions, doing the mode unset, fixing interrupts, etc. |
| 8292 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 8293 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 8294 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8295 | { |
| 8296 | uint32_t val; |
| 8297 | |
| 8298 | assert_can_disable_lcpll(dev_priv); |
| 8299 | |
| 8300 | val = I915_READ(LCPLL_CTL); |
| 8301 | |
| 8302 | if (switch_to_fclk) { |
| 8303 | val |= LCPLL_CD_SOURCE_FCLK; |
| 8304 | I915_WRITE(LCPLL_CTL, val); |
| 8305 | |
| 8306 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 8307 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 8308 | DRM_ERROR("Switching to FCLK failed\n"); |
| 8309 | |
| 8310 | val = I915_READ(LCPLL_CTL); |
| 8311 | } |
| 8312 | |
| 8313 | val |= LCPLL_PLL_DISABLE; |
| 8314 | I915_WRITE(LCPLL_CTL, val); |
| 8315 | POSTING_READ(LCPLL_CTL); |
| 8316 | |
| 8317 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 8318 | DRM_ERROR("LCPLL still locked\n"); |
| 8319 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8320 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8321 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8322 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8323 | ndelay(100); |
| 8324 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8325 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 8326 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8327 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 8328 | |
| 8329 | if (allow_power_down) { |
| 8330 | val = I915_READ(LCPLL_CTL); |
| 8331 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 8332 | I915_WRITE(LCPLL_CTL, val); |
| 8333 | POSTING_READ(LCPLL_CTL); |
| 8334 | } |
| 8335 | } |
| 8336 | |
| 8337 | /* |
| 8338 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 8339 | * source. |
| 8340 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 8341 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8342 | { |
| 8343 | uint32_t val; |
| 8344 | |
| 8345 | val = I915_READ(LCPLL_CTL); |
| 8346 | |
| 8347 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 8348 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 8349 | return; |
| 8350 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 8351 | /* |
| 8352 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 8353 | * 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] | 8354 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 8355 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 8356 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8357 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 8358 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 8359 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 8360 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8361 | } |
| 8362 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8363 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8364 | val |= D_COMP_COMP_FORCE; |
| 8365 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8366 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8367 | |
| 8368 | val = I915_READ(LCPLL_CTL); |
| 8369 | val &= ~LCPLL_PLL_DISABLE; |
| 8370 | I915_WRITE(LCPLL_CTL, val); |
| 8371 | |
| 8372 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 8373 | DRM_ERROR("LCPLL not locked yet\n"); |
| 8374 | |
| 8375 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 8376 | val = I915_READ(LCPLL_CTL); |
| 8377 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 8378 | I915_WRITE(LCPLL_CTL, val); |
| 8379 | |
| 8380 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 8381 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 8382 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 8383 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 8384 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 8385 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8386 | } |
| 8387 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 8388 | /* |
| 8389 | * Package states C8 and deeper are really deep PC states that can only be |
| 8390 | * reached when all the devices on the system allow it, so even if the graphics |
| 8391 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 8392 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 8393 | * |
| 8394 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 8395 | * well is disabled and most interrupts are disabled, and these are also |
| 8396 | * requirements for runtime PM. When these conditions are met, we manually do |
| 8397 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 8398 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 8399 | * hang the machine. |
| 8400 | * |
| 8401 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 8402 | * the state of some registers, so when we come back from PC8+ we need to |
| 8403 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 8404 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 8405 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 8406 | * because of the runtime PM support). |
| 8407 | * |
| 8408 | * For more, read "Display Sequences for Package C8" on the hardware |
| 8409 | * documentation. |
| 8410 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 8411 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8412 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8413 | struct drm_device *dev = dev_priv->dev; |
| 8414 | uint32_t val; |
| 8415 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8416 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 8417 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8418 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 8419 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 8420 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8421 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8422 | } |
| 8423 | |
| 8424 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8425 | hsw_disable_lcpll(dev_priv, true, true); |
| 8426 | } |
| 8427 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 8428 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8429 | { |
| 8430 | struct drm_device *dev = dev_priv->dev; |
| 8431 | uint32_t val; |
| 8432 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8433 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 8434 | |
| 8435 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8436 | lpt_init_pch_refclk(dev); |
| 8437 | |
| 8438 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 8439 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 8440 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8441 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8442 | } |
| 8443 | |
| 8444 | intel_prepare_ddi(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8445 | } |
| 8446 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8447 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 8448 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 8449 | { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8450 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 8451 | return -EINVAL; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 8452 | |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8453 | crtc->lowfreq_avail = false; |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 8454 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8455 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8456 | } |
| 8457 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8458 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 8459 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8460 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8461 | { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 8462 | u32 temp, dpll_ctl1; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8463 | |
| 8464 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
| 8465 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); |
| 8466 | |
| 8467 | switch (pipe_config->ddi_pll_sel) { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 8468 | case SKL_DPLL0: |
| 8469 | /* |
| 8470 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part |
| 8471 | * of the shared DPLL framework and thus needs to be read out |
| 8472 | * separately |
| 8473 | */ |
| 8474 | dpll_ctl1 = I915_READ(DPLL_CTRL1); |
| 8475 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; |
| 8476 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8477 | case SKL_DPLL1: |
| 8478 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; |
| 8479 | break; |
| 8480 | case SKL_DPLL2: |
| 8481 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; |
| 8482 | break; |
| 8483 | case SKL_DPLL3: |
| 8484 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; |
| 8485 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8486 | } |
| 8487 | } |
| 8488 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 8489 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 8490 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8491 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 8492 | { |
| 8493 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 8494 | |
| 8495 | switch (pipe_config->ddi_pll_sel) { |
| 8496 | case PORT_CLK_SEL_WRPLL1: |
| 8497 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; |
| 8498 | break; |
| 8499 | case PORT_CLK_SEL_WRPLL2: |
| 8500 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; |
| 8501 | break; |
| 8502 | } |
| 8503 | } |
| 8504 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8505 | 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] | 8506 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8507 | { |
| 8508 | struct drm_device *dev = crtc->base.dev; |
| 8509 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 8510 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8511 | enum port port; |
| 8512 | uint32_t tmp; |
| 8513 | |
| 8514 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 8515 | |
| 8516 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 8517 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8518 | if (IS_SKYLAKE(dev)) |
| 8519 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
| 8520 | else |
| 8521 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 8522 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 8523 | if (pipe_config->shared_dpll >= 0) { |
| 8524 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 8525 | |
| 8526 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 8527 | &pipe_config->dpll_hw_state)); |
| 8528 | } |
| 8529 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8530 | /* |
| 8531 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 8532 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 8533 | * the PCH transcoder is on. |
| 8534 | */ |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 8535 | if (INTEL_INFO(dev)->gen < 9 && |
| 8536 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8537 | pipe_config->has_pch_encoder = true; |
| 8538 | |
| 8539 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 8540 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8541 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 8542 | |
| 8543 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 8544 | } |
| 8545 | } |
| 8546 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8547 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8548 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8549 | { |
| 8550 | struct drm_device *dev = crtc->base.dev; |
| 8551 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8552 | enum intel_display_power_domain pfit_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8553 | uint32_t tmp; |
| 8554 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8555 | if (!intel_display_power_is_enabled(dev_priv, |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 8556 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 8557 | return false; |
| 8558 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8559 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8560 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
| 8561 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8562 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 8563 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 8564 | enum pipe trans_edp_pipe; |
| 8565 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 8566 | default: |
| 8567 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 8568 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 8569 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 8570 | trans_edp_pipe = PIPE_A; |
| 8571 | break; |
| 8572 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 8573 | trans_edp_pipe = PIPE_B; |
| 8574 | break; |
| 8575 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 8576 | trans_edp_pipe = PIPE_C; |
| 8577 | break; |
| 8578 | } |
| 8579 | |
| 8580 | if (trans_edp_pipe == crtc->pipe) |
| 8581 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 8582 | } |
| 8583 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8584 | if (!intel_display_power_is_enabled(dev_priv, |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8585 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
Paulo Zanoni | 2bfce95 | 2013-04-18 16:35:40 -0300 | [diff] [blame] | 8586 | return false; |
| 8587 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8588 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8589 | if (!(tmp & PIPECONF_ENABLE)) |
| 8590 | return false; |
| 8591 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8592 | haswell_get_ddi_port_state(crtc, pipe_config); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8593 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8594 | intel_get_pipe_timings(crtc, pipe_config); |
| 8595 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8596 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8597 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
| 8598 | if (IS_SKYLAKE(dev)) |
| 8599 | skylake_get_pfit_config(crtc, pipe_config); |
| 8600 | else |
| 8601 | ironlake_get_pfit_config(crtc, pipe_config); |
| 8602 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8603 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 8604 | if (IS_HASWELL(dev)) |
| 8605 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 8606 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 8607 | |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 8608 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
| 8609 | pipe_config->pixel_multiplier = |
| 8610 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 8611 | } else { |
| 8612 | pipe_config->pixel_multiplier = 1; |
| 8613 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8614 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8615 | return true; |
| 8616 | } |
| 8617 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8618 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8619 | { |
| 8620 | struct drm_device *dev = crtc->dev; |
| 8621 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8622 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8623 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8624 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8625 | if (base) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8626 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
| 8627 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8628 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 8629 | |
| 8630 | switch (stride) { |
| 8631 | default: |
| 8632 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 8633 | width, stride); |
| 8634 | stride = 256; |
| 8635 | /* fallthrough */ |
| 8636 | case 256: |
| 8637 | case 512: |
| 8638 | case 1024: |
| 8639 | case 2048: |
| 8640 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8641 | } |
| 8642 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8643 | cntl |= CURSOR_ENABLE | |
| 8644 | CURSOR_GAMMA_ENABLE | |
| 8645 | CURSOR_FORMAT_ARGB | |
| 8646 | CURSOR_STRIDE(stride); |
| 8647 | |
| 8648 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8649 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8650 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8651 | if (intel_crtc->cursor_cntl != 0 && |
| 8652 | (intel_crtc->cursor_base != base || |
| 8653 | intel_crtc->cursor_size != size || |
| 8654 | intel_crtc->cursor_cntl != cntl)) { |
| 8655 | /* On these chipsets we can only modify the base/size/stride |
| 8656 | * whilst the cursor is disabled. |
| 8657 | */ |
| 8658 | I915_WRITE(_CURACNTR, 0); |
| 8659 | POSTING_READ(_CURACNTR); |
| 8660 | intel_crtc->cursor_cntl = 0; |
| 8661 | } |
| 8662 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8663 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8664 | I915_WRITE(_CURABASE, base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8665 | intel_crtc->cursor_base = base; |
| 8666 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8667 | |
| 8668 | if (intel_crtc->cursor_size != size) { |
| 8669 | I915_WRITE(CURSIZE, size); |
| 8670 | intel_crtc->cursor_size = size; |
| 8671 | } |
| 8672 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8673 | if (intel_crtc->cursor_cntl != cntl) { |
| 8674 | I915_WRITE(_CURACNTR, cntl); |
| 8675 | POSTING_READ(_CURACNTR); |
| 8676 | intel_crtc->cursor_cntl = cntl; |
| 8677 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8678 | } |
| 8679 | |
| 8680 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8681 | { |
| 8682 | struct drm_device *dev = crtc->dev; |
| 8683 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8684 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8685 | int pipe = intel_crtc->pipe; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8686 | uint32_t cntl; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8687 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8688 | cntl = 0; |
| 8689 | if (base) { |
| 8690 | cntl = MCURSOR_GAMMA_ENABLE; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8691 | switch (intel_crtc->base.cursor->state->crtc_w) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8692 | case 64: |
| 8693 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 8694 | break; |
| 8695 | case 128: |
| 8696 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 8697 | break; |
| 8698 | case 256: |
| 8699 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 8700 | break; |
| 8701 | default: |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8702 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8703 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8704 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8705 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 8706 | |
| 8707 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 8708 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8709 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8710 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 8711 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 8712 | cntl |= CURSOR_ROTATE_180; |
| 8713 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8714 | if (intel_crtc->cursor_cntl != cntl) { |
| 8715 | I915_WRITE(CURCNTR(pipe), cntl); |
| 8716 | POSTING_READ(CURCNTR(pipe)); |
| 8717 | intel_crtc->cursor_cntl = cntl; |
| 8718 | } |
| 8719 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8720 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8721 | I915_WRITE(CURBASE(pipe), base); |
| 8722 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8723 | |
| 8724 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8725 | } |
| 8726 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8727 | /* 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] | 8728 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 8729 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8730 | { |
| 8731 | struct drm_device *dev = crtc->dev; |
| 8732 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8733 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8734 | int pipe = intel_crtc->pipe; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 8735 | int x = crtc->cursor_x; |
| 8736 | int y = crtc->cursor_y; |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8737 | u32 base = 0, pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8738 | |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8739 | if (on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8740 | base = intel_crtc->cursor_addr; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8741 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8742 | if (x >= intel_crtc->config->pipe_src_w) |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8743 | base = 0; |
| 8744 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8745 | if (y >= intel_crtc->config->pipe_src_h) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8746 | base = 0; |
| 8747 | |
| 8748 | if (x < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8749 | if (x + intel_crtc->base.cursor->state->crtc_w <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8750 | base = 0; |
| 8751 | |
| 8752 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 8753 | x = -x; |
| 8754 | } |
| 8755 | pos |= x << CURSOR_X_SHIFT; |
| 8756 | |
| 8757 | if (y < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8758 | if (y + intel_crtc->base.cursor->state->crtc_h <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8759 | base = 0; |
| 8760 | |
| 8761 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 8762 | y = -y; |
| 8763 | } |
| 8764 | pos |= y << CURSOR_Y_SHIFT; |
| 8765 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8766 | if (base == 0 && intel_crtc->cursor_base == 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8767 | return; |
| 8768 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8769 | I915_WRITE(CURPOS(pipe), pos); |
| 8770 | |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 8771 | /* ILK+ do this automagically */ |
| 8772 | if (HAS_GMCH_DISPLAY(dev) && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 8773 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8774 | base += (intel_crtc->base.cursor->state->crtc_h * |
| 8775 | intel_crtc->base.cursor->state->crtc_w - 1) * 4; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 8776 | } |
| 8777 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 8778 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8779 | i845_update_cursor(crtc, base); |
| 8780 | else |
| 8781 | i9xx_update_cursor(crtc, base); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8782 | } |
| 8783 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8784 | static bool cursor_size_ok(struct drm_device *dev, |
| 8785 | uint32_t width, uint32_t height) |
| 8786 | { |
| 8787 | if (width == 0 || height == 0) |
| 8788 | return false; |
| 8789 | |
| 8790 | /* |
| 8791 | * 845g/865g are special in that they are only limited by |
| 8792 | * the width of their cursors, the height is arbitrary up to |
| 8793 | * the precision of the register. Everything else requires |
| 8794 | * square cursors, limited to a few power-of-two sizes. |
| 8795 | */ |
| 8796 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 8797 | if ((width & 63) != 0) |
| 8798 | return false; |
| 8799 | |
| 8800 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 8801 | return false; |
| 8802 | |
| 8803 | if (height > 1023) |
| 8804 | return false; |
| 8805 | } else { |
| 8806 | switch (width | height) { |
| 8807 | case 256: |
| 8808 | case 128: |
| 8809 | if (IS_GEN2(dev)) |
| 8810 | return false; |
| 8811 | case 64: |
| 8812 | break; |
| 8813 | default: |
| 8814 | return false; |
| 8815 | } |
| 8816 | } |
| 8817 | |
| 8818 | return true; |
| 8819 | } |
| 8820 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8821 | 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] | 8822 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8823 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 8824 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8825 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8826 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 8827 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8828 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 8829 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 8830 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 8831 | } |
| 8832 | |
| 8833 | intel_crtc_load_lut(crtc); |
| 8834 | } |
| 8835 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8836 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 8837 | static struct drm_display_mode load_detect_mode = { |
| 8838 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 8839 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 8840 | }; |
| 8841 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 8842 | struct drm_framebuffer * |
| 8843 | __intel_framebuffer_create(struct drm_device *dev, |
| 8844 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 8845 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8846 | { |
| 8847 | struct intel_framebuffer *intel_fb; |
| 8848 | int ret; |
| 8849 | |
| 8850 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 8851 | if (!intel_fb) { |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 8852 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8853 | return ERR_PTR(-ENOMEM); |
| 8854 | } |
| 8855 | |
| 8856 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8857 | if (ret) |
| 8858 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8859 | |
| 8860 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8861 | err: |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 8862 | drm_gem_object_unreference(&obj->base); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 8863 | kfree(intel_fb); |
| 8864 | |
| 8865 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8866 | } |
| 8867 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 8868 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 8869 | intel_framebuffer_create(struct drm_device *dev, |
| 8870 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 8871 | struct drm_i915_gem_object *obj) |
| 8872 | { |
| 8873 | struct drm_framebuffer *fb; |
| 8874 | int ret; |
| 8875 | |
| 8876 | ret = i915_mutex_lock_interruptible(dev); |
| 8877 | if (ret) |
| 8878 | return ERR_PTR(ret); |
| 8879 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 8880 | mutex_unlock(&dev->struct_mutex); |
| 8881 | |
| 8882 | return fb; |
| 8883 | } |
| 8884 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8885 | static u32 |
| 8886 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 8887 | { |
| 8888 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 8889 | return ALIGN(pitch, 64); |
| 8890 | } |
| 8891 | |
| 8892 | static u32 |
| 8893 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 8894 | { |
| 8895 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 8896 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8897 | } |
| 8898 | |
| 8899 | static struct drm_framebuffer * |
| 8900 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 8901 | struct drm_display_mode *mode, |
| 8902 | int depth, int bpp) |
| 8903 | { |
| 8904 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 8905 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8906 | |
| 8907 | obj = i915_gem_alloc_object(dev, |
| 8908 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 8909 | if (obj == NULL) |
| 8910 | return ERR_PTR(-ENOMEM); |
| 8911 | |
| 8912 | mode_cmd.width = mode->hdisplay; |
| 8913 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 8914 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 8915 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 8916 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8917 | |
| 8918 | return intel_framebuffer_create(dev, &mode_cmd, obj); |
| 8919 | } |
| 8920 | |
| 8921 | static struct drm_framebuffer * |
| 8922 | mode_fits_in_fbdev(struct drm_device *dev, |
| 8923 | struct drm_display_mode *mode) |
| 8924 | { |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 8925 | #ifdef CONFIG_DRM_I915_FBDEV |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8926 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8927 | struct drm_i915_gem_object *obj; |
| 8928 | struct drm_framebuffer *fb; |
| 8929 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 8930 | if (!dev_priv->fbdev) |
| 8931 | return NULL; |
| 8932 | |
| 8933 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8934 | return NULL; |
| 8935 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 8936 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 8937 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8938 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 8939 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 8940 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 8941 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8942 | return NULL; |
| 8943 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 8944 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8945 | return NULL; |
| 8946 | |
| 8947 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 8948 | #else |
| 8949 | return NULL; |
| 8950 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8951 | } |
| 8952 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8953 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 8954 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8955 | struct intel_load_detect_pipe *old, |
| 8956 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8957 | { |
| 8958 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 8959 | struct intel_encoder *intel_encoder = |
| 8960 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8961 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 8962 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8963 | struct drm_crtc *crtc = NULL; |
| 8964 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 8965 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8966 | struct drm_mode_config *config = &dev->mode_config; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 8967 | struct drm_atomic_state *state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 8968 | struct drm_connector_state *connector_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8969 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8970 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8971 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 8972 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 8973 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 8974 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8975 | retry: |
| 8976 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 8977 | if (ret) |
| 8978 | goto fail_unlock; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 8979 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8980 | /* |
| 8981 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 8982 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8983 | * - if the connector already has an assigned crtc, use it (but make |
| 8984 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 8985 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8986 | * - try to find the first unused crtc that can drive this connector, |
| 8987 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8988 | */ |
| 8989 | |
| 8990 | /* See if we already have a CRTC for this connector */ |
| 8991 | if (encoder->crtc) { |
| 8992 | crtc = encoder->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 8993 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 8994 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 8995 | if (ret) |
| 8996 | goto fail_unlock; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 8997 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 8998 | if (ret) |
| 8999 | goto fail_unlock; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 9000 | |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9001 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9002 | old->load_detect_temp = false; |
| 9003 | |
| 9004 | /* Make sure the crtc and connector are running */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9005 | if (connector->dpms != DRM_MODE_DPMS_ON) |
| 9006 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9007 | |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9008 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9009 | } |
| 9010 | |
| 9011 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 9012 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9013 | i++; |
| 9014 | if (!(encoder->possible_crtcs & (1 << i))) |
| 9015 | continue; |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 9016 | if (possible_crtc->state->enable) |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 9017 | continue; |
| 9018 | /* This can occur when applying the pipe A quirk on resume. */ |
| 9019 | if (to_intel_crtc(possible_crtc)->new_enabled) |
| 9020 | continue; |
| 9021 | |
| 9022 | crtc = possible_crtc; |
| 9023 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9024 | } |
| 9025 | |
| 9026 | /* |
| 9027 | * If we didn't find an unused CRTC, don't use any. |
| 9028 | */ |
| 9029 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9030 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9031 | goto fail_unlock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9032 | } |
| 9033 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9034 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 9035 | if (ret) |
| 9036 | goto fail_unlock; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 9037 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 9038 | if (ret) |
| 9039 | goto fail_unlock; |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 9040 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
| 9041 | to_intel_connector(connector)->new_encoder = intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9042 | |
| 9043 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9044 | intel_crtc->new_enabled = true; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9045 | intel_crtc->new_config = intel_crtc->config; |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9046 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9047 | old->load_detect_temp = true; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9048 | old->release_fb = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9049 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9050 | state = drm_atomic_state_alloc(dev); |
| 9051 | if (!state) |
| 9052 | return false; |
| 9053 | |
| 9054 | state->acquire_ctx = ctx; |
| 9055 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9056 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 9057 | if (IS_ERR(connector_state)) { |
| 9058 | ret = PTR_ERR(connector_state); |
| 9059 | goto fail; |
| 9060 | } |
| 9061 | |
| 9062 | connector_state->crtc = crtc; |
| 9063 | connector_state->best_encoder = &intel_encoder->base; |
| 9064 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 9065 | if (!mode) |
| 9066 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9067 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9068 | /* We need a framebuffer large enough to accommodate all accesses |
| 9069 | * that the plane may generate whilst we perform load detection. |
| 9070 | * We can not rely on the fbcon either being present (we get called |
| 9071 | * during its initialisation to detect all boot displays, or it may |
| 9072 | * not even exist) or that it is large enough to satisfy the |
| 9073 | * requested mode. |
| 9074 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9075 | fb = mode_fits_in_fbdev(dev, mode); |
| 9076 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9077 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9078 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
| 9079 | old->release_fb = fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9080 | } else |
| 9081 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9082 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9083 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9084 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9085 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9086 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9087 | if (intel_set_mode(crtc, mode, 0, 0, fb, state)) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 9088 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9089 | if (old->release_fb) |
| 9090 | old->release_fb->funcs->destroy(old->release_fb); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9091 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9092 | } |
Daniel Vetter | 9128b04 | 2015-03-03 17:31:21 +0100 | [diff] [blame] | 9093 | crtc->primary->crtc = crtc; |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9094 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9095 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 9096 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9097 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9098 | |
| 9099 | fail: |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 9100 | intel_crtc->new_enabled = crtc->state->enable; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9101 | if (intel_crtc->new_enabled) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9102 | intel_crtc->new_config = intel_crtc->config; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9103 | else |
| 9104 | intel_crtc->new_config = NULL; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9105 | fail_unlock: |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9106 | if (state) { |
| 9107 | drm_atomic_state_free(state); |
| 9108 | state = NULL; |
| 9109 | } |
| 9110 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9111 | if (ret == -EDEADLK) { |
| 9112 | drm_modeset_backoff(ctx); |
| 9113 | goto retry; |
| 9114 | } |
| 9115 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9116 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9117 | } |
| 9118 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9119 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 9120 | struct intel_load_detect_pipe *old, |
| 9121 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9122 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9123 | struct drm_device *dev = connector->dev; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9124 | struct intel_encoder *intel_encoder = |
| 9125 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 9126 | struct drm_encoder *encoder = &intel_encoder->base; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 9127 | struct drm_crtc *crtc = encoder->crtc; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9128 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9129 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9130 | struct drm_connector_state *connector_state; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9131 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9132 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 9133 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 9134 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9135 | |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9136 | if (old->load_detect_temp) { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9137 | state = drm_atomic_state_alloc(dev); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9138 | if (!state) |
| 9139 | goto fail; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9140 | |
| 9141 | state->acquire_ctx = ctx; |
| 9142 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9143 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 9144 | if (IS_ERR(connector_state)) |
| 9145 | goto fail; |
| 9146 | |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 9147 | to_intel_connector(connector)->new_encoder = NULL; |
| 9148 | intel_encoder->new_crtc = NULL; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9149 | intel_crtc->new_enabled = false; |
| 9150 | intel_crtc->new_config = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9151 | |
| 9152 | connector_state->best_encoder = NULL; |
| 9153 | connector_state->crtc = NULL; |
| 9154 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9155 | intel_set_mode(crtc, NULL, 0, 0, NULL, state); |
| 9156 | |
| 9157 | drm_atomic_state_free(state); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9158 | |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 9159 | if (old->release_fb) { |
| 9160 | drm_framebuffer_unregister_private(old->release_fb); |
| 9161 | drm_framebuffer_unreference(old->release_fb); |
| 9162 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9163 | |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 9164 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9165 | } |
| 9166 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 9167 | /* Switch crtc and encoder back off if necessary */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9168 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
| 9169 | connector->funcs->dpms(connector, old->dpms_mode); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9170 | |
| 9171 | return; |
| 9172 | fail: |
| 9173 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); |
| 9174 | drm_atomic_state_free(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9175 | } |
| 9176 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9177 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9178 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9179 | { |
| 9180 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9181 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 9182 | |
| 9183 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 9184 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9185 | else if (HAS_PCH_SPLIT(dev)) |
| 9186 | return 120000; |
| 9187 | else if (!IS_GEN2(dev)) |
| 9188 | return 96000; |
| 9189 | else |
| 9190 | return 48000; |
| 9191 | } |
| 9192 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9193 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9194 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9195 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9196 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9197 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9198 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9199 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9200 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9201 | u32 fp; |
| 9202 | intel_clock_t clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9203 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9204 | |
| 9205 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9206 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9207 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9208 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9209 | |
| 9210 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 9211 | if (IS_PINEVIEW(dev)) { |
| 9212 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 9213 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 9214 | } else { |
| 9215 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 9216 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 9217 | } |
| 9218 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 9219 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 9220 | if (IS_PINEVIEW(dev)) |
| 9221 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 9222 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 9223 | else |
| 9224 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9225 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 9226 | |
| 9227 | switch (dpll & DPLL_MODE_MASK) { |
| 9228 | case DPLLB_MODE_DAC_SERIAL: |
| 9229 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 9230 | 5 : 10; |
| 9231 | break; |
| 9232 | case DPLLB_MODE_LVDS: |
| 9233 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 9234 | 7 : 14; |
| 9235 | break; |
| 9236 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 9237 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9238 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9239 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9240 | } |
| 9241 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 9242 | if (IS_PINEVIEW(dev)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9243 | pineview_clock(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 9244 | else |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9245 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9246 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 9247 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 9248 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9249 | |
| 9250 | if (is_lvds) { |
| 9251 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 9252 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 9253 | |
| 9254 | if (lvds & LVDS_CLKB_POWER_UP) |
| 9255 | clock.p2 = 7; |
| 9256 | else |
| 9257 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9258 | } else { |
| 9259 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 9260 | clock.p1 = 2; |
| 9261 | else { |
| 9262 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 9263 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 9264 | } |
| 9265 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 9266 | clock.p2 = 4; |
| 9267 | else |
| 9268 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9269 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9270 | |
| 9271 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9272 | } |
| 9273 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9274 | /* |
| 9275 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 9276 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9277 | * encoder's get_config() function. |
| 9278 | */ |
| 9279 | pipe_config->port_clock = clock.dot; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9280 | } |
| 9281 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9282 | int intel_dotclock_calculate(int link_freq, |
| 9283 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9284 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9285 | /* |
| 9286 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 9287 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9288 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 9289 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9290 | * |
| 9291 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 9292 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9293 | */ |
| 9294 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9295 | if (!m_n->link_n) |
| 9296 | return 0; |
| 9297 | |
| 9298 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 9299 | } |
| 9300 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9301 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9302 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9303 | { |
| 9304 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9305 | |
| 9306 | /* read out port_clock from the DPLL */ |
| 9307 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9308 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9309 | /* |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9310 | * This value does not include pixel_multiplier. |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 9311 | * We will check that port_clock and adjusted_mode.crtc_clock |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9312 | * agree once we know their relationship in the encoder's |
| 9313 | * get_config() function. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9314 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 9315 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9316 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
| 9317 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9318 | } |
| 9319 | |
| 9320 | /** Returns the currently programmed mode of the given pipe. */ |
| 9321 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 9322 | struct drm_crtc *crtc) |
| 9323 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 9324 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9325 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9326 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9327 | struct drm_display_mode *mode; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9328 | struct intel_crtc_state pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 9329 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 9330 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 9331 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 9332 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9333 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9334 | |
| 9335 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 9336 | if (!mode) |
| 9337 | return NULL; |
| 9338 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9339 | /* |
| 9340 | * Construct a pipe_config sufficient for getting the clock info |
| 9341 | * back out of crtc_clock_get. |
| 9342 | * |
| 9343 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 9344 | * to use a real value here instead. |
| 9345 | */ |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9346 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9347 | pipe_config.pixel_multiplier = 1; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9348 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 9349 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 9350 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9351 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
| 9352 | |
Ville Syrjälä | 773ae03 | 2013-09-23 17:48:20 +0300 | [diff] [blame] | 9353 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9354 | mode->hdisplay = (htot & 0xffff) + 1; |
| 9355 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 9356 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 9357 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 9358 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 9359 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 9360 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 9361 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 9362 | |
| 9363 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9364 | |
| 9365 | return mode; |
| 9366 | } |
| 9367 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9368 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 9369 | { |
| 9370 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9371 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9372 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9373 | |
Sonika Jindal | baff296 | 2014-07-22 11:16:35 +0530 | [diff] [blame] | 9374 | if (!HAS_GMCH_DISPLAY(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9375 | return; |
| 9376 | |
| 9377 | if (!dev_priv->lvds_downclock_avail) |
| 9378 | return; |
| 9379 | |
| 9380 | /* |
| 9381 | * Since this is called by a timer, we should never get here in |
| 9382 | * the manual case. |
| 9383 | */ |
| 9384 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9385 | int pipe = intel_crtc->pipe; |
| 9386 | int dpll_reg = DPLL(pipe); |
Daniel Vetter | dc257cf | 2012-05-07 11:30:46 +0200 | [diff] [blame] | 9387 | int dpll; |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9388 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9389 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9390 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 9391 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9392 | |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9393 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9394 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 9395 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 9396 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9397 | dpll = I915_READ(dpll_reg); |
| 9398 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9399 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9400 | } |
| 9401 | |
| 9402 | } |
| 9403 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9404 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9405 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9406 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9407 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9408 | if (dev_priv->mm.busy) |
| 9409 | return; |
| 9410 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 9411 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9412 | i915_update_gfx_val(dev_priv); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 9413 | if (INTEL_INFO(dev)->gen >= 6) |
| 9414 | gen6_rps_busy(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9415 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9416 | } |
| 9417 | |
| 9418 | void intel_mark_idle(struct drm_device *dev) |
| 9419 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9420 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9421 | struct drm_crtc *crtc; |
| 9422 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9423 | if (!dev_priv->mm.busy) |
| 9424 | return; |
| 9425 | |
| 9426 | dev_priv->mm.busy = false; |
| 9427 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 9428 | for_each_crtc(dev, crtc) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9429 | if (!crtc->primary->fb) |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9430 | continue; |
| 9431 | |
| 9432 | intel_decrease_pllclock(crtc); |
| 9433 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9434 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 9435 | if (INTEL_INFO(dev)->gen >= 6) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9436 | gen6_rps_idle(dev->dev_private); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 9437 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 9438 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9439 | } |
| 9440 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 9441 | static void intel_crtc_set_state(struct intel_crtc *crtc, |
| 9442 | struct intel_crtc_state *crtc_state) |
| 9443 | { |
| 9444 | kfree(crtc->config); |
| 9445 | crtc->config = crtc_state; |
Ander Conselvan de Oliveira | 16f3f65 | 2015-01-15 14:55:27 +0200 | [diff] [blame] | 9446 | crtc->base.state = &crtc_state->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 9447 | } |
| 9448 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9449 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 9450 | { |
| 9451 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9452 | struct drm_device *dev = crtc->dev; |
| 9453 | struct intel_unpin_work *work; |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9454 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 9455 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9456 | work = intel_crtc->unpin_work; |
| 9457 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 9458 | spin_unlock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9459 | |
| 9460 | if (work) { |
| 9461 | cancel_work_sync(&work->work); |
| 9462 | kfree(work); |
| 9463 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9464 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 9465 | intel_crtc_set_state(intel_crtc, NULL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9466 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9467 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9468 | kfree(intel_crtc); |
| 9469 | } |
| 9470 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9471 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 9472 | { |
| 9473 | struct intel_unpin_work *work = |
| 9474 | container_of(__work, struct intel_unpin_work, work); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9475 | struct drm_device *dev = work->crtc->dev; |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9476 | enum pipe pipe = to_intel_crtc(work->crtc)->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9477 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9478 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 9479 | intel_unpin_fb_obj(work->old_fb, work->crtc->primary->state); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9480 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 9481 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 9482 | intel_fbc_update(dev); |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 9483 | |
| 9484 | if (work->flip_queued_req) |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 9485 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9486 | mutex_unlock(&dev->struct_mutex); |
| 9487 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9488 | intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 9489 | drm_framebuffer_unreference(work->old_fb); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9490 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9491 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
| 9492 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); |
| 9493 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9494 | kfree(work); |
| 9495 | } |
| 9496 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9497 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9498 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9499 | { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9500 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9501 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9502 | unsigned long flags; |
| 9503 | |
| 9504 | /* Ignore early vblank irqs */ |
| 9505 | if (intel_crtc == NULL) |
| 9506 | return; |
| 9507 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 9508 | /* |
| 9509 | * This is called both by irq handlers and the reset code (to complete |
| 9510 | * lost pageflips) so needs the full irqsave spinlocks. |
| 9511 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9512 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9513 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9514 | |
| 9515 | /* Ensure we don't miss a work->pending update ... */ |
| 9516 | smp_rmb(); |
| 9517 | |
| 9518 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9519 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9520 | return; |
| 9521 | } |
| 9522 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9523 | page_flip_completed(intel_crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 9524 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9525 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9526 | } |
| 9527 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9528 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 9529 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9530 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9531 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 9532 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9533 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9534 | } |
| 9535 | |
| 9536 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 9537 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9538 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9539 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 9540 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9541 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9542 | } |
| 9543 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9544 | /* Is 'a' after or equal to 'b'? */ |
| 9545 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 9546 | { |
| 9547 | return !((a - b) & 0x80000000); |
| 9548 | } |
| 9549 | |
| 9550 | static bool page_flip_finished(struct intel_crtc *crtc) |
| 9551 | { |
| 9552 | struct drm_device *dev = crtc->base.dev; |
| 9553 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9554 | |
Ville Syrjälä | bdfa754 | 2014-05-27 21:33:09 +0300 | [diff] [blame] | 9555 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 9556 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 9557 | return true; |
| 9558 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9559 | /* |
| 9560 | * The relevant registers doen't exist on pre-ctg. |
| 9561 | * As the flip done interrupt doesn't trigger for mmio |
| 9562 | * flips on gmch platforms, a flip count check isn't |
| 9563 | * really needed there. But since ctg has the registers, |
| 9564 | * include it in the check anyway. |
| 9565 | */ |
| 9566 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 9567 | return true; |
| 9568 | |
| 9569 | /* |
| 9570 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 9571 | * used the same base address. In that case the mmio flip might |
| 9572 | * have completed, but the CS hasn't even executed the flip yet. |
| 9573 | * |
| 9574 | * A flip count check isn't enough as the CS might have updated |
| 9575 | * the base address just after start of vblank, but before we |
| 9576 | * managed to process the interrupt. This means we'd complete the |
| 9577 | * CS flip too soon. |
| 9578 | * |
| 9579 | * Combining both checks should get us a good enough result. It may |
| 9580 | * still happen that the CS flip has been executed, but has not |
| 9581 | * yet actually completed. But in case the base address is the same |
| 9582 | * anyway, we don't really care. |
| 9583 | */ |
| 9584 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 9585 | crtc->unpin_work->gtt_offset && |
| 9586 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), |
| 9587 | crtc->unpin_work->flip_count); |
| 9588 | } |
| 9589 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9590 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 9591 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9592 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9593 | struct intel_crtc *intel_crtc = |
| 9594 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 9595 | unsigned long flags; |
| 9596 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 9597 | |
| 9598 | /* |
| 9599 | * This is called both by irq handlers and the reset code (to complete |
| 9600 | * lost pageflips) so needs the full irqsave spinlocks. |
| 9601 | * |
| 9602 | * NB: An MMIO update of the plane base pointer will also |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9603 | * generate a page-flip completion irq, i.e. every modeset |
| 9604 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 9605 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9606 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9607 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9608 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9609 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9610 | } |
| 9611 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9612 | 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] | 9613 | { |
| 9614 | /* Ensure that the work item is consistent when activating it ... */ |
| 9615 | smp_wmb(); |
| 9616 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); |
| 9617 | /* and that it is marked active as soon as the irq could fire. */ |
| 9618 | smp_wmb(); |
| 9619 | } |
| 9620 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9621 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 9622 | struct drm_crtc *crtc, |
| 9623 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9624 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9625 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9626 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9627 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9628 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9629 | u32 flip_mask; |
| 9630 | int ret; |
| 9631 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9632 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9633 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9634 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9635 | |
| 9636 | /* Can't queue multiple flips, so wait for the previous |
| 9637 | * one to finish before executing the next. |
| 9638 | */ |
| 9639 | if (intel_crtc->plane) |
| 9640 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9641 | else |
| 9642 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9643 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9644 | intel_ring_emit(ring, MI_NOOP); |
| 9645 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9646 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9647 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9648 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9649 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9650 | |
| 9651 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9652 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9653 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9654 | } |
| 9655 | |
| 9656 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 9657 | struct drm_crtc *crtc, |
| 9658 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9659 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9660 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9661 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9662 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9663 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9664 | u32 flip_mask; |
| 9665 | int ret; |
| 9666 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9667 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9668 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9669 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9670 | |
| 9671 | if (intel_crtc->plane) |
| 9672 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9673 | else |
| 9674 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9675 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9676 | intel_ring_emit(ring, MI_NOOP); |
| 9677 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
| 9678 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9679 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9680 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9681 | intel_ring_emit(ring, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9682 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9683 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9684 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9685 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9686 | } |
| 9687 | |
| 9688 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 9689 | struct drm_crtc *crtc, |
| 9690 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9691 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9692 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9693 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9694 | { |
| 9695 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9696 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9697 | uint32_t pf, pipesrc; |
| 9698 | int ret; |
| 9699 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9700 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9701 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9702 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9703 | |
| 9704 | /* i965+ uses the linear or tiled offsets from the |
| 9705 | * Display Registers (which do not change across a page-flip) |
| 9706 | * so we need only reprogram the base address. |
| 9707 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9708 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9709 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9710 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9711 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 9712 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9713 | |
| 9714 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 9715 | * untested on non-native modes, so ignore it for now. |
| 9716 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 9717 | */ |
| 9718 | pf = 0; |
| 9719 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9720 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9721 | |
| 9722 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9723 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9724 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9725 | } |
| 9726 | |
| 9727 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 9728 | struct drm_crtc *crtc, |
| 9729 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9730 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9731 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9732 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9733 | { |
| 9734 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9735 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9736 | uint32_t pf, pipesrc; |
| 9737 | int ret; |
| 9738 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9739 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9740 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9741 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9742 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9743 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9744 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9745 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9746 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9747 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 9748 | /* Contrary to the suggestions in the documentation, |
| 9749 | * "Enable Panel Fitter" does not seem to be required when page |
| 9750 | * flipping with a non-native mode, and worse causes a normal |
| 9751 | * modeset to fail. |
| 9752 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 9753 | */ |
| 9754 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9755 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9756 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9757 | |
| 9758 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9759 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9760 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9761 | } |
| 9762 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9763 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 9764 | struct drm_crtc *crtc, |
| 9765 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9766 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9767 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9768 | uint32_t flags) |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9769 | { |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9770 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9771 | uint32_t plane_bit = 0; |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9772 | int len, ret; |
| 9773 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9774 | switch (intel_crtc->plane) { |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9775 | case PLANE_A: |
| 9776 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 9777 | break; |
| 9778 | case PLANE_B: |
| 9779 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 9780 | break; |
| 9781 | case PLANE_C: |
| 9782 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 9783 | break; |
| 9784 | default: |
| 9785 | WARN_ONCE(1, "unknown plane in flip command\n"); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9786 | return -ENODEV; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9787 | } |
| 9788 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9789 | len = 4; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9790 | if (ring->id == RCS) { |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9791 | len += 6; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9792 | /* |
| 9793 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 9794 | * 48bits addresses, and we need a NOOP for the batch size to |
| 9795 | * stay even. |
| 9796 | */ |
| 9797 | if (IS_GEN8(dev)) |
| 9798 | len += 2; |
| 9799 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9800 | |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9801 | /* |
| 9802 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 9803 | * "The full packet must be contained within the same cache line." |
| 9804 | * |
| 9805 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 9806 | * cacheline, if we ever start emitting more commands before |
| 9807 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 9808 | * then do the cacheline alignment, and finally emit the |
| 9809 | * MI_DISPLAY_FLIP. |
| 9810 | */ |
| 9811 | ret = intel_ring_cacheline_align(ring); |
| 9812 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9813 | return ret; |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9814 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9815 | ret = intel_ring_begin(ring, len); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9816 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9817 | return ret; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9818 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9819 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 9820 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 9821 | * more than one flip event at any time (or ensure that one flip message |
| 9822 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 9823 | * Experimentation says that BCS works despite DERRMR masking all |
| 9824 | * flip-done completion events and that unmasking all planes at once |
| 9825 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 9826 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 9827 | */ |
| 9828 | if (ring->id == RCS) { |
| 9829 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
| 9830 | intel_ring_emit(ring, DERRMR); |
| 9831 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 9832 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 9833 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9834 | if (IS_GEN8(dev)) |
| 9835 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) | |
| 9836 | MI_SRM_LRM_GLOBAL_GTT); |
| 9837 | else |
| 9838 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | |
| 9839 | MI_SRM_LRM_GLOBAL_GTT); |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9840 | intel_ring_emit(ring, DERRMR); |
| 9841 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9842 | if (IS_GEN8(dev)) { |
| 9843 | intel_ring_emit(ring, 0); |
| 9844 | intel_ring_emit(ring, MI_NOOP); |
| 9845 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9846 | } |
| 9847 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9848 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 9849 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9850 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9851 | intel_ring_emit(ring, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9852 | |
| 9853 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9854 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9855 | return 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9856 | } |
| 9857 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9858 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
| 9859 | struct drm_i915_gem_object *obj) |
| 9860 | { |
| 9861 | /* |
| 9862 | * This is not being used for older platforms, because |
| 9863 | * non-availability of flip done interrupt forces us to use |
| 9864 | * CS flips. Older platforms derive flip done using some clever |
| 9865 | * tricks involving the flip_pending status bits and vblank irqs. |
| 9866 | * So using MMIO flips there would disrupt this mechanism. |
| 9867 | */ |
| 9868 | |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 9869 | if (ring == NULL) |
| 9870 | return true; |
| 9871 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9872 | if (INTEL_INFO(ring->dev)->gen < 5) |
| 9873 | return false; |
| 9874 | |
| 9875 | if (i915.use_mmio_flip < 0) |
| 9876 | return false; |
| 9877 | else if (i915.use_mmio_flip > 0) |
| 9878 | return true; |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 9879 | else if (i915.enable_execlists) |
| 9880 | return true; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9881 | else |
John Harrison | 41c5241 | 2014-11-24 18:49:43 +0000 | [diff] [blame] | 9882 | return ring != i915_gem_request_get_ring(obj->last_read_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9883 | } |
| 9884 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 9885 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 9886 | { |
| 9887 | struct drm_device *dev = intel_crtc->base.dev; |
| 9888 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9889 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
| 9890 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 9891 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 9892 | const enum pipe pipe = intel_crtc->pipe; |
| 9893 | u32 ctl, stride; |
| 9894 | |
| 9895 | ctl = I915_READ(PLANE_CTL(pipe, 0)); |
| 9896 | ctl &= ~PLANE_CTL_TILED_MASK; |
| 9897 | if (obj->tiling_mode == I915_TILING_X) |
| 9898 | ctl |= PLANE_CTL_TILED_X; |
| 9899 | |
| 9900 | /* |
| 9901 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 9902 | * linear buffers or in number of tiles for tiled buffers. |
| 9903 | */ |
| 9904 | stride = fb->pitches[0] >> 6; |
| 9905 | if (obj->tiling_mode == I915_TILING_X) |
| 9906 | stride = fb->pitches[0] >> 9; /* X tiles are 512 bytes wide */ |
| 9907 | |
| 9908 | /* |
| 9909 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on |
| 9910 | * PLANE_SURF updates, the update is then guaranteed to be atomic. |
| 9911 | */ |
| 9912 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); |
| 9913 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
| 9914 | |
| 9915 | I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset); |
| 9916 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 9917 | } |
| 9918 | |
| 9919 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9920 | { |
| 9921 | struct drm_device *dev = intel_crtc->base.dev; |
| 9922 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9923 | struct intel_framebuffer *intel_fb = |
| 9924 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 9925 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 9926 | u32 dspcntr; |
| 9927 | u32 reg; |
| 9928 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9929 | reg = DSPCNTR(intel_crtc->plane); |
| 9930 | dspcntr = I915_READ(reg); |
| 9931 | |
Damien Lespiau | c5d9747 | 2014-10-25 00:11:11 +0100 | [diff] [blame] | 9932 | if (obj->tiling_mode != I915_TILING_NONE) |
| 9933 | dspcntr |= DISPPLANE_TILED; |
| 9934 | else |
| 9935 | dspcntr &= ~DISPPLANE_TILED; |
| 9936 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9937 | I915_WRITE(reg, dspcntr); |
| 9938 | |
| 9939 | I915_WRITE(DSPSURF(intel_crtc->plane), |
| 9940 | intel_crtc->unpin_work->gtt_offset); |
| 9941 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 9942 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 9943 | } |
| 9944 | |
| 9945 | /* |
| 9946 | * XXX: This is the temporary way to update the plane registers until we get |
| 9947 | * around to using the usual plane update functions for MMIO flips |
| 9948 | */ |
| 9949 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 9950 | { |
| 9951 | struct drm_device *dev = intel_crtc->base.dev; |
| 9952 | bool atomic_update; |
| 9953 | u32 start_vbl_count; |
| 9954 | |
| 9955 | intel_mark_page_flip_active(intel_crtc); |
| 9956 | |
| 9957 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 9958 | |
| 9959 | if (INTEL_INFO(dev)->gen >= 9) |
| 9960 | skl_do_mmio_flip(intel_crtc); |
| 9961 | else |
| 9962 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ |
| 9963 | ilk_do_mmio_flip(intel_crtc); |
| 9964 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 9965 | if (atomic_update) |
| 9966 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9967 | } |
| 9968 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 9969 | static void intel_mmio_flip_work_func(struct work_struct *work) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9970 | { |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9971 | struct intel_crtc *crtc = |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 9972 | container_of(work, struct intel_crtc, mmio_flip.work); |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9973 | struct intel_mmio_flip *mmio_flip; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9974 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9975 | mmio_flip = &crtc->mmio_flip; |
| 9976 | if (mmio_flip->req) |
John Harrison | 9c65481 | 2014-11-24 18:49:35 +0000 | [diff] [blame] | 9977 | WARN_ON(__i915_wait_request(mmio_flip->req, |
| 9978 | crtc->reset_counter, |
| 9979 | false, NULL, NULL) != 0); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9980 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9981 | intel_do_mmio_flip(crtc); |
| 9982 | if (mmio_flip->req) { |
| 9983 | mutex_lock(&crtc->base.dev->struct_mutex); |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 9984 | i915_gem_request_assign(&mmio_flip->req, NULL); |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9985 | mutex_unlock(&crtc->base.dev->struct_mutex); |
| 9986 | } |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9987 | } |
| 9988 | |
| 9989 | static int intel_queue_mmio_flip(struct drm_device *dev, |
| 9990 | struct drm_crtc *crtc, |
| 9991 | struct drm_framebuffer *fb, |
| 9992 | struct drm_i915_gem_object *obj, |
| 9993 | struct intel_engine_cs *ring, |
| 9994 | uint32_t flags) |
| 9995 | { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9996 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 9997 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 9998 | i915_gem_request_assign(&intel_crtc->mmio_flip.req, |
| 9999 | obj->last_write_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10000 | |
Ander Conselvan de Oliveira | 536f5b5 | 2014-11-06 11:03:40 +0200 | [diff] [blame] | 10001 | schedule_work(&intel_crtc->mmio_flip.work); |
| 10002 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10003 | return 0; |
| 10004 | } |
| 10005 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10006 | static int intel_default_queue_flip(struct drm_device *dev, |
| 10007 | struct drm_crtc *crtc, |
| 10008 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10009 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10010 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10011 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10012 | { |
| 10013 | return -ENODEV; |
| 10014 | } |
| 10015 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10016 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
| 10017 | struct drm_crtc *crtc) |
| 10018 | { |
| 10019 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10020 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10021 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 10022 | u32 addr; |
| 10023 | |
| 10024 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) |
| 10025 | return true; |
| 10026 | |
| 10027 | if (!work->enable_stall_check) |
| 10028 | return false; |
| 10029 | |
| 10030 | if (work->flip_ready_vblank == 0) { |
Daniel Vetter | 3a8a946 | 2014-11-26 14:39:48 +0100 | [diff] [blame] | 10031 | if (work->flip_queued_req && |
| 10032 | !i915_gem_request_completed(work->flip_queued_req, true)) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10033 | return false; |
| 10034 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 10035 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10036 | } |
| 10037 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 10038 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10039 | return false; |
| 10040 | |
| 10041 | /* Potential stall - if we see that the flip has happened, |
| 10042 | * assume a missed interrupt. */ |
| 10043 | if (INTEL_INFO(dev)->gen >= 4) |
| 10044 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 10045 | else |
| 10046 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 10047 | |
| 10048 | /* There is a potential issue here with a false positive after a flip |
| 10049 | * to the same address. We could address this by checking for a |
| 10050 | * non-incrementing frame counter. |
| 10051 | */ |
| 10052 | return addr == work->gtt_offset; |
| 10053 | } |
| 10054 | |
| 10055 | void intel_check_page_flip(struct drm_device *dev, int pipe) |
| 10056 | { |
| 10057 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10058 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 10059 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10060 | |
Dave Gordon | 6c51d46 | 2015-03-06 15:34:26 +0000 | [diff] [blame] | 10061 | WARN_ON(!in_interrupt()); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10062 | |
| 10063 | if (crtc == NULL) |
| 10064 | return; |
| 10065 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10066 | spin_lock(&dev->event_lock); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10067 | if (intel_crtc->unpin_work && __intel_pageflip_stall_check(dev, crtc)) { |
| 10068 | 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] | 10069 | intel_crtc->unpin_work->flip_queued_vblank, |
| 10070 | drm_vblank_count(dev, pipe)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10071 | page_flip_completed(intel_crtc); |
| 10072 | } |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10073 | spin_unlock(&dev->event_lock); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10074 | } |
| 10075 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10076 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 10077 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10078 | struct drm_pending_vblank_event *event, |
| 10079 | uint32_t page_flip_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10080 | { |
| 10081 | struct drm_device *dev = crtc->dev; |
| 10082 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10083 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 10084 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10085 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 10086 | struct drm_plane *primary = crtc->primary; |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10087 | enum pipe pipe = intel_crtc->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10088 | struct intel_unpin_work *work; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10089 | struct intel_engine_cs *ring; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 10090 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10091 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 10092 | /* |
| 10093 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 10094 | * check to be safe. In the future we may enable pageflipping from |
| 10095 | * a disabled primary plane. |
| 10096 | */ |
| 10097 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 10098 | return -EBUSY; |
| 10099 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 10100 | /* Can't change pixel format via MI display flips. */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10101 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 10102 | return -EINVAL; |
| 10103 | |
| 10104 | /* |
| 10105 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 10106 | * Note that pitch changes could also affect these register. |
| 10107 | */ |
| 10108 | if (INTEL_INFO(dev)->gen > 3 && |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10109 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 10110 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 10111 | return -EINVAL; |
| 10112 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10113 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 10114 | goto out_hang; |
| 10115 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 10116 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10117 | if (work == NULL) |
| 10118 | return -ENOMEM; |
| 10119 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10120 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10121 | work->crtc = crtc; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10122 | work->old_fb = old_fb; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10123 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 10124 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 10125 | ret = drm_crtc_vblank_get(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 10126 | if (ret) |
| 10127 | goto free_work; |
| 10128 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10129 | /* We borrow the event spin lock for protecting unpin_work */ |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10130 | spin_lock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10131 | if (intel_crtc->unpin_work) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10132 | /* Before declaring the flip queue wedged, check if |
| 10133 | * the hardware completed the operation behind our backs. |
| 10134 | */ |
| 10135 | if (__intel_pageflip_stall_check(dev, crtc)) { |
| 10136 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 10137 | page_flip_completed(intel_crtc); |
| 10138 | } else { |
| 10139 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10140 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 10141 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10142 | drm_crtc_vblank_put(crtc); |
| 10143 | kfree(work); |
| 10144 | return -EBUSY; |
| 10145 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10146 | } |
| 10147 | intel_crtc->unpin_work = work; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10148 | spin_unlock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10149 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10150 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 10151 | flush_workqueue(dev_priv->wq); |
| 10152 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 10153 | /* Reference the objects for the scheduled work. */ |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10154 | drm_framebuffer_reference(work->old_fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 10155 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10156 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10157 | crtc->primary->fb = fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 10158 | update_state_fb(crtc->primary); |
Matt Roper | 1ed1f96 | 2015-01-30 16:22:36 -0800 | [diff] [blame] | 10159 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10160 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10161 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10162 | ret = i915_mutex_lock_interruptible(dev); |
| 10163 | if (ret) |
| 10164 | goto cleanup; |
| 10165 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10166 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 10167 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10168 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10169 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10170 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10171 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10172 | if (IS_VALLEYVIEW(dev)) { |
| 10173 | ring = &dev_priv->ring[BCS]; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10174 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 10175 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
| 10176 | ring = NULL; |
Chris Wilson | 48bf5b2 | 2014-12-27 09:48:28 +0000 | [diff] [blame] | 10177 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
Chris Wilson | 2a92d5b | 2014-07-08 10:40:29 +0100 | [diff] [blame] | 10178 | ring = &dev_priv->ring[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10179 | } else if (INTEL_INFO(dev)->gen >= 7) { |
John Harrison | 41c5241 | 2014-11-24 18:49:43 +0000 | [diff] [blame] | 10180 | ring = i915_gem_request_get_ring(obj->last_read_req); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10181 | if (ring == NULL || ring->id != RCS) |
| 10182 | ring = &dev_priv->ring[BCS]; |
| 10183 | } else { |
| 10184 | ring = &dev_priv->ring[RCS]; |
| 10185 | } |
| 10186 | |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 10187 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
| 10188 | crtc->primary->state, ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10189 | if (ret) |
| 10190 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10191 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 10192 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj) |
| 10193 | + intel_crtc->dspaddr_offset; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10194 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10195 | if (use_mmio_flip(ring, obj)) { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10196 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
| 10197 | page_flip_flags); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10198 | if (ret) |
| 10199 | goto cleanup_unpin; |
| 10200 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10201 | i915_gem_request_assign(&work->flip_queued_req, |
| 10202 | obj->last_write_req); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10203 | } else { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10204 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring, |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10205 | page_flip_flags); |
| 10206 | if (ret) |
| 10207 | goto cleanup_unpin; |
| 10208 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10209 | i915_gem_request_assign(&work->flip_queued_req, |
| 10210 | intel_ring_get_request(ring)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10211 | } |
| 10212 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 10213 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10214 | work->enable_stall_check = true; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10215 | |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10216 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10217 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 10218 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 10219 | intel_fbc_disable(dev); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10220 | intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10221 | mutex_unlock(&dev->struct_mutex); |
| 10222 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 10223 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 10224 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10225 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10226 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10227 | cleanup_unpin: |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 10228 | intel_unpin_fb_obj(fb, crtc->primary->state); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10229 | cleanup_pending: |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10230 | atomic_dec(&intel_crtc->unpin_work_count); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10231 | mutex_unlock(&dev->struct_mutex); |
| 10232 | cleanup: |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10233 | crtc->primary->fb = old_fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 10234 | update_state_fb(crtc->primary); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10235 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10236 | drm_gem_object_unreference_unlocked(&obj->base); |
| 10237 | drm_framebuffer_unreference(work->old_fb); |
| 10238 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10239 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10240 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10241 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10242 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 10243 | drm_crtc_vblank_put(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 10244 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10245 | kfree(work); |
| 10246 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10247 | if (ret == -EIO) { |
| 10248 | out_hang: |
Matt Roper | 53a366b | 2014-12-23 10:41:53 -0800 | [diff] [blame] | 10249 | ret = intel_plane_restore(primary); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 10250 | if (ret == 0 && event) { |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10251 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10252 | drm_send_vblank_event(dev, pipe, event); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10253 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 10254 | } |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10255 | } |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10256 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10257 | } |
| 10258 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10259 | static struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10260 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 10261 | .load_lut = intel_crtc_load_lut, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 10262 | .atomic_begin = intel_begin_crtc_commit, |
| 10263 | .atomic_flush = intel_finish_crtc_commit, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10264 | }; |
| 10265 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10266 | /** |
| 10267 | * intel_modeset_update_staged_output_state |
| 10268 | * |
| 10269 | * Updates the staged output configuration state, e.g. after we've read out the |
| 10270 | * current hw state. |
| 10271 | */ |
| 10272 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) |
| 10273 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10274 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10275 | struct intel_encoder *encoder; |
| 10276 | struct intel_connector *connector; |
| 10277 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10278 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10279 | connector->new_encoder = |
| 10280 | to_intel_encoder(connector->base.encoder); |
| 10281 | } |
| 10282 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10283 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10284 | encoder->new_crtc = |
| 10285 | to_intel_crtc(encoder->base.crtc); |
| 10286 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10287 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10288 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10289 | crtc->new_enabled = crtc->base.state->enable; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 10290 | |
| 10291 | if (crtc->new_enabled) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 10292 | crtc->new_config = crtc->config; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 10293 | else |
| 10294 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10295 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10296 | } |
| 10297 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10298 | /* Transitional helper to copy current connector/encoder state to |
| 10299 | * connector->state. This is needed so that code that is partially |
| 10300 | * converted to atomic does the right thing. |
| 10301 | */ |
| 10302 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 10303 | { |
| 10304 | struct intel_connector *connector; |
| 10305 | |
| 10306 | for_each_intel_connector(dev, connector) { |
| 10307 | if (connector->base.encoder) { |
| 10308 | connector->base.state->best_encoder = |
| 10309 | connector->base.encoder; |
| 10310 | connector->base.state->crtc = |
| 10311 | connector->base.encoder->crtc; |
| 10312 | } else { |
| 10313 | connector->base.state->best_encoder = NULL; |
| 10314 | connector->base.state->crtc = NULL; |
| 10315 | } |
| 10316 | } |
| 10317 | } |
| 10318 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10319 | /** |
| 10320 | * intel_modeset_commit_output_state |
| 10321 | * |
| 10322 | * This function copies the stage display pipe configuration to the real one. |
| 10323 | */ |
| 10324 | static void intel_modeset_commit_output_state(struct drm_device *dev) |
| 10325 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10326 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10327 | struct intel_encoder *encoder; |
| 10328 | struct intel_connector *connector; |
| 10329 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10330 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10331 | connector->base.encoder = &connector->new_encoder->base; |
| 10332 | } |
| 10333 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10334 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10335 | encoder->base.crtc = &encoder->new_crtc->base; |
| 10336 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10337 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10338 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10339 | crtc->base.state->enable = crtc->new_enabled; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10340 | crtc->base.enabled = crtc->new_enabled; |
| 10341 | } |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10342 | |
| 10343 | intel_modeset_update_connector_atomic_state(dev); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10344 | } |
| 10345 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10346 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10347 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10348 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10349 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10350 | int bpp = pipe_config->pipe_bpp; |
| 10351 | |
| 10352 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 10353 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10354 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10355 | |
| 10356 | /* Don't use an invalid EDID bpc value */ |
| 10357 | if (connector->base.display_info.bpc && |
| 10358 | connector->base.display_info.bpc * 3 < bpp) { |
| 10359 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 10360 | bpp, connector->base.display_info.bpc*3); |
| 10361 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 10362 | } |
| 10363 | |
| 10364 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
| 10365 | if (connector->base.display_info.bpc == 0 && bpp > 24) { |
| 10366 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 10367 | bpp); |
| 10368 | pipe_config->pipe_bpp = 24; |
| 10369 | } |
| 10370 | } |
| 10371 | |
| 10372 | static int |
| 10373 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
| 10374 | struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10375 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10376 | { |
| 10377 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10378 | struct drm_atomic_state *state; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10379 | struct intel_connector *connector; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10380 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10381 | |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10382 | switch (fb->pixel_format) { |
| 10383 | case DRM_FORMAT_C8: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10384 | bpp = 8*3; /* since we go through a colormap */ |
| 10385 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10386 | case DRM_FORMAT_XRGB1555: |
| 10387 | case DRM_FORMAT_ARGB1555: |
| 10388 | /* checked in intel_framebuffer_init already */ |
| 10389 | if (WARN_ON(INTEL_INFO(dev)->gen > 3)) |
| 10390 | return -EINVAL; |
| 10391 | case DRM_FORMAT_RGB565: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10392 | bpp = 6*3; /* min is 18bpp */ |
| 10393 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10394 | case DRM_FORMAT_XBGR8888: |
| 10395 | case DRM_FORMAT_ABGR8888: |
| 10396 | /* checked in intel_framebuffer_init already */ |
| 10397 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
| 10398 | return -EINVAL; |
| 10399 | case DRM_FORMAT_XRGB8888: |
| 10400 | case DRM_FORMAT_ARGB8888: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10401 | bpp = 8*3; |
| 10402 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10403 | case DRM_FORMAT_XRGB2101010: |
| 10404 | case DRM_FORMAT_ARGB2101010: |
| 10405 | case DRM_FORMAT_XBGR2101010: |
| 10406 | case DRM_FORMAT_ABGR2101010: |
| 10407 | /* checked in intel_framebuffer_init already */ |
| 10408 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10409 | return -EINVAL; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10410 | bpp = 10*3; |
| 10411 | break; |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10412 | /* TODO: gen4+ supports 16 bpc floating point, too. */ |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10413 | default: |
| 10414 | DRM_DEBUG_KMS("unsupported depth\n"); |
| 10415 | return -EINVAL; |
| 10416 | } |
| 10417 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10418 | pipe_config->pipe_bpp = bpp; |
| 10419 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10420 | state = pipe_config->base.state; |
| 10421 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10422 | /* Clamp display bpp to EDID value */ |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10423 | for (i = 0; i < state->num_connector; i++) { |
| 10424 | if (!state->connectors[i]) |
| 10425 | continue; |
| 10426 | |
| 10427 | connector = to_intel_connector(state->connectors[i]); |
| 10428 | if (state->connector_states[i]->crtc != &crtc->base) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10429 | continue; |
| 10430 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10431 | connected_sink_compute_bpp(connector, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10432 | } |
| 10433 | |
| 10434 | return bpp; |
| 10435 | } |
| 10436 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10437 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 10438 | { |
| 10439 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 10440 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 10441 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10442 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 10443 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 10444 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 10445 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 10446 | } |
| 10447 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10448 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10449 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10450 | const char *context) |
| 10451 | { |
| 10452 | DRM_DEBUG_KMS("[CRTC:%d]%s config for pipe %c\n", crtc->base.base.id, |
| 10453 | context, pipe_name(crtc->pipe)); |
| 10454 | |
| 10455 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); |
| 10456 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 10457 | pipe_config->pipe_bpp, pipe_config->dither); |
| 10458 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10459 | pipe_config->has_pch_encoder, |
| 10460 | pipe_config->fdi_lanes, |
| 10461 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 10462 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 10463 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10464 | DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10465 | pipe_config->has_dp_encoder, |
| 10466 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 10467 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 10468 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10469 | |
| 10470 | DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
| 10471 | pipe_config->has_dp_encoder, |
| 10472 | pipe_config->dp_m2_n2.gmch_m, |
| 10473 | pipe_config->dp_m2_n2.gmch_n, |
| 10474 | pipe_config->dp_m2_n2.link_m, |
| 10475 | pipe_config->dp_m2_n2.link_n, |
| 10476 | pipe_config->dp_m2_n2.tu); |
| 10477 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 10478 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
| 10479 | pipe_config->has_audio, |
| 10480 | pipe_config->has_infoframe); |
| 10481 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10482 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10483 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10484 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10485 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 10486 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 10487 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10488 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 10489 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10490 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 10491 | pipe_config->gmch_pfit.control, |
| 10492 | pipe_config->gmch_pfit.pgm_ratios, |
| 10493 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10494 | 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] | 10495 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10496 | pipe_config->pch_pfit.size, |
| 10497 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10498 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 10499 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10500 | } |
| 10501 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10502 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10503 | const struct intel_encoder *b) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10504 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10505 | /* masks could be asymmetric, so check both ways */ |
| 10506 | return a == b || (a->cloneable & (1 << b->type) && |
| 10507 | b->cloneable & (1 << a->type)); |
| 10508 | } |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10509 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10510 | static bool check_single_encoder_cloning(struct intel_crtc *crtc, |
| 10511 | struct intel_encoder *encoder) |
| 10512 | { |
| 10513 | struct drm_device *dev = crtc->base.dev; |
| 10514 | struct intel_encoder *source_encoder; |
| 10515 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10516 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10517 | if (source_encoder->new_crtc != crtc) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10518 | continue; |
| 10519 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10520 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10521 | return false; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10522 | } |
| 10523 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10524 | return true; |
| 10525 | } |
| 10526 | |
| 10527 | static bool check_encoder_cloning(struct intel_crtc *crtc) |
| 10528 | { |
| 10529 | struct drm_device *dev = crtc->base.dev; |
| 10530 | struct intel_encoder *encoder; |
| 10531 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10532 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10533 | if (encoder->new_crtc != crtc) |
| 10534 | continue; |
| 10535 | |
| 10536 | if (!check_single_encoder_cloning(crtc, encoder)) |
| 10537 | return false; |
| 10538 | } |
| 10539 | |
| 10540 | return true; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10541 | } |
| 10542 | |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10543 | static bool check_digital_port_conflicts(struct drm_device *dev) |
| 10544 | { |
| 10545 | struct intel_connector *connector; |
| 10546 | unsigned int used_ports = 0; |
| 10547 | |
| 10548 | /* |
| 10549 | * Walk the connector list instead of the encoder |
| 10550 | * list to detect the problem on ddi platforms |
| 10551 | * where there's just one encoder per digital port. |
| 10552 | */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10553 | for_each_intel_connector(dev, connector) { |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10554 | struct intel_encoder *encoder = connector->new_encoder; |
| 10555 | |
| 10556 | if (!encoder) |
| 10557 | continue; |
| 10558 | |
| 10559 | WARN_ON(!encoder->new_crtc); |
| 10560 | |
| 10561 | switch (encoder->type) { |
| 10562 | unsigned int port_mask; |
| 10563 | case INTEL_OUTPUT_UNKNOWN: |
| 10564 | if (WARN_ON(!HAS_DDI(dev))) |
| 10565 | break; |
| 10566 | case INTEL_OUTPUT_DISPLAYPORT: |
| 10567 | case INTEL_OUTPUT_HDMI: |
| 10568 | case INTEL_OUTPUT_EDP: |
| 10569 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; |
| 10570 | |
| 10571 | /* the same port mustn't appear more than once */ |
| 10572 | if (used_ports & port_mask) |
| 10573 | return false; |
| 10574 | |
| 10575 | used_ports |= port_mask; |
| 10576 | default: |
| 10577 | break; |
| 10578 | } |
| 10579 | } |
| 10580 | |
| 10581 | return true; |
| 10582 | } |
| 10583 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10584 | static void |
| 10585 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 10586 | { |
| 10587 | struct drm_crtc_state tmp_state; |
| 10588 | |
| 10589 | /* Clear only the intel specific part of the crtc state */ |
| 10590 | tmp_state = crtc_state->base; |
| 10591 | memset(crtc_state, 0, sizeof *crtc_state); |
| 10592 | crtc_state->base = tmp_state; |
| 10593 | } |
| 10594 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10595 | static struct intel_crtc_state * |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10596 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10597 | struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10598 | struct drm_display_mode *mode, |
| 10599 | struct drm_atomic_state *state) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10600 | { |
| 10601 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10602 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10603 | struct intel_connector *connector; |
| 10604 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10605 | struct intel_crtc_state *pipe_config; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10606 | int plane_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10607 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10608 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10609 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10610 | if (!check_encoder_cloning(to_intel_crtc(crtc))) { |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10611 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 10612 | return ERR_PTR(-EINVAL); |
| 10613 | } |
| 10614 | |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10615 | if (!check_digital_port_conflicts(dev)) { |
| 10616 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 10617 | return ERR_PTR(-EINVAL); |
| 10618 | } |
| 10619 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10620 | pipe_config = intel_atomic_get_crtc_state(state, to_intel_crtc(crtc)); |
| 10621 | if (IS_ERR(pipe_config)) |
| 10622 | return pipe_config; |
| 10623 | |
| 10624 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10625 | |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 10626 | pipe_config->base.crtc = crtc; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10627 | drm_mode_copy(&pipe_config->base.adjusted_mode, mode); |
| 10628 | drm_mode_copy(&pipe_config->base.mode, mode); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10629 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 10630 | pipe_config->cpu_transcoder = |
| 10631 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10632 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10633 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10634 | /* |
| 10635 | * Sanitize sync polarity flags based on requested ones. If neither |
| 10636 | * positive or negative polarity is requested, treat this as meaning |
| 10637 | * negative polarity. |
| 10638 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10639 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10640 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10641 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10642 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10643 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10644 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10645 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10646 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10647 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
| 10648 | * plane pixel format and any sink constraints into account. Returns the |
| 10649 | * source plane bpp so that dithering can be selected on mismatches |
| 10650 | * after encoders and crtc also have had their say. */ |
| 10651 | plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 10652 | fb, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10653 | if (plane_bpp < 0) |
| 10654 | goto fail; |
| 10655 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10656 | /* |
| 10657 | * Determine the real pipe dimensions. Note that stereo modes can |
| 10658 | * increase the actual pipe size due to the frame doubling and |
| 10659 | * insertion of additional space for blanks between the frame. This |
| 10660 | * is stored in the crtc timings. We use the requested mode to do this |
| 10661 | * computation to clearly distinguish it from the adjusted mode, which |
| 10662 | * can be changed by the connectors in the below retry loop. |
| 10663 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10664 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 10665 | &pipe_config->pipe_src_w, |
| 10666 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10667 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10668 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10669 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10670 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10671 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10672 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10673 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10674 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 10675 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10676 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10677 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 10678 | * adjust it according to limitations or connector properties, and also |
| 10679 | * a chance to reject the mode entirely. |
| 10680 | */ |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10681 | for (i = 0; i < state->num_connector; i++) { |
| 10682 | connector = to_intel_connector(state->connectors[i]); |
| 10683 | if (!connector) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10684 | continue; |
Daniel Vetter | 7ae8923 | 2013-03-27 00:44:52 +0100 | [diff] [blame] | 10685 | |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10686 | connector_state = state->connector_states[i]; |
| 10687 | if (connector_state->crtc != crtc) |
| 10688 | continue; |
| 10689 | |
| 10690 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 10691 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 10692 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 10693 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10694 | goto fail; |
| 10695 | } |
| 10696 | } |
| 10697 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10698 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 10699 | * done afterwards in case the encoder adjusts the mode. */ |
| 10700 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10701 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10702 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10703 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 10704 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10705 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10706 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 10707 | goto fail; |
| 10708 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10709 | |
| 10710 | if (ret == RETRY) { |
| 10711 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 10712 | ret = -EINVAL; |
| 10713 | goto fail; |
| 10714 | } |
| 10715 | |
| 10716 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 10717 | retry = false; |
| 10718 | goto encoder_retry; |
| 10719 | } |
| 10720 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10721 | pipe_config->dither = pipe_config->pipe_bpp != plane_bpp; |
| 10722 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
| 10723 | plane_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
| 10724 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10725 | return pipe_config; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10726 | fail: |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10727 | return ERR_PTR(ret); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10728 | } |
| 10729 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10730 | /* Computes which crtcs are affected and sets the relevant bits in the mask. For |
| 10731 | * simplicity we use the crtc's pipe number (because it's easier to obtain). */ |
| 10732 | static void |
| 10733 | intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes, |
| 10734 | unsigned *prepare_pipes, unsigned *disable_pipes) |
| 10735 | { |
| 10736 | struct intel_crtc *intel_crtc; |
| 10737 | struct drm_device *dev = crtc->dev; |
| 10738 | struct intel_encoder *encoder; |
| 10739 | struct intel_connector *connector; |
| 10740 | struct drm_crtc *tmp_crtc; |
| 10741 | |
| 10742 | *disable_pipes = *modeset_pipes = *prepare_pipes = 0; |
| 10743 | |
| 10744 | /* Check which crtcs have changed outputs connected to them, these need |
| 10745 | * to be part of the prepare_pipes mask. We don't (yet) support global |
| 10746 | * modeset across multiple crtcs, so modeset_pipes will only have one |
| 10747 | * bit set at most. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10748 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10749 | if (connector->base.encoder == &connector->new_encoder->base) |
| 10750 | continue; |
| 10751 | |
| 10752 | if (connector->base.encoder) { |
| 10753 | tmp_crtc = connector->base.encoder->crtc; |
| 10754 | |
| 10755 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 10756 | } |
| 10757 | |
| 10758 | if (connector->new_encoder) |
| 10759 | *prepare_pipes |= |
| 10760 | 1 << connector->new_encoder->new_crtc->pipe; |
| 10761 | } |
| 10762 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10763 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10764 | if (encoder->base.crtc == &encoder->new_crtc->base) |
| 10765 | continue; |
| 10766 | |
| 10767 | if (encoder->base.crtc) { |
| 10768 | tmp_crtc = encoder->base.crtc; |
| 10769 | |
| 10770 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 10771 | } |
| 10772 | |
| 10773 | if (encoder->new_crtc) |
| 10774 | *prepare_pipes |= 1 << encoder->new_crtc->pipe; |
| 10775 | } |
| 10776 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10777 | /* Check for pipes that will be enabled/disabled ... */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10778 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10779 | if (intel_crtc->base.state->enable == intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10780 | continue; |
| 10781 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10782 | if (!intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10783 | *disable_pipes |= 1 << intel_crtc->pipe; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10784 | else |
| 10785 | *prepare_pipes |= 1 << intel_crtc->pipe; |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10786 | } |
| 10787 | |
| 10788 | |
| 10789 | /* set_mode is also used to update properties on life display pipes. */ |
| 10790 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10791 | if (intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10792 | *prepare_pipes |= 1 << intel_crtc->pipe; |
| 10793 | |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 10794 | /* |
| 10795 | * For simplicity do a full modeset on any pipe where the output routing |
| 10796 | * changed. We could be more clever, but that would require us to be |
| 10797 | * more careful with calling the relevant encoder->mode_set functions. |
| 10798 | */ |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10799 | if (*prepare_pipes) |
| 10800 | *modeset_pipes = *prepare_pipes; |
| 10801 | |
| 10802 | /* ... and mask these out. */ |
| 10803 | *modeset_pipes &= ~(*disable_pipes); |
| 10804 | *prepare_pipes &= ~(*disable_pipes); |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 10805 | |
| 10806 | /* |
| 10807 | * HACK: We don't (yet) fully support global modesets. intel_set_config |
| 10808 | * obies this rule, but the modeset restore mode of |
| 10809 | * intel_modeset_setup_hw_state does not. |
| 10810 | */ |
| 10811 | *modeset_pipes &= 1 << intel_crtc->pipe; |
| 10812 | *prepare_pipes &= 1 << intel_crtc->pipe; |
Daniel Vetter | e3641d3 | 2013-04-11 19:49:07 +0200 | [diff] [blame] | 10813 | |
| 10814 | DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n", |
| 10815 | *modeset_pipes, *prepare_pipes, *disable_pipes); |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10816 | } |
| 10817 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10818 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
| 10819 | { |
| 10820 | struct drm_encoder *encoder; |
| 10821 | struct drm_device *dev = crtc->dev; |
| 10822 | |
| 10823 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 10824 | if (encoder->crtc == crtc) |
| 10825 | return true; |
| 10826 | |
| 10827 | return false; |
| 10828 | } |
| 10829 | |
| 10830 | static void |
| 10831 | intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes) |
| 10832 | { |
Daniel Vetter | ba41c0de | 2014-11-03 15:04:55 +0100 | [diff] [blame] | 10833 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10834 | struct intel_encoder *intel_encoder; |
| 10835 | struct intel_crtc *intel_crtc; |
| 10836 | struct drm_connector *connector; |
| 10837 | |
Daniel Vetter | ba41c0de | 2014-11-03 15:04:55 +0100 | [diff] [blame] | 10838 | intel_shared_dpll_commit(dev_priv); |
| 10839 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10840 | for_each_intel_encoder(dev, intel_encoder) { |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10841 | if (!intel_encoder->base.crtc) |
| 10842 | continue; |
| 10843 | |
| 10844 | intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
| 10845 | |
| 10846 | if (prepare_pipes & (1 << intel_crtc->pipe)) |
| 10847 | intel_encoder->connectors_active = false; |
| 10848 | } |
| 10849 | |
| 10850 | intel_modeset_commit_output_state(dev); |
| 10851 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10852 | /* Double check state. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10853 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10854 | 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] | 10855 | WARN_ON(intel_crtc->new_config && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 10856 | intel_crtc->new_config != intel_crtc->config); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10857 | WARN_ON(intel_crtc->base.state->enable != !!intel_crtc->new_config); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10858 | } |
| 10859 | |
| 10860 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 10861 | if (!connector->encoder || !connector->encoder->crtc) |
| 10862 | continue; |
| 10863 | |
| 10864 | intel_crtc = to_intel_crtc(connector->encoder->crtc); |
| 10865 | |
| 10866 | if (prepare_pipes & (1 << intel_crtc->pipe)) { |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 10867 | struct drm_property *dpms_property = |
| 10868 | dev->mode_config.dpms_property; |
| 10869 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10870 | connector->dpms = DRM_MODE_DPMS_ON; |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 10871 | drm_object_property_set_value(&connector->base, |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 10872 | dpms_property, |
| 10873 | DRM_MODE_DPMS_ON); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 10874 | |
| 10875 | intel_encoder = to_intel_encoder(connector->encoder); |
| 10876 | intel_encoder->connectors_active = true; |
| 10877 | } |
| 10878 | } |
| 10879 | |
| 10880 | } |
| 10881 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 10882 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10883 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 10884 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 10885 | |
| 10886 | if (clock1 == clock2) |
| 10887 | return true; |
| 10888 | |
| 10889 | if (!clock1 || !clock2) |
| 10890 | return false; |
| 10891 | |
| 10892 | diff = abs(clock1 - clock2); |
| 10893 | |
| 10894 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 10895 | return true; |
| 10896 | |
| 10897 | return false; |
| 10898 | } |
| 10899 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10900 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 10901 | list_for_each_entry((intel_crtc), \ |
| 10902 | &(dev)->mode_config.crtc_list, \ |
| 10903 | base.head) \ |
Daniel Vetter | 0973f18 | 2013-04-19 11:25:33 +0200 | [diff] [blame] | 10904 | if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 10905 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10906 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 10907 | intel_pipe_config_compare(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10908 | struct intel_crtc_state *current_config, |
| 10909 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 10910 | { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 10911 | #define PIPE_CONF_CHECK_X(name) \ |
| 10912 | if (current_config->name != pipe_config->name) { \ |
| 10913 | DRM_ERROR("mismatch in " #name " " \ |
| 10914 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 10915 | current_config->name, \ |
| 10916 | pipe_config->name); \ |
| 10917 | return false; \ |
| 10918 | } |
| 10919 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10920 | #define PIPE_CONF_CHECK_I(name) \ |
| 10921 | if (current_config->name != pipe_config->name) { \ |
| 10922 | DRM_ERROR("mismatch in " #name " " \ |
| 10923 | "(expected %i, found %i)\n", \ |
| 10924 | current_config->name, \ |
| 10925 | pipe_config->name); \ |
| 10926 | return false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 10927 | } |
| 10928 | |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10929 | /* This is required for BDW+ where there is only one set of registers for |
| 10930 | * switching between high and low RR. |
| 10931 | * This macro can be used whenever a comparison has to be made between one |
| 10932 | * hw state and multiple sw state variables. |
| 10933 | */ |
| 10934 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ |
| 10935 | if ((current_config->name != pipe_config->name) && \ |
| 10936 | (current_config->alt_name != pipe_config->name)) { \ |
| 10937 | DRM_ERROR("mismatch in " #name " " \ |
| 10938 | "(expected %i or %i, found %i)\n", \ |
| 10939 | current_config->name, \ |
| 10940 | current_config->alt_name, \ |
| 10941 | pipe_config->name); \ |
| 10942 | return false; \ |
| 10943 | } |
| 10944 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10945 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 10946 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Jesse Barnes | 6f02488 | 2013-07-01 10:19:09 -0700 | [diff] [blame] | 10947 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 10948 | "(expected %i, found %i)\n", \ |
| 10949 | current_config->name & (mask), \ |
| 10950 | pipe_config->name & (mask)); \ |
| 10951 | return false; \ |
| 10952 | } |
| 10953 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 10954 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 10955 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
| 10956 | DRM_ERROR("mismatch in " #name " " \ |
| 10957 | "(expected %i, found %i)\n", \ |
| 10958 | current_config->name, \ |
| 10959 | pipe_config->name); \ |
| 10960 | return false; \ |
| 10961 | } |
| 10962 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 10963 | #define PIPE_CONF_QUIRK(quirk) \ |
| 10964 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 10965 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 10966 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 10967 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10968 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 10969 | PIPE_CONF_CHECK_I(fdi_lanes); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 10970 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
| 10971 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); |
| 10972 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); |
| 10973 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); |
| 10974 | PIPE_CONF_CHECK_I(fdi_m_n.tu); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 10975 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10976 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10977 | |
| 10978 | if (INTEL_INFO(dev)->gen < 8) { |
| 10979 | PIPE_CONF_CHECK_I(dp_m_n.gmch_m); |
| 10980 | PIPE_CONF_CHECK_I(dp_m_n.gmch_n); |
| 10981 | PIPE_CONF_CHECK_I(dp_m_n.link_m); |
| 10982 | PIPE_CONF_CHECK_I(dp_m_n.link_n); |
| 10983 | PIPE_CONF_CHECK_I(dp_m_n.tu); |
| 10984 | |
| 10985 | if (current_config->has_drrs) { |
| 10986 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m); |
| 10987 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n); |
| 10988 | PIPE_CONF_CHECK_I(dp_m2_n2.link_m); |
| 10989 | PIPE_CONF_CHECK_I(dp_m2_n2.link_n); |
| 10990 | PIPE_CONF_CHECK_I(dp_m2_n2.tu); |
| 10991 | } |
| 10992 | } else { |
| 10993 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m); |
| 10994 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n); |
| 10995 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m); |
| 10996 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n); |
| 10997 | PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu); |
| 10998 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10999 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11000 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 11001 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 11002 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 11003 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 11004 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 11005 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11006 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11007 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 11008 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 11009 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 11010 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 11011 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 11012 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11013 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 11014 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b5 | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 11015 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 11016 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
| 11017 | IS_VALLEYVIEW(dev)) |
| 11018 | PIPE_CONF_CHECK_I(limited_color_range); |
Jesse Barnes | e43823e | 2014-11-05 14:26:08 -0800 | [diff] [blame] | 11019 | PIPE_CONF_CHECK_I(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11020 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 11021 | PIPE_CONF_CHECK_I(has_audio); |
| 11022 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11023 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11024 | DRM_MODE_FLAG_INTERLACE); |
| 11025 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11026 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11027 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11028 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11029 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11030 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11031 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11032 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11033 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11034 | DRM_MODE_FLAG_NVSYNC); |
| 11035 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11036 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 11037 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 11038 | PIPE_CONF_CHECK_I(pipe_src_h); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11039 | |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 11040 | /* |
| 11041 | * FIXME: BIOS likes to set up a cloned config with lvds+external |
| 11042 | * screen. Since we don't yet re-compute the pipe config when moving |
| 11043 | * just the lvds port away to another pipe the sw tracking won't match. |
| 11044 | * |
| 11045 | * Proper atomic modesets with recomputed global state will fix this. |
| 11046 | * Until then just don't check gmch state for inherited modes. |
| 11047 | */ |
| 11048 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) { |
| 11049 | PIPE_CONF_CHECK_I(gmch_pfit.control); |
| 11050 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 11051 | if (INTEL_INFO(dev)->gen < 4) |
| 11052 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
| 11053 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); |
| 11054 | } |
| 11055 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 11056 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 11057 | if (current_config->pch_pfit.enabled) { |
| 11058 | PIPE_CONF_CHECK_I(pch_pfit.pos); |
| 11059 | PIPE_CONF_CHECK_I(pch_pfit.size); |
| 11060 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11061 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 11062 | /* BDW+ don't expose a synchronous way to read the state */ |
| 11063 | if (IS_HASWELL(dev)) |
| 11064 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 11065 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 11066 | PIPE_CONF_CHECK_I(double_wide); |
| 11067 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 11068 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 11069 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11070 | PIPE_CONF_CHECK_I(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11071 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 11072 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11073 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 11074 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 11075 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 11076 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 11077 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 11078 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11079 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 11080 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 11081 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 11082 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11083 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 11084 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11085 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11086 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11087 | #undef PIPE_CONF_CHECK_I |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11088 | #undef PIPE_CONF_CHECK_I_ALT |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11089 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11090 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11091 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 11092 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11093 | return true; |
| 11094 | } |
| 11095 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11096 | static void check_wm_state(struct drm_device *dev) |
| 11097 | { |
| 11098 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11099 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
| 11100 | struct intel_crtc *intel_crtc; |
| 11101 | int plane; |
| 11102 | |
| 11103 | if (INTEL_INFO(dev)->gen < 9) |
| 11104 | return; |
| 11105 | |
| 11106 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 11107 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 11108 | |
| 11109 | for_each_intel_crtc(dev, intel_crtc) { |
| 11110 | struct skl_ddb_entry *hw_entry, *sw_entry; |
| 11111 | const enum pipe pipe = intel_crtc->pipe; |
| 11112 | |
| 11113 | if (!intel_crtc->active) |
| 11114 | continue; |
| 11115 | |
| 11116 | /* planes */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 11117 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11118 | hw_entry = &hw_ddb.plane[pipe][plane]; |
| 11119 | sw_entry = &sw_ddb->plane[pipe][plane]; |
| 11120 | |
| 11121 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 11122 | continue; |
| 11123 | |
| 11124 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " |
| 11125 | "(expected (%u,%u), found (%u,%u))\n", |
| 11126 | pipe_name(pipe), plane + 1, |
| 11127 | sw_entry->start, sw_entry->end, |
| 11128 | hw_entry->start, hw_entry->end); |
| 11129 | } |
| 11130 | |
| 11131 | /* cursor */ |
| 11132 | hw_entry = &hw_ddb.cursor[pipe]; |
| 11133 | sw_entry = &sw_ddb->cursor[pipe]; |
| 11134 | |
| 11135 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 11136 | continue; |
| 11137 | |
| 11138 | DRM_ERROR("mismatch in DDB state pipe %c cursor " |
| 11139 | "(expected (%u,%u), found (%u,%u))\n", |
| 11140 | pipe_name(pipe), |
| 11141 | sw_entry->start, sw_entry->end, |
| 11142 | hw_entry->start, hw_entry->end); |
| 11143 | } |
| 11144 | } |
| 11145 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11146 | static void |
| 11147 | check_connector_state(struct drm_device *dev) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11148 | { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11149 | struct intel_connector *connector; |
| 11150 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11151 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11152 | /* This also checks the encoder/connector hw state with the |
| 11153 | * ->get_hw_state callbacks. */ |
| 11154 | intel_connector_check_state(connector); |
| 11155 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11156 | I915_STATE_WARN(&connector->new_encoder->base != connector->base.encoder, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11157 | "connector's staged encoder doesn't match current encoder\n"); |
| 11158 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11159 | } |
| 11160 | |
| 11161 | static void |
| 11162 | check_encoder_state(struct drm_device *dev) |
| 11163 | { |
| 11164 | struct intel_encoder *encoder; |
| 11165 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11166 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11167 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11168 | bool enabled = false; |
| 11169 | bool active = false; |
| 11170 | enum pipe pipe, tracked_pipe; |
| 11171 | |
| 11172 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 11173 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 11174 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11175 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11176 | I915_STATE_WARN(&encoder->new_crtc->base != encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11177 | "encoder's stage crtc doesn't match current crtc\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11178 | I915_STATE_WARN(encoder->connectors_active && !encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11179 | "encoder's active_connectors set, but no crtc\n"); |
| 11180 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11181 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11182 | if (connector->base.encoder != &encoder->base) |
| 11183 | continue; |
| 11184 | enabled = true; |
| 11185 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) |
| 11186 | active = true; |
| 11187 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11188 | /* |
| 11189 | * for MST connectors if we unplug the connector is gone |
| 11190 | * away but the encoder is still connected to a crtc |
| 11191 | * until a modeset happens in response to the hotplug. |
| 11192 | */ |
| 11193 | if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST) |
| 11194 | continue; |
| 11195 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11196 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11197 | "encoder's enabled state mismatch " |
| 11198 | "(expected %i, found %i)\n", |
| 11199 | !!encoder->base.crtc, enabled); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11200 | I915_STATE_WARN(active && !encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11201 | "active encoder with no crtc\n"); |
| 11202 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11203 | I915_STATE_WARN(encoder->connectors_active != active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11204 | "encoder's computed active state doesn't match tracked active state " |
| 11205 | "(expected %i, found %i)\n", active, encoder->connectors_active); |
| 11206 | |
| 11207 | active = encoder->get_hw_state(encoder, &pipe); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11208 | I915_STATE_WARN(active != encoder->connectors_active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11209 | "encoder's hw state doesn't match sw tracking " |
| 11210 | "(expected %i, found %i)\n", |
| 11211 | encoder->connectors_active, active); |
| 11212 | |
| 11213 | if (!encoder->base.crtc) |
| 11214 | continue; |
| 11215 | |
| 11216 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11217 | I915_STATE_WARN(active && pipe != tracked_pipe, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11218 | "active encoder's pipe doesn't match" |
| 11219 | "(expected %i, found %i)\n", |
| 11220 | tracked_pipe, pipe); |
| 11221 | |
| 11222 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11223 | } |
| 11224 | |
| 11225 | static void |
| 11226 | check_crtc_state(struct drm_device *dev) |
| 11227 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11228 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11229 | struct intel_crtc *crtc; |
| 11230 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11231 | struct intel_crtc_state pipe_config; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11232 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11233 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11234 | bool enabled = false; |
| 11235 | bool active = false; |
| 11236 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11237 | memset(&pipe_config, 0, sizeof(pipe_config)); |
| 11238 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11239 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 11240 | crtc->base.base.id); |
| 11241 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11242 | I915_STATE_WARN(crtc->active && !crtc->base.state->enable, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11243 | "active crtc, but not enabled in sw tracking\n"); |
| 11244 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11245 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11246 | if (encoder->base.crtc != &crtc->base) |
| 11247 | continue; |
| 11248 | enabled = true; |
| 11249 | if (encoder->connectors_active) |
| 11250 | active = true; |
| 11251 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11252 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11253 | I915_STATE_WARN(active != crtc->active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11254 | "crtc's computed active state doesn't match tracked active state " |
| 11255 | "(expected %i, found %i)\n", active, crtc->active); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11256 | I915_STATE_WARN(enabled != crtc->base.state->enable, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11257 | "crtc's computed enabled state doesn't match tracked enabled state " |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11258 | "(expected %i, found %i)\n", enabled, |
| 11259 | crtc->base.state->enable); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11260 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11261 | active = dev_priv->display.get_pipe_config(crtc, |
| 11262 | &pipe_config); |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 11263 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 11264 | /* hw state is inconsistent with the pipe quirk */ |
| 11265 | if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 11266 | (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 11267 | active = crtc->active; |
| 11268 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11269 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 3eaba51 | 2013-08-05 17:57:48 +0300 | [diff] [blame] | 11270 | enum pipe pipe; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11271 | if (encoder->base.crtc != &crtc->base) |
| 11272 | continue; |
Daniel Vetter | 1d37b68 | 2013-11-18 09:00:59 +0100 | [diff] [blame] | 11273 | if (encoder->get_hw_state(encoder, &pipe)) |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11274 | encoder->get_config(encoder, &pipe_config); |
| 11275 | } |
| 11276 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11277 | I915_STATE_WARN(crtc->active != active, |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11278 | "crtc active state doesn't match with hw state " |
| 11279 | "(expected %i, found %i)\n", crtc->active, active); |
| 11280 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11281 | if (active && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11282 | !intel_pipe_config_compare(dev, crtc->config, &pipe_config)) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11283 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11284 | intel_dump_pipe_config(crtc, &pipe_config, |
| 11285 | "[hw state]"); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11286 | intel_dump_pipe_config(crtc, crtc->config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11287 | "[sw state]"); |
| 11288 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11289 | } |
| 11290 | } |
| 11291 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11292 | static void |
| 11293 | check_shared_dpll_state(struct drm_device *dev) |
| 11294 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11295 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11296 | struct intel_crtc *crtc; |
| 11297 | struct intel_dpll_hw_state dpll_hw_state; |
| 11298 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11299 | |
| 11300 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 11301 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 11302 | int enabled_crtcs = 0, active_crtcs = 0; |
| 11303 | bool active; |
| 11304 | |
| 11305 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 11306 | |
| 11307 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 11308 | |
| 11309 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 11310 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11311 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11312 | "more active pll users than references: %i vs %i\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 11313 | pll->active, hweight32(pll->config.crtc_mask)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11314 | I915_STATE_WARN(pll->active && !pll->on, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11315 | "pll in active use but not on in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11316 | I915_STATE_WARN(pll->on && !pll->active, |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 11317 | "pll in on but not on in use in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11318 | I915_STATE_WARN(pll->on != active, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11319 | "pll on state mismatch (expected %i, found %i)\n", |
| 11320 | pll->on, active); |
| 11321 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11322 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11323 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11324 | enabled_crtcs++; |
| 11325 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 11326 | active_crtcs++; |
| 11327 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11328 | I915_STATE_WARN(pll->active != active_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11329 | "pll active crtcs mismatch (expected %i, found %i)\n", |
| 11330 | pll->active, active_crtcs); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11331 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11332 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 11333 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11334 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11335 | 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] | 11336 | sizeof(dpll_hw_state)), |
| 11337 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11338 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11339 | } |
| 11340 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11341 | void |
| 11342 | intel_modeset_check_state(struct drm_device *dev) |
| 11343 | { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11344 | check_wm_state(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11345 | check_connector_state(dev); |
| 11346 | check_encoder_state(dev); |
| 11347 | check_crtc_state(dev); |
| 11348 | check_shared_dpll_state(dev); |
| 11349 | } |
| 11350 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11351 | 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] | 11352 | int dotclock) |
| 11353 | { |
| 11354 | /* |
| 11355 | * FDI already provided one idea for the dotclock. |
| 11356 | * Yell if the encoder disagrees. |
| 11357 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11358 | 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] | 11359 | "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] | 11360 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11361 | } |
| 11362 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11363 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 11364 | { |
| 11365 | struct drm_device *dev = crtc->base.dev; |
| 11366 | |
| 11367 | /* |
| 11368 | * The scanline counter increments at the leading edge of hsync. |
| 11369 | * |
| 11370 | * On most platforms it starts counting from vtotal-1 on the |
| 11371 | * first active line. That means the scanline counter value is |
| 11372 | * always one less than what we would expect. Ie. just after |
| 11373 | * start of vblank, which also occurs at start of hsync (on the |
| 11374 | * last active line), the scanline counter will read vblank_start-1. |
| 11375 | * |
| 11376 | * On gen2 the scanline counter starts counting from 1 instead |
| 11377 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 11378 | * to keep the value positive), instead of adding one. |
| 11379 | * |
| 11380 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 11381 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 11382 | * there's an extra 1 line difference. So we need to add two instead of |
| 11383 | * one to the value. |
| 11384 | */ |
| 11385 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11386 | const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11387 | int vtotal; |
| 11388 | |
| 11389 | vtotal = mode->crtc_vtotal; |
| 11390 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 11391 | vtotal /= 2; |
| 11392 | |
| 11393 | crtc->scanline_offset = vtotal - 1; |
| 11394 | } else if (HAS_DDI(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 11395 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11396 | crtc->scanline_offset = 2; |
| 11397 | } else |
| 11398 | crtc->scanline_offset = 1; |
| 11399 | } |
| 11400 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11401 | static struct intel_crtc_state * |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11402 | intel_modeset_compute_config(struct drm_crtc *crtc, |
| 11403 | struct drm_display_mode *mode, |
| 11404 | struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11405 | struct drm_atomic_state *state, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11406 | unsigned *modeset_pipes, |
| 11407 | unsigned *prepare_pipes, |
| 11408 | unsigned *disable_pipes) |
| 11409 | { |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11410 | struct drm_device *dev = crtc->dev; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11411 | struct intel_crtc_state *pipe_config = NULL; |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11412 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11413 | int ret = 0; |
| 11414 | |
| 11415 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 11416 | if (ret) |
| 11417 | return ERR_PTR(ret); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11418 | |
| 11419 | intel_modeset_affected_pipes(crtc, modeset_pipes, |
| 11420 | prepare_pipes, disable_pipes); |
| 11421 | |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11422 | for_each_intel_crtc_masked(dev, *disable_pipes, intel_crtc) { |
| 11423 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 11424 | if (IS_ERR(pipe_config)) |
| 11425 | return pipe_config; |
| 11426 | |
| 11427 | pipe_config->base.enable = false; |
| 11428 | } |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11429 | |
| 11430 | /* |
| 11431 | * Note this needs changes when we start tracking multiple modes |
| 11432 | * and crtcs. At that point we'll need to compute the whole config |
| 11433 | * (i.e. one pipe_config for each crtc) rather than just the one |
| 11434 | * for this crtc. |
| 11435 | */ |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11436 | for_each_intel_crtc_masked(dev, *modeset_pipes, intel_crtc) { |
| 11437 | /* FIXME: For now we still expect modeset_pipes has at most |
| 11438 | * one bit set. */ |
| 11439 | if (WARN_ON(&intel_crtc->base != crtc)) |
| 11440 | continue; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11441 | |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11442 | pipe_config = intel_modeset_pipe_config(crtc, fb, mode, state); |
| 11443 | if (IS_ERR(pipe_config)) |
| 11444 | return pipe_config; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11445 | |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11446 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 11447 | "[modeset]"); |
| 11448 | } |
| 11449 | |
| 11450 | return intel_atomic_get_crtc_state(state, to_intel_crtc(crtc));; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11451 | } |
| 11452 | |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11453 | static int __intel_set_mode_setup_plls(struct drm_device *dev, |
| 11454 | unsigned modeset_pipes, |
| 11455 | unsigned disable_pipes) |
| 11456 | { |
| 11457 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 11458 | unsigned clear_pipes = modeset_pipes | disable_pipes; |
| 11459 | struct intel_crtc *intel_crtc; |
| 11460 | int ret = 0; |
| 11461 | |
| 11462 | if (!dev_priv->display.crtc_compute_clock) |
| 11463 | return 0; |
| 11464 | |
| 11465 | ret = intel_shared_dpll_start_config(dev_priv, clear_pipes); |
| 11466 | if (ret) |
| 11467 | goto done; |
| 11468 | |
| 11469 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
| 11470 | struct intel_crtc_state *state = intel_crtc->new_config; |
| 11471 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
| 11472 | state); |
| 11473 | if (ret) { |
| 11474 | intel_shared_dpll_abort_config(dev_priv); |
| 11475 | goto done; |
| 11476 | } |
| 11477 | } |
| 11478 | |
| 11479 | done: |
| 11480 | return ret; |
| 11481 | } |
| 11482 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11483 | static int __intel_set_mode(struct drm_crtc *crtc, |
| 11484 | struct drm_display_mode *mode, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11485 | int x, int y, struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11486 | struct intel_crtc_state *pipe_config, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11487 | unsigned modeset_pipes, |
| 11488 | unsigned prepare_pipes, |
| 11489 | unsigned disable_pipes) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11490 | { |
| 11491 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11492 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11493 | struct drm_display_mode *saved_mode; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11494 | struct intel_crtc_state *crtc_state_copy = NULL; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11495 | struct intel_crtc *intel_crtc; |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11496 | int ret = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11497 | |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11498 | saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11499 | if (!saved_mode) |
| 11500 | return -ENOMEM; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11501 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11502 | crtc_state_copy = kmalloc(sizeof(*crtc_state_copy), GFP_KERNEL); |
| 11503 | if (!crtc_state_copy) { |
| 11504 | ret = -ENOMEM; |
| 11505 | goto done; |
| 11506 | } |
| 11507 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11508 | *saved_mode = crtc->mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11509 | |
Ville Syrjälä | b9950a1 | 2014-11-21 21:00:36 +0200 | [diff] [blame] | 11510 | if (modeset_pipes) |
| 11511 | to_intel_crtc(crtc)->new_config = pipe_config; |
| 11512 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 11513 | /* |
| 11514 | * See if the config requires any additional preparation, e.g. |
| 11515 | * to adjust global state with pipes off. We need to do this |
| 11516 | * here so we can get the modeset_pipe updated config for the new |
| 11517 | * mode set on this crtc. For other crtcs we need to use the |
| 11518 | * adjusted_mode bits in the crtc directly. |
| 11519 | */ |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 11520 | if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 11521 | valleyview_modeset_global_pipes(dev, &prepare_pipes); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 11522 | |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 11523 | /* may have added more to prepare_pipes than we should */ |
| 11524 | prepare_pipes &= ~disable_pipes; |
| 11525 | } |
| 11526 | |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11527 | ret = __intel_set_mode_setup_plls(dev, modeset_pipes, disable_pipes); |
| 11528 | if (ret) |
| 11529 | goto done; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 11530 | |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 11531 | for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc) |
| 11532 | intel_crtc_disable(&intel_crtc->base); |
| 11533 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11534 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11535 | if (intel_crtc->base.state->enable) |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11536 | dev_priv->display.crtc_disable(&intel_crtc->base); |
| 11537 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11538 | |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 11539 | /* crtc->mode is already used by the ->mode_set callbacks, hence we need |
| 11540 | * 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] | 11541 | * |
| 11542 | * Note we'll need to fix this up when we start tracking multiple |
| 11543 | * pipes; here we assume a single modeset_pipe and only track the |
| 11544 | * single crtc and mode. |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 11545 | */ |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11546 | if (modeset_pipes) { |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11547 | crtc->mode = *mode; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11548 | /* mode_set/enable/disable functions rely on a correct pipe |
| 11549 | * config. */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 11550 | intel_crtc_set_state(to_intel_crtc(crtc), pipe_config); |
Ville Syrjälä | c326c0a | 2013-10-28 12:53:41 +0200 | [diff] [blame] | 11551 | |
| 11552 | /* |
| 11553 | * Calculate and store various constants which |
| 11554 | * are later needed by vblank and swap-completion |
| 11555 | * timestamping. They are derived from true hwmode. |
| 11556 | */ |
| 11557 | drm_calc_timestamping_constants(crtc, |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11558 | &pipe_config->base.adjusted_mode); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11559 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11560 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11561 | /* Only after disabling all output pipelines that will be changed can we |
| 11562 | * update the the output configuration. */ |
| 11563 | intel_modeset_update_state(dev, prepare_pipes); |
| 11564 | |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 11565 | modeset_update_crtc_power_domains(pipe_config->base.state); |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 11566 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11567 | /* Set up the DPLL and any encoders state that needs to adjust or depend |
| 11568 | * on the DPLL. |
| 11569 | */ |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11570 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11571 | struct drm_plane *primary = intel_crtc->base.primary; |
| 11572 | int vdisplay, hdisplay; |
Daniel Vetter | 4c10794 | 2014-04-24 23:55:05 +0200 | [diff] [blame] | 11573 | |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11574 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
| 11575 | ret = primary->funcs->update_plane(primary, &intel_crtc->base, |
| 11576 | fb, 0, 0, |
| 11577 | hdisplay, vdisplay, |
| 11578 | x << 16, y << 16, |
| 11579 | hdisplay << 16, vdisplay << 16); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11580 | } |
| 11581 | |
| 11582 | /* 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] | 11583 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
| 11584 | update_scanline_offset(intel_crtc); |
| 11585 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11586 | dev_priv->display.crtc_enable(&intel_crtc->base); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11587 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11588 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11589 | /* FIXME: add subpixel order */ |
| 11590 | done: |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11591 | if (ret && crtc->state->enable) |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11592 | crtc->mode = *saved_mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11593 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11594 | if (ret == 0 && pipe_config) { |
| 11595 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11596 | |
| 11597 | /* The pipe_config will be freed with the atomic state, so |
| 11598 | * make a copy. */ |
| 11599 | memcpy(crtc_state_copy, intel_crtc->config, |
| 11600 | sizeof *crtc_state_copy); |
| 11601 | intel_crtc->config = crtc_state_copy; |
| 11602 | intel_crtc->base.state = &crtc_state_copy->base; |
| 11603 | |
| 11604 | if (modeset_pipes) |
| 11605 | intel_crtc->new_config = intel_crtc->config; |
| 11606 | } else { |
| 11607 | kfree(crtc_state_copy); |
| 11608 | } |
| 11609 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11610 | kfree(saved_mode); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11611 | return ret; |
| 11612 | } |
| 11613 | |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11614 | static int intel_set_mode_pipes(struct drm_crtc *crtc, |
| 11615 | struct drm_display_mode *mode, |
| 11616 | int x, int y, struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11617 | struct intel_crtc_state *pipe_config, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11618 | unsigned modeset_pipes, |
| 11619 | unsigned prepare_pipes, |
| 11620 | unsigned disable_pipes) |
| 11621 | { |
| 11622 | int ret; |
| 11623 | |
| 11624 | ret = __intel_set_mode(crtc, mode, x, y, fb, pipe_config, modeset_pipes, |
| 11625 | prepare_pipes, disable_pipes); |
| 11626 | |
| 11627 | if (ret == 0) |
| 11628 | intel_modeset_check_state(crtc->dev); |
| 11629 | |
| 11630 | return ret; |
| 11631 | } |
| 11632 | |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 11633 | static int intel_set_mode(struct drm_crtc *crtc, |
| 11634 | struct drm_display_mode *mode, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11635 | int x, int y, struct drm_framebuffer *fb, |
| 11636 | struct drm_atomic_state *state) |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11637 | { |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11638 | struct intel_crtc_state *pipe_config; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11639 | unsigned modeset_pipes, prepare_pipes, disable_pipes; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11640 | int ret = 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11641 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11642 | pipe_config = intel_modeset_compute_config(crtc, mode, fb, state, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11643 | &modeset_pipes, |
| 11644 | &prepare_pipes, |
| 11645 | &disable_pipes); |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11646 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11647 | if (IS_ERR(pipe_config)) { |
| 11648 | ret = PTR_ERR(pipe_config); |
| 11649 | goto out; |
| 11650 | } |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11651 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11652 | ret = intel_set_mode_pipes(crtc, mode, x, y, fb, pipe_config, |
| 11653 | modeset_pipes, prepare_pipes, |
| 11654 | disable_pipes); |
| 11655 | if (ret) |
| 11656 | goto out; |
| 11657 | |
| 11658 | out: |
| 11659 | return ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11660 | } |
| 11661 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11662 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 11663 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11664 | struct drm_device *dev = crtc->dev; |
| 11665 | struct drm_atomic_state *state; |
| 11666 | struct intel_encoder *encoder; |
| 11667 | struct intel_connector *connector; |
| 11668 | struct drm_connector_state *connector_state; |
| 11669 | |
| 11670 | state = drm_atomic_state_alloc(dev); |
| 11671 | if (!state) { |
| 11672 | DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory", |
| 11673 | crtc->base.id); |
| 11674 | return; |
| 11675 | } |
| 11676 | |
| 11677 | state->acquire_ctx = dev->mode_config.acquire_ctx; |
| 11678 | |
| 11679 | /* The force restore path in the HW readout code relies on the staged |
| 11680 | * config still keeping the user requested config while the actual |
| 11681 | * state has been overwritten by the configuration read from HW. We |
| 11682 | * need to copy the staged config to the atomic state, otherwise the |
| 11683 | * mode set will just reapply the state the HW is already in. */ |
| 11684 | for_each_intel_encoder(dev, encoder) { |
| 11685 | if (&encoder->new_crtc->base != crtc) |
| 11686 | continue; |
| 11687 | |
| 11688 | for_each_intel_connector(dev, connector) { |
| 11689 | if (connector->new_encoder != encoder) |
| 11690 | continue; |
| 11691 | |
| 11692 | connector_state = drm_atomic_get_connector_state(state, &connector->base); |
| 11693 | if (IS_ERR(connector_state)) { |
| 11694 | DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n", |
| 11695 | connector->base.base.id, |
| 11696 | connector->base.name, |
| 11697 | PTR_ERR(connector_state)); |
| 11698 | continue; |
| 11699 | } |
| 11700 | |
| 11701 | connector_state->crtc = crtc; |
| 11702 | connector_state->best_encoder = &encoder->base; |
| 11703 | } |
| 11704 | } |
| 11705 | |
| 11706 | intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb, |
| 11707 | state); |
| 11708 | |
| 11709 | drm_atomic_state_free(state); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11710 | } |
| 11711 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11712 | #undef for_each_intel_crtc_masked |
| 11713 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11714 | static void intel_set_config_free(struct intel_set_config *config) |
| 11715 | { |
| 11716 | if (!config) |
| 11717 | return; |
| 11718 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11719 | kfree(config->save_connector_encoders); |
| 11720 | kfree(config->save_encoder_crtcs); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11721 | kfree(config->save_crtc_enabled); |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11722 | kfree(config); |
| 11723 | } |
| 11724 | |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11725 | static int intel_set_config_save_state(struct drm_device *dev, |
| 11726 | struct intel_set_config *config) |
| 11727 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11728 | struct drm_crtc *crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11729 | struct drm_encoder *encoder; |
| 11730 | struct drm_connector *connector; |
| 11731 | int count; |
| 11732 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11733 | config->save_crtc_enabled = |
| 11734 | kcalloc(dev->mode_config.num_crtc, |
| 11735 | sizeof(bool), GFP_KERNEL); |
| 11736 | if (!config->save_crtc_enabled) |
| 11737 | return -ENOMEM; |
| 11738 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11739 | config->save_encoder_crtcs = |
| 11740 | kcalloc(dev->mode_config.num_encoder, |
| 11741 | sizeof(struct drm_crtc *), GFP_KERNEL); |
| 11742 | if (!config->save_encoder_crtcs) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11743 | return -ENOMEM; |
| 11744 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11745 | config->save_connector_encoders = |
| 11746 | kcalloc(dev->mode_config.num_connector, |
| 11747 | sizeof(struct drm_encoder *), GFP_KERNEL); |
| 11748 | if (!config->save_connector_encoders) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11749 | return -ENOMEM; |
| 11750 | |
| 11751 | /* Copy data. Note that driver private data is not affected. |
| 11752 | * Should anything bad happen only the expected state is |
| 11753 | * restored, not the drivers personal bookkeeping. |
| 11754 | */ |
| 11755 | count = 0; |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 11756 | for_each_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11757 | config->save_crtc_enabled[count++] = crtc->state->enable; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11758 | } |
| 11759 | |
| 11760 | count = 0; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11761 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11762 | config->save_encoder_crtcs[count++] = encoder->crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11763 | } |
| 11764 | |
| 11765 | count = 0; |
| 11766 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11767 | config->save_connector_encoders[count++] = connector->encoder; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11768 | } |
| 11769 | |
| 11770 | return 0; |
| 11771 | } |
| 11772 | |
| 11773 | static void intel_set_config_restore_state(struct drm_device *dev, |
| 11774 | struct intel_set_config *config) |
| 11775 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11776 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11777 | struct intel_encoder *encoder; |
| 11778 | struct intel_connector *connector; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11779 | int count; |
| 11780 | |
| 11781 | count = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11782 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11783 | crtc->new_enabled = config->save_crtc_enabled[count++]; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11784 | |
| 11785 | if (crtc->new_enabled) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11786 | crtc->new_config = crtc->config; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 11787 | else |
| 11788 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11789 | } |
| 11790 | |
| 11791 | count = 0; |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11792 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11793 | encoder->new_crtc = |
| 11794 | to_intel_crtc(config->save_encoder_crtcs[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11795 | } |
| 11796 | |
| 11797 | count = 0; |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11798 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11799 | connector->new_encoder = |
| 11800 | to_intel_encoder(config->save_connector_encoders[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11801 | } |
| 11802 | } |
| 11803 | |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11804 | static bool |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11805 | is_crtc_connector_off(struct drm_mode_set *set) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11806 | { |
| 11807 | int i; |
| 11808 | |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11809 | if (set->num_connectors == 0) |
| 11810 | return false; |
| 11811 | |
| 11812 | if (WARN_ON(set->connectors == NULL)) |
| 11813 | return false; |
| 11814 | |
| 11815 | for (i = 0; i < set->num_connectors; i++) |
| 11816 | if (set->connectors[i]->encoder && |
| 11817 | set->connectors[i]->encoder->crtc == set->crtc && |
| 11818 | set->connectors[i]->dpms != DRM_MODE_DPMS_ON) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11819 | return true; |
| 11820 | |
| 11821 | return false; |
| 11822 | } |
| 11823 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11824 | static void |
| 11825 | intel_set_config_compute_mode_changes(struct drm_mode_set *set, |
| 11826 | struct intel_set_config *config) |
| 11827 | { |
| 11828 | |
| 11829 | /* We should be able to check here if the fb has the same properties |
| 11830 | * and then just flip_or_move it */ |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 11831 | if (is_crtc_connector_off(set)) { |
| 11832 | config->mode_changed = true; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11833 | } else if (set->crtc->primary->fb != set->fb) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11834 | /* |
| 11835 | * If we have no fb, we can only flip as long as the crtc is |
| 11836 | * active, otherwise we need a full mode set. The crtc may |
| 11837 | * be active if we've only disabled the primary plane, or |
| 11838 | * in fastboot situations. |
| 11839 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11840 | if (set->crtc->primary->fb == NULL) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 11841 | struct intel_crtc *intel_crtc = |
| 11842 | to_intel_crtc(set->crtc); |
| 11843 | |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 11844 | if (intel_crtc->active) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 11845 | DRM_DEBUG_KMS("crtc has no fb, will flip\n"); |
| 11846 | config->fb_changed = true; |
| 11847 | } else { |
| 11848 | DRM_DEBUG_KMS("inactive crtc, full mode set\n"); |
| 11849 | config->mode_changed = true; |
| 11850 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11851 | } else if (set->fb == NULL) { |
| 11852 | config->mode_changed = true; |
Daniel Vetter | 72f4901 | 2013-03-28 16:01:35 +0100 | [diff] [blame] | 11853 | } else if (set->fb->pixel_format != |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 11854 | set->crtc->primary->fb->pixel_format) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11855 | config->mode_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11856 | } else { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11857 | config->fb_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 11858 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11859 | } |
| 11860 | |
Daniel Vetter | 835c587 | 2012-07-10 18:11:08 +0200 | [diff] [blame] | 11861 | 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] | 11862 | config->fb_changed = true; |
| 11863 | |
| 11864 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
| 11865 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
| 11866 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 11867 | drm_mode_debug_printmodeline(set->mode); |
| 11868 | config->mode_changed = true; |
| 11869 | } |
Chris Wilson | a1d9570 | 2013-08-13 18:48:47 +0100 | [diff] [blame] | 11870 | |
| 11871 | DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n", |
| 11872 | set->crtc->base.id, config->mode_changed, config->fb_changed); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11873 | } |
| 11874 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 11875 | static int |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11876 | intel_modeset_stage_output_state(struct drm_device *dev, |
| 11877 | struct drm_mode_set *set, |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 11878 | struct intel_set_config *config, |
| 11879 | struct drm_atomic_state *state) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11880 | { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11881 | struct intel_connector *connector; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 11882 | struct drm_connector_state *connector_state; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11883 | struct intel_encoder *encoder; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11884 | struct intel_crtc *crtc; |
Paulo Zanoni | f3f0857 | 2013-08-12 14:56:53 -0300 | [diff] [blame] | 11885 | int ro; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11886 | |
Damien Lespiau | 9abdda7 | 2013-02-13 13:29:23 +0000 | [diff] [blame] | 11887 | /* 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] | 11888 | * of connectors. For paranoia, double-check this. */ |
| 11889 | WARN_ON(!set->fb && (set->num_connectors != 0)); |
| 11890 | WARN_ON(set->fb && (set->num_connectors == 0)); |
| 11891 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11892 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11893 | /* Otherwise traverse passed in connector list and get encoders |
| 11894 | * for them. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11895 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11896 | if (set->connectors[ro] == &connector->base) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11897 | 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] | 11898 | break; |
| 11899 | } |
| 11900 | } |
| 11901 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11902 | /* If we disable the crtc, disable all its connectors. Also, if |
| 11903 | * the connector is on the changing crtc but not on the new |
| 11904 | * connector list, disable it. */ |
| 11905 | if ((!set->fb || ro == set->num_connectors) && |
| 11906 | connector->base.encoder && |
| 11907 | connector->base.encoder->crtc == set->crtc) { |
| 11908 | connector->new_encoder = NULL; |
| 11909 | |
| 11910 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", |
| 11911 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11912 | connector->base.name); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11913 | } |
| 11914 | |
| 11915 | |
| 11916 | if (&connector->new_encoder->base != connector->base.encoder) { |
Ander Conselvan de Oliveira | 1063418 | 2015-03-03 15:21:57 +0200 | [diff] [blame] | 11917 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] encoder changed, full mode switch\n", |
| 11918 | connector->base.base.id, |
| 11919 | connector->base.name); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11920 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11921 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11922 | } |
| 11923 | /* connector->new_encoder is now updated for all connectors. */ |
| 11924 | |
| 11925 | /* Update crtc of enabled connectors. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11926 | for_each_intel_connector(dev, connector) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11927 | struct drm_crtc *new_crtc; |
| 11928 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11929 | if (!connector->new_encoder) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11930 | continue; |
| 11931 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11932 | new_crtc = connector->new_encoder->base.crtc; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11933 | |
| 11934 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11935 | if (set->connectors[ro] == &connector->base) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11936 | new_crtc = set->crtc; |
| 11937 | } |
| 11938 | |
| 11939 | /* Make sure the new CRTC will work with the encoder */ |
Thierry Reding | 1450991 | 2014-01-13 12:00:22 +0100 | [diff] [blame] | 11940 | if (!drm_encoder_crtc_ok(&connector->new_encoder->base, |
| 11941 | new_crtc)) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11942 | return -EINVAL; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11943 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11944 | connector->new_encoder->new_crtc = to_intel_crtc(new_crtc); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11945 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 11946 | connector_state = |
| 11947 | drm_atomic_get_connector_state(state, &connector->base); |
| 11948 | if (IS_ERR(connector_state)) |
| 11949 | return PTR_ERR(connector_state); |
| 11950 | |
| 11951 | connector_state->crtc = new_crtc; |
| 11952 | connector_state->best_encoder = &connector->new_encoder->base; |
| 11953 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11954 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
| 11955 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 11956 | connector->base.name, |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11957 | new_crtc->base.id); |
| 11958 | } |
| 11959 | |
| 11960 | /* Check for any encoders that needs to be disabled. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11961 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11962 | int num_connectors = 0; |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11963 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11964 | if (connector->new_encoder == encoder) { |
| 11965 | WARN_ON(!connector->new_encoder->new_crtc); |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11966 | num_connectors++; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11967 | } |
| 11968 | } |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 11969 | |
| 11970 | if (num_connectors == 0) |
| 11971 | encoder->new_crtc = NULL; |
| 11972 | else if (num_connectors > 1) |
| 11973 | return -EINVAL; |
| 11974 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11975 | /* Only now check for crtc changes so we don't miss encoders |
| 11976 | * that will be disabled. */ |
| 11977 | if (&encoder->new_crtc->base != encoder->base.crtc) { |
Ander Conselvan de Oliveira | 1063418 | 2015-03-03 15:21:57 +0200 | [diff] [blame] | 11978 | DRM_DEBUG_KMS("[ENCODER:%d:%s] crtc changed, full mode switch\n", |
| 11979 | encoder->base.base.id, |
| 11980 | encoder->base.name); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 11981 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 11982 | } |
| 11983 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 11984 | /* 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] | 11985 | for_each_intel_connector(dev, connector) { |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 11986 | connector_state = |
| 11987 | drm_atomic_get_connector_state(state, &connector->base); |
Ander Conselvan de Oliveira | 9d918c1 | 2015-03-27 15:33:51 +0200 | [diff] [blame] | 11988 | if (IS_ERR(connector_state)) |
| 11989 | return PTR_ERR(connector_state); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 11990 | |
| 11991 | if (connector->new_encoder) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11992 | if (connector->new_encoder != connector->encoder) |
| 11993 | connector->encoder = connector->new_encoder; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 11994 | } else { |
| 11995 | connector_state->crtc = NULL; |
| 11996 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11997 | } |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11998 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11999 | crtc->new_enabled = false; |
| 12000 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12001 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12002 | if (encoder->new_crtc == crtc) { |
| 12003 | crtc->new_enabled = true; |
| 12004 | break; |
| 12005 | } |
| 12006 | } |
| 12007 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 12008 | if (crtc->new_enabled != crtc->base.state->enable) { |
Ander Conselvan de Oliveira | 1063418 | 2015-03-03 15:21:57 +0200 | [diff] [blame] | 12009 | DRM_DEBUG_KMS("[CRTC:%d] %sabled, full mode switch\n", |
| 12010 | crtc->base.base.id, |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12011 | crtc->new_enabled ? "en" : "dis"); |
| 12012 | config->mode_changed = true; |
| 12013 | } |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 12014 | |
| 12015 | if (crtc->new_enabled) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 12016 | crtc->new_config = crtc->config; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 12017 | else |
| 12018 | crtc->new_config = NULL; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12019 | } |
| 12020 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12021 | return 0; |
| 12022 | } |
| 12023 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 12024 | static void disable_crtc_nofb(struct intel_crtc *crtc) |
| 12025 | { |
| 12026 | struct drm_device *dev = crtc->base.dev; |
| 12027 | struct intel_encoder *encoder; |
| 12028 | struct intel_connector *connector; |
| 12029 | |
| 12030 | DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n", |
| 12031 | pipe_name(crtc->pipe)); |
| 12032 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12033 | for_each_intel_connector(dev, connector) { |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 12034 | if (connector->new_encoder && |
| 12035 | connector->new_encoder->new_crtc == crtc) |
| 12036 | connector->new_encoder = NULL; |
| 12037 | } |
| 12038 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12039 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 12040 | if (encoder->new_crtc == crtc) |
| 12041 | encoder->new_crtc = NULL; |
| 12042 | } |
| 12043 | |
| 12044 | crtc->new_enabled = false; |
Ville Syrjälä | 7bd0a8e | 2014-01-14 14:31:38 +0200 | [diff] [blame] | 12045 | crtc->new_config = NULL; |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 12046 | } |
| 12047 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12048 | static int intel_crtc_set_config(struct drm_mode_set *set) |
| 12049 | { |
| 12050 | struct drm_device *dev; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12051 | struct drm_mode_set save_set; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12052 | struct drm_atomic_state *state = NULL; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12053 | struct intel_set_config *config; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12054 | struct intel_crtc_state *pipe_config; |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12055 | unsigned modeset_pipes, prepare_pipes, disable_pipes; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12056 | int ret; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12057 | |
Daniel Vetter | 8d3e375 | 2012-07-05 16:09:09 +0200 | [diff] [blame] | 12058 | BUG_ON(!set); |
| 12059 | BUG_ON(!set->crtc); |
| 12060 | BUG_ON(!set->crtc->helper_private); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12061 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 12062 | /* Enforce sane interface api - has been abused by the fb helper. */ |
| 12063 | BUG_ON(!set->mode && set->fb); |
| 12064 | BUG_ON(set->fb && set->num_connectors == 0); |
Daniel Vetter | 431e50f | 2012-07-10 17:53:42 +0200 | [diff] [blame] | 12065 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12066 | if (set->fb) { |
| 12067 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", |
| 12068 | set->crtc->base.id, set->fb->base.id, |
| 12069 | (int)set->num_connectors, set->x, set->y); |
| 12070 | } else { |
| 12071 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12072 | } |
| 12073 | |
| 12074 | dev = set->crtc->dev; |
| 12075 | |
| 12076 | ret = -ENOMEM; |
| 12077 | config = kzalloc(sizeof(*config), GFP_KERNEL); |
| 12078 | if (!config) |
| 12079 | goto out_config; |
| 12080 | |
| 12081 | ret = intel_set_config_save_state(dev, config); |
| 12082 | if (ret) |
| 12083 | goto out_config; |
| 12084 | |
| 12085 | save_set.crtc = set->crtc; |
| 12086 | save_set.mode = &set->crtc->mode; |
| 12087 | save_set.x = set->crtc->x; |
| 12088 | save_set.y = set->crtc->y; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 12089 | save_set.fb = set->crtc->primary->fb; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12090 | |
| 12091 | /* Compute whether we need a full modeset, only an fb base update or no |
| 12092 | * change at all. In the future we might also check whether only the |
| 12093 | * mode changed, e.g. for LVDS where we only change the panel fitter in |
| 12094 | * such cases. */ |
| 12095 | intel_set_config_compute_mode_changes(set, config); |
| 12096 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12097 | state = drm_atomic_state_alloc(dev); |
| 12098 | if (!state) { |
| 12099 | ret = -ENOMEM; |
| 12100 | goto out_config; |
| 12101 | } |
| 12102 | |
| 12103 | state->acquire_ctx = dev->mode_config.acquire_ctx; |
| 12104 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12105 | ret = intel_modeset_stage_output_state(dev, set, config, state); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12106 | if (ret) |
| 12107 | goto fail; |
| 12108 | |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12109 | pipe_config = intel_modeset_compute_config(set->crtc, set->mode, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12110 | set->fb, state, |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12111 | &modeset_pipes, |
| 12112 | &prepare_pipes, |
| 12113 | &disable_pipes); |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12114 | if (IS_ERR(pipe_config)) { |
Matt Roper | 6ac0483 | 2014-11-17 09:59:28 -0800 | [diff] [blame] | 12115 | ret = PTR_ERR(pipe_config); |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12116 | goto fail; |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12117 | } else if (pipe_config) { |
Ville Syrjälä | b9950a1 | 2014-11-21 21:00:36 +0200 | [diff] [blame] | 12118 | if (pipe_config->has_audio != |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 12119 | to_intel_crtc(set->crtc)->config->has_audio) |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12120 | config->mode_changed = true; |
| 12121 | |
Jesse Barnes | af15d2c | 2014-12-01 09:54:28 -0800 | [diff] [blame] | 12122 | /* |
| 12123 | * Note we have an issue here with infoframes: current code |
| 12124 | * only updates them on the full mode set path per hw |
| 12125 | * requirements. So here we should be checking for any |
| 12126 | * required changes and forcing a mode set. |
| 12127 | */ |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12128 | } |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12129 | |
Jesse Barnes | 1f9954d | 2014-11-05 14:26:10 -0800 | [diff] [blame] | 12130 | intel_update_pipe_size(to_intel_crtc(set->crtc)); |
| 12131 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12132 | if (config->mode_changed) { |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12133 | ret = intel_set_mode_pipes(set->crtc, set->mode, |
| 12134 | set->x, set->y, set->fb, pipe_config, |
| 12135 | modeset_pipes, prepare_pipes, |
| 12136 | disable_pipes); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12137 | } else if (config->fb_changed) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12138 | struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 12139 | struct drm_plane *primary = set->crtc->primary; |
| 12140 | int vdisplay, hdisplay; |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12141 | |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 12142 | drm_crtc_get_hv_timing(set->mode, &hdisplay, &vdisplay); |
| 12143 | ret = primary->funcs->update_plane(primary, set->crtc, set->fb, |
| 12144 | 0, 0, hdisplay, vdisplay, |
| 12145 | set->x << 16, set->y << 16, |
| 12146 | hdisplay << 16, vdisplay << 16); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12147 | |
| 12148 | /* |
| 12149 | * We need to make sure the primary plane is re-enabled if it |
| 12150 | * has previously been turned off. |
| 12151 | */ |
| 12152 | if (!intel_crtc->primary_enabled && ret == 0) { |
| 12153 | WARN_ON(!intel_crtc->active); |
Ville Syrjälä | fdd508a6 | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 12154 | intel_enable_primary_hw_plane(set->crtc->primary, set->crtc); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12155 | } |
| 12156 | |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 12157 | /* |
| 12158 | * In the fastboot case this may be our only check of the |
| 12159 | * state after boot. It would be better to only do it on |
| 12160 | * the first update, but we don't have a nice way of doing that |
| 12161 | * (and really, set_config isn't used much for high freq page |
| 12162 | * flipping, so increasing its cost here shouldn't be a big |
| 12163 | * deal). |
| 12164 | */ |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 12165 | if (i915.fastboot && ret == 0) |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 12166 | intel_modeset_check_state(set->crtc->dev); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12167 | } |
| 12168 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12169 | if (ret) { |
Daniel Vetter | bf67dfe | 2013-06-25 11:06:52 +0200 | [diff] [blame] | 12170 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
| 12171 | set->crtc->base.id, ret); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12172 | fail: |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12173 | intel_set_config_restore_state(dev, config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12174 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12175 | drm_atomic_state_clear(state); |
| 12176 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 12177 | /* |
| 12178 | * HACK: if the pipe was on, but we didn't have a framebuffer, |
| 12179 | * force the pipe off to avoid oopsing in the modeset code |
| 12180 | * due to fb==NULL. This should only happen during boot since |
| 12181 | * we don't yet reconstruct the FB from the hardware state. |
| 12182 | */ |
| 12183 | if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb) |
| 12184 | disable_crtc_nofb(to_intel_crtc(save_set.crtc)); |
| 12185 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12186 | /* Try to restore the config */ |
| 12187 | if (config->mode_changed && |
| 12188 | intel_set_mode(save_set.crtc, save_set.mode, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12189 | save_set.x, save_set.y, save_set.fb, |
| 12190 | state)) |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12191 | DRM_ERROR("failed to restore config after modeset failure\n"); |
| 12192 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12193 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 12194 | out_config: |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12195 | if (state) |
| 12196 | drm_atomic_state_free(state); |
| 12197 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 12198 | intel_set_config_free(config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12199 | return ret; |
| 12200 | } |
| 12201 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12202 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12203 | .gamma_set = intel_crtc_gamma_set, |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12204 | .set_config = intel_crtc_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12205 | .destroy = intel_crtc_destroy, |
| 12206 | .page_flip = intel_crtc_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 12207 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 12208 | .atomic_destroy_state = intel_crtc_destroy_state, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12209 | }; |
| 12210 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12211 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
| 12212 | struct intel_shared_dpll *pll, |
| 12213 | struct intel_dpll_hw_state *hw_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12214 | { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12215 | uint32_t val; |
| 12216 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 12217 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 12218 | return false; |
| 12219 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12220 | val = I915_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12221 | hw_state->dpll = val; |
| 12222 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); |
| 12223 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12224 | |
| 12225 | return val & DPLL_VCO_ENABLE; |
| 12226 | } |
| 12227 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12228 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
| 12229 | struct intel_shared_dpll *pll) |
| 12230 | { |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12231 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
| 12232 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12233 | } |
| 12234 | |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12235 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
| 12236 | struct intel_shared_dpll *pll) |
| 12237 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12238 | /* PCH refclock must be enabled first */ |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 12239 | ibx_assert_pch_refclk_enabled(dev_priv); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12240 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12241 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12242 | |
| 12243 | /* Wait for the clocks to stabilize. */ |
| 12244 | POSTING_READ(PCH_DPLL(pll->id)); |
| 12245 | udelay(150); |
| 12246 | |
| 12247 | /* The pixel multiplier can only be updated once the |
| 12248 | * DPLL is enabled and the clocks are stable. |
| 12249 | * |
| 12250 | * So write it again. |
| 12251 | */ |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12252 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12253 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12254 | udelay(200); |
| 12255 | } |
| 12256 | |
| 12257 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, |
| 12258 | struct intel_shared_dpll *pll) |
| 12259 | { |
| 12260 | struct drm_device *dev = dev_priv->dev; |
| 12261 | struct intel_crtc *crtc; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12262 | |
| 12263 | /* Make sure no transcoder isn't still depending on us. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12264 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12265 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
| 12266 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); |
| 12267 | } |
| 12268 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12269 | I915_WRITE(PCH_DPLL(pll->id), 0); |
| 12270 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12271 | udelay(200); |
| 12272 | } |
| 12273 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 12274 | static char *ibx_pch_dpll_names[] = { |
| 12275 | "PCH DPLL A", |
| 12276 | "PCH DPLL B", |
| 12277 | }; |
| 12278 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12279 | static void ibx_pch_dpll_init(struct drm_device *dev) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12280 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12281 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12282 | int i; |
| 12283 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12284 | dev_priv->num_shared_dpll = 2; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12285 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 12286 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 12287 | dev_priv->shared_dplls[i].id = i; |
| 12288 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12289 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12290 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
| 12291 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12292 | dev_priv->shared_dplls[i].get_hw_state = |
| 12293 | ibx_pch_dpll_get_hw_state; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12294 | } |
| 12295 | } |
| 12296 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12297 | static void intel_shared_dpll_init(struct drm_device *dev) |
| 12298 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12299 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12300 | |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 12301 | if (HAS_DDI(dev)) |
| 12302 | intel_ddi_pll_init(dev); |
| 12303 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12304 | ibx_pch_dpll_init(dev); |
| 12305 | else |
| 12306 | dev_priv->num_shared_dpll = 0; |
| 12307 | |
| 12308 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12309 | } |
| 12310 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12311 | /** |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 12312 | * intel_wm_need_update - Check whether watermarks need updating |
| 12313 | * @plane: drm plane |
| 12314 | * @state: new plane state |
| 12315 | * |
| 12316 | * Check current plane state versus the new one to determine whether |
| 12317 | * watermarks need to be recalculated. |
| 12318 | * |
| 12319 | * Returns true or false. |
| 12320 | */ |
| 12321 | bool intel_wm_need_update(struct drm_plane *plane, |
| 12322 | struct drm_plane_state *state) |
| 12323 | { |
| 12324 | /* Update watermarks on tiling changes. */ |
| 12325 | if (!plane->state->fb || !state->fb || |
| 12326 | plane->state->fb->modifier[0] != state->fb->modifier[0] || |
| 12327 | plane->state->rotation != state->rotation) |
| 12328 | return true; |
| 12329 | |
| 12330 | return false; |
| 12331 | } |
| 12332 | |
| 12333 | /** |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12334 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 12335 | * @plane: drm plane to prepare for |
| 12336 | * @fb: framebuffer to prepare for presentation |
| 12337 | * |
| 12338 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 12339 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 12340 | * bits. Some older platforms need special physical address handling for |
| 12341 | * cursor planes. |
| 12342 | * |
| 12343 | * Returns 0 on success, negative error code on failure. |
| 12344 | */ |
| 12345 | int |
| 12346 | intel_prepare_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 12347 | struct drm_framebuffer *fb, |
| 12348 | const struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12349 | { |
| 12350 | struct drm_device *dev = plane->dev; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12351 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 12352 | enum pipe pipe = intel_plane->pipe; |
| 12353 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 12354 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); |
| 12355 | unsigned frontbuffer_bits = 0; |
| 12356 | int ret = 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12357 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12358 | if (!obj) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12359 | return 0; |
| 12360 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12361 | switch (plane->type) { |
| 12362 | case DRM_PLANE_TYPE_PRIMARY: |
| 12363 | frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(pipe); |
| 12364 | break; |
| 12365 | case DRM_PLANE_TYPE_CURSOR: |
| 12366 | frontbuffer_bits = INTEL_FRONTBUFFER_CURSOR(pipe); |
| 12367 | break; |
| 12368 | case DRM_PLANE_TYPE_OVERLAY: |
| 12369 | frontbuffer_bits = INTEL_FRONTBUFFER_SPRITE(pipe); |
| 12370 | break; |
| 12371 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12372 | |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 12373 | mutex_lock(&dev->struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12374 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12375 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
| 12376 | INTEL_INFO(dev)->cursor_needs_physical) { |
| 12377 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
| 12378 | ret = i915_gem_object_attach_phys(obj, align); |
| 12379 | if (ret) |
| 12380 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
| 12381 | } else { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 12382 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12383 | } |
| 12384 | |
| 12385 | if (ret == 0) |
| 12386 | i915_gem_track_fb(old_obj, obj, frontbuffer_bits); |
| 12387 | |
| 12388 | mutex_unlock(&dev->struct_mutex); |
| 12389 | |
| 12390 | return ret; |
| 12391 | } |
| 12392 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12393 | /** |
| 12394 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 12395 | * @plane: drm plane to clean up for |
| 12396 | * @fb: old framebuffer that was on plane |
| 12397 | * |
| 12398 | * Cleans up a framebuffer that has just been removed from a plane. |
| 12399 | */ |
| 12400 | void |
| 12401 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 12402 | struct drm_framebuffer *fb, |
| 12403 | const struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12404 | { |
| 12405 | struct drm_device *dev = plane->dev; |
| 12406 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 12407 | |
| 12408 | if (WARN_ON(!obj)) |
| 12409 | return; |
| 12410 | |
| 12411 | if (plane->type != DRM_PLANE_TYPE_CURSOR || |
| 12412 | !INTEL_INFO(dev)->cursor_needs_physical) { |
| 12413 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 12414 | intel_unpin_fb_obj(fb, old_state); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12415 | mutex_unlock(&dev->struct_mutex); |
| 12416 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12417 | } |
| 12418 | |
| 12419 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12420 | intel_check_primary_plane(struct drm_plane *plane, |
| 12421 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12422 | { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12423 | struct drm_device *dev = plane->dev; |
| 12424 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12425 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12426 | struct intel_crtc *intel_crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12427 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12428 | struct drm_rect *dest = &state->dst; |
| 12429 | struct drm_rect *src = &state->src; |
| 12430 | const struct drm_rect *clip = &state->clip; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12431 | int ret; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12432 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12433 | crtc = crtc ? crtc : plane->crtc; |
| 12434 | intel_crtc = to_intel_crtc(crtc); |
| 12435 | |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12436 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
| 12437 | src, dest, clip, |
| 12438 | DRM_PLANE_HELPER_NO_SCALING, |
| 12439 | DRM_PLANE_HELPER_NO_SCALING, |
| 12440 | false, true, &state->visible); |
| 12441 | if (ret) |
| 12442 | return ret; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12443 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12444 | if (intel_crtc->active) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12445 | intel_crtc->atomic.wait_for_flips = true; |
| 12446 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12447 | /* |
| 12448 | * FBC does not work on some platforms for rotated |
| 12449 | * planes, so disable it when rotation is not 0 and |
| 12450 | * update it when rotation is set back to 0. |
| 12451 | * |
| 12452 | * FIXME: This is redundant with the fbc update done in |
| 12453 | * the primary plane enable function except that that |
| 12454 | * one is done too late. We eventually need to unify |
| 12455 | * this. |
| 12456 | */ |
| 12457 | if (intel_crtc->primary_enabled && |
| 12458 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
Paulo Zanoni | e35fef2 | 2015-02-09 14:46:29 -0200 | [diff] [blame] | 12459 | dev_priv->fbc.crtc == intel_crtc && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12460 | state->base.rotation != BIT(DRM_ROTATE_0)) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12461 | intel_crtc->atomic.disable_fbc = true; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12462 | } |
| 12463 | |
| 12464 | if (state->visible) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12465 | /* |
| 12466 | * BDW signals flip done immediately if the plane |
| 12467 | * is disabled, even if the plane enable is already |
| 12468 | * armed to occur at the next vblank :( |
| 12469 | */ |
| 12470 | if (IS_BROADWELL(dev) && !intel_crtc->primary_enabled) |
| 12471 | intel_crtc->atomic.wait_vblank = true; |
| 12472 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12473 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12474 | intel_crtc->atomic.fb_bits |= |
| 12475 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
| 12476 | |
| 12477 | intel_crtc->atomic.update_fbc = true; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 12478 | |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 12479 | if (intel_wm_need_update(plane, &state->base)) |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 12480 | intel_crtc->atomic.update_wm = true; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12481 | } |
| 12482 | |
| 12483 | return 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12484 | } |
| 12485 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12486 | static void |
| 12487 | intel_commit_primary_plane(struct drm_plane *plane, |
| 12488 | struct intel_plane_state *state) |
| 12489 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12490 | struct drm_crtc *crtc = state->base.crtc; |
| 12491 | struct drm_framebuffer *fb = state->base.fb; |
| 12492 | struct drm_device *dev = plane->dev; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12493 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12494 | struct intel_crtc *intel_crtc; |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 12495 | struct drm_rect *src = &state->src; |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12496 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12497 | crtc = crtc ? crtc : plane->crtc; |
| 12498 | intel_crtc = to_intel_crtc(crtc); |
| 12499 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12500 | plane->fb = fb; |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 12501 | crtc->x = src->x1 >> 16; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12502 | crtc->y = src->y1 >> 16; |
| 12503 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12504 | if (intel_crtc->active) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12505 | if (state->visible) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12506 | /* FIXME: kill this fastboot hack */ |
| 12507 | intel_update_pipe_size(intel_crtc); |
| 12508 | |
| 12509 | intel_crtc->primary_enabled = true; |
| 12510 | |
| 12511 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 12512 | crtc->x, crtc->y); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12513 | } else { |
| 12514 | /* |
| 12515 | * If clipping results in a non-visible primary plane, |
| 12516 | * we'll disable the primary plane. Note that this is |
| 12517 | * a bit different than what happens if userspace |
| 12518 | * explicitly disables the plane by passing fb=0 |
| 12519 | * because plane->fb still gets set and pinned. |
| 12520 | */ |
| 12521 | intel_disable_primary_hw_plane(plane, crtc); |
| 12522 | } |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12523 | } |
| 12524 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12525 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12526 | static void intel_begin_crtc_commit(struct drm_crtc *crtc) |
| 12527 | { |
| 12528 | struct drm_device *dev = crtc->dev; |
| 12529 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12530 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12531 | struct intel_plane *intel_plane; |
| 12532 | struct drm_plane *p; |
| 12533 | unsigned fb_bits = 0; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12534 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12535 | /* Track fb's for any planes being disabled */ |
| 12536 | list_for_each_entry(p, &dev->mode_config.plane_list, head) { |
| 12537 | intel_plane = to_intel_plane(p); |
| 12538 | |
| 12539 | if (intel_crtc->atomic.disabled_planes & |
| 12540 | (1 << drm_plane_index(p))) { |
| 12541 | switch (p->type) { |
| 12542 | case DRM_PLANE_TYPE_PRIMARY: |
| 12543 | fb_bits = INTEL_FRONTBUFFER_PRIMARY(intel_plane->pipe); |
| 12544 | break; |
| 12545 | case DRM_PLANE_TYPE_CURSOR: |
| 12546 | fb_bits = INTEL_FRONTBUFFER_CURSOR(intel_plane->pipe); |
| 12547 | break; |
| 12548 | case DRM_PLANE_TYPE_OVERLAY: |
| 12549 | fb_bits = INTEL_FRONTBUFFER_SPRITE(intel_plane->pipe); |
| 12550 | break; |
| 12551 | } |
| 12552 | |
| 12553 | mutex_lock(&dev->struct_mutex); |
| 12554 | i915_gem_track_fb(intel_fb_obj(p->fb), NULL, fb_bits); |
| 12555 | mutex_unlock(&dev->struct_mutex); |
| 12556 | } |
| 12557 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12558 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12559 | if (intel_crtc->atomic.wait_for_flips) |
| 12560 | intel_crtc_wait_for_pending_flips(crtc); |
| 12561 | |
| 12562 | if (intel_crtc->atomic.disable_fbc) |
| 12563 | intel_fbc_disable(dev); |
| 12564 | |
| 12565 | if (intel_crtc->atomic.pre_disable_primary) |
| 12566 | intel_pre_disable_primary(crtc); |
| 12567 | |
| 12568 | if (intel_crtc->atomic.update_wm) |
| 12569 | intel_update_watermarks(crtc); |
| 12570 | |
| 12571 | intel_runtime_pm_get(dev_priv); |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 12572 | |
| 12573 | /* Perform vblank evasion around commit operation */ |
| 12574 | if (intel_crtc->active) |
| 12575 | intel_crtc->atomic.evade = |
| 12576 | intel_pipe_update_start(intel_crtc, |
| 12577 | &intel_crtc->atomic.start_vbl_count); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12578 | } |
| 12579 | |
| 12580 | static void intel_finish_crtc_commit(struct drm_crtc *crtc) |
| 12581 | { |
| 12582 | struct drm_device *dev = crtc->dev; |
| 12583 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12584 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12585 | struct drm_plane *p; |
| 12586 | |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 12587 | if (intel_crtc->atomic.evade) |
| 12588 | intel_pipe_update_end(intel_crtc, |
| 12589 | intel_crtc->atomic.start_vbl_count); |
| 12590 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12591 | intel_runtime_pm_put(dev_priv); |
| 12592 | |
| 12593 | if (intel_crtc->atomic.wait_vblank) |
| 12594 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 12595 | |
| 12596 | intel_frontbuffer_flip(dev, intel_crtc->atomic.fb_bits); |
| 12597 | |
| 12598 | if (intel_crtc->atomic.update_fbc) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12599 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 12600 | intel_fbc_update(dev); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12601 | mutex_unlock(&dev->struct_mutex); |
| 12602 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12603 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12604 | if (intel_crtc->atomic.post_enable_primary) |
| 12605 | intel_post_enable_primary(crtc); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12606 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12607 | drm_for_each_legacy_plane(p, &dev->mode_config.plane_list) |
| 12608 | if (intel_crtc->atomic.update_sprite_watermarks & drm_plane_index(p)) |
| 12609 | intel_update_sprite_watermarks(p, crtc, 0, 0, 0, |
| 12610 | false, false); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12611 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12612 | memset(&intel_crtc->atomic, 0, sizeof(intel_crtc->atomic)); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12613 | } |
| 12614 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12615 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 12616 | * intel_plane_destroy - destroy a plane |
| 12617 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12618 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 12619 | * Common destruction function for all types of planes (primary, cursor, |
| 12620 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12621 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 12622 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12623 | { |
| 12624 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 12625 | drm_plane_cleanup(plane); |
| 12626 | kfree(intel_plane); |
| 12627 | } |
| 12628 | |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 12629 | const struct drm_plane_funcs intel_plane_funcs = { |
Daniel Vetter | ff42e09 | 2015-03-02 16:35:20 +0100 | [diff] [blame] | 12630 | .update_plane = drm_plane_helper_update, |
| 12631 | .disable_plane = drm_plane_helper_disable, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12632 | .destroy = intel_plane_destroy, |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 12633 | .set_property = drm_atomic_helper_plane_set_property, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 12634 | .atomic_get_property = intel_plane_atomic_get_property, |
| 12635 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12636 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 12637 | .atomic_destroy_state = intel_plane_destroy_state, |
| 12638 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12639 | }; |
| 12640 | |
| 12641 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 12642 | int pipe) |
| 12643 | { |
| 12644 | struct intel_plane *primary; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12645 | struct intel_plane_state *state; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12646 | const uint32_t *intel_primary_formats; |
| 12647 | int num_formats; |
| 12648 | |
| 12649 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
| 12650 | if (primary == NULL) |
| 12651 | return NULL; |
| 12652 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12653 | state = intel_create_plane_state(&primary->base); |
| 12654 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12655 | kfree(primary); |
| 12656 | return NULL; |
| 12657 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12658 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12659 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12660 | primary->can_scale = false; |
| 12661 | primary->max_downscale = 1; |
| 12662 | primary->pipe = pipe; |
| 12663 | primary->plane = pipe; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12664 | primary->check_plane = intel_check_primary_plane; |
| 12665 | primary->commit_plane = intel_commit_primary_plane; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12666 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 12667 | primary->plane = !pipe; |
| 12668 | |
| 12669 | if (INTEL_INFO(dev)->gen <= 3) { |
| 12670 | intel_primary_formats = intel_primary_formats_gen2; |
| 12671 | num_formats = ARRAY_SIZE(intel_primary_formats_gen2); |
| 12672 | } else { |
| 12673 | intel_primary_formats = intel_primary_formats_gen4; |
| 12674 | num_formats = ARRAY_SIZE(intel_primary_formats_gen4); |
| 12675 | } |
| 12676 | |
| 12677 | drm_universal_plane_init(dev, &primary->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 12678 | &intel_plane_funcs, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12679 | intel_primary_formats, num_formats, |
| 12680 | DRM_PLANE_TYPE_PRIMARY); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12681 | |
| 12682 | if (INTEL_INFO(dev)->gen >= 4) { |
| 12683 | if (!dev->mode_config.rotation_property) |
| 12684 | dev->mode_config.rotation_property = |
| 12685 | drm_mode_create_rotation_property(dev, |
| 12686 | BIT(DRM_ROTATE_0) | |
| 12687 | BIT(DRM_ROTATE_180)); |
| 12688 | if (dev->mode_config.rotation_property) |
| 12689 | drm_object_attach_property(&primary->base.base, |
| 12690 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12691 | state->base.rotation); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12692 | } |
| 12693 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12694 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 12695 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12696 | return &primary->base; |
| 12697 | } |
| 12698 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12699 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12700 | intel_check_cursor_plane(struct drm_plane *plane, |
| 12701 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12702 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12703 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12704 | struct drm_device *dev = plane->dev; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12705 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12706 | struct drm_rect *dest = &state->dst; |
| 12707 | struct drm_rect *src = &state->src; |
| 12708 | const struct drm_rect *clip = &state->clip; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12709 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12710 | struct intel_crtc *intel_crtc; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12711 | unsigned stride; |
| 12712 | int ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12713 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12714 | crtc = crtc ? crtc : plane->crtc; |
| 12715 | intel_crtc = to_intel_crtc(crtc); |
| 12716 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12717 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12718 | src, dest, clip, |
| 12719 | DRM_PLANE_HELPER_NO_SCALING, |
| 12720 | DRM_PLANE_HELPER_NO_SCALING, |
| 12721 | true, true, &state->visible); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12722 | if (ret) |
| 12723 | return ret; |
| 12724 | |
| 12725 | |
| 12726 | /* if we want to turn off the cursor ignore width and height */ |
| 12727 | if (!obj) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12728 | goto finish; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12729 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12730 | /* Check for which cursor types we support */ |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12731 | if (!cursor_size_ok(dev, state->base.crtc_w, state->base.crtc_h)) { |
| 12732 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 12733 | state->base.crtc_w, state->base.crtc_h); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12734 | return -EINVAL; |
| 12735 | } |
| 12736 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12737 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
| 12738 | if (obj->base.size < stride * state->base.crtc_h) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12739 | DRM_DEBUG_KMS("buffer is too small\n"); |
| 12740 | return -ENOMEM; |
| 12741 | } |
| 12742 | |
Ville Syrjälä | 3a656b5 | 2015-03-09 21:08:37 +0200 | [diff] [blame] | 12743 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12744 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 12745 | ret = -EINVAL; |
| 12746 | } |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12747 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12748 | finish: |
| 12749 | if (intel_crtc->active) { |
Ville Syrjälä | 3749f46 | 2015-03-10 13:15:22 +0200 | [diff] [blame] | 12750 | if (plane->state->crtc_w != state->base.crtc_w) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12751 | intel_crtc->atomic.update_wm = true; |
| 12752 | |
| 12753 | intel_crtc->atomic.fb_bits |= |
| 12754 | INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe); |
| 12755 | } |
| 12756 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12757 | return ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12758 | } |
| 12759 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 12760 | static void |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12761 | intel_commit_cursor_plane(struct drm_plane *plane, |
| 12762 | struct intel_plane_state *state) |
| 12763 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12764 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12765 | struct drm_device *dev = plane->dev; |
| 12766 | struct intel_crtc *intel_crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12767 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12768 | uint32_t addr; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12769 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12770 | crtc = crtc ? crtc : plane->crtc; |
| 12771 | intel_crtc = to_intel_crtc(crtc); |
Sonika Jindal | a919db9 | 2014-10-23 07:41:33 -0700 | [diff] [blame] | 12772 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12773 | plane->fb = state->base.fb; |
| 12774 | crtc->cursor_x = state->base.crtc_x; |
| 12775 | crtc->cursor_y = state->base.crtc_y; |
| 12776 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12777 | if (intel_crtc->cursor_bo == obj) |
| 12778 | goto update; |
| 12779 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 12780 | if (!obj) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12781 | addr = 0; |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 12782 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12783 | addr = i915_gem_obj_ggtt_offset(obj); |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 12784 | else |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12785 | addr = obj->phys_handle->busaddr; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12786 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12787 | intel_crtc->cursor_addr = addr; |
| 12788 | intel_crtc->cursor_bo = obj; |
| 12789 | update: |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 12790 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12791 | if (intel_crtc->active) |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12792 | intel_crtc_update_cursor(crtc, state->visible); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12793 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12794 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12795 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 12796 | int pipe) |
| 12797 | { |
| 12798 | struct intel_plane *cursor; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12799 | struct intel_plane_state *state; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12800 | |
| 12801 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
| 12802 | if (cursor == NULL) |
| 12803 | return NULL; |
| 12804 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12805 | state = intel_create_plane_state(&cursor->base); |
| 12806 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12807 | kfree(cursor); |
| 12808 | return NULL; |
| 12809 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12810 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12811 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12812 | cursor->can_scale = false; |
| 12813 | cursor->max_downscale = 1; |
| 12814 | cursor->pipe = pipe; |
| 12815 | cursor->plane = pipe; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12816 | cursor->check_plane = intel_check_cursor_plane; |
| 12817 | cursor->commit_plane = intel_commit_cursor_plane; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12818 | |
| 12819 | drm_universal_plane_init(dev, &cursor->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 12820 | &intel_plane_funcs, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12821 | intel_cursor_formats, |
| 12822 | ARRAY_SIZE(intel_cursor_formats), |
| 12823 | DRM_PLANE_TYPE_CURSOR); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 12824 | |
| 12825 | if (INTEL_INFO(dev)->gen >= 4) { |
| 12826 | if (!dev->mode_config.rotation_property) |
| 12827 | dev->mode_config.rotation_property = |
| 12828 | drm_mode_create_rotation_property(dev, |
| 12829 | BIT(DRM_ROTATE_0) | |
| 12830 | BIT(DRM_ROTATE_180)); |
| 12831 | if (dev->mode_config.rotation_property) |
| 12832 | drm_object_attach_property(&cursor->base.base, |
| 12833 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12834 | state->base.rotation); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 12835 | } |
| 12836 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12837 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 12838 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12839 | return &cursor->base; |
| 12840 | } |
| 12841 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 12842 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12843 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 12844 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12845 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 12846 | struct intel_crtc_state *crtc_state = NULL; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12847 | struct drm_plane *primary = NULL; |
| 12848 | struct drm_plane *cursor = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12849 | int i, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12850 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 12851 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12852 | if (intel_crtc == NULL) |
| 12853 | return; |
| 12854 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 12855 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 12856 | if (!crtc_state) |
| 12857 | goto fail; |
| 12858 | intel_crtc_set_state(intel_crtc, crtc_state); |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 12859 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 12860 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12861 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12862 | if (!primary) |
| 12863 | goto fail; |
| 12864 | |
| 12865 | cursor = intel_cursor_plane_create(dev, pipe); |
| 12866 | if (!cursor) |
| 12867 | goto fail; |
| 12868 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12869 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12870 | cursor, &intel_crtc_funcs); |
| 12871 | if (ret) |
| 12872 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12873 | |
| 12874 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12875 | for (i = 0; i < 256; i++) { |
| 12876 | intel_crtc->lut_r[i] = i; |
| 12877 | intel_crtc->lut_g[i] = i; |
| 12878 | intel_crtc->lut_b[i] = i; |
| 12879 | } |
| 12880 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 12881 | /* |
| 12882 | * 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] | 12883 | * 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] | 12884 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 12885 | intel_crtc->pipe = pipe; |
| 12886 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 12887 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 12888 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 12889 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 12890 | } |
| 12891 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 12892 | intel_crtc->cursor_base = ~0; |
| 12893 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 12894 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 12895 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 12896 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 12897 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 12898 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 12899 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 12900 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 12901 | INIT_WORK(&intel_crtc->mmio_flip.work, intel_mmio_flip_work_func); |
| 12902 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12903 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 12904 | |
| 12905 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12906 | return; |
| 12907 | |
| 12908 | fail: |
| 12909 | if (primary) |
| 12910 | drm_plane_cleanup(primary); |
| 12911 | if (cursor) |
| 12912 | drm_plane_cleanup(cursor); |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 12913 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12914 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12915 | } |
| 12916 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12917 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 12918 | { |
| 12919 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 12920 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12921 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 12922 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12923 | |
Ville Syrjälä | d3babd3 | 2014-11-07 11:16:01 +0200 | [diff] [blame] | 12924 | if (!encoder || WARN_ON(!encoder->crtc)) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 12925 | return INVALID_PIPE; |
| 12926 | |
| 12927 | return to_intel_crtc(encoder->crtc)->pipe; |
| 12928 | } |
| 12929 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12930 | 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] | 12931 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12932 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12933 | 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] | 12934 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12935 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12936 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12937 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12938 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12939 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12940 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 12941 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12942 | } |
| 12943 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 12944 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12945 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12946 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 12947 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 12948 | } |
| 12949 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12950 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12951 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12952 | struct drm_device *dev = encoder->base.dev; |
| 12953 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12954 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12955 | int entry = 0; |
| 12956 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12957 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 12958 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 12959 | index_mask |= (1 << entry); |
| 12960 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12961 | entry++; |
| 12962 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 12963 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 12964 | return index_mask; |
| 12965 | } |
| 12966 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 12967 | static bool has_edp_a(struct drm_device *dev) |
| 12968 | { |
| 12969 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12970 | |
| 12971 | if (!IS_MOBILE(dev)) |
| 12972 | return false; |
| 12973 | |
| 12974 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 12975 | return false; |
| 12976 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 12977 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 12978 | return false; |
| 12979 | |
| 12980 | return true; |
| 12981 | } |
| 12982 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 12983 | static bool intel_crt_present(struct drm_device *dev) |
| 12984 | { |
| 12985 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12986 | |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 12987 | if (INTEL_INFO(dev)->gen >= 9) |
| 12988 | return false; |
| 12989 | |
Damien Lespiau | cf404ce | 2014-10-01 20:04:15 +0100 | [diff] [blame] | 12990 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 12991 | return false; |
| 12992 | |
| 12993 | if (IS_CHERRYVIEW(dev)) |
| 12994 | return false; |
| 12995 | |
| 12996 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) |
| 12997 | return false; |
| 12998 | |
| 12999 | return true; |
| 13000 | } |
| 13001 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13002 | static void intel_setup_outputs(struct drm_device *dev) |
| 13003 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13004 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13005 | struct intel_encoder *encoder; |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 13006 | struct drm_connector *connector; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13007 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13008 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 13009 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13010 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13011 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 13012 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13013 | |
Vandana Kannan | c776eb2 | 2014-08-19 12:05:01 +0530 | [diff] [blame^] | 13014 | if (IS_BROXTON(dev)) { |
| 13015 | /* |
| 13016 | * FIXME: Broxton doesn't support port detection via the |
| 13017 | * DDI_BUF_CTL_A or SFUSE_STRAP registers, find another way to |
| 13018 | * detect the ports. |
| 13019 | */ |
| 13020 | intel_ddi_init(dev, PORT_A); |
| 13021 | intel_ddi_init(dev, PORT_B); |
| 13022 | intel_ddi_init(dev, PORT_C); |
| 13023 | } else if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13024 | int found; |
| 13025 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13026 | /* |
| 13027 | * Haswell uses DDI functions to detect digital outputs. |
| 13028 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 13029 | * it's there. |
| 13030 | */ |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13031 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13032 | /* WaIgnoreDDIAStrap: skl */ |
| 13033 | if (found || |
| 13034 | (IS_SKYLAKE(dev) && INTEL_REVID(dev) < SKL_REVID_D0)) |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13035 | intel_ddi_init(dev, PORT_A); |
| 13036 | |
| 13037 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 13038 | * register */ |
| 13039 | found = I915_READ(SFUSE_STRAP); |
| 13040 | |
| 13041 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 13042 | intel_ddi_init(dev, PORT_B); |
| 13043 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 13044 | intel_ddi_init(dev, PORT_C); |
| 13045 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 13046 | intel_ddi_init(dev, PORT_D); |
| 13047 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13048 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 13049 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13050 | |
| 13051 | if (has_edp_a(dev)) |
| 13052 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13053 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13054 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 13055 | /* PCH SDVOB multiplex with HDMIB */ |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 13056 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13057 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13058 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13059 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13060 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13061 | } |
| 13062 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13063 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13064 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13065 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13066 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13067 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13068 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13069 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13070 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13071 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13072 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13073 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 13074 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13075 | /* |
| 13076 | * The DP_DETECTED bit is the latched state of the DDC |
| 13077 | * SDA pin at boot. However since eDP doesn't require DDC |
| 13078 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 13079 | * eDP ports may have been muxed to an alternate function. |
| 13080 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 13081 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 13082 | * detect eDP ports. |
| 13083 | */ |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 13084 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED && |
| 13085 | !intel_dp_is_edp(dev, PORT_B)) |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 13086 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
| 13087 | PORT_B); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13088 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || |
| 13089 | intel_dp_is_edp(dev, PORT_B)) |
| 13090 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 13091 | |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 13092 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED && |
| 13093 | !intel_dp_is_edp(dev, PORT_C)) |
Jesse Barnes | 6f6005a | 2013-08-09 09:34:35 -0700 | [diff] [blame] | 13094 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
| 13095 | PORT_C); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13096 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || |
| 13097 | intel_dp_is_edp(dev, PORT_C)) |
| 13098 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 13099 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13100 | if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13101 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13102 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
| 13103 | PORT_D); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13104 | /* eDP not supported on port D, so don't check VBT */ |
| 13105 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) |
| 13106 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13107 | } |
| 13108 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 13109 | intel_dsi_init(dev); |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 13110 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13111 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 13112 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13113 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13114 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13115 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13116 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 13117 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13118 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13119 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13120 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 13121 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13122 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13123 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 13124 | |
| 13125 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 13126 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13127 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13128 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13129 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13130 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13131 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13132 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13133 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13134 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 13135 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13136 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13137 | } |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 13138 | if (SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13139 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13140 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13141 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13142 | if (SUPPORTS_INTEGRATED_DP(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 13143 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13144 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 13145 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13146 | intel_dvo_init(dev); |
| 13147 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 13148 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13149 | intel_tv_init(dev); |
| 13150 | |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 13151 | /* |
| 13152 | * FIXME: We don't have full atomic support yet, but we want to be |
| 13153 | * able to enable/test plane updates via the atomic interface in the |
| 13154 | * meantime. However as soon as we flip DRIVER_ATOMIC on, the DRM core |
| 13155 | * will take some atomic codepaths to lookup properties during |
| 13156 | * drmModeGetConnector() that unconditionally dereference |
| 13157 | * connector->state. |
| 13158 | * |
| 13159 | * We create a dummy connector state here for each connector to ensure |
| 13160 | * the DRM core doesn't try to dereference a NULL connector->state. |
| 13161 | * The actual connector properties will never be updated or contain |
| 13162 | * useful information, but since we're doing this specifically for |
| 13163 | * testing/debug of the plane operations (and only when a specific |
| 13164 | * kernel module option is given), that shouldn't really matter. |
| 13165 | * |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 13166 | * We are also relying on these states to convert the legacy mode set |
| 13167 | * to use a drm_atomic_state struct. The states are kept consistent |
| 13168 | * with actual state, so that it is safe to rely on that instead of |
| 13169 | * the staged config. |
| 13170 | * |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 13171 | * Once atomic support for crtc's + connectors lands, this loop should |
| 13172 | * be removed since we'll be setting up real connector state, which |
| 13173 | * will contain Intel-specific properties. |
| 13174 | */ |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 13175 | list_for_each_entry(connector, |
| 13176 | &dev->mode_config.connector_list, |
| 13177 | head) { |
| 13178 | if (!WARN_ON(connector->state)) { |
| 13179 | connector->state = kzalloc(sizeof(*connector->state), |
| 13180 | GFP_KERNEL); |
Matt Roper | c6f95f2 | 2015-01-22 16:50:32 -0800 | [diff] [blame] | 13181 | } |
| 13182 | } |
| 13183 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 13184 | intel_psr_init(dev); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 13185 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13186 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13187 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 13188 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13189 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13190 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 13191 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 13192 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13193 | |
| 13194 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13195 | } |
| 13196 | |
| 13197 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 13198 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 13199 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13200 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13201 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 13202 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 13203 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 13204 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 13205 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 13206 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13207 | kfree(intel_fb); |
| 13208 | } |
| 13209 | |
| 13210 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13211 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13212 | unsigned int *handle) |
| 13213 | { |
| 13214 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13215 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13216 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13217 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13218 | } |
| 13219 | |
| 13220 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 13221 | .destroy = intel_user_framebuffer_destroy, |
| 13222 | .create_handle = intel_user_framebuffer_create_handle, |
| 13223 | }; |
| 13224 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13225 | static |
| 13226 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, |
| 13227 | uint32_t pixel_format) |
| 13228 | { |
| 13229 | u32 gen = INTEL_INFO(dev)->gen; |
| 13230 | |
| 13231 | if (gen >= 9) { |
| 13232 | /* "The stride in bytes must not exceed the of the size of 8K |
| 13233 | * pixels and 32K bytes." |
| 13234 | */ |
| 13235 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); |
| 13236 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { |
| 13237 | return 32*1024; |
| 13238 | } else if (gen >= 4) { |
| 13239 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 13240 | return 16*1024; |
| 13241 | else |
| 13242 | return 32*1024; |
| 13243 | } else if (gen >= 3) { |
| 13244 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 13245 | return 8*1024; |
| 13246 | else |
| 13247 | return 16*1024; |
| 13248 | } else { |
| 13249 | /* XXX DSPC is limited to 4k tiled */ |
| 13250 | return 8*1024; |
| 13251 | } |
| 13252 | } |
| 13253 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 13254 | static int intel_framebuffer_init(struct drm_device *dev, |
| 13255 | struct intel_framebuffer *intel_fb, |
| 13256 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 13257 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13258 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 13259 | unsigned int aligned_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13260 | int ret; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13261 | u32 pitch_limit, stride_alignment; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13262 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 13263 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 13264 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 13265 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
| 13266 | /* Enforce that fb modifier and tiling mode match, but only for |
| 13267 | * X-tiled. This is needed for FBC. */ |
| 13268 | if (!!(obj->tiling_mode == I915_TILING_X) != |
| 13269 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { |
| 13270 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); |
| 13271 | return -EINVAL; |
| 13272 | } |
| 13273 | } else { |
| 13274 | if (obj->tiling_mode == I915_TILING_X) |
| 13275 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 13276 | else if (obj->tiling_mode == I915_TILING_Y) { |
| 13277 | DRM_DEBUG("No Y tiling for legacy addfb\n"); |
| 13278 | return -EINVAL; |
| 13279 | } |
| 13280 | } |
| 13281 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 13282 | /* Passed in modifier sanity checking. */ |
| 13283 | switch (mode_cmd->modifier[0]) { |
| 13284 | case I915_FORMAT_MOD_Y_TILED: |
| 13285 | case I915_FORMAT_MOD_Yf_TILED: |
| 13286 | if (INTEL_INFO(dev)->gen < 9) { |
| 13287 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", |
| 13288 | mode_cmd->modifier[0]); |
| 13289 | return -EINVAL; |
| 13290 | } |
| 13291 | case DRM_FORMAT_MOD_NONE: |
| 13292 | case I915_FORMAT_MOD_X_TILED: |
| 13293 | break; |
| 13294 | default: |
Jesse Barnes | c0f4042 | 2015-03-23 12:43:50 -0700 | [diff] [blame] | 13295 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
| 13296 | mode_cmd->modifier[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13297 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13298 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13299 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13300 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
| 13301 | mode_cmd->pixel_format); |
| 13302 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { |
| 13303 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", |
| 13304 | mode_cmd->pitches[0], stride_alignment); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13305 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13306 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13307 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13308 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
| 13309 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 13310 | if (mode_cmd->pitches[0] > pitch_limit) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13311 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
| 13312 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 13313 | "tiled" : "linear", |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 13314 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13315 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13316 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13317 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 13318 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13319 | mode_cmd->pitches[0] != obj->stride) { |
| 13320 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 13321 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13322 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13323 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13324 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13325 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 13326 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13327 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 13328 | case DRM_FORMAT_RGB565: |
| 13329 | case DRM_FORMAT_XRGB8888: |
| 13330 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13331 | break; |
| 13332 | case DRM_FORMAT_XRGB1555: |
| 13333 | case DRM_FORMAT_ARGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13334 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13335 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13336 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13337 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13338 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13339 | break; |
| 13340 | case DRM_FORMAT_XBGR8888: |
| 13341 | case DRM_FORMAT_ABGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 13342 | case DRM_FORMAT_XRGB2101010: |
| 13343 | case DRM_FORMAT_ARGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13344 | case DRM_FORMAT_XBGR2101010: |
| 13345 | case DRM_FORMAT_ABGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13346 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13347 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13348 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13349 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13350 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 13351 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 13352 | case DRM_FORMAT_YUYV: |
| 13353 | case DRM_FORMAT_UYVY: |
| 13354 | case DRM_FORMAT_YVYU: |
| 13355 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13356 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13357 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13358 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13359 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13360 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13361 | break; |
| 13362 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13363 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13364 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13365 | return -EINVAL; |
| 13366 | } |
| 13367 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 13368 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 13369 | if (mode_cmd->offsets[0] != 0) |
| 13370 | return -EINVAL; |
| 13371 | |
Damien Lespiau | ec2c981 | 2015-01-20 12:51:45 +0000 | [diff] [blame] | 13372 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 13373 | mode_cmd->pixel_format, |
| 13374 | mode_cmd->modifier[0]); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 13375 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 13376 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 13377 | return -EINVAL; |
| 13378 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 13379 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 13380 | intel_fb->obj = obj; |
Daniel Vetter | 80075d4 | 2013-10-09 21:23:52 +0200 | [diff] [blame] | 13381 | intel_fb->obj->framebuffer_references++; |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 13382 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13383 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 13384 | if (ret) { |
| 13385 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 13386 | return ret; |
| 13387 | } |
| 13388 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13389 | return 0; |
| 13390 | } |
| 13391 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13392 | static struct drm_framebuffer * |
| 13393 | intel_user_framebuffer_create(struct drm_device *dev, |
| 13394 | struct drm_file *filp, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 13395 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13396 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13397 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13398 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 13399 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
| 13400 | mode_cmd->handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 13401 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 13402 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13403 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 13404 | return intel_framebuffer_create(dev, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13405 | } |
| 13406 | |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 13407 | #ifndef CONFIG_DRM_I915_FBDEV |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 13408 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 13409 | { |
| 13410 | } |
| 13411 | #endif |
| 13412 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13413 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13414 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 13415 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 13416 | .atomic_check = intel_atomic_check, |
| 13417 | .atomic_commit = intel_atomic_commit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13418 | }; |
| 13419 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13420 | /* Set up chip specific display functions */ |
| 13421 | static void intel_init_display(struct drm_device *dev) |
| 13422 | { |
| 13423 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13424 | |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 13425 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
| 13426 | dev_priv->display.find_dpll = g4x_find_best_dpll; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 13427 | else if (IS_CHERRYVIEW(dev)) |
| 13428 | dev_priv->display.find_dpll = chv_find_best_dpll; |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 13429 | else if (IS_VALLEYVIEW(dev)) |
| 13430 | dev_priv->display.find_dpll = vlv_find_best_dpll; |
| 13431 | else if (IS_PINEVIEW(dev)) |
| 13432 | dev_priv->display.find_dpll = pnv_find_best_dpll; |
| 13433 | else |
| 13434 | dev_priv->display.find_dpll = i9xx_find_best_dpll; |
| 13435 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 13436 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13437 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13438 | dev_priv->display.get_initial_plane_config = |
| 13439 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 13440 | dev_priv->display.crtc_compute_clock = |
| 13441 | haswell_crtc_compute_clock; |
| 13442 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 13443 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
| 13444 | dev_priv->display.off = ironlake_crtc_off; |
| 13445 | dev_priv->display.update_primary_plane = |
| 13446 | skylake_update_primary_plane; |
| 13447 | } else if (HAS_DDI(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13448 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13449 | dev_priv->display.get_initial_plane_config = |
| 13450 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 13451 | dev_priv->display.crtc_compute_clock = |
| 13452 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 13453 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 13454 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 13455 | dev_priv->display.off = ironlake_crtc_off; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 13456 | dev_priv->display.update_primary_plane = |
| 13457 | ironlake_update_primary_plane; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 13458 | } else if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13459 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13460 | dev_priv->display.get_initial_plane_config = |
| 13461 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 13462 | dev_priv->display.crtc_compute_clock = |
| 13463 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 13464 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 13465 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13466 | dev_priv->display.off = ironlake_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 13467 | dev_priv->display.update_primary_plane = |
| 13468 | ironlake_update_primary_plane; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 13469 | } else if (IS_VALLEYVIEW(dev)) { |
| 13470 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13471 | dev_priv->display.get_initial_plane_config = |
| 13472 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 13473 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 13474 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 13475 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 13476 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 13477 | dev_priv->display.update_primary_plane = |
| 13478 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 13479 | } else { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13480 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13481 | dev_priv->display.get_initial_plane_config = |
| 13482 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 13483 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 13484 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 13485 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13486 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 13487 | dev_priv->display.update_primary_plane = |
| 13488 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 13489 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13490 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13491 | /* Returns the core display clock speed */ |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 13492 | if (IS_VALLEYVIEW(dev)) |
| 13493 | dev_priv->display.get_display_clock_speed = |
| 13494 | valleyview_get_display_clock_speed; |
| 13495 | else if (IS_I945G(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev))) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13496 | dev_priv->display.get_display_clock_speed = |
| 13497 | i945_get_display_clock_speed; |
| 13498 | else if (IS_I915G(dev)) |
| 13499 | dev_priv->display.get_display_clock_speed = |
| 13500 | i915_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 13501 | else if (IS_I945GM(dev) || IS_845G(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13502 | dev_priv->display.get_display_clock_speed = |
| 13503 | i9xx_misc_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 13504 | else if (IS_PINEVIEW(dev)) |
| 13505 | dev_priv->display.get_display_clock_speed = |
| 13506 | pnv_get_display_clock_speed; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13507 | else if (IS_I915GM(dev)) |
| 13508 | dev_priv->display.get_display_clock_speed = |
| 13509 | i915gm_get_display_clock_speed; |
| 13510 | else if (IS_I865G(dev)) |
| 13511 | dev_priv->display.get_display_clock_speed = |
| 13512 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 13513 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13514 | dev_priv->display.get_display_clock_speed = |
| 13515 | i855_get_display_clock_speed; |
| 13516 | else /* 852, 830 */ |
| 13517 | dev_priv->display.get_display_clock_speed = |
| 13518 | i830_get_display_clock_speed; |
| 13519 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 13520 | if (IS_GEN5(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13521 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13522 | } else if (IS_GEN6(dev)) { |
| 13523 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13524 | } else if (IS_IVYBRIDGE(dev)) { |
| 13525 | /* FIXME: detect B0+ stepping and use auto training */ |
| 13526 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Paulo Zanoni | 059b2fe | 2014-09-02 16:53:57 -0300 | [diff] [blame] | 13527 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13528 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 13529 | } else if (IS_VALLEYVIEW(dev)) { |
| 13530 | dev_priv->display.modeset_global_resources = |
| 13531 | valleyview_modeset_global_resources; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13532 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 13533 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 13534 | switch (INTEL_INFO(dev)->gen) { |
| 13535 | case 2: |
| 13536 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 13537 | break; |
| 13538 | |
| 13539 | case 3: |
| 13540 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 13541 | break; |
| 13542 | |
| 13543 | case 4: |
| 13544 | case 5: |
| 13545 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 13546 | break; |
| 13547 | |
| 13548 | case 6: |
| 13549 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 13550 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 13551 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 13552 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 13553 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 13554 | break; |
Damien Lespiau | 830c81d | 2014-11-13 17:51:46 +0000 | [diff] [blame] | 13555 | case 9: |
Tvrtko Ursulin | ba343e0 | 2015-02-10 17:16:12 +0000 | [diff] [blame] | 13556 | /* Drop through - unsupported since execlist only. */ |
| 13557 | default: |
| 13558 | /* Default just returns -ENODEV to indicate unsupported */ |
| 13559 | dev_priv->display.queue_flip = intel_default_queue_flip; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 13560 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 13561 | |
| 13562 | intel_panel_init_backlight_funcs(dev); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 13563 | |
| 13564 | mutex_init(&dev_priv->pps_mutex); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13565 | } |
| 13566 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13567 | /* |
| 13568 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 13569 | * resume, or other times. This quirk makes sure that's the case for |
| 13570 | * affected systems. |
| 13571 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 13572 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13573 | { |
| 13574 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13575 | |
| 13576 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 13577 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13578 | } |
| 13579 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 13580 | static void quirk_pipeb_force(struct drm_device *dev) |
| 13581 | { |
| 13582 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13583 | |
| 13584 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 13585 | DRM_INFO("applying pipe b force quirk\n"); |
| 13586 | } |
| 13587 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 13588 | /* |
| 13589 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 13590 | */ |
| 13591 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 13592 | { |
| 13593 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13594 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 13595 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 13596 | } |
| 13597 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 13598 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 13599 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 13600 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 13601 | */ |
| 13602 | static void quirk_invert_brightness(struct drm_device *dev) |
| 13603 | { |
| 13604 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13605 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 13606 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13607 | } |
| 13608 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 13609 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 13610 | static void quirk_backlight_present(struct drm_device *dev) |
| 13611 | { |
| 13612 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13613 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 13614 | DRM_INFO("applying backlight present quirk\n"); |
| 13615 | } |
| 13616 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13617 | struct intel_quirk { |
| 13618 | int device; |
| 13619 | int subsystem_vendor; |
| 13620 | int subsystem_device; |
| 13621 | void (*hook)(struct drm_device *dev); |
| 13622 | }; |
| 13623 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 13624 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 13625 | struct intel_dmi_quirk { |
| 13626 | void (*hook)(struct drm_device *dev); |
| 13627 | const struct dmi_system_id (*dmi_id_list)[]; |
| 13628 | }; |
| 13629 | |
| 13630 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 13631 | { |
| 13632 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 13633 | return 1; |
| 13634 | } |
| 13635 | |
| 13636 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 13637 | { |
| 13638 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 13639 | { |
| 13640 | .callback = intel_dmi_reverse_brightness, |
| 13641 | .ident = "NCR Corporation", |
| 13642 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 13643 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 13644 | }, |
| 13645 | }, |
| 13646 | { } /* terminating entry */ |
| 13647 | }, |
| 13648 | .hook = quirk_invert_brightness, |
| 13649 | }, |
| 13650 | }; |
| 13651 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 13652 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13653 | /* HP Mini needs pipe A force quirk (LP: #322104) */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 13654 | { 0x27ae, 0x103c, 0x361a, quirk_pipea_force }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13655 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13656 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 13657 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 13658 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13659 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 13660 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 13661 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 13662 | /* 830 needs to leave pipe A & dpll A up */ |
| 13663 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 13664 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 13665 | /* 830 needs to leave pipe B & dpll B up */ |
| 13666 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 13667 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 13668 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 13669 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 13670 | |
| 13671 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 13672 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 13673 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 13674 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 13675 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 13676 | |
| 13677 | /* Acer/eMachines G725 */ |
| 13678 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 13679 | |
| 13680 | /* Acer/eMachines e725 */ |
| 13681 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 13682 | |
| 13683 | /* Acer/Packard Bell NCL20 */ |
| 13684 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 13685 | |
| 13686 | /* Acer Aspire 4736Z */ |
| 13687 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 13688 | |
| 13689 | /* Acer Aspire 5336 */ |
| 13690 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 13691 | |
| 13692 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 13693 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 13694 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 13695 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 13696 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 13697 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 13698 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 13699 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 13700 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 13701 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 13702 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 13703 | |
| 13704 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 13705 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 13706 | |
| 13707 | /* Dell Chromebook 11 */ |
| 13708 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13709 | }; |
| 13710 | |
| 13711 | static void intel_init_quirks(struct drm_device *dev) |
| 13712 | { |
| 13713 | struct pci_dev *d = dev->pdev; |
| 13714 | int i; |
| 13715 | |
| 13716 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 13717 | struct intel_quirk *q = &intel_quirks[i]; |
| 13718 | |
| 13719 | if (d->device == q->device && |
| 13720 | (d->subsystem_vendor == q->subsystem_vendor || |
| 13721 | q->subsystem_vendor == PCI_ANY_ID) && |
| 13722 | (d->subsystem_device == q->subsystem_device || |
| 13723 | q->subsystem_device == PCI_ANY_ID)) |
| 13724 | q->hook(dev); |
| 13725 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 13726 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 13727 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 13728 | intel_dmi_quirks[i].hook(dev); |
| 13729 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13730 | } |
| 13731 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13732 | /* Disable the VGA plane that we never use */ |
| 13733 | static void i915_disable_vga(struct drm_device *dev) |
| 13734 | { |
| 13735 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13736 | u8 sr1; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 13737 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13738 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 13739 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13740 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 13741 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13742 | sr1 = inb(VGA_SR_DATA); |
| 13743 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 13744 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 13745 | udelay(300); |
| 13746 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 13747 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13748 | POSTING_READ(vga_reg); |
| 13749 | } |
| 13750 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 13751 | void intel_modeset_init_hw(struct drm_device *dev) |
| 13752 | { |
Eugeni Dodonov | a8f78b5 | 2012-06-28 15:55:35 -0300 | [diff] [blame] | 13753 | intel_prepare_ddi(dev); |
| 13754 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 13755 | if (IS_VALLEYVIEW(dev)) |
| 13756 | vlv_update_cdclk(dev); |
| 13757 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 13758 | intel_init_clock_gating(dev); |
| 13759 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 13760 | intel_enable_gt_powersave(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 13761 | } |
| 13762 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13763 | void intel_modeset_init(struct drm_device *dev) |
| 13764 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 13765 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 13766 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 13767 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13768 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13769 | |
| 13770 | drm_mode_config_init(dev); |
| 13771 | |
| 13772 | dev->mode_config.min_width = 0; |
| 13773 | dev->mode_config.min_height = 0; |
| 13774 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 13775 | dev->mode_config.preferred_depth = 24; |
| 13776 | dev->mode_config.prefer_shadow = 1; |
| 13777 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 13778 | dev->mode_config.allow_fb_modifiers = true; |
| 13779 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 13780 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13781 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13782 | intel_init_quirks(dev); |
| 13783 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 13784 | intel_init_pm(dev); |
| 13785 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 13786 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 13787 | return; |
| 13788 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13789 | intel_init_display(dev); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 13790 | intel_init_audio(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13791 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 13792 | if (IS_GEN2(dev)) { |
| 13793 | dev->mode_config.max_width = 2048; |
| 13794 | dev->mode_config.max_height = 2048; |
| 13795 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 13796 | dev->mode_config.max_width = 4096; |
| 13797 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13798 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 13799 | dev->mode_config.max_width = 8192; |
| 13800 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13801 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 13802 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 13803 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 13804 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 13805 | dev->mode_config.cursor_height = 1023; |
| 13806 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 13807 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 13808 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 13809 | } else { |
| 13810 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 13811 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 13812 | } |
| 13813 | |
Ben Widawsky | 5d4545a | 2013-01-17 12:45:15 -0800 | [diff] [blame] | 13814 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13815 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 13816 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 13817 | INTEL_INFO(dev)->num_pipes, |
| 13818 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13819 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 13820 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 13821 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 13822 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 13823 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 13824 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 13825 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 13826 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 13827 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13828 | } |
| 13829 | |
Jesse Barnes | f42bb70 | 2013-12-16 16:34:23 -0800 | [diff] [blame] | 13830 | intel_init_dpio(dev); |
| 13831 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 13832 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13833 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13834 | /* Just disable it once at startup */ |
| 13835 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13836 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 13837 | |
| 13838 | /* Just in case the BIOS is doing something questionable. */ |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 13839 | intel_fbc_disable(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 13840 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13841 | drm_modeset_lock_all(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 13842 | intel_modeset_setup_hw_state(dev, false); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13843 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13844 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 13845 | for_each_intel_crtc(dev, crtc) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13846 | if (!crtc->active) |
| 13847 | continue; |
| 13848 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13849 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13850 | * Note that reserving the BIOS fb up front prevents us |
| 13851 | * from stuffing other stolen allocations like the ring |
| 13852 | * on top. This prevents some ugliness at boot time, and |
| 13853 | * can even allow for smooth boot transitions if the BIOS |
| 13854 | * fb is large enough for the active pipe configuration. |
| 13855 | */ |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13856 | if (dev_priv->display.get_initial_plane_config) { |
| 13857 | dev_priv->display.get_initial_plane_config(crtc, |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13858 | &crtc->plane_config); |
| 13859 | /* |
| 13860 | * If the fb is shared between multiple heads, we'll |
| 13861 | * just get the first one. |
| 13862 | */ |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 13863 | intel_find_initial_plane_obj(crtc, &crtc->plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13864 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 13865 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 13866 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 13867 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13868 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 13869 | { |
| 13870 | struct intel_connector *connector; |
| 13871 | struct drm_connector *crt = NULL; |
| 13872 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 13873 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13874 | |
| 13875 | /* We can't just switch on the pipe A, we need to set things up with a |
| 13876 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 13877 | * by enabling the load detect pipe once. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13878 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13879 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 13880 | crt = &connector->base; |
| 13881 | break; |
| 13882 | } |
| 13883 | } |
| 13884 | |
| 13885 | if (!crt) |
| 13886 | return; |
| 13887 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 13888 | if (intel_get_load_detect_pipe(crt, NULL, &load_detect_temp, ctx)) |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 13889 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13890 | } |
| 13891 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13892 | static bool |
| 13893 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 13894 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 13895 | struct drm_device *dev = crtc->base.dev; |
| 13896 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13897 | u32 reg, val; |
| 13898 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 13899 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13900 | return true; |
| 13901 | |
| 13902 | reg = DSPCNTR(!crtc->plane); |
| 13903 | val = I915_READ(reg); |
| 13904 | |
| 13905 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 13906 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 13907 | return false; |
| 13908 | |
| 13909 | return true; |
| 13910 | } |
| 13911 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13912 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 13913 | { |
| 13914 | struct drm_device *dev = crtc->base.dev; |
| 13915 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13916 | u32 reg; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13917 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13918 | /* 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] | 13919 | reg = PIPECONF(crtc->config->cpu_transcoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13920 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 13921 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 13922 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 13923 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 13924 | if (crtc->active) { |
| 13925 | update_scanline_offset(crtc); |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 13926 | drm_crtc_vblank_on(&crtc->base); |
| 13927 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 13928 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13929 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 13930 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 13931 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 13932 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13933 | struct intel_connector *connector; |
| 13934 | bool plane; |
| 13935 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13936 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 13937 | crtc->base.base.id); |
| 13938 | |
| 13939 | /* Pipe has the wrong plane attached and the plane is active. |
| 13940 | * Temporarily change the plane mapping and disable everything |
| 13941 | * ... */ |
| 13942 | plane = crtc->plane; |
| 13943 | crtc->plane = !plane; |
Daniel Vetter | 9c8958b | 2014-07-14 19:35:31 +0200 | [diff] [blame] | 13944 | crtc->primary_enabled = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13945 | dev_priv->display.crtc_disable(&crtc->base); |
| 13946 | crtc->plane = plane; |
| 13947 | |
| 13948 | /* ... and break all links. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13949 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13950 | if (connector->encoder->base.crtc != &crtc->base) |
| 13951 | continue; |
| 13952 | |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13953 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 13954 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13955 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13956 | /* multiple connectors may have the same encoder: |
| 13957 | * handle them and break crtc link separately */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 13958 | for_each_intel_connector(dev, connector) |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 13959 | if (connector->encoder->base.crtc == &crtc->base) { |
| 13960 | connector->encoder->base.crtc = NULL; |
| 13961 | connector->encoder->connectors_active = false; |
| 13962 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13963 | |
| 13964 | WARN_ON(crtc->active); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 13965 | crtc->base.state->enable = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13966 | crtc->base.enabled = false; |
| 13967 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13968 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 13969 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 13970 | crtc->pipe == PIPE_A && !crtc->active) { |
| 13971 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 13972 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 13973 | * call below we restore the pipe to the right state, but leave |
| 13974 | * the required bits on. */ |
| 13975 | intel_enable_pipe_a(dev); |
| 13976 | } |
| 13977 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13978 | /* Adjust the state of the output pipe according to whether we |
| 13979 | * have active connectors/encoders. */ |
| 13980 | intel_crtc_update_dpms(&crtc->base); |
| 13981 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 13982 | if (crtc->active != crtc->base.state->enable) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13983 | struct intel_encoder *encoder; |
| 13984 | |
| 13985 | /* This can happen either due to bugs in the get_hw_state |
| 13986 | * functions or because the pipe is force-enabled due to the |
| 13987 | * pipe A quirk. */ |
| 13988 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", |
| 13989 | crtc->base.base.id, |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 13990 | crtc->base.state->enable ? "enabled" : "disabled", |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13991 | crtc->active ? "enabled" : "disabled"); |
| 13992 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 13993 | crtc->base.state->enable = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 13994 | crtc->base.enabled = crtc->active; |
| 13995 | |
| 13996 | /* Because we only establish the connector -> encoder -> |
| 13997 | * crtc links if something is active, this means the |
| 13998 | * crtc is now deactivated. Break the links. connector |
| 13999 | * -> encoder links are only establish when things are |
| 14000 | * actually up, hence no need to break them. */ |
| 14001 | WARN_ON(crtc->active); |
| 14002 | |
| 14003 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
| 14004 | WARN_ON(encoder->connectors_active); |
| 14005 | encoder->base.crtc = NULL; |
| 14006 | } |
| 14007 | } |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 14008 | |
Ville Syrjälä | a3ed6aa | 2014-09-03 14:09:52 +0300 | [diff] [blame] | 14009 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 14010 | /* |
| 14011 | * We start out with underrun reporting disabled to avoid races. |
| 14012 | * For correct bookkeeping mark this on active crtcs. |
| 14013 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 14014 | * Also on gmch platforms we dont have any hardware bits to |
| 14015 | * disable the underrun reporting. Which means we need to start |
| 14016 | * out with underrun reporting disabled also on inactive pipes, |
| 14017 | * since otherwise we'll complain about the garbage we read when |
| 14018 | * e.g. coming up after runtime pm. |
| 14019 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 14020 | * No protection against concurrent access is required - at |
| 14021 | * worst a fifo underrun happens which also sets this to false. |
| 14022 | */ |
| 14023 | crtc->cpu_fifo_underrun_disabled = true; |
| 14024 | crtc->pch_fifo_underrun_disabled = true; |
| 14025 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14026 | } |
| 14027 | |
| 14028 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 14029 | { |
| 14030 | struct intel_connector *connector; |
| 14031 | struct drm_device *dev = encoder->base.dev; |
| 14032 | |
| 14033 | /* We need to check both for a crtc link (meaning that the |
| 14034 | * encoder is active and trying to read from a pipe) and the |
| 14035 | * pipe itself being active. */ |
| 14036 | bool has_active_crtc = encoder->base.crtc && |
| 14037 | to_intel_crtc(encoder->base.crtc)->active; |
| 14038 | |
| 14039 | if (encoder->connectors_active && !has_active_crtc) { |
| 14040 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 14041 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14042 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14043 | |
| 14044 | /* Connector is active, but has no active pipe. This is |
| 14045 | * fallout from our resume register restoring. Disable |
| 14046 | * the encoder manually again. */ |
| 14047 | if (encoder->base.crtc) { |
| 14048 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 14049 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14050 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14051 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 14052 | if (encoder->post_disable) |
| 14053 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14054 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14055 | encoder->base.crtc = NULL; |
| 14056 | encoder->connectors_active = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14057 | |
| 14058 | /* Inconsistent output/port/pipe state happens presumably due to |
| 14059 | * a bug in one of the get_hw_state functions. Or someplace else |
| 14060 | * in our code, like the register restore mess on resume. Clamp |
| 14061 | * things to off as a safer default. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14062 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14063 | if (connector->encoder != encoder) |
| 14064 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14065 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 14066 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14067 | } |
| 14068 | } |
| 14069 | /* Enabled encoders without active connectors will be fixed in |
| 14070 | * the crtc fixup. */ |
| 14071 | } |
| 14072 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14073 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14074 | { |
| 14075 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 14076 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14077 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14078 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 14079 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 14080 | i915_disable_vga(dev); |
| 14081 | } |
| 14082 | } |
| 14083 | |
| 14084 | void i915_redisable_vga(struct drm_device *dev) |
| 14085 | { |
| 14086 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14087 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 14088 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 14089 | * at a very early point in our resume sequence, where the power well |
| 14090 | * structures are not yet restored. Since this function is at a very |
| 14091 | * paranoid "someone might have enabled VGA while we were not looking" |
| 14092 | * level, just check if the power well is enabled instead of trying to |
| 14093 | * follow the "don't touch the power well if we don't need it" policy |
| 14094 | * the rest of the driver uses. */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14095 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 14096 | return; |
| 14097 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14098 | i915_redisable_vga_power_on(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14099 | } |
| 14100 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 14101 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
| 14102 | { |
| 14103 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 14104 | |
| 14105 | if (!crtc->active) |
| 14106 | return false; |
| 14107 | |
| 14108 | return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE; |
| 14109 | } |
| 14110 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14111 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14112 | { |
| 14113 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14114 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14115 | struct intel_crtc *crtc; |
| 14116 | struct intel_encoder *encoder; |
| 14117 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14118 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14119 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14120 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14121 | memset(crtc->config, 0, sizeof(*crtc->config)); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 14122 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14123 | crtc->config->quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE; |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 14124 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14125 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14126 | crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14127 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14128 | crtc->base.state->enable = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14129 | crtc->base.enabled = crtc->active; |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 14130 | crtc->primary_enabled = primary_get_hw_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14131 | |
| 14132 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 14133 | crtc->base.base.id, |
| 14134 | crtc->active ? "enabled" : "disabled"); |
| 14135 | } |
| 14136 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14137 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 14138 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 14139 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14140 | pll->on = pll->get_hw_state(dev_priv, pll, |
| 14141 | &pll->config.hw_state); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14142 | pll->active = 0; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14143 | pll->config.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14144 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 14145 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14146 | pll->active++; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14147 | pll->config.crtc_mask |= 1 << crtc->pipe; |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 14148 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14149 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14150 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 14151 | 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] | 14152 | pll->name, pll->config.crtc_mask, pll->on); |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 14153 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14154 | if (pll->config.crtc_mask) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 14155 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14156 | } |
| 14157 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14158 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14159 | pipe = 0; |
| 14160 | |
| 14161 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 14162 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 14163 | encoder->base.crtc = &crtc->base; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14164 | encoder->get_config(encoder, crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14165 | } else { |
| 14166 | encoder->base.crtc = NULL; |
| 14167 | } |
| 14168 | |
| 14169 | encoder->connectors_active = false; |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 14170 | 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] | 14171 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14172 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14173 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 14174 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14175 | } |
| 14176 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14177 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14178 | if (connector->get_hw_state(connector)) { |
| 14179 | connector->base.dpms = DRM_MODE_DPMS_ON; |
| 14180 | connector->encoder->connectors_active = true; |
| 14181 | connector->base.encoder = &connector->encoder->base; |
| 14182 | } else { |
| 14183 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 14184 | connector->base.encoder = NULL; |
| 14185 | } |
| 14186 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 14187 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 14188 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14189 | connector->base.encoder ? "enabled" : "disabled"); |
| 14190 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14191 | } |
| 14192 | |
| 14193 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm |
| 14194 | * and i915 state tracking structures. */ |
| 14195 | void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 14196 | bool force_restore) |
| 14197 | { |
| 14198 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14199 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14200 | struct intel_crtc *crtc; |
| 14201 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 14202 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14203 | |
| 14204 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14205 | |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 14206 | /* |
| 14207 | * Now that we have the config, copy it to each CRTC struct |
| 14208 | * Note that this could go away if we move to using crtc_config |
| 14209 | * checking everywhere. |
| 14210 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14211 | for_each_intel_crtc(dev, crtc) { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 14212 | if (crtc->active && i915.fastboot) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14213 | intel_mode_from_pipe_config(&crtc->base.mode, |
| 14214 | crtc->config); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 14215 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
| 14216 | crtc->base.base.id); |
| 14217 | drm_mode_debug_printmodeline(&crtc->base.mode); |
| 14218 | } |
| 14219 | } |
| 14220 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14221 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14222 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14223 | intel_sanitize_encoder(encoder); |
| 14224 | } |
| 14225 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14226 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14227 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 14228 | intel_sanitize_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14229 | intel_dump_pipe_config(crtc, crtc->config, |
| 14230 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14231 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 14232 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 14233 | intel_modeset_update_connector_atomic_state(dev); |
| 14234 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 14235 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 14236 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 14237 | |
| 14238 | if (!pll->on || pll->active) |
| 14239 | continue; |
| 14240 | |
| 14241 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 14242 | |
| 14243 | pll->disable(dev_priv, pll); |
| 14244 | pll->on = false; |
| 14245 | } |
| 14246 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 14247 | if (IS_GEN9(dev)) |
| 14248 | skl_wm_get_hw_state(dev); |
| 14249 | else if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 14250 | ilk_wm_get_hw_state(dev); |
| 14251 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 14252 | if (force_restore) { |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 14253 | i915_redisable_vga(dev); |
| 14254 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 14255 | /* |
| 14256 | * We need to use raw interfaces for restoring state to avoid |
| 14257 | * checking (bogus) intermediate states. |
| 14258 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14259 | for_each_pipe(dev_priv, pipe) { |
Jesse Barnes | b5644d0 | 2013-03-26 13:25:27 -0700 | [diff] [blame] | 14260 | struct drm_crtc *crtc = |
| 14261 | dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 14262 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 14263 | intel_crtc_restore_mode(crtc); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 14264 | } |
| 14265 | } else { |
| 14266 | intel_modeset_update_staged_output_state(dev); |
| 14267 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 14268 | |
| 14269 | intel_modeset_check_state(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 14270 | } |
| 14271 | |
| 14272 | void intel_modeset_gem_init(struct drm_device *dev) |
| 14273 | { |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 14274 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14275 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 14276 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14277 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 14278 | mutex_lock(&dev->struct_mutex); |
| 14279 | intel_init_gt_powersave(dev); |
| 14280 | mutex_unlock(&dev->struct_mutex); |
| 14281 | |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 14282 | /* |
| 14283 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 14284 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 14285 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 14286 | * indicates as much. |
| 14287 | */ |
| 14288 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 14289 | dev_priv->vbt.lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 14290 | DREF_SSC1_ENABLE); |
| 14291 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 14292 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 14293 | |
| 14294 | intel_setup_overlay(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14295 | |
| 14296 | /* |
| 14297 | * Make sure any fbs we allocated at startup are properly |
| 14298 | * pinned & fenced. When we do the allocation it's too early |
| 14299 | * for this. |
| 14300 | */ |
| 14301 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 14302 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 14303 | obj = intel_fb_obj(c->primary->fb); |
| 14304 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14305 | continue; |
| 14306 | |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 14307 | if (intel_pin_and_fence_fb_obj(c->primary, |
| 14308 | c->primary->fb, |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 14309 | c->primary->state, |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 14310 | NULL)) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14311 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 14312 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 14313 | drm_framebuffer_unreference(c->primary->fb); |
| 14314 | c->primary->fb = NULL; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 14315 | update_state_fb(c->primary); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14316 | } |
| 14317 | } |
| 14318 | mutex_unlock(&dev->struct_mutex); |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 14319 | |
| 14320 | intel_backlight_register(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14321 | } |
| 14322 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 14323 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 14324 | { |
| 14325 | struct drm_connector *connector = &intel_connector->base; |
| 14326 | |
| 14327 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 14328 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 14329 | } |
| 14330 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14331 | void intel_modeset_cleanup(struct drm_device *dev) |
| 14332 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14333 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 14334 | struct drm_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14335 | |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 14336 | intel_disable_gt_powersave(dev); |
| 14337 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 14338 | intel_backlight_unregister(dev); |
| 14339 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14340 | /* |
| 14341 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 14342 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14343 | * experience fancy races otherwise. |
| 14344 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 14345 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 14346 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14347 | /* |
| 14348 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 14349 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 14350 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 14351 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14352 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14353 | mutex_lock(&dev->struct_mutex); |
| 14354 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 14355 | intel_unregister_dsm_handler(); |
| 14356 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 14357 | intel_fbc_disable(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14358 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 14359 | mutex_unlock(&dev->struct_mutex); |
| 14360 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 14361 | /* flush any delayed tasks or pending work */ |
| 14362 | flush_scheduled_work(); |
| 14363 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 14364 | /* destroy the backlight and sysfs files before encoders/connectors */ |
| 14365 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 14366 | struct intel_connector *intel_connector; |
| 14367 | |
| 14368 | intel_connector = to_intel_connector(connector); |
| 14369 | intel_connector->unregister(intel_connector); |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 14370 | } |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 14371 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14372 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 14373 | |
| 14374 | intel_cleanup_overlay(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 14375 | |
| 14376 | mutex_lock(&dev->struct_mutex); |
| 14377 | intel_cleanup_gt_powersave(dev); |
| 14378 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14379 | } |
| 14380 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14381 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 14382 | * Return which encoder is currently attached for connector. |
| 14383 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 14384 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14385 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 14386 | return &intel_attached_encoder(connector)->base; |
| 14387 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14388 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 14389 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 14390 | struct intel_encoder *encoder) |
| 14391 | { |
| 14392 | connector->encoder = encoder; |
| 14393 | drm_mode_connector_attach_encoder(&connector->base, |
| 14394 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14395 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14396 | |
| 14397 | /* |
| 14398 | * set vga decode state - true == enable VGA decode |
| 14399 | */ |
| 14400 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 14401 | { |
| 14402 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 14403 | 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] | 14404 | u16 gmch_ctrl; |
| 14405 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 14406 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 14407 | DRM_ERROR("failed to read control word\n"); |
| 14408 | return -EIO; |
| 14409 | } |
| 14410 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 14411 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 14412 | return 0; |
| 14413 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14414 | if (state) |
| 14415 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 14416 | else |
| 14417 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 14418 | |
| 14419 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 14420 | DRM_ERROR("failed to write control word\n"); |
| 14421 | return -EIO; |
| 14422 | } |
| 14423 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14424 | return 0; |
| 14425 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14426 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14427 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 14428 | |
| 14429 | u32 power_well_driver; |
| 14430 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14431 | int num_transcoders; |
| 14432 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14433 | struct intel_cursor_error_state { |
| 14434 | u32 control; |
| 14435 | u32 position; |
| 14436 | u32 base; |
| 14437 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 14438 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14439 | |
| 14440 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14441 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14442 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14443 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 14444 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14445 | |
| 14446 | struct intel_plane_error_state { |
| 14447 | u32 control; |
| 14448 | u32 stride; |
| 14449 | u32 size; |
| 14450 | u32 pos; |
| 14451 | u32 addr; |
| 14452 | u32 surface; |
| 14453 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 14454 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14455 | |
| 14456 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14457 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14458 | enum transcoder cpu_transcoder; |
| 14459 | |
| 14460 | u32 conf; |
| 14461 | |
| 14462 | u32 htotal; |
| 14463 | u32 hblank; |
| 14464 | u32 hsync; |
| 14465 | u32 vtotal; |
| 14466 | u32 vblank; |
| 14467 | u32 vsync; |
| 14468 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14469 | }; |
| 14470 | |
| 14471 | struct intel_display_error_state * |
| 14472 | intel_display_capture_error_state(struct drm_device *dev) |
| 14473 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 14474 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14475 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14476 | int transcoders[] = { |
| 14477 | TRANSCODER_A, |
| 14478 | TRANSCODER_B, |
| 14479 | TRANSCODER_C, |
| 14480 | TRANSCODER_EDP, |
| 14481 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14482 | int i; |
| 14483 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14484 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 14485 | return NULL; |
| 14486 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 14487 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14488 | if (error == NULL) |
| 14489 | return NULL; |
| 14490 | |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 14491 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 14492 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 14493 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14494 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14495 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14496 | __intel_display_power_is_enabled(dev_priv, |
| 14497 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14498 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 14499 | continue; |
| 14500 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 14501 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 14502 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 14503 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14504 | |
| 14505 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 14506 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14507 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 14508 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14509 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 14510 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 14511 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 14512 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14513 | if (INTEL_INFO(dev)->gen >= 4) { |
| 14514 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 14515 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 14516 | } |
| 14517 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14518 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14519 | |
Sonika Jindal | 3abfce7 | 2014-07-21 15:23:43 +0530 | [diff] [blame] | 14520 | if (HAS_GMCH_DISPLAY(dev)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14521 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14522 | } |
| 14523 | |
| 14524 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; |
| 14525 | if (HAS_DDI(dev_priv->dev)) |
| 14526 | error->num_transcoders++; /* Account for eDP. */ |
| 14527 | |
| 14528 | for (i = 0; i < error->num_transcoders; i++) { |
| 14529 | enum transcoder cpu_transcoder = transcoders[i]; |
| 14530 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14531 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14532 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 14533 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14534 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 14535 | continue; |
| 14536 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14537 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 14538 | |
| 14539 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 14540 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 14541 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 14542 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 14543 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 14544 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 14545 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14546 | } |
| 14547 | |
| 14548 | return error; |
| 14549 | } |
| 14550 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14551 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 14552 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14553 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14554 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14555 | struct drm_device *dev, |
| 14556 | struct intel_display_error_state *error) |
| 14557 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14558 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14559 | int i; |
| 14560 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14561 | if (!error) |
| 14562 | return; |
| 14563 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14564 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 14565 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14566 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 14567 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14568 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14569 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14570 | err_printf(m, " Power: %s\n", |
| 14571 | error->pipe[i].power_domain_on ? "on" : "off"); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14572 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14573 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14574 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14575 | err_printf(m, "Plane [%d]:\n", i); |
| 14576 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 14577 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14578 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14579 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 14580 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14581 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 14582 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14583 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14584 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14585 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 14586 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14587 | } |
| 14588 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14589 | err_printf(m, "Cursor [%d]:\n", i); |
| 14590 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 14591 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 14592 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14593 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14594 | |
| 14595 | for (i = 0; i < error->num_transcoders; i++) { |
Chris Wilson | 1cf84bb | 2013-10-21 09:10:33 +0100 | [diff] [blame] | 14596 | err_printf(m, "CPU transcoder: %c\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14597 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14598 | err_printf(m, " Power: %s\n", |
| 14599 | error->transcoder[i].power_domain_on ? "on" : "off"); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14600 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 14601 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 14602 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 14603 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 14604 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 14605 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 14606 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 14607 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14608 | } |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14609 | |
| 14610 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) |
| 14611 | { |
| 14612 | struct intel_crtc *crtc; |
| 14613 | |
| 14614 | for_each_intel_crtc(dev, crtc) { |
| 14615 | struct intel_unpin_work *work; |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14616 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 14617 | spin_lock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14618 | |
| 14619 | work = crtc->unpin_work; |
| 14620 | |
| 14621 | if (work && work->event && |
| 14622 | work->event->base.file_priv == file) { |
| 14623 | kfree(work->event); |
| 14624 | work->event = NULL; |
| 14625 | } |
| 14626 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 14627 | spin_unlock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14628 | } |
| 14629 | } |