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); |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 106 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 107 | struct intel_crtc_state *crtc_state); |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 108 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 109 | static struct intel_encoder *intel_find_encoder(struct intel_connector *connector, int pipe) |
| 110 | { |
| 111 | if (!connector->mst_port) |
| 112 | return connector->encoder; |
| 113 | else |
| 114 | return &connector->mst_port->mst_encoders[pipe]->base; |
| 115 | } |
| 116 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 117 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 118 | int min, max; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 119 | } intel_range_t; |
| 120 | |
| 121 | typedef struct { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 122 | int dot_limit; |
| 123 | int p2_slow, p2_fast; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 124 | } intel_p2_t; |
| 125 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 126 | typedef struct intel_limit intel_limit_t; |
| 127 | struct intel_limit { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 128 | intel_range_t dot, vco, n, m, m1, m2, p, p1; |
| 129 | intel_p2_t p2; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 130 | }; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 131 | |
Daniel Vetter | d2acd21 | 2012-10-20 20:57:43 +0200 | [diff] [blame] | 132 | int |
| 133 | intel_pch_rawclk(struct drm_device *dev) |
| 134 | { |
| 135 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 136 | |
| 137 | WARN_ON(!HAS_PCH_SPLIT(dev)); |
| 138 | |
| 139 | return I915_READ(PCH_RAWCLK_FREQ) & RAWCLK_FREQ_MASK; |
| 140 | } |
| 141 | |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 142 | static inline u32 /* units of 100MHz */ |
| 143 | intel_fdi_link_freq(struct drm_device *dev) |
| 144 | { |
Chris Wilson | 8b99e68 | 2010-10-13 09:59:17 +0100 | [diff] [blame] | 145 | if (IS_GEN5(dev)) { |
| 146 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 147 | return (I915_READ(FDI_PLL_BIOS_0) & FDI_PLL_FB_CLOCK_MASK) + 2; |
| 148 | } else |
| 149 | return 27; |
Chris Wilson | 021357a | 2010-09-07 20:54:59 +0100 | [diff] [blame] | 150 | } |
| 151 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 152 | static const intel_limit_t intel_limits_i8xx_dac = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 153 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 154 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 155 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 156 | .m = { .min = 96, .max = 140 }, |
| 157 | .m1 = { .min = 18, .max = 26 }, |
| 158 | .m2 = { .min = 6, .max = 16 }, |
| 159 | .p = { .min = 4, .max = 128 }, |
| 160 | .p1 = { .min = 2, .max = 33 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 161 | .p2 = { .dot_limit = 165000, |
| 162 | .p2_slow = 4, .p2_fast = 2 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 163 | }; |
| 164 | |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 165 | static const intel_limit_t intel_limits_i8xx_dvo = { |
| 166 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 167 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 168 | .n = { .min = 2, .max = 16 }, |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 169 | .m = { .min = 96, .max = 140 }, |
| 170 | .m1 = { .min = 18, .max = 26 }, |
| 171 | .m2 = { .min = 6, .max = 16 }, |
| 172 | .p = { .min = 4, .max = 128 }, |
| 173 | .p1 = { .min = 2, .max = 33 }, |
| 174 | .p2 = { .dot_limit = 165000, |
| 175 | .p2_slow = 4, .p2_fast = 4 }, |
| 176 | }; |
| 177 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 178 | static const intel_limit_t intel_limits_i8xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 179 | .dot = { .min = 25000, .max = 350000 }, |
Ville Syrjälä | 9c33371 | 2013-12-09 18:54:17 +0200 | [diff] [blame] | 180 | .vco = { .min = 908000, .max = 1512000 }, |
Ville Syrjälä | 91dbe5f | 2013-12-09 18:54:14 +0200 | [diff] [blame] | 181 | .n = { .min = 2, .max = 16 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 182 | .m = { .min = 96, .max = 140 }, |
| 183 | .m1 = { .min = 18, .max = 26 }, |
| 184 | .m2 = { .min = 6, .max = 16 }, |
| 185 | .p = { .min = 4, .max = 128 }, |
| 186 | .p1 = { .min = 1, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 187 | .p2 = { .dot_limit = 165000, |
| 188 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 189 | }; |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 190 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 191 | static const intel_limit_t intel_limits_i9xx_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 192 | .dot = { .min = 20000, .max = 400000 }, |
| 193 | .vco = { .min = 1400000, .max = 2800000 }, |
| 194 | .n = { .min = 1, .max = 6 }, |
| 195 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 4f7dfb6 | 2013-02-13 22:20:22 +0100 | [diff] [blame] | 196 | .m1 = { .min = 8, .max = 18 }, |
| 197 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 198 | .p = { .min = 5, .max = 80 }, |
| 199 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 200 | .p2 = { .dot_limit = 200000, |
| 201 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | static const intel_limit_t intel_limits_i9xx_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 205 | .dot = { .min = 20000, .max = 400000 }, |
| 206 | .vco = { .min = 1400000, .max = 2800000 }, |
| 207 | .n = { .min = 1, .max = 6 }, |
| 208 | .m = { .min = 70, .max = 120 }, |
Patrik Jakobsson | 53a7d2d | 2013-02-13 22:20:21 +0100 | [diff] [blame] | 209 | .m1 = { .min = 8, .max = 18 }, |
| 210 | .m2 = { .min = 3, .max = 7 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 211 | .p = { .min = 7, .max = 98 }, |
| 212 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 213 | .p2 = { .dot_limit = 112000, |
| 214 | .p2_slow = 14, .p2_fast = 7 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 215 | }; |
| 216 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 217 | |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 218 | static const intel_limit_t intel_limits_g4x_sdvo = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 219 | .dot = { .min = 25000, .max = 270000 }, |
| 220 | .vco = { .min = 1750000, .max = 3500000}, |
| 221 | .n = { .min = 1, .max = 4 }, |
| 222 | .m = { .min = 104, .max = 138 }, |
| 223 | .m1 = { .min = 17, .max = 23 }, |
| 224 | .m2 = { .min = 5, .max = 11 }, |
| 225 | .p = { .min = 10, .max = 30 }, |
| 226 | .p1 = { .min = 1, .max = 3}, |
| 227 | .p2 = { .dot_limit = 270000, |
| 228 | .p2_slow = 10, |
| 229 | .p2_fast = 10 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 230 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | static const intel_limit_t intel_limits_g4x_hdmi = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 234 | .dot = { .min = 22000, .max = 400000 }, |
| 235 | .vco = { .min = 1750000, .max = 3500000}, |
| 236 | .n = { .min = 1, .max = 4 }, |
| 237 | .m = { .min = 104, .max = 138 }, |
| 238 | .m1 = { .min = 16, .max = 23 }, |
| 239 | .m2 = { .min = 5, .max = 11 }, |
| 240 | .p = { .min = 5, .max = 80 }, |
| 241 | .p1 = { .min = 1, .max = 8}, |
| 242 | .p2 = { .dot_limit = 165000, |
| 243 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 244 | }; |
| 245 | |
| 246 | static const intel_limit_t intel_limits_g4x_single_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 247 | .dot = { .min = 20000, .max = 115000 }, |
| 248 | .vco = { .min = 1750000, .max = 3500000 }, |
| 249 | .n = { .min = 1, .max = 3 }, |
| 250 | .m = { .min = 104, .max = 138 }, |
| 251 | .m1 = { .min = 17, .max = 23 }, |
| 252 | .m2 = { .min = 5, .max = 11 }, |
| 253 | .p = { .min = 28, .max = 112 }, |
| 254 | .p1 = { .min = 2, .max = 8 }, |
| 255 | .p2 = { .dot_limit = 0, |
| 256 | .p2_slow = 14, .p2_fast = 14 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 257 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 258 | }; |
| 259 | |
| 260 | static const intel_limit_t intel_limits_g4x_dual_channel_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 261 | .dot = { .min = 80000, .max = 224000 }, |
| 262 | .vco = { .min = 1750000, .max = 3500000 }, |
| 263 | .n = { .min = 1, .max = 3 }, |
| 264 | .m = { .min = 104, .max = 138 }, |
| 265 | .m1 = { .min = 17, .max = 23 }, |
| 266 | .m2 = { .min = 5, .max = 11 }, |
| 267 | .p = { .min = 14, .max = 42 }, |
| 268 | .p1 = { .min = 2, .max = 6 }, |
| 269 | .p2 = { .dot_limit = 0, |
| 270 | .p2_slow = 7, .p2_fast = 7 |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 271 | }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 274 | static const intel_limit_t intel_limits_pineview_sdvo = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 275 | .dot = { .min = 20000, .max = 400000}, |
| 276 | .vco = { .min = 1700000, .max = 3500000 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 277 | /* Pineview's Ncounter is a ring counter */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 278 | .n = { .min = 3, .max = 6 }, |
| 279 | .m = { .min = 2, .max = 256 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 280 | /* Pineview only has one combined m divider, which we treat as m2. */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 281 | .m1 = { .min = 0, .max = 0 }, |
| 282 | .m2 = { .min = 0, .max = 254 }, |
| 283 | .p = { .min = 5, .max = 80 }, |
| 284 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 285 | .p2 = { .dot_limit = 200000, |
| 286 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 287 | }; |
| 288 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 289 | static const intel_limit_t intel_limits_pineview_lvds = { |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 290 | .dot = { .min = 20000, .max = 400000 }, |
| 291 | .vco = { .min = 1700000, .max = 3500000 }, |
| 292 | .n = { .min = 3, .max = 6 }, |
| 293 | .m = { .min = 2, .max = 256 }, |
| 294 | .m1 = { .min = 0, .max = 0 }, |
| 295 | .m2 = { .min = 0, .max = 254 }, |
| 296 | .p = { .min = 7, .max = 112 }, |
| 297 | .p1 = { .min = 1, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 298 | .p2 = { .dot_limit = 112000, |
| 299 | .p2_slow = 14, .p2_fast = 14 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 300 | }; |
| 301 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 302 | /* Ironlake / Sandybridge |
| 303 | * |
| 304 | * We calculate clock using (register_value + 2) for N/M1/M2, so here |
| 305 | * the range value for them is (actual_value - 2). |
| 306 | */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 307 | static const intel_limit_t intel_limits_ironlake_dac = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 308 | .dot = { .min = 25000, .max = 350000 }, |
| 309 | .vco = { .min = 1760000, .max = 3510000 }, |
| 310 | .n = { .min = 1, .max = 5 }, |
| 311 | .m = { .min = 79, .max = 127 }, |
| 312 | .m1 = { .min = 12, .max = 22 }, |
| 313 | .m2 = { .min = 5, .max = 9 }, |
| 314 | .p = { .min = 5, .max = 80 }, |
| 315 | .p1 = { .min = 1, .max = 8 }, |
| 316 | .p2 = { .dot_limit = 225000, |
| 317 | .p2_slow = 10, .p2_fast = 5 }, |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 318 | }; |
| 319 | |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 320 | static const intel_limit_t intel_limits_ironlake_single_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 321 | .dot = { .min = 25000, .max = 350000 }, |
| 322 | .vco = { .min = 1760000, .max = 3510000 }, |
| 323 | .n = { .min = 1, .max = 3 }, |
| 324 | .m = { .min = 79, .max = 118 }, |
| 325 | .m1 = { .min = 12, .max = 22 }, |
| 326 | .m2 = { .min = 5, .max = 9 }, |
| 327 | .p = { .min = 28, .max = 112 }, |
| 328 | .p1 = { .min = 2, .max = 8 }, |
| 329 | .p2 = { .dot_limit = 225000, |
| 330 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | static const intel_limit_t intel_limits_ironlake_dual_lvds = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 334 | .dot = { .min = 25000, .max = 350000 }, |
| 335 | .vco = { .min = 1760000, .max = 3510000 }, |
| 336 | .n = { .min = 1, .max = 3 }, |
| 337 | .m = { .min = 79, .max = 127 }, |
| 338 | .m1 = { .min = 12, .max = 22 }, |
| 339 | .m2 = { .min = 5, .max = 9 }, |
| 340 | .p = { .min = 14, .max = 56 }, |
| 341 | .p1 = { .min = 2, .max = 8 }, |
| 342 | .p2 = { .dot_limit = 225000, |
| 343 | .p2_slow = 7, .p2_fast = 7 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 344 | }; |
| 345 | |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 346 | /* LVDS 100mhz refclk limits. */ |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 347 | static const intel_limit_t intel_limits_ironlake_single_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 348 | .dot = { .min = 25000, .max = 350000 }, |
| 349 | .vco = { .min = 1760000, .max = 3510000 }, |
| 350 | .n = { .min = 1, .max = 2 }, |
| 351 | .m = { .min = 79, .max = 126 }, |
| 352 | .m1 = { .min = 12, .max = 22 }, |
| 353 | .m2 = { .min = 5, .max = 9 }, |
| 354 | .p = { .min = 28, .max = 112 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 355 | .p1 = { .min = 2, .max = 8 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 356 | .p2 = { .dot_limit = 225000, |
| 357 | .p2_slow = 14, .p2_fast = 14 }, |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 358 | }; |
| 359 | |
| 360 | static const intel_limit_t intel_limits_ironlake_dual_lvds_100m = { |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 361 | .dot = { .min = 25000, .max = 350000 }, |
| 362 | .vco = { .min = 1760000, .max = 3510000 }, |
| 363 | .n = { .min = 1, .max = 3 }, |
| 364 | .m = { .min = 79, .max = 126 }, |
| 365 | .m1 = { .min = 12, .max = 22 }, |
| 366 | .m2 = { .min = 5, .max = 9 }, |
| 367 | .p = { .min = 14, .max = 42 }, |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 368 | .p1 = { .min = 2, .max = 6 }, |
Eric Anholt | 273e27c | 2011-03-30 13:01:10 -0700 | [diff] [blame] | 369 | .p2 = { .dot_limit = 225000, |
| 370 | .p2_slow = 7, .p2_fast = 7 }, |
Zhao Yakui | 4547668 | 2009-12-31 16:06:04 +0800 | [diff] [blame] | 371 | }; |
| 372 | |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 373 | static const intel_limit_t intel_limits_vlv = { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 374 | /* |
| 375 | * These are the data rate limits (measured in fast clocks) |
| 376 | * since those are the strictest limits we have. The fast |
| 377 | * clock and actual rate limits are more relaxed, so checking |
| 378 | * them would make no difference. |
| 379 | */ |
| 380 | .dot = { .min = 25000 * 5, .max = 270000 * 5 }, |
Daniel Vetter | 75e5398 | 2013-04-18 21:10:43 +0200 | [diff] [blame] | 381 | .vco = { .min = 4000000, .max = 6000000 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 382 | .n = { .min = 1, .max = 7 }, |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 383 | .m1 = { .min = 2, .max = 3 }, |
| 384 | .m2 = { .min = 11, .max = 156 }, |
Ville Syrjälä | b99ab66 | 2013-09-24 21:26:26 +0300 | [diff] [blame] | 385 | .p1 = { .min = 2, .max = 3 }, |
Ville Syrjälä | 5fdc9c49 | 2013-09-24 21:26:29 +0300 | [diff] [blame] | 386 | .p2 = { .p2_slow = 2, .p2_fast = 20 }, /* slow=min, fast=max */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 387 | }; |
| 388 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 389 | static const intel_limit_t intel_limits_chv = { |
| 390 | /* |
| 391 | * These are the data rate limits (measured in fast clocks) |
| 392 | * since those are the strictest limits we have. The fast |
| 393 | * clock and actual rate limits are more relaxed, so checking |
| 394 | * them would make no difference. |
| 395 | */ |
| 396 | .dot = { .min = 25000 * 5, .max = 540000 * 5}, |
Ville Syrjälä | 17fe102 | 2015-02-26 21:01:52 +0200 | [diff] [blame] | 397 | .vco = { .min = 4800000, .max = 6480000 }, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 398 | .n = { .min = 1, .max = 1 }, |
| 399 | .m1 = { .min = 2, .max = 2 }, |
| 400 | .m2 = { .min = 24 << 22, .max = 175 << 22 }, |
| 401 | .p1 = { .min = 2, .max = 4 }, |
| 402 | .p2 = { .p2_slow = 1, .p2_fast = 14 }, |
| 403 | }; |
| 404 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 405 | static void vlv_clock(int refclk, intel_clock_t *clock) |
| 406 | { |
| 407 | clock->m = clock->m1 * clock->m2; |
| 408 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 409 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 410 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 411 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 412 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 413 | } |
| 414 | |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 415 | /** |
| 416 | * Returns whether any output on the specified pipe is of the specified type |
| 417 | */ |
Damien Lespiau | 4093561 | 2014-10-29 11:16:59 +0000 | [diff] [blame] | 418 | 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] | 419 | { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 420 | struct drm_device *dev = crtc->base.dev; |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 421 | struct intel_encoder *encoder; |
| 422 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 423 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) |
Paulo Zanoni | e0638cd | 2013-09-24 13:52:54 -0300 | [diff] [blame] | 424 | if (encoder->type == type) |
| 425 | return true; |
| 426 | |
| 427 | return false; |
| 428 | } |
| 429 | |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 430 | /** |
| 431 | * Returns whether any output on the specified pipe will have the specified |
| 432 | * type after a staged modeset is complete, i.e., the same as |
| 433 | * intel_pipe_has_type() but looking at encoder->new_crtc instead of |
| 434 | * encoder->crtc. |
| 435 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 436 | static bool intel_pipe_will_have_type(const struct intel_crtc_state *crtc_state, |
| 437 | int type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 438 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 439 | struct drm_atomic_state *state = crtc_state->base.state; |
| 440 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 441 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 442 | int i, num_connectors = 0; |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 443 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 444 | for (i = 0; i < state->num_connector; i++) { |
| 445 | if (!state->connectors[i]) |
| 446 | continue; |
| 447 | |
| 448 | connector_state = state->connector_states[i]; |
| 449 | if (connector_state->crtc != crtc_state->base.crtc) |
| 450 | continue; |
| 451 | |
| 452 | num_connectors++; |
| 453 | |
| 454 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 455 | if (encoder->type == type) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 456 | return true; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | WARN_ON(num_connectors == 0); |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 460 | |
| 461 | return false; |
| 462 | } |
| 463 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 464 | static const intel_limit_t * |
| 465 | intel_ironlake_limit(struct intel_crtc_state *crtc_state, int refclk) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 466 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 467 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 468 | const intel_limit_t *limit; |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 469 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 470 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 471 | if (intel_is_dual_link_lvds(dev)) { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 472 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 473 | limit = &intel_limits_ironlake_dual_lvds_100m; |
| 474 | else |
| 475 | limit = &intel_limits_ironlake_dual_lvds; |
| 476 | } else { |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 477 | if (refclk == 100000) |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 478 | limit = &intel_limits_ironlake_single_lvds_100m; |
| 479 | else |
| 480 | limit = &intel_limits_ironlake_single_lvds; |
| 481 | } |
Daniel Vetter | c6bb353 | 2013-04-19 11:14:33 +0200 | [diff] [blame] | 482 | } else |
Zhenyu Wang | b91ad0e | 2010-02-05 09:14:17 +0800 | [diff] [blame] | 483 | limit = &intel_limits_ironlake_dac; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 484 | |
| 485 | return limit; |
| 486 | } |
| 487 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 488 | static const intel_limit_t * |
| 489 | intel_g4x_limit(struct intel_crtc_state *crtc_state) |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 490 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 491 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 492 | const intel_limit_t *limit; |
| 493 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 494 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 495 | if (intel_is_dual_link_lvds(dev)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 496 | limit = &intel_limits_g4x_dual_channel_lvds; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 497 | else |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 498 | limit = &intel_limits_g4x_single_channel_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 499 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI) || |
| 500 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_ANALOG)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 501 | limit = &intel_limits_g4x_hdmi; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 502 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO)) { |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 503 | limit = &intel_limits_g4x_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 504 | } else /* The option is for other outputs */ |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 505 | limit = &intel_limits_i9xx_sdvo; |
Ma Ling | 044c7c4 | 2009-03-18 20:13:23 +0800 | [diff] [blame] | 506 | |
| 507 | return limit; |
| 508 | } |
| 509 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 510 | static const intel_limit_t * |
| 511 | intel_limit(struct intel_crtc_state *crtc_state, int refclk) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 512 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 513 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 514 | const intel_limit_t *limit; |
| 515 | |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 516 | if (HAS_PCH_SPLIT(dev)) |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 517 | limit = intel_ironlake_limit(crtc_state, refclk); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 518 | else if (IS_G4X(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 519 | limit = intel_g4x_limit(crtc_state); |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 520 | } else if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 521 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 522 | limit = &intel_limits_pineview_lvds; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 523 | else |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 524 | limit = &intel_limits_pineview_sdvo; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 525 | } else if (IS_CHERRYVIEW(dev)) { |
| 526 | limit = &intel_limits_chv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 527 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | dc73051 | 2013-09-24 21:26:30 +0300 | [diff] [blame] | 528 | limit = &intel_limits_vlv; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 529 | } else if (!IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 530 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 531 | limit = &intel_limits_i9xx_lvds; |
| 532 | else |
| 533 | limit = &intel_limits_i9xx_sdvo; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 534 | } else { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 535 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 536 | limit = &intel_limits_i8xx_lvds; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 537 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_DVO)) |
Keith Packard | e4b3669 | 2009-06-05 19:22:17 -0700 | [diff] [blame] | 538 | limit = &intel_limits_i8xx_dvo; |
Daniel Vetter | 5d536e2 | 2013-07-06 12:52:06 +0200 | [diff] [blame] | 539 | else |
| 540 | limit = &intel_limits_i8xx_dac; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 541 | } |
| 542 | return limit; |
| 543 | } |
| 544 | |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 545 | /* m1 is reserved as 0 in Pineview, n is a ring counter */ |
| 546 | static void pineview_clock(int refclk, intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 547 | { |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 548 | clock->m = clock->m2 + 2; |
| 549 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 550 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 551 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 552 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n); |
| 553 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 554 | } |
| 555 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 556 | static uint32_t i9xx_dpll_compute_m(struct dpll *dpll) |
| 557 | { |
| 558 | return 5 * (dpll->m1 + 2) + (dpll->m2 + 2); |
| 559 | } |
| 560 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 561 | static void i9xx_clock(int refclk, intel_clock_t *clock) |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 562 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 563 | clock->m = i9xx_dpll_compute_m(clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 564 | clock->p = clock->p1 * clock->p2; |
Ville Syrjälä | ed5ca77 | 2013-12-02 19:00:45 +0200 | [diff] [blame] | 565 | if (WARN_ON(clock->n + 2 == 0 || clock->p == 0)) |
| 566 | return; |
Ville Syrjälä | fb03ac0 | 2013-10-14 14:50:30 +0300 | [diff] [blame] | 567 | clock->vco = DIV_ROUND_CLOSEST(refclk * clock->m, clock->n + 2); |
| 568 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 569 | } |
| 570 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 571 | static void chv_clock(int refclk, intel_clock_t *clock) |
| 572 | { |
| 573 | clock->m = clock->m1 * clock->m2; |
| 574 | clock->p = clock->p1 * clock->p2; |
| 575 | if (WARN_ON(clock->n == 0 || clock->p == 0)) |
| 576 | return; |
| 577 | clock->vco = DIV_ROUND_CLOSEST_ULL((uint64_t)refclk * clock->m, |
| 578 | clock->n << 22); |
| 579 | clock->dot = DIV_ROUND_CLOSEST(clock->vco, clock->p); |
| 580 | } |
| 581 | |
Jesse Barnes | 7c04d1d | 2009-02-23 15:36:40 -0800 | [diff] [blame] | 582 | #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 583 | /** |
| 584 | * Returns whether the given set of divisors are valid for a given refclk with |
| 585 | * the given connectors. |
| 586 | */ |
| 587 | |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 588 | static bool intel_PLL_is_valid(struct drm_device *dev, |
| 589 | const intel_limit_t *limit, |
| 590 | const intel_clock_t *clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 591 | { |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 592 | if (clock->n < limit->n.min || limit->n.max < clock->n) |
| 593 | INTELPllInvalid("n out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 594 | if (clock->p1 < limit->p1.min || limit->p1.max < clock->p1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 595 | INTELPllInvalid("p1 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 596 | if (clock->m2 < limit->m2.min || limit->m2.max < clock->m2) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 597 | INTELPllInvalid("m2 out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 598 | if (clock->m1 < limit->m1.min || limit->m1.max < clock->m1) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 599 | INTELPllInvalid("m1 out of range\n"); |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 600 | |
| 601 | if (!IS_PINEVIEW(dev) && !IS_VALLEYVIEW(dev)) |
| 602 | if (clock->m1 <= clock->m2) |
| 603 | INTELPllInvalid("m1 <= m2\n"); |
| 604 | |
| 605 | if (!IS_VALLEYVIEW(dev)) { |
| 606 | if (clock->p < limit->p.min || limit->p.max < clock->p) |
| 607 | INTELPllInvalid("p out of range\n"); |
| 608 | if (clock->m < limit->m.min || limit->m.max < clock->m) |
| 609 | INTELPllInvalid("m out of range\n"); |
| 610 | } |
| 611 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 612 | if (clock->vco < limit->vco.min || limit->vco.max < clock->vco) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 613 | INTELPllInvalid("vco out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 614 | /* XXX: We may need to be checking "Dot clock" depending on the multiplier, |
| 615 | * connector, etc., rather than just a single range. |
| 616 | */ |
| 617 | if (clock->dot < limit->dot.min || limit->dot.max < clock->dot) |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 618 | INTELPllInvalid("dot out of range\n"); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 619 | |
| 620 | return true; |
| 621 | } |
| 622 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 623 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 624 | i9xx_find_best_dpll(const intel_limit_t *limit, |
| 625 | struct intel_crtc_state *crtc_state, |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 626 | int target, int refclk, intel_clock_t *match_clock, |
| 627 | intel_clock_t *best_clock) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 628 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 629 | 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] | 630 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 631 | intel_clock_t clock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 632 | int err = target; |
| 633 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 634 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 635 | /* |
Daniel Vetter | a210b02 | 2012-11-26 17:22:08 +0100 | [diff] [blame] | 636 | * For LVDS just rely on its current settings for dual-channel. |
| 637 | * We haven't figured out how to reliably set up different |
| 638 | * single/dual channel state, if we even can. |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 639 | */ |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 640 | if (intel_is_dual_link_lvds(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 641 | clock.p2 = limit->p2.p2_fast; |
| 642 | else |
| 643 | clock.p2 = limit->p2.p2_slow; |
| 644 | } else { |
| 645 | if (target < limit->p2.dot_limit) |
| 646 | clock.p2 = limit->p2.p2_slow; |
| 647 | else |
| 648 | clock.p2 = limit->p2.p2_fast; |
| 649 | } |
| 650 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 651 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 652 | |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 653 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 654 | clock.m1++) { |
| 655 | for (clock.m2 = limit->m2.min; |
| 656 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | c0efc38 | 2013-06-03 20:56:24 +0200 | [diff] [blame] | 657 | if (clock.m2 >= clock.m1) |
Zhao Yakui | 4215866 | 2009-11-20 11:24:18 +0800 | [diff] [blame] | 658 | break; |
| 659 | for (clock.n = limit->n.min; |
| 660 | clock.n <= limit->n.max; clock.n++) { |
| 661 | for (clock.p1 = limit->p1.min; |
| 662 | clock.p1 <= limit->p1.max; clock.p1++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 663 | int this_err; |
| 664 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 665 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 666 | if (!intel_PLL_is_valid(dev, limit, |
| 667 | &clock)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 668 | continue; |
Sean Paul | cec2f35 | 2012-01-10 15:09:36 -0800 | [diff] [blame] | 669 | if (match_clock && |
| 670 | clock.p != match_clock->p) |
| 671 | continue; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 672 | |
| 673 | this_err = abs(clock.dot - target); |
| 674 | if (this_err < err) { |
| 675 | *best_clock = clock; |
| 676 | err = this_err; |
| 677 | } |
| 678 | } |
| 679 | } |
| 680 | } |
| 681 | } |
| 682 | |
| 683 | return (err != target); |
| 684 | } |
| 685 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 686 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 687 | pnv_find_best_dpll(const intel_limit_t *limit, |
| 688 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 689 | int target, int refclk, intel_clock_t *match_clock, |
| 690 | intel_clock_t *best_clock) |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 691 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 692 | 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] | 693 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 694 | intel_clock_t clock; |
| 695 | int err = target; |
| 696 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 697 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 698 | /* |
| 699 | * For LVDS just rely on its current settings for dual-channel. |
| 700 | * We haven't figured out how to reliably set up different |
| 701 | * single/dual channel state, if we even can. |
| 702 | */ |
| 703 | if (intel_is_dual_link_lvds(dev)) |
| 704 | clock.p2 = limit->p2.p2_fast; |
| 705 | else |
| 706 | clock.p2 = limit->p2.p2_slow; |
| 707 | } else { |
| 708 | if (target < limit->p2.dot_limit) |
| 709 | clock.p2 = limit->p2.p2_slow; |
| 710 | else |
| 711 | clock.p2 = limit->p2.p2_fast; |
| 712 | } |
| 713 | |
| 714 | memset(best_clock, 0, sizeof(*best_clock)); |
| 715 | |
| 716 | for (clock.m1 = limit->m1.min; clock.m1 <= limit->m1.max; |
| 717 | clock.m1++) { |
| 718 | for (clock.m2 = limit->m2.min; |
| 719 | clock.m2 <= limit->m2.max; clock.m2++) { |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 720 | for (clock.n = limit->n.min; |
| 721 | clock.n <= limit->n.max; clock.n++) { |
| 722 | for (clock.p1 = limit->p1.min; |
| 723 | clock.p1 <= limit->p1.max; clock.p1++) { |
| 724 | int this_err; |
| 725 | |
| 726 | pineview_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 727 | if (!intel_PLL_is_valid(dev, limit, |
| 728 | &clock)) |
| 729 | continue; |
| 730 | if (match_clock && |
| 731 | clock.p != match_clock->p) |
| 732 | continue; |
| 733 | |
| 734 | this_err = abs(clock.dot - target); |
| 735 | if (this_err < err) { |
| 736 | *best_clock = clock; |
| 737 | err = this_err; |
| 738 | } |
| 739 | } |
| 740 | } |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | return (err != target); |
| 745 | } |
| 746 | |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 747 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 748 | g4x_find_best_dpll(const intel_limit_t *limit, |
| 749 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 750 | int target, int refclk, intel_clock_t *match_clock, |
| 751 | intel_clock_t *best_clock) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 752 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 753 | 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] | 754 | struct drm_device *dev = crtc->base.dev; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 755 | intel_clock_t clock; |
| 756 | int max_n; |
| 757 | bool found; |
Adam Jackson | 6ba770d | 2010-07-02 16:43:30 -0400 | [diff] [blame] | 758 | /* approximately equals target * 0.00585 */ |
| 759 | int err_most = (target >> 8) + (target >> 9); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 760 | found = false; |
| 761 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 762 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | 1974cad | 2012-11-26 17:22:09 +0100 | [diff] [blame] | 763 | if (intel_is_dual_link_lvds(dev)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 764 | clock.p2 = limit->p2.p2_fast; |
| 765 | else |
| 766 | clock.p2 = limit->p2.p2_slow; |
| 767 | } else { |
| 768 | if (target < limit->p2.dot_limit) |
| 769 | clock.p2 = limit->p2.p2_slow; |
| 770 | else |
| 771 | clock.p2 = limit->p2.p2_fast; |
| 772 | } |
| 773 | |
| 774 | memset(best_clock, 0, sizeof(*best_clock)); |
| 775 | max_n = limit->n.max; |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 776 | /* based on hardware requirement, prefer smaller n to precision */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 777 | for (clock.n = limit->n.min; clock.n <= max_n; clock.n++) { |
Gilles Espinasse | f77f13e | 2010-03-29 15:41:47 +0200 | [diff] [blame] | 778 | /* based on hardware requirement, prefere larger m1,m2 */ |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 779 | for (clock.m1 = limit->m1.max; |
| 780 | clock.m1 >= limit->m1.min; clock.m1--) { |
| 781 | for (clock.m2 = limit->m2.max; |
| 782 | clock.m2 >= limit->m2.min; clock.m2--) { |
| 783 | for (clock.p1 = limit->p1.max; |
| 784 | clock.p1 >= limit->p1.min; clock.p1--) { |
| 785 | int this_err; |
| 786 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 787 | i9xx_clock(refclk, &clock); |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 788 | if (!intel_PLL_is_valid(dev, limit, |
| 789 | &clock)) |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 790 | continue; |
Chris Wilson | 1b894b5 | 2010-12-14 20:04:54 +0000 | [diff] [blame] | 791 | |
| 792 | this_err = abs(clock.dot - target); |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 793 | if (this_err < err_most) { |
| 794 | *best_clock = clock; |
| 795 | err_most = this_err; |
| 796 | max_n = clock.n; |
| 797 | found = true; |
| 798 | } |
| 799 | } |
| 800 | } |
| 801 | } |
| 802 | } |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 803 | return found; |
| 804 | } |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 805 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 806 | /* |
| 807 | * Check if the calculated PLL configuration is more optimal compared to the |
| 808 | * best configuration and error found so far. Return the calculated error. |
| 809 | */ |
| 810 | static bool vlv_PLL_is_optimal(struct drm_device *dev, int target_freq, |
| 811 | const intel_clock_t *calculated_clock, |
| 812 | const intel_clock_t *best_clock, |
| 813 | unsigned int best_error_ppm, |
| 814 | unsigned int *error_ppm) |
| 815 | { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 816 | /* |
| 817 | * For CHV ignore the error and consider only the P value. |
| 818 | * Prefer a bigger P value based on HW requirements. |
| 819 | */ |
| 820 | if (IS_CHERRYVIEW(dev)) { |
| 821 | *error_ppm = 0; |
| 822 | |
| 823 | return calculated_clock->p > best_clock->p; |
| 824 | } |
| 825 | |
Imre Deak | 24be4e4 | 2015-03-17 11:40:04 +0200 | [diff] [blame] | 826 | if (WARN_ON_ONCE(!target_freq)) |
| 827 | return false; |
| 828 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 829 | *error_ppm = div_u64(1000000ULL * |
| 830 | abs(target_freq - calculated_clock->dot), |
| 831 | target_freq); |
| 832 | /* |
| 833 | * Prefer a better P value over a better (smaller) error if the error |
| 834 | * is small. Ensure this preference for future configurations too by |
| 835 | * setting the error to 0. |
| 836 | */ |
| 837 | if (*error_ppm < 100 && calculated_clock->p > best_clock->p) { |
| 838 | *error_ppm = 0; |
| 839 | |
| 840 | return true; |
| 841 | } |
| 842 | |
| 843 | return *error_ppm + 10 < best_error_ppm; |
| 844 | } |
| 845 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 846 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 847 | vlv_find_best_dpll(const intel_limit_t *limit, |
| 848 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 849 | int target, int refclk, intel_clock_t *match_clock, |
| 850 | intel_clock_t *best_clock) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 851 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 852 | 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] | 853 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 854 | intel_clock_t clock; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 855 | unsigned int bestppm = 1000000; |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 856 | /* min update 19.2 MHz */ |
| 857 | int max_n = min(limit->n.max, refclk / 19200); |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 858 | bool found = false; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 859 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 860 | target *= 5; /* fast clock */ |
| 861 | |
| 862 | memset(best_clock, 0, sizeof(*best_clock)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 863 | |
| 864 | /* based on hardware requirement, prefer smaller n to precision */ |
Ville Syrjälä | 27e639b | 2013-09-24 21:26:24 +0300 | [diff] [blame] | 865 | 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] | 866 | 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] | 867 | 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] | 868 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 869 | clock.p = clock.p1 * clock.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 870 | /* based on hardware requirement, prefer bigger m1,m2 values */ |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 871 | 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] | 872 | unsigned int ppm; |
Ville Syrjälä | 69e4f900 | 2013-09-24 21:26:20 +0300 | [diff] [blame] | 873 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 874 | clock.m2 = DIV_ROUND_CLOSEST(target * clock.p * clock.n, |
| 875 | refclk * clock.m1); |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 876 | |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 877 | vlv_clock(refclk, &clock); |
| 878 | |
Ville Syrjälä | f01b796 | 2013-09-27 16:55:49 +0300 | [diff] [blame] | 879 | if (!intel_PLL_is_valid(dev, limit, |
| 880 | &clock)) |
Ville Syrjälä | 43b0ac5 | 2013-09-24 21:26:18 +0300 | [diff] [blame] | 881 | continue; |
| 882 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 883 | if (!vlv_PLL_is_optimal(dev, target, |
| 884 | &clock, |
| 885 | best_clock, |
| 886 | bestppm, &ppm)) |
| 887 | continue; |
Ville Syrjälä | 6b4bf1c | 2013-09-27 16:54:19 +0300 | [diff] [blame] | 888 | |
Imre Deak | d5dd62b | 2015-03-17 11:40:03 +0200 | [diff] [blame] | 889 | *best_clock = clock; |
| 890 | bestppm = ppm; |
| 891 | found = true; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 892 | } |
| 893 | } |
| 894 | } |
| 895 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 896 | |
Ville Syrjälä | 49e497e | 2013-09-24 21:26:31 +0300 | [diff] [blame] | 897 | return found; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 898 | } |
Keith Packard | a4fc5ed | 2009-04-07 16:16:42 -0700 | [diff] [blame] | 899 | |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 900 | static bool |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 901 | chv_find_best_dpll(const intel_limit_t *limit, |
| 902 | struct intel_crtc_state *crtc_state, |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 903 | int target, int refclk, intel_clock_t *match_clock, |
| 904 | intel_clock_t *best_clock) |
| 905 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 906 | 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] | 907 | struct drm_device *dev = crtc->base.dev; |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 908 | unsigned int best_error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 909 | intel_clock_t clock; |
| 910 | uint64_t m2; |
| 911 | int found = false; |
| 912 | |
| 913 | memset(best_clock, 0, sizeof(*best_clock)); |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 914 | best_error_ppm = 1000000; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 915 | |
| 916 | /* |
| 917 | * Based on hardware doc, the n always set to 1, and m1 always |
| 918 | * set to 2. If requires to support 200Mhz refclk, we need to |
| 919 | * revisit this because n may not 1 anymore. |
| 920 | */ |
| 921 | clock.n = 1, clock.m1 = 2; |
| 922 | target *= 5; /* fast clock */ |
| 923 | |
| 924 | for (clock.p1 = limit->p1.max; clock.p1 >= limit->p1.min; clock.p1--) { |
| 925 | for (clock.p2 = limit->p2.p2_fast; |
| 926 | clock.p2 >= limit->p2.p2_slow; |
| 927 | clock.p2 -= clock.p2 > 10 ? 2 : 1) { |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 928 | unsigned int error_ppm; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 929 | |
| 930 | clock.p = clock.p1 * clock.p2; |
| 931 | |
| 932 | m2 = DIV_ROUND_CLOSEST_ULL(((uint64_t)target * clock.p * |
| 933 | clock.n) << 22, refclk * clock.m1); |
| 934 | |
| 935 | if (m2 > INT_MAX/clock.m1) |
| 936 | continue; |
| 937 | |
| 938 | clock.m2 = m2; |
| 939 | |
| 940 | chv_clock(refclk, &clock); |
| 941 | |
| 942 | if (!intel_PLL_is_valid(dev, limit, &clock)) |
| 943 | continue; |
| 944 | |
Imre Deak | 9ca3ba0 | 2015-03-17 11:40:05 +0200 | [diff] [blame] | 945 | if (!vlv_PLL_is_optimal(dev, target, &clock, best_clock, |
| 946 | best_error_ppm, &error_ppm)) |
| 947 | continue; |
| 948 | |
| 949 | *best_clock = clock; |
| 950 | best_error_ppm = error_ppm; |
| 951 | found = true; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 952 | } |
| 953 | } |
| 954 | |
| 955 | return found; |
| 956 | } |
| 957 | |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 958 | bool intel_crtc_active(struct drm_crtc *crtc) |
| 959 | { |
| 960 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 961 | |
| 962 | /* Be paranoid as we can arrive here with only partial |
| 963 | * state retrieved from the hardware during setup. |
| 964 | * |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 965 | * We can ditch the adjusted_mode.crtc_clock check as soon |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 966 | * as Haswell has gained clock readout/fastboot support. |
| 967 | * |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 968 | * 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] | 969 | * properly reconstruct framebuffers. |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 970 | * |
| 971 | * FIXME: The intel_crtc->active here should be switched to |
| 972 | * crtc->state->active once we have proper CRTC states wired up |
| 973 | * for atomic. |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 974 | */ |
Matt Roper | c3d1f43 | 2015-03-09 10:19:23 -0700 | [diff] [blame] | 975 | return intel_crtc->active && crtc->primary->state->fb && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 976 | intel_crtc->config->base.adjusted_mode.crtc_clock; |
Ville Syrjälä | 20ddf66 | 2013-09-04 18:25:25 +0300 | [diff] [blame] | 977 | } |
| 978 | |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 979 | enum transcoder intel_pipe_to_cpu_transcoder(struct drm_i915_private *dev_priv, |
| 980 | enum pipe pipe) |
| 981 | { |
| 982 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 983 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 984 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 985 | return intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | a5c961d | 2012-10-24 15:59:34 -0200 | [diff] [blame] | 986 | } |
| 987 | |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 988 | static bool pipe_dsl_stopped(struct drm_device *dev, enum pipe pipe) |
| 989 | { |
| 990 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 991 | u32 reg = PIPEDSL(pipe); |
| 992 | u32 line1, line2; |
| 993 | u32 line_mask; |
| 994 | |
| 995 | if (IS_GEN2(dev)) |
| 996 | line_mask = DSL_LINEMASK_GEN2; |
| 997 | else |
| 998 | line_mask = DSL_LINEMASK_GEN3; |
| 999 | |
| 1000 | line1 = I915_READ(reg) & line_mask; |
| 1001 | mdelay(5); |
| 1002 | line2 = I915_READ(reg) & line_mask; |
| 1003 | |
| 1004 | return line1 == line2; |
| 1005 | } |
| 1006 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1007 | /* |
| 1008 | * intel_wait_for_pipe_off - wait for pipe to turn off |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1009 | * @crtc: crtc whose pipe to wait for |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1010 | * |
| 1011 | * After disabling a pipe, we can't wait for vblank in the usual way, |
| 1012 | * spinning on the vblank interrupt status bit, since we won't actually |
| 1013 | * see an interrupt when the pipe is disabled. |
| 1014 | * |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1015 | * On Gen4 and above: |
| 1016 | * wait for the pipe register state bit to turn off |
| 1017 | * |
| 1018 | * Otherwise: |
| 1019 | * wait for the display line value to settle (it usually |
| 1020 | * ends up stopping at the start of the next frame). |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1021 | * |
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 | static void intel_wait_for_pipe_off(struct intel_crtc *crtc) |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1024 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1025 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1026 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1027 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 1028 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1029 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1030 | if (INTEL_INFO(dev)->gen >= 4) { |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1031 | int reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 1032 | |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1033 | /* Wait for the Pipe State to go off */ |
Chris Wilson | 58e10eb | 2010-10-03 10:56:11 +0100 | [diff] [blame] | 1034 | if (wait_for((I915_READ(reg) & I965_PIPECONF_ACTIVE) == 0, |
| 1035 | 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1036 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1037 | } else { |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1038 | /* Wait for the display line to settle */ |
Ville Syrjälä | fbf49ea | 2013-10-11 14:21:31 +0300 | [diff] [blame] | 1039 | if (wait_for(pipe_dsl_stopped(dev, pipe), 100)) |
Daniel Vetter | 284637d | 2012-07-09 09:51:57 +0200 | [diff] [blame] | 1040 | WARN(1, "pipe_off wait timed out\n"); |
Keith Packard | ab7ad7f | 2010-10-03 00:33:06 -0700 | [diff] [blame] | 1041 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 1042 | } |
| 1043 | |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1044 | /* |
| 1045 | * ibx_digital_port_connected - is the specified port connected? |
| 1046 | * @dev_priv: i915 private structure |
| 1047 | * @port: the port to test |
| 1048 | * |
| 1049 | * Returns true if @port is connected, false otherwise. |
| 1050 | */ |
| 1051 | bool ibx_digital_port_connected(struct drm_i915_private *dev_priv, |
| 1052 | struct intel_digital_port *port) |
| 1053 | { |
| 1054 | u32 bit; |
| 1055 | |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1056 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1057 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1058 | case PORT_B: |
| 1059 | bit = SDE_PORTB_HOTPLUG; |
| 1060 | break; |
| 1061 | case PORT_C: |
| 1062 | bit = SDE_PORTC_HOTPLUG; |
| 1063 | break; |
| 1064 | case PORT_D: |
| 1065 | bit = SDE_PORTD_HOTPLUG; |
| 1066 | break; |
| 1067 | default: |
| 1068 | return true; |
| 1069 | } |
| 1070 | } else { |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 1071 | switch (port->port) { |
Damien Lespiau | c36346e | 2012-12-13 16:09:03 +0000 | [diff] [blame] | 1072 | case PORT_B: |
| 1073 | bit = SDE_PORTB_HOTPLUG_CPT; |
| 1074 | break; |
| 1075 | case PORT_C: |
| 1076 | bit = SDE_PORTC_HOTPLUG_CPT; |
| 1077 | break; |
| 1078 | case PORT_D: |
| 1079 | bit = SDE_PORTD_HOTPLUG_CPT; |
| 1080 | break; |
| 1081 | default: |
| 1082 | return true; |
| 1083 | } |
Damien Lespiau | b0ea7d3 | 2012-12-13 16:09:00 +0000 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | return I915_READ(SDEISR) & bit; |
| 1087 | } |
| 1088 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1089 | static const char *state_string(bool enabled) |
| 1090 | { |
| 1091 | return enabled ? "on" : "off"; |
| 1092 | } |
| 1093 | |
| 1094 | /* Only for pre-ILK configs */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1095 | void assert_pll(struct drm_i915_private *dev_priv, |
| 1096 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1097 | { |
| 1098 | int reg; |
| 1099 | u32 val; |
| 1100 | bool cur_state; |
| 1101 | |
| 1102 | reg = DPLL(pipe); |
| 1103 | val = I915_READ(reg); |
| 1104 | cur_state = !!(val & DPLL_VCO_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1105 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1106 | "PLL state assertion failure (expected %s, current %s)\n", |
| 1107 | state_string(state), state_string(cur_state)); |
| 1108 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1109 | |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1110 | /* XXX: the dsi pll is shared between MIPI DSI ports */ |
| 1111 | static void assert_dsi_pll(struct drm_i915_private *dev_priv, bool state) |
| 1112 | { |
| 1113 | u32 val; |
| 1114 | bool cur_state; |
| 1115 | |
| 1116 | mutex_lock(&dev_priv->dpio_lock); |
| 1117 | val = vlv_cck_read(dev_priv, CCK_REG_DSI_PLL_CONTROL); |
| 1118 | mutex_unlock(&dev_priv->dpio_lock); |
| 1119 | |
| 1120 | cur_state = val & DSI_PLL_VCO_EN; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1121 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 1122 | "DSI PLL state assertion failure (expected %s, current %s)\n", |
| 1123 | state_string(state), state_string(cur_state)); |
| 1124 | } |
| 1125 | #define assert_dsi_pll_enabled(d) assert_dsi_pll(d, true) |
| 1126 | #define assert_dsi_pll_disabled(d) assert_dsi_pll(d, false) |
| 1127 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1128 | struct intel_shared_dpll * |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1129 | intel_crtc_to_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1130 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1131 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 1132 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1133 | if (crtc->config->shared_dpll < 0) |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1134 | return NULL; |
| 1135 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1136 | return &dev_priv->shared_dplls[crtc->config->shared_dpll]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1137 | } |
| 1138 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1139 | /* For ILK+ */ |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1140 | void assert_shared_dpll(struct drm_i915_private *dev_priv, |
| 1141 | struct intel_shared_dpll *pll, |
| 1142 | bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1143 | { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1144 | bool cur_state; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1145 | struct intel_dpll_hw_state hw_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1146 | |
Chris Wilson | 92b27b0 | 2012-05-20 18:10:50 +0100 | [diff] [blame] | 1147 | if (WARN (!pll, |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1148 | "asserting DPLL %s with no DPLL\n", state_string(state))) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1149 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1150 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1151 | cur_state = pll->get_hw_state(dev_priv, pll, &hw_state); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1152 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 1153 | "%s assertion failure (expected %s, current %s)\n", |
| 1154 | pll->name, state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1155 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1156 | |
| 1157 | static void assert_fdi_tx(struct drm_i915_private *dev_priv, |
| 1158 | enum pipe pipe, bool state) |
| 1159 | { |
| 1160 | int reg; |
| 1161 | u32 val; |
| 1162 | bool cur_state; |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1163 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1164 | pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1165 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1166 | if (HAS_DDI(dev_priv->dev)) { |
| 1167 | /* DDI does not have a specific FDI_TX register */ |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1168 | reg = TRANS_DDI_FUNC_CTL(cpu_transcoder); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1169 | val = I915_READ(reg); |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 1170 | cur_state = !!(val & TRANS_DDI_FUNC_ENABLE); |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1171 | } else { |
| 1172 | reg = FDI_TX_CTL(pipe); |
| 1173 | val = I915_READ(reg); |
| 1174 | cur_state = !!(val & FDI_TX_ENABLE); |
| 1175 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1176 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1177 | "FDI TX state assertion failure (expected %s, current %s)\n", |
| 1178 | state_string(state), state_string(cur_state)); |
| 1179 | } |
| 1180 | #define assert_fdi_tx_enabled(d, p) assert_fdi_tx(d, p, true) |
| 1181 | #define assert_fdi_tx_disabled(d, p) assert_fdi_tx(d, p, false) |
| 1182 | |
| 1183 | static void assert_fdi_rx(struct drm_i915_private *dev_priv, |
| 1184 | enum pipe pipe, bool state) |
| 1185 | { |
| 1186 | int reg; |
| 1187 | u32 val; |
| 1188 | bool cur_state; |
| 1189 | |
Paulo Zanoni | d63fa0d | 2012-11-20 13:27:35 -0200 | [diff] [blame] | 1190 | reg = FDI_RX_CTL(pipe); |
| 1191 | val = I915_READ(reg); |
| 1192 | cur_state = !!(val & FDI_RX_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1193 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1194 | "FDI RX state assertion failure (expected %s, current %s)\n", |
| 1195 | state_string(state), state_string(cur_state)); |
| 1196 | } |
| 1197 | #define assert_fdi_rx_enabled(d, p) assert_fdi_rx(d, p, true) |
| 1198 | #define assert_fdi_rx_disabled(d, p) assert_fdi_rx(d, p, false) |
| 1199 | |
| 1200 | static void assert_fdi_tx_pll_enabled(struct drm_i915_private *dev_priv, |
| 1201 | enum pipe pipe) |
| 1202 | { |
| 1203 | int reg; |
| 1204 | u32 val; |
| 1205 | |
| 1206 | /* ILK FDI PLL is always enabled */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1207 | if (INTEL_INFO(dev_priv->dev)->gen == 5) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1208 | return; |
| 1209 | |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1210 | /* On Haswell, DDI ports are responsible for the FDI PLL setup */ |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 1211 | if (HAS_DDI(dev_priv->dev)) |
Eugeni Dodonov | bf507ef | 2012-05-09 15:37:18 -0300 | [diff] [blame] | 1212 | return; |
| 1213 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1214 | reg = FDI_TX_CTL(pipe); |
| 1215 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1216 | 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] | 1217 | } |
| 1218 | |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1219 | void assert_fdi_rx_pll(struct drm_i915_private *dev_priv, |
| 1220 | enum pipe pipe, bool state) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1221 | { |
| 1222 | int reg; |
| 1223 | u32 val; |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1224 | bool cur_state; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1225 | |
| 1226 | reg = FDI_RX_CTL(pipe); |
| 1227 | val = I915_READ(reg); |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1228 | cur_state = !!(val & FDI_RX_PLL_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1229 | I915_STATE_WARN(cur_state != state, |
Daniel Vetter | 55607e8 | 2013-06-16 21:42:39 +0200 | [diff] [blame] | 1230 | "FDI RX PLL assertion failure (expected %s, current %s)\n", |
| 1231 | state_string(state), state_string(cur_state)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1232 | } |
| 1233 | |
Daniel Vetter | b680c37 | 2014-09-19 18:27:27 +0200 | [diff] [blame] | 1234 | void assert_panel_unlocked(struct drm_i915_private *dev_priv, |
| 1235 | enum pipe pipe) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1236 | { |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1237 | struct drm_device *dev = dev_priv->dev; |
| 1238 | int pp_reg; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1239 | u32 val; |
| 1240 | enum pipe panel_pipe = PIPE_A; |
Thomas Jarosch | 0de3b48 | 2011-08-25 15:37:45 +0200 | [diff] [blame] | 1241 | bool locked = true; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1242 | |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1243 | if (WARN_ON(HAS_DDI(dev))) |
| 1244 | return; |
| 1245 | |
| 1246 | if (HAS_PCH_SPLIT(dev)) { |
| 1247 | u32 port_sel; |
| 1248 | |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1249 | pp_reg = PCH_PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1250 | port_sel = I915_READ(PCH_PP_ON_DELAYS) & PANEL_PORT_SELECT_MASK; |
| 1251 | |
| 1252 | if (port_sel == PANEL_PORT_SELECT_LVDS && |
| 1253 | I915_READ(PCH_LVDS) & LVDS_PIPEB_SELECT) |
| 1254 | panel_pipe = PIPE_B; |
| 1255 | /* XXX: else fix for eDP */ |
| 1256 | } else if (IS_VALLEYVIEW(dev)) { |
| 1257 | /* presumably write lock depends on pipe, not port select */ |
| 1258 | pp_reg = VLV_PIPE_PP_CONTROL(pipe); |
| 1259 | panel_pipe = pipe; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1260 | } else { |
| 1261 | pp_reg = PP_CONTROL; |
Jani Nikula | bedd4db | 2014-08-22 15:04:13 +0300 | [diff] [blame] | 1262 | if (I915_READ(LVDS) & LVDS_PIPEB_SELECT) |
| 1263 | panel_pipe = PIPE_B; |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | val = I915_READ(pp_reg); |
| 1267 | if (!(val & PANEL_POWER_ON) || |
Jani Nikula | ec49ba2 | 2014-08-21 15:06:25 +0300 | [diff] [blame] | 1268 | ((val & PANEL_UNLOCK_MASK) == PANEL_UNLOCK_REGS)) |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1269 | locked = false; |
| 1270 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1271 | I915_STATE_WARN(panel_pipe == pipe && locked, |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1272 | "panel assertion failure, pipe %c regs locked\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1273 | pipe_name(pipe)); |
Jesse Barnes | ea0760c | 2011-01-04 15:09:32 -0800 | [diff] [blame] | 1274 | } |
| 1275 | |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1276 | static void assert_cursor(struct drm_i915_private *dev_priv, |
| 1277 | enum pipe pipe, bool state) |
| 1278 | { |
| 1279 | struct drm_device *dev = dev_priv->dev; |
| 1280 | bool cur_state; |
| 1281 | |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1282 | if (IS_845G(dev) || IS_I865G(dev)) |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1283 | cur_state = I915_READ(_CURACNTR) & CURSOR_ENABLE; |
Paulo Zanoni | d9d8208 | 2014-02-27 16:30:56 -0300 | [diff] [blame] | 1284 | else |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 1285 | cur_state = I915_READ(CURCNTR(pipe)) & CURSOR_MODE; |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1286 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1287 | I915_STATE_WARN(cur_state != state, |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 1288 | "cursor on pipe %c assertion failure (expected %s, current %s)\n", |
| 1289 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
| 1290 | } |
| 1291 | #define assert_cursor_enabled(d, p) assert_cursor(d, p, true) |
| 1292 | #define assert_cursor_disabled(d, p) assert_cursor(d, p, false) |
| 1293 | |
Jesse Barnes | b840d907f | 2011-12-13 13:19:38 -0800 | [diff] [blame] | 1294 | void assert_pipe(struct drm_i915_private *dev_priv, |
| 1295 | enum pipe pipe, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1296 | { |
| 1297 | int reg; |
| 1298 | u32 val; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1299 | bool cur_state; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 1300 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 1301 | pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1302 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1303 | /* if we need the pipe quirk it must be always on */ |
| 1304 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1305 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | 8e63678 | 2012-01-22 01:36:48 +0100 | [diff] [blame] | 1306 | state = true; |
| 1307 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 1308 | if (!intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | b97186f | 2013-05-03 12:15:36 -0300 | [diff] [blame] | 1309 | POWER_DOMAIN_TRANSCODER(cpu_transcoder))) { |
Paulo Zanoni | 6931016 | 2013-01-29 16:35:19 -0200 | [diff] [blame] | 1310 | cur_state = false; |
| 1311 | } else { |
| 1312 | reg = PIPECONF(cpu_transcoder); |
| 1313 | val = I915_READ(reg); |
| 1314 | cur_state = !!(val & PIPECONF_ENABLE); |
| 1315 | } |
| 1316 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1317 | I915_STATE_WARN(cur_state != state, |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1318 | "pipe %c assertion failure (expected %s, current %s)\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1319 | pipe_name(pipe), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1320 | } |
| 1321 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1322 | static void assert_plane(struct drm_i915_private *dev_priv, |
| 1323 | enum plane plane, bool state) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1324 | { |
| 1325 | int reg; |
| 1326 | u32 val; |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1327 | bool cur_state; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1328 | |
| 1329 | reg = DSPCNTR(plane); |
| 1330 | val = I915_READ(reg); |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1331 | cur_state = !!(val & DISPLAY_PLANE_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1332 | I915_STATE_WARN(cur_state != state, |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1333 | "plane %c assertion failure (expected %s, current %s)\n", |
| 1334 | plane_name(plane), state_string(state), state_string(cur_state)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1335 | } |
| 1336 | |
Chris Wilson | 931872f | 2012-01-16 23:01:13 +0000 | [diff] [blame] | 1337 | #define assert_plane_enabled(d, p) assert_plane(d, p, true) |
| 1338 | #define assert_plane_disabled(d, p) assert_plane(d, p, false) |
| 1339 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1340 | static void assert_planes_disabled(struct drm_i915_private *dev_priv, |
| 1341 | enum pipe pipe) |
| 1342 | { |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1343 | struct drm_device *dev = dev_priv->dev; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1344 | int reg, i; |
| 1345 | u32 val; |
| 1346 | int cur_pipe; |
| 1347 | |
Ville Syrjälä | 653e102 | 2013-06-04 13:49:05 +0300 | [diff] [blame] | 1348 | /* Primary planes are fixed to pipes on gen4+ */ |
| 1349 | if (INTEL_INFO(dev)->gen >= 4) { |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1350 | reg = DSPCNTR(pipe); |
| 1351 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1352 | I915_STATE_WARN(val & DISPLAY_PLANE_ENABLE, |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1353 | "plane %c assertion failure, should be disabled but not\n", |
| 1354 | plane_name(pipe)); |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1355 | return; |
Adam Jackson | 28c05794 | 2011-10-07 14:38:42 -0400 | [diff] [blame] | 1356 | } |
Jesse Barnes | 19ec135 | 2011-02-02 12:28:02 -0800 | [diff] [blame] | 1357 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1358 | /* Need to check both planes against the pipe */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 1359 | for_each_pipe(dev_priv, i) { |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1360 | reg = DSPCNTR(i); |
| 1361 | val = I915_READ(reg); |
| 1362 | cur_pipe = (val & DISPPLANE_SEL_PIPE_MASK) >> |
| 1363 | DISPPLANE_SEL_PIPE_SHIFT; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1364 | I915_STATE_WARN((val & DISPLAY_PLANE_ENABLE) && pipe == cur_pipe, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1365 | "plane %c assertion failure, should be off on pipe %c but is still active\n", |
| 1366 | plane_name(i), pipe_name(pipe)); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 1367 | } |
| 1368 | } |
| 1369 | |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1370 | static void assert_sprites_disabled(struct drm_i915_private *dev_priv, |
| 1371 | enum pipe pipe) |
| 1372 | { |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1373 | struct drm_device *dev = dev_priv->dev; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1374 | int reg, sprite; |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1375 | u32 val; |
| 1376 | |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1377 | if (INTEL_INFO(dev)->gen >= 9) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1378 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1379 | val = I915_READ(PLANE_CTL(pipe, sprite)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1380 | I915_STATE_WARN(val & PLANE_CTL_ENABLE, |
Damien Lespiau | 7feb8b8 | 2014-03-12 21:05:38 +0000 | [diff] [blame] | 1381 | "plane %d assertion failure, should be off on pipe %c but is still active\n", |
| 1382 | sprite, pipe_name(pipe)); |
| 1383 | } |
| 1384 | } else if (IS_VALLEYVIEW(dev)) { |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 1385 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 1386 | reg = SPCNTR(pipe, sprite); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1387 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1388 | I915_STATE_WARN(val & SP_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1389 | "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] | 1390 | sprite_name(pipe, sprite), pipe_name(pipe)); |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1391 | } |
| 1392 | } else if (INTEL_INFO(dev)->gen >= 7) { |
| 1393 | reg = SPRCTL(pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1394 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1395 | I915_STATE_WARN(val & SPRITE_ENABLE, |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 1396 | "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] | 1397 | plane_name(pipe), pipe_name(pipe)); |
| 1398 | } else if (INTEL_INFO(dev)->gen >= 5) { |
| 1399 | reg = DVSCNTR(pipe); |
| 1400 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1401 | I915_STATE_WARN(val & DVS_ENABLE, |
Ville Syrjälä | 20674ee | 2013-06-04 13:49:06 +0300 | [diff] [blame] | 1402 | "sprite %c assertion failure, should be off on pipe %c but is still active\n", |
| 1403 | plane_name(pipe), pipe_name(pipe)); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 1404 | } |
| 1405 | } |
| 1406 | |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1407 | static void assert_vblank_disabled(struct drm_crtc *crtc) |
| 1408 | { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1409 | if (I915_STATE_WARN_ON(drm_crtc_vblank_get(crtc) == 0)) |
Ville Syrjälä | 08c71e5 | 2014-08-06 14:49:45 +0300 | [diff] [blame] | 1410 | drm_crtc_vblank_put(crtc); |
| 1411 | } |
| 1412 | |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 1413 | 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] | 1414 | { |
| 1415 | u32 val; |
| 1416 | bool enabled; |
| 1417 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1418 | 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] | 1419 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1420 | val = I915_READ(PCH_DREF_CONTROL); |
| 1421 | enabled = !!(val & (DREF_SSC_SOURCE_MASK | DREF_NONSPREAD_SOURCE_MASK | |
| 1422 | DREF_SUPERSPREAD_SOURCE_MASK)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1423 | 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] | 1424 | } |
| 1425 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1426 | static void assert_pch_transcoder_disabled(struct drm_i915_private *dev_priv, |
| 1427 | enum pipe pipe) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1428 | { |
| 1429 | int reg; |
| 1430 | u32 val; |
| 1431 | bool enabled; |
| 1432 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1433 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1434 | val = I915_READ(reg); |
| 1435 | enabled = !!(val & TRANS_ENABLE); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1436 | I915_STATE_WARN(enabled, |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1437 | "transcoder assertion failed, should be off on pipe %c but is still active\n", |
| 1438 | pipe_name(pipe)); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1439 | } |
| 1440 | |
Keith Packard | 4e63438 | 2011-08-06 10:39:45 -0700 | [diff] [blame] | 1441 | static bool dp_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1442 | enum pipe pipe, u32 port_sel, u32 val) |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1443 | { |
| 1444 | if ((val & DP_PORT_EN) == 0) |
| 1445 | return false; |
| 1446 | |
| 1447 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1448 | u32 trans_dp_ctl_reg = TRANS_DP_CTL(pipe); |
| 1449 | u32 trans_dp_ctl = I915_READ(trans_dp_ctl_reg); |
| 1450 | if ((trans_dp_ctl & TRANS_DP_PORT_SEL_MASK) != port_sel) |
| 1451 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1452 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1453 | if ((val & DP_PIPE_MASK_CHV) != DP_PIPE_SELECT_CHV(pipe)) |
| 1454 | return false; |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1455 | } else { |
| 1456 | if ((val & DP_PIPE_MASK) != (pipe << 30)) |
| 1457 | return false; |
| 1458 | } |
| 1459 | return true; |
| 1460 | } |
| 1461 | |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1462 | static bool hdmi_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1463 | enum pipe pipe, u32 val) |
| 1464 | { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1465 | if ((val & SDVO_ENABLE) == 0) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1466 | return false; |
| 1467 | |
| 1468 | if (HAS_PCH_CPT(dev_priv->dev)) { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1469 | if ((val & SDVO_PIPE_SEL_MASK_CPT) != SDVO_PIPE_SEL_CPT(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1470 | return false; |
Chon Ming Lee | 44f37d1 | 2014-04-09 13:28:21 +0300 | [diff] [blame] | 1471 | } else if (IS_CHERRYVIEW(dev_priv->dev)) { |
| 1472 | if ((val & SDVO_PIPE_SEL_MASK_CHV) != SDVO_PIPE_SEL_CHV(pipe)) |
| 1473 | return false; |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1474 | } else { |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 1475 | if ((val & SDVO_PIPE_SEL_MASK) != SDVO_PIPE_SEL(pipe)) |
Keith Packard | 1519b99 | 2011-08-06 10:35:34 -0700 | [diff] [blame] | 1476 | return false; |
| 1477 | } |
| 1478 | return true; |
| 1479 | } |
| 1480 | |
| 1481 | static bool lvds_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1482 | enum pipe pipe, u32 val) |
| 1483 | { |
| 1484 | if ((val & LVDS_PORT_EN) == 0) |
| 1485 | return false; |
| 1486 | |
| 1487 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1488 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1489 | return false; |
| 1490 | } else { |
| 1491 | if ((val & LVDS_PIPE_MASK) != LVDS_PIPE(pipe)) |
| 1492 | return false; |
| 1493 | } |
| 1494 | return true; |
| 1495 | } |
| 1496 | |
| 1497 | static bool adpa_pipe_enabled(struct drm_i915_private *dev_priv, |
| 1498 | enum pipe pipe, u32 val) |
| 1499 | { |
| 1500 | if ((val & ADPA_DAC_ENABLE) == 0) |
| 1501 | return false; |
| 1502 | if (HAS_PCH_CPT(dev_priv->dev)) { |
| 1503 | if ((val & PORT_TRANS_SEL_MASK) != PORT_TRANS_SEL_CPT(pipe)) |
| 1504 | return false; |
| 1505 | } else { |
| 1506 | if ((val & ADPA_PIPE_SELECT_MASK) != ADPA_PIPE_SELECT(pipe)) |
| 1507 | return false; |
| 1508 | } |
| 1509 | return true; |
| 1510 | } |
| 1511 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1512 | static void assert_pch_dp_disabled(struct drm_i915_private *dev_priv, |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1513 | enum pipe pipe, int reg, u32 port_sel) |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1514 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1515 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1516 | I915_STATE_WARN(dp_pipe_enabled(dev_priv, pipe, port_sel, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1517 | "PCH DP (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1518 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1519 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1520 | 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] | 1521 | && (val & DP_PIPEB_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1522 | "IBX PCH dp port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1523 | } |
| 1524 | |
| 1525 | static void assert_pch_hdmi_disabled(struct drm_i915_private *dev_priv, |
| 1526 | enum pipe pipe, int reg) |
| 1527 | { |
Jesse Barnes | 47a05ec | 2011-02-07 13:46:40 -0800 | [diff] [blame] | 1528 | u32 val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1529 | I915_STATE_WARN(hdmi_pipe_enabled(dev_priv, pipe, val), |
Adam Jackson | 23c99e7 | 2011-10-07 14:38:43 -0400 | [diff] [blame] | 1530 | "PCH HDMI (0x%08x) enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1531 | reg, pipe_name(pipe)); |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1532 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1533 | 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] | 1534 | && (val & SDVO_PIPE_B_SELECT), |
Daniel Vetter | de9a35a | 2012-06-05 11:03:40 +0200 | [diff] [blame] | 1535 | "IBX PCH hdmi port still using transcoder B\n"); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | static void assert_pch_ports_disabled(struct drm_i915_private *dev_priv, |
| 1539 | enum pipe pipe) |
| 1540 | { |
| 1541 | int reg; |
| 1542 | u32 val; |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1543 | |
Keith Packard | f0575e9 | 2011-07-25 22:12:43 -0700 | [diff] [blame] | 1544 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_B, TRANS_DP_PORT_SEL_B); |
| 1545 | assert_pch_dp_disabled(dev_priv, pipe, PCH_DP_C, TRANS_DP_PORT_SEL_C); |
| 1546 | 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] | 1547 | |
| 1548 | reg = PCH_ADPA; |
| 1549 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1550 | I915_STATE_WARN(adpa_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1551 | "PCH VGA enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1552 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1553 | |
| 1554 | reg = PCH_LVDS; |
| 1555 | val = I915_READ(reg); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 1556 | I915_STATE_WARN(lvds_pipe_enabled(dev_priv, pipe, val), |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1557 | "PCH LVDS enabled on transcoder %c, should be disabled\n", |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 1558 | pipe_name(pipe)); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1559 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 1560 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIB); |
| 1561 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMIC); |
| 1562 | assert_pch_hdmi_disabled(dev_priv, pipe, PCH_HDMID); |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 1563 | } |
| 1564 | |
Jesse Barnes | 40e9cf6 | 2013-10-03 11:35:46 -0700 | [diff] [blame] | 1565 | static void intel_init_dpio(struct drm_device *dev) |
| 1566 | { |
| 1567 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1568 | |
| 1569 | if (!IS_VALLEYVIEW(dev)) |
| 1570 | return; |
| 1571 | |
Chon Ming Lee | a09cadd | 2014-04-09 13:28:14 +0300 | [diff] [blame] | 1572 | /* |
| 1573 | * IOSF_PORT_DPIO is used for VLV x2 PHY (DP/HDMI B and C), |
| 1574 | * CHV x1 PHY (DP/HDMI D) |
| 1575 | * IOSF_PORT_DPIO_2 is used for CHV x2 PHY (DP/HDMI B and C) |
| 1576 | */ |
| 1577 | if (IS_CHERRYVIEW(dev)) { |
| 1578 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO_2; |
| 1579 | DPIO_PHY_IOSF_PORT(DPIO_PHY1) = IOSF_PORT_DPIO; |
| 1580 | } else { |
| 1581 | DPIO_PHY_IOSF_PORT(DPIO_PHY0) = IOSF_PORT_DPIO; |
| 1582 | } |
Jesse Barnes | 5382f5f35 | 2013-12-16 16:34:24 -0800 | [diff] [blame] | 1583 | } |
| 1584 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1585 | static void vlv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1586 | const struct intel_crtc_state *pipe_config) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1587 | { |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1588 | struct drm_device *dev = crtc->base.dev; |
| 1589 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1590 | int reg = DPLL(crtc->pipe); |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1591 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1592 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1593 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 1594 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1595 | /* No really, not for ILK+ */ |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1596 | BUG_ON(!IS_VALLEYVIEW(dev_priv->dev)); |
| 1597 | |
| 1598 | /* PLL is protected by panel, make sure we can write it */ |
Jani Nikula | 6a9e736 | 2014-08-22 15:06:35 +0300 | [diff] [blame] | 1599 | if (IS_MOBILE(dev_priv->dev)) |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1600 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1601 | |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1602 | I915_WRITE(reg, dpll); |
| 1603 | POSTING_READ(reg); |
| 1604 | udelay(150); |
| 1605 | |
| 1606 | if (wait_for(((I915_READ(reg) & DPLL_LOCK_VLV) == DPLL_LOCK_VLV), 1)) |
| 1607 | DRM_ERROR("DPLL %d failed to lock\n", crtc->pipe); |
| 1608 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1609 | 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] | 1610 | POSTING_READ(DPLL_MD(crtc->pipe)); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1611 | |
| 1612 | /* We do this three times for luck */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1613 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1614 | POSTING_READ(reg); |
| 1615 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1616 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1617 | POSTING_READ(reg); |
| 1618 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 426115c | 2013-07-11 22:13:42 +0200 | [diff] [blame] | 1619 | I915_WRITE(reg, dpll); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1620 | POSTING_READ(reg); |
| 1621 | udelay(150); /* wait for warmup */ |
| 1622 | } |
| 1623 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1624 | static void chv_enable_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 1625 | const struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1626 | { |
| 1627 | struct drm_device *dev = crtc->base.dev; |
| 1628 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1629 | int pipe = crtc->pipe; |
| 1630 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1631 | u32 tmp; |
| 1632 | |
| 1633 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 1634 | |
| 1635 | BUG_ON(!IS_CHERRYVIEW(dev_priv->dev)); |
| 1636 | |
| 1637 | mutex_lock(&dev_priv->dpio_lock); |
| 1638 | |
| 1639 | /* Enable back the 10bit clock to display controller */ |
| 1640 | tmp = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1641 | tmp |= DPIO_DCLKP_EN; |
| 1642 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), tmp); |
| 1643 | |
| 1644 | /* |
| 1645 | * Need to wait > 100ns between dclkp clock enable bit and PLL enable. |
| 1646 | */ |
| 1647 | udelay(1); |
| 1648 | |
| 1649 | /* Enable PLL */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1650 | I915_WRITE(DPLL(pipe), pipe_config->dpll_hw_state.dpll); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1651 | |
| 1652 | /* Check PLL is locked */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1653 | 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] | 1654 | DRM_ERROR("PLL %d failed to lock\n", pipe); |
| 1655 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1656 | /* not sure when this should be written */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 1657 | 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] | 1658 | POSTING_READ(DPLL_MD(pipe)); |
| 1659 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 1660 | mutex_unlock(&dev_priv->dpio_lock); |
| 1661 | } |
| 1662 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1663 | static int intel_num_dvo_pipes(struct drm_device *dev) |
| 1664 | { |
| 1665 | struct intel_crtc *crtc; |
| 1666 | int count = 0; |
| 1667 | |
| 1668 | for_each_intel_crtc(dev, crtc) |
| 1669 | count += crtc->active && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1670 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO); |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1671 | |
| 1672 | return count; |
| 1673 | } |
| 1674 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1675 | static void i9xx_enable_pll(struct intel_crtc *crtc) |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1676 | { |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1677 | struct drm_device *dev = crtc->base.dev; |
| 1678 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1679 | int reg = DPLL(crtc->pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1680 | u32 dpll = crtc->config->dpll_hw_state.dpll; |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1681 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1682 | assert_pipe_disabled(dev_priv, crtc->pipe); |
Daniel Vetter | 87442f7 | 2013-06-06 00:52:17 +0200 | [diff] [blame] | 1683 | |
| 1684 | /* No really, not for ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1685 | BUG_ON(INTEL_INFO(dev)->gen >= 5); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1686 | |
| 1687 | /* PLL is protected by panel, make sure we can write it */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1688 | if (IS_MOBILE(dev) && !IS_I830(dev)) |
| 1689 | assert_panel_unlocked(dev_priv, crtc->pipe); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1690 | |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1691 | /* Enable DVO 2x clock on both PLLs if necessary */ |
| 1692 | if (IS_I830(dev) && intel_num_dvo_pipes(dev) > 0) { |
| 1693 | /* |
| 1694 | * It appears to be important that we don't enable this |
| 1695 | * for the current pipe before otherwise configuring the |
| 1696 | * PLL. No idea how this should be handled if multiple |
| 1697 | * DVO outputs are enabled simultaneosly. |
| 1698 | */ |
| 1699 | dpll |= DPLL_DVO_2X_MODE; |
| 1700 | I915_WRITE(DPLL(!crtc->pipe), |
| 1701 | I915_READ(DPLL(!crtc->pipe)) | DPLL_DVO_2X_MODE); |
| 1702 | } |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1703 | |
| 1704 | /* Wait for the clocks to stabilize. */ |
| 1705 | POSTING_READ(reg); |
| 1706 | udelay(150); |
| 1707 | |
| 1708 | if (INTEL_INFO(dev)->gen >= 4) { |
| 1709 | I915_WRITE(DPLL_MD(crtc->pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 1710 | crtc->config->dpll_hw_state.dpll_md); |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1711 | } else { |
| 1712 | /* The pixel multiplier can only be updated once the |
| 1713 | * DPLL is enabled and the clocks are stable. |
| 1714 | * |
| 1715 | * So write it again. |
| 1716 | */ |
| 1717 | I915_WRITE(reg, dpll); |
| 1718 | } |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1719 | |
| 1720 | /* We do this three times for luck */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1721 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1722 | POSTING_READ(reg); |
| 1723 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1724 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1725 | POSTING_READ(reg); |
| 1726 | udelay(150); /* wait for warmup */ |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 1727 | I915_WRITE(reg, dpll); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1728 | POSTING_READ(reg); |
| 1729 | udelay(150); /* wait for warmup */ |
| 1730 | } |
| 1731 | |
| 1732 | /** |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1733 | * i9xx_disable_pll - disable a PLL |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1734 | * @dev_priv: i915 private structure |
| 1735 | * @pipe: pipe PLL to disable |
| 1736 | * |
| 1737 | * Disable the PLL for @pipe, making sure the pipe is off first. |
| 1738 | * |
| 1739 | * Note! This is for pre-ILK only. |
| 1740 | */ |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1741 | static void i9xx_disable_pll(struct intel_crtc *crtc) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1742 | { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1743 | struct drm_device *dev = crtc->base.dev; |
| 1744 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1745 | enum pipe pipe = crtc->pipe; |
| 1746 | |
| 1747 | /* Disable DVO 2x clock on both PLLs if necessary */ |
| 1748 | if (IS_I830(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1749 | intel_pipe_has_type(crtc, INTEL_OUTPUT_DVO) && |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 1750 | intel_num_dvo_pipes(dev) == 1) { |
| 1751 | I915_WRITE(DPLL(PIPE_B), |
| 1752 | I915_READ(DPLL(PIPE_B)) & ~DPLL_DVO_2X_MODE); |
| 1753 | I915_WRITE(DPLL(PIPE_A), |
| 1754 | I915_READ(DPLL(PIPE_A)) & ~DPLL_DVO_2X_MODE); |
| 1755 | } |
| 1756 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 1757 | /* Don't disable pipe or pipe PLLs if needed */ |
| 1758 | if ((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 1759 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1760 | return; |
| 1761 | |
| 1762 | /* Make sure the pipe isn't still relying on us */ |
| 1763 | assert_pipe_disabled(dev_priv, pipe); |
| 1764 | |
Daniel Vetter | 50b44a4 | 2013-06-05 13:34:33 +0200 | [diff] [blame] | 1765 | I915_WRITE(DPLL(pipe), 0); |
| 1766 | POSTING_READ(DPLL(pipe)); |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1767 | } |
| 1768 | |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1769 | static void vlv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1770 | { |
| 1771 | u32 val = 0; |
| 1772 | |
| 1773 | /* Make sure the pipe isn't still relying on us */ |
| 1774 | assert_pipe_disabled(dev_priv, pipe); |
| 1775 | |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1776 | /* |
| 1777 | * Leave integrated clock source and reference clock enabled for pipe B. |
| 1778 | * The latter is needed for VGA hotplug / manual detection. |
| 1779 | */ |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1780 | if (pipe == PIPE_B) |
Imre Deak | e5cbfbf | 2014-01-09 17:08:16 +0200 | [diff] [blame] | 1781 | val = DPLL_INTEGRATED_CRI_CLK_VLV | DPLL_REFA_CLK_ENABLE_VLV; |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1782 | I915_WRITE(DPLL(pipe), val); |
| 1783 | POSTING_READ(DPLL(pipe)); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1784 | |
| 1785 | } |
| 1786 | |
| 1787 | static void chv_disable_pll(struct drm_i915_private *dev_priv, enum pipe pipe) |
| 1788 | { |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1789 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1790 | u32 val; |
| 1791 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1792 | /* Make sure the pipe isn't still relying on us */ |
| 1793 | assert_pipe_disabled(dev_priv, pipe); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 1794 | |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1795 | /* Set PLL en = 0 */ |
Ville Syrjälä | d17ec4c | 2014-06-28 02:03:59 +0300 | [diff] [blame] | 1796 | val = DPLL_SSC_REF_CLOCK_CHV | DPLL_REFA_CLK_ENABLE_VLV; |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 1797 | if (pipe != PIPE_A) |
| 1798 | val |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 1799 | I915_WRITE(DPLL(pipe), val); |
| 1800 | POSTING_READ(DPLL(pipe)); |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1801 | |
| 1802 | mutex_lock(&dev_priv->dpio_lock); |
| 1803 | |
| 1804 | /* Disable 10bit clock to display controller */ |
| 1805 | val = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)); |
| 1806 | val &= ~DPIO_DCLKP_EN; |
| 1807 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), val); |
| 1808 | |
Ville Syrjälä | 61407f6 | 2014-05-27 16:32:55 +0300 | [diff] [blame] | 1809 | /* disable left/right clock distribution */ |
| 1810 | if (pipe != PIPE_B) { |
| 1811 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW5_CH0); |
| 1812 | val &= ~(CHV_BUFLEFTENA1_MASK | CHV_BUFRIGHTENA1_MASK); |
| 1813 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW5_CH0, val); |
| 1814 | } else { |
| 1815 | val = vlv_dpio_read(dev_priv, pipe, _CHV_CMN_DW1_CH1); |
| 1816 | val &= ~(CHV_BUFLEFTENA2_MASK | CHV_BUFRIGHTENA2_MASK); |
| 1817 | vlv_dpio_write(dev_priv, pipe, _CHV_CMN_DW1_CH1, val); |
| 1818 | } |
| 1819 | |
Ville Syrjälä | d752048 | 2014-04-09 13:28:59 +0300 | [diff] [blame] | 1820 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | f607116 | 2013-10-01 10:41:38 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1823 | void vlv_wait_port_ready(struct drm_i915_private *dev_priv, |
| 1824 | struct intel_digital_port *dport) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1825 | { |
| 1826 | u32 port_mask; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1827 | int dpll_reg; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1828 | |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1829 | switch (dport->port) { |
| 1830 | case PORT_B: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1831 | port_mask = DPLL_PORTB_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1832 | dpll_reg = DPLL(0); |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1833 | break; |
| 1834 | case PORT_C: |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1835 | port_mask = DPLL_PORTC_READY_MASK; |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1836 | dpll_reg = DPLL(0); |
| 1837 | break; |
| 1838 | case PORT_D: |
| 1839 | port_mask = DPLL_PORTD_READY_MASK; |
| 1840 | dpll_reg = DPIO_PHY_STATUS; |
Chon Ming Lee | e4607fc | 2013-11-06 14:36:35 +0800 | [diff] [blame] | 1841 | break; |
| 1842 | default: |
| 1843 | BUG(); |
| 1844 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1845 | |
Chon Ming Lee | 00fc31b | 2014-04-09 13:28:15 +0300 | [diff] [blame] | 1846 | if (wait_for((I915_READ(dpll_reg) & port_mask) == 0, 1000)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1847 | 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] | 1848 | port_name(dport->port), I915_READ(dpll_reg)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 1849 | } |
| 1850 | |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1851 | static void intel_prepare_shared_dpll(struct intel_crtc *crtc) |
| 1852 | { |
| 1853 | struct drm_device *dev = crtc->base.dev; |
| 1854 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 1855 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
| 1856 | |
Chris Wilson | be19f0f | 2014-05-28 16:16:42 +0100 | [diff] [blame] | 1857 | if (WARN_ON(pll == NULL)) |
| 1858 | return; |
| 1859 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1860 | WARN_ON(!pll->config.crtc_mask); |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 1861 | if (pll->active == 0) { |
| 1862 | DRM_DEBUG_DRIVER("setting up %s\n", pll->name); |
| 1863 | WARN_ON(pll->on); |
| 1864 | assert_shared_dpll_disabled(dev_priv, pll); |
| 1865 | |
| 1866 | pll->mode_set(dev_priv, pll); |
| 1867 | } |
| 1868 | } |
| 1869 | |
Jesse Barnes | 63d7bbe | 2011-01-04 15:09:33 -0800 | [diff] [blame] | 1870 | /** |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1871 | * intel_enable_shared_dpll - enable PCH PLL |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1872 | * @dev_priv: i915 private structure |
| 1873 | * @pipe: pipe PLL to enable |
| 1874 | * |
| 1875 | * The PCH PLL needs to be enabled before the PCH transcoder, since it |
| 1876 | * drives the transcoder clock. |
| 1877 | */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 1878 | static void intel_enable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1879 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1880 | struct drm_device *dev = crtc->base.dev; |
| 1881 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1882 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1883 | |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1884 | if (WARN_ON(pll == NULL)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1885 | return; |
| 1886 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1887 | if (WARN_ON(pll->config.crtc_mask == 0)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1888 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1889 | |
Damien Lespiau | 74dd692 | 2014-07-29 18:06:17 +0100 | [diff] [blame] | 1890 | 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] | 1891 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1892 | crtc->base.base.id); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1893 | |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1894 | if (pll->active++) { |
| 1895 | WARN_ON(!pll->on); |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1896 | assert_shared_dpll_enabled(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1897 | return; |
| 1898 | } |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1899 | WARN_ON(pll->on); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1900 | |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1901 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
| 1902 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1903 | DRM_DEBUG_KMS("enabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1904 | pll->enable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1905 | pll->on = true; |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1906 | } |
| 1907 | |
Damien Lespiau | f6daaec | 2014-08-09 23:00:56 +0100 | [diff] [blame] | 1908 | static void intel_disable_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1909 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1910 | struct drm_device *dev = crtc->base.dev; |
| 1911 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1912 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | 4c609cb | 2011-09-02 12:52:11 -0700 | [diff] [blame] | 1913 | |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1914 | /* PCH only available on ILK+ */ |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 1915 | BUG_ON(INTEL_INFO(dev)->gen < 5); |
Daniel Vetter | 87a875b | 2013-06-05 13:34:19 +0200 | [diff] [blame] | 1916 | if (WARN_ON(pll == NULL)) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1917 | return; |
| 1918 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 1919 | if (WARN_ON(pll->config.crtc_mask == 0)) |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1920 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1921 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1922 | DRM_DEBUG_KMS("disable %s (active %d, on? %d) for crtc %d\n", |
| 1923 | pll->name, pll->active, pll->on, |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1924 | crtc->base.base.id); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1925 | |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1926 | if (WARN_ON(pll->active == 0)) { |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1927 | assert_shared_dpll_disabled(dev_priv, pll); |
Chris Wilson | 48da64a | 2012-05-13 20:16:12 +0100 | [diff] [blame] | 1928 | return; |
| 1929 | } |
| 1930 | |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1931 | assert_shared_dpll_enabled(dev_priv, pll); |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 1932 | WARN_ON(!pll->on); |
Daniel Vetter | cdbd231 | 2013-06-05 13:34:03 +0200 | [diff] [blame] | 1933 | if (--pll->active) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1934 | return; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1935 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 1936 | DRM_DEBUG_KMS("disabling %s\n", pll->name); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 1937 | pll->disable(dev_priv, pll); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 1938 | pll->on = false; |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 1939 | |
| 1940 | intel_display_power_put(dev_priv, POWER_DOMAIN_PLLS); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 1941 | } |
| 1942 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 1943 | static void ironlake_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 1944 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1945 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1946 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1947 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 1948 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1949 | uint32_t reg, val, pipeconf_val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1950 | |
| 1951 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 1952 | BUG_ON(!HAS_PCH_SPLIT(dev)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1953 | |
| 1954 | /* Make sure PCH DPLL is enabled */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 1955 | assert_shared_dpll_enabled(dev_priv, |
Daniel Vetter | e9d6944 | 2013-06-05 13:34:15 +0200 | [diff] [blame] | 1956 | intel_crtc_to_shared_dpll(intel_crtc)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1957 | |
| 1958 | /* FDI must be feeding us bits for PCH ports */ |
| 1959 | assert_fdi_tx_enabled(dev_priv, pipe); |
| 1960 | assert_fdi_rx_enabled(dev_priv, pipe); |
| 1961 | |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1962 | if (HAS_PCH_CPT(dev)) { |
| 1963 | /* Workaround: Set the timing override bit before enabling the |
| 1964 | * pch transcoder. */ |
| 1965 | reg = TRANS_CHICKEN2(pipe); |
| 1966 | val = I915_READ(reg); |
| 1967 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 1968 | I915_WRITE(reg, val); |
Eugeni Dodonov | 59c859d | 2012-05-09 15:37:19 -0300 | [diff] [blame] | 1969 | } |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 1970 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 1971 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1972 | val = I915_READ(reg); |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1973 | pipeconf_val = I915_READ(PIPECONF(pipe)); |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1974 | |
| 1975 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 1976 | /* |
| 1977 | * make the BPC in transcoder be consistent with |
| 1978 | * that in pipeconf reg. |
| 1979 | */ |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 1980 | val &= ~PIPECONF_BPC_MASK; |
| 1981 | val |= pipeconf_val & PIPECONF_BPC_MASK; |
Jesse Barnes | e9bcff5 | 2011-06-24 12:19:20 -0700 | [diff] [blame] | 1982 | } |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1983 | |
| 1984 | val &= ~TRANS_INTERLACE_MASK; |
| 1985 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK) == PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1986 | if (HAS_PCH_IBX(dev_priv->dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 1987 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Paulo Zanoni | 7c26e5c | 2012-02-14 17:07:09 -0200 | [diff] [blame] | 1988 | val |= TRANS_LEGACY_INTERLACED_ILK; |
| 1989 | else |
| 1990 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 5f7f726 | 2012-02-03 17:47:15 -0200 | [diff] [blame] | 1991 | else |
| 1992 | val |= TRANS_PROGRESSIVE; |
| 1993 | |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1994 | I915_WRITE(reg, val | TRANS_ENABLE); |
| 1995 | if (wait_for(I915_READ(reg) & TRANS_STATE_ENABLE, 100)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 1996 | DRM_ERROR("failed to enable transcoder %c\n", pipe_name(pipe)); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 1997 | } |
| 1998 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 1999 | static void lpt_enable_pch_transcoder(struct drm_i915_private *dev_priv, |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2000 | enum transcoder cpu_transcoder) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2001 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2002 | u32 val, pipeconf_val; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2003 | |
| 2004 | /* PCH only available on ILK+ */ |
Ville Syrjälä | 55522f3 | 2014-09-03 14:09:53 +0300 | [diff] [blame] | 2005 | BUG_ON(!HAS_PCH_SPLIT(dev_priv->dev)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2006 | |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2007 | /* FDI must be feeding us bits for PCH ports */ |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2008 | assert_fdi_tx_enabled(dev_priv, (enum pipe) cpu_transcoder); |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2009 | assert_fdi_rx_enabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2010 | |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2011 | /* Workaround: set timing override bit. */ |
| 2012 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2013 | val |= TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2014 | I915_WRITE(_TRANSA_CHICKEN2, val); |
| 2015 | |
Paulo Zanoni | 25f3ef1 | 2012-10-31 18:12:49 -0200 | [diff] [blame] | 2016 | val = TRANS_ENABLE; |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2017 | pipeconf_val = I915_READ(PIPECONF(cpu_transcoder)); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2018 | |
Paulo Zanoni | 9a76b1c | 2012-10-31 18:12:48 -0200 | [diff] [blame] | 2019 | if ((pipeconf_val & PIPECONF_INTERLACE_MASK_HSW) == |
| 2020 | PIPECONF_INTERLACED_ILK) |
Paulo Zanoni | a35f267 | 2012-10-31 18:12:45 -0200 | [diff] [blame] | 2021 | val |= TRANS_INTERLACED; |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2022 | else |
| 2023 | val |= TRANS_PROGRESSIVE; |
| 2024 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2025 | I915_WRITE(LPT_TRANSCONF, val); |
| 2026 | if (wait_for(I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE, 100)) |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 2027 | DRM_ERROR("Failed to enable PCH transcoder\n"); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2028 | } |
| 2029 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 2030 | static void ironlake_disable_pch_transcoder(struct drm_i915_private *dev_priv, |
| 2031 | enum pipe pipe) |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2032 | { |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2033 | struct drm_device *dev = dev_priv->dev; |
| 2034 | uint32_t reg, val; |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2035 | |
| 2036 | /* FDI relies on the transcoder */ |
| 2037 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 2038 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 2039 | |
Jesse Barnes | 291906f | 2011-02-02 12:28:03 -0800 | [diff] [blame] | 2040 | /* Ports must be off as well */ |
| 2041 | assert_pch_ports_disabled(dev_priv, pipe); |
| 2042 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2043 | reg = PCH_TRANSCONF(pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2044 | val = I915_READ(reg); |
| 2045 | val &= ~TRANS_ENABLE; |
| 2046 | I915_WRITE(reg, val); |
| 2047 | /* wait for PCH transcoder off, transcoder state */ |
| 2048 | if (wait_for((I915_READ(reg) & TRANS_STATE_ENABLE) == 0, 50)) |
Ville Syrjälä | 4bb6f1f | 2013-04-17 17:48:50 +0300 | [diff] [blame] | 2049 | DRM_ERROR("failed to disable transcoder %c\n", pipe_name(pipe)); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2050 | |
| 2051 | if (!HAS_PCH_IBX(dev)) { |
| 2052 | /* Workaround: Clear the timing override chicken bit again. */ |
| 2053 | reg = TRANS_CHICKEN2(pipe); |
| 2054 | val = I915_READ(reg); |
| 2055 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
| 2056 | I915_WRITE(reg, val); |
| 2057 | } |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2058 | } |
| 2059 | |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 2060 | static void lpt_disable_pch_transcoder(struct drm_i915_private *dev_priv) |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2061 | { |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2062 | u32 val; |
| 2063 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2064 | val = I915_READ(LPT_TRANSCONF); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2065 | val &= ~TRANS_ENABLE; |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2066 | I915_WRITE(LPT_TRANSCONF, val); |
Paulo Zanoni | 8fb033d | 2012-10-31 18:12:43 -0200 | [diff] [blame] | 2067 | /* wait for PCH transcoder off, transcoder state */ |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 2068 | if (wait_for((I915_READ(LPT_TRANSCONF) & TRANS_STATE_ENABLE) == 0, 50)) |
Paulo Zanoni | 8a52fd9 | 2012-10-31 18:12:51 -0200 | [diff] [blame] | 2069 | DRM_ERROR("Failed to disable PCH transcoder\n"); |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2070 | |
| 2071 | /* Workaround: clear timing override bit. */ |
| 2072 | val = I915_READ(_TRANSA_CHICKEN2); |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 2073 | val &= ~TRANS_CHICKEN2_TIMING_OVERRIDE; |
Paulo Zanoni | 223a6fd | 2012-10-31 18:12:52 -0200 | [diff] [blame] | 2074 | I915_WRITE(_TRANSA_CHICKEN2, val); |
Jesse Barnes | 92f2584 | 2011-01-04 15:09:34 -0800 | [diff] [blame] | 2075 | } |
| 2076 | |
| 2077 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2078 | * intel_enable_pipe - enable a pipe, asserting requirements |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2079 | * @crtc: crtc responsible for the pipe |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2080 | * |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2081 | * Enable @crtc's pipe, making sure that various hardware specific requirements |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2082 | * are met, if applicable, e.g. PLL enabled, LVDS pairs enabled, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2083 | */ |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 2084 | static void intel_enable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2085 | { |
Paulo Zanoni | 0372264 | 2014-01-17 13:51:09 -0200 | [diff] [blame] | 2086 | struct drm_device *dev = crtc->base.dev; |
| 2087 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2088 | enum pipe pipe = crtc->pipe; |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2089 | enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv, |
| 2090 | pipe); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2091 | enum pipe pch_transcoder; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2092 | int reg; |
| 2093 | u32 val; |
| 2094 | |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2095 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2096 | assert_cursor_disabled(dev_priv, pipe); |
Daniel Vetter | 58c6eaa | 2013-04-11 16:29:09 +0200 | [diff] [blame] | 2097 | assert_sprites_disabled(dev_priv, pipe); |
| 2098 | |
Paulo Zanoni | 681e581 | 2012-12-06 11:12:38 -0200 | [diff] [blame] | 2099 | if (HAS_PCH_LPT(dev_priv->dev)) |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2100 | pch_transcoder = TRANSCODER_A; |
| 2101 | else |
| 2102 | pch_transcoder = pipe; |
| 2103 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2104 | /* |
| 2105 | * A pipe without a PLL won't actually be able to drive bits from |
| 2106 | * a plane. On ILK+ the pipe PLLs are integrated, so we don't |
| 2107 | * need the check. |
| 2108 | */ |
| 2109 | if (!HAS_PCH_SPLIT(dev_priv->dev)) |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 2110 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DSI)) |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 2111 | assert_dsi_pll_enabled(dev_priv); |
| 2112 | else |
| 2113 | assert_pll_enabled(dev_priv, pipe); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2114 | else { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2115 | if (crtc->config->has_pch_encoder) { |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2116 | /* if driving the PCH, we need FDI enabled */ |
Paulo Zanoni | cc391bb | 2012-11-20 13:27:37 -0200 | [diff] [blame] | 2117 | assert_fdi_rx_pll_enabled(dev_priv, pch_transcoder); |
Daniel Vetter | 1a240d4 | 2012-11-29 22:18:51 +0100 | [diff] [blame] | 2118 | assert_fdi_tx_pll_enabled(dev_priv, |
| 2119 | (enum pipe) cpu_transcoder); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 2120 | } |
| 2121 | /* FIXME: assert CPU port conditions for SNB+ */ |
| 2122 | } |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2123 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2124 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2125 | val = I915_READ(reg); |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2126 | if (val & PIPECONF_ENABLE) { |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2127 | WARN_ON(!((pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 2128 | (pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE))); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2129 | return; |
Paulo Zanoni | 7ad25d4 | 2014-01-17 13:51:13 -0200 | [diff] [blame] | 2130 | } |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2131 | |
| 2132 | I915_WRITE(reg, val | PIPECONF_ENABLE); |
Paulo Zanoni | 851855d | 2013-12-19 19:12:29 -0200 | [diff] [blame] | 2133 | POSTING_READ(reg); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2134 | } |
| 2135 | |
| 2136 | /** |
Chris Wilson | 309cfea | 2011-01-28 13:54:53 +0000 | [diff] [blame] | 2137 | * intel_disable_pipe - disable a pipe, asserting requirements |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2138 | * @crtc: crtc whose pipes is to be disabled |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2139 | * |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2140 | * Disable the pipe of @crtc, making sure that various hardware |
| 2141 | * specific requirements are met, if applicable, e.g. plane |
| 2142 | * disabled, panel fitter off, etc. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2143 | * |
| 2144 | * Will wait until the pipe has shut down before returning. |
| 2145 | */ |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2146 | static void intel_disable_pipe(struct intel_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2147 | { |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2148 | 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] | 2149 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 2150 | enum pipe pipe = crtc->pipe; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2151 | int reg; |
| 2152 | u32 val; |
| 2153 | |
| 2154 | /* |
| 2155 | * Make sure planes won't keep trying to pump pixels to us, |
| 2156 | * or we might hang the display. |
| 2157 | */ |
| 2158 | assert_planes_disabled(dev_priv, pipe); |
Jani Nikula | 93ce0ba | 2013-09-13 11:03:08 +0300 | [diff] [blame] | 2159 | assert_cursor_disabled(dev_priv, pipe); |
Jesse Barnes | 19332d7 | 2013-03-28 09:55:38 -0700 | [diff] [blame] | 2160 | assert_sprites_disabled(dev_priv, pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2161 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 2162 | reg = PIPECONF(cpu_transcoder); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2163 | val = I915_READ(reg); |
Chris Wilson | 00d70b1 | 2011-03-17 07:18:29 +0000 | [diff] [blame] | 2164 | if ((val & PIPECONF_ENABLE) == 0) |
| 2165 | return; |
| 2166 | |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2167 | /* |
| 2168 | * Double wide has implications for planes |
| 2169 | * so best keep it disabled when not needed. |
| 2170 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2171 | if (crtc->config->double_wide) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2172 | val &= ~PIPECONF_DOUBLE_WIDE; |
| 2173 | |
| 2174 | /* Don't disable pipe or pipe PLLs if needed */ |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 2175 | if (!(pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) && |
| 2176 | !(pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Ville Syrjälä | 67adc64 | 2014-08-15 01:21:57 +0300 | [diff] [blame] | 2177 | val &= ~PIPECONF_ENABLE; |
| 2178 | |
| 2179 | I915_WRITE(reg, val); |
| 2180 | if ((val & PIPECONF_ENABLE) == 0) |
| 2181 | intel_wait_for_pipe_off(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2182 | } |
| 2183 | |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2184 | /* |
| 2185 | * Plane regs are double buffered, going from enabled->disabled needs a |
| 2186 | * trigger in order to latch. The display address reg provides this. |
| 2187 | */ |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2188 | void intel_flush_primary_plane(struct drm_i915_private *dev_priv, |
| 2189 | enum plane plane) |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2190 | { |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 2191 | struct drm_device *dev = dev_priv->dev; |
| 2192 | u32 reg = INTEL_INFO(dev)->gen >= 4 ? DSPSURF(plane) : DSPADDR(plane); |
Ville Syrjälä | 1dba99f | 2013-10-01 18:02:18 +0300 | [diff] [blame] | 2193 | |
| 2194 | I915_WRITE(reg, I915_READ(reg)); |
| 2195 | POSTING_READ(reg); |
Keith Packard | d74362c | 2011-07-28 14:47:14 -0700 | [diff] [blame] | 2196 | } |
| 2197 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2198 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2199 | * intel_enable_primary_hw_plane - enable the primary plane on a given pipe |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2200 | * @plane: plane to be enabled |
| 2201 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2202 | * |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2203 | * Enable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2204 | */ |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2205 | static void intel_enable_primary_hw_plane(struct drm_plane *plane, |
| 2206 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2207 | { |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2208 | struct drm_device *dev = plane->dev; |
| 2209 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2210 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2211 | |
| 2212 | /* If the pipe isn't enabled, we can't pump pixels and may hang */ |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2213 | assert_pipe_enabled(dev_priv, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2214 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2215 | if (intel_crtc->primary_enabled) |
| 2216 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2217 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2218 | intel_crtc->primary_enabled = true; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2219 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2220 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2221 | crtc->x, crtc->y); |
Ville Syrjälä | 33c3b0d | 2014-06-24 13:59:28 +0300 | [diff] [blame] | 2222 | |
| 2223 | /* |
| 2224 | * BDW signals flip done immediately if the plane |
| 2225 | * is disabled, even if the plane enable is already |
| 2226 | * armed to occur at the next vblank :( |
| 2227 | */ |
| 2228 | if (IS_BROADWELL(dev)) |
| 2229 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2230 | } |
| 2231 | |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2232 | /** |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 2233 | * intel_disable_primary_hw_plane - disable the primary hardware plane |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2234 | * @plane: plane to be disabled |
| 2235 | * @crtc: crtc for the plane |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2236 | * |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2237 | * Disable @plane on @crtc, making sure that the pipe is running first. |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2238 | */ |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2239 | static void intel_disable_primary_hw_plane(struct drm_plane *plane, |
| 2240 | struct drm_crtc *crtc) |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2241 | { |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2242 | struct drm_device *dev = plane->dev; |
| 2243 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2244 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 2245 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 2246 | if (WARN_ON(!intel_crtc->active)) |
| 2247 | return; |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2248 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 2249 | if (!intel_crtc->primary_enabled) |
| 2250 | return; |
Ville Syrjälä | 0037f71 | 2013-10-01 18:02:20 +0300 | [diff] [blame] | 2251 | |
Ville Syrjälä | 4c445e0 | 2013-10-09 17:24:58 +0300 | [diff] [blame] | 2252 | intel_crtc->primary_enabled = false; |
Ville Syrjälä | 939c2fe | 2013-10-01 18:02:10 +0300 | [diff] [blame] | 2253 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2254 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 2255 | crtc->x, crtc->y); |
Jesse Barnes | b24e717 | 2011-01-04 15:09:30 -0800 | [diff] [blame] | 2256 | } |
| 2257 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2258 | static bool need_vtd_wa(struct drm_device *dev) |
| 2259 | { |
| 2260 | #ifdef CONFIG_INTEL_IOMMU |
| 2261 | if (INTEL_INFO(dev)->gen >= 6 && intel_iommu_gfx_mapped) |
| 2262 | return true; |
| 2263 | #endif |
| 2264 | return false; |
| 2265 | } |
| 2266 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2267 | unsigned int |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2268 | intel_tile_height(struct drm_device *dev, uint32_t pixel_format, |
| 2269 | uint64_t fb_format_modifier) |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2270 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2271 | unsigned int tile_height; |
| 2272 | uint32_t pixel_bytes; |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2273 | |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2274 | switch (fb_format_modifier) { |
| 2275 | case DRM_FORMAT_MOD_NONE: |
| 2276 | tile_height = 1; |
| 2277 | break; |
| 2278 | case I915_FORMAT_MOD_X_TILED: |
| 2279 | tile_height = IS_GEN2(dev) ? 16 : 8; |
| 2280 | break; |
| 2281 | case I915_FORMAT_MOD_Y_TILED: |
| 2282 | tile_height = 32; |
| 2283 | break; |
| 2284 | case I915_FORMAT_MOD_Yf_TILED: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2285 | pixel_bytes = drm_format_plane_cpp(pixel_format, 0); |
| 2286 | switch (pixel_bytes) { |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2287 | default: |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2288 | case 1: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2289 | tile_height = 64; |
| 2290 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2291 | case 2: |
| 2292 | case 4: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2293 | tile_height = 32; |
| 2294 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2295 | case 8: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2296 | tile_height = 16; |
| 2297 | break; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2298 | case 16: |
Damien Lespiau | b5d0e9b | 2015-02-27 11:15:19 +0000 | [diff] [blame] | 2299 | WARN_ONCE(1, |
| 2300 | "128-bit pixels are not supported for display!"); |
| 2301 | tile_height = 16; |
| 2302 | break; |
| 2303 | } |
| 2304 | break; |
| 2305 | default: |
| 2306 | MISSING_CASE(fb_format_modifier); |
| 2307 | tile_height = 1; |
| 2308 | break; |
| 2309 | } |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 2310 | |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 2311 | return tile_height; |
| 2312 | } |
| 2313 | |
| 2314 | unsigned int |
| 2315 | intel_fb_align_height(struct drm_device *dev, unsigned int height, |
| 2316 | uint32_t pixel_format, uint64_t fb_format_modifier) |
| 2317 | { |
| 2318 | return ALIGN(height, intel_tile_height(dev, pixel_format, |
| 2319 | fb_format_modifier)); |
Jesse Barnes | a57ce0b | 2014-02-07 12:10:35 -0800 | [diff] [blame] | 2320 | } |
| 2321 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2322 | static int |
| 2323 | intel_fill_fb_ggtt_view(struct i915_ggtt_view *view, struct drm_framebuffer *fb, |
| 2324 | const struct drm_plane_state *plane_state) |
| 2325 | { |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2326 | struct intel_rotation_info *info = &view->rotation_info; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2327 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2328 | *view = i915_ggtt_view_normal; |
| 2329 | |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2330 | if (!plane_state) |
| 2331 | return 0; |
| 2332 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2333 | if (!intel_rotation_90_or_270(plane_state->rotation)) |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2334 | return 0; |
| 2335 | |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2336 | *view = i915_ggtt_view_rotated; |
Tvrtko Ursulin | 50470bb | 2015-03-23 11:10:36 +0000 | [diff] [blame] | 2337 | |
| 2338 | info->height = fb->height; |
| 2339 | info->pixel_format = fb->pixel_format; |
| 2340 | info->pitch = fb->pitches[0]; |
| 2341 | info->fb_modifier = fb->modifier[0]; |
| 2342 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2343 | return 0; |
| 2344 | } |
| 2345 | |
Chris Wilson | 127bd2a | 2010-07-23 23:32:05 +0100 | [diff] [blame] | 2346 | int |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2347 | intel_pin_and_fence_fb_obj(struct drm_plane *plane, |
| 2348 | struct drm_framebuffer *fb, |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2349 | const struct drm_plane_state *plane_state, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 2350 | struct intel_engine_cs *pipelined) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2351 | { |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2352 | struct drm_device *dev = fb->dev; |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2353 | struct drm_i915_private *dev_priv = dev->dev_private; |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 2354 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2355 | struct i915_ggtt_view view; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2356 | u32 alignment; |
| 2357 | int ret; |
| 2358 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2359 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 2360 | |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2361 | switch (fb->modifier[0]) { |
| 2362 | case DRM_FORMAT_MOD_NONE: |
Damien Lespiau | 1fada4c | 2013-07-03 21:06:02 +0100 | [diff] [blame] | 2363 | if (INTEL_INFO(dev)->gen >= 9) |
| 2364 | alignment = 256 * 1024; |
| 2365 | else if (IS_BROADWATER(dev) || IS_CRESTLINE(dev)) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2366 | alignment = 128 * 1024; |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2367 | else if (INTEL_INFO(dev)->gen >= 4) |
Chris Wilson | 534843d | 2010-07-05 18:01:46 +0100 | [diff] [blame] | 2368 | alignment = 4 * 1024; |
| 2369 | else |
| 2370 | alignment = 64 * 1024; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2371 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2372 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | 1fada4c | 2013-07-03 21:06:02 +0100 | [diff] [blame] | 2373 | if (INTEL_INFO(dev)->gen >= 9) |
| 2374 | alignment = 256 * 1024; |
| 2375 | else { |
| 2376 | /* pin() will align the object as required by fence */ |
| 2377 | alignment = 0; |
| 2378 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2379 | break; |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2380 | case I915_FORMAT_MOD_Y_TILED: |
Damien Lespiau | 1327b9a | 2015-02-27 11:15:20 +0000 | [diff] [blame] | 2381 | case I915_FORMAT_MOD_Yf_TILED: |
| 2382 | if (WARN_ONCE(INTEL_INFO(dev)->gen < 9, |
| 2383 | "Y tiling bo slipped through, driver bug!\n")) |
| 2384 | return -EINVAL; |
| 2385 | alignment = 1 * 1024 * 1024; |
| 2386 | break; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2387 | default: |
Tvrtko Ursulin | 7b911ad | 2015-02-10 17:16:15 +0000 | [diff] [blame] | 2388 | MISSING_CASE(fb->modifier[0]); |
| 2389 | return -EINVAL; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2390 | } |
| 2391 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2392 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
| 2393 | if (ret) |
| 2394 | return ret; |
| 2395 | |
Chris Wilson | 693db18 | 2013-03-05 14:52:39 +0000 | [diff] [blame] | 2396 | /* Note that the w/a also requires 64 PTE of padding following the |
| 2397 | * bo. We currently fill all unused PTE with the shadow page and so |
| 2398 | * we should always have valid PTE following the scanout preventing |
| 2399 | * the VT-d warning. |
| 2400 | */ |
| 2401 | if (need_vtd_wa(dev) && alignment < 256 * 1024) |
| 2402 | alignment = 256 * 1024; |
| 2403 | |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2404 | /* |
| 2405 | * Global gtt pte registers are special registers which actually forward |
| 2406 | * writes to a chunk of system memory. Which means that there is no risk |
| 2407 | * that the register values disappear as soon as we call |
| 2408 | * intel_runtime_pm_put(), so it is correct to wrap only the |
| 2409 | * pin/unpin/fence and not more. |
| 2410 | */ |
| 2411 | intel_runtime_pm_get(dev_priv); |
| 2412 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2413 | dev_priv->mm.interruptible = false; |
Tvrtko Ursulin | e661733 | 2015-03-23 11:10:33 +0000 | [diff] [blame] | 2414 | ret = i915_gem_object_pin_to_display_plane(obj, alignment, pipelined, |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2415 | &view); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2416 | if (ret) |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2417 | goto err_interruptible; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2418 | |
| 2419 | /* Install a fence for tiled scan-out. Pre-i965 always needs a |
| 2420 | * fence, whereas 965+ only requires a fence if using |
| 2421 | * framebuffer compression. For simplicity, we always install |
| 2422 | * a fence as the cost is not that onerous. |
| 2423 | */ |
Chris Wilson | 06d9813 | 2012-04-17 15:31:24 +0100 | [diff] [blame] | 2424 | ret = i915_gem_object_get_fence(obj); |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2425 | if (ret) |
| 2426 | goto err_unpin; |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2427 | |
Chris Wilson | 9a5a53b | 2012-03-22 15:10:00 +0000 | [diff] [blame] | 2428 | i915_gem_object_pin_fence(obj); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2429 | |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2430 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2431 | intel_runtime_pm_put(dev_priv); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2432 | return 0; |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2433 | |
| 2434 | err_unpin: |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2435 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | ce453d8 | 2011-02-21 14:43:56 +0000 | [diff] [blame] | 2436 | err_interruptible: |
| 2437 | dev_priv->mm.interruptible = true; |
Paulo Zanoni | d6dd684 | 2014-08-15 15:59:32 -0300 | [diff] [blame] | 2438 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | 48b956c | 2010-09-14 12:50:34 +0100 | [diff] [blame] | 2439 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 2440 | } |
| 2441 | |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2442 | static void intel_unpin_fb_obj(struct drm_framebuffer *fb, |
| 2443 | const struct drm_plane_state *plane_state) |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2444 | { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2445 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2446 | struct i915_ggtt_view view; |
| 2447 | int ret; |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 2448 | |
Matt Roper | ebcdd39 | 2014-07-09 16:22:11 -0700 | [diff] [blame] | 2449 | WARN_ON(!mutex_is_locked(&obj->base.dev->struct_mutex)); |
| 2450 | |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2451 | ret = intel_fill_fb_ggtt_view(&view, fb, plane_state); |
| 2452 | WARN_ONCE(ret, "Couldn't get view from plane state!"); |
| 2453 | |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2454 | i915_gem_object_unpin_fence(obj); |
Tvrtko Ursulin | f64b98c | 2015-03-23 11:10:35 +0000 | [diff] [blame] | 2455 | i915_gem_object_unpin_from_display_plane(obj, &view); |
Chris Wilson | 1690e1e | 2011-12-14 13:57:08 +0100 | [diff] [blame] | 2456 | } |
| 2457 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2458 | /* Computes the linear offset to the base tile and adjusts x, y. bytes per pixel |
| 2459 | * is assumed to be a power-of-two. */ |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2460 | unsigned long intel_gen4_compute_page_offset(int *x, int *y, |
| 2461 | unsigned int tiling_mode, |
| 2462 | unsigned int cpp, |
| 2463 | unsigned int pitch) |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2464 | { |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2465 | if (tiling_mode != I915_TILING_NONE) { |
| 2466 | unsigned int tile_rows, tiles; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2467 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2468 | tile_rows = *y / 8; |
| 2469 | *y %= 8; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2470 | |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2471 | tiles = *x / (512/cpp); |
| 2472 | *x %= 512/cpp; |
| 2473 | |
| 2474 | return tile_rows * pitch * 8 + tiles * 4096; |
| 2475 | } else { |
| 2476 | unsigned int offset; |
| 2477 | |
| 2478 | offset = *y * pitch + *x * cpp; |
| 2479 | *y = 0; |
| 2480 | *x = (offset & 4095) / cpp; |
| 2481 | return offset & -4096; |
| 2482 | } |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2483 | } |
| 2484 | |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 2485 | static int i9xx_format_to_fourcc(int format) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2486 | { |
| 2487 | switch (format) { |
| 2488 | case DISPPLANE_8BPP: |
| 2489 | return DRM_FORMAT_C8; |
| 2490 | case DISPPLANE_BGRX555: |
| 2491 | return DRM_FORMAT_XRGB1555; |
| 2492 | case DISPPLANE_BGRX565: |
| 2493 | return DRM_FORMAT_RGB565; |
| 2494 | default: |
| 2495 | case DISPPLANE_BGRX888: |
| 2496 | return DRM_FORMAT_XRGB8888; |
| 2497 | case DISPPLANE_RGBX888: |
| 2498 | return DRM_FORMAT_XBGR8888; |
| 2499 | case DISPPLANE_BGRX101010: |
| 2500 | return DRM_FORMAT_XRGB2101010; |
| 2501 | case DISPPLANE_RGBX101010: |
| 2502 | return DRM_FORMAT_XBGR2101010; |
| 2503 | } |
| 2504 | } |
| 2505 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 2506 | static int skl_format_to_fourcc(int format, bool rgb_order, bool alpha) |
| 2507 | { |
| 2508 | switch (format) { |
| 2509 | case PLANE_CTL_FORMAT_RGB_565: |
| 2510 | return DRM_FORMAT_RGB565; |
| 2511 | default: |
| 2512 | case PLANE_CTL_FORMAT_XRGB_8888: |
| 2513 | if (rgb_order) { |
| 2514 | if (alpha) |
| 2515 | return DRM_FORMAT_ABGR8888; |
| 2516 | else |
| 2517 | return DRM_FORMAT_XBGR8888; |
| 2518 | } else { |
| 2519 | if (alpha) |
| 2520 | return DRM_FORMAT_ARGB8888; |
| 2521 | else |
| 2522 | return DRM_FORMAT_XRGB8888; |
| 2523 | } |
| 2524 | case PLANE_CTL_FORMAT_XRGB_2101010: |
| 2525 | if (rgb_order) |
| 2526 | return DRM_FORMAT_XBGR2101010; |
| 2527 | else |
| 2528 | return DRM_FORMAT_XRGB2101010; |
| 2529 | } |
| 2530 | } |
| 2531 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2532 | static bool |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2533 | intel_alloc_initial_plane_obj(struct intel_crtc *crtc, |
| 2534 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2535 | { |
| 2536 | struct drm_device *dev = crtc->base.dev; |
| 2537 | struct drm_i915_gem_object *obj = NULL; |
| 2538 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2539 | struct drm_framebuffer *fb = &plane_config->fb->base; |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2540 | u32 base_aligned = round_down(plane_config->base, PAGE_SIZE); |
| 2541 | u32 size_aligned = round_up(plane_config->base + plane_config->size, |
| 2542 | PAGE_SIZE); |
| 2543 | |
| 2544 | size_aligned -= base_aligned; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2545 | |
Chris Wilson | ff2652e | 2014-03-10 08:07:02 +0000 | [diff] [blame] | 2546 | if (plane_config->size == 0) |
| 2547 | return false; |
| 2548 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 2549 | obj = i915_gem_object_create_stolen_for_preallocated(dev, |
| 2550 | base_aligned, |
| 2551 | base_aligned, |
| 2552 | size_aligned); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2553 | if (!obj) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2554 | return false; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2555 | |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 2556 | obj->tiling_mode = plane_config->tiling; |
| 2557 | if (obj->tiling_mode == I915_TILING_X) |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2558 | obj->stride = fb->pitches[0]; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2559 | |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2560 | mode_cmd.pixel_format = fb->pixel_format; |
| 2561 | mode_cmd.width = fb->width; |
| 2562 | mode_cmd.height = fb->height; |
| 2563 | mode_cmd.pitches[0] = fb->pitches[0]; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 2564 | mode_cmd.modifier[0] = fb->modifier[0]; |
| 2565 | mode_cmd.flags = DRM_MODE_FB_MODIFIERS; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2566 | |
| 2567 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 6bf129d | 2015-02-05 17:22:16 +0000 | [diff] [blame] | 2568 | if (intel_framebuffer_init(dev, to_intel_framebuffer(fb), |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2569 | &mode_cmd, obj)) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2570 | DRM_DEBUG_KMS("intel fb init failed\n"); |
| 2571 | goto out_unref_obj; |
| 2572 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2573 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2574 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2575 | DRM_DEBUG_KMS("initial plane fb obj %p\n", obj); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2576 | return true; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2577 | |
| 2578 | out_unref_obj: |
| 2579 | drm_gem_object_unreference(&obj->base); |
| 2580 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2581 | return false; |
| 2582 | } |
| 2583 | |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 2584 | /* Update plane->state->fb to match plane->fb after driver-internal updates */ |
| 2585 | static void |
| 2586 | update_state_fb(struct drm_plane *plane) |
| 2587 | { |
| 2588 | if (plane->fb == plane->state->fb) |
| 2589 | return; |
| 2590 | |
| 2591 | if (plane->state->fb) |
| 2592 | drm_framebuffer_unreference(plane->state->fb); |
| 2593 | plane->state->fb = plane->fb; |
| 2594 | if (plane->state->fb) |
| 2595 | drm_framebuffer_reference(plane->state->fb); |
| 2596 | } |
| 2597 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 2598 | static void |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2599 | intel_find_initial_plane_obj(struct intel_crtc *intel_crtc, |
| 2600 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2601 | { |
| 2602 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | d9ceb81 | 2014-10-09 12:57:43 -0700 | [diff] [blame] | 2603 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2604 | struct drm_crtc *c; |
| 2605 | struct intel_crtc *i; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2606 | struct drm_i915_gem_object *obj; |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2607 | struct drm_plane *primary = intel_crtc->base.primary; |
| 2608 | struct drm_framebuffer *fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2609 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2610 | if (!plane_config->fb) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2611 | return; |
| 2612 | |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 2613 | if (intel_alloc_initial_plane_obj(intel_crtc, plane_config)) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2614 | fb = &plane_config->fb->base; |
| 2615 | goto valid_fb; |
Damien Lespiau | f55548b | 2015-02-05 18:30:20 +0000 | [diff] [blame] | 2616 | } |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2617 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 2618 | kfree(plane_config->fb); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2619 | |
| 2620 | /* |
| 2621 | * Failed to alloc the obj, check to see if we should share |
| 2622 | * an fb with another CRTC instead |
| 2623 | */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 2624 | for_each_crtc(dev, c) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2625 | i = to_intel_crtc(c); |
| 2626 | |
| 2627 | if (c == &intel_crtc->base) |
| 2628 | continue; |
| 2629 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2630 | if (!i->active) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2631 | continue; |
| 2632 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2633 | fb = c->primary->fb; |
| 2634 | if (!fb) |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2635 | continue; |
| 2636 | |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2637 | obj = intel_fb_obj(fb); |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 2638 | if (i915_gem_obj_ggtt_offset(obj) == plane_config->base) { |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2639 | drm_framebuffer_reference(fb); |
| 2640 | goto valid_fb; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 2641 | } |
| 2642 | } |
Daniel Vetter | 88595ac | 2015-03-26 12:42:24 +0100 | [diff] [blame] | 2643 | |
| 2644 | return; |
| 2645 | |
| 2646 | valid_fb: |
| 2647 | obj = intel_fb_obj(fb); |
| 2648 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2649 | dev_priv->preserve_bios_swizzle = true; |
| 2650 | |
| 2651 | primary->fb = fb; |
| 2652 | primary->state->crtc = &intel_crtc->base; |
| 2653 | primary->crtc = &intel_crtc->base; |
| 2654 | update_state_fb(primary); |
| 2655 | obj->frontbuffer_bits |= INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 2656 | } |
| 2657 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2658 | static void i9xx_update_primary_plane(struct drm_crtc *crtc, |
| 2659 | struct drm_framebuffer *fb, |
| 2660 | int x, int y) |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2661 | { |
| 2662 | struct drm_device *dev = crtc->dev; |
| 2663 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2664 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2665 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2666 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2667 | unsigned long linear_offset; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2668 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2669 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2670 | int pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2671 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2672 | if (!intel_crtc->primary_enabled) { |
| 2673 | I915_WRITE(reg, 0); |
| 2674 | if (INTEL_INFO(dev)->gen >= 4) |
| 2675 | I915_WRITE(DSPSURF(plane), 0); |
| 2676 | else |
| 2677 | I915_WRITE(DSPADDR(plane), 0); |
| 2678 | POSTING_READ(reg); |
| 2679 | return; |
| 2680 | } |
| 2681 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2682 | obj = intel_fb_obj(fb); |
| 2683 | if (WARN_ON(obj == NULL)) |
| 2684 | return; |
| 2685 | |
| 2686 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2687 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2688 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2689 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2690 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2691 | |
| 2692 | if (INTEL_INFO(dev)->gen < 4) { |
| 2693 | if (intel_crtc->pipe == PIPE_B) |
| 2694 | dspcntr |= DISPPLANE_SEL_PIPE_B; |
| 2695 | |
| 2696 | /* pipesrc and dspsize control the size that is scaled from, |
| 2697 | * which should always be the user's requested size. |
| 2698 | */ |
| 2699 | I915_WRITE(DSPSIZE(plane), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2700 | ((intel_crtc->config->pipe_src_h - 1) << 16) | |
| 2701 | (intel_crtc->config->pipe_src_w - 1)); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2702 | I915_WRITE(DSPPOS(plane), 0); |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2703 | } else if (IS_CHERRYVIEW(dev) && plane == PLANE_B) { |
| 2704 | I915_WRITE(PRIMSIZE(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ä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 2707 | I915_WRITE(PRIMPOS(plane), 0); |
| 2708 | I915_WRITE(PRIMCNSTALPHA(plane), 0); |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2709 | } |
| 2710 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2711 | switch (fb->pixel_format) { |
| 2712 | case DRM_FORMAT_C8: |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2713 | dspcntr |= DISPPLANE_8BPP; |
| 2714 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2715 | case DRM_FORMAT_XRGB1555: |
| 2716 | case DRM_FORMAT_ARGB1555: |
| 2717 | dspcntr |= DISPPLANE_BGRX555; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2718 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2719 | case DRM_FORMAT_RGB565: |
| 2720 | dspcntr |= DISPPLANE_BGRX565; |
| 2721 | break; |
| 2722 | case DRM_FORMAT_XRGB8888: |
| 2723 | case DRM_FORMAT_ARGB8888: |
| 2724 | dspcntr |= DISPPLANE_BGRX888; |
| 2725 | break; |
| 2726 | case DRM_FORMAT_XBGR8888: |
| 2727 | case DRM_FORMAT_ABGR8888: |
| 2728 | dspcntr |= DISPPLANE_RGBX888; |
| 2729 | break; |
| 2730 | case DRM_FORMAT_XRGB2101010: |
| 2731 | case DRM_FORMAT_ARGB2101010: |
| 2732 | dspcntr |= DISPPLANE_BGRX101010; |
| 2733 | break; |
| 2734 | case DRM_FORMAT_XBGR2101010: |
| 2735 | case DRM_FORMAT_ABGR2101010: |
| 2736 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2737 | break; |
| 2738 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2739 | BUG(); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2740 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2741 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2742 | if (INTEL_INFO(dev)->gen >= 4 && |
| 2743 | obj->tiling_mode != I915_TILING_NONE) |
| 2744 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2745 | |
Ville Syrjälä | de1aa62 | 2013-06-07 10:47:01 +0300 | [diff] [blame] | 2746 | if (IS_G4X(dev)) |
| 2747 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
| 2748 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2749 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 2750 | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2751 | if (INTEL_INFO(dev)->gen >= 4) { |
| 2752 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2753 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2754 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2755 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2756 | linear_offset -= intel_crtc->dspaddr_offset; |
| 2757 | } else { |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2758 | intel_crtc->dspaddr_offset = linear_offset; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2759 | } |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2760 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2761 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2762 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2763 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2764 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2765 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2766 | |
| 2767 | /* Finding the last pixel of the last line of the display |
| 2768 | data and adding to linear_offset*/ |
| 2769 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2770 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2771 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | I915_WRITE(reg, dspcntr); |
| 2775 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2776 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 2777 | if (INTEL_INFO(dev)->gen >= 4) { |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2778 | I915_WRITE(DSPSURF(plane), |
| 2779 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2780 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2781 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2782 | } else |
Ben Widawsky | f343c5f | 2013-07-05 14:41:04 -0700 | [diff] [blame] | 2783 | I915_WRITE(DSPADDR(plane), i915_gem_obj_ggtt_offset(obj) + linear_offset); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 2784 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2785 | } |
| 2786 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 2787 | static void ironlake_update_primary_plane(struct drm_crtc *crtc, |
| 2788 | struct drm_framebuffer *fb, |
| 2789 | int x, int y) |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2790 | { |
| 2791 | struct drm_device *dev = crtc->dev; |
| 2792 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2793 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2794 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2795 | int plane = intel_crtc->plane; |
Daniel Vetter | e506a0c | 2012-07-05 12:17:29 +0200 | [diff] [blame] | 2796 | unsigned long linear_offset; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2797 | u32 dspcntr; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2798 | u32 reg = DSPCNTR(plane); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2799 | int pixel_size; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2800 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2801 | if (!intel_crtc->primary_enabled) { |
| 2802 | I915_WRITE(reg, 0); |
| 2803 | I915_WRITE(DSPSURF(plane), 0); |
| 2804 | POSTING_READ(reg); |
| 2805 | return; |
| 2806 | } |
| 2807 | |
Ville Syrjälä | c9ba6fa | 2014-08-27 17:48:41 +0300 | [diff] [blame] | 2808 | obj = intel_fb_obj(fb); |
| 2809 | if (WARN_ON(obj == NULL)) |
| 2810 | return; |
| 2811 | |
| 2812 | pixel_size = drm_format_plane_cpp(fb->pixel_format, 0); |
| 2813 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2814 | dspcntr = DISPPLANE_GAMMA_ENABLE; |
| 2815 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 2816 | dspcntr |= DISPLAY_PLANE_ENABLE; |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2817 | |
| 2818 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 2819 | dspcntr |= DISPPLANE_PIPE_CSC_ENABLE; |
| 2820 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2821 | switch (fb->pixel_format) { |
| 2822 | case DRM_FORMAT_C8: |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2823 | dspcntr |= DISPPLANE_8BPP; |
| 2824 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2825 | case DRM_FORMAT_RGB565: |
| 2826 | dspcntr |= DISPPLANE_BGRX565; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2827 | break; |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 2828 | case DRM_FORMAT_XRGB8888: |
| 2829 | case DRM_FORMAT_ARGB8888: |
| 2830 | dspcntr |= DISPPLANE_BGRX888; |
| 2831 | break; |
| 2832 | case DRM_FORMAT_XBGR8888: |
| 2833 | case DRM_FORMAT_ABGR8888: |
| 2834 | dspcntr |= DISPPLANE_RGBX888; |
| 2835 | break; |
| 2836 | case DRM_FORMAT_XRGB2101010: |
| 2837 | case DRM_FORMAT_ARGB2101010: |
| 2838 | dspcntr |= DISPPLANE_BGRX101010; |
| 2839 | break; |
| 2840 | case DRM_FORMAT_XBGR2101010: |
| 2841 | case DRM_FORMAT_ABGR2101010: |
| 2842 | dspcntr |= DISPPLANE_RGBX101010; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2843 | break; |
| 2844 | default: |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 2845 | BUG(); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2846 | } |
| 2847 | |
| 2848 | if (obj->tiling_mode != I915_TILING_NONE) |
| 2849 | dspcntr |= DISPPLANE_TILED; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2850 | |
Ville Syrjälä | f45651b | 2014-08-08 21:51:10 +0300 | [diff] [blame] | 2851 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) |
Paulo Zanoni | 1f5d76d | 2013-08-23 19:51:28 -0300 | [diff] [blame] | 2852 | dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2853 | |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2854 | linear_offset = y * fb->pitches[0] + x * pixel_size; |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2855 | intel_crtc->dspaddr_offset = |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2856 | intel_gen4_compute_page_offset(&x, &y, obj->tiling_mode, |
Ville Syrjälä | b9897127 | 2014-08-27 16:51:22 +0300 | [diff] [blame] | 2857 | pixel_size, |
Chris Wilson | bc75286 | 2013-02-21 20:04:31 +0000 | [diff] [blame] | 2858 | fb->pitches[0]); |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 2859 | linear_offset -= intel_crtc->dspaddr_offset; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 2860 | if (crtc->primary->state->rotation == BIT(DRM_ROTATE_180)) { |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2861 | dspcntr |= DISPPLANE_ROTATE_180; |
| 2862 | |
| 2863 | if (!IS_HASWELL(dev) && !IS_BROADWELL(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2864 | x += (intel_crtc->config->pipe_src_w - 1); |
| 2865 | y += (intel_crtc->config->pipe_src_h - 1); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2866 | |
| 2867 | /* Finding the last pixel of the last line of the display |
| 2868 | data and adding to linear_offset*/ |
| 2869 | linear_offset += |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 2870 | (intel_crtc->config->pipe_src_h - 1) * fb->pitches[0] + |
| 2871 | (intel_crtc->config->pipe_src_w - 1) * pixel_size; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 2872 | } |
| 2873 | } |
| 2874 | |
| 2875 | I915_WRITE(reg, dspcntr); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2876 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 2877 | I915_WRITE(DSPSTRIDE(plane), fb->pitches[0]); |
Daniel Vetter | 85ba7b7 | 2014-01-24 10:31:44 +0100 | [diff] [blame] | 2878 | I915_WRITE(DSPSURF(plane), |
| 2879 | i915_gem_obj_ggtt_offset(obj) + intel_crtc->dspaddr_offset); |
Paulo Zanoni | b3dc685 | 2013-11-02 21:07:33 -0700 | [diff] [blame] | 2880 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | bc1c91e | 2012-10-29 12:14:21 +0000 | [diff] [blame] | 2881 | I915_WRITE(DSPOFFSET(plane), (y << 16) | x); |
| 2882 | } else { |
| 2883 | I915_WRITE(DSPTILEOFF(plane), (y << 16) | x); |
| 2884 | I915_WRITE(DSPLINOFF(plane), linear_offset); |
| 2885 | } |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2886 | POSTING_READ(reg); |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 2887 | } |
| 2888 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2889 | u32 intel_fb_stride_alignment(struct drm_device *dev, uint64_t fb_modifier, |
| 2890 | uint32_t pixel_format) |
| 2891 | { |
| 2892 | u32 bits_per_pixel = drm_format_plane_cpp(pixel_format, 0) * 8; |
| 2893 | |
| 2894 | /* |
| 2895 | * The stride is either expressed as a multiple of 64 bytes |
| 2896 | * chunks for linear buffers or in number of tiles for tiled |
| 2897 | * buffers. |
| 2898 | */ |
| 2899 | switch (fb_modifier) { |
| 2900 | case DRM_FORMAT_MOD_NONE: |
| 2901 | return 64; |
| 2902 | case I915_FORMAT_MOD_X_TILED: |
| 2903 | if (INTEL_INFO(dev)->gen == 2) |
| 2904 | return 128; |
| 2905 | return 512; |
| 2906 | case I915_FORMAT_MOD_Y_TILED: |
| 2907 | /* No need to check for old gens and Y tiling since this is |
| 2908 | * about the display engine and those will be blocked before |
| 2909 | * we get here. |
| 2910 | */ |
| 2911 | return 128; |
| 2912 | case I915_FORMAT_MOD_Yf_TILED: |
| 2913 | if (bits_per_pixel == 8) |
| 2914 | return 64; |
| 2915 | else |
| 2916 | return 128; |
| 2917 | default: |
| 2918 | MISSING_CASE(fb_modifier); |
| 2919 | return 64; |
| 2920 | } |
| 2921 | } |
| 2922 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2923 | unsigned long intel_plane_obj_offset(struct intel_plane *intel_plane, |
| 2924 | struct drm_i915_gem_object *obj) |
| 2925 | { |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2926 | const struct i915_ggtt_view *view = &i915_ggtt_view_normal; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2927 | |
| 2928 | if (intel_rotation_90_or_270(intel_plane->base.state->rotation)) |
Joonas Lahtinen | 9abc464 | 2015-03-27 13:09:22 +0200 | [diff] [blame] | 2929 | view = &i915_ggtt_view_rotated; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2930 | |
| 2931 | return i915_gem_obj_ggtt_offset_view(obj, view); |
| 2932 | } |
| 2933 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2934 | static void skylake_update_primary_plane(struct drm_crtc *crtc, |
| 2935 | struct drm_framebuffer *fb, |
| 2936 | int x, int y) |
| 2937 | { |
| 2938 | struct drm_device *dev = crtc->dev; |
| 2939 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 2940 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2941 | struct drm_i915_gem_object *obj; |
| 2942 | int pipe = intel_crtc->pipe; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 2943 | u32 plane_ctl, stride_div, stride; |
| 2944 | u32 tile_height, plane_offset, plane_size; |
| 2945 | unsigned int rotation; |
| 2946 | int x_offset, y_offset; |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 2947 | unsigned long surf_addr; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 2948 | struct drm_plane *plane; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2949 | |
| 2950 | if (!intel_crtc->primary_enabled) { |
| 2951 | I915_WRITE(PLANE_CTL(pipe, 0), 0); |
| 2952 | I915_WRITE(PLANE_SURF(pipe, 0), 0); |
| 2953 | POSTING_READ(PLANE_CTL(pipe, 0)); |
| 2954 | return; |
| 2955 | } |
| 2956 | |
| 2957 | plane_ctl = PLANE_CTL_ENABLE | |
| 2958 | PLANE_CTL_PIPE_GAMMA_ENABLE | |
| 2959 | PLANE_CTL_PIPE_CSC_ENABLE; |
| 2960 | |
| 2961 | switch (fb->pixel_format) { |
| 2962 | case DRM_FORMAT_RGB565: |
| 2963 | plane_ctl |= PLANE_CTL_FORMAT_RGB_565; |
| 2964 | break; |
| 2965 | case DRM_FORMAT_XRGB8888: |
| 2966 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2967 | break; |
Jani Nikula | f75fb42 | 2015-02-10 13:15:49 +0200 | [diff] [blame] | 2968 | case DRM_FORMAT_ARGB8888: |
| 2969 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2970 | plane_ctl |= PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 2971 | break; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2972 | case DRM_FORMAT_XBGR8888: |
| 2973 | plane_ctl |= PLANE_CTL_ORDER_RGBX; |
| 2974 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2975 | break; |
Jani Nikula | f75fb42 | 2015-02-10 13:15:49 +0200 | [diff] [blame] | 2976 | case DRM_FORMAT_ABGR8888: |
| 2977 | plane_ctl |= PLANE_CTL_ORDER_RGBX; |
| 2978 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_8888; |
| 2979 | plane_ctl |= PLANE_CTL_ALPHA_SW_PREMULTIPLY; |
| 2980 | break; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2981 | case DRM_FORMAT_XRGB2101010: |
| 2982 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_2101010; |
| 2983 | break; |
| 2984 | case DRM_FORMAT_XBGR2101010: |
| 2985 | plane_ctl |= PLANE_CTL_ORDER_RGBX; |
| 2986 | plane_ctl |= PLANE_CTL_FORMAT_XRGB_2101010; |
| 2987 | break; |
| 2988 | default: |
| 2989 | BUG(); |
| 2990 | } |
| 2991 | |
Daniel Vetter | 30af77c | 2015-02-10 17:16:11 +0000 | [diff] [blame] | 2992 | switch (fb->modifier[0]) { |
| 2993 | case DRM_FORMAT_MOD_NONE: |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2994 | break; |
Daniel Vetter | 30af77c | 2015-02-10 17:16:11 +0000 | [diff] [blame] | 2995 | case I915_FORMAT_MOD_X_TILED: |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 2996 | plane_ctl |= PLANE_CTL_TILED_X; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 2997 | break; |
| 2998 | case I915_FORMAT_MOD_Y_TILED: |
| 2999 | plane_ctl |= PLANE_CTL_TILED_Y; |
| 3000 | break; |
| 3001 | case I915_FORMAT_MOD_Yf_TILED: |
| 3002 | plane_ctl |= PLANE_CTL_TILED_YF; |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3003 | break; |
| 3004 | default: |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3005 | MISSING_CASE(fb->modifier[0]); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3006 | } |
| 3007 | |
| 3008 | plane_ctl |= PLANE_CTL_PLANE_GAMMA_DISABLE; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3009 | |
| 3010 | plane = crtc->primary; |
| 3011 | rotation = plane->state->rotation; |
| 3012 | switch (rotation) { |
| 3013 | case BIT(DRM_ROTATE_90): |
| 3014 | plane_ctl |= PLANE_CTL_ROTATE_90; |
| 3015 | break; |
| 3016 | |
| 3017 | case BIT(DRM_ROTATE_180): |
Sonika Jindal | 1447dde | 2014-10-04 10:53:31 +0100 | [diff] [blame] | 3018 | plane_ctl |= PLANE_CTL_ROTATE_180; |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3019 | break; |
| 3020 | |
| 3021 | case BIT(DRM_ROTATE_270): |
| 3022 | plane_ctl |= PLANE_CTL_ROTATE_270; |
| 3023 | break; |
| 3024 | } |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3025 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3026 | obj = intel_fb_obj(fb); |
| 3027 | stride_div = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 3028 | fb->pixel_format); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3029 | surf_addr = intel_plane_obj_offset(to_intel_plane(plane), obj); |
| 3030 | |
| 3031 | if (intel_rotation_90_or_270(rotation)) { |
| 3032 | /* stride = Surface height in tiles */ |
| 3033 | tile_height = intel_tile_height(dev, fb->bits_per_pixel, |
| 3034 | fb->modifier[0]); |
| 3035 | stride = DIV_ROUND_UP(fb->height, tile_height); |
| 3036 | x_offset = stride * tile_height - y - (plane->state->src_h >> 16); |
| 3037 | y_offset = x; |
| 3038 | plane_size = ((plane->state->src_w >> 16) - 1) << 16 | |
| 3039 | ((plane->state->src_h >> 16) - 1); |
| 3040 | } else { |
| 3041 | stride = fb->pitches[0] / stride_div; |
| 3042 | x_offset = x; |
| 3043 | y_offset = y; |
| 3044 | plane_size = ((plane->state->src_h >> 16) - 1) << 16 | |
| 3045 | ((plane->state->src_w >> 16) - 1); |
| 3046 | } |
| 3047 | plane_offset = y_offset << 16 | x_offset; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 3048 | |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3049 | I915_WRITE(PLANE_CTL(pipe, 0), plane_ctl); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3050 | I915_WRITE(PLANE_POS(pipe, 0), 0); |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 3051 | I915_WRITE(PLANE_OFFSET(pipe, 0), plane_offset); |
| 3052 | I915_WRITE(PLANE_SIZE(pipe, 0), plane_size); |
| 3053 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 3054 | I915_WRITE(PLANE_SURF(pipe, 0), surf_addr); |
Damien Lespiau | 70d21f0 | 2013-07-03 21:06:04 +0100 | [diff] [blame] | 3055 | |
| 3056 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 3057 | } |
| 3058 | |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3059 | /* Assume fb object is pinned & idle & fenced and just update base pointers */ |
| 3060 | static int |
| 3061 | intel_pipe_set_base_atomic(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
| 3062 | int x, int y, enum mode_set_atomic state) |
| 3063 | { |
| 3064 | struct drm_device *dev = crtc->dev; |
| 3065 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 17638cd | 2011-06-24 12:19:23 -0700 | [diff] [blame] | 3066 | |
Chris Wilson | 6b8e6ed | 2012-04-17 15:08:19 +0100 | [diff] [blame] | 3067 | if (dev_priv->display.disable_fbc) |
| 3068 | dev_priv->display.disable_fbc(dev); |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3069 | |
Daniel Vetter | 29b9bde | 2014-04-24 23:55:01 +0200 | [diff] [blame] | 3070 | dev_priv->display.update_primary_plane(crtc, fb, x, y); |
| 3071 | |
| 3072 | return 0; |
Jesse Barnes | 8125556 | 2010-08-02 12:07:50 -0700 | [diff] [blame] | 3073 | } |
| 3074 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3075 | static void intel_complete_page_flips(struct drm_device *dev) |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3076 | { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3077 | struct drm_crtc *crtc; |
| 3078 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3079 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3080 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3081 | enum plane plane = intel_crtc->plane; |
| 3082 | |
| 3083 | intel_prepare_page_flip(dev, plane); |
| 3084 | intel_finish_page_flip_plane(dev, plane); |
| 3085 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3086 | } |
| 3087 | |
| 3088 | static void intel_update_primary_planes(struct drm_device *dev) |
| 3089 | { |
| 3090 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3091 | struct drm_crtc *crtc; |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3092 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 3093 | for_each_crtc(dev, crtc) { |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3094 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3095 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 3096 | drm_modeset_lock(&crtc->mutex, NULL); |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 3097 | /* |
| 3098 | * FIXME: Once we have proper support for primary planes (and |
| 3099 | * disabling them without disabling the entire crtc) allow again |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 3100 | * a NULL crtc->primary->fb. |
Chris Wilson | 947fdaadf | 2013-11-27 12:01:32 +0000 | [diff] [blame] | 3101 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 3102 | if (intel_crtc->active && crtc->primary->fb) |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 3103 | dev_priv->display.update_primary_plane(crtc, |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 3104 | crtc->primary->fb, |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 3105 | crtc->x, |
| 3106 | crtc->y); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 3107 | drm_modeset_unlock(&crtc->mutex); |
Ville Syrjälä | 96a0291 | 2013-02-18 19:08:49 +0200 | [diff] [blame] | 3108 | } |
| 3109 | } |
| 3110 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3111 | void intel_prepare_reset(struct drm_device *dev) |
| 3112 | { |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3113 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3114 | struct intel_crtc *crtc; |
| 3115 | |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3116 | /* no reset support for gen2 */ |
| 3117 | if (IS_GEN2(dev)) |
| 3118 | return; |
| 3119 | |
| 3120 | /* reset doesn't touch the display */ |
| 3121 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
| 3122 | return; |
| 3123 | |
| 3124 | drm_modeset_lock_all(dev); |
Ville Syrjälä | f98ce92 | 2014-11-21 21:54:30 +0200 | [diff] [blame] | 3125 | |
| 3126 | /* |
| 3127 | * Disabling the crtcs gracefully seems nicer. Also the |
| 3128 | * g33 docs say we should at least disable all the planes. |
| 3129 | */ |
| 3130 | for_each_intel_crtc(dev, crtc) { |
| 3131 | if (crtc->active) |
| 3132 | dev_priv->display.crtc_disable(&crtc->base); |
| 3133 | } |
Ville Syrjälä | 7514747 | 2014-11-24 18:28:11 +0200 | [diff] [blame] | 3134 | } |
| 3135 | |
| 3136 | void intel_finish_reset(struct drm_device *dev) |
| 3137 | { |
| 3138 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 3139 | |
| 3140 | /* |
| 3141 | * Flips in the rings will be nuked by the reset, |
| 3142 | * so complete all pending flips so that user space |
| 3143 | * will get its events and not get stuck. |
| 3144 | */ |
| 3145 | intel_complete_page_flips(dev); |
| 3146 | |
| 3147 | /* no reset support for gen2 */ |
| 3148 | if (IS_GEN2(dev)) |
| 3149 | return; |
| 3150 | |
| 3151 | /* reset doesn't touch the display */ |
| 3152 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) { |
| 3153 | /* |
| 3154 | * Flips in the rings have been nuked by the reset, |
| 3155 | * so update the base address of all primary |
| 3156 | * planes to the the last fb to make sure we're |
| 3157 | * showing the correct fb after a reset. |
| 3158 | */ |
| 3159 | intel_update_primary_planes(dev); |
| 3160 | return; |
| 3161 | } |
| 3162 | |
| 3163 | /* |
| 3164 | * The display has been reset as well, |
| 3165 | * so need a full re-initialization. |
| 3166 | */ |
| 3167 | intel_runtime_pm_disable_interrupts(dev_priv); |
| 3168 | intel_runtime_pm_enable_interrupts(dev_priv); |
| 3169 | |
| 3170 | intel_modeset_init_hw(dev); |
| 3171 | |
| 3172 | spin_lock_irq(&dev_priv->irq_lock); |
| 3173 | if (dev_priv->display.hpd_irq_setup) |
| 3174 | dev_priv->display.hpd_irq_setup(dev); |
| 3175 | spin_unlock_irq(&dev_priv->irq_lock); |
| 3176 | |
| 3177 | intel_modeset_setup_hw_state(dev, true); |
| 3178 | |
| 3179 | intel_hpd_init(dev_priv); |
| 3180 | |
| 3181 | drm_modeset_unlock_all(dev); |
| 3182 | } |
| 3183 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 3184 | static int |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3185 | intel_finish_fb(struct drm_framebuffer *old_fb) |
| 3186 | { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 3187 | struct drm_i915_gem_object *obj = intel_fb_obj(old_fb); |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3188 | struct drm_i915_private *dev_priv = obj->base.dev->dev_private; |
| 3189 | bool was_interruptible = dev_priv->mm.interruptible; |
| 3190 | int ret; |
| 3191 | |
Chris Wilson | 14667a4 | 2012-04-03 17:58:35 +0100 | [diff] [blame] | 3192 | /* Big Hammer, we also need to ensure that any pending |
| 3193 | * MI_WAIT_FOR_EVENT inside a user batch buffer on the |
| 3194 | * current scanout is retired before unpinning the old |
| 3195 | * framebuffer. |
| 3196 | * |
| 3197 | * This should only fail upon a hung GPU, in which case we |
| 3198 | * can safely continue. |
| 3199 | */ |
| 3200 | dev_priv->mm.interruptible = false; |
| 3201 | ret = i915_gem_object_finish_gpu(obj); |
| 3202 | dev_priv->mm.interruptible = was_interruptible; |
| 3203 | |
| 3204 | return ret; |
| 3205 | } |
| 3206 | |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3207 | static bool intel_crtc_has_pending_flip(struct drm_crtc *crtc) |
| 3208 | { |
| 3209 | struct drm_device *dev = crtc->dev; |
| 3210 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3211 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3212 | bool pending; |
| 3213 | |
| 3214 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 3215 | intel_crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 3216 | return false; |
| 3217 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3218 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3219 | pending = to_intel_crtc(crtc)->unpin_work != NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3220 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 7d5e379 | 2014-03-04 13:15:08 +0000 | [diff] [blame] | 3221 | |
| 3222 | return pending; |
| 3223 | } |
| 3224 | |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3225 | static void intel_update_pipe_size(struct intel_crtc *crtc) |
| 3226 | { |
| 3227 | struct drm_device *dev = crtc->base.dev; |
| 3228 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3229 | const struct drm_display_mode *adjusted_mode; |
| 3230 | |
| 3231 | if (!i915.fastboot) |
| 3232 | return; |
| 3233 | |
| 3234 | /* |
| 3235 | * Update pipe size and adjust fitter if needed: the reason for this is |
| 3236 | * that in compute_mode_changes we check the native mode (not the pfit |
| 3237 | * mode) to see if we can flip rather than do a full mode set. In the |
| 3238 | * fastboot case, we'll flip, but if we don't update the pipesrc and |
| 3239 | * pfit state, we'll end up with a big fb scanned out into the wrong |
| 3240 | * sized surface. |
| 3241 | * |
| 3242 | * To fix this properly, we need to hoist the checks up into |
| 3243 | * compute_mode_changes (or above), check the actual pfit state and |
| 3244 | * whether the platform allows pfit disable with pipe active, and only |
| 3245 | * then update the pipesrc and pfit state, even on the flip path. |
| 3246 | */ |
| 3247 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3248 | adjusted_mode = &crtc->config->base.adjusted_mode; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3249 | |
| 3250 | I915_WRITE(PIPESRC(crtc->pipe), |
| 3251 | ((adjusted_mode->crtc_hdisplay - 1) << 16) | |
| 3252 | (adjusted_mode->crtc_vdisplay - 1)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3253 | if (!crtc->config->pch_pfit.enabled && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 3254 | (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS) || |
| 3255 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP))) { |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3256 | I915_WRITE(PF_CTL(crtc->pipe), 0); |
| 3257 | I915_WRITE(PF_WIN_POS(crtc->pipe), 0); |
| 3258 | I915_WRITE(PF_WIN_SZ(crtc->pipe), 0); |
| 3259 | } |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3260 | crtc->config->pipe_src_w = adjusted_mode->crtc_hdisplay; |
| 3261 | crtc->config->pipe_src_h = adjusted_mode->crtc_vdisplay; |
Gustavo Padovan | e30e8f7 | 2014-09-10 12:04:17 -0300 | [diff] [blame] | 3262 | } |
| 3263 | |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3264 | static void intel_fdi_normal_train(struct drm_crtc *crtc) |
| 3265 | { |
| 3266 | struct drm_device *dev = crtc->dev; |
| 3267 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3268 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3269 | int pipe = intel_crtc->pipe; |
| 3270 | u32 reg, temp; |
| 3271 | |
| 3272 | /* enable normal train */ |
| 3273 | reg = FDI_TX_CTL(pipe); |
| 3274 | temp = I915_READ(reg); |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3275 | if (IS_IVYBRIDGE(dev)) { |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3276 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3277 | temp |= FDI_LINK_TRAIN_NONE_IVB | FDI_TX_ENHANCE_FRAME_ENABLE; |
Keith Packard | 61e499b | 2011-05-17 16:13:52 -0700 | [diff] [blame] | 3278 | } else { |
| 3279 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3280 | temp |= FDI_LINK_TRAIN_NONE | FDI_TX_ENHANCE_FRAME_ENABLE; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3281 | } |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3282 | I915_WRITE(reg, temp); |
| 3283 | |
| 3284 | reg = FDI_RX_CTL(pipe); |
| 3285 | temp = I915_READ(reg); |
| 3286 | if (HAS_PCH_CPT(dev)) { |
| 3287 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3288 | temp |= FDI_LINK_TRAIN_NORMAL_CPT; |
| 3289 | } else { |
| 3290 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3291 | temp |= FDI_LINK_TRAIN_NONE; |
| 3292 | } |
| 3293 | I915_WRITE(reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); |
| 3294 | |
| 3295 | /* wait one idle pattern time */ |
| 3296 | POSTING_READ(reg); |
| 3297 | udelay(1000); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3298 | |
| 3299 | /* IVB wants error correction enabled */ |
| 3300 | if (IS_IVYBRIDGE(dev)) |
| 3301 | I915_WRITE(reg, I915_READ(reg) | FDI_FS_ERRC_ENABLE | |
| 3302 | FDI_FE_ERRC_ENABLE); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 3303 | } |
| 3304 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3305 | /* The FDI link training functions for ILK/Ibexpeak. */ |
| 3306 | static void ironlake_fdi_link_train(struct drm_crtc *crtc) |
| 3307 | { |
| 3308 | struct drm_device *dev = crtc->dev; |
| 3309 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3310 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3311 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3312 | u32 reg, temp, tries; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3313 | |
Ville Syrjälä | 1c8562f | 2014-04-25 22:12:07 +0300 | [diff] [blame] | 3314 | /* FDI needs bits from pipe first */ |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3315 | assert_pipe_enabled(dev_priv, pipe); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3316 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3317 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3318 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3319 | reg = FDI_RX_IMR(pipe); |
| 3320 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3321 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3322 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3323 | I915_WRITE(reg, temp); |
| 3324 | I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3325 | udelay(150); |
| 3326 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3327 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3328 | reg = FDI_TX_CTL(pipe); |
| 3329 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3330 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3331 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3332 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3333 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3334 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3335 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3336 | reg = FDI_RX_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_1; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3340 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3341 | |
| 3342 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3343 | udelay(150); |
| 3344 | |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3345 | /* Ironlake workaround, enable clock pointer after FDI enable*/ |
Daniel Vetter | 8f5718a | 2012-10-31 22:52:28 +0100 | [diff] [blame] | 3346 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
| 3347 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR | |
| 3348 | FDI_RX_PHASE_SYNC_POINTER_EN); |
Jesse Barnes | 5b2adf8 | 2010-10-07 16:01:15 -0700 | [diff] [blame] | 3349 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3350 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3351 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3352 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3353 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3354 | |
| 3355 | if ((temp & FDI_RX_BIT_LOCK)) { |
| 3356 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3357 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3358 | break; |
| 3359 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3360 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3361 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3362 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3363 | |
| 3364 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3365 | reg = FDI_TX_CTL(pipe); |
| 3366 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3367 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3368 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3369 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3370 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3371 | reg = FDI_RX_CTL(pipe); |
| 3372 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3373 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3374 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3375 | I915_WRITE(reg, temp); |
| 3376 | |
| 3377 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3378 | udelay(150); |
| 3379 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3380 | reg = FDI_RX_IIR(pipe); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3381 | for (tries = 0; tries < 5; tries++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3382 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3383 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3384 | |
| 3385 | if (temp & FDI_RX_SYMBOL_LOCK) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3386 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3387 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3388 | break; |
| 3389 | } |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3390 | } |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3391 | if (tries == 5) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3392 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3393 | |
| 3394 | DRM_DEBUG_KMS("FDI train done\n"); |
Jesse Barnes | 5c5313c | 2010-10-07 16:01:11 -0700 | [diff] [blame] | 3395 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3396 | } |
| 3397 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3398 | static const int snb_b_fdi_train_param[] = { |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3399 | FDI_LINK_TRAIN_400MV_0DB_SNB_B, |
| 3400 | FDI_LINK_TRAIN_400MV_6DB_SNB_B, |
| 3401 | FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, |
| 3402 | FDI_LINK_TRAIN_800MV_0DB_SNB_B, |
| 3403 | }; |
| 3404 | |
| 3405 | /* The FDI link training functions for SNB/Cougarpoint. */ |
| 3406 | static void gen6_fdi_link_train(struct drm_crtc *crtc) |
| 3407 | { |
| 3408 | struct drm_device *dev = crtc->dev; |
| 3409 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3410 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3411 | int pipe = intel_crtc->pipe; |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3412 | u32 reg, temp, i, retry; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3413 | |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3414 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3415 | for train result */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3416 | reg = FDI_RX_IMR(pipe); |
| 3417 | temp = I915_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3418 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3419 | temp &= ~FDI_RX_BIT_LOCK; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3420 | I915_WRITE(reg, temp); |
| 3421 | |
| 3422 | POSTING_READ(reg); |
Adam Jackson | e1a4474 | 2010-06-25 15:32:14 -0400 | [diff] [blame] | 3423 | udelay(150); |
| 3424 | |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3425 | /* enable CPU FDI TX and PCH FDI RX */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3426 | reg = FDI_TX_CTL(pipe); |
| 3427 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3428 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3429 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3430 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3431 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3432 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3433 | /* SNB-B */ |
| 3434 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3435 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3436 | |
Daniel Vetter | d74cf32 | 2012-10-26 10:58:13 +0200 | [diff] [blame] | 3437 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3438 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3439 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3440 | reg = FDI_RX_CTL(pipe); |
| 3441 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3442 | if (HAS_PCH_CPT(dev)) { |
| 3443 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3444 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3445 | } else { |
| 3446 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3447 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3448 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3449 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3450 | |
| 3451 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3452 | udelay(150); |
| 3453 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3454 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3455 | reg = FDI_TX_CTL(pipe); |
| 3456 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3457 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3458 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3459 | I915_WRITE(reg, temp); |
| 3460 | |
| 3461 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3462 | udelay(500); |
| 3463 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3464 | for (retry = 0; retry < 5; retry++) { |
| 3465 | reg = FDI_RX_IIR(pipe); |
| 3466 | temp = I915_READ(reg); |
| 3467 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3468 | if (temp & FDI_RX_BIT_LOCK) { |
| 3469 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3470 | DRM_DEBUG_KMS("FDI train 1 done.\n"); |
| 3471 | break; |
| 3472 | } |
| 3473 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3474 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3475 | if (retry < 5) |
| 3476 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3477 | } |
| 3478 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3479 | DRM_ERROR("FDI train 1 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3480 | |
| 3481 | /* Train 2 */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3482 | reg = FDI_TX_CTL(pipe); |
| 3483 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3484 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3485 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3486 | if (IS_GEN6(dev)) { |
| 3487 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3488 | /* SNB-B */ |
| 3489 | temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; |
| 3490 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3491 | I915_WRITE(reg, temp); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3492 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3493 | reg = FDI_RX_CTL(pipe); |
| 3494 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3495 | if (HAS_PCH_CPT(dev)) { |
| 3496 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3497 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
| 3498 | } else { |
| 3499 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3500 | temp |= FDI_LINK_TRAIN_PATTERN_2; |
| 3501 | } |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3502 | I915_WRITE(reg, temp); |
| 3503 | |
| 3504 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3505 | udelay(150); |
| 3506 | |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 3507 | for (i = 0; i < 4; i++) { |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3508 | reg = FDI_TX_CTL(pipe); |
| 3509 | temp = I915_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3510 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
| 3511 | temp |= snb_b_fdi_train_param[i]; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3512 | I915_WRITE(reg, temp); |
| 3513 | |
| 3514 | POSTING_READ(reg); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3515 | udelay(500); |
| 3516 | |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3517 | for (retry = 0; retry < 5; retry++) { |
| 3518 | reg = FDI_RX_IIR(pipe); |
| 3519 | temp = I915_READ(reg); |
| 3520 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3521 | if (temp & FDI_RX_SYMBOL_LOCK) { |
| 3522 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3523 | DRM_DEBUG_KMS("FDI train 2 done.\n"); |
| 3524 | break; |
| 3525 | } |
| 3526 | udelay(50); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3527 | } |
Sean Paul | fa37d39 | 2012-03-02 12:53:39 -0500 | [diff] [blame] | 3528 | if (retry < 5) |
| 3529 | break; |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3530 | } |
| 3531 | if (i == 4) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3532 | DRM_ERROR("FDI train 2 fail!\n"); |
Zhenyu Wang | 8db9d77 | 2010-04-07 16:15:54 +0800 | [diff] [blame] | 3533 | |
| 3534 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3535 | } |
| 3536 | |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3537 | /* Manual link training for Ivy Bridge A0 parts */ |
| 3538 | static void ivb_manual_fdi_link_train(struct drm_crtc *crtc) |
| 3539 | { |
| 3540 | struct drm_device *dev = crtc->dev; |
| 3541 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3542 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3543 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3544 | u32 reg, temp, i, j; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3545 | |
| 3546 | /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit |
| 3547 | for train result */ |
| 3548 | reg = FDI_RX_IMR(pipe); |
| 3549 | temp = I915_READ(reg); |
| 3550 | temp &= ~FDI_RX_SYMBOL_LOCK; |
| 3551 | temp &= ~FDI_RX_BIT_LOCK; |
| 3552 | I915_WRITE(reg, temp); |
| 3553 | |
| 3554 | POSTING_READ(reg); |
| 3555 | udelay(150); |
| 3556 | |
Daniel Vetter | 01a415f | 2012-10-27 15:58:40 +0200 | [diff] [blame] | 3557 | DRM_DEBUG_KMS("FDI_RX_IIR before link train 0x%x\n", |
| 3558 | I915_READ(FDI_RX_IIR(pipe))); |
| 3559 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3560 | /* Try each vswing and preemphasis setting twice before moving on */ |
| 3561 | for (j = 0; j < ARRAY_SIZE(snb_b_fdi_train_param) * 2; j++) { |
| 3562 | /* disable first in case we need to retry */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3563 | reg = FDI_TX_CTL(pipe); |
| 3564 | temp = I915_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3565 | temp &= ~(FDI_LINK_TRAIN_AUTO | FDI_LINK_TRAIN_NONE_IVB); |
| 3566 | temp &= ~FDI_TX_ENABLE; |
| 3567 | I915_WRITE(reg, temp); |
| 3568 | |
| 3569 | reg = FDI_RX_CTL(pipe); |
| 3570 | temp = I915_READ(reg); |
| 3571 | temp &= ~FDI_LINK_TRAIN_AUTO; |
| 3572 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3573 | temp &= ~FDI_RX_ENABLE; |
| 3574 | I915_WRITE(reg, temp); |
| 3575 | |
| 3576 | /* enable CPU FDI TX and PCH FDI RX */ |
| 3577 | reg = FDI_TX_CTL(pipe); |
| 3578 | temp = I915_READ(reg); |
| 3579 | temp &= ~FDI_DP_PORT_WIDTH_MASK; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3580 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3581 | temp |= FDI_LINK_TRAIN_PATTERN_1_IVB; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3582 | temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3583 | temp |= snb_b_fdi_train_param[j/2]; |
| 3584 | temp |= FDI_COMPOSITE_SYNC; |
| 3585 | I915_WRITE(reg, temp | FDI_TX_ENABLE); |
| 3586 | |
| 3587 | I915_WRITE(FDI_RX_MISC(pipe), |
| 3588 | FDI_RX_TP1_TO_TP2_48 | FDI_RX_FDI_DELAY_90); |
| 3589 | |
| 3590 | reg = FDI_RX_CTL(pipe); |
| 3591 | temp = I915_READ(reg); |
| 3592 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3593 | temp |= FDI_COMPOSITE_SYNC; |
| 3594 | I915_WRITE(reg, temp | FDI_RX_ENABLE); |
| 3595 | |
| 3596 | POSTING_READ(reg); |
| 3597 | udelay(1); /* should be 0.5us */ |
| 3598 | |
| 3599 | for (i = 0; i < 4; i++) { |
| 3600 | reg = FDI_RX_IIR(pipe); |
| 3601 | temp = I915_READ(reg); |
| 3602 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
| 3603 | |
| 3604 | if (temp & FDI_RX_BIT_LOCK || |
| 3605 | (I915_READ(reg) & FDI_RX_BIT_LOCK)) { |
| 3606 | I915_WRITE(reg, temp | FDI_RX_BIT_LOCK); |
| 3607 | DRM_DEBUG_KMS("FDI train 1 done, level %i.\n", |
| 3608 | i); |
| 3609 | break; |
| 3610 | } |
| 3611 | udelay(1); /* should be 0.5us */ |
| 3612 | } |
| 3613 | if (i == 4) { |
| 3614 | DRM_DEBUG_KMS("FDI train 1 fail on vswing %d\n", j / 2); |
| 3615 | continue; |
| 3616 | } |
| 3617 | |
| 3618 | /* Train 2 */ |
| 3619 | reg = FDI_TX_CTL(pipe); |
| 3620 | temp = I915_READ(reg); |
| 3621 | temp &= ~FDI_LINK_TRAIN_NONE_IVB; |
| 3622 | temp |= FDI_LINK_TRAIN_PATTERN_2_IVB; |
| 3623 | I915_WRITE(reg, temp); |
| 3624 | |
| 3625 | reg = FDI_RX_CTL(pipe); |
| 3626 | temp = I915_READ(reg); |
| 3627 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3628 | temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3629 | I915_WRITE(reg, temp); |
| 3630 | |
| 3631 | POSTING_READ(reg); |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3632 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3633 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3634 | for (i = 0; i < 4; i++) { |
| 3635 | reg = FDI_RX_IIR(pipe); |
| 3636 | temp = I915_READ(reg); |
| 3637 | DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3638 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3639 | if (temp & FDI_RX_SYMBOL_LOCK || |
| 3640 | (I915_READ(reg) & FDI_RX_SYMBOL_LOCK)) { |
| 3641 | I915_WRITE(reg, temp | FDI_RX_SYMBOL_LOCK); |
| 3642 | DRM_DEBUG_KMS("FDI train 2 done, level %i.\n", |
| 3643 | i); |
| 3644 | goto train_done; |
| 3645 | } |
| 3646 | udelay(2); /* should be 1.5us */ |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3647 | } |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3648 | if (i == 4) |
| 3649 | 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] | 3650 | } |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3651 | |
Jesse Barnes | 139ccd3 | 2013-08-19 11:04:55 -0700 | [diff] [blame] | 3652 | train_done: |
Jesse Barnes | 357555c | 2011-04-28 15:09:55 -0700 | [diff] [blame] | 3653 | DRM_DEBUG_KMS("FDI train done.\n"); |
| 3654 | } |
| 3655 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3656 | static void ironlake_fdi_pll_enable(struct intel_crtc *intel_crtc) |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3657 | { |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3658 | struct drm_device *dev = intel_crtc->base.dev; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3659 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3660 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3661 | u32 reg, temp; |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3662 | |
Jesse Barnes | c64e311 | 2010-09-10 11:27:03 -0700 | [diff] [blame] | 3663 | |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3664 | /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3665 | reg = FDI_RX_CTL(pipe); |
| 3666 | temp = I915_READ(reg); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 3667 | temp &= ~(FDI_DP_PORT_WIDTH_MASK | (0x7 << 16)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3668 | temp |= FDI_DP_PORT_WIDTH(intel_crtc->config->fdi_lanes); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3669 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3670 | I915_WRITE(reg, temp | FDI_RX_PLL_ENABLE); |
| 3671 | |
| 3672 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3673 | udelay(200); |
| 3674 | |
| 3675 | /* Switch from Rawclk to PCDclk */ |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3676 | temp = I915_READ(reg); |
| 3677 | I915_WRITE(reg, temp | FDI_PCDCLK); |
| 3678 | |
| 3679 | POSTING_READ(reg); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3680 | udelay(200); |
| 3681 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3682 | /* Enable CPU FDI TX PLL, always on for Ironlake */ |
| 3683 | reg = FDI_TX_CTL(pipe); |
| 3684 | temp = I915_READ(reg); |
| 3685 | if ((temp & FDI_TX_PLL_ENABLE) == 0) { |
| 3686 | I915_WRITE(reg, temp | FDI_TX_PLL_ENABLE); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 3687 | |
Paulo Zanoni | 2074973 | 2012-11-23 15:30:38 -0200 | [diff] [blame] | 3688 | POSTING_READ(reg); |
| 3689 | udelay(100); |
Jesse Barnes | 0e23b99 | 2010-09-10 11:10:00 -0700 | [diff] [blame] | 3690 | } |
| 3691 | } |
| 3692 | |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 3693 | static void ironlake_fdi_pll_disable(struct intel_crtc *intel_crtc) |
| 3694 | { |
| 3695 | struct drm_device *dev = intel_crtc->base.dev; |
| 3696 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3697 | int pipe = intel_crtc->pipe; |
| 3698 | u32 reg, temp; |
| 3699 | |
| 3700 | /* Switch from PCDclk to Rawclk */ |
| 3701 | reg = FDI_RX_CTL(pipe); |
| 3702 | temp = I915_READ(reg); |
| 3703 | I915_WRITE(reg, temp & ~FDI_PCDCLK); |
| 3704 | |
| 3705 | /* Disable CPU FDI TX PLL */ |
| 3706 | reg = FDI_TX_CTL(pipe); |
| 3707 | temp = I915_READ(reg); |
| 3708 | I915_WRITE(reg, temp & ~FDI_TX_PLL_ENABLE); |
| 3709 | |
| 3710 | POSTING_READ(reg); |
| 3711 | udelay(100); |
| 3712 | |
| 3713 | reg = FDI_RX_CTL(pipe); |
| 3714 | temp = I915_READ(reg); |
| 3715 | I915_WRITE(reg, temp & ~FDI_RX_PLL_ENABLE); |
| 3716 | |
| 3717 | /* Wait for the clocks to turn off. */ |
| 3718 | POSTING_READ(reg); |
| 3719 | udelay(100); |
| 3720 | } |
| 3721 | |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3722 | static void ironlake_fdi_disable(struct drm_crtc *crtc) |
| 3723 | { |
| 3724 | struct drm_device *dev = crtc->dev; |
| 3725 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3726 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 3727 | int pipe = intel_crtc->pipe; |
| 3728 | u32 reg, temp; |
| 3729 | |
| 3730 | /* disable CPU FDI tx and PCH FDI rx */ |
| 3731 | reg = FDI_TX_CTL(pipe); |
| 3732 | temp = I915_READ(reg); |
| 3733 | I915_WRITE(reg, temp & ~FDI_TX_ENABLE); |
| 3734 | POSTING_READ(reg); |
| 3735 | |
| 3736 | reg = FDI_RX_CTL(pipe); |
| 3737 | temp = I915_READ(reg); |
| 3738 | temp &= ~(0x7 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3739 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3740 | I915_WRITE(reg, temp & ~FDI_RX_ENABLE); |
| 3741 | |
| 3742 | POSTING_READ(reg); |
| 3743 | udelay(100); |
| 3744 | |
| 3745 | /* Ironlake workaround, disable clock pointer after downing FDI */ |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 3746 | if (HAS_PCH_IBX(dev)) |
Jesse Barnes | 6f06ce1 | 2011-01-04 15:09:38 -0800 | [diff] [blame] | 3747 | I915_WRITE(FDI_RX_CHICKEN(pipe), FDI_RX_PHASE_SYNC_POINTER_OVR); |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3748 | |
| 3749 | /* still set train pattern 1 */ |
| 3750 | reg = FDI_TX_CTL(pipe); |
| 3751 | temp = I915_READ(reg); |
| 3752 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3753 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3754 | I915_WRITE(reg, temp); |
| 3755 | |
| 3756 | reg = FDI_RX_CTL(pipe); |
| 3757 | temp = I915_READ(reg); |
| 3758 | if (HAS_PCH_CPT(dev)) { |
| 3759 | temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; |
| 3760 | temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; |
| 3761 | } else { |
| 3762 | temp &= ~FDI_LINK_TRAIN_NONE; |
| 3763 | temp |= FDI_LINK_TRAIN_PATTERN_1; |
| 3764 | } |
| 3765 | /* BPC in FDI rx is consistent with that in PIPECONF */ |
| 3766 | temp &= ~(0x07 << 16); |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 3767 | temp |= (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) << 11; |
Jesse Barnes | 0fc932b | 2011-01-04 15:09:37 -0800 | [diff] [blame] | 3768 | I915_WRITE(reg, temp); |
| 3769 | |
| 3770 | POSTING_READ(reg); |
| 3771 | udelay(100); |
| 3772 | } |
| 3773 | |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3774 | bool intel_has_pending_fb_unpin(struct drm_device *dev) |
| 3775 | { |
| 3776 | struct intel_crtc *crtc; |
| 3777 | |
| 3778 | /* Note that we don't need to be called with mode_config.lock here |
| 3779 | * as our list of CRTC objects is static for the lifetime of the |
| 3780 | * device and so cannot disappear as we iterate. Similarly, we can |
| 3781 | * happily treat the predicates as racy, atomic checks as userspace |
| 3782 | * cannot claim and pin a new fb without at least acquring the |
| 3783 | * struct_mutex and so serialising with us. |
| 3784 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 3785 | for_each_intel_crtc(dev, crtc) { |
Chris Wilson | 5dce5b93 | 2014-01-20 10:17:36 +0000 | [diff] [blame] | 3786 | if (atomic_read(&crtc->unpin_work_count) == 0) |
| 3787 | continue; |
| 3788 | |
| 3789 | if (crtc->unpin_work) |
| 3790 | intel_wait_for_vblank(dev, crtc->pipe); |
| 3791 | |
| 3792 | return true; |
| 3793 | } |
| 3794 | |
| 3795 | return false; |
| 3796 | } |
| 3797 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 3798 | static void page_flip_completed(struct intel_crtc *intel_crtc) |
| 3799 | { |
| 3800 | struct drm_i915_private *dev_priv = to_i915(intel_crtc->base.dev); |
| 3801 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 3802 | |
| 3803 | /* ensure that the unpin work is consistent wrt ->pending. */ |
| 3804 | smp_rmb(); |
| 3805 | intel_crtc->unpin_work = NULL; |
| 3806 | |
| 3807 | if (work->event) |
| 3808 | drm_send_vblank_event(intel_crtc->base.dev, |
| 3809 | intel_crtc->pipe, |
| 3810 | work->event); |
| 3811 | |
| 3812 | drm_crtc_vblank_put(&intel_crtc->base); |
| 3813 | |
| 3814 | wake_up_all(&dev_priv->pending_flip_queue); |
| 3815 | queue_work(dev_priv->wq, &work->work); |
| 3816 | |
| 3817 | trace_i915_flip_complete(intel_crtc->plane, |
| 3818 | work->pending_flip_obj); |
| 3819 | } |
| 3820 | |
Ville Syrjälä | 46a55d3 | 2014-05-21 14:04:46 +0300 | [diff] [blame] | 3821 | void intel_crtc_wait_for_pending_flips(struct drm_crtc *crtc) |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3822 | { |
Chris Wilson | 0f91128 | 2012-04-17 10:05:38 +0100 | [diff] [blame] | 3823 | struct drm_device *dev = crtc->dev; |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3824 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3825 | |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3826 | WARN_ON(waitqueue_active(&dev_priv->pending_flip_queue)); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3827 | if (WARN_ON(wait_event_timeout(dev_priv->pending_flip_queue, |
| 3828 | !intel_crtc_has_pending_flip(crtc), |
| 3829 | 60*HZ) == 0)) { |
| 3830 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 2c10d57 | 2012-12-20 21:24:07 +0100 | [diff] [blame] | 3831 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3832 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3833 | if (intel_crtc->unpin_work) { |
| 3834 | WARN_ONCE(1, "Removing stuck page flip\n"); |
| 3835 | page_flip_completed(intel_crtc); |
| 3836 | } |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 3837 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 9c78794 | 2014-09-05 07:13:25 +0100 | [diff] [blame] | 3838 | } |
Chris Wilson | 5bb6164 | 2012-09-27 21:25:58 +0100 | [diff] [blame] | 3839 | |
Chris Wilson | 975d568 | 2014-08-20 13:13:34 +0100 | [diff] [blame] | 3840 | if (crtc->primary->fb) { |
| 3841 | mutex_lock(&dev->struct_mutex); |
| 3842 | intel_finish_fb(crtc->primary->fb); |
| 3843 | mutex_unlock(&dev->struct_mutex); |
| 3844 | } |
Chris Wilson | e6c3a2a | 2010-09-23 23:04:43 +0100 | [diff] [blame] | 3845 | } |
| 3846 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3847 | /* Program iCLKIP clock to the desired frequency */ |
| 3848 | static void lpt_program_iclkip(struct drm_crtc *crtc) |
| 3849 | { |
| 3850 | struct drm_device *dev = crtc->dev; |
| 3851 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3852 | int clock = to_intel_crtc(crtc)->config->base.adjusted_mode.crtc_clock; |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3853 | u32 divsel, phaseinc, auxdiv, phasedir = 0; |
| 3854 | u32 temp; |
| 3855 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3856 | mutex_lock(&dev_priv->dpio_lock); |
| 3857 | |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3858 | /* It is necessary to ungate the pixclk gate prior to programming |
| 3859 | * the divisors, and gate it back when it is done. |
| 3860 | */ |
| 3861 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_GATE); |
| 3862 | |
| 3863 | /* Disable SSCCTL */ |
| 3864 | intel_sbi_write(dev_priv, SBI_SSCCTL6, |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3865 | intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK) | |
| 3866 | SBI_SSCCTL_DISABLE, |
| 3867 | SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3868 | |
| 3869 | /* 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] | 3870 | if (clock == 20000) { |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3871 | auxdiv = 1; |
| 3872 | divsel = 0x41; |
| 3873 | phaseinc = 0x20; |
| 3874 | } else { |
| 3875 | /* The iCLK virtual clock root frequency is in MHz, |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 3876 | * but the adjusted_mode->crtc_clock in in KHz. To get the |
| 3877 | * divisors, it is necessary to divide one by another, so we |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3878 | * convert the virtual clock precision to KHz here for higher |
| 3879 | * precision. |
| 3880 | */ |
| 3881 | u32 iclk_virtual_root_freq = 172800 * 1000; |
| 3882 | u32 iclk_pi_range = 64; |
| 3883 | u32 desired_divisor, msb_divisor_value, pi_value; |
| 3884 | |
Ville Syrjälä | 12d7cee | 2013-09-04 18:25:19 +0300 | [diff] [blame] | 3885 | desired_divisor = (iclk_virtual_root_freq / clock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3886 | msb_divisor_value = desired_divisor / iclk_pi_range; |
| 3887 | pi_value = desired_divisor % iclk_pi_range; |
| 3888 | |
| 3889 | auxdiv = 0; |
| 3890 | divsel = msb_divisor_value - 2; |
| 3891 | phaseinc = pi_value; |
| 3892 | } |
| 3893 | |
| 3894 | /* This should not happen with any sane values */ |
| 3895 | WARN_ON(SBI_SSCDIVINTPHASE_DIVSEL(divsel) & |
| 3896 | ~SBI_SSCDIVINTPHASE_DIVSEL_MASK); |
| 3897 | WARN_ON(SBI_SSCDIVINTPHASE_DIR(phasedir) & |
| 3898 | ~SBI_SSCDIVINTPHASE_INCVAL_MASK); |
| 3899 | |
| 3900 | 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] | 3901 | clock, |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3902 | auxdiv, |
| 3903 | divsel, |
| 3904 | phasedir, |
| 3905 | phaseinc); |
| 3906 | |
| 3907 | /* Program SSCDIVINTPHASE6 */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3908 | temp = intel_sbi_read(dev_priv, SBI_SSCDIVINTPHASE6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3909 | temp &= ~SBI_SSCDIVINTPHASE_DIVSEL_MASK; |
| 3910 | temp |= SBI_SSCDIVINTPHASE_DIVSEL(divsel); |
| 3911 | temp &= ~SBI_SSCDIVINTPHASE_INCVAL_MASK; |
| 3912 | temp |= SBI_SSCDIVINTPHASE_INCVAL(phaseinc); |
| 3913 | temp |= SBI_SSCDIVINTPHASE_DIR(phasedir); |
| 3914 | temp |= SBI_SSCDIVINTPHASE_PROPAGATE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3915 | intel_sbi_write(dev_priv, SBI_SSCDIVINTPHASE6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3916 | |
| 3917 | /* Program SSCAUXDIV */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3918 | temp = intel_sbi_read(dev_priv, SBI_SSCAUXDIV6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3919 | temp &= ~SBI_SSCAUXDIV_FINALDIV2SEL(1); |
| 3920 | temp |= SBI_SSCAUXDIV_FINALDIV2SEL(auxdiv); |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3921 | intel_sbi_write(dev_priv, SBI_SSCAUXDIV6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3922 | |
| 3923 | /* Enable modulator and associated divider */ |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3924 | temp = intel_sbi_read(dev_priv, SBI_SSCCTL6, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3925 | temp &= ~SBI_SSCCTL_DISABLE; |
Paulo Zanoni | 988d6ee | 2012-12-01 12:04:24 -0200 | [diff] [blame] | 3926 | intel_sbi_write(dev_priv, SBI_SSCCTL6, temp, SBI_ICLK); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3927 | |
| 3928 | /* Wait for initialization time */ |
| 3929 | udelay(24); |
| 3930 | |
| 3931 | I915_WRITE(PIXCLK_GATE, PIXCLK_GATE_UNGATE); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 3932 | |
| 3933 | mutex_unlock(&dev_priv->dpio_lock); |
Eugeni Dodonov | e615efe | 2012-05-09 15:37:26 -0300 | [diff] [blame] | 3934 | } |
| 3935 | |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3936 | static void ironlake_pch_transcoder_set_timings(struct intel_crtc *crtc, |
| 3937 | enum pipe pch_transcoder) |
| 3938 | { |
| 3939 | struct drm_device *dev = crtc->base.dev; |
| 3940 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3941 | enum transcoder cpu_transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 3942 | |
| 3943 | I915_WRITE(PCH_TRANS_HTOTAL(pch_transcoder), |
| 3944 | I915_READ(HTOTAL(cpu_transcoder))); |
| 3945 | I915_WRITE(PCH_TRANS_HBLANK(pch_transcoder), |
| 3946 | I915_READ(HBLANK(cpu_transcoder))); |
| 3947 | I915_WRITE(PCH_TRANS_HSYNC(pch_transcoder), |
| 3948 | I915_READ(HSYNC(cpu_transcoder))); |
| 3949 | |
| 3950 | I915_WRITE(PCH_TRANS_VTOTAL(pch_transcoder), |
| 3951 | I915_READ(VTOTAL(cpu_transcoder))); |
| 3952 | I915_WRITE(PCH_TRANS_VBLANK(pch_transcoder), |
| 3953 | I915_READ(VBLANK(cpu_transcoder))); |
| 3954 | I915_WRITE(PCH_TRANS_VSYNC(pch_transcoder), |
| 3955 | I915_READ(VSYNC(cpu_transcoder))); |
| 3956 | I915_WRITE(PCH_TRANS_VSYNCSHIFT(pch_transcoder), |
| 3957 | I915_READ(VSYNCSHIFT(cpu_transcoder))); |
| 3958 | } |
| 3959 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3960 | 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] | 3961 | { |
| 3962 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 3963 | uint32_t temp; |
| 3964 | |
| 3965 | temp = I915_READ(SOUTH_CHICKEN1); |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3966 | if (!!(temp & FDI_BC_BIFURCATION_SELECT) == enable) |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3967 | return; |
| 3968 | |
| 3969 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_B)) & FDI_RX_ENABLE); |
| 3970 | WARN_ON(I915_READ(FDI_RX_CTL(PIPE_C)) & FDI_RX_ENABLE); |
| 3971 | |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3972 | temp &= ~FDI_BC_BIFURCATION_SELECT; |
| 3973 | if (enable) |
| 3974 | temp |= FDI_BC_BIFURCATION_SELECT; |
| 3975 | |
| 3976 | DRM_DEBUG_KMS("%sabling fdi C rx\n", enable ? "en" : "dis"); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3977 | I915_WRITE(SOUTH_CHICKEN1, temp); |
| 3978 | POSTING_READ(SOUTH_CHICKEN1); |
| 3979 | } |
| 3980 | |
| 3981 | static void ivybridge_update_fdi_bc_bifurcation(struct intel_crtc *intel_crtc) |
| 3982 | { |
| 3983 | struct drm_device *dev = intel_crtc->base.dev; |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3984 | |
| 3985 | switch (intel_crtc->pipe) { |
| 3986 | case PIPE_A: |
| 3987 | break; |
| 3988 | case PIPE_B: |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 3989 | if (intel_crtc->config->fdi_lanes > 2) |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3990 | cpt_set_fdi_bc_bifurcation(dev, false); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3991 | else |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3992 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3993 | |
| 3994 | break; |
| 3995 | case PIPE_C: |
Ander Conselvan de Oliveira | 003632d | 2015-03-11 13:35:43 +0200 | [diff] [blame] | 3996 | cpt_set_fdi_bc_bifurcation(dev, true); |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 3997 | |
| 3998 | break; |
| 3999 | default: |
| 4000 | BUG(); |
| 4001 | } |
| 4002 | } |
| 4003 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4004 | /* |
| 4005 | * Enable PCH resources required for PCH ports: |
| 4006 | * - PCH PLLs |
| 4007 | * - FDI training & RX/TX |
| 4008 | * - update transcoder timings |
| 4009 | * - DP transcoding bits |
| 4010 | * - transcoder |
| 4011 | */ |
| 4012 | static void ironlake_pch_enable(struct drm_crtc *crtc) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 4013 | { |
| 4014 | struct drm_device *dev = crtc->dev; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 4015 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4016 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4017 | int pipe = intel_crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4018 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4019 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4020 | assert_pch_transcoder_disabled(dev_priv, pipe); |
Chris Wilson | e7e164d | 2012-05-11 09:21:25 +0100 | [diff] [blame] | 4021 | |
Daniel Vetter | 1fbc0d7 | 2013-10-29 12:04:08 +0100 | [diff] [blame] | 4022 | if (IS_IVYBRIDGE(dev)) |
| 4023 | ivybridge_update_fdi_bc_bifurcation(intel_crtc); |
| 4024 | |
Daniel Vetter | cd986ab | 2012-10-26 10:58:12 +0200 | [diff] [blame] | 4025 | /* Write the TU size bits before fdi link training, so that error |
| 4026 | * detection works. */ |
| 4027 | I915_WRITE(FDI_RX_TUSIZE1(pipe), |
| 4028 | I915_READ(PIPE_DATA_M1(pipe)) & TU_SIZE_MASK); |
| 4029 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4030 | /* For PCH output, training FDI link */ |
Jesse Barnes | 674cf96 | 2011-04-28 14:27:04 -0700 | [diff] [blame] | 4031 | dev_priv->display.fdi_link_train(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4032 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4033 | /* We need to program the right clock selection before writing the pixel |
| 4034 | * mutliplier into the DPLL. */ |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4035 | if (HAS_PCH_CPT(dev)) { |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4036 | u32 sel; |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 4037 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4038 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4039 | temp |= TRANS_DPLL_ENABLE(pipe); |
| 4040 | sel = TRANS_DPLLB_SEL(pipe); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4041 | if (intel_crtc->config->shared_dpll == DPLL_ID_PCH_PLL_B) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4042 | temp |= sel; |
| 4043 | else |
| 4044 | temp &= ~sel; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4045 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4046 | } |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4047 | |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4048 | /* XXX: pch pll's can be enabled any time before we enable the PCH |
| 4049 | * transcoder, and we actually should do this to not upset any PCH |
| 4050 | * transcoder that already use the clock when we share it. |
| 4051 | * |
| 4052 | * Note that enable_shared_dpll tries to do the right thing, but |
| 4053 | * get_shared_dpll unconditionally resets the pll - we need that to have |
| 4054 | * the right LVDS enable sequence. */ |
Daniel Vetter | 85b3894 | 2014-04-24 23:55:14 +0200 | [diff] [blame] | 4055 | intel_enable_shared_dpll(intel_crtc); |
Daniel Vetter | 3ad8a20 | 2013-06-05 13:34:32 +0200 | [diff] [blame] | 4056 | |
Jesse Barnes | d9b6cb5 | 2011-01-04 15:09:35 -0800 | [diff] [blame] | 4057 | /* set transcoder timing, panel must allow it */ |
| 4058 | assert_panel_unlocked(dev_priv, pipe); |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4059 | ironlake_pch_transcoder_set_timings(intel_crtc, pipe); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4060 | |
Paulo Zanoni | 303b81e | 2012-10-31 18:12:23 -0200 | [diff] [blame] | 4061 | intel_fdi_normal_train(crtc); |
Zhenyu Wang | 5e84e1a | 2010-10-28 16:38:08 +0800 | [diff] [blame] | 4062 | |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4063 | /* For PCH DP, enable TRANS_DP_CTL */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4064 | if (HAS_PCH_CPT(dev) && intel_crtc->config->has_dp_encoder) { |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 4065 | u32 bpc = (I915_READ(PIPECONF(pipe)) & PIPECONF_BPC_MASK) >> 5; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4066 | reg = TRANS_DP_CTL(pipe); |
| 4067 | temp = I915_READ(reg); |
| 4068 | temp &= ~(TRANS_DP_PORT_SEL_MASK | |
Eric Anholt | 220cad3 | 2010-11-18 09:32:58 +0800 | [diff] [blame] | 4069 | TRANS_DP_SYNC_MASK | |
| 4070 | TRANS_DP_BPC_MASK); |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4071 | temp |= (TRANS_DP_OUTPUT_ENABLE | |
| 4072 | TRANS_DP_ENH_FRAMING); |
Jesse Barnes | 9325c9f | 2011-06-24 12:19:21 -0700 | [diff] [blame] | 4073 | temp |= bpc << 9; /* same format but at 11:9 */ |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4074 | |
| 4075 | if (crtc->mode.flags & DRM_MODE_FLAG_PHSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4076 | temp |= TRANS_DP_HSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4077 | if (crtc->mode.flags & DRM_MODE_FLAG_PVSYNC) |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4078 | temp |= TRANS_DP_VSYNC_ACTIVE_HIGH; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4079 | |
| 4080 | switch (intel_trans_dp_port_sel(crtc)) { |
| 4081 | case PCH_DP_B: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4082 | temp |= TRANS_DP_PORT_SEL_B; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4083 | break; |
| 4084 | case PCH_DP_C: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4085 | temp |= TRANS_DP_PORT_SEL_C; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4086 | break; |
| 4087 | case PCH_DP_D: |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4088 | temp |= TRANS_DP_PORT_SEL_D; |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4089 | break; |
| 4090 | default: |
Daniel Vetter | e95d41e | 2012-10-26 10:58:16 +0200 | [diff] [blame] | 4091 | BUG(); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4092 | } |
| 4093 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4094 | I915_WRITE(reg, temp); |
Jesse Barnes | c98e9dc | 2010-09-10 10:57:18 -0700 | [diff] [blame] | 4095 | } |
| 4096 | |
Paulo Zanoni | b8a4f40 | 2012-10-31 18:12:42 -0200 | [diff] [blame] | 4097 | ironlake_enable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4098 | } |
| 4099 | |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4100 | static void lpt_pch_enable(struct drm_crtc *crtc) |
| 4101 | { |
| 4102 | struct drm_device *dev = crtc->dev; |
| 4103 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4104 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4105 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4106 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 4107 | assert_pch_transcoder_disabled(dev_priv, TRANSCODER_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4108 | |
Paulo Zanoni | 8c52b5e | 2012-10-31 18:12:24 -0200 | [diff] [blame] | 4109 | lpt_program_iclkip(crtc); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4110 | |
Paulo Zanoni | 0540e48 | 2012-10-31 18:12:40 -0200 | [diff] [blame] | 4111 | /* Set transcoder timing. */ |
Daniel Vetter | 275f01b2 | 2013-05-03 11:49:47 +0200 | [diff] [blame] | 4112 | ironlake_pch_transcoder_set_timings(intel_crtc, PIPE_A); |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4113 | |
Paulo Zanoni | 937bb61 | 2012-10-31 18:12:47 -0200 | [diff] [blame] | 4114 | lpt_enable_pch_transcoder(dev_priv, cpu_transcoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4115 | } |
| 4116 | |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 4117 | void intel_put_shared_dpll(struct intel_crtc *crtc) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4118 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4119 | struct intel_shared_dpll *pll = intel_crtc_to_shared_dpll(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4120 | |
| 4121 | if (pll == NULL) |
| 4122 | return; |
| 4123 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 4124 | if (!(pll->config.crtc_mask & (1 << crtc->pipe))) { |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 4125 | WARN(1, "bad %s crtc mask\n", pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4126 | return; |
| 4127 | } |
| 4128 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 4129 | pll->config.crtc_mask &= ~(1 << crtc->pipe); |
| 4130 | if (pll->config.crtc_mask == 0) { |
Daniel Vetter | f4a091c | 2013-06-10 17:28:22 +0200 | [diff] [blame] | 4131 | WARN_ON(pll->on); |
| 4132 | WARN_ON(pll->active); |
| 4133 | } |
| 4134 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4135 | crtc->config->shared_dpll = DPLL_ID_PRIVATE; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4136 | } |
| 4137 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4138 | struct intel_shared_dpll *intel_get_shared_dpll(struct intel_crtc *crtc, |
| 4139 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4140 | { |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4141 | 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] | 4142 | struct intel_shared_dpll *pll; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 4143 | enum intel_dpll_id i; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4144 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4145 | if (HAS_PCH_IBX(dev_priv->dev)) { |
| 4146 | /* Ironlake PCH has a fixed PLL->PCH pipe mapping. */ |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 4147 | i = (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4148 | pll = &dev_priv->shared_dplls[i]; |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4149 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4150 | DRM_DEBUG_KMS("CRTC:%d using pre-allocated %s\n", |
| 4151 | crtc->base.base.id, pll->name); |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4152 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4153 | WARN_ON(pll->new_config->crtc_mask); |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4154 | |
Daniel Vetter | 98b6bd9 | 2012-05-20 20:00:25 +0200 | [diff] [blame] | 4155 | goto found; |
| 4156 | } |
| 4157 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4158 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4159 | pll = &dev_priv->shared_dplls[i]; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4160 | |
| 4161 | /* Only want to check enabled timings first */ |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4162 | if (pll->new_config->crtc_mask == 0) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4163 | continue; |
| 4164 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4165 | if (memcmp(&crtc_state->dpll_hw_state, |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4166 | &pll->new_config->hw_state, |
| 4167 | sizeof(pll->new_config->hw_state)) == 0) { |
| 4168 | 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] | 4169 | crtc->base.base.id, pll->name, |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4170 | pll->new_config->crtc_mask, |
| 4171 | pll->active); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4172 | goto found; |
| 4173 | } |
| 4174 | } |
| 4175 | |
| 4176 | /* Ok no matching timings, maybe there's a free one? */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4177 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4178 | pll = &dev_priv->shared_dplls[i]; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4179 | if (pll->new_config->crtc_mask == 0) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4180 | DRM_DEBUG_KMS("CRTC:%d allocated %s\n", |
| 4181 | crtc->base.base.id, pll->name); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4182 | goto found; |
| 4183 | } |
| 4184 | } |
| 4185 | |
| 4186 | return NULL; |
| 4187 | |
| 4188 | found: |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4189 | if (pll->new_config->crtc_mask == 0) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4190 | pll->new_config->hw_state = crtc_state->dpll_hw_state; |
Daniel Vetter | f2a69f4 | 2014-05-20 15:19:19 +0200 | [diff] [blame] | 4191 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 4192 | crtc_state->shared_dpll = i; |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 4193 | DRM_DEBUG_DRIVER("using %s for pipe %c\n", pll->name, |
| 4194 | pipe_name(crtc->pipe)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 4195 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4196 | pll->new_config->crtc_mask |= 1 << crtc->pipe; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4197 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4198 | return pll; |
| 4199 | } |
| 4200 | |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4201 | /** |
| 4202 | * intel_shared_dpll_start_config - start a new PLL staged config |
| 4203 | * @dev_priv: DRM device |
| 4204 | * @clear_pipes: mask of pipes that will have their PLLs freed |
| 4205 | * |
| 4206 | * Starts a new PLL staged config, copying the current config but |
| 4207 | * releasing the references of pipes specified in clear_pipes. |
| 4208 | */ |
| 4209 | static int intel_shared_dpll_start_config(struct drm_i915_private *dev_priv, |
| 4210 | unsigned clear_pipes) |
| 4211 | { |
| 4212 | struct intel_shared_dpll *pll; |
| 4213 | enum intel_dpll_id i; |
| 4214 | |
| 4215 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4216 | pll = &dev_priv->shared_dplls[i]; |
| 4217 | |
| 4218 | pll->new_config = kmemdup(&pll->config, sizeof pll->config, |
| 4219 | GFP_KERNEL); |
| 4220 | if (!pll->new_config) |
| 4221 | goto cleanup; |
| 4222 | |
| 4223 | pll->new_config->crtc_mask &= ~clear_pipes; |
| 4224 | } |
| 4225 | |
| 4226 | return 0; |
| 4227 | |
| 4228 | cleanup: |
| 4229 | while (--i >= 0) { |
| 4230 | pll = &dev_priv->shared_dplls[i]; |
Ander Conselvan de Oliveira | f354d73 | 2014-11-07 14:07:41 +0200 | [diff] [blame] | 4231 | kfree(pll->new_config); |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 4232 | pll->new_config = NULL; |
| 4233 | } |
| 4234 | |
| 4235 | return -ENOMEM; |
| 4236 | } |
| 4237 | |
| 4238 | static void intel_shared_dpll_commit(struct drm_i915_private *dev_priv) |
| 4239 | { |
| 4240 | struct intel_shared_dpll *pll; |
| 4241 | enum intel_dpll_id i; |
| 4242 | |
| 4243 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4244 | pll = &dev_priv->shared_dplls[i]; |
| 4245 | |
| 4246 | WARN_ON(pll->new_config == &pll->config); |
| 4247 | |
| 4248 | pll->config = *pll->new_config; |
| 4249 | kfree(pll->new_config); |
| 4250 | pll->new_config = NULL; |
| 4251 | } |
| 4252 | } |
| 4253 | |
| 4254 | static void intel_shared_dpll_abort_config(struct drm_i915_private *dev_priv) |
| 4255 | { |
| 4256 | struct intel_shared_dpll *pll; |
| 4257 | enum intel_dpll_id i; |
| 4258 | |
| 4259 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 4260 | pll = &dev_priv->shared_dplls[i]; |
| 4261 | |
| 4262 | WARN_ON(pll->new_config == &pll->config); |
| 4263 | |
| 4264 | kfree(pll->new_config); |
| 4265 | pll->new_config = NULL; |
| 4266 | } |
| 4267 | } |
| 4268 | |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4269 | static void cpt_verify_modeset(struct drm_device *dev, int pipe) |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4270 | { |
| 4271 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 23670b32 | 2012-11-01 09:15:30 +0100 | [diff] [blame] | 4272 | int dslreg = PIPEDSL(pipe); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4273 | u32 temp; |
| 4274 | |
| 4275 | temp = I915_READ(dslreg); |
| 4276 | udelay(500); |
| 4277 | if (wait_for(I915_READ(dslreg) != temp, 5)) { |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4278 | if (wait_for(I915_READ(dslreg) != temp, 5)) |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 4279 | DRM_ERROR("mode set failed: pipe %c stuck\n", pipe_name(pipe)); |
Jesse Barnes | d4270e5 | 2011-10-11 10:43:02 -0700 | [diff] [blame] | 4280 | } |
| 4281 | } |
| 4282 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4283 | static void skylake_pfit_enable(struct intel_crtc *crtc) |
| 4284 | { |
| 4285 | struct drm_device *dev = crtc->base.dev; |
| 4286 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4287 | int pipe = crtc->pipe; |
| 4288 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4289 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4290 | I915_WRITE(PS_CTL(pipe), PS_ENABLE); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4291 | I915_WRITE(PS_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4292 | I915_WRITE(PS_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4293 | } |
| 4294 | } |
| 4295 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4296 | static void ironlake_pfit_enable(struct intel_crtc *crtc) |
| 4297 | { |
| 4298 | struct drm_device *dev = crtc->base.dev; |
| 4299 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4300 | int pipe = crtc->pipe; |
| 4301 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4302 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4303 | /* Force use of hard-coded filter coefficients |
| 4304 | * as some pre-programmed values are broken, |
| 4305 | * e.g. x201. |
| 4306 | */ |
| 4307 | if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) |
| 4308 | I915_WRITE(PF_CTL(pipe), PF_ENABLE | PF_FILTER_MED_3x3 | |
| 4309 | PF_PIPE_SEL_IVB(pipe)); |
| 4310 | else |
| 4311 | 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] | 4312 | I915_WRITE(PF_WIN_POS(pipe), crtc->config->pch_pfit.pos); |
| 4313 | I915_WRITE(PF_WIN_SZ(pipe), crtc->config->pch_pfit.size); |
Jesse Barnes | 040484a | 2011-01-03 12:14:26 -0800 | [diff] [blame] | 4314 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4315 | } |
| 4316 | |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4317 | static void intel_enable_sprite_planes(struct drm_crtc *crtc) |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4318 | { |
| 4319 | struct drm_device *dev = crtc->dev; |
| 4320 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4321 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4322 | struct intel_plane *intel_plane; |
| 4323 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4324 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 4325 | intel_plane = to_intel_plane(plane); |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4326 | if (intel_plane->pipe == pipe) |
| 4327 | intel_plane_restore(&intel_plane->base); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4328 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4329 | } |
| 4330 | |
Matt Roper | 0d703d4 | 2015-03-04 10:49:04 -0800 | [diff] [blame] | 4331 | /* |
| 4332 | * Disable a plane internally without actually modifying the plane's state. |
| 4333 | * This will allow us to easily restore the plane later by just reprogramming |
| 4334 | * its state. |
| 4335 | */ |
| 4336 | static void disable_plane_internal(struct drm_plane *plane) |
| 4337 | { |
| 4338 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 4339 | struct drm_plane_state *state = |
| 4340 | plane->funcs->atomic_duplicate_state(plane); |
| 4341 | struct intel_plane_state *intel_state = to_intel_plane_state(state); |
| 4342 | |
| 4343 | intel_state->visible = false; |
| 4344 | intel_plane->commit_plane(plane, intel_state); |
| 4345 | |
| 4346 | intel_plane_destroy_state(plane, state); |
| 4347 | } |
| 4348 | |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4349 | static void intel_disable_sprite_planes(struct drm_crtc *crtc) |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4350 | { |
| 4351 | struct drm_device *dev = crtc->dev; |
| 4352 | enum pipe pipe = to_intel_crtc(crtc)->pipe; |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4353 | struct drm_plane *plane; |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4354 | struct intel_plane *intel_plane; |
| 4355 | |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4356 | drm_for_each_legacy_plane(plane, &dev->mode_config.plane_list) { |
| 4357 | intel_plane = to_intel_plane(plane); |
Matt Roper | 0d703d4 | 2015-03-04 10:49:04 -0800 | [diff] [blame] | 4358 | if (plane->fb && intel_plane->pipe == pipe) |
| 4359 | disable_plane_internal(plane); |
Matt Roper | af2b653 | 2014-04-01 15:22:32 -0700 | [diff] [blame] | 4360 | } |
Ville Syrjälä | bb53d4a | 2013-06-04 13:49:04 +0300 | [diff] [blame] | 4361 | } |
| 4362 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4363 | void hsw_enable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4364 | { |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4365 | struct drm_device *dev = crtc->base.dev; |
| 4366 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4367 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4368 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4369 | return; |
| 4370 | |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4371 | /* We can only enable IPS after we enable a plane and wait for a vblank */ |
| 4372 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4373 | |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4374 | assert_plane_enabled(dev_priv, crtc->plane); |
Ville Syrjälä | cea165c | 2014-04-15 21:41:35 +0300 | [diff] [blame] | 4375 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4376 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4377 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0xc0000000)); |
| 4378 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 4379 | /* Quoting Art Runyan: "its not safe to expect any particular |
| 4380 | * value in IPS_CTL bit 31 after enabling IPS through the |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4381 | * mailbox." Moreover, the mailbox may return a bogus state, |
| 4382 | * so we need to just enable it and continue on. |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4383 | */ |
| 4384 | } else { |
| 4385 | I915_WRITE(IPS_CTL, IPS_ENABLE); |
| 4386 | /* The bit only becomes 1 in the next vblank, so this wait here |
| 4387 | * is essentially intel_wait_for_vblank. If we don't have this |
| 4388 | * and don't wait for vblanks until the end of crtc_enable, then |
| 4389 | * the HW state readout code will complain that the expected |
| 4390 | * IPS_CTL value is not the one we read. */ |
| 4391 | if (wait_for(I915_READ_NOTRACE(IPS_CTL) & IPS_ENABLE, 50)) |
| 4392 | DRM_ERROR("Timed out waiting for IPS enable\n"); |
| 4393 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4394 | } |
| 4395 | |
Ville Syrjälä | 20bc8673 | 2013-10-01 18:02:17 +0300 | [diff] [blame] | 4396 | void hsw_disable_ips(struct intel_crtc *crtc) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4397 | { |
| 4398 | struct drm_device *dev = crtc->base.dev; |
| 4399 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4400 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4401 | if (!crtc->config->ips_enabled) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4402 | return; |
| 4403 | |
| 4404 | assert_plane_enabled(dev_priv, crtc->plane); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4405 | if (IS_BROADWELL(dev)) { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4406 | mutex_lock(&dev_priv->rps.hw_lock); |
| 4407 | WARN_ON(sandybridge_pcode_write(dev_priv, DISPLAY_IPS_CONTROL, 0)); |
| 4408 | mutex_unlock(&dev_priv->rps.hw_lock); |
Ben Widawsky | 23d0b13 | 2014-04-10 14:32:41 -0700 | [diff] [blame] | 4409 | /* wait for pcode to finish disabling IPS, which may take up to 42ms */ |
| 4410 | if (wait_for((I915_READ(IPS_CTL) & IPS_ENABLE) == 0, 42)) |
| 4411 | DRM_ERROR("Timed out waiting for IPS disable\n"); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4412 | } else { |
Ben Widawsky | 2a114cc | 2013-11-02 21:07:47 -0700 | [diff] [blame] | 4413 | I915_WRITE(IPS_CTL, 0); |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 4414 | POSTING_READ(IPS_CTL); |
| 4415 | } |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4416 | |
| 4417 | /* We need to wait for a vblank before we can disable the plane. */ |
| 4418 | intel_wait_for_vblank(dev, crtc->pipe); |
| 4419 | } |
| 4420 | |
| 4421 | /** Loads the palette/gamma unit for the CRTC with the prepared values */ |
| 4422 | static void intel_crtc_load_lut(struct drm_crtc *crtc) |
| 4423 | { |
| 4424 | struct drm_device *dev = crtc->dev; |
| 4425 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4426 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4427 | enum pipe pipe = intel_crtc->pipe; |
| 4428 | int palreg = PALETTE(pipe); |
| 4429 | int i; |
| 4430 | bool reenable_ips = false; |
| 4431 | |
| 4432 | /* The clocks have to be on to load the palette. */ |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4433 | if (!crtc->state->enable || !intel_crtc->active) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4434 | return; |
| 4435 | |
| 4436 | if (!HAS_PCH_SPLIT(dev_priv->dev)) { |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 4437 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4438 | assert_dsi_pll_enabled(dev_priv); |
| 4439 | else |
| 4440 | assert_pll_enabled(dev_priv, pipe); |
| 4441 | } |
| 4442 | |
| 4443 | /* use legacy palette for Ironlake */ |
Sonika Jindal | 7a1db49 | 2014-07-22 11:18:27 +0530 | [diff] [blame] | 4444 | if (!HAS_GMCH_DISPLAY(dev)) |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4445 | palreg = LGC_PALETTE(pipe); |
| 4446 | |
| 4447 | /* Workaround : Do not read or write the pipe palette/gamma data while |
| 4448 | * GAMMA_MODE is configured for split gamma and IPS_CTL has IPS enabled. |
| 4449 | */ |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4450 | if (IS_HASWELL(dev) && intel_crtc->config->ips_enabled && |
Paulo Zanoni | d77e453 | 2013-09-24 13:52:55 -0300 | [diff] [blame] | 4451 | ((I915_READ(GAMMA_MODE(pipe)) & GAMMA_MODE_MODE_MASK) == |
| 4452 | GAMMA_MODE_MODE_SPLIT)) { |
| 4453 | hsw_disable_ips(intel_crtc); |
| 4454 | reenable_ips = true; |
| 4455 | } |
| 4456 | |
| 4457 | for (i = 0; i < 256; i++) { |
| 4458 | I915_WRITE(palreg + 4 * i, |
| 4459 | (intel_crtc->lut_r[i] << 16) | |
| 4460 | (intel_crtc->lut_g[i] << 8) | |
| 4461 | intel_crtc->lut_b[i]); |
| 4462 | } |
| 4463 | |
| 4464 | if (reenable_ips) |
| 4465 | hsw_enable_ips(intel_crtc); |
| 4466 | } |
| 4467 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4468 | static void intel_crtc_dpms_overlay(struct intel_crtc *intel_crtc, bool enable) |
| 4469 | { |
| 4470 | if (!enable && intel_crtc->overlay) { |
| 4471 | struct drm_device *dev = intel_crtc->base.dev; |
| 4472 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4473 | |
| 4474 | mutex_lock(&dev->struct_mutex); |
| 4475 | dev_priv->mm.interruptible = false; |
| 4476 | (void) intel_overlay_switch_off(intel_crtc->overlay); |
| 4477 | dev_priv->mm.interruptible = true; |
| 4478 | mutex_unlock(&dev->struct_mutex); |
| 4479 | } |
| 4480 | |
| 4481 | /* Let userspace switch the overlay on again. In most cases userspace |
| 4482 | * has to recompute where to put it anyway. |
| 4483 | */ |
| 4484 | } |
| 4485 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4486 | static void intel_crtc_enable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4487 | { |
| 4488 | struct drm_device *dev = crtc->dev; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4489 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4490 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4491 | |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 4492 | intel_enable_primary_hw_plane(crtc->primary, crtc); |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4493 | intel_enable_sprite_planes(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4494 | intel_crtc_update_cursor(crtc, true); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4495 | intel_crtc_dpms_overlay(intel_crtc, true); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4496 | |
| 4497 | hsw_enable_ips(intel_crtc); |
| 4498 | |
| 4499 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4500 | intel_fbc_update(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4501 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4502 | |
| 4503 | /* |
| 4504 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4505 | * to compute the mask of flip planes precisely. For the time being |
| 4506 | * consider this a flip from a NULL plane. |
| 4507 | */ |
| 4508 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4509 | } |
| 4510 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4511 | static void intel_crtc_disable_planes(struct drm_crtc *crtc) |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4512 | { |
| 4513 | struct drm_device *dev = crtc->dev; |
| 4514 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4515 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4516 | int pipe = intel_crtc->pipe; |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4517 | |
| 4518 | intel_crtc_wait_for_pending_flips(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4519 | |
Paulo Zanoni | e35fef2 | 2015-02-09 14:46:29 -0200 | [diff] [blame] | 4520 | if (dev_priv->fbc.crtc == intel_crtc) |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4521 | intel_fbc_disable(dev); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4522 | |
| 4523 | hsw_disable_ips(intel_crtc); |
| 4524 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4525 | intel_crtc_dpms_overlay(intel_crtc, false); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4526 | intel_crtc_update_cursor(crtc, false); |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 4527 | intel_disable_sprite_planes(crtc); |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 4528 | intel_disable_primary_hw_plane(crtc->primary, crtc); |
Ville Syrjälä | f98551a | 2014-05-22 17:48:06 +0300 | [diff] [blame] | 4529 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 4530 | /* |
| 4531 | * FIXME: Once we grow proper nuclear flip support out of this we need |
| 4532 | * to compute the mask of flip planes precisely. For the time being |
| 4533 | * consider this a flip to a NULL plane. |
| 4534 | */ |
| 4535 | intel_frontbuffer_flip(dev, INTEL_FRONTBUFFER_ALL_MASK(pipe)); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4536 | } |
| 4537 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4538 | static void ironlake_crtc_enable(struct drm_crtc *crtc) |
| 4539 | { |
| 4540 | struct drm_device *dev = crtc->dev; |
| 4541 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4542 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4543 | struct intel_encoder *encoder; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4544 | int pipe = intel_crtc->pipe; |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4545 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4546 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 4547 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4548 | if (intel_crtc->active) |
| 4549 | return; |
| 4550 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4551 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | b14b105 | 2014-04-24 23:55:13 +0200 | [diff] [blame] | 4552 | intel_prepare_shared_dpll(intel_crtc); |
| 4553 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4554 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48d | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4555 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4556 | |
| 4557 | intel_set_pipe_timings(intel_crtc); |
| 4558 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4559 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4560 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4561 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 29407aa | 2014-04-24 23:55:08 +0200 | [diff] [blame] | 4562 | } |
| 4563 | |
| 4564 | ironlake_set_pipeconf(crtc); |
| 4565 | |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4566 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4567 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4568 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
| 4569 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4570 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 4571 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Daniel Vetter | 952735e | 2013-06-05 13:34:27 +0200 | [diff] [blame] | 4572 | if (encoder->pre_enable) |
| 4573 | encoder->pre_enable(encoder); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4574 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4575 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | fff367c | 2012-10-27 15:50:28 +0200 | [diff] [blame] | 4576 | /* Note: FDI PLL enabling _must_ be done before we enable the |
| 4577 | * cpu pipes, hence this is separate from all the other fdi/pch |
| 4578 | * enabling. */ |
Daniel Vetter | 88cefb6 | 2012-08-12 19:27:14 +0200 | [diff] [blame] | 4579 | ironlake_fdi_pll_enable(intel_crtc); |
Daniel Vetter | 46b6f81 | 2012-09-06 22:08:33 +0200 | [diff] [blame] | 4580 | } else { |
| 4581 | assert_fdi_tx_disabled(dev_priv, pipe); |
| 4582 | assert_fdi_rx_disabled(dev_priv, pipe); |
| 4583 | } |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4584 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4585 | ironlake_pfit_enable(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4586 | |
Jesse Barnes | 9c54c0d | 2011-06-15 23:32:33 +0200 | [diff] [blame] | 4587 | /* |
| 4588 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4589 | * clocks enabled |
| 4590 | */ |
| 4591 | intel_crtc_load_lut(crtc); |
| 4592 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4593 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4594 | intel_enable_pipe(intel_crtc); |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4595 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4596 | if (intel_crtc->config->has_pch_encoder) |
Jesse Barnes | f67a559 | 2011-01-05 10:31:48 -0800 | [diff] [blame] | 4597 | ironlake_pch_enable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4598 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4599 | assert_vblank_disabled(crtc); |
| 4600 | drm_crtc_vblank_on(crtc); |
| 4601 | |
Daniel Vetter | fa5c73b | 2012-07-01 23:24:36 +0200 | [diff] [blame] | 4602 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4603 | encoder->enable(encoder); |
Daniel Vetter | 61b77dd | 2012-07-02 00:16:19 +0200 | [diff] [blame] | 4604 | |
| 4605 | if (HAS_PCH_CPT(dev)) |
Daniel Vetter | a152031 | 2013-05-03 11:49:50 +0200 | [diff] [blame] | 4606 | cpt_verify_modeset(dev, intel_crtc->pipe); |
Daniel Vetter | 6ce9410 | 2012-10-04 19:20:03 +0200 | [diff] [blame] | 4607 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4608 | intel_crtc_enable_planes(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4609 | } |
| 4610 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4611 | /* IPS only exists on ULT machines and is tied to pipe A. */ |
| 4612 | static bool hsw_crtc_supports_ips(struct intel_crtc *crtc) |
| 4613 | { |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 4614 | return HAS_IPS(crtc->base.dev) && crtc->pipe == PIPE_A; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4615 | } |
| 4616 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4617 | /* |
| 4618 | * This implements the workaround described in the "notes" section of the mode |
| 4619 | * set sequence documentation. When going from no pipes or single pipe to |
| 4620 | * multiple pipes, and planes are enabled after the pipe, we need to wait at |
| 4621 | * least 2 vblanks on the first pipe before enabling planes on the second pipe. |
| 4622 | */ |
| 4623 | static void haswell_mode_set_planes_workaround(struct intel_crtc *crtc) |
| 4624 | { |
| 4625 | struct drm_device *dev = crtc->base.dev; |
| 4626 | struct intel_crtc *crtc_it, *other_active_crtc = NULL; |
| 4627 | |
| 4628 | /* We want to get the other_active_crtc only if there's only 1 other |
| 4629 | * active crtc. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4630 | for_each_intel_crtc(dev, crtc_it) { |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4631 | if (!crtc_it->active || crtc_it == crtc) |
| 4632 | continue; |
| 4633 | |
| 4634 | if (other_active_crtc) |
| 4635 | return; |
| 4636 | |
| 4637 | other_active_crtc = crtc_it; |
| 4638 | } |
| 4639 | if (!other_active_crtc) |
| 4640 | return; |
| 4641 | |
| 4642 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4643 | intel_wait_for_vblank(dev, other_active_crtc->pipe); |
| 4644 | } |
| 4645 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4646 | static void haswell_crtc_enable(struct drm_crtc *crtc) |
| 4647 | { |
| 4648 | struct drm_device *dev = crtc->dev; |
| 4649 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4650 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4651 | struct intel_encoder *encoder; |
| 4652 | int pipe = intel_crtc->pipe; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4653 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 4654 | WARN_ON(!crtc->state->enable); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4655 | |
| 4656 | if (intel_crtc->active) |
| 4657 | return; |
| 4658 | |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4659 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4660 | intel_enable_shared_dpll(intel_crtc); |
| 4661 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4662 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48d | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 4663 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4664 | |
| 4665 | intel_set_pipe_timings(intel_crtc); |
| 4666 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4667 | if (intel_crtc->config->cpu_transcoder != TRANSCODER_EDP) { |
| 4668 | I915_WRITE(PIPE_MULT(intel_crtc->config->cpu_transcoder), |
| 4669 | intel_crtc->config->pixel_multiplier - 1); |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 4670 | } |
| 4671 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4672 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4673 | intel_cpu_transcoder_set_m_n(intel_crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4674 | &intel_crtc->config->fdi_m_n, NULL); |
Daniel Vetter | 229fca9 | 2014-04-24 23:55:09 +0200 | [diff] [blame] | 4675 | } |
| 4676 | |
| 4677 | haswell_set_pipeconf(crtc); |
| 4678 | |
| 4679 | intel_set_pipe_csc(crtc); |
| 4680 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4681 | intel_crtc->active = true; |
Paulo Zanoni | 8664281 | 2013-04-12 17:57:57 -0300 | [diff] [blame] | 4682 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4683 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4684 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4685 | if (encoder->pre_enable) |
| 4686 | encoder->pre_enable(encoder); |
| 4687 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4688 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4689 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4690 | true); |
Imre Deak | 4fe9467 | 2014-06-25 22:01:49 +0300 | [diff] [blame] | 4691 | dev_priv->display.fdi_link_train(crtc); |
| 4692 | } |
| 4693 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4694 | intel_ddi_enable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4695 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4696 | if (IS_SKYLAKE(dev)) |
| 4697 | skylake_pfit_enable(intel_crtc); |
| 4698 | else |
| 4699 | ironlake_pfit_enable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4700 | |
| 4701 | /* |
| 4702 | * On ILK+ LUT must be loaded before the pipe is running but with |
| 4703 | * clocks enabled |
| 4704 | */ |
| 4705 | intel_crtc_load_lut(crtc); |
| 4706 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4707 | intel_ddi_set_pipe_settings(crtc); |
Damien Lespiau | 8228c25 | 2013-03-07 15:30:27 +0000 | [diff] [blame] | 4708 | intel_ddi_enable_transcoder_func(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4709 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 4710 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 4711 | intel_enable_pipe(intel_crtc); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 4712 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4713 | if (intel_crtc->config->has_pch_encoder) |
Paulo Zanoni | 1507e5b | 2012-10-31 18:12:22 -0200 | [diff] [blame] | 4714 | lpt_pch_enable(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4715 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4716 | if (intel_crtc->config->dp_encoder_is_mst) |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4717 | intel_ddi_set_vc_payload_alloc(crtc, true); |
| 4718 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4719 | assert_vblank_disabled(crtc); |
| 4720 | drm_crtc_vblank_on(crtc); |
| 4721 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4722 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4723 | encoder->enable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4724 | intel_opregion_notify_encoder(encoder, true); |
| 4725 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4726 | |
Paulo Zanoni | e491694 | 2013-09-20 16:21:19 -0300 | [diff] [blame] | 4727 | /* If we change the relative order between pipe/planes enabling, we need |
| 4728 | * to change the workaround. */ |
| 4729 | haswell_mode_set_planes_workaround(intel_crtc); |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4730 | intel_crtc_enable_planes(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4731 | } |
| 4732 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4733 | static void skylake_pfit_disable(struct intel_crtc *crtc) |
| 4734 | { |
| 4735 | struct drm_device *dev = crtc->base.dev; |
| 4736 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4737 | int pipe = crtc->pipe; |
| 4738 | |
| 4739 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4740 | * 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] | 4741 | if (crtc->config->pch_pfit.enabled) { |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4742 | I915_WRITE(PS_CTL(pipe), 0); |
| 4743 | I915_WRITE(PS_WIN_POS(pipe), 0); |
| 4744 | I915_WRITE(PS_WIN_SZ(pipe), 0); |
| 4745 | } |
| 4746 | } |
| 4747 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4748 | static void ironlake_pfit_disable(struct intel_crtc *crtc) |
| 4749 | { |
| 4750 | struct drm_device *dev = crtc->base.dev; |
| 4751 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4752 | int pipe = crtc->pipe; |
| 4753 | |
| 4754 | /* To avoid upsetting the power well on haswell only disable the pfit if |
| 4755 | * 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] | 4756 | if (crtc->config->pch_pfit.enabled) { |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4757 | I915_WRITE(PF_CTL(pipe), 0); |
| 4758 | I915_WRITE(PF_WIN_POS(pipe), 0); |
| 4759 | I915_WRITE(PF_WIN_SZ(pipe), 0); |
| 4760 | } |
| 4761 | } |
| 4762 | |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4763 | static void ironlake_crtc_disable(struct drm_crtc *crtc) |
| 4764 | { |
| 4765 | struct drm_device *dev = crtc->dev; |
| 4766 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4767 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 4768 | struct intel_encoder *encoder; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4769 | int pipe = intel_crtc->pipe; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 4770 | u32 reg, temp; |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4771 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4772 | if (!intel_crtc->active) |
| 4773 | return; |
| 4774 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4775 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | a5c4d7b | 2014-03-07 18:32:13 +0200 | [diff] [blame] | 4776 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 4777 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4778 | encoder->disable(encoder); |
| 4779 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4780 | drm_crtc_vblank_off(crtc); |
| 4781 | assert_vblank_disabled(crtc); |
| 4782 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4783 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4784 | intel_set_pch_fifo_underrun_reporting(dev_priv, pipe, false); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4785 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4786 | intel_disable_pipe(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4787 | |
Daniel Vetter | 3f8dce3 | 2013-05-08 10:36:30 +0200 | [diff] [blame] | 4788 | ironlake_pfit_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4789 | |
Daniel Vetter | bf49ec8 | 2012-09-06 22:15:40 +0200 | [diff] [blame] | 4790 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4791 | if (encoder->post_disable) |
| 4792 | encoder->post_disable(encoder); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4793 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4794 | if (intel_crtc->config->has_pch_encoder) { |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4795 | ironlake_fdi_disable(crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4796 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4797 | ironlake_disable_pch_transcoder(dev_priv, pipe); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4798 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4799 | if (HAS_PCH_CPT(dev)) { |
| 4800 | /* disable TRANS_DP_CTL */ |
| 4801 | reg = TRANS_DP_CTL(pipe); |
| 4802 | temp = I915_READ(reg); |
| 4803 | temp &= ~(TRANS_DP_OUTPUT_ENABLE | |
| 4804 | TRANS_DP_PORT_SEL_MASK); |
| 4805 | temp |= TRANS_DP_PORT_SEL_NONE; |
| 4806 | I915_WRITE(reg, temp); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4807 | |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4808 | /* disable DPLL_SEL */ |
| 4809 | temp = I915_READ(PCH_DPLL_SEL); |
Daniel Vetter | 1188739 | 2013-06-05 13:34:09 +0200 | [diff] [blame] | 4810 | temp &= ~(TRANS_DPLL_ENABLE(pipe) | TRANS_DPLLB_SEL(pipe)); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4811 | I915_WRITE(PCH_DPLL_SEL, temp); |
Jesse Barnes | 9db4a9c | 2011-02-07 12:26:52 -0800 | [diff] [blame] | 4812 | } |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4813 | |
| 4814 | /* disable PCH DPLL */ |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4815 | intel_disable_shared_dpll(intel_crtc); |
Daniel Vetter | d925c59 | 2013-06-05 13:34:04 +0200 | [diff] [blame] | 4816 | |
| 4817 | ironlake_fdi_pll_disable(intel_crtc); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4818 | } |
| 4819 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 4820 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4821 | intel_update_watermarks(crtc); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4822 | |
| 4823 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4824 | intel_fbc_update(dev); |
Ben Widawsky | d1ebd816 | 2011-04-25 20:11:50 +0100 | [diff] [blame] | 4825 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 6be4a60 | 2010-09-10 10:26:01 -0700 | [diff] [blame] | 4826 | } |
| 4827 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4828 | static void haswell_crtc_disable(struct drm_crtc *crtc) |
| 4829 | { |
| 4830 | struct drm_device *dev = crtc->dev; |
| 4831 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4832 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4833 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4834 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4835 | |
| 4836 | if (!intel_crtc->active) |
| 4837 | return; |
| 4838 | |
Ville Syrjälä | d3eedb1 | 2014-05-08 19:23:13 +0300 | [diff] [blame] | 4839 | intel_crtc_disable_planes(crtc); |
Ville Syrjälä | dda9a66 | 2013-09-19 17:00:37 -0300 | [diff] [blame] | 4840 | |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4841 | for_each_encoder_on_crtc(dev, crtc, encoder) { |
| 4842 | intel_opregion_notify_encoder(encoder, false); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4843 | encoder->disable(encoder); |
Jani Nikula | 8807e55 | 2013-08-30 19:40:32 +0300 | [diff] [blame] | 4844 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4845 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 4846 | drm_crtc_vblank_off(crtc); |
| 4847 | assert_vblank_disabled(crtc); |
| 4848 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4849 | if (intel_crtc->config->has_pch_encoder) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 4850 | intel_set_pch_fifo_underrun_reporting(dev_priv, TRANSCODER_A, |
| 4851 | false); |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 4852 | intel_disable_pipe(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4853 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4854 | if (intel_crtc->config->dp_encoder_is_mst) |
Ville Syrjälä | a4bf214 | 2014-08-18 21:27:34 +0300 | [diff] [blame] | 4855 | intel_ddi_set_vc_payload_alloc(crtc, false); |
| 4856 | |
Paulo Zanoni | ad80a81 | 2012-10-24 16:06:19 -0200 | [diff] [blame] | 4857 | intel_ddi_disable_transcoder_func(dev_priv, cpu_transcoder); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4858 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 4859 | if (IS_SKYLAKE(dev)) |
| 4860 | skylake_pfit_disable(intel_crtc); |
| 4861 | else |
| 4862 | ironlake_pfit_disable(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4863 | |
Paulo Zanoni | 1f54438 | 2012-10-24 11:32:00 -0200 | [diff] [blame] | 4864 | intel_ddi_disable_pipe_clock(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4865 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4866 | if (intel_crtc->config->has_pch_encoder) { |
Paulo Zanoni | ab4d966 | 2012-10-31 18:12:55 -0200 | [diff] [blame] | 4867 | lpt_disable_pch_transcoder(dev_priv); |
Paulo Zanoni | 1ad960f | 2012-11-01 21:05:05 -0200 | [diff] [blame] | 4868 | intel_ddi_fdi_disable(crtc); |
Paulo Zanoni | 8361663 | 2012-10-23 18:29:54 -0200 | [diff] [blame] | 4869 | } |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4870 | |
Imre Deak | 97b040a | 2014-06-25 22:01:50 +0300 | [diff] [blame] | 4871 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 4872 | if (encoder->post_disable) |
| 4873 | encoder->post_disable(encoder); |
| 4874 | |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4875 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 4876 | intel_update_watermarks(crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4877 | |
| 4878 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 4879 | intel_fbc_update(dev); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4880 | mutex_unlock(&dev->struct_mutex); |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 4881 | |
| 4882 | if (intel_crtc_to_shared_dpll(intel_crtc)) |
| 4883 | intel_disable_shared_dpll(intel_crtc); |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 4884 | } |
| 4885 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4886 | static void ironlake_crtc_off(struct drm_crtc *crtc) |
| 4887 | { |
| 4888 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 4889 | intel_put_shared_dpll(intel_crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 4890 | } |
| 4891 | |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 4892 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4893 | static void i9xx_pfit_enable(struct intel_crtc *crtc) |
| 4894 | { |
| 4895 | struct drm_device *dev = crtc->base.dev; |
| 4896 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4897 | struct intel_crtc_state *pipe_config = crtc->config; |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4898 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 4899 | if (!pipe_config->gmch_pfit.control) |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4900 | return; |
| 4901 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 4902 | /* |
| 4903 | * The panel fitter should only be adjusted whilst the pipe is disabled, |
| 4904 | * according to register description and PRM. |
| 4905 | */ |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4906 | WARN_ON(I915_READ(PFIT_CONTROL) & PFIT_ENABLE); |
| 4907 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 4908 | |
Jesse Barnes | b074cec | 2013-04-25 12:55:02 -0700 | [diff] [blame] | 4909 | I915_WRITE(PFIT_PGM_RATIOS, pipe_config->gmch_pfit.pgm_ratios); |
| 4910 | I915_WRITE(PFIT_CONTROL, pipe_config->gmch_pfit.control); |
Daniel Vetter | 5a80c45 | 2013-04-25 22:52:18 +0200 | [diff] [blame] | 4911 | |
| 4912 | /* Border color in case we don't scale up to the full screen. Black by |
| 4913 | * default, change to something else for debugging. */ |
| 4914 | I915_WRITE(BCLRPAT(crtc->pipe), 0); |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 4915 | } |
| 4916 | |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4917 | static enum intel_display_power_domain port_to_power_domain(enum port port) |
| 4918 | { |
| 4919 | switch (port) { |
| 4920 | case PORT_A: |
| 4921 | return POWER_DOMAIN_PORT_DDI_A_4_LANES; |
| 4922 | case PORT_B: |
| 4923 | return POWER_DOMAIN_PORT_DDI_B_4_LANES; |
| 4924 | case PORT_C: |
| 4925 | return POWER_DOMAIN_PORT_DDI_C_4_LANES; |
| 4926 | case PORT_D: |
| 4927 | return POWER_DOMAIN_PORT_DDI_D_4_LANES; |
| 4928 | default: |
| 4929 | WARN_ON_ONCE(1); |
| 4930 | return POWER_DOMAIN_PORT_OTHER; |
| 4931 | } |
| 4932 | } |
| 4933 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4934 | #define for_each_power_domain(domain, mask) \ |
| 4935 | for ((domain) = 0; (domain) < POWER_DOMAIN_NUM; (domain)++) \ |
| 4936 | if ((1 << (domain)) & (mask)) |
| 4937 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4938 | enum intel_display_power_domain |
| 4939 | intel_display_port_power_domain(struct intel_encoder *intel_encoder) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4940 | { |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4941 | struct drm_device *dev = intel_encoder->base.dev; |
| 4942 | struct intel_digital_port *intel_dig_port; |
| 4943 | |
| 4944 | switch (intel_encoder->type) { |
| 4945 | case INTEL_OUTPUT_UNKNOWN: |
| 4946 | /* Only DDI platforms should ever use this output type */ |
| 4947 | WARN_ON_ONCE(!HAS_DDI(dev)); |
| 4948 | case INTEL_OUTPUT_DISPLAYPORT: |
| 4949 | case INTEL_OUTPUT_HDMI: |
| 4950 | case INTEL_OUTPUT_EDP: |
| 4951 | intel_dig_port = enc_to_dig_port(&intel_encoder->base); |
Dave Airlie | d05410f | 2014-06-05 13:22:59 +1000 | [diff] [blame] | 4952 | return port_to_power_domain(intel_dig_port->port); |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 4953 | case INTEL_OUTPUT_DP_MST: |
| 4954 | intel_dig_port = enc_to_mst(&intel_encoder->base)->primary; |
| 4955 | return port_to_power_domain(intel_dig_port->port); |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4956 | case INTEL_OUTPUT_ANALOG: |
| 4957 | return POWER_DOMAIN_PORT_CRT; |
| 4958 | case INTEL_OUTPUT_DSI: |
| 4959 | return POWER_DOMAIN_PORT_DSI; |
| 4960 | default: |
| 4961 | return POWER_DOMAIN_PORT_OTHER; |
| 4962 | } |
| 4963 | } |
| 4964 | |
| 4965 | static unsigned long get_crtc_power_domains(struct drm_crtc *crtc) |
| 4966 | { |
| 4967 | struct drm_device *dev = crtc->dev; |
| 4968 | struct intel_encoder *intel_encoder; |
| 4969 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 4970 | enum pipe pipe = intel_crtc->pipe; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4971 | unsigned long mask; |
| 4972 | enum transcoder transcoder; |
| 4973 | |
| 4974 | transcoder = intel_pipe_to_cpu_transcoder(dev->dev_private, pipe); |
| 4975 | |
| 4976 | mask = BIT(POWER_DOMAIN_PIPE(pipe)); |
| 4977 | mask |= BIT(POWER_DOMAIN_TRANSCODER(transcoder)); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 4978 | if (intel_crtc->config->pch_pfit.enabled || |
| 4979 | intel_crtc->config->pch_pfit.force_thru) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4980 | mask |= BIT(POWER_DOMAIN_PIPE_PANEL_FITTER(pipe)); |
| 4981 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 4982 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 4983 | mask |= BIT(intel_display_port_power_domain(intel_encoder)); |
| 4984 | |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4985 | return mask; |
| 4986 | } |
| 4987 | |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 4988 | static void modeset_update_crtc_power_domains(struct drm_atomic_state *state) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4989 | { |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 4990 | struct drm_device *dev = state->dev; |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 4991 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 4992 | unsigned long pipe_domains[I915_MAX_PIPES] = { 0, }; |
| 4993 | struct intel_crtc *crtc; |
| 4994 | |
| 4995 | /* |
| 4996 | * First get all needed power domains, then put all unneeded, to avoid |
| 4997 | * any unnecessary toggling of the power wells. |
| 4998 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 4999 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5000 | enum intel_display_power_domain domain; |
| 5001 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5002 | if (!crtc->base.state->enable) |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5003 | continue; |
| 5004 | |
Imre Deak | 319be8a | 2014-03-04 19:22:57 +0200 | [diff] [blame] | 5005 | pipe_domains[crtc->pipe] = get_crtc_power_domains(&crtc->base); |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5006 | |
| 5007 | for_each_power_domain(domain, pipe_domains[crtc->pipe]) |
| 5008 | intel_display_power_get(dev_priv, domain); |
| 5009 | } |
| 5010 | |
Ville Syrjälä | 50f6e50 | 2014-11-06 14:49:12 +0200 | [diff] [blame] | 5011 | if (dev_priv->display.modeset_global_resources) |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5012 | dev_priv->display.modeset_global_resources(state); |
Ville Syrjälä | 50f6e50 | 2014-11-06 14:49:12 +0200 | [diff] [blame] | 5013 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5014 | for_each_intel_crtc(dev, crtc) { |
Imre Deak | 77d22dc | 2014-03-05 16:20:52 +0200 | [diff] [blame] | 5015 | enum intel_display_power_domain domain; |
| 5016 | |
| 5017 | for_each_power_domain(domain, crtc->enabled_power_domains) |
| 5018 | intel_display_power_put(dev_priv, domain); |
| 5019 | |
| 5020 | crtc->enabled_power_domains = pipe_domains[crtc->pipe]; |
| 5021 | } |
| 5022 | |
| 5023 | intel_display_set_init_power(dev_priv, false); |
| 5024 | } |
| 5025 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5026 | /* returns HPLL frequency in kHz */ |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5027 | static int valleyview_get_vco(struct drm_i915_private *dev_priv) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5028 | { |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 5029 | int hpll_freq, vco_freq[] = { 800, 1600, 2000, 2400 }; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5030 | |
Jesse Barnes | 586f49d | 2013-11-04 16:06:59 -0800 | [diff] [blame] | 5031 | /* Obtain SKU information */ |
| 5032 | mutex_lock(&dev_priv->dpio_lock); |
| 5033 | hpll_freq = vlv_cck_read(dev_priv, CCK_FUSE_REG) & |
| 5034 | CCK_FUSE_HPLL_FREQ_MASK; |
| 5035 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5036 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5037 | return vco_freq[hpll_freq] * 1000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5038 | } |
| 5039 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5040 | static void vlv_update_cdclk(struct drm_device *dev) |
| 5041 | { |
| 5042 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5043 | |
| 5044 | 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] | 5045 | DRM_DEBUG_DRIVER("Current CD clock rate: %d kHz\n", |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5046 | dev_priv->vlv_cdclk_freq); |
| 5047 | |
| 5048 | /* |
| 5049 | * Program the gmbus_freq based on the cdclk frequency. |
| 5050 | * BSpec erroneously claims we should aim for 4MHz, but |
| 5051 | * in fact 1MHz is the correct frequency. |
| 5052 | */ |
Ville Syrjälä | 6be1e3d | 2014-10-16 20:52:31 +0300 | [diff] [blame] | 5053 | 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] | 5054 | } |
| 5055 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5056 | /* Adjust CDclk dividers to allow high res or save power if possible */ |
| 5057 | static void valleyview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5058 | { |
| 5059 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5060 | u32 val, cmd; |
| 5061 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 5062 | 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] | 5063 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5064 | if (cdclk >= 320000) /* jump to highest voltage for 400MHz too */ |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5065 | cmd = 2; |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5066 | else if (cdclk == 266667) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5067 | cmd = 1; |
| 5068 | else |
| 5069 | cmd = 0; |
| 5070 | |
| 5071 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5072 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5073 | val &= ~DSPFREQGUAR_MASK; |
| 5074 | val |= (cmd << DSPFREQGUAR_SHIFT); |
| 5075 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5076 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5077 | DSPFREQSTAT_MASK) == (cmd << DSPFREQSTAT_SHIFT), |
| 5078 | 50)) { |
| 5079 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5080 | } |
| 5081 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5082 | |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5083 | if (cdclk == 400000) { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5084 | u32 divider; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5085 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5086 | divider = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5087 | |
| 5088 | mutex_lock(&dev_priv->dpio_lock); |
| 5089 | /* adjust cdclk divider */ |
| 5090 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
Ville Syrjälä | 9cf33db | 2014-06-13 13:37:48 +0300 | [diff] [blame] | 5091 | val &= ~DISPLAY_FREQUENCY_VALUES; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5092 | val |= divider; |
| 5093 | vlv_cck_write(dev_priv, CCK_DISPLAY_CLOCK_CONTROL, val); |
Ville Syrjälä | a877e80 | 2014-06-13 13:37:52 +0300 | [diff] [blame] | 5094 | |
| 5095 | if (wait_for((vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL) & |
| 5096 | DISPLAY_FREQUENCY_STATUS) == (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 5097 | 50)) |
| 5098 | DRM_ERROR("timed out waiting for CDclk change\n"); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5099 | mutex_unlock(&dev_priv->dpio_lock); |
| 5100 | } |
| 5101 | |
| 5102 | mutex_lock(&dev_priv->dpio_lock); |
| 5103 | /* adjust self-refresh exit latency value */ |
| 5104 | val = vlv_bunit_read(dev_priv, BUNIT_REG_BISOC); |
| 5105 | val &= ~0x7f; |
| 5106 | |
| 5107 | /* |
| 5108 | * For high bandwidth configs, we set a higher latency in the bunit |
| 5109 | * so that the core display fetch happens in time to avoid underruns. |
| 5110 | */ |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5111 | if (cdclk == 400000) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5112 | val |= 4500 / 250; /* 4.5 usec */ |
| 5113 | else |
| 5114 | val |= 3000 / 250; /* 3.0 usec */ |
| 5115 | vlv_bunit_write(dev_priv, BUNIT_REG_BISOC, val); |
| 5116 | mutex_unlock(&dev_priv->dpio_lock); |
| 5117 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 5118 | vlv_update_cdclk(dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5119 | } |
| 5120 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5121 | static void cherryview_set_cdclk(struct drm_device *dev, int cdclk) |
| 5122 | { |
| 5123 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5124 | u32 val, cmd; |
| 5125 | |
| 5126 | WARN_ON(dev_priv->display.get_display_clock_speed(dev) != dev_priv->vlv_cdclk_freq); |
| 5127 | |
| 5128 | switch (cdclk) { |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5129 | case 333333: |
| 5130 | case 320000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5131 | case 266667: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5132 | case 200000: |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5133 | break; |
| 5134 | default: |
Daniel Vetter | 5f77eeb | 2014-12-08 16:40:10 +0100 | [diff] [blame] | 5135 | MISSING_CASE(cdclk); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5136 | return; |
| 5137 | } |
| 5138 | |
Ville Syrjälä | 9d0d3fd | 2015-03-02 20:07:17 +0200 | [diff] [blame] | 5139 | /* |
| 5140 | * Specs are full of misinformation, but testing on actual |
| 5141 | * hardware has shown that we just need to write the desired |
| 5142 | * CCK divider into the Punit register. |
| 5143 | */ |
| 5144 | cmd = DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, cdclk) - 1; |
| 5145 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5146 | mutex_lock(&dev_priv->rps.hw_lock); |
| 5147 | val = vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ); |
| 5148 | val &= ~DSPFREQGUAR_MASK_CHV; |
| 5149 | val |= (cmd << DSPFREQGUAR_SHIFT_CHV); |
| 5150 | vlv_punit_write(dev_priv, PUNIT_REG_DSPFREQ, val); |
| 5151 | if (wait_for((vlv_punit_read(dev_priv, PUNIT_REG_DSPFREQ) & |
| 5152 | DSPFREQSTAT_MASK_CHV) == (cmd << DSPFREQSTAT_SHIFT_CHV), |
| 5153 | 50)) { |
| 5154 | DRM_ERROR("timed out waiting for CDclk change\n"); |
| 5155 | } |
| 5156 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 5157 | |
| 5158 | vlv_update_cdclk(dev); |
| 5159 | } |
| 5160 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5161 | static int valleyview_calc_cdclk(struct drm_i915_private *dev_priv, |
| 5162 | int max_pixclk) |
| 5163 | { |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 5164 | 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] | 5165 | int limit = IS_CHERRYVIEW(dev_priv) ? 95 : 90; |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5166 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5167 | /* |
| 5168 | * Really only a few cases to deal with, as only 4 CDclks are supported: |
| 5169 | * 200MHz |
| 5170 | * 267MHz |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5171 | * 320/333MHz (depends on HPLL freq) |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5172 | * 400MHz (VLV only) |
| 5173 | * So we check to see whether we're above 90% (VLV) or 95% (CHV) |
| 5174 | * of the lower bin and adjust if needed. |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5175 | * |
| 5176 | * We seem to get an unstable or solid color picture at 200MHz. |
| 5177 | * Not sure what's wrong. For now use 200MHz only when all pipes |
| 5178 | * are off. |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5179 | */ |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5180 | if (!IS_CHERRYVIEW(dev_priv) && |
| 5181 | max_pixclk > freq_320*limit/100) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5182 | return 400000; |
Ville Syrjälä | 6cca319 | 2015-03-02 20:07:16 +0200 | [diff] [blame] | 5183 | else if (max_pixclk > 266667*limit/100) |
Ville Syrjälä | 29dc7ef | 2014-06-13 13:37:50 +0300 | [diff] [blame] | 5184 | return freq_320; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5185 | else if (max_pixclk > 0) |
Ville Syrjälä | dfcab17 | 2014-06-13 13:37:47 +0300 | [diff] [blame] | 5186 | return 266667; |
Ville Syrjälä | e37c67a | 2014-06-13 13:37:51 +0300 | [diff] [blame] | 5187 | else |
| 5188 | return 200000; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5189 | } |
| 5190 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5191 | /* compute the max pixel clock for new configuration */ |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5192 | static int intel_mode_max_pixclk(struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5193 | { |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5194 | struct drm_device *dev = state->dev; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5195 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5196 | struct intel_crtc_state *crtc_state; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5197 | int max_pixclk = 0; |
| 5198 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 5199 | for_each_intel_crtc(dev, intel_crtc) { |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5200 | crtc_state = intel_atomic_get_crtc_state(state, intel_crtc); |
| 5201 | if (IS_ERR(crtc_state)) |
| 5202 | return PTR_ERR(crtc_state); |
| 5203 | |
| 5204 | if (!crtc_state->base.enable) |
| 5205 | continue; |
| 5206 | |
| 5207 | max_pixclk = max(max_pixclk, |
| 5208 | crtc_state->base.adjusted_mode.crtc_clock); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5209 | } |
| 5210 | |
| 5211 | return max_pixclk; |
| 5212 | } |
| 5213 | |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5214 | static int valleyview_modeset_global_pipes(struct drm_atomic_state *state, |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5215 | unsigned *prepare_pipes) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5216 | { |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5217 | struct drm_i915_private *dev_priv = to_i915(state->dev); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5218 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5219 | int max_pixclk = intel_mode_max_pixclk(state); |
| 5220 | |
| 5221 | if (max_pixclk < 0) |
| 5222 | return max_pixclk; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5223 | |
Imre Deak | d60c447 | 2014-03-27 17:45:10 +0200 | [diff] [blame] | 5224 | if (valleyview_calc_cdclk(dev_priv, max_pixclk) == |
| 5225 | dev_priv->vlv_cdclk_freq) |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5226 | return 0; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5227 | |
Ville Syrjälä | 2f2d7aa | 2014-01-10 11:28:08 +0200 | [diff] [blame] | 5228 | /* disable/enable all currently active pipes while we change cdclk */ |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5229 | for_each_intel_crtc(state->dev, intel_crtc) |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5230 | if (intel_crtc->base.state->enable) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5231 | *prepare_pipes |= (1 << intel_crtc->pipe); |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5232 | |
| 5233 | return 0; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5234 | } |
| 5235 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5236 | static void vlv_program_pfi_credits(struct drm_i915_private *dev_priv) |
| 5237 | { |
| 5238 | unsigned int credits, default_credits; |
| 5239 | |
| 5240 | if (IS_CHERRYVIEW(dev_priv)) |
| 5241 | default_credits = PFI_CREDIT(12); |
| 5242 | else |
| 5243 | default_credits = PFI_CREDIT(8); |
| 5244 | |
| 5245 | if (DIV_ROUND_CLOSEST(dev_priv->vlv_cdclk_freq, 1000) >= dev_priv->rps.cz_freq) { |
| 5246 | /* CHV suggested value is 31 or 63 */ |
| 5247 | if (IS_CHERRYVIEW(dev_priv)) |
| 5248 | credits = PFI_CREDIT_31; |
| 5249 | else |
| 5250 | credits = PFI_CREDIT(15); |
| 5251 | } else { |
| 5252 | credits = default_credits; |
| 5253 | } |
| 5254 | |
| 5255 | /* |
| 5256 | * WA - write default credits before re-programming |
| 5257 | * FIXME: should we also set the resend bit here? |
| 5258 | */ |
| 5259 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5260 | default_credits); |
| 5261 | |
| 5262 | I915_WRITE(GCI_CONTROL, VGA_FAST_MODE_DISABLE | |
| 5263 | credits | PFI_CREDIT_RESEND); |
| 5264 | |
| 5265 | /* |
| 5266 | * FIXME is this guaranteed to clear |
| 5267 | * immediately or should we poll for it? |
| 5268 | */ |
| 5269 | WARN_ON(I915_READ(GCI_CONTROL) & PFI_CREDIT_RESEND); |
| 5270 | } |
| 5271 | |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5272 | static void valleyview_modeset_global_resources(struct drm_atomic_state *state) |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5273 | { |
Ander Conselvan de Oliveira | 679dacd | 2015-03-20 16:18:15 +0200 | [diff] [blame] | 5274 | struct drm_device *dev = state->dev; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5275 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 5276 | int max_pixclk = intel_mode_max_pixclk(state); |
| 5277 | int req_cdclk; |
| 5278 | |
| 5279 | /* The only reason this can fail is if we fail to add the crtc_state |
| 5280 | * to the atomic state. But that can't happen since the call to |
| 5281 | * intel_mode_max_pixclk() in valleyview_modeset_global_pipes() (which |
| 5282 | * can't have failed otherwise the mode set would be aborted) added all |
| 5283 | * the states already. */ |
| 5284 | if (WARN_ON(max_pixclk < 0)) |
| 5285 | return; |
| 5286 | |
| 5287 | req_cdclk = valleyview_calc_cdclk(dev_priv, max_pixclk); |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5288 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5289 | if (req_cdclk != dev_priv->vlv_cdclk_freq) { |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5290 | /* |
| 5291 | * FIXME: We can end up here with all power domains off, yet |
| 5292 | * with a CDCLK frequency other than the minimum. To account |
| 5293 | * for this take the PIPE-A power domain, which covers the HW |
| 5294 | * blocks needed for the following programming. This can be |
| 5295 | * removed once it's guaranteed that we get here either with |
| 5296 | * the minimum CDCLK set, or the required power domains |
| 5297 | * enabled. |
| 5298 | */ |
| 5299 | intel_display_power_get(dev_priv, POWER_DOMAIN_PIPE_A); |
| 5300 | |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5301 | if (IS_CHERRYVIEW(dev)) |
| 5302 | cherryview_set_cdclk(dev, req_cdclk); |
| 5303 | else |
| 5304 | valleyview_set_cdclk(dev, req_cdclk); |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5305 | |
Vidya Srinivas | 1e69cd7 | 2015-03-05 21:19:50 +0200 | [diff] [blame] | 5306 | vlv_program_pfi_credits(dev_priv); |
| 5307 | |
Imre Deak | 738c05c | 2014-11-19 16:25:37 +0200 | [diff] [blame] | 5308 | intel_display_power_put(dev_priv, POWER_DOMAIN_PIPE_A); |
Ville Syrjälä | 383c5a6 | 2014-06-28 02:03:57 +0300 | [diff] [blame] | 5309 | } |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 5310 | } |
| 5311 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5312 | static void valleyview_crtc_enable(struct drm_crtc *crtc) |
| 5313 | { |
| 5314 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5315 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5316 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 5317 | struct intel_encoder *encoder; |
| 5318 | int pipe = intel_crtc->pipe; |
Jani Nikula | 23538ef | 2013-08-27 15:12:22 +0300 | [diff] [blame] | 5319 | bool is_dsi; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5320 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5321 | WARN_ON(!crtc->state->enable); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5322 | |
| 5323 | if (intel_crtc->active) |
| 5324 | return; |
| 5325 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5326 | is_dsi = intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI); |
Shobhit Kumar | 8525a23 | 2014-06-25 12:20:39 +0530 | [diff] [blame] | 5327 | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5328 | if (!is_dsi) { |
| 5329 | if (IS_CHERRYVIEW(dev)) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5330 | chv_prepare_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5331 | else |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5332 | vlv_prepare_pll(intel_crtc, intel_crtc->config); |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 5333 | } |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5334 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5335 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48d | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5336 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5337 | |
| 5338 | intel_set_pipe_timings(intel_crtc); |
| 5339 | |
Ville Syrjälä | c14b048 | 2014-10-16 20:52:34 +0300 | [diff] [blame] | 5340 | if (IS_CHERRYVIEW(dev) && pipe == PIPE_B) { |
| 5341 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5342 | |
| 5343 | I915_WRITE(CHV_BLEND(pipe), CHV_BLEND_LEGACY); |
| 5344 | I915_WRITE(CHV_CANVAS(pipe), 0); |
| 5345 | } |
| 5346 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5347 | i9xx_set_pipeconf(intel_crtc); |
| 5348 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5349 | intel_crtc->active = true; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5350 | |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5351 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5352 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5353 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5354 | if (encoder->pre_pll_enable) |
| 5355 | encoder->pre_pll_enable(encoder); |
| 5356 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5357 | if (!is_dsi) { |
| 5358 | if (IS_CHERRYVIEW(dev)) |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5359 | chv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5360 | else |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5361 | vlv_enable_pll(intel_crtc, intel_crtc->config); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 5362 | } |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5363 | |
| 5364 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5365 | if (encoder->pre_enable) |
| 5366 | encoder->pre_enable(encoder); |
| 5367 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5368 | i9xx_pfit_enable(intel_crtc); |
| 5369 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 5370 | intel_crtc_load_lut(crtc); |
| 5371 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5372 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5373 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 5374 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5375 | assert_vblank_disabled(crtc); |
| 5376 | drm_crtc_vblank_on(crtc); |
| 5377 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5378 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5379 | encoder->enable(encoder); |
| 5380 | |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 5381 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 5382 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 5383 | /* Underruns don't raise interrupts, so check manually. */ |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5384 | i9xx_check_fifo_underruns(dev_priv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5385 | } |
| 5386 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5387 | static void i9xx_set_pll_dividers(struct intel_crtc *crtc) |
| 5388 | { |
| 5389 | struct drm_device *dev = crtc->base.dev; |
| 5390 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5391 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5392 | I915_WRITE(FP0(crtc->pipe), crtc->config->dpll_hw_state.fp0); |
| 5393 | I915_WRITE(FP1(crtc->pipe), crtc->config->dpll_hw_state.fp1); |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5394 | } |
| 5395 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5396 | static void i9xx_crtc_enable(struct drm_crtc *crtc) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5397 | { |
| 5398 | struct drm_device *dev = crtc->dev; |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5399 | struct drm_i915_private *dev_priv = to_i915(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5400 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5401 | struct intel_encoder *encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5402 | int pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5403 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5404 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 08a4846 | 2012-07-02 11:43:47 +0200 | [diff] [blame] | 5405 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5406 | if (intel_crtc->active) |
| 5407 | return; |
| 5408 | |
Daniel Vetter | f13c2ef | 2014-04-24 23:55:10 +0200 | [diff] [blame] | 5409 | i9xx_set_pll_dividers(intel_crtc); |
| 5410 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5411 | if (intel_crtc->config->has_dp_encoder) |
Ramalingam C | fe3cd48d | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 5412 | intel_dp_set_m_n(intel_crtc, M1_N1); |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5413 | |
| 5414 | intel_set_pipe_timings(intel_crtc); |
| 5415 | |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 5416 | i9xx_set_pipeconf(intel_crtc); |
| 5417 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5418 | intel_crtc->active = true; |
Chris Wilson | 6b383a7 | 2010-09-13 13:54:26 +0100 | [diff] [blame] | 5419 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5420 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5421 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5422 | |
Daniel Vetter | 66e3d5c | 2013-06-16 21:24:16 +0200 | [diff] [blame] | 5423 | for_each_encoder_on_crtc(dev, crtc, encoder) |
Mika Kuoppala | 9d6d9f1 | 2013-02-08 16:35:38 +0200 | [diff] [blame] | 5424 | if (encoder->pre_enable) |
| 5425 | encoder->pre_enable(encoder); |
| 5426 | |
Daniel Vetter | f6736a1 | 2013-06-05 13:34:30 +0200 | [diff] [blame] | 5427 | i9xx_enable_pll(intel_crtc); |
| 5428 | |
Jesse Barnes | 2dd2455 | 2013-04-25 12:55:01 -0700 | [diff] [blame] | 5429 | i9xx_pfit_enable(intel_crtc); |
| 5430 | |
Ville Syrjälä | 63cbb07 | 2013-06-04 13:48:59 +0300 | [diff] [blame] | 5431 | intel_crtc_load_lut(crtc); |
| 5432 | |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5433 | intel_update_watermarks(crtc); |
Paulo Zanoni | e1fdc47 | 2014-01-17 13:51:12 -0200 | [diff] [blame] | 5434 | intel_enable_pipe(intel_crtc); |
Daniel Vetter | be6a6f8 | 2014-04-15 18:41:22 +0200 | [diff] [blame] | 5435 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5436 | assert_vblank_disabled(crtc); |
| 5437 | drm_crtc_vblank_on(crtc); |
| 5438 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5439 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5440 | encoder->enable(encoder); |
| 5441 | |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 5442 | intel_crtc_enable_planes(crtc); |
Daniel Vetter | d40d918 | 2014-05-21 11:45:40 +0200 | [diff] [blame] | 5443 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5444 | /* |
| 5445 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5446 | * So don't enable underrun reporting before at least some planes |
| 5447 | * are enabled. |
| 5448 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5449 | * but leave the pipe running. |
| 5450 | */ |
| 5451 | if (IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5452 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, true); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5453 | |
Ville Syrjälä | 56b80e1 | 2014-05-16 19:40:22 +0300 | [diff] [blame] | 5454 | /* Underruns don't raise interrupts, so check manually. */ |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5455 | i9xx_check_fifo_underruns(dev_priv); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5456 | } |
| 5457 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5458 | static void i9xx_pfit_disable(struct intel_crtc *crtc) |
| 5459 | { |
| 5460 | struct drm_device *dev = crtc->base.dev; |
| 5461 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5462 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 5463 | if (!crtc->config->gmch_pfit.control) |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5464 | return; |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5465 | |
| 5466 | assert_pipe_disabled(dev_priv, crtc->pipe); |
| 5467 | |
Daniel Vetter | 328d8e8 | 2013-05-08 10:36:31 +0200 | [diff] [blame] | 5468 | DRM_DEBUG_DRIVER("disabling pfit, current: 0x%08x\n", |
| 5469 | I915_READ(PFIT_CONTROL)); |
| 5470 | I915_WRITE(PFIT_CONTROL, 0); |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5471 | } |
| 5472 | |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5473 | static void i9xx_crtc_disable(struct drm_crtc *crtc) |
| 5474 | { |
| 5475 | struct drm_device *dev = crtc->dev; |
| 5476 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5477 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5478 | struct intel_encoder *encoder; |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5479 | int pipe = intel_crtc->pipe; |
Daniel Vetter | ef9c3ae | 2012-06-29 22:40:09 +0200 | [diff] [blame] | 5480 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5481 | if (!intel_crtc->active) |
| 5482 | return; |
| 5483 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5484 | /* |
| 5485 | * Gen2 reports pipe underruns whenever all planes are disabled. |
| 5486 | * So diasble underrun reporting before all the planes get disabled. |
| 5487 | * FIXME: Need to fix the logic to work when we turn off all planes |
| 5488 | * but leave the pipe running. |
| 5489 | */ |
| 5490 | if (IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5491 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5492 | |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 5493 | /* |
| 5494 | * Vblank time updates from the shadow to live plane control register |
| 5495 | * are blocked if the memory self-refresh mode is active at that |
| 5496 | * moment. So to make sure the plane gets truly disabled, disable |
| 5497 | * first the self-refresh mode. The self-refresh enable bit in turn |
| 5498 | * will be checked/applied by the HW only at the next frame start |
| 5499 | * event which is after the vblank start event, so we need to have a |
| 5500 | * wait-for-vblank between disabling the plane and the pipe. |
| 5501 | */ |
| 5502 | intel_set_memory_cxsr(dev_priv, false); |
Ville Syrjälä | 9ab0460 | 2014-05-08 19:23:14 +0300 | [diff] [blame] | 5503 | intel_crtc_disable_planes(crtc); |
| 5504 | |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 5505 | /* |
| 5506 | * On gen2 planes are double buffered but the pipe isn't, so we must |
| 5507 | * wait for planes to fully turn off before disabling the pipe. |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 5508 | * We also need to wait on all gmch platforms because of the |
| 5509 | * self-refresh mode constraint explained above. |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 5510 | */ |
Imre Deak | 564ed19 | 2014-06-13 14:54:21 +0300 | [diff] [blame] | 5511 | intel_wait_for_vblank(dev, pipe); |
Ville Syrjälä | 6304cd9 | 2014-04-25 13:30:12 +0300 | [diff] [blame] | 5512 | |
Ville Syrjälä | 4b3a952 | 2014-08-14 22:04:37 +0300 | [diff] [blame] | 5513 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5514 | encoder->disable(encoder); |
| 5515 | |
Daniel Vetter | f9b61ff | 2015-01-07 13:54:39 +0100 | [diff] [blame] | 5516 | drm_crtc_vblank_off(crtc); |
| 5517 | assert_vblank_disabled(crtc); |
| 5518 | |
Ville Syrjälä | 575f7ab | 2014-08-15 01:21:56 +0300 | [diff] [blame] | 5519 | intel_disable_pipe(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 5520 | |
Daniel Vetter | 87476d6 | 2013-04-11 16:29:06 +0200 | [diff] [blame] | 5521 | i9xx_pfit_disable(intel_crtc); |
Mika Kuoppala | 24a1f16 | 2013-02-08 16:35:37 +0200 | [diff] [blame] | 5522 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 5523 | for_each_encoder_on_crtc(dev, crtc, encoder) |
| 5524 | if (encoder->post_disable) |
| 5525 | encoder->post_disable(encoder); |
| 5526 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 5527 | if (!intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_DSI)) { |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 5528 | if (IS_CHERRYVIEW(dev)) |
| 5529 | chv_disable_pll(dev_priv, pipe); |
| 5530 | else if (IS_VALLEYVIEW(dev)) |
| 5531 | vlv_disable_pll(dev_priv, pipe); |
| 5532 | else |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 5533 | i9xx_disable_pll(intel_crtc); |
Chon Ming Lee | 076ed3b | 2014-04-09 13:28:17 +0300 | [diff] [blame] | 5534 | } |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5535 | |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5536 | if (!IS_GEN2(dev)) |
Daniel Vetter | a72e4c9 | 2014-09-30 10:56:47 +0200 | [diff] [blame] | 5537 | intel_set_cpu_fifo_underrun_reporting(dev_priv, pipe, false); |
Ville Syrjälä | 4a3436e | 2014-05-16 19:40:25 +0300 | [diff] [blame] | 5538 | |
Chris Wilson | f7abfe8 | 2010-09-13 14:19:16 +0100 | [diff] [blame] | 5539 | intel_crtc->active = false; |
Ville Syrjälä | 46ba614 | 2013-09-10 11:40:40 +0300 | [diff] [blame] | 5540 | intel_update_watermarks(crtc); |
Ville Syrjälä | f37fcc2 | 2013-09-10 11:39:55 +0300 | [diff] [blame] | 5541 | |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 5542 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 5543 | intel_fbc_update(dev); |
Daniel Vetter | efa9624 | 2014-04-24 23:55:02 +0200 | [diff] [blame] | 5544 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 0b8765c6 | 2010-09-10 10:31:34 -0700 | [diff] [blame] | 5545 | } |
| 5546 | |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5547 | static void i9xx_crtc_off(struct drm_crtc *crtc) |
| 5548 | { |
| 5549 | } |
| 5550 | |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 5551 | /* Master function to enable/disable CRTC and corresponding power wells */ |
| 5552 | void intel_crtc_control(struct drm_crtc *crtc, bool enable) |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5553 | { |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5554 | struct drm_device *dev = crtc->dev; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5555 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5556 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5557 | enum intel_display_power_domain domain; |
| 5558 | unsigned long domains; |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5559 | |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5560 | if (enable) { |
| 5561 | if (!intel_crtc->active) { |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 5562 | domains = get_crtc_power_domains(crtc); |
| 5563 | for_each_power_domain(domain, domains) |
| 5564 | intel_display_power_get(dev_priv, domain); |
| 5565 | intel_crtc->enabled_power_domains = domains; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5566 | |
| 5567 | dev_priv->display.crtc_enable(crtc); |
| 5568 | } |
| 5569 | } else { |
| 5570 | if (intel_crtc->active) { |
| 5571 | dev_priv->display.crtc_disable(crtc); |
| 5572 | |
Daniel Vetter | e1e9fb8 | 2014-06-25 22:02:04 +0300 | [diff] [blame] | 5573 | domains = intel_crtc->enabled_power_domains; |
| 5574 | for_each_power_domain(domain, domains) |
| 5575 | intel_display_power_put(dev_priv, domain); |
| 5576 | intel_crtc->enabled_power_domains = 0; |
Daniel Vetter | 0e572fe | 2014-04-24 23:55:42 +0200 | [diff] [blame] | 5577 | } |
| 5578 | } |
Borun Fu | b04c5bd | 2014-07-12 10:02:27 +0530 | [diff] [blame] | 5579 | } |
| 5580 | |
| 5581 | /** |
| 5582 | * Sets the power management mode of the pipe and plane. |
| 5583 | */ |
| 5584 | void intel_crtc_update_dpms(struct drm_crtc *crtc) |
| 5585 | { |
| 5586 | struct drm_device *dev = crtc->dev; |
| 5587 | struct intel_encoder *intel_encoder; |
| 5588 | bool enable = false; |
| 5589 | |
| 5590 | for_each_encoder_on_crtc(dev, crtc, intel_encoder) |
| 5591 | enable |= intel_encoder->connectors_active; |
| 5592 | |
| 5593 | intel_crtc_control(crtc, enable); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5594 | } |
| 5595 | |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5596 | static void intel_crtc_disable(struct drm_crtc *crtc) |
| 5597 | { |
| 5598 | struct drm_device *dev = crtc->dev; |
| 5599 | struct drm_connector *connector; |
| 5600 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5601 | |
| 5602 | /* crtc should still be enabled when we disable it. */ |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5603 | WARN_ON(!crtc->state->enable); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5604 | |
| 5605 | dev_priv->display.crtc_disable(crtc); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 5606 | dev_priv->display.off(crtc); |
| 5607 | |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 5608 | drm_plane_helper_disable(crtc->primary); |
Daniel Vetter | 976f8a2 | 2012-07-08 22:34:21 +0200 | [diff] [blame] | 5609 | |
| 5610 | /* Update computed state. */ |
| 5611 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 5612 | if (!connector->encoder || !connector->encoder->crtc) |
| 5613 | continue; |
| 5614 | |
| 5615 | if (connector->encoder->crtc != crtc) |
| 5616 | continue; |
| 5617 | |
| 5618 | connector->dpms = DRM_MODE_DPMS_OFF; |
| 5619 | to_intel_encoder(connector->encoder)->connectors_active = false; |
Chris Wilson | cdd5998 | 2010-09-08 16:30:16 +0100 | [diff] [blame] | 5620 | } |
| 5621 | } |
| 5622 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5623 | void intel_encoder_destroy(struct drm_encoder *encoder) |
| 5624 | { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 5625 | struct intel_encoder *intel_encoder = to_intel_encoder(encoder); |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5626 | |
Chris Wilson | ea5b213 | 2010-08-04 13:50:23 +0100 | [diff] [blame] | 5627 | drm_encoder_cleanup(encoder); |
| 5628 | kfree(intel_encoder); |
| 5629 | } |
| 5630 | |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5631 | /* 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] | 5632 | * one kind of off state. It clamps all !ON modes to fully OFF and changes the |
| 5633 | * state of the entire output pipe. */ |
Damien Lespiau | 9237329 | 2013-08-08 22:28:57 +0100 | [diff] [blame] | 5634 | static void intel_encoder_dpms(struct intel_encoder *encoder, int mode) |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5635 | { |
| 5636 | if (mode == DRM_MODE_DPMS_ON) { |
| 5637 | encoder->connectors_active = true; |
| 5638 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5639 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5640 | } else { |
| 5641 | encoder->connectors_active = false; |
| 5642 | |
Daniel Vetter | b2cabb0 | 2012-07-01 22:42:24 +0200 | [diff] [blame] | 5643 | intel_crtc_update_dpms(encoder->base.crtc); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5644 | } |
| 5645 | } |
| 5646 | |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5647 | /* Cross check the actual hw state with our own modeset state tracking (and it's |
| 5648 | * internal consistency). */ |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5649 | static void intel_connector_check_state(struct intel_connector *connector) |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5650 | { |
| 5651 | if (connector->get_hw_state(connector)) { |
| 5652 | struct intel_encoder *encoder = connector->encoder; |
| 5653 | struct drm_crtc *crtc; |
| 5654 | bool encoder_enabled; |
| 5655 | enum pipe pipe; |
| 5656 | |
| 5657 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", |
| 5658 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 5659 | connector->base.name); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5660 | |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 5661 | /* there is no real hw state for MST connectors */ |
| 5662 | if (connector->mst_port) |
| 5663 | return; |
| 5664 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5665 | I915_STATE_WARN(connector->base.dpms == DRM_MODE_DPMS_OFF, |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5666 | "wrong connector dpms state\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5667 | I915_STATE_WARN(connector->base.encoder != &encoder->base, |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5668 | "active connector not linked to encoder\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5669 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5670 | if (encoder) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5671 | I915_STATE_WARN(!encoder->connectors_active, |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5672 | "encoder->connectors_active not set\n"); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5673 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5674 | encoder_enabled = encoder->get_hw_state(encoder, &pipe); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5675 | I915_STATE_WARN(!encoder_enabled, "encoder not enabled\n"); |
| 5676 | if (I915_STATE_WARN_ON(!encoder->base.crtc)) |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5677 | return; |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5678 | |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5679 | crtc = encoder->base.crtc; |
| 5680 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 5681 | I915_STATE_WARN(!crtc->state->enable, |
| 5682 | "crtc not enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 5683 | I915_STATE_WARN(!to_intel_crtc(crtc)->active, "crtc not active\n"); |
| 5684 | I915_STATE_WARN(pipe != to_intel_crtc(crtc)->pipe, |
Dave Airlie | 36cd744 | 2014-05-02 13:44:18 +1000 | [diff] [blame] | 5685 | "encoder active on the wrong pipe\n"); |
| 5686 | } |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5687 | } |
| 5688 | } |
| 5689 | |
Ander Conselvan de Oliveira | 9bdbd0b | 2015-04-10 10:59:10 +0300 | [diff] [blame] | 5690 | int intel_connector_init(struct intel_connector *connector) |
| 5691 | { |
| 5692 | struct drm_connector_state *connector_state; |
| 5693 | |
| 5694 | connector_state = kzalloc(sizeof *connector_state, GFP_KERNEL); |
| 5695 | if (!connector_state) |
| 5696 | return -ENOMEM; |
| 5697 | |
| 5698 | connector->base.state = connector_state; |
| 5699 | return 0; |
| 5700 | } |
| 5701 | |
| 5702 | struct intel_connector *intel_connector_alloc(void) |
| 5703 | { |
| 5704 | struct intel_connector *connector; |
| 5705 | |
| 5706 | connector = kzalloc(sizeof *connector, GFP_KERNEL); |
| 5707 | if (!connector) |
| 5708 | return NULL; |
| 5709 | |
| 5710 | if (intel_connector_init(connector) < 0) { |
| 5711 | kfree(connector); |
| 5712 | return NULL; |
| 5713 | } |
| 5714 | |
| 5715 | return connector; |
| 5716 | } |
| 5717 | |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5718 | /* Even simpler default implementation, if there's really no special case to |
| 5719 | * consider. */ |
| 5720 | void intel_connector_dpms(struct drm_connector *connector, int mode) |
| 5721 | { |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5722 | /* All the simple cases only support two dpms states. */ |
| 5723 | if (mode != DRM_MODE_DPMS_ON) |
| 5724 | mode = DRM_MODE_DPMS_OFF; |
| 5725 | |
| 5726 | if (mode == connector->dpms) |
| 5727 | return; |
| 5728 | |
| 5729 | connector->dpms = mode; |
| 5730 | |
| 5731 | /* Only need to change hw state when actually enabled */ |
Chris Wilson | c9976dcf | 2013-09-29 19:15:07 +0100 | [diff] [blame] | 5732 | if (connector->encoder) |
| 5733 | intel_encoder_dpms(to_intel_encoder(connector->encoder), mode); |
Daniel Vetter | 0a91ca2 | 2012-07-02 21:54:27 +0200 | [diff] [blame] | 5734 | |
Daniel Vetter | b980514 | 2012-08-31 17:37:33 +0200 | [diff] [blame] | 5735 | intel_modeset_check_state(connector->dev); |
Daniel Vetter | 5ab432e | 2012-06-30 08:59:56 +0200 | [diff] [blame] | 5736 | } |
| 5737 | |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5738 | /* Simple connector->get_hw_state implementation for encoders that support only |
| 5739 | * one connector and no cloning and hence the encoder state determines the state |
| 5740 | * of the connector. */ |
| 5741 | bool intel_connector_get_hw_state(struct intel_connector *connector) |
| 5742 | { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 5743 | enum pipe pipe = 0; |
Daniel Vetter | f0947c3 | 2012-07-02 13:10:34 +0200 | [diff] [blame] | 5744 | struct intel_encoder *encoder = connector->encoder; |
| 5745 | |
| 5746 | return encoder->get_hw_state(encoder, &pipe); |
| 5747 | } |
| 5748 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5749 | static int pipe_required_fdi_lanes(struct intel_crtc_state *crtc_state) |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 5750 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5751 | if (crtc_state->base.enable && crtc_state->has_pch_encoder) |
| 5752 | return crtc_state->fdi_lanes; |
Ville Syrjälä | d272ddf | 2015-03-11 18:52:31 +0200 | [diff] [blame] | 5753 | |
| 5754 | return 0; |
| 5755 | } |
| 5756 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5757 | static int 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] | 5758 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5759 | { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5760 | struct drm_atomic_state *state = pipe_config->base.state; |
| 5761 | struct intel_crtc *other_crtc; |
| 5762 | struct intel_crtc_state *other_crtc_state; |
| 5763 | |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5764 | DRM_DEBUG_KMS("checking fdi config on pipe %c, lanes %i\n", |
| 5765 | pipe_name(pipe), pipe_config->fdi_lanes); |
| 5766 | if (pipe_config->fdi_lanes > 4) { |
| 5767 | DRM_DEBUG_KMS("invalid fdi lane config on pipe %c: %i lanes\n", |
| 5768 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5769 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5770 | } |
| 5771 | |
Paulo Zanoni | bafb655 | 2013-11-02 21:07:44 -0700 | [diff] [blame] | 5772 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5773 | if (pipe_config->fdi_lanes > 2) { |
| 5774 | DRM_DEBUG_KMS("only 2 lanes on haswell, required: %i lanes\n", |
| 5775 | pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5776 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5777 | } else { |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5778 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5779 | } |
| 5780 | } |
| 5781 | |
| 5782 | if (INTEL_INFO(dev)->num_pipes == 2) |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5783 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5784 | |
| 5785 | /* Ivybridge 3 pipe is really complicated */ |
| 5786 | switch (pipe) { |
| 5787 | case PIPE_A: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5788 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5789 | case PIPE_B: |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5790 | if (pipe_config->fdi_lanes <= 2) |
| 5791 | return 0; |
| 5792 | |
| 5793 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_C)); |
| 5794 | other_crtc_state = |
| 5795 | intel_atomic_get_crtc_state(state, other_crtc); |
| 5796 | if (IS_ERR(other_crtc_state)) |
| 5797 | return PTR_ERR(other_crtc_state); |
| 5798 | |
| 5799 | if (pipe_required_fdi_lanes(other_crtc_state) > 0) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5800 | DRM_DEBUG_KMS("invalid shared fdi lane config on pipe %c: %i lanes\n", |
| 5801 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5802 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5803 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5804 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5805 | case PIPE_C: |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 5806 | if (pipe_config->fdi_lanes > 2) { |
| 5807 | DRM_DEBUG_KMS("only 2 lanes on pipe %c: required %i lanes\n", |
| 5808 | pipe_name(pipe), pipe_config->fdi_lanes); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5809 | return -EINVAL; |
Ville Syrjälä | 251cc67 | 2015-03-11 18:52:30 +0200 | [diff] [blame] | 5810 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5811 | |
| 5812 | other_crtc = to_intel_crtc(intel_get_crtc_for_pipe(dev, PIPE_B)); |
| 5813 | other_crtc_state = |
| 5814 | intel_atomic_get_crtc_state(state, other_crtc); |
| 5815 | if (IS_ERR(other_crtc_state)) |
| 5816 | return PTR_ERR(other_crtc_state); |
| 5817 | |
| 5818 | if (pipe_required_fdi_lanes(other_crtc_state) > 2) { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5819 | DRM_DEBUG_KMS("fdi link B uses too many lanes to enable link C\n"); |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5820 | return -EINVAL; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5821 | } |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5822 | return 0; |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5823 | default: |
| 5824 | BUG(); |
| 5825 | } |
| 5826 | } |
| 5827 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5828 | #define RETRY 1 |
| 5829 | 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] | 5830 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5831 | { |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5832 | struct drm_device *dev = intel_crtc->base.dev; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 5833 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5834 | int lane, link_bw, fdi_dotclock, ret; |
| 5835 | bool needs_recompute = false; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5836 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5837 | retry: |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5838 | /* FDI is a binary signal running at ~2.7GHz, encoding |
| 5839 | * each output octet as 10 bits. The actual frequency |
| 5840 | * is stored as a divider into a 100MHz clock, and the |
| 5841 | * mode pixel clock is stored in units of 1KHz. |
| 5842 | * Hence the bw of each lane in terms of the mode signal |
| 5843 | * is: |
| 5844 | */ |
| 5845 | link_bw = intel_fdi_link_freq(dev) * MHz(100)/KHz(1)/10; |
| 5846 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5847 | fdi_dotclock = adjusted_mode->crtc_clock; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5848 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5849 | lane = ironlake_get_lanes_required(fdi_dotclock, link_bw, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5850 | pipe_config->pipe_bpp); |
| 5851 | |
| 5852 | pipe_config->fdi_lanes = lane; |
| 5853 | |
Daniel Vetter | 2bd89a0 | 2013-06-01 17:16:19 +0200 | [diff] [blame] | 5854 | intel_link_compute_m_n(pipe_config->pipe_bpp, lane, fdi_dotclock, |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5855 | link_bw, &pipe_config->fdi_m_n); |
Daniel Vetter | 1857e1d | 2013-04-29 19:34:16 +0200 | [diff] [blame] | 5856 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5857 | ret = ironlake_check_fdi_lanes(intel_crtc->base.dev, |
| 5858 | intel_crtc->pipe, pipe_config); |
| 5859 | if (ret == -EINVAL && pipe_config->pipe_bpp > 6*3) { |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5860 | pipe_config->pipe_bpp -= 2*3; |
| 5861 | DRM_DEBUG_KMS("fdi link bw constraint, reducing pipe bpp to %i\n", |
| 5862 | pipe_config->pipe_bpp); |
| 5863 | needs_recompute = true; |
| 5864 | pipe_config->bw_constrained = true; |
| 5865 | |
| 5866 | goto retry; |
| 5867 | } |
| 5868 | |
| 5869 | if (needs_recompute) |
| 5870 | return RETRY; |
| 5871 | |
Ander Conselvan de Oliveira | 6d29398 | 2015-03-30 08:33:12 +0300 | [diff] [blame] | 5872 | return ret; |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5873 | } |
| 5874 | |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5875 | static void hsw_compute_ips_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 5876 | struct intel_crtc_state *pipe_config) |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5877 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 5878 | pipe_config->ips_enabled = i915.enable_ips && |
Paulo Zanoni | 3c4ca58 | 2013-05-31 16:33:23 -0300 | [diff] [blame] | 5879 | hsw_crtc_supports_ips(crtc) && |
Jesse Barnes | b6dfdc9 | 2013-07-25 10:06:50 -0700 | [diff] [blame] | 5880 | pipe_config->pipe_bpp <= 24; |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 5881 | } |
| 5882 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5883 | static int intel_crtc_compute_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 5884 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5885 | { |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5886 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 5887 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 5888 | struct drm_display_mode *adjusted_mode = &pipe_config->base.adjusted_mode; |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5889 | |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5890 | /* FIXME should check pixel clock limits on all platforms */ |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5891 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5892 | int clock_limit = |
| 5893 | dev_priv->display.get_display_clock_speed(dev); |
| 5894 | |
| 5895 | /* |
| 5896 | * Enable pixel doubling when the dot clock |
| 5897 | * is > 90% of the (display) core speed. |
| 5898 | * |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5899 | * GDG double wide on either pipe, |
| 5900 | * otherwise pipe A only. |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5901 | */ |
Ville Syrjälä | b397c96 | 2013-09-04 18:30:06 +0300 | [diff] [blame] | 5902 | if ((crtc->pipe == PIPE_A || IS_I915G(dev)) && |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5903 | adjusted_mode->crtc_clock > clock_limit * 9 / 10) { |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5904 | clock_limit *= 2; |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 5905 | pipe_config->double_wide = true; |
Ville Syrjälä | ad3a447 | 2013-09-04 18:30:04 +0300 | [diff] [blame] | 5906 | } |
| 5907 | |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 5908 | if (adjusted_mode->crtc_clock > clock_limit * 9 / 10) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5909 | return -EINVAL; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 5910 | } |
Chris Wilson | 8974935 | 2010-09-12 18:25:19 +0100 | [diff] [blame] | 5911 | |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 5912 | /* |
| 5913 | * Pipe horizontal size must be even in: |
| 5914 | * - DVO ganged mode |
| 5915 | * - LVDS dual channel mode |
| 5916 | * - Double wide pipe |
| 5917 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 5918 | if ((intel_pipe_will_have_type(pipe_config, INTEL_OUTPUT_LVDS) && |
Ville Syrjälä | 1d1d0e2 | 2013-09-04 18:30:05 +0300 | [diff] [blame] | 5919 | intel_is_dual_link_lvds(dev)) || pipe_config->double_wide) |
| 5920 | pipe_config->pipe_src_w &= ~1; |
| 5921 | |
Damien Lespiau | 8693a82 | 2013-05-03 18:48:11 +0100 | [diff] [blame] | 5922 | /* Cantiga+ cannot handle modes with a hsync front porch of 0. |
| 5923 | * WaPruneModeWithIncorrectHsyncOffset:ctg,elk,ilk,snb,ivb,vlv,hsw. |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5924 | */ |
| 5925 | if ((INTEL_INFO(dev)->gen > 4 || IS_G4X(dev)) && |
| 5926 | adjusted_mode->hsync_start == adjusted_mode->hdisplay) |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5927 | return -EINVAL; |
Chris Wilson | 44f46b42 | 2012-06-21 13:19:59 +0300 | [diff] [blame] | 5928 | |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5929 | 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] | 5930 | pipe_config->pipe_bpp = 10*3; /* 12bpc is gen5+ */ |
Daniel Vetter | bd080ee | 2013-04-17 20:01:39 +0200 | [diff] [blame] | 5931 | } 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] | 5932 | /* only a 8bpc pipe, with 6bpc dither through the panel fitter |
| 5933 | * for lvds. */ |
| 5934 | pipe_config->pipe_bpp = 8*3; |
| 5935 | } |
| 5936 | |
Damien Lespiau | f5adf94 | 2013-06-24 18:29:34 +0100 | [diff] [blame] | 5937 | if (HAS_IPS(dev)) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5938 | hsw_compute_ips_config(crtc, pipe_config); |
| 5939 | |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5940 | if (pipe_config->has_pch_encoder) |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 5941 | return ironlake_fdi_compute_config(crtc, pipe_config); |
Daniel Vetter | 877d48d | 2013-04-19 11:24:43 +0200 | [diff] [blame] | 5942 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 5943 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 5944 | } |
| 5945 | |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 5946 | static int skylake_get_display_clock_speed(struct drm_device *dev) |
| 5947 | { |
| 5948 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 5949 | uint32_t lcpll1 = I915_READ(LCPLL1_CTL); |
| 5950 | uint32_t cdctl = I915_READ(CDCLK_CTL); |
| 5951 | uint32_t linkrate; |
| 5952 | |
| 5953 | if (!(lcpll1 & LCPLL_PLL_ENABLE)) { |
| 5954 | WARN(1, "LCPLL1 not enabled\n"); |
| 5955 | return 24000; /* 24MHz is the cd freq with NSSC ref */ |
| 5956 | } |
| 5957 | |
| 5958 | if ((cdctl & CDCLK_FREQ_SEL_MASK) == CDCLK_FREQ_540) |
| 5959 | return 540000; |
| 5960 | |
| 5961 | linkrate = (I915_READ(DPLL_CTRL1) & |
| 5962 | DPLL_CRTL1_LINK_RATE_MASK(SKL_DPLL0)) >> 1; |
| 5963 | |
| 5964 | if (linkrate == DPLL_CRTL1_LINK_RATE_2160 || |
| 5965 | linkrate == DPLL_CRTL1_LINK_RATE_1080) { |
| 5966 | /* vco 8640 */ |
| 5967 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 5968 | case CDCLK_FREQ_450_432: |
| 5969 | return 432000; |
| 5970 | case CDCLK_FREQ_337_308: |
| 5971 | return 308570; |
| 5972 | case CDCLK_FREQ_675_617: |
| 5973 | return 617140; |
| 5974 | default: |
| 5975 | WARN(1, "Unknown cd freq selection\n"); |
| 5976 | } |
| 5977 | } else { |
| 5978 | /* vco 8100 */ |
| 5979 | switch (cdctl & CDCLK_FREQ_SEL_MASK) { |
| 5980 | case CDCLK_FREQ_450_432: |
| 5981 | return 450000; |
| 5982 | case CDCLK_FREQ_337_308: |
| 5983 | return 337500; |
| 5984 | case CDCLK_FREQ_675_617: |
| 5985 | return 675000; |
| 5986 | default: |
| 5987 | WARN(1, "Unknown cd freq selection\n"); |
| 5988 | } |
| 5989 | } |
| 5990 | |
| 5991 | /* error case, do as if DPLL0 isn't enabled */ |
| 5992 | return 24000; |
| 5993 | } |
| 5994 | |
| 5995 | static int broadwell_get_display_clock_speed(struct drm_device *dev) |
| 5996 | { |
| 5997 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 5998 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 5999 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6000 | |
| 6001 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6002 | return 800000; |
| 6003 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6004 | return 450000; |
| 6005 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6006 | return 450000; |
| 6007 | else if (freq == LCPLL_CLK_FREQ_54O_BDW) |
| 6008 | return 540000; |
| 6009 | else if (freq == LCPLL_CLK_FREQ_337_5_BDW) |
| 6010 | return 337500; |
| 6011 | else |
| 6012 | return 675000; |
| 6013 | } |
| 6014 | |
| 6015 | static int haswell_get_display_clock_speed(struct drm_device *dev) |
| 6016 | { |
| 6017 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6018 | uint32_t lcpll = I915_READ(LCPLL_CTL); |
| 6019 | uint32_t freq = lcpll & LCPLL_CLK_FREQ_MASK; |
| 6020 | |
| 6021 | if (lcpll & LCPLL_CD_SOURCE_FCLK) |
| 6022 | return 800000; |
| 6023 | else if (I915_READ(FUSE_STRAP) & HSW_CDCLK_LIMIT) |
| 6024 | return 450000; |
| 6025 | else if (freq == LCPLL_CLK_FREQ_450) |
| 6026 | return 450000; |
| 6027 | else if (IS_HSW_ULT(dev)) |
| 6028 | return 337500; |
| 6029 | else |
| 6030 | return 540000; |
| 6031 | } |
| 6032 | |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6033 | static int valleyview_get_display_clock_speed(struct drm_device *dev) |
| 6034 | { |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6035 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6036 | u32 val; |
| 6037 | int divider; |
| 6038 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 6039 | if (dev_priv->hpll_freq == 0) |
| 6040 | dev_priv->hpll_freq = valleyview_get_vco(dev_priv); |
| 6041 | |
Ville Syrjälä | d197b7d | 2014-06-13 13:37:49 +0300 | [diff] [blame] | 6042 | mutex_lock(&dev_priv->dpio_lock); |
| 6043 | val = vlv_cck_read(dev_priv, CCK_DISPLAY_CLOCK_CONTROL); |
| 6044 | mutex_unlock(&dev_priv->dpio_lock); |
| 6045 | |
| 6046 | divider = val & DISPLAY_FREQUENCY_VALUES; |
| 6047 | |
Ville Syrjälä | 7d007f4 | 2014-06-13 13:37:53 +0300 | [diff] [blame] | 6048 | WARN((val & DISPLAY_FREQUENCY_STATUS) != |
| 6049 | (divider << DISPLAY_FREQUENCY_STATUS_SHIFT), |
| 6050 | "cdclk change in progress\n"); |
| 6051 | |
Ville Syrjälä | 6bcda4f | 2014-10-07 17:41:22 +0300 | [diff] [blame] | 6052 | return DIV_ROUND_CLOSEST(dev_priv->hpll_freq << 1, divider + 1); |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 6053 | } |
| 6054 | |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 6055 | static int ilk_get_display_clock_speed(struct drm_device *dev) |
| 6056 | { |
| 6057 | return 450000; |
| 6058 | } |
| 6059 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6060 | static int i945_get_display_clock_speed(struct drm_device *dev) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6061 | { |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6062 | return 400000; |
| 6063 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6064 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6065 | static int i915_get_display_clock_speed(struct drm_device *dev) |
| 6066 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6067 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6068 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6069 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6070 | static int i9xx_misc_get_display_clock_speed(struct drm_device *dev) |
| 6071 | { |
| 6072 | return 200000; |
| 6073 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6074 | |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6075 | static int pnv_get_display_clock_speed(struct drm_device *dev) |
| 6076 | { |
| 6077 | u16 gcfgc = 0; |
| 6078 | |
| 6079 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6080 | |
| 6081 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6082 | case GC_DISPLAY_CLOCK_267_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6083 | return 266667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6084 | case GC_DISPLAY_CLOCK_333_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6085 | return 333333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6086 | case GC_DISPLAY_CLOCK_444_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6087 | return 444444; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6088 | case GC_DISPLAY_CLOCK_200_MHZ_PNV: |
| 6089 | return 200000; |
| 6090 | default: |
| 6091 | DRM_ERROR("Unknown pnv display core clock 0x%04x\n", gcfgc); |
| 6092 | case GC_DISPLAY_CLOCK_133_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6093 | return 133333; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6094 | case GC_DISPLAY_CLOCK_167_MHZ_PNV: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6095 | return 166667; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 6096 | } |
| 6097 | } |
| 6098 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6099 | static int i915gm_get_display_clock_speed(struct drm_device *dev) |
| 6100 | { |
| 6101 | u16 gcfgc = 0; |
| 6102 | |
| 6103 | pci_read_config_word(dev->pdev, GCFGC, &gcfgc); |
| 6104 | |
| 6105 | if (gcfgc & GC_LOW_FREQUENCY_ENABLE) |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6106 | return 133333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6107 | else { |
| 6108 | switch (gcfgc & GC_DISPLAY_CLOCK_MASK) { |
| 6109 | case GC_DISPLAY_CLOCK_333_MHZ: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6110 | return 333333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6111 | default: |
| 6112 | case GC_DISPLAY_CLOCK_190_200_MHZ: |
| 6113 | return 190000; |
| 6114 | } |
| 6115 | } |
| 6116 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6117 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6118 | static int i865_get_display_clock_speed(struct drm_device *dev) |
| 6119 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6120 | return 266667; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6121 | } |
| 6122 | |
| 6123 | static int i855_get_display_clock_speed(struct drm_device *dev) |
| 6124 | { |
| 6125 | u16 hpllcc = 0; |
| 6126 | /* Assume that the hardware is in the high speed state. This |
| 6127 | * should be the default. |
| 6128 | */ |
| 6129 | switch (hpllcc & GC_CLOCK_CONTROL_MASK) { |
| 6130 | case GC_CLOCK_133_200: |
| 6131 | case GC_CLOCK_100_200: |
| 6132 | return 200000; |
| 6133 | case GC_CLOCK_166_250: |
| 6134 | return 250000; |
| 6135 | case GC_CLOCK_100_133: |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6136 | return 133333; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 6137 | } |
| 6138 | |
| 6139 | /* Shouldn't happen */ |
| 6140 | return 0; |
| 6141 | } |
| 6142 | |
| 6143 | static int i830_get_display_clock_speed(struct drm_device *dev) |
| 6144 | { |
Ville Syrjälä | e907f17 | 2015-03-31 14:09:47 +0300 | [diff] [blame] | 6145 | return 133333; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6146 | } |
| 6147 | |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6148 | static void |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6149 | intel_reduce_m_n_ratio(uint32_t *num, uint32_t *den) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6150 | { |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6151 | while (*num > DATA_LINK_M_N_MASK || |
| 6152 | *den > DATA_LINK_M_N_MASK) { |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6153 | *num >>= 1; |
| 6154 | *den >>= 1; |
| 6155 | } |
| 6156 | } |
| 6157 | |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6158 | static void compute_m_n(unsigned int m, unsigned int n, |
| 6159 | uint32_t *ret_m, uint32_t *ret_n) |
| 6160 | { |
| 6161 | *ret_n = min_t(unsigned int, roundup_pow_of_two(n), DATA_LINK_N_MAX); |
| 6162 | *ret_m = div_u64((uint64_t) m * *ret_n, n); |
| 6163 | intel_reduce_m_n_ratio(ret_m, ret_n); |
| 6164 | } |
| 6165 | |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6166 | void |
| 6167 | intel_link_compute_m_n(int bits_per_pixel, int nlanes, |
| 6168 | int pixel_clock, int link_clock, |
| 6169 | struct intel_link_m_n *m_n) |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6170 | { |
Daniel Vetter | e69d0bc | 2012-11-29 15:59:36 +0100 | [diff] [blame] | 6171 | m_n->tu = 64; |
Ville Syrjälä | a65851a | 2013-04-23 15:03:34 +0300 | [diff] [blame] | 6172 | |
| 6173 | compute_m_n(bits_per_pixel * pixel_clock, |
| 6174 | link_clock * nlanes * 8, |
| 6175 | &m_n->gmch_m, &m_n->gmch_n); |
| 6176 | |
| 6177 | compute_m_n(pixel_clock, link_clock, |
| 6178 | &m_n->link_m, &m_n->link_n); |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 6179 | } |
| 6180 | |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6181 | static inline bool intel_panel_use_ssc(struct drm_i915_private *dev_priv) |
| 6182 | { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 6183 | if (i915.panel_use_ssc >= 0) |
| 6184 | return i915.panel_use_ssc != 0; |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 6185 | return dev_priv->vbt.lvds_use_ssc |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 6186 | && !(dev_priv->quirks & QUIRK_LVDS_SSC_DISABLE); |
Chris Wilson | a761503 | 2011-01-12 17:04:08 +0000 | [diff] [blame] | 6187 | } |
| 6188 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6189 | static int i9xx_get_refclk(const struct intel_crtc_state *crtc_state, |
| 6190 | int num_connectors) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6191 | { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6192 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6193 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6194 | int refclk; |
| 6195 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6196 | WARN_ON(!crtc_state->base.state); |
| 6197 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6198 | if (IS_VALLEYVIEW(dev)) { |
Daniel Vetter | 9a0ea49 | 2013-09-16 11:29:34 +0200 | [diff] [blame] | 6199 | refclk = 100000; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6200 | } else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6201 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) { |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 6202 | refclk = dev_priv->vbt.lvds_ssc_freq; |
| 6203 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", refclk); |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6204 | } else if (!IS_GEN2(dev)) { |
| 6205 | refclk = 96000; |
| 6206 | } else { |
| 6207 | refclk = 48000; |
| 6208 | } |
| 6209 | |
| 6210 | return refclk; |
| 6211 | } |
| 6212 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6213 | static uint32_t pnv_dpll_compute_fp(struct dpll *dpll) |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6214 | { |
Daniel Vetter | 7df00d7 | 2013-05-21 21:54:55 +0200 | [diff] [blame] | 6215 | return (1 << dpll->n) << 16 | dpll->m2; |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6216 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6217 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6218 | static uint32_t i9xx_dpll_compute_fp(struct dpll *dpll) |
| 6219 | { |
| 6220 | return dpll->n << 16 | dpll->m1 << 8 | dpll->m2; |
Jesse Barnes | c65d77d | 2011-12-15 12:30:36 -0800 | [diff] [blame] | 6221 | } |
| 6222 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6223 | static void i9xx_update_pll_dividers(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6224 | struct intel_crtc_state *crtc_state, |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6225 | intel_clock_t *reduced_clock) |
| 6226 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6227 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6228 | u32 fp, fp2 = 0; |
| 6229 | |
| 6230 | if (IS_PINEVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6231 | fp = pnv_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6232 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6233 | fp2 = pnv_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6234 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6235 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6236 | if (reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 6237 | fp2 = i9xx_dpll_compute_fp(reduced_clock); |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6238 | } |
| 6239 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6240 | crtc_state->dpll_hw_state.fp0 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6241 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6242 | crtc->lowfreq_avail = false; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6243 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 6244 | reduced_clock) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6245 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6246 | crtc->lowfreq_avail = true; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6247 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6248 | crtc_state->dpll_hw_state.fp1 = fp; |
Jesse Barnes | a7516a0 | 2011-12-15 12:30:37 -0800 | [diff] [blame] | 6249 | } |
| 6250 | } |
| 6251 | |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6252 | static void vlv_pllb_recal_opamp(struct drm_i915_private *dev_priv, enum pipe |
| 6253 | pipe) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6254 | { |
| 6255 | u32 reg_val; |
| 6256 | |
| 6257 | /* |
| 6258 | * PLLB opamp always calibrates to max value of 0x3f, force enable it |
| 6259 | * and set it to a reasonable value instead. |
| 6260 | */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6261 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6262 | reg_val &= 0xffffff00; |
| 6263 | reg_val |= 0x00000030; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6264 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6265 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6266 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6267 | reg_val &= 0x8cffffff; |
| 6268 | reg_val = 0x8c000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6269 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6270 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6271 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW9(1)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6272 | reg_val &= 0xffffff00; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6273 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9(1), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6274 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6275 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_REF_DW13); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6276 | reg_val &= 0x00ffffff; |
| 6277 | reg_val |= 0xb0000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6278 | vlv_dpio_write(dev_priv, pipe, VLV_REF_DW13, reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6279 | } |
| 6280 | |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6281 | static void intel_pch_transcoder_set_m_n(struct intel_crtc *crtc, |
| 6282 | struct intel_link_m_n *m_n) |
| 6283 | { |
| 6284 | struct drm_device *dev = crtc->base.dev; |
| 6285 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6286 | int pipe = crtc->pipe; |
| 6287 | |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6288 | I915_WRITE(PCH_TRANS_DATA_M1(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6289 | I915_WRITE(PCH_TRANS_DATA_N1(pipe), m_n->gmch_n); |
| 6290 | I915_WRITE(PCH_TRANS_LINK_M1(pipe), m_n->link_m); |
| 6291 | I915_WRITE(PCH_TRANS_LINK_N1(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | static void intel_cpu_transcoder_set_m_n(struct intel_crtc *crtc, |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6295 | struct intel_link_m_n *m_n, |
| 6296 | struct intel_link_m_n *m2_n2) |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6297 | { |
| 6298 | struct drm_device *dev = crtc->base.dev; |
| 6299 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6300 | int pipe = crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6301 | enum transcoder transcoder = crtc->config->cpu_transcoder; |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6302 | |
| 6303 | if (INTEL_INFO(dev)->gen >= 5) { |
| 6304 | I915_WRITE(PIPE_DATA_M1(transcoder), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6305 | I915_WRITE(PIPE_DATA_N1(transcoder), m_n->gmch_n); |
| 6306 | I915_WRITE(PIPE_LINK_M1(transcoder), m_n->link_m); |
| 6307 | I915_WRITE(PIPE_LINK_N1(transcoder), m_n->link_n); |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6308 | /* M2_N2 registers to be set only for gen < 8 (M2_N2 available |
| 6309 | * for gen < 8) and if DRRS is supported (to make sure the |
| 6310 | * registers are not unnecessarily accessed). |
| 6311 | */ |
Durgadoss R | 44395bf | 2015-02-13 15:33:02 +0530 | [diff] [blame] | 6312 | 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] | 6313 | crtc->config->has_drrs) { |
Vandana Kannan | f769cd2 | 2014-08-05 07:51:22 -0700 | [diff] [blame] | 6314 | I915_WRITE(PIPE_DATA_M2(transcoder), |
| 6315 | TU_SIZE(m2_n2->tu) | m2_n2->gmch_m); |
| 6316 | I915_WRITE(PIPE_DATA_N2(transcoder), m2_n2->gmch_n); |
| 6317 | I915_WRITE(PIPE_LINK_M2(transcoder), m2_n2->link_m); |
| 6318 | I915_WRITE(PIPE_LINK_N2(transcoder), m2_n2->link_n); |
| 6319 | } |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6320 | } else { |
Daniel Vetter | e3b95f1 | 2013-05-03 11:49:49 +0200 | [diff] [blame] | 6321 | I915_WRITE(PIPE_DATA_M_G4X(pipe), TU_SIZE(m_n->tu) | m_n->gmch_m); |
| 6322 | I915_WRITE(PIPE_DATA_N_G4X(pipe), m_n->gmch_n); |
| 6323 | I915_WRITE(PIPE_LINK_M_G4X(pipe), m_n->link_m); |
| 6324 | I915_WRITE(PIPE_LINK_N_G4X(pipe), m_n->link_n); |
Daniel Vetter | b551842 | 2013-05-03 11:49:48 +0200 | [diff] [blame] | 6325 | } |
| 6326 | } |
| 6327 | |
Ramalingam C | fe3cd48d | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6328 | 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] | 6329 | { |
Ramalingam C | fe3cd48d | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6330 | struct intel_link_m_n *dp_m_n, *dp_m2_n2 = NULL; |
| 6331 | |
| 6332 | if (m_n == M1_N1) { |
| 6333 | dp_m_n = &crtc->config->dp_m_n; |
| 6334 | dp_m2_n2 = &crtc->config->dp_m2_n2; |
| 6335 | } else if (m_n == M2_N2) { |
| 6336 | |
| 6337 | /* |
| 6338 | * M2_N2 registers are not supported. Hence m2_n2 divider value |
| 6339 | * needs to be programmed into M1_N1. |
| 6340 | */ |
| 6341 | dp_m_n = &crtc->config->dp_m2_n2; |
| 6342 | } else { |
| 6343 | DRM_ERROR("Unsupported divider value\n"); |
| 6344 | return; |
| 6345 | } |
| 6346 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6347 | if (crtc->config->has_pch_encoder) |
| 6348 | intel_pch_transcoder_set_m_n(crtc, &crtc->config->dp_m_n); |
Daniel Vetter | 03afc4a | 2013-04-02 23:42:31 +0200 | [diff] [blame] | 6349 | else |
Ramalingam C | fe3cd48d | 2015-02-13 15:32:59 +0530 | [diff] [blame] | 6350 | 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] | 6351 | } |
| 6352 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6353 | static void vlv_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6354 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6355 | { |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6356 | u32 dpll, dpll_md; |
| 6357 | |
| 6358 | /* |
| 6359 | * Enable DPIO clock input. We should never disable the reference |
| 6360 | * clock for pipe B, since VGA hotplug / manual detection depends |
| 6361 | * on it. |
| 6362 | */ |
| 6363 | dpll = DPLL_EXT_BUFFER_ENABLE_VLV | DPLL_REFA_CLK_ENABLE_VLV | |
| 6364 | DPLL_VGA_MODE_DIS | DPLL_INTEGRATED_CLOCK_VLV; |
| 6365 | /* We should never disable this, set it here for state tracking */ |
| 6366 | if (crtc->pipe == PIPE_B) |
| 6367 | dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
| 6368 | dpll |= DPLL_VCO_ENABLE; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6369 | pipe_config->dpll_hw_state.dpll = dpll; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6370 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6371 | dpll_md = (pipe_config->pixel_multiplier - 1) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6372 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6373 | pipe_config->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6374 | } |
| 6375 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6376 | static void vlv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6377 | const struct intel_crtc_state *pipe_config) |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6378 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6379 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6380 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6381 | int pipe = crtc->pipe; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6382 | u32 mdiv; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6383 | u32 bestn, bestm1, bestm2, bestp1, bestp2; |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6384 | u32 coreclk, reg_val; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6385 | |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6386 | mutex_lock(&dev_priv->dpio_lock); |
| 6387 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6388 | bestn = pipe_config->dpll.n; |
| 6389 | bestm1 = pipe_config->dpll.m1; |
| 6390 | bestm2 = pipe_config->dpll.m2; |
| 6391 | bestp1 = pipe_config->dpll.p1; |
| 6392 | bestp2 = pipe_config->dpll.p2; |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6393 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6394 | /* See eDP HDMI DPIO driver vbios notes doc */ |
| 6395 | |
| 6396 | /* PLL B needs special handling */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6397 | if (pipe == PIPE_B) |
Chon Ming Lee | 5e69f97 | 2013-09-05 20:41:49 +0800 | [diff] [blame] | 6398 | vlv_pllb_recal_opamp(dev_priv, pipe); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6399 | |
| 6400 | /* Set up Tx target for periodic Rcomp update */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6401 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW9_BCAST, 0x0100000f); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6402 | |
| 6403 | /* Disable target IRef on PLL */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6404 | reg_val = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW8(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6405 | reg_val &= 0x00ffffff; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6406 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW8(pipe), reg_val); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6407 | |
| 6408 | /* Disable fast lock */ |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6409 | vlv_dpio_write(dev_priv, pipe, VLV_CMN_DW0, 0x610); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6410 | |
| 6411 | /* Set idtafcrecal before PLL is enabled */ |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6412 | mdiv = ((bestm1 << DPIO_M1DIV_SHIFT) | (bestm2 & DPIO_M2DIV_MASK)); |
| 6413 | mdiv |= ((bestp1 << DPIO_P1_SHIFT) | (bestp2 << DPIO_P2_SHIFT)); |
| 6414 | mdiv |= ((bestn << DPIO_N_SHIFT)); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6415 | mdiv |= (1 << DPIO_K_SHIFT); |
Jesse Barnes | 7df5080 | 2013-05-02 10:48:09 -0700 | [diff] [blame] | 6416 | |
| 6417 | /* |
| 6418 | * Post divider depends on pixel clock rate, DAC vs digital (and LVDS, |
| 6419 | * but we don't support that). |
| 6420 | * Note: don't use the DAC post divider as it seems unstable. |
| 6421 | */ |
| 6422 | mdiv |= (DPIO_POST_DIV_HDMIDP << DPIO_POST_DIV_SHIFT); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6423 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6424 | |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6425 | mdiv |= DPIO_ENABLE_CALIBRATION; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6426 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW3(pipe), mdiv); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6427 | |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6428 | /* Set HBR and RBR LPF coefficients */ |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6429 | if (pipe_config->port_clock == 162000 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6430 | intel_pipe_has_type(crtc, INTEL_OUTPUT_ANALOG) || |
| 6431 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6432 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Ville Syrjälä | 885b012 | 2013-07-05 19:21:38 +0300 | [diff] [blame] | 6433 | 0x009f0003); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6434 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6435 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW10(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6436 | 0x00d0000f); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6437 | |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 6438 | if (pipe_config->has_dp_encoder) { |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6439 | /* Use SSC source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6440 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6441 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6442 | 0x0df40000); |
| 6443 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6444 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6445 | 0x0df70000); |
| 6446 | } else { /* HDMI or VGA */ |
| 6447 | /* Use bend source */ |
Daniel Vetter | bdd4b6a | 2014-04-24 23:55:11 +0200 | [diff] [blame] | 6448 | if (pipe == PIPE_A) |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6449 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6450 | 0x0df70000); |
| 6451 | else |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6452 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW5(pipe), |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6453 | 0x0df40000); |
| 6454 | } |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6455 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6456 | coreclk = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW7(pipe)); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6457 | coreclk = (coreclk & 0x0000ff00) | 0x01c00000; |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6458 | if (intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT) || |
| 6459 | intel_pipe_has_type(crtc, INTEL_OUTPUT_EDP)) |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6460 | coreclk |= 0x01000000; |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6461 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW7(pipe), coreclk); |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 6462 | |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 6463 | vlv_dpio_write(dev_priv, pipe, VLV_PLL_DW11(pipe), 0x87871000); |
Daniel Vetter | 0915300 | 2012-12-12 14:06:44 +0100 | [diff] [blame] | 6464 | mutex_unlock(&dev_priv->dpio_lock); |
Jesse Barnes | a0c4da24 | 2012-06-15 11:55:13 -0700 | [diff] [blame] | 6465 | } |
| 6466 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6467 | static void chv_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6468 | struct intel_crtc_state *pipe_config) |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6469 | { |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6470 | pipe_config->dpll_hw_state.dpll = DPLL_SSC_REF_CLOCK_CHV | |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6471 | DPLL_REFA_CLK_ENABLE_VLV | DPLL_VGA_MODE_DIS | |
| 6472 | DPLL_VCO_ENABLE; |
| 6473 | if (crtc->pipe != PIPE_A) |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6474 | pipe_config->dpll_hw_state.dpll |= DPLL_INTEGRATED_CRI_CLK_VLV; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6475 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6476 | pipe_config->dpll_hw_state.dpll_md = |
| 6477 | (pipe_config->pixel_multiplier - 1) << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6478 | } |
| 6479 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6480 | static void chv_prepare_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6481 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 1ae0d13 | 2014-06-28 02:04:00 +0300 | [diff] [blame] | 6482 | { |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6483 | struct drm_device *dev = crtc->base.dev; |
| 6484 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6485 | int pipe = crtc->pipe; |
| 6486 | int dpll_reg = DPLL(crtc->pipe); |
| 6487 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6488 | u32 loopfilter, tribuf_calcntr; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6489 | u32 bestn, bestm1, bestm2, bestp1, bestp2, bestm2_frac; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6490 | u32 dpio_val; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6491 | int vco; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6492 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6493 | bestn = pipe_config->dpll.n; |
| 6494 | bestm2_frac = pipe_config->dpll.m2 & 0x3fffff; |
| 6495 | bestm1 = pipe_config->dpll.m1; |
| 6496 | bestm2 = pipe_config->dpll.m2 >> 22; |
| 6497 | bestp1 = pipe_config->dpll.p1; |
| 6498 | bestp2 = pipe_config->dpll.p2; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6499 | vco = pipe_config->dpll.vco; |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6500 | dpio_val = 0; |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6501 | loopfilter = 0; |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6502 | |
| 6503 | /* |
| 6504 | * Enable Refclk and SSC |
| 6505 | */ |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 6506 | I915_WRITE(dpll_reg, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6507 | pipe_config->dpll_hw_state.dpll & ~DPLL_VCO_ENABLE); |
Ville Syrjälä | a11b070 | 2014-04-09 13:28:57 +0300 | [diff] [blame] | 6508 | |
| 6509 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6510 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6511 | /* p1 and p2 divider */ |
| 6512 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW13(port), |
| 6513 | 5 << DPIO_CHV_S1_DIV_SHIFT | |
| 6514 | bestp1 << DPIO_CHV_P1_DIV_SHIFT | |
| 6515 | bestp2 << DPIO_CHV_P2_DIV_SHIFT | |
| 6516 | 1 << DPIO_CHV_K_DIV_SHIFT); |
| 6517 | |
| 6518 | /* Feedback post-divider - m2 */ |
| 6519 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW0(port), bestm2); |
| 6520 | |
| 6521 | /* Feedback refclk divider - n and m1 */ |
| 6522 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW1(port), |
| 6523 | DPIO_CHV_M1_DIV_BY_2 | |
| 6524 | 1 << DPIO_CHV_N_DIV_SHIFT); |
| 6525 | |
| 6526 | /* M2 fraction division */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6527 | if (bestm2_frac) |
| 6528 | 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] | 6529 | |
| 6530 | /* M2 fraction division enable */ |
Vijay Purushothaman | a945ce7e | 2015-03-05 19:30:57 +0530 | [diff] [blame] | 6531 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW3(port)); |
| 6532 | dpio_val &= ~(DPIO_CHV_FEEDFWD_GAIN_MASK | DPIO_CHV_FRAC_DIV_EN); |
| 6533 | dpio_val |= (2 << DPIO_CHV_FEEDFWD_GAIN_SHIFT); |
| 6534 | if (bestm2_frac) |
| 6535 | dpio_val |= DPIO_CHV_FRAC_DIV_EN; |
| 6536 | 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] | 6537 | |
Vijay Purushothaman | de3a0fd | 2015-03-05 19:32:06 +0530 | [diff] [blame] | 6538 | /* Program digital lock detect threshold */ |
| 6539 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW9(port)); |
| 6540 | dpio_val &= ~(DPIO_CHV_INT_LOCK_THRESHOLD_MASK | |
| 6541 | DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE); |
| 6542 | dpio_val |= (0x5 << DPIO_CHV_INT_LOCK_THRESHOLD_SHIFT); |
| 6543 | if (!bestm2_frac) |
| 6544 | dpio_val |= DPIO_CHV_INT_LOCK_THRESHOLD_SEL_COARSE; |
| 6545 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW9(port), dpio_val); |
| 6546 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6547 | /* Loop filter */ |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6548 | if (vco == 5400000) { |
| 6549 | loopfilter |= (0x3 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6550 | loopfilter |= (0x8 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6551 | loopfilter |= (0x1 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6552 | tribuf_calcntr = 0x9; |
| 6553 | } else if (vco <= 6200000) { |
| 6554 | loopfilter |= (0x5 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6555 | loopfilter |= (0xB << DPIO_CHV_INT_COEFF_SHIFT); |
| 6556 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6557 | tribuf_calcntr = 0x9; |
| 6558 | } else if (vco <= 6480000) { |
| 6559 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6560 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6561 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6562 | tribuf_calcntr = 0x8; |
| 6563 | } else { |
| 6564 | /* Not supported. Apply the same limits as in the max case */ |
| 6565 | loopfilter |= (0x4 << DPIO_CHV_PROP_COEFF_SHIFT); |
| 6566 | loopfilter |= (0x9 << DPIO_CHV_INT_COEFF_SHIFT); |
| 6567 | loopfilter |= (0x3 << DPIO_CHV_GAIN_CTRL_SHIFT); |
| 6568 | tribuf_calcntr = 0; |
| 6569 | } |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6570 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW6(port), loopfilter); |
| 6571 | |
Ville Syrjälä | 968040b | 2015-03-11 22:52:08 +0200 | [diff] [blame] | 6572 | dpio_val = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW8(port)); |
Vijay Purushothaman | 9cbe40c | 2015-03-05 19:33:08 +0530 | [diff] [blame] | 6573 | dpio_val &= ~DPIO_CHV_TDC_TARGET_CNT_MASK; |
| 6574 | dpio_val |= (tribuf_calcntr << DPIO_CHV_TDC_TARGET_CNT_SHIFT); |
| 6575 | vlv_dpio_write(dev_priv, pipe, CHV_PLL_DW8(port), dpio_val); |
| 6576 | |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 6577 | /* AFC Recal */ |
| 6578 | vlv_dpio_write(dev_priv, pipe, CHV_CMN_DW14(port), |
| 6579 | vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW14(port)) | |
| 6580 | DPIO_AFC_RECAL); |
| 6581 | |
| 6582 | mutex_unlock(&dev_priv->dpio_lock); |
| 6583 | } |
| 6584 | |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6585 | /** |
| 6586 | * vlv_force_pll_on - forcibly enable just the PLL |
| 6587 | * @dev_priv: i915 private structure |
| 6588 | * @pipe: pipe PLL to enable |
| 6589 | * @dpll: PLL configuration |
| 6590 | * |
| 6591 | * Enable the PLL for @pipe using the supplied @dpll config. To be used |
| 6592 | * in cases where we need the PLL enabled even when @pipe is not going to |
| 6593 | * be enabled. |
| 6594 | */ |
| 6595 | void vlv_force_pll_on(struct drm_device *dev, enum pipe pipe, |
| 6596 | const struct dpll *dpll) |
| 6597 | { |
| 6598 | struct intel_crtc *crtc = |
| 6599 | to_intel_crtc(intel_get_crtc_for_pipe(dev, pipe)); |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6600 | struct intel_crtc_state pipe_config = { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6601 | .base.crtc = &crtc->base, |
Ville Syrjälä | d288f65 | 2014-10-28 13:20:22 +0200 | [diff] [blame] | 6602 | .pixel_multiplier = 1, |
| 6603 | .dpll = *dpll, |
| 6604 | }; |
| 6605 | |
| 6606 | if (IS_CHERRYVIEW(dev)) { |
| 6607 | chv_update_pll(crtc, &pipe_config); |
| 6608 | chv_prepare_pll(crtc, &pipe_config); |
| 6609 | chv_enable_pll(crtc, &pipe_config); |
| 6610 | } else { |
| 6611 | vlv_update_pll(crtc, &pipe_config); |
| 6612 | vlv_prepare_pll(crtc, &pipe_config); |
| 6613 | vlv_enable_pll(crtc, &pipe_config); |
| 6614 | } |
| 6615 | } |
| 6616 | |
| 6617 | /** |
| 6618 | * vlv_force_pll_off - forcibly disable just the PLL |
| 6619 | * @dev_priv: i915 private structure |
| 6620 | * @pipe: pipe PLL to disable |
| 6621 | * |
| 6622 | * Disable the PLL for @pipe. To be used in cases where we need |
| 6623 | * the PLL enabled even when @pipe is not going to be enabled. |
| 6624 | */ |
| 6625 | void vlv_force_pll_off(struct drm_device *dev, enum pipe pipe) |
| 6626 | { |
| 6627 | if (IS_CHERRYVIEW(dev)) |
| 6628 | chv_disable_pll(to_i915(dev), pipe); |
| 6629 | else |
| 6630 | vlv_disable_pll(to_i915(dev), pipe); |
| 6631 | } |
| 6632 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6633 | static void i9xx_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6634 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6635 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6636 | int num_connectors) |
| 6637 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6638 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6639 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6640 | u32 dpll; |
| 6641 | bool is_sdvo; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6642 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6643 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6644 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6645 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6646 | is_sdvo = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_SDVO) || |
| 6647 | intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_HDMI); |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6648 | |
| 6649 | dpll = DPLL_VGA_MODE_DIS; |
| 6650 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6651 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6652 | dpll |= DPLLB_MODE_LVDS; |
| 6653 | else |
| 6654 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 6cc5f34 | 2013-03-27 00:44:53 +0100 | [diff] [blame] | 6655 | |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 6656 | if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6657 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 6658 | << SDVO_MULTIPLIER_SHIFT_HIRES; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6659 | } |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 6660 | |
| 6661 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 6662 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 6663 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6664 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 6665 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6666 | |
| 6667 | /* compute bitmask from p1 value */ |
| 6668 | if (IS_PINEVIEW(dev)) |
| 6669 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW; |
| 6670 | else { |
| 6671 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 6672 | if (IS_G4X(dev) && reduced_clock) |
| 6673 | dpll |= (1 << (reduced_clock->p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; |
| 6674 | } |
| 6675 | switch (clock->p2) { |
| 6676 | case 5: |
| 6677 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 6678 | break; |
| 6679 | case 7: |
| 6680 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 6681 | break; |
| 6682 | case 10: |
| 6683 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 6684 | break; |
| 6685 | case 14: |
| 6686 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 6687 | break; |
| 6688 | } |
| 6689 | if (INTEL_INFO(dev)->gen >= 4) |
| 6690 | dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); |
| 6691 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6692 | if (crtc_state->sdvo_tv_clock) |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6693 | dpll |= PLL_REF_INPUT_TVCLKINBC; |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6694 | else if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6695 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 6696 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 6697 | else |
| 6698 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 6699 | |
| 6700 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6701 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 6702 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6703 | if (INTEL_INFO(dev)->gen >= 4) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6704 | u32 dpll_md = (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 6705 | << DPLL_MD_UDI_MULTIPLIER_SHIFT; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6706 | crtc_state->dpll_hw_state.dpll_md = dpll_md; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6707 | } |
| 6708 | } |
| 6709 | |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6710 | static void i8xx_update_pll(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6711 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6712 | intel_clock_t *reduced_clock, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6713 | int num_connectors) |
| 6714 | { |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 6715 | struct drm_device *dev = crtc->base.dev; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6716 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6717 | u32 dpll; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6718 | struct dpll *clock = &crtc_state->dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6719 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6720 | i9xx_update_pll_dividers(crtc, crtc_state, reduced_clock); |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 6721 | |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6722 | dpll = DPLL_VGA_MODE_DIS; |
| 6723 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6724 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS)) { |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6725 | dpll |= (1 << (clock->p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 6726 | } else { |
| 6727 | if (clock->p1 == 2) |
| 6728 | dpll |= PLL_P1_DIVIDE_BY_TWO; |
| 6729 | else |
| 6730 | dpll |= (clock->p1 - 2) << DPLL_FPA01_P1_POST_DIV_SHIFT; |
| 6731 | if (clock->p2 == 4) |
| 6732 | dpll |= PLL_P2_DIVIDE_BY_4; |
| 6733 | } |
| 6734 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6735 | 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] | 6736 | dpll |= DPLL_DVO_2X_MODE; |
| 6737 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6738 | if (intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS) && |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6739 | intel_panel_use_ssc(dev_priv) && num_connectors < 2) |
| 6740 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
| 6741 | else |
| 6742 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 6743 | |
| 6744 | dpll |= DPLL_VCO_ENABLE; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6745 | crtc_state->dpll_hw_state.dpll = dpll; |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 6746 | } |
| 6747 | |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 6748 | static void intel_set_pipe_timings(struct intel_crtc *intel_crtc) |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6749 | { |
| 6750 | struct drm_device *dev = intel_crtc->base.dev; |
| 6751 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6752 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6753 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Daniel Vetter | 8a654f3 | 2013-06-01 17:16:22 +0200 | [diff] [blame] | 6754 | struct drm_display_mode *adjusted_mode = |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6755 | &intel_crtc->config->base.adjusted_mode; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 6756 | uint32_t crtc_vtotal, crtc_vblank_end; |
| 6757 | int vsyncshift = 0; |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6758 | |
| 6759 | /* We need to be careful not to changed the adjusted mode, for otherwise |
| 6760 | * the hw state checker will get angry at the mismatch. */ |
| 6761 | crtc_vtotal = adjusted_mode->crtc_vtotal; |
| 6762 | crtc_vblank_end = adjusted_mode->crtc_vblank_end; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6763 | |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 6764 | if (adjusted_mode->flags & DRM_MODE_FLAG_INTERLACE) { |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6765 | /* the chip adds 2 halflines automatically */ |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6766 | crtc_vtotal -= 1; |
| 6767 | crtc_vblank_end -= 1; |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 6768 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6769 | if (intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | 609aeac | 2014-03-28 23:29:30 +0200 | [diff] [blame] | 6770 | vsyncshift = (adjusted_mode->crtc_htotal - 1) / 2; |
| 6771 | else |
| 6772 | vsyncshift = adjusted_mode->crtc_hsync_start - |
| 6773 | adjusted_mode->crtc_htotal / 2; |
Ville Syrjälä | 1caea6e | 2014-03-28 23:29:32 +0200 | [diff] [blame] | 6774 | if (vsyncshift < 0) |
| 6775 | vsyncshift += adjusted_mode->crtc_htotal; |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6776 | } |
| 6777 | |
| 6778 | if (INTEL_INFO(dev)->gen > 3) |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6779 | I915_WRITE(VSYNCSHIFT(cpu_transcoder), vsyncshift); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6780 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6781 | I915_WRITE(HTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6782 | (adjusted_mode->crtc_hdisplay - 1) | |
| 6783 | ((adjusted_mode->crtc_htotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6784 | I915_WRITE(HBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6785 | (adjusted_mode->crtc_hblank_start - 1) | |
| 6786 | ((adjusted_mode->crtc_hblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6787 | I915_WRITE(HSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6788 | (adjusted_mode->crtc_hsync_start - 1) | |
| 6789 | ((adjusted_mode->crtc_hsync_end - 1) << 16)); |
| 6790 | |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6791 | I915_WRITE(VTOTAL(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6792 | (adjusted_mode->crtc_vdisplay - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6793 | ((crtc_vtotal - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6794 | I915_WRITE(VBLANK(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6795 | (adjusted_mode->crtc_vblank_start - 1) | |
Daniel Vetter | 4d8a62e | 2013-05-03 11:49:51 +0200 | [diff] [blame] | 6796 | ((crtc_vblank_end - 1) << 16)); |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 6797 | I915_WRITE(VSYNC(cpu_transcoder), |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6798 | (adjusted_mode->crtc_vsync_start - 1) | |
| 6799 | ((adjusted_mode->crtc_vsync_end - 1) << 16)); |
| 6800 | |
Paulo Zanoni | b5e508d | 2012-10-24 11:34:43 -0200 | [diff] [blame] | 6801 | /* Workaround: when the EDP input selection is B, the VTOTAL_B must be |
| 6802 | * programmed with the VTOTAL_EDP value. Same for VTOTAL_C. This is |
| 6803 | * documented on the DDI_FUNC_CTL register description, EDP Input Select |
| 6804 | * bits. */ |
| 6805 | if (IS_HASWELL(dev) && cpu_transcoder == TRANSCODER_EDP && |
| 6806 | (pipe == PIPE_B || pipe == PIPE_C)) |
| 6807 | I915_WRITE(VTOTAL(pipe), I915_READ(VTOTAL(cpu_transcoder))); |
| 6808 | |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6809 | /* pipesrc controls the size that is scaled from, which should |
| 6810 | * always be the user's requested size. |
| 6811 | */ |
| 6812 | I915_WRITE(PIPESRC(pipe), |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6813 | ((intel_crtc->config->pipe_src_w - 1) << 16) | |
| 6814 | (intel_crtc->config->pipe_src_h - 1)); |
Paulo Zanoni | b0e77b9 | 2012-10-01 18:10:53 -0300 | [diff] [blame] | 6815 | } |
| 6816 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6817 | static void intel_get_pipe_timings(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 6818 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6819 | { |
| 6820 | struct drm_device *dev = crtc->base.dev; |
| 6821 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6822 | enum transcoder cpu_transcoder = pipe_config->cpu_transcoder; |
| 6823 | uint32_t tmp; |
| 6824 | |
| 6825 | tmp = I915_READ(HTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6826 | pipe_config->base.adjusted_mode.crtc_hdisplay = (tmp & 0xffff) + 1; |
| 6827 | pipe_config->base.adjusted_mode.crtc_htotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6828 | tmp = I915_READ(HBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6829 | pipe_config->base.adjusted_mode.crtc_hblank_start = (tmp & 0xffff) + 1; |
| 6830 | pipe_config->base.adjusted_mode.crtc_hblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6831 | tmp = I915_READ(HSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6832 | pipe_config->base.adjusted_mode.crtc_hsync_start = (tmp & 0xffff) + 1; |
| 6833 | pipe_config->base.adjusted_mode.crtc_hsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6834 | |
| 6835 | tmp = I915_READ(VTOTAL(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6836 | pipe_config->base.adjusted_mode.crtc_vdisplay = (tmp & 0xffff) + 1; |
| 6837 | pipe_config->base.adjusted_mode.crtc_vtotal = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6838 | tmp = I915_READ(VBLANK(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6839 | pipe_config->base.adjusted_mode.crtc_vblank_start = (tmp & 0xffff) + 1; |
| 6840 | pipe_config->base.adjusted_mode.crtc_vblank_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6841 | tmp = I915_READ(VSYNC(cpu_transcoder)); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6842 | pipe_config->base.adjusted_mode.crtc_vsync_start = (tmp & 0xffff) + 1; |
| 6843 | pipe_config->base.adjusted_mode.crtc_vsync_end = ((tmp >> 16) & 0xffff) + 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6844 | |
| 6845 | if (I915_READ(PIPECONF(cpu_transcoder)) & PIPECONF_INTERLACE_MASK) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6846 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_INTERLACE; |
| 6847 | pipe_config->base.adjusted_mode.crtc_vtotal += 1; |
| 6848 | pipe_config->base.adjusted_mode.crtc_vblank_end += 1; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6849 | } |
| 6850 | |
| 6851 | tmp = I915_READ(PIPESRC(crtc->pipe)); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 6852 | pipe_config->pipe_src_h = (tmp & 0xffff) + 1; |
| 6853 | pipe_config->pipe_src_w = ((tmp >> 16) & 0xffff) + 1; |
| 6854 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6855 | pipe_config->base.mode.vdisplay = pipe_config->pipe_src_h; |
| 6856 | pipe_config->base.mode.hdisplay = pipe_config->pipe_src_w; |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 6857 | } |
| 6858 | |
Daniel Vetter | f6a8328 | 2014-02-11 15:28:57 -0800 | [diff] [blame] | 6859 | 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] | 6860 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6861 | { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6862 | mode->hdisplay = pipe_config->base.adjusted_mode.crtc_hdisplay; |
| 6863 | mode->htotal = pipe_config->base.adjusted_mode.crtc_htotal; |
| 6864 | mode->hsync_start = pipe_config->base.adjusted_mode.crtc_hsync_start; |
| 6865 | mode->hsync_end = pipe_config->base.adjusted_mode.crtc_hsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6866 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6867 | mode->vdisplay = pipe_config->base.adjusted_mode.crtc_vdisplay; |
| 6868 | mode->vtotal = pipe_config->base.adjusted_mode.crtc_vtotal; |
| 6869 | mode->vsync_start = pipe_config->base.adjusted_mode.crtc_vsync_start; |
| 6870 | mode->vsync_end = pipe_config->base.adjusted_mode.crtc_vsync_end; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6871 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6872 | mode->flags = pipe_config->base.adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6873 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 6874 | mode->clock = pipe_config->base.adjusted_mode.crtc_clock; |
| 6875 | mode->flags |= pipe_config->base.adjusted_mode.flags; |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 6876 | } |
| 6877 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6878 | static void i9xx_set_pipeconf(struct intel_crtc *intel_crtc) |
| 6879 | { |
| 6880 | struct drm_device *dev = intel_crtc->base.dev; |
| 6881 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 6882 | uint32_t pipeconf; |
| 6883 | |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6884 | pipeconf = 0; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6885 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 6886 | if ((intel_crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 6887 | (intel_crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
| 6888 | pipeconf |= I915_READ(PIPECONF(intel_crtc->pipe)) & PIPECONF_ENABLE; |
Daniel Vetter | 67c72a1 | 2013-09-24 11:46:14 +0200 | [diff] [blame] | 6889 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6890 | if (intel_crtc->config->double_wide) |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 6891 | pipeconf |= PIPECONF_DOUBLE_WIDE; |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6892 | |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6893 | /* only g4x and later have fancy bpc/dither controls */ |
| 6894 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6895 | /* 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] | 6896 | if (intel_crtc->config->dither && intel_crtc->config->pipe_bpp != 30) |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6897 | pipeconf |= PIPECONF_DITHER_EN | |
| 6898 | PIPECONF_DITHER_TYPE_SP; |
| 6899 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6900 | switch (intel_crtc->config->pipe_bpp) { |
Daniel Vetter | ff9ce46 | 2013-04-24 14:57:17 +0200 | [diff] [blame] | 6901 | case 18: |
| 6902 | pipeconf |= PIPECONF_6BPC; |
| 6903 | break; |
| 6904 | case 24: |
| 6905 | pipeconf |= PIPECONF_8BPC; |
| 6906 | break; |
| 6907 | case 30: |
| 6908 | pipeconf |= PIPECONF_10BPC; |
| 6909 | break; |
| 6910 | default: |
| 6911 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 6912 | BUG(); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6913 | } |
| 6914 | } |
| 6915 | |
| 6916 | if (HAS_PIPE_CXSR(dev)) { |
| 6917 | if (intel_crtc->lowfreq_avail) { |
| 6918 | DRM_DEBUG_KMS("enabling CxSR downclocking\n"); |
| 6919 | pipeconf |= PIPECONF_CXSR_DOWNCLOCK; |
| 6920 | } else { |
| 6921 | DRM_DEBUG_KMS("disabling CxSR downclocking\n"); |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6922 | } |
| 6923 | } |
| 6924 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6925 | 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] | 6926 | if (INTEL_INFO(dev)->gen < 4 || |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 6927 | intel_pipe_has_type(intel_crtc, INTEL_OUTPUT_SDVO)) |
Ville Syrjälä | efc2cff | 2014-03-28 23:29:31 +0200 | [diff] [blame] | 6928 | pipeconf |= PIPECONF_INTERLACE_W_FIELD_INDICATION; |
| 6929 | else |
| 6930 | pipeconf |= PIPECONF_INTERLACE_W_SYNC_SHIFT; |
| 6931 | } else |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6932 | pipeconf |= PIPECONF_PROGRESSIVE; |
| 6933 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 6934 | if (IS_VALLEYVIEW(dev) && intel_crtc->config->limited_color_range) |
Daniel Vetter | 9f11a9e | 2013-06-13 00:54:58 +0200 | [diff] [blame] | 6935 | pipeconf |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 9c8e09b | 2013-04-02 16:10:09 +0300 | [diff] [blame] | 6936 | |
Daniel Vetter | 84b046f | 2013-02-19 18:48:54 +0100 | [diff] [blame] | 6937 | I915_WRITE(PIPECONF(intel_crtc->pipe), pipeconf); |
| 6938 | POSTING_READ(PIPECONF(intel_crtc->pipe)); |
| 6939 | } |
| 6940 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6941 | static int i9xx_crtc_compute_clock(struct intel_crtc *crtc, |
| 6942 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6943 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 6944 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6945 | struct drm_i915_private *dev_priv = dev->dev_private; |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6946 | int refclk, num_connectors = 0; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 6947 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | a16af72 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 6948 | bool ok, has_reduced_clock = false; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6949 | bool is_lvds = false, is_dsi = false; |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6950 | struct intel_encoder *encoder; |
Ma Ling | d490609 | 2009-03-18 20:13:27 +0800 | [diff] [blame] | 6951 | const intel_limit_t *limit; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 6952 | struct drm_atomic_state *state = crtc_state->base.state; |
| 6953 | struct drm_connector_state *connector_state; |
| 6954 | int i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6955 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 6956 | for (i = 0; i < state->num_connector; i++) { |
| 6957 | if (!state->connectors[i]) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 6958 | continue; |
| 6959 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 6960 | connector_state = state->connector_states[i]; |
| 6961 | if (connector_state->crtc != &crtc->base) |
| 6962 | continue; |
| 6963 | |
| 6964 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 6965 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 6966 | switch (encoder->type) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6967 | case INTEL_OUTPUT_LVDS: |
| 6968 | is_lvds = true; |
| 6969 | break; |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6970 | case INTEL_OUTPUT_DSI: |
| 6971 | is_dsi = true; |
| 6972 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 6973 | default: |
| 6974 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6975 | } |
Kristian Høgsberg | 43565a0 | 2009-02-13 20:56:52 -0500 | [diff] [blame] | 6976 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 6977 | num_connectors++; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6978 | } |
| 6979 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6980 | if (is_dsi) |
Daniel Vetter | 5b18e57 | 2014-04-24 23:55:06 +0200 | [diff] [blame] | 6981 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 6982 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6983 | if (!crtc_state->clock_set) { |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6984 | refclk = i9xx_get_refclk(crtc_state, num_connectors); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6985 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6986 | /* |
| 6987 | * Returns a set of divisors for the desired target clock with |
| 6988 | * the given refclk, or FALSE. The returned values represent |
| 6989 | * the clock equation: reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + |
| 6990 | * 2) / p1 / p2. |
| 6991 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 6992 | limit = intel_limit(crtc_state, refclk); |
| 6993 | ok = dev_priv->display.find_dpll(limit, crtc_state, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 6994 | crtc_state->port_clock, |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6995 | refclk, NULL, &clock); |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 6996 | if (!ok) { |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 6997 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 6998 | return -EINVAL; |
| 6999 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7000 | |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7001 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 7002 | /* |
| 7003 | * Ensure we match the reduced clock's P to the target |
| 7004 | * clock. If the clocks don't match, we can't switch |
| 7005 | * the display clock by using the FP0/FP1. In such case |
| 7006 | * we will disable the LVDS downclock feature. |
| 7007 | */ |
| 7008 | has_reduced_clock = |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7009 | dev_priv->display.find_dpll(limit, crtc_state, |
Jani Nikula | f233533 | 2013-09-13 11:03:09 +0300 | [diff] [blame] | 7010 | dev_priv->lvds_downclock, |
| 7011 | refclk, &clock, |
| 7012 | &reduced_clock); |
| 7013 | } |
| 7014 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7015 | crtc_state->dpll.n = clock.n; |
| 7016 | crtc_state->dpll.m1 = clock.m1; |
| 7017 | crtc_state->dpll.m2 = clock.m2; |
| 7018 | crtc_state->dpll.p1 = clock.p1; |
| 7019 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 7020 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7021 | |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7022 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7023 | i8xx_update_pll(crtc, crtc_state, |
Vijay Purushothaman | 2a8f64c | 2012-09-27 19:13:06 +0530 | [diff] [blame] | 7024 | has_reduced_clock ? &reduced_clock : NULL, |
| 7025 | num_connectors); |
Chon Ming Lee | 9d556c9 | 2014-05-02 14:27:47 +0300 | [diff] [blame] | 7026 | } else if (IS_CHERRYVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7027 | chv_update_pll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7028 | } else if (IS_VALLEYVIEW(dev)) { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7029 | vlv_update_pll(crtc, crtc_state); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7030 | } else { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7031 | i9xx_update_pll(crtc, crtc_state, |
Daniel Vetter | eb1cbe4 | 2012-03-28 23:12:16 +0200 | [diff] [blame] | 7032 | has_reduced_clock ? &reduced_clock : NULL, |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 7033 | num_connectors); |
Jani Nikula | e9fd1c0 | 2013-08-27 15:12:23 +0300 | [diff] [blame] | 7034 | } |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7035 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 7036 | return 0; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 7037 | } |
| 7038 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7039 | static void i9xx_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7040 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7041 | { |
| 7042 | struct drm_device *dev = crtc->base.dev; |
| 7043 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7044 | uint32_t tmp; |
| 7045 | |
Ville Syrjälä | dc9e7dec | 2014-01-10 14:06:45 +0200 | [diff] [blame] | 7046 | if (INTEL_INFO(dev)->gen <= 3 && (IS_I830(dev) || !IS_MOBILE(dev))) |
| 7047 | return; |
| 7048 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7049 | tmp = I915_READ(PFIT_CONTROL); |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7050 | if (!(tmp & PFIT_ENABLE)) |
| 7051 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7052 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7053 | /* Check whether the pfit is attached to our pipe. */ |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7054 | if (INTEL_INFO(dev)->gen < 4) { |
| 7055 | if (crtc->pipe != PIPE_B) |
| 7056 | return; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7057 | } else { |
| 7058 | if ((tmp & PFIT_PIPE_MASK) != (crtc->pipe << PFIT_PIPE_SHIFT)) |
| 7059 | return; |
| 7060 | } |
| 7061 | |
Daniel Vetter | 0692282 | 2013-07-11 13:35:40 +0200 | [diff] [blame] | 7062 | pipe_config->gmch_pfit.control = tmp; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7063 | pipe_config->gmch_pfit.pgm_ratios = I915_READ(PFIT_PGM_RATIOS); |
| 7064 | if (INTEL_INFO(dev)->gen < 5) |
| 7065 | pipe_config->gmch_pfit.lvds_border_bits = |
| 7066 | I915_READ(LVDS) & LVDS_BORDER_ENABLE; |
| 7067 | } |
| 7068 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7069 | static void vlv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7070 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7071 | { |
| 7072 | struct drm_device *dev = crtc->base.dev; |
| 7073 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7074 | int pipe = pipe_config->cpu_transcoder; |
| 7075 | intel_clock_t clock; |
| 7076 | u32 mdiv; |
Chris Wilson | 662c6ec | 2013-09-25 14:24:01 -0700 | [diff] [blame] | 7077 | int refclk = 100000; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7078 | |
Shobhit Kumar | f573de5 | 2014-07-30 20:32:37 +0530 | [diff] [blame] | 7079 | /* In case of MIPI DPLL will not even be used */ |
| 7080 | if (!(pipe_config->dpll_hw_state.dpll & DPLL_VCO_ENABLE)) |
| 7081 | return; |
| 7082 | |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7083 | mutex_lock(&dev_priv->dpio_lock); |
Chon Ming Lee | ab3c759 | 2013-11-07 10:43:30 +0800 | [diff] [blame] | 7084 | mdiv = vlv_dpio_read(dev_priv, pipe, VLV_PLL_DW3(pipe)); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7085 | mutex_unlock(&dev_priv->dpio_lock); |
| 7086 | |
| 7087 | clock.m1 = (mdiv >> DPIO_M1DIV_SHIFT) & 7; |
| 7088 | clock.m2 = mdiv & DPIO_M2DIV_MASK; |
| 7089 | clock.n = (mdiv >> DPIO_N_SHIFT) & 0xf; |
| 7090 | clock.p1 = (mdiv >> DPIO_P1_SHIFT) & 7; |
| 7091 | clock.p2 = (mdiv >> DPIO_P2_SHIFT) & 0x1f; |
| 7092 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 7093 | vlv_clock(refclk, &clock); |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7094 | |
Ville Syrjälä | f646628 | 2013-10-14 14:50:31 +0300 | [diff] [blame] | 7095 | /* clock.dot is the fast clock */ |
| 7096 | pipe_config->port_clock = clock.dot / 5; |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7097 | } |
| 7098 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 7099 | static void |
| 7100 | i9xx_get_initial_plane_config(struct intel_crtc *crtc, |
| 7101 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7102 | { |
| 7103 | struct drm_device *dev = crtc->base.dev; |
| 7104 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7105 | u32 val, base, offset; |
| 7106 | int pipe = crtc->pipe, plane = crtc->plane; |
| 7107 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 7108 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7109 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7110 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7111 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 7112 | val = I915_READ(DSPCNTR(plane)); |
| 7113 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 7114 | return; |
| 7115 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 7116 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7117 | if (!intel_fb) { |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7118 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 7119 | return; |
| 7120 | } |
| 7121 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 7122 | fb = &intel_fb->base; |
| 7123 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7124 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7125 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7126 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 7127 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 7128 | } |
| 7129 | } |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7130 | |
| 7131 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 7132 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7133 | fb->pixel_format = fourcc; |
| 7134 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7135 | |
| 7136 | if (INTEL_INFO(dev)->gen >= 4) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 7137 | if (plane_config->tiling) |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7138 | offset = I915_READ(DSPTILEOFF(plane)); |
| 7139 | else |
| 7140 | offset = I915_READ(DSPLINOFF(plane)); |
| 7141 | base = I915_READ(DSPSURF(plane)) & 0xfffff000; |
| 7142 | } else { |
| 7143 | base = I915_READ(DSPADDR(plane)); |
| 7144 | } |
| 7145 | plane_config->base = base; |
| 7146 | |
| 7147 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7148 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 7149 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7150 | |
| 7151 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7152 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7153 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 7154 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 7155 | fb->pixel_format, |
| 7156 | fb->modifier[0]); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7157 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 7158 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7159 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 7160 | DRM_DEBUG_KMS("pipe/plane %c/%d with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 7161 | pipe_name(pipe), plane, fb->width, fb->height, |
| 7162 | fb->bits_per_pixel, base, fb->pitches[0], |
| 7163 | plane_config->size); |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7164 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 7165 | plane_config->fb = intel_fb; |
Jesse Barnes | 1ad292b | 2014-03-07 08:57:49 -0800 | [diff] [blame] | 7166 | } |
| 7167 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7168 | static void chv_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7169 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7170 | { |
| 7171 | struct drm_device *dev = crtc->base.dev; |
| 7172 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7173 | int pipe = pipe_config->cpu_transcoder; |
| 7174 | enum dpio_channel port = vlv_pipe_to_channel(pipe); |
| 7175 | intel_clock_t clock; |
| 7176 | u32 cmn_dw13, pll_dw0, pll_dw1, pll_dw2; |
| 7177 | int refclk = 100000; |
| 7178 | |
| 7179 | mutex_lock(&dev_priv->dpio_lock); |
| 7180 | cmn_dw13 = vlv_dpio_read(dev_priv, pipe, CHV_CMN_DW13(port)); |
| 7181 | pll_dw0 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW0(port)); |
| 7182 | pll_dw1 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW1(port)); |
| 7183 | pll_dw2 = vlv_dpio_read(dev_priv, pipe, CHV_PLL_DW2(port)); |
| 7184 | mutex_unlock(&dev_priv->dpio_lock); |
| 7185 | |
| 7186 | clock.m1 = (pll_dw1 & 0x7) == DPIO_CHV_M1_DIV_BY_2 ? 2 : 0; |
| 7187 | clock.m2 = ((pll_dw0 & 0xff) << 22) | (pll_dw2 & 0x3fffff); |
| 7188 | clock.n = (pll_dw1 >> DPIO_CHV_N_DIV_SHIFT) & 0xf; |
| 7189 | clock.p1 = (cmn_dw13 >> DPIO_CHV_P1_DIV_SHIFT) & 0x7; |
| 7190 | clock.p2 = (cmn_dw13 >> DPIO_CHV_P2_DIV_SHIFT) & 0x1f; |
| 7191 | |
| 7192 | chv_clock(refclk, &clock); |
| 7193 | |
| 7194 | /* clock.dot is the fast clock */ |
| 7195 | pipe_config->port_clock = clock.dot / 5; |
| 7196 | } |
| 7197 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7198 | static bool i9xx_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 7199 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7200 | { |
| 7201 | struct drm_device *dev = crtc->base.dev; |
| 7202 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7203 | uint32_t tmp; |
| 7204 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 7205 | if (!intel_display_power_is_enabled(dev_priv, |
| 7206 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 7207 | return false; |
| 7208 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 7209 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 7210 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 7211 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7212 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 7213 | if (!(tmp & PIPECONF_ENABLE)) |
| 7214 | return false; |
| 7215 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 7216 | if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) { |
| 7217 | switch (tmp & PIPECONF_BPC_MASK) { |
| 7218 | case PIPECONF_6BPC: |
| 7219 | pipe_config->pipe_bpp = 18; |
| 7220 | break; |
| 7221 | case PIPECONF_8BPC: |
| 7222 | pipe_config->pipe_bpp = 24; |
| 7223 | break; |
| 7224 | case PIPECONF_10BPC: |
| 7225 | pipe_config->pipe_bpp = 30; |
| 7226 | break; |
| 7227 | default: |
| 7228 | break; |
| 7229 | } |
| 7230 | } |
| 7231 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 7232 | if (IS_VALLEYVIEW(dev) && (tmp & PIPECONF_COLOR_RANGE_SELECT)) |
| 7233 | pipe_config->limited_color_range = true; |
| 7234 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 7235 | if (INTEL_INFO(dev)->gen < 4) |
| 7236 | pipe_config->double_wide = tmp & PIPECONF_DOUBLE_WIDE; |
| 7237 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 7238 | intel_get_pipe_timings(crtc, pipe_config); |
| 7239 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 7240 | i9xx_get_pfit_config(crtc, pipe_config); |
| 7241 | |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7242 | if (INTEL_INFO(dev)->gen >= 4) { |
| 7243 | tmp = I915_READ(DPLL_MD(crtc->pipe)); |
| 7244 | pipe_config->pixel_multiplier = |
| 7245 | ((tmp & DPLL_MD_UDI_MULTIPLIER_MASK) |
| 7246 | >> DPLL_MD_UDI_MULTIPLIER_SHIFT) + 1; |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7247 | pipe_config->dpll_hw_state.dpll_md = tmp; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7248 | } else if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) { |
| 7249 | tmp = I915_READ(DPLL(crtc->pipe)); |
| 7250 | pipe_config->pixel_multiplier = |
| 7251 | ((tmp & SDVO_MULTIPLIER_MASK) |
| 7252 | >> SDVO_MULTIPLIER_SHIFT_HIRES) + 1; |
| 7253 | } else { |
| 7254 | /* Note that on i915G/GM the pixel multiplier is in the sdvo |
| 7255 | * port and will be fixed up in the encoder->get_config |
| 7256 | * function. */ |
| 7257 | pipe_config->pixel_multiplier = 1; |
| 7258 | } |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7259 | pipe_config->dpll_hw_state.dpll = I915_READ(DPLL(crtc->pipe)); |
| 7260 | if (!IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | 1c4e027 | 2014-09-05 21:52:42 +0300 | [diff] [blame] | 7261 | /* |
| 7262 | * DPLL_DVO_2X_MODE must be enabled for both DPLLs |
| 7263 | * on 830. Filter it out here so that we don't |
| 7264 | * report errors due to that. |
| 7265 | */ |
| 7266 | if (IS_I830(dev)) |
| 7267 | pipe_config->dpll_hw_state.dpll &= ~DPLL_DVO_2X_MODE; |
| 7268 | |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7269 | pipe_config->dpll_hw_state.fp0 = I915_READ(FP0(crtc->pipe)); |
| 7270 | pipe_config->dpll_hw_state.fp1 = I915_READ(FP1(crtc->pipe)); |
Ville Syrjälä | 165e901 | 2013-06-26 17:44:15 +0300 | [diff] [blame] | 7271 | } else { |
| 7272 | /* Mask out read-only status bits. */ |
| 7273 | pipe_config->dpll_hw_state.dpll &= ~(DPLL_LOCK_VLV | |
| 7274 | DPLL_PORTC_READY_MASK | |
| 7275 | DPLL_PORTB_READY_MASK); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 7276 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 7277 | |
Ville Syrjälä | 70b23a9 | 2014-04-09 13:28:22 +0300 | [diff] [blame] | 7278 | if (IS_CHERRYVIEW(dev)) |
| 7279 | chv_crtc_clock_get(crtc, pipe_config); |
| 7280 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | acbec81 | 2013-09-20 11:29:32 -0700 | [diff] [blame] | 7281 | vlv_crtc_clock_get(crtc, pipe_config); |
| 7282 | else |
| 7283 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 7284 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 7285 | return true; |
| 7286 | } |
| 7287 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7288 | static void ironlake_init_pch_refclk(struct drm_device *dev) |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7289 | { |
| 7290 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7291 | struct intel_encoder *encoder; |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7292 | u32 val, final; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7293 | bool has_lvds = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7294 | bool has_cpu_edp = false; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7295 | bool has_panel = false; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7296 | bool has_ck505 = false; |
| 7297 | bool can_ssc = false; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7298 | |
| 7299 | /* We need to take the global config into account */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 7300 | for_each_intel_encoder(dev, encoder) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7301 | switch (encoder->type) { |
| 7302 | case INTEL_OUTPUT_LVDS: |
| 7303 | has_panel = true; |
| 7304 | has_lvds = true; |
| 7305 | break; |
| 7306 | case INTEL_OUTPUT_EDP: |
| 7307 | has_panel = true; |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 7308 | if (enc_to_dig_port(&encoder->base)->port == PORT_A) |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7309 | has_cpu_edp = true; |
| 7310 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7311 | default: |
| 7312 | break; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7313 | } |
| 7314 | } |
| 7315 | |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7316 | if (HAS_PCH_IBX(dev)) { |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7317 | has_ck505 = dev_priv->vbt.display_clock_mode; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7318 | can_ssc = has_ck505; |
| 7319 | } else { |
| 7320 | has_ck505 = false; |
| 7321 | can_ssc = true; |
| 7322 | } |
| 7323 | |
Imre Deak | 2de6905 | 2013-05-08 13:14:04 +0300 | [diff] [blame] | 7324 | DRM_DEBUG_KMS("has_panel %d has_lvds %d has_ck505 %d\n", |
| 7325 | has_panel, has_lvds, has_ck505); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7326 | |
| 7327 | /* Ironlake: try to setup display ref clock before DPLL |
| 7328 | * enabling. This is only under driver's control after |
| 7329 | * PCH B stepping, previous chipset stepping should be |
| 7330 | * ignoring this setting. |
| 7331 | */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7332 | val = I915_READ(PCH_DREF_CONTROL); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7333 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7334 | /* As we must carefully and slowly disable/enable each source in turn, |
| 7335 | * compute the final state we want first and check if we need to |
| 7336 | * make any changes at all. |
| 7337 | */ |
| 7338 | final = val; |
| 7339 | final &= ~DREF_NONSPREAD_SOURCE_MASK; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7340 | if (has_ck505) |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7341 | final |= DREF_NONSPREAD_CK505_ENABLE; |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7342 | else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7343 | final |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7344 | |
| 7345 | final &= ~DREF_SSC_SOURCE_MASK; |
| 7346 | final &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
| 7347 | final &= ~DREF_SSC1_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7348 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7349 | if (has_panel) { |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7350 | final |= DREF_SSC_SOURCE_ENABLE; |
| 7351 | |
| 7352 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7353 | final |= DREF_SSC1_ENABLE; |
| 7354 | |
| 7355 | if (has_cpu_edp) { |
| 7356 | if (intel_panel_use_ssc(dev_priv) && can_ssc) |
| 7357 | final |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
| 7358 | else |
| 7359 | final |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
| 7360 | } else |
| 7361 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 7362 | } else { |
| 7363 | final |= DREF_SSC_SOURCE_DISABLE; |
| 7364 | final |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
| 7365 | } |
| 7366 | |
| 7367 | if (final == val) |
| 7368 | return; |
| 7369 | |
| 7370 | /* Always enable nonspread source */ |
| 7371 | val &= ~DREF_NONSPREAD_SOURCE_MASK; |
| 7372 | |
| 7373 | if (has_ck505) |
| 7374 | val |= DREF_NONSPREAD_CK505_ENABLE; |
| 7375 | else |
| 7376 | val |= DREF_NONSPREAD_SOURCE_ENABLE; |
| 7377 | |
| 7378 | if (has_panel) { |
| 7379 | val &= ~DREF_SSC_SOURCE_MASK; |
| 7380 | val |= DREF_SSC_SOURCE_ENABLE; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7381 | |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7382 | /* SSC must be turned on before enabling the CPU output */ |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7383 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7384 | DRM_DEBUG_KMS("Using SSC on panel\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7385 | val |= DREF_SSC1_ENABLE; |
Daniel Vetter | e77166b | 2012-03-30 22:14:05 +0200 | [diff] [blame] | 7386 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7387 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7388 | |
| 7389 | /* Get SSC going before enabling the outputs */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7390 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7391 | POSTING_READ(PCH_DREF_CONTROL); |
| 7392 | udelay(200); |
| 7393 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7394 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7395 | |
| 7396 | /* Enable CPU source on CPU attached eDP */ |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7397 | if (has_cpu_edp) { |
Keith Packard | 99eb6a0 | 2011-09-26 14:29:12 -0700 | [diff] [blame] | 7398 | if (intel_panel_use_ssc(dev_priv) && can_ssc) { |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7399 | DRM_DEBUG_KMS("Using SSC on eDP\n"); |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7400 | val |= DREF_CPU_SOURCE_OUTPUT_DOWNSPREAD; |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 7401 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7402 | val |= DREF_CPU_SOURCE_OUTPUT_NONSPREAD; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7403 | } else |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7404 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7405 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7406 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7407 | POSTING_READ(PCH_DREF_CONTROL); |
| 7408 | udelay(200); |
| 7409 | } else { |
| 7410 | DRM_DEBUG_KMS("Disabling SSC entirely\n"); |
| 7411 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7412 | val &= ~DREF_CPU_SOURCE_OUTPUT_MASK; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7413 | |
| 7414 | /* Turn off CPU output */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7415 | val |= DREF_CPU_SOURCE_OUTPUT_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7416 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7417 | I915_WRITE(PCH_DREF_CONTROL, val); |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7418 | POSTING_READ(PCH_DREF_CONTROL); |
| 7419 | udelay(200); |
| 7420 | |
| 7421 | /* Turn off the SSC source */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7422 | val &= ~DREF_SSC_SOURCE_MASK; |
| 7423 | val |= DREF_SSC_SOURCE_DISABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7424 | |
| 7425 | /* Turn off SSC1 */ |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7426 | val &= ~DREF_SSC1_ENABLE; |
Keith Packard | 199e5d7 | 2011-09-22 12:01:57 -0700 | [diff] [blame] | 7427 | |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7428 | I915_WRITE(PCH_DREF_CONTROL, val); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7429 | POSTING_READ(PCH_DREF_CONTROL); |
| 7430 | udelay(200); |
| 7431 | } |
Chris Wilson | 74cfd7a | 2013-03-26 16:33:04 -0700 | [diff] [blame] | 7432 | |
| 7433 | BUG_ON(val != final); |
Jesse Barnes | 13d83a6 | 2011-08-03 12:59:20 -0700 | [diff] [blame] | 7434 | } |
| 7435 | |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7436 | static void lpt_reset_fdi_mphy(struct drm_i915_private *dev_priv) |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7437 | { |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7438 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7439 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7440 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 7441 | tmp |= FDI_MPHY_IOSFSB_RESET_CTL; |
| 7442 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7443 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7444 | if (wait_for_atomic_us(I915_READ(SOUTH_CHICKEN2) & |
| 7445 | FDI_MPHY_IOSFSB_RESET_STATUS, 100)) |
| 7446 | DRM_ERROR("FDI mPHY reset assert timeout\n"); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7447 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7448 | tmp = I915_READ(SOUTH_CHICKEN2); |
| 7449 | tmp &= ~FDI_MPHY_IOSFSB_RESET_CTL; |
| 7450 | I915_WRITE(SOUTH_CHICKEN2, tmp); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7451 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7452 | if (wait_for_atomic_us((I915_READ(SOUTH_CHICKEN2) & |
| 7453 | FDI_MPHY_IOSFSB_RESET_STATUS) == 0, 100)) |
| 7454 | DRM_ERROR("FDI mPHY reset de-assert timeout\n"); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7455 | } |
| 7456 | |
| 7457 | /* WaMPhyProgramming:hsw */ |
| 7458 | static void lpt_program_fdi_mphy(struct drm_i915_private *dev_priv) |
| 7459 | { |
| 7460 | uint32_t tmp; |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7461 | |
| 7462 | tmp = intel_sbi_read(dev_priv, 0x8008, SBI_MPHY); |
| 7463 | tmp &= ~(0xFF << 24); |
| 7464 | tmp |= (0x12 << 24); |
| 7465 | intel_sbi_write(dev_priv, 0x8008, tmp, SBI_MPHY); |
| 7466 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7467 | tmp = intel_sbi_read(dev_priv, 0x2008, SBI_MPHY); |
| 7468 | tmp |= (1 << 11); |
| 7469 | intel_sbi_write(dev_priv, 0x2008, tmp, SBI_MPHY); |
| 7470 | |
| 7471 | tmp = intel_sbi_read(dev_priv, 0x2108, SBI_MPHY); |
| 7472 | tmp |= (1 << 11); |
| 7473 | intel_sbi_write(dev_priv, 0x2108, tmp, SBI_MPHY); |
| 7474 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7475 | tmp = intel_sbi_read(dev_priv, 0x206C, SBI_MPHY); |
| 7476 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 7477 | intel_sbi_write(dev_priv, 0x206C, tmp, SBI_MPHY); |
| 7478 | |
| 7479 | tmp = intel_sbi_read(dev_priv, 0x216C, SBI_MPHY); |
| 7480 | tmp |= (1 << 24) | (1 << 21) | (1 << 18); |
| 7481 | intel_sbi_write(dev_priv, 0x216C, tmp, SBI_MPHY); |
| 7482 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7483 | tmp = intel_sbi_read(dev_priv, 0x2080, SBI_MPHY); |
| 7484 | tmp &= ~(7 << 13); |
| 7485 | tmp |= (5 << 13); |
| 7486 | intel_sbi_write(dev_priv, 0x2080, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7487 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7488 | tmp = intel_sbi_read(dev_priv, 0x2180, SBI_MPHY); |
| 7489 | tmp &= ~(7 << 13); |
| 7490 | tmp |= (5 << 13); |
| 7491 | intel_sbi_write(dev_priv, 0x2180, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7492 | |
| 7493 | tmp = intel_sbi_read(dev_priv, 0x208C, SBI_MPHY); |
| 7494 | tmp &= ~0xFF; |
| 7495 | tmp |= 0x1C; |
| 7496 | intel_sbi_write(dev_priv, 0x208C, tmp, SBI_MPHY); |
| 7497 | |
| 7498 | tmp = intel_sbi_read(dev_priv, 0x218C, SBI_MPHY); |
| 7499 | tmp &= ~0xFF; |
| 7500 | tmp |= 0x1C; |
| 7501 | intel_sbi_write(dev_priv, 0x218C, tmp, SBI_MPHY); |
| 7502 | |
| 7503 | tmp = intel_sbi_read(dev_priv, 0x2098, SBI_MPHY); |
| 7504 | tmp &= ~(0xFF << 16); |
| 7505 | tmp |= (0x1C << 16); |
| 7506 | intel_sbi_write(dev_priv, 0x2098, tmp, SBI_MPHY); |
| 7507 | |
| 7508 | tmp = intel_sbi_read(dev_priv, 0x2198, SBI_MPHY); |
| 7509 | tmp &= ~(0xFF << 16); |
| 7510 | tmp |= (0x1C << 16); |
| 7511 | intel_sbi_write(dev_priv, 0x2198, tmp, SBI_MPHY); |
| 7512 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7513 | tmp = intel_sbi_read(dev_priv, 0x20C4, SBI_MPHY); |
| 7514 | tmp |= (1 << 27); |
| 7515 | intel_sbi_write(dev_priv, 0x20C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7516 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7517 | tmp = intel_sbi_read(dev_priv, 0x21C4, SBI_MPHY); |
| 7518 | tmp |= (1 << 27); |
| 7519 | intel_sbi_write(dev_priv, 0x21C4, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7520 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7521 | tmp = intel_sbi_read(dev_priv, 0x20EC, SBI_MPHY); |
| 7522 | tmp &= ~(0xF << 28); |
| 7523 | tmp |= (4 << 28); |
| 7524 | intel_sbi_write(dev_priv, 0x20EC, tmp, SBI_MPHY); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7525 | |
Paulo Zanoni | 0ff066a | 2013-07-12 14:19:36 -0300 | [diff] [blame] | 7526 | tmp = intel_sbi_read(dev_priv, 0x21EC, SBI_MPHY); |
| 7527 | tmp &= ~(0xF << 28); |
| 7528 | tmp |= (4 << 28); |
| 7529 | intel_sbi_write(dev_priv, 0x21EC, tmp, SBI_MPHY); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7530 | } |
| 7531 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7532 | /* Implements 3 different sequences from BSpec chapter "Display iCLK |
| 7533 | * Programming" based on the parameters passed: |
| 7534 | * - Sequence to enable CLKOUT_DP |
| 7535 | * - Sequence to enable CLKOUT_DP without spread |
| 7536 | * - Sequence to enable CLKOUT_DP for FDI usage and configure PCH FDI I/O |
| 7537 | */ |
| 7538 | static void lpt_enable_clkout_dp(struct drm_device *dev, bool with_spread, |
| 7539 | bool with_fdi) |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7540 | { |
| 7541 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7542 | uint32_t reg, tmp; |
| 7543 | |
| 7544 | if (WARN(with_fdi && !with_spread, "FDI requires downspread\n")) |
| 7545 | with_spread = true; |
| 7546 | if (WARN(dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE && |
| 7547 | with_fdi, "LP PCH doesn't have FDI\n")) |
| 7548 | with_fdi = false; |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7549 | |
| 7550 | mutex_lock(&dev_priv->dpio_lock); |
| 7551 | |
| 7552 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 7553 | tmp &= ~SBI_SSCCTL_DISABLE; |
| 7554 | tmp |= SBI_SSCCTL_PATHALT; |
| 7555 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 7556 | |
| 7557 | udelay(24); |
| 7558 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7559 | if (with_spread) { |
| 7560 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 7561 | tmp &= ~SBI_SSCCTL_PATHALT; |
| 7562 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
Paulo Zanoni | f31f2d5 | 2013-07-18 18:51:11 -0300 | [diff] [blame] | 7563 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7564 | if (with_fdi) { |
| 7565 | lpt_reset_fdi_mphy(dev_priv); |
| 7566 | lpt_program_fdi_mphy(dev_priv); |
| 7567 | } |
| 7568 | } |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7569 | |
Paulo Zanoni | 2fa86a1 | 2013-07-23 11:19:24 -0300 | [diff] [blame] | 7570 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 7571 | SBI_GEN0 : SBI_DBUFF0; |
| 7572 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 7573 | tmp |= SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 7574 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
Daniel Vetter | c00db24 | 2013-01-22 15:33:27 +0100 | [diff] [blame] | 7575 | |
| 7576 | mutex_unlock(&dev_priv->dpio_lock); |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7577 | } |
| 7578 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 7579 | /* Sequence to disable CLKOUT_DP */ |
| 7580 | static void lpt_disable_clkout_dp(struct drm_device *dev) |
| 7581 | { |
| 7582 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7583 | uint32_t reg, tmp; |
| 7584 | |
| 7585 | mutex_lock(&dev_priv->dpio_lock); |
| 7586 | |
| 7587 | reg = (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) ? |
| 7588 | SBI_GEN0 : SBI_DBUFF0; |
| 7589 | tmp = intel_sbi_read(dev_priv, reg, SBI_ICLK); |
| 7590 | tmp &= ~SBI_GEN0_CFG_BUFFENABLE_DISABLE; |
| 7591 | intel_sbi_write(dev_priv, reg, tmp, SBI_ICLK); |
| 7592 | |
| 7593 | tmp = intel_sbi_read(dev_priv, SBI_SSCCTL, SBI_ICLK); |
| 7594 | if (!(tmp & SBI_SSCCTL_DISABLE)) { |
| 7595 | if (!(tmp & SBI_SSCCTL_PATHALT)) { |
| 7596 | tmp |= SBI_SSCCTL_PATHALT; |
| 7597 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 7598 | udelay(32); |
| 7599 | } |
| 7600 | tmp |= SBI_SSCCTL_DISABLE; |
| 7601 | intel_sbi_write(dev_priv, SBI_SSCCTL, tmp, SBI_ICLK); |
| 7602 | } |
| 7603 | |
| 7604 | mutex_unlock(&dev_priv->dpio_lock); |
| 7605 | } |
| 7606 | |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7607 | static void lpt_init_pch_refclk(struct drm_device *dev) |
| 7608 | { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7609 | struct intel_encoder *encoder; |
| 7610 | bool has_vga = false; |
| 7611 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 7612 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7613 | switch (encoder->type) { |
| 7614 | case INTEL_OUTPUT_ANALOG: |
| 7615 | has_vga = true; |
| 7616 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7617 | default: |
| 7618 | break; |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7619 | } |
| 7620 | } |
| 7621 | |
Paulo Zanoni | 47701c3 | 2013-07-23 11:19:25 -0300 | [diff] [blame] | 7622 | if (has_vga) |
| 7623 | lpt_enable_clkout_dp(dev, true, true); |
| 7624 | else |
| 7625 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | bf8fa3d | 2013-07-12 14:19:38 -0300 | [diff] [blame] | 7626 | } |
| 7627 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 7628 | /* |
| 7629 | * Initialize reference clocks when the driver loads |
| 7630 | */ |
| 7631 | void intel_init_pch_refclk(struct drm_device *dev) |
| 7632 | { |
| 7633 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 7634 | ironlake_init_pch_refclk(dev); |
| 7635 | else if (HAS_PCH_LPT(dev)) |
| 7636 | lpt_init_pch_refclk(dev); |
| 7637 | } |
| 7638 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7639 | static int ironlake_get_refclk(struct intel_crtc_state *crtc_state) |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7640 | { |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7641 | struct drm_device *dev = crtc_state->base.crtc->dev; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7642 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7643 | struct drm_atomic_state *state = crtc_state->base.state; |
| 7644 | struct drm_connector_state *connector_state; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7645 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7646 | int num_connectors = 0, i; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7647 | bool is_lvds = false; |
| 7648 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7649 | for (i = 0; i < state->num_connector; i++) { |
| 7650 | if (!state->connectors[i]) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 7651 | continue; |
| 7652 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7653 | connector_state = state->connector_states[i]; |
| 7654 | if (connector_state->crtc != crtc_state->base.crtc) |
| 7655 | continue; |
| 7656 | |
| 7657 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 7658 | |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7659 | switch (encoder->type) { |
| 7660 | case INTEL_OUTPUT_LVDS: |
| 7661 | is_lvds = true; |
| 7662 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7663 | default: |
| 7664 | break; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7665 | } |
| 7666 | num_connectors++; |
| 7667 | } |
| 7668 | |
| 7669 | 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] | 7670 | DRM_DEBUG_KMS("using SSC reference clock of %d kHz\n", |
Rodrigo Vivi | 41aa344 | 2013-05-09 20:03:18 -0300 | [diff] [blame] | 7671 | dev_priv->vbt.lvds_ssc_freq); |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 7672 | return dev_priv->vbt.lvds_ssc_freq; |
Jesse Barnes | d9d444c | 2011-09-02 13:03:05 -0700 | [diff] [blame] | 7673 | } |
| 7674 | |
| 7675 | return 120000; |
| 7676 | } |
| 7677 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 7678 | static void ironlake_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7679 | { |
| 7680 | struct drm_i915_private *dev_priv = crtc->dev->dev_private; |
| 7681 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7682 | int pipe = intel_crtc->pipe; |
| 7683 | uint32_t val; |
| 7684 | |
Daniel Vetter | 7811407 | 2013-06-13 00:54:57 +0200 | [diff] [blame] | 7685 | val = 0; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7686 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7687 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7688 | case 18: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7689 | val |= PIPECONF_6BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7690 | break; |
| 7691 | case 24: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7692 | val |= PIPECONF_8BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7693 | break; |
| 7694 | case 30: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7695 | val |= PIPECONF_10BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7696 | break; |
| 7697 | case 36: |
Daniel Vetter | dfd07d7 | 2012-12-17 11:21:38 +0100 | [diff] [blame] | 7698 | val |= PIPECONF_12BPC; |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7699 | break; |
| 7700 | default: |
Paulo Zanoni | cc769b6 | 2012-09-20 18:36:03 -0300 | [diff] [blame] | 7701 | /* Case prevented by intel_choose_pipe_bpp_dither. */ |
| 7702 | BUG(); |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7703 | } |
| 7704 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7705 | if (intel_crtc->config->dither) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7706 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 7707 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7708 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7709 | val |= PIPECONF_INTERLACED_ILK; |
| 7710 | else |
| 7711 | val |= PIPECONF_PROGRESSIVE; |
| 7712 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7713 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 7714 | val |= PIPECONF_COLOR_RANGE_SELECT; |
Ville Syrjälä | 3685a8f | 2013-01-17 16:31:28 +0200 | [diff] [blame] | 7715 | |
Paulo Zanoni | c820356 | 2012-09-12 10:06:29 -0300 | [diff] [blame] | 7716 | I915_WRITE(PIPECONF(pipe), val); |
| 7717 | POSTING_READ(PIPECONF(pipe)); |
| 7718 | } |
| 7719 | |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7720 | /* |
| 7721 | * Set up the pipe CSC unit. |
| 7722 | * |
| 7723 | * Currently only full range RGB to limited range RGB conversion |
| 7724 | * is supported, but eventually this should handle various |
| 7725 | * RGB<->YCbCr scenarios as well. |
| 7726 | */ |
Daniel Vetter | 50f3b01 | 2013-03-27 00:44:56 +0100 | [diff] [blame] | 7727 | static void intel_set_pipe_csc(struct drm_crtc *crtc) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7728 | { |
| 7729 | struct drm_device *dev = crtc->dev; |
| 7730 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 7731 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 7732 | int pipe = intel_crtc->pipe; |
| 7733 | uint16_t coeff = 0x7800; /* 1.0 */ |
| 7734 | |
| 7735 | /* |
| 7736 | * TODO: Check what kind of values actually come out of the pipe |
| 7737 | * with these coeff/postoff values and adjust to get the best |
| 7738 | * accuracy. Perhaps we even need to take the bpc value into |
| 7739 | * consideration. |
| 7740 | */ |
| 7741 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7742 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7743 | coeff = ((235 - 16) * (1 << 12) / 255) & 0xff8; /* 0.xxx... */ |
| 7744 | |
| 7745 | /* |
| 7746 | * GY/GU and RY/RU should be the other way around according |
| 7747 | * to BSpec, but reality doesn't agree. Just set them up in |
| 7748 | * a way that results in the correct picture. |
| 7749 | */ |
| 7750 | I915_WRITE(PIPE_CSC_COEFF_RY_GY(pipe), coeff << 16); |
| 7751 | I915_WRITE(PIPE_CSC_COEFF_BY(pipe), 0); |
| 7752 | |
| 7753 | I915_WRITE(PIPE_CSC_COEFF_RU_GU(pipe), coeff); |
| 7754 | I915_WRITE(PIPE_CSC_COEFF_BU(pipe), 0); |
| 7755 | |
| 7756 | I915_WRITE(PIPE_CSC_COEFF_RV_GV(pipe), 0); |
| 7757 | I915_WRITE(PIPE_CSC_COEFF_BV(pipe), coeff << 16); |
| 7758 | |
| 7759 | I915_WRITE(PIPE_CSC_PREOFF_HI(pipe), 0); |
| 7760 | I915_WRITE(PIPE_CSC_PREOFF_ME(pipe), 0); |
| 7761 | I915_WRITE(PIPE_CSC_PREOFF_LO(pipe), 0); |
| 7762 | |
| 7763 | if (INTEL_INFO(dev)->gen > 6) { |
| 7764 | uint16_t postoff = 0; |
| 7765 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7766 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 32cf0cb | 2013-11-28 22:10:38 +0200 | [diff] [blame] | 7767 | postoff = (16 * (1 << 12) / 255) & 0x1fff; |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7768 | |
| 7769 | I915_WRITE(PIPE_CSC_POSTOFF_HI(pipe), postoff); |
| 7770 | I915_WRITE(PIPE_CSC_POSTOFF_ME(pipe), postoff); |
| 7771 | I915_WRITE(PIPE_CSC_POSTOFF_LO(pipe), postoff); |
| 7772 | |
| 7773 | I915_WRITE(PIPE_CSC_MODE(pipe), 0); |
| 7774 | } else { |
| 7775 | uint32_t mode = CSC_MODE_YUV_TO_RGB; |
| 7776 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7777 | if (intel_crtc->config->limited_color_range) |
Ville Syrjälä | 86d3efc | 2013-01-18 19:11:38 +0200 | [diff] [blame] | 7778 | mode |= CSC_BLACK_SCREEN_OFFSET; |
| 7779 | |
| 7780 | I915_WRITE(PIPE_CSC_MODE(pipe), mode); |
| 7781 | } |
| 7782 | } |
| 7783 | |
Daniel Vetter | 6ff9360 | 2013-04-19 11:24:36 +0200 | [diff] [blame] | 7784 | static void haswell_set_pipeconf(struct drm_crtc *crtc) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7785 | { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7786 | struct drm_device *dev = crtc->dev; |
| 7787 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7788 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7789 | enum pipe pipe = intel_crtc->pipe; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7790 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7791 | uint32_t val; |
| 7792 | |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 7793 | val = 0; |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7794 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7795 | if (IS_HASWELL(dev) && intel_crtc->config->dither) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7796 | val |= (PIPECONF_DITHER_EN | PIPECONF_DITHER_TYPE_SP); |
| 7797 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7798 | if (intel_crtc->config->base.adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE) |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7799 | val |= PIPECONF_INTERLACED_ILK; |
| 7800 | else |
| 7801 | val |= PIPECONF_PROGRESSIVE; |
| 7802 | |
Paulo Zanoni | 702e7a5 | 2012-10-23 18:29:59 -0200 | [diff] [blame] | 7803 | I915_WRITE(PIPECONF(cpu_transcoder), val); |
| 7804 | POSTING_READ(PIPECONF(cpu_transcoder)); |
Daniel Vetter | 3eff4fa | 2013-06-13 00:54:59 +0200 | [diff] [blame] | 7805 | |
| 7806 | I915_WRITE(GAMMA_MODE(intel_crtc->pipe), GAMMA_MODE_MODE_8BIT); |
| 7807 | POSTING_READ(GAMMA_MODE(intel_crtc->pipe)); |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7808 | |
Satheeshakrishna M | 3cdf122 | 2014-04-08 15:46:53 +0530 | [diff] [blame] | 7809 | if (IS_BROADWELL(dev) || INTEL_INFO(dev)->gen >= 9) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7810 | val = 0; |
| 7811 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7812 | switch (intel_crtc->config->pipe_bpp) { |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7813 | case 18: |
| 7814 | val |= PIPEMISC_DITHER_6_BPC; |
| 7815 | break; |
| 7816 | case 24: |
| 7817 | val |= PIPEMISC_DITHER_8_BPC; |
| 7818 | break; |
| 7819 | case 30: |
| 7820 | val |= PIPEMISC_DITHER_10_BPC; |
| 7821 | break; |
| 7822 | case 36: |
| 7823 | val |= PIPEMISC_DITHER_12_BPC; |
| 7824 | break; |
| 7825 | default: |
| 7826 | /* Case prevented by pipe_config_set_bpp. */ |
| 7827 | BUG(); |
| 7828 | } |
| 7829 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 7830 | if (intel_crtc->config->dither) |
Paulo Zanoni | 756f85c | 2013-11-02 21:07:38 -0700 | [diff] [blame] | 7831 | val |= PIPEMISC_DITHER_ENABLE | PIPEMISC_DITHER_TYPE_SP; |
| 7832 | |
| 7833 | I915_WRITE(PIPEMISC(pipe), val); |
| 7834 | } |
Paulo Zanoni | ee2b0b3 | 2012-10-05 12:05:57 -0300 | [diff] [blame] | 7835 | } |
| 7836 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7837 | static bool ironlake_compute_clocks(struct drm_crtc *crtc, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7838 | struct intel_crtc_state *crtc_state, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7839 | intel_clock_t *clock, |
| 7840 | bool *has_reduced_clock, |
| 7841 | intel_clock_t *reduced_clock) |
| 7842 | { |
| 7843 | struct drm_device *dev = crtc->dev; |
| 7844 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7845 | int refclk; |
| 7846 | const intel_limit_t *limit; |
Daniel Vetter | a16af72 | 2013-04-30 14:01:44 +0200 | [diff] [blame] | 7847 | bool ret, is_lvds = false; |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7848 | |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7849 | is_lvds = intel_pipe_will_have_type(crtc_state, INTEL_OUTPUT_LVDS); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7850 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7851 | refclk = ironlake_get_refclk(crtc_state); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7852 | |
| 7853 | /* |
| 7854 | * Returns a set of divisors for the desired target clock with the given |
| 7855 | * refclk, or FALSE. The returned values represent the clock equation: |
| 7856 | * reflck * (5 * (m1 + 2) + (m2 + 2)) / (n + 2) / p1 / p2. |
| 7857 | */ |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7858 | limit = intel_limit(crtc_state, refclk); |
| 7859 | ret = dev_priv->display.find_dpll(limit, crtc_state, |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7860 | crtc_state->port_clock, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7861 | refclk, NULL, clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7862 | if (!ret) |
| 7863 | return false; |
| 7864 | |
| 7865 | if (is_lvds && dev_priv->lvds_downclock_avail) { |
| 7866 | /* |
| 7867 | * Ensure we match the reduced clock's P to the target clock. |
| 7868 | * If the clocks don't match, we can't switch the display clock |
| 7869 | * by using the FP0/FP1. In such case we will disable the LVDS |
| 7870 | * downclock feature. |
| 7871 | */ |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7872 | *has_reduced_clock = |
Ander Conselvan de Oliveira | a93e255 | 2015-03-20 16:18:17 +0200 | [diff] [blame] | 7873 | dev_priv->display.find_dpll(limit, crtc_state, |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 7874 | dev_priv->lvds_downclock, |
| 7875 | refclk, clock, |
| 7876 | reduced_clock); |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7877 | } |
| 7878 | |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 7879 | return true; |
| 7880 | } |
| 7881 | |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7882 | int ironlake_get_lanes_required(int target_clock, int link_bw, int bpp) |
| 7883 | { |
| 7884 | /* |
| 7885 | * Account for spread spectrum to avoid |
| 7886 | * oversubscribing the link. Max center spread |
| 7887 | * is 2.5%; use 5% for safety's sake. |
| 7888 | */ |
| 7889 | u32 bps = target_clock * bpp * 21 / 20; |
Ville Syrjälä | 619d4d0 | 2014-02-27 14:23:14 +0200 | [diff] [blame] | 7890 | return DIV_ROUND_UP(bps, link_bw * 8); |
Paulo Zanoni | d4b1931 | 2012-11-29 11:29:32 -0200 | [diff] [blame] | 7891 | } |
| 7892 | |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7893 | static bool ironlake_needs_fb_cb_tune(struct dpll *dpll, int factor) |
Daniel Vetter | 6cf86a5 | 2013-04-02 23:38:10 +0200 | [diff] [blame] | 7894 | { |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7895 | return i9xx_dpll_compute_m(dpll) < factor * dpll->n; |
Paulo Zanoni | f48d8f2 | 2012-09-20 18:36:04 -0300 | [diff] [blame] | 7896 | } |
| 7897 | |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7898 | 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] | 7899 | struct intel_crtc_state *crtc_state, |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 7900 | u32 *fp, |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7901 | intel_clock_t *reduced_clock, u32 *fp2) |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7902 | { |
| 7903 | struct drm_crtc *crtc = &intel_crtc->base; |
| 7904 | struct drm_device *dev = crtc->dev; |
| 7905 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7906 | struct drm_atomic_state *state = crtc_state->base.state; |
| 7907 | struct drm_connector_state *connector_state; |
| 7908 | struct intel_encoder *encoder; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7909 | uint32_t dpll; |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7910 | int factor, num_connectors = 0, i; |
Daniel Vetter | 09ede54 | 2013-04-30 14:01:45 +0200 | [diff] [blame] | 7911 | bool is_lvds = false, is_sdvo = false; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7912 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7913 | for (i = 0; i < state->num_connector; i++) { |
| 7914 | if (!state->connectors[i]) |
Ander Conselvan de Oliveira | d0737e1 | 2014-10-29 11:32:30 +0200 | [diff] [blame] | 7915 | continue; |
| 7916 | |
Ander Conselvan de Oliveira | 55bb999 | 2015-03-20 16:18:19 +0200 | [diff] [blame] | 7917 | connector_state = state->connector_states[i]; |
| 7918 | if (connector_state->crtc != crtc_state->base.crtc) |
| 7919 | continue; |
| 7920 | |
| 7921 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 7922 | |
| 7923 | switch (encoder->type) { |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7924 | case INTEL_OUTPUT_LVDS: |
| 7925 | is_lvds = true; |
| 7926 | break; |
| 7927 | case INTEL_OUTPUT_SDVO: |
| 7928 | case INTEL_OUTPUT_HDMI: |
| 7929 | is_sdvo = true; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7930 | break; |
Paulo Zanoni | 6847d71b | 2014-10-27 17:47:52 -0200 | [diff] [blame] | 7931 | default: |
| 7932 | break; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7933 | } |
| 7934 | |
| 7935 | num_connectors++; |
| 7936 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7937 | |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7938 | /* Enable autotuning of the PLL clock (if permissible) */ |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7939 | factor = 21; |
| 7940 | if (is_lvds) { |
| 7941 | if ((intel_panel_use_ssc(dev_priv) && |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 7942 | dev_priv->vbt.lvds_ssc_freq == 100000) || |
Daniel Vetter | f0b4405 | 2013-04-04 22:20:33 +0200 | [diff] [blame] | 7943 | (HAS_PCH_IBX(dev) && intel_is_dual_link_lvds(dev))) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7944 | factor = 25; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7945 | } else if (crtc_state->sdvo_tv_clock) |
Eric Anholt | 8febb29 | 2011-03-30 13:01:07 -0700 | [diff] [blame] | 7946 | factor = 20; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7947 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7948 | if (ironlake_needs_fb_cb_tune(&crtc_state->dpll, factor)) |
Daniel Vetter | 7d0ac5b | 2013-04-04 22:20:32 +0200 | [diff] [blame] | 7949 | *fp |= FP_CB_TUNE; |
Chris Wilson | c185812 | 2010-12-03 21:35:48 +0000 | [diff] [blame] | 7950 | |
Daniel Vetter | 9a7c789 | 2013-04-04 22:20:34 +0200 | [diff] [blame] | 7951 | if (fp2 && (reduced_clock->m < factor * reduced_clock->n)) |
| 7952 | *fp2 |= FP_CB_TUNE; |
| 7953 | |
Chris Wilson | 5eddb70 | 2010-09-11 13:48:45 +0100 | [diff] [blame] | 7954 | dpll = 0; |
Zhenyu Wang | 2c07245 | 2009-06-05 15:38:42 +0800 | [diff] [blame] | 7955 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7956 | if (is_lvds) |
| 7957 | dpll |= DPLLB_MODE_LVDS; |
| 7958 | else |
| 7959 | dpll |= DPLLB_MODE_DAC_SERIAL; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7960 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7961 | dpll |= (crtc_state->pixel_multiplier - 1) |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 7962 | << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; |
Daniel Vetter | 198a037f | 2013-04-19 11:14:37 +0200 | [diff] [blame] | 7963 | |
| 7964 | if (is_sdvo) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7965 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7966 | if (crtc_state->has_dp_encoder) |
Daniel Vetter | 4a33e48 | 2013-07-06 12:52:05 +0200 | [diff] [blame] | 7967 | dpll |= DPLL_SDVO_HIGH_SPEED; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7968 | |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7969 | /* compute bitmask from p1 value */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7970 | 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] | 7971 | /* also FPA1 */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7972 | 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] | 7973 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7974 | switch (crtc_state->dpll.p2) { |
Eric Anholt | a07d678 | 2011-03-30 13:01:08 -0700 | [diff] [blame] | 7975 | case 5: |
| 7976 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_5; |
| 7977 | break; |
| 7978 | case 7: |
| 7979 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_7; |
| 7980 | break; |
| 7981 | case 10: |
| 7982 | dpll |= DPLL_DAC_SERIAL_P2_CLOCK_DIV_10; |
| 7983 | break; |
| 7984 | case 14: |
| 7985 | dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; |
| 7986 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7987 | } |
| 7988 | |
Daniel Vetter | b4c09f3 | 2013-04-30 14:01:42 +0200 | [diff] [blame] | 7989 | 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] | 7990 | dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7991 | else |
| 7992 | dpll |= PLL_REF_INPUT_DREFCLK; |
| 7993 | |
Daniel Vetter | 959e16d | 2013-06-05 13:34:21 +0200 | [diff] [blame] | 7994 | return dpll | DPLL_VCO_ENABLE; |
Paulo Zanoni | de13a2e | 2012-09-20 18:36:05 -0300 | [diff] [blame] | 7995 | } |
| 7996 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 7997 | static int ironlake_crtc_compute_clock(struct intel_crtc *crtc, |
| 7998 | struct intel_crtc_state *crtc_state) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 7999 | { |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8000 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8001 | intel_clock_t clock, reduced_clock; |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8002 | u32 dpll = 0, fp = 0, fp2 = 0; |
Paulo Zanoni | e2f12b0 | 2012-09-20 18:36:06 -0300 | [diff] [blame] | 8003 | bool ok, has_reduced_clock = false; |
Daniel Vetter | 8b47047 | 2013-03-28 10:41:59 +0100 | [diff] [blame] | 8004 | bool is_lvds = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8005 | struct intel_shared_dpll *pll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8006 | |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 8007 | is_lvds = intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8008 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 8009 | WARN(!(HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)), |
| 8010 | "Unexpected PCH type %d\n", INTEL_PCH_TYPE(dev)); |
| 8011 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8012 | ok = ironlake_compute_clocks(&crtc->base, crtc_state, &clock, |
Paulo Zanoni | 6591c6e | 2012-09-12 10:06:34 -0300 | [diff] [blame] | 8013 | &has_reduced_clock, &reduced_clock); |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8014 | if (!ok && !crtc_state->clock_set) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8015 | DRM_ERROR("Couldn't find PLL settings for mode!\n"); |
| 8016 | return -EINVAL; |
| 8017 | } |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8018 | /* Compat-code for transition, will disappear. */ |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8019 | if (!crtc_state->clock_set) { |
| 8020 | crtc_state->dpll.n = clock.n; |
| 8021 | crtc_state->dpll.m1 = clock.m1; |
| 8022 | crtc_state->dpll.m2 = clock.m2; |
| 8023 | crtc_state->dpll.p1 = clock.p1; |
| 8024 | crtc_state->dpll.p2 = clock.p2; |
Daniel Vetter | f47709a | 2013-03-28 10:42:02 +0100 | [diff] [blame] | 8025 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8026 | |
Paulo Zanoni | 5dc5298 | 2012-10-05 12:05:56 -0300 | [diff] [blame] | 8027 | /* 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] | 8028 | if (crtc_state->has_pch_encoder) { |
| 8029 | fp = i9xx_dpll_compute_fp(&crtc_state->dpll); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8030 | if (has_reduced_clock) |
Daniel Vetter | 7429e9d | 2013-04-20 17:19:46 +0200 | [diff] [blame] | 8031 | fp2 = i9xx_dpll_compute_fp(&reduced_clock); |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8032 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8033 | dpll = ironlake_compute_dpll(crtc, crtc_state, |
Daniel Vetter | cbbab5b | 2013-04-19 11:14:31 +0200 | [diff] [blame] | 8034 | &fp, &reduced_clock, |
| 8035 | has_reduced_clock ? &fp2 : NULL); |
| 8036 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8037 | crtc_state->dpll_hw_state.dpll = dpll; |
| 8038 | crtc_state->dpll_hw_state.fp0 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8039 | if (has_reduced_clock) |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8040 | crtc_state->dpll_hw_state.fp1 = fp2; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8041 | else |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8042 | crtc_state->dpll_hw_state.fp1 = fp; |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8043 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8044 | pll = intel_get_shared_dpll(crtc, crtc_state); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 8045 | if (pll == NULL) { |
Ville Syrjälä | 84f44ce | 2013-04-17 17:48:49 +0300 | [diff] [blame] | 8046 | 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] | 8047 | pipe_name(crtc->pipe)); |
Jesse Barnes | 4b645f1 | 2011-10-12 09:51:31 -0700 | [diff] [blame] | 8048 | return -EINVAL; |
| 8049 | } |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 8050 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8051 | |
Rodrigo Vivi | ab585de | 2015-03-24 12:40:09 -0700 | [diff] [blame] | 8052 | if (is_lvds && has_reduced_clock) |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8053 | crtc->lowfreq_avail = true; |
Daniel Vetter | bcd644e | 2013-06-05 13:34:22 +0200 | [diff] [blame] | 8054 | else |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8055 | crtc->lowfreq_avail = false; |
Daniel Vetter | e2b7826 | 2013-06-07 23:10:03 +0200 | [diff] [blame] | 8056 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8057 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8058 | } |
| 8059 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8060 | static void intel_pch_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8061 | struct intel_link_m_n *m_n) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8062 | { |
| 8063 | struct drm_device *dev = crtc->base.dev; |
| 8064 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8065 | enum pipe pipe = crtc->pipe; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8066 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8067 | m_n->link_m = I915_READ(PCH_TRANS_LINK_M1(pipe)); |
| 8068 | m_n->link_n = I915_READ(PCH_TRANS_LINK_N1(pipe)); |
| 8069 | m_n->gmch_m = I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8070 | & ~TU_SIZE_MASK; |
| 8071 | m_n->gmch_n = I915_READ(PCH_TRANS_DATA_N1(pipe)); |
| 8072 | m_n->tu = ((I915_READ(PCH_TRANS_DATA_M1(pipe)) |
| 8073 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8074 | } |
| 8075 | |
| 8076 | static void intel_cpu_transcoder_get_m_n(struct intel_crtc *crtc, |
| 8077 | enum transcoder transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8078 | struct intel_link_m_n *m_n, |
| 8079 | struct intel_link_m_n *m2_n2) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8080 | { |
| 8081 | struct drm_device *dev = crtc->base.dev; |
| 8082 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8083 | enum pipe pipe = crtc->pipe; |
| 8084 | |
| 8085 | if (INTEL_INFO(dev)->gen >= 5) { |
| 8086 | m_n->link_m = I915_READ(PIPE_LINK_M1(transcoder)); |
| 8087 | m_n->link_n = I915_READ(PIPE_LINK_N1(transcoder)); |
| 8088 | m_n->gmch_m = I915_READ(PIPE_DATA_M1(transcoder)) |
| 8089 | & ~TU_SIZE_MASK; |
| 8090 | m_n->gmch_n = I915_READ(PIPE_DATA_N1(transcoder)); |
| 8091 | m_n->tu = ((I915_READ(PIPE_DATA_M1(transcoder)) |
| 8092 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8093 | /* Read M2_N2 registers only for gen < 8 (M2_N2 available for |
| 8094 | * gen < 8) and if DRRS is supported (to make sure the |
| 8095 | * registers are not unnecessarily read). |
| 8096 | */ |
| 8097 | if (m2_n2 && INTEL_INFO(dev)->gen < 8 && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8098 | crtc->config->has_drrs) { |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8099 | m2_n2->link_m = I915_READ(PIPE_LINK_M2(transcoder)); |
| 8100 | m2_n2->link_n = I915_READ(PIPE_LINK_N2(transcoder)); |
| 8101 | m2_n2->gmch_m = I915_READ(PIPE_DATA_M2(transcoder)) |
| 8102 | & ~TU_SIZE_MASK; |
| 8103 | m2_n2->gmch_n = I915_READ(PIPE_DATA_N2(transcoder)); |
| 8104 | m2_n2->tu = ((I915_READ(PIPE_DATA_M2(transcoder)) |
| 8105 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8106 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8107 | } else { |
| 8108 | m_n->link_m = I915_READ(PIPE_LINK_M_G4X(pipe)); |
| 8109 | m_n->link_n = I915_READ(PIPE_LINK_N_G4X(pipe)); |
| 8110 | m_n->gmch_m = I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8111 | & ~TU_SIZE_MASK; |
| 8112 | m_n->gmch_n = I915_READ(PIPE_DATA_N_G4X(pipe)); |
| 8113 | m_n->tu = ((I915_READ(PIPE_DATA_M_G4X(pipe)) |
| 8114 | & TU_SIZE_MASK) >> TU_SIZE_SHIFT) + 1; |
| 8115 | } |
| 8116 | } |
| 8117 | |
| 8118 | void intel_dp_get_m_n(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8119 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8120 | { |
Ander Conselvan de Oliveira | 681a850 | 2015-01-15 14:55:24 +0200 | [diff] [blame] | 8121 | if (pipe_config->has_pch_encoder) |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8122 | intel_pch_transcoder_get_m_n(crtc, &pipe_config->dp_m_n); |
| 8123 | else |
| 8124 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8125 | &pipe_config->dp_m_n, |
| 8126 | &pipe_config->dp_m2_n2); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8127 | } |
| 8128 | |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8129 | 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] | 8130 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8131 | { |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 8132 | intel_cpu_transcoder_get_m_n(crtc, pipe_config->cpu_transcoder, |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 8133 | &pipe_config->fdi_m_n, NULL); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8134 | } |
| 8135 | |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8136 | static void skylake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8137 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8138 | { |
| 8139 | struct drm_device *dev = crtc->base.dev; |
| 8140 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8141 | uint32_t tmp; |
| 8142 | |
| 8143 | tmp = I915_READ(PS_CTL(crtc->pipe)); |
| 8144 | |
| 8145 | if (tmp & PS_ENABLE) { |
| 8146 | pipe_config->pch_pfit.enabled = true; |
| 8147 | pipe_config->pch_pfit.pos = I915_READ(PS_WIN_POS(crtc->pipe)); |
| 8148 | pipe_config->pch_pfit.size = I915_READ(PS_WIN_SZ(crtc->pipe)); |
| 8149 | } |
| 8150 | } |
| 8151 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8152 | static void |
| 8153 | skylake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8154 | struct intel_initial_plane_config *plane_config) |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8155 | { |
| 8156 | struct drm_device *dev = crtc->base.dev; |
| 8157 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8158 | u32 val, base, offset, stride_mult, tiling; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8159 | int pipe = crtc->pipe; |
| 8160 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8161 | unsigned int aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8162 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8163 | struct intel_framebuffer *intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8164 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8165 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8166 | if (!intel_fb) { |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8167 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8168 | return; |
| 8169 | } |
| 8170 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8171 | fb = &intel_fb->base; |
| 8172 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8173 | val = I915_READ(PLANE_CTL(pipe, 0)); |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8174 | if (!(val & PLANE_CTL_ENABLE)) |
| 8175 | goto error; |
| 8176 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8177 | pixel_format = val & PLANE_CTL_FORMAT_MASK; |
| 8178 | fourcc = skl_format_to_fourcc(pixel_format, |
| 8179 | val & PLANE_CTL_ORDER_RGBX, |
| 8180 | val & PLANE_CTL_ALPHA_MASK); |
| 8181 | fb->pixel_format = fourcc; |
| 8182 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
| 8183 | |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8184 | tiling = val & PLANE_CTL_TILED_MASK; |
| 8185 | switch (tiling) { |
| 8186 | case PLANE_CTL_TILED_LINEAR: |
| 8187 | fb->modifier[0] = DRM_FORMAT_MOD_NONE; |
| 8188 | break; |
| 8189 | case PLANE_CTL_TILED_X: |
| 8190 | plane_config->tiling = I915_TILING_X; |
| 8191 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 8192 | break; |
| 8193 | case PLANE_CTL_TILED_Y: |
| 8194 | fb->modifier[0] = I915_FORMAT_MOD_Y_TILED; |
| 8195 | break; |
| 8196 | case PLANE_CTL_TILED_YF: |
| 8197 | fb->modifier[0] = I915_FORMAT_MOD_Yf_TILED; |
| 8198 | break; |
| 8199 | default: |
| 8200 | MISSING_CASE(tiling); |
| 8201 | goto error; |
| 8202 | } |
| 8203 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8204 | base = I915_READ(PLANE_SURF(pipe, 0)) & 0xfffff000; |
| 8205 | plane_config->base = base; |
| 8206 | |
| 8207 | offset = I915_READ(PLANE_OFFSET(pipe, 0)); |
| 8208 | |
| 8209 | val = I915_READ(PLANE_SIZE(pipe, 0)); |
| 8210 | fb->height = ((val >> 16) & 0xfff) + 1; |
| 8211 | fb->width = ((val >> 0) & 0x1fff) + 1; |
| 8212 | |
| 8213 | val = I915_READ(PLANE_STRIDE(pipe, 0)); |
Damien Lespiau | 40f4628 | 2015-02-27 11:15:21 +0000 | [diff] [blame] | 8214 | stride_mult = intel_fb_stride_alignment(dev, fb->modifier[0], |
| 8215 | fb->pixel_format); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8216 | fb->pitches[0] = (val & 0x3ff) * stride_mult; |
| 8217 | |
| 8218 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8219 | fb->pixel_format, |
| 8220 | fb->modifier[0]); |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8221 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8222 | plane_config->size = fb->pitches[0] * aligned_height; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8223 | |
| 8224 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8225 | pipe_name(pipe), fb->width, fb->height, |
| 8226 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8227 | plane_config->size); |
| 8228 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8229 | plane_config->fb = intel_fb; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 8230 | return; |
| 8231 | |
| 8232 | error: |
| 8233 | kfree(fb); |
| 8234 | } |
| 8235 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8236 | static void ironlake_get_pfit_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8237 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8238 | { |
| 8239 | struct drm_device *dev = crtc->base.dev; |
| 8240 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8241 | uint32_t tmp; |
| 8242 | |
| 8243 | tmp = I915_READ(PF_CTL(crtc->pipe)); |
| 8244 | |
| 8245 | if (tmp & PF_ENABLE) { |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 8246 | pipe_config->pch_pfit.enabled = true; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8247 | pipe_config->pch_pfit.pos = I915_READ(PF_WIN_POS(crtc->pipe)); |
| 8248 | pipe_config->pch_pfit.size = I915_READ(PF_WIN_SZ(crtc->pipe)); |
Daniel Vetter | cb8b2a3 | 2013-06-01 17:16:23 +0200 | [diff] [blame] | 8249 | |
| 8250 | /* We currently do not free assignements of panel fitters on |
| 8251 | * ivb/hsw (since we don't use the higher upscaling modes which |
| 8252 | * differentiates them) so just WARN about this case for now. */ |
| 8253 | if (IS_GEN7(dev)) { |
| 8254 | WARN_ON((tmp & PF_PIPE_SEL_MASK_IVB) != |
| 8255 | PF_PIPE_SEL_IVB(crtc->pipe)); |
| 8256 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8257 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8258 | } |
| 8259 | |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 8260 | static void |
| 8261 | ironlake_get_initial_plane_config(struct intel_crtc *crtc, |
| 8262 | struct intel_initial_plane_config *plane_config) |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8263 | { |
| 8264 | struct drm_device *dev = crtc->base.dev; |
| 8265 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8266 | u32 val, base, offset; |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8267 | int pipe = crtc->pipe; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8268 | int fourcc, pixel_format; |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 8269 | unsigned int aligned_height; |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8270 | struct drm_framebuffer *fb; |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8271 | struct intel_framebuffer *intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8272 | |
Damien Lespiau | 42a7b08 | 2015-02-05 19:35:13 +0000 | [diff] [blame] | 8273 | val = I915_READ(DSPCNTR(pipe)); |
| 8274 | if (!(val & DISPLAY_PLANE_ENABLE)) |
| 8275 | return; |
| 8276 | |
Damien Lespiau | d9806c9 | 2015-01-21 14:07:19 +0000 | [diff] [blame] | 8277 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8278 | if (!intel_fb) { |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8279 | DRM_DEBUG_KMS("failed to alloc fb\n"); |
| 8280 | return; |
| 8281 | } |
| 8282 | |
Damien Lespiau | 1b842c8 | 2015-01-21 13:50:54 +0000 | [diff] [blame] | 8283 | fb = &intel_fb->base; |
| 8284 | |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8285 | if (INTEL_INFO(dev)->gen >= 4) { |
| 8286 | if (val & DISPPLANE_TILED) { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8287 | plane_config->tiling = I915_TILING_X; |
Daniel Vetter | 18c5247 | 2015-02-10 17:16:09 +0000 | [diff] [blame] | 8288 | fb->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 8289 | } |
| 8290 | } |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8291 | |
| 8292 | pixel_format = val & DISPPLANE_PIXFORMAT_MASK; |
Damien Lespiau | b35d63f | 2015-01-20 12:51:50 +0000 | [diff] [blame] | 8293 | fourcc = i9xx_format_to_fourcc(pixel_format); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8294 | fb->pixel_format = fourcc; |
| 8295 | fb->bits_per_pixel = drm_format_plane_cpp(fourcc, 0) * 8; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8296 | |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8297 | base = I915_READ(DSPSURF(pipe)) & 0xfffff000; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8298 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8299 | offset = I915_READ(DSPOFFSET(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8300 | } else { |
Damien Lespiau | 49af449 | 2015-01-20 12:51:44 +0000 | [diff] [blame] | 8301 | if (plane_config->tiling) |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8302 | offset = I915_READ(DSPTILEOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8303 | else |
Damien Lespiau | aeee5a4 | 2015-01-20 12:51:47 +0000 | [diff] [blame] | 8304 | offset = I915_READ(DSPLINOFF(pipe)); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8305 | } |
| 8306 | plane_config->base = base; |
| 8307 | |
| 8308 | val = I915_READ(PIPESRC(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8309 | fb->width = ((val >> 16) & 0xfff) + 1; |
| 8310 | fb->height = ((val >> 0) & 0xfff) + 1; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8311 | |
| 8312 | val = I915_READ(DSPSTRIDE(pipe)); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8313 | fb->pitches[0] = val & 0xffffffc0; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8314 | |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8315 | aligned_height = intel_fb_align_height(dev, fb->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 8316 | fb->pixel_format, |
| 8317 | fb->modifier[0]); |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8318 | |
Daniel Vetter | f37b5c2 | 2015-02-10 23:12:27 +0100 | [diff] [blame] | 8319 | plane_config->size = fb->pitches[0] * aligned_height; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8320 | |
Damien Lespiau | 2844a92 | 2015-01-20 12:51:48 +0000 | [diff] [blame] | 8321 | DRM_DEBUG_KMS("pipe %c with fb: size=%dx%d@%d, offset=%x, pitch %d, size 0x%x\n", |
| 8322 | pipe_name(pipe), fb->width, fb->height, |
| 8323 | fb->bits_per_pixel, base, fb->pitches[0], |
| 8324 | plane_config->size); |
Damien Lespiau | b113d5e | 2015-01-20 12:51:46 +0000 | [diff] [blame] | 8325 | |
Damien Lespiau | 2d14030 | 2015-02-05 17:22:18 +0000 | [diff] [blame] | 8326 | plane_config->fb = intel_fb; |
Jesse Barnes | 4c6baa5 | 2014-03-07 08:57:50 -0800 | [diff] [blame] | 8327 | } |
| 8328 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8329 | static bool ironlake_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8330 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8331 | { |
| 8332 | struct drm_device *dev = crtc->base.dev; |
| 8333 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8334 | uint32_t tmp; |
| 8335 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8336 | if (!intel_display_power_is_enabled(dev_priv, |
| 8337 | POWER_DOMAIN_PIPE(crtc->pipe))) |
Paulo Zanoni | 930e8c9 | 2014-07-04 13:38:34 -0300 | [diff] [blame] | 8338 | return false; |
| 8339 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8340 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8341 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8342 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8343 | tmp = I915_READ(PIPECONF(crtc->pipe)); |
| 8344 | if (!(tmp & PIPECONF_ENABLE)) |
| 8345 | return false; |
| 8346 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 8347 | switch (tmp & PIPECONF_BPC_MASK) { |
| 8348 | case PIPECONF_6BPC: |
| 8349 | pipe_config->pipe_bpp = 18; |
| 8350 | break; |
| 8351 | case PIPECONF_8BPC: |
| 8352 | pipe_config->pipe_bpp = 24; |
| 8353 | break; |
| 8354 | case PIPECONF_10BPC: |
| 8355 | pipe_config->pipe_bpp = 30; |
| 8356 | break; |
| 8357 | case PIPECONF_12BPC: |
| 8358 | pipe_config->pipe_bpp = 36; |
| 8359 | break; |
| 8360 | default: |
| 8361 | break; |
| 8362 | } |
| 8363 | |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 8364 | if (tmp & PIPECONF_COLOR_RANGE_SELECT) |
| 8365 | pipe_config->limited_color_range = true; |
| 8366 | |
Daniel Vetter | ab9412b | 2013-05-03 11:49:46 +0200 | [diff] [blame] | 8367 | if (I915_READ(PCH_TRANSCONF(crtc->pipe)) & TRANS_ENABLE) { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8368 | struct intel_shared_dpll *pll; |
| 8369 | |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8370 | pipe_config->has_pch_encoder = true; |
| 8371 | |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8372 | tmp = I915_READ(FDI_RX_CTL(crtc->pipe)); |
| 8373 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8374 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 8375 | |
| 8376 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8377 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8378 | if (HAS_PCH_IBX(dev_priv->dev)) { |
Daniel Vetter | d94ab06 | 2013-07-04 12:01:16 +0200 | [diff] [blame] | 8379 | pipe_config->shared_dpll = |
| 8380 | (enum intel_dpll_id) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8381 | } else { |
| 8382 | tmp = I915_READ(PCH_DPLL_SEL); |
| 8383 | if (tmp & TRANS_DPLLB_SEL(crtc->pipe)) |
| 8384 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_B; |
| 8385 | else |
| 8386 | pipe_config->shared_dpll = DPLL_ID_PCH_PLL_A; |
| 8387 | } |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 8388 | |
| 8389 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 8390 | |
| 8391 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 8392 | &pipe_config->dpll_hw_state)); |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 8393 | |
| 8394 | tmp = pipe_config->dpll_hw_state.dpll; |
| 8395 | pipe_config->pixel_multiplier = |
| 8396 | ((tmp & PLL_REF_SDVO_HDMI_MULTIPLIER_MASK) |
| 8397 | >> PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT) + 1; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 8398 | |
| 8399 | ironlake_pch_clock_get(crtc, pipe_config); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8400 | } else { |
| 8401 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8402 | } |
| 8403 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8404 | intel_get_pipe_timings(crtc, pipe_config); |
| 8405 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8406 | ironlake_get_pfit_config(crtc, pipe_config); |
| 8407 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8408 | return true; |
| 8409 | } |
| 8410 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8411 | static void assert_can_disable_lcpll(struct drm_i915_private *dev_priv) |
| 8412 | { |
| 8413 | struct drm_device *dev = dev_priv->dev; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8414 | struct intel_crtc *crtc; |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8415 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 8416 | for_each_intel_crtc(dev, crtc) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8417 | I915_STATE_WARN(crtc->active, "CRTC for pipe %c enabled\n", |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8418 | pipe_name(crtc->pipe)); |
| 8419 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8420 | I915_STATE_WARN(I915_READ(HSW_PWR_WELL_DRIVER), "Power well on\n"); |
| 8421 | I915_STATE_WARN(I915_READ(SPLL_CTL) & SPLL_PLL_ENABLE, "SPLL enabled\n"); |
| 8422 | I915_STATE_WARN(I915_READ(WRPLL_CTL1) & WRPLL_PLL_ENABLE, "WRPLL1 enabled\n"); |
| 8423 | I915_STATE_WARN(I915_READ(WRPLL_CTL2) & WRPLL_PLL_ENABLE, "WRPLL2 enabled\n"); |
| 8424 | I915_STATE_WARN(I915_READ(PCH_PP_STATUS) & PP_ON, "Panel power on\n"); |
| 8425 | I915_STATE_WARN(I915_READ(BLC_PWM_CPU_CTL2) & BLM_PWM_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8426 | "CPU PWM1 enabled\n"); |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 8427 | if (IS_HASWELL(dev)) |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8428 | I915_STATE_WARN(I915_READ(HSW_BLC_PWM2_CTL) & BLM_PWM_ENABLE, |
Paulo Zanoni | c5107b8 | 2014-07-04 11:50:30 -0300 | [diff] [blame] | 8429 | "CPU PWM2 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8430 | 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] | 8431 | "PCH PWM1 enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8432 | I915_STATE_WARN(I915_READ(UTIL_PIN_CTL) & UTIL_PIN_ENABLE, |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8433 | "Utility pin enabled\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8434 | 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] | 8435 | |
Paulo Zanoni | 9926ada | 2014-04-01 19:39:47 -0300 | [diff] [blame] | 8436 | /* |
| 8437 | * In theory we can still leave IRQs enabled, as long as only the HPD |
| 8438 | * interrupts remain enabled. We used to check for that, but since it's |
| 8439 | * gen-specific and since we only disable LCPLL after we fully disable |
| 8440 | * the interrupts, the check below should be enough. |
| 8441 | */ |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 8442 | I915_STATE_WARN(intel_irqs_enabled(dev_priv), "IRQs enabled\n"); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8443 | } |
| 8444 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8445 | static uint32_t hsw_read_dcomp(struct drm_i915_private *dev_priv) |
| 8446 | { |
| 8447 | struct drm_device *dev = dev_priv->dev; |
| 8448 | |
| 8449 | if (IS_HASWELL(dev)) |
| 8450 | return I915_READ(D_COMP_HSW); |
| 8451 | else |
| 8452 | return I915_READ(D_COMP_BDW); |
| 8453 | } |
| 8454 | |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8455 | static void hsw_write_dcomp(struct drm_i915_private *dev_priv, uint32_t val) |
| 8456 | { |
| 8457 | struct drm_device *dev = dev_priv->dev; |
| 8458 | |
| 8459 | if (IS_HASWELL(dev)) { |
| 8460 | mutex_lock(&dev_priv->rps.hw_lock); |
| 8461 | if (sandybridge_pcode_write(dev_priv, GEN6_PCODE_WRITE_D_COMP, |
| 8462 | val)) |
Paulo Zanoni | f475dad | 2014-07-04 11:59:57 -0300 | [diff] [blame] | 8463 | DRM_ERROR("Failed to write to D_COMP\n"); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8464 | mutex_unlock(&dev_priv->rps.hw_lock); |
| 8465 | } else { |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8466 | I915_WRITE(D_COMP_BDW, val); |
| 8467 | POSTING_READ(D_COMP_BDW); |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8468 | } |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8469 | } |
| 8470 | |
| 8471 | /* |
| 8472 | * This function implements pieces of two sequences from BSpec: |
| 8473 | * - Sequence for display software to disable LCPLL |
| 8474 | * - Sequence for display software to allow package C8+ |
| 8475 | * The steps implemented here are just the steps that actually touch the LCPLL |
| 8476 | * register. Callers should take care of disabling all the display engine |
| 8477 | * functions, doing the mode unset, fixing interrupts, etc. |
| 8478 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 8479 | static void hsw_disable_lcpll(struct drm_i915_private *dev_priv, |
| 8480 | bool switch_to_fclk, bool allow_power_down) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8481 | { |
| 8482 | uint32_t val; |
| 8483 | |
| 8484 | assert_can_disable_lcpll(dev_priv); |
| 8485 | |
| 8486 | val = I915_READ(LCPLL_CTL); |
| 8487 | |
| 8488 | if (switch_to_fclk) { |
| 8489 | val |= LCPLL_CD_SOURCE_FCLK; |
| 8490 | I915_WRITE(LCPLL_CTL, val); |
| 8491 | |
| 8492 | if (wait_for_atomic_us(I915_READ(LCPLL_CTL) & |
| 8493 | LCPLL_CD_SOURCE_FCLK_DONE, 1)) |
| 8494 | DRM_ERROR("Switching to FCLK failed\n"); |
| 8495 | |
| 8496 | val = I915_READ(LCPLL_CTL); |
| 8497 | } |
| 8498 | |
| 8499 | val |= LCPLL_PLL_DISABLE; |
| 8500 | I915_WRITE(LCPLL_CTL, val); |
| 8501 | POSTING_READ(LCPLL_CTL); |
| 8502 | |
| 8503 | if (wait_for((I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK) == 0, 1)) |
| 8504 | DRM_ERROR("LCPLL still locked\n"); |
| 8505 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8506 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8507 | val |= D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8508 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8509 | ndelay(100); |
| 8510 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8511 | if (wait_for((hsw_read_dcomp(dev_priv) & D_COMP_RCOMP_IN_PROGRESS) == 0, |
| 8512 | 1)) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8513 | DRM_ERROR("D_COMP RCOMP still in progress\n"); |
| 8514 | |
| 8515 | if (allow_power_down) { |
| 8516 | val = I915_READ(LCPLL_CTL); |
| 8517 | val |= LCPLL_POWER_DOWN_ALLOW; |
| 8518 | I915_WRITE(LCPLL_CTL, val); |
| 8519 | POSTING_READ(LCPLL_CTL); |
| 8520 | } |
| 8521 | } |
| 8522 | |
| 8523 | /* |
| 8524 | * Fully restores LCPLL, disallowing power down and switching back to LCPLL |
| 8525 | * source. |
| 8526 | */ |
Paulo Zanoni | 6ff58d5 | 2013-09-24 13:52:57 -0300 | [diff] [blame] | 8527 | static void hsw_restore_lcpll(struct drm_i915_private *dev_priv) |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8528 | { |
| 8529 | uint32_t val; |
| 8530 | |
| 8531 | val = I915_READ(LCPLL_CTL); |
| 8532 | |
| 8533 | if ((val & (LCPLL_PLL_LOCK | LCPLL_PLL_DISABLE | LCPLL_CD_SOURCE_FCLK | |
| 8534 | LCPLL_POWER_DOWN_ALLOW)) == LCPLL_PLL_LOCK) |
| 8535 | return; |
| 8536 | |
Paulo Zanoni | a8a8bd5 | 2014-03-07 20:08:05 -0300 | [diff] [blame] | 8537 | /* |
| 8538 | * Make sure we're not on PC8 state before disabling PC8, otherwise |
| 8539 | * 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] | 8540 | */ |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 8541 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 8542 | |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8543 | if (val & LCPLL_POWER_DOWN_ALLOW) { |
| 8544 | val &= ~LCPLL_POWER_DOWN_ALLOW; |
| 8545 | I915_WRITE(LCPLL_CTL, val); |
Daniel Vetter | 35d8f2e | 2013-08-21 23:38:08 +0200 | [diff] [blame] | 8546 | POSTING_READ(LCPLL_CTL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8547 | } |
| 8548 | |
Paulo Zanoni | 9ccd5ae | 2014-07-04 11:59:58 -0300 | [diff] [blame] | 8549 | val = hsw_read_dcomp(dev_priv); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8550 | val |= D_COMP_COMP_FORCE; |
| 8551 | val &= ~D_COMP_COMP_DISABLE; |
Paulo Zanoni | 3c4c9b8 | 2014-03-07 20:12:36 -0300 | [diff] [blame] | 8552 | hsw_write_dcomp(dev_priv, val); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8553 | |
| 8554 | val = I915_READ(LCPLL_CTL); |
| 8555 | val &= ~LCPLL_PLL_DISABLE; |
| 8556 | I915_WRITE(LCPLL_CTL, val); |
| 8557 | |
| 8558 | if (wait_for(I915_READ(LCPLL_CTL) & LCPLL_PLL_LOCK, 5)) |
| 8559 | DRM_ERROR("LCPLL not locked yet\n"); |
| 8560 | |
| 8561 | if (val & LCPLL_CD_SOURCE_FCLK) { |
| 8562 | val = I915_READ(LCPLL_CTL); |
| 8563 | val &= ~LCPLL_CD_SOURCE_FCLK; |
| 8564 | I915_WRITE(LCPLL_CTL, val); |
| 8565 | |
| 8566 | if (wait_for_atomic_us((I915_READ(LCPLL_CTL) & |
| 8567 | LCPLL_CD_SOURCE_FCLK_DONE) == 0, 1)) |
| 8568 | DRM_ERROR("Switching back to LCPLL failed\n"); |
| 8569 | } |
Paulo Zanoni | 215733f | 2013-08-19 13:18:07 -0300 | [diff] [blame] | 8570 | |
Mika Kuoppala | 59bad94 | 2015-01-16 11:34:40 +0200 | [diff] [blame] | 8571 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Paulo Zanoni | be256dc | 2013-07-23 11:19:26 -0300 | [diff] [blame] | 8572 | } |
| 8573 | |
Paulo Zanoni | 765dab67 | 2014-03-07 20:08:18 -0300 | [diff] [blame] | 8574 | /* |
| 8575 | * Package states C8 and deeper are really deep PC states that can only be |
| 8576 | * reached when all the devices on the system allow it, so even if the graphics |
| 8577 | * device allows PC8+, it doesn't mean the system will actually get to these |
| 8578 | * states. Our driver only allows PC8+ when going into runtime PM. |
| 8579 | * |
| 8580 | * The requirements for PC8+ are that all the outputs are disabled, the power |
| 8581 | * well is disabled and most interrupts are disabled, and these are also |
| 8582 | * requirements for runtime PM. When these conditions are met, we manually do |
| 8583 | * the other conditions: disable the interrupts, clocks and switch LCPLL refclk |
| 8584 | * to Fclk. If we're in PC8+ and we get an non-hotplug interrupt, we can hard |
| 8585 | * hang the machine. |
| 8586 | * |
| 8587 | * When we really reach PC8 or deeper states (not just when we allow it) we lose |
| 8588 | * the state of some registers, so when we come back from PC8+ we need to |
| 8589 | * restore this state. We don't get into PC8+ if we're not in RC6, so we don't |
| 8590 | * need to take care of the registers kept by RC6. Notice that this happens even |
| 8591 | * if we don't put the device in PCI D3 state (which is what currently happens |
| 8592 | * because of the runtime PM support). |
| 8593 | * |
| 8594 | * For more, read "Display Sequences for Package C8" on the hardware |
| 8595 | * documentation. |
| 8596 | */ |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 8597 | void hsw_enable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8598 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8599 | struct drm_device *dev = dev_priv->dev; |
| 8600 | uint32_t val; |
| 8601 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8602 | DRM_DEBUG_KMS("Enabling package C8+\n"); |
| 8603 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8604 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 8605 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 8606 | val &= ~PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8607 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8608 | } |
| 8609 | |
| 8610 | lpt_disable_clkout_dp(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8611 | hsw_disable_lcpll(dev_priv, true, true); |
| 8612 | } |
| 8613 | |
Paulo Zanoni | a14cb6f | 2014-03-07 20:08:17 -0300 | [diff] [blame] | 8614 | void hsw_disable_pc8(struct drm_i915_private *dev_priv) |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8615 | { |
| 8616 | struct drm_device *dev = dev_priv->dev; |
| 8617 | uint32_t val; |
| 8618 | |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8619 | DRM_DEBUG_KMS("Disabling package C8+\n"); |
| 8620 | |
| 8621 | hsw_restore_lcpll(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8622 | lpt_init_pch_refclk(dev); |
| 8623 | |
| 8624 | if (dev_priv->pch_id == INTEL_PCH_LPT_LP_DEVICE_ID_TYPE) { |
| 8625 | val = I915_READ(SOUTH_DSPCLK_GATE_D); |
| 8626 | val |= PCH_LP_PARTITION_LEVEL_DISABLE; |
| 8627 | I915_WRITE(SOUTH_DSPCLK_GATE_D, val); |
| 8628 | } |
| 8629 | |
| 8630 | intel_prepare_ddi(dev); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 8631 | } |
| 8632 | |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8633 | static int haswell_crtc_compute_clock(struct intel_crtc *crtc, |
| 8634 | struct intel_crtc_state *crtc_state) |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 8635 | { |
Ander Conselvan de Oliveira | 190f68c | 2015-01-15 14:55:23 +0200 | [diff] [blame] | 8636 | if (!intel_ddi_pll_select(crtc, crtc_state)) |
Paulo Zanoni | 6441ab5 | 2012-10-05 12:05:58 -0300 | [diff] [blame] | 8637 | return -EINVAL; |
Daniel Vetter | 716c2e5 | 2014-06-25 22:02:02 +0300 | [diff] [blame] | 8638 | |
Ander Conselvan de Oliveira | c765319 | 2014-10-20 13:46:44 +0300 | [diff] [blame] | 8639 | crtc->lowfreq_avail = false; |
Daniel Vetter | 644cef3 | 2014-04-24 23:55:07 +0200 | [diff] [blame] | 8640 | |
Daniel Vetter | c8f7a0d | 2014-04-24 23:55:04 +0200 | [diff] [blame] | 8641 | return 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 8642 | } |
| 8643 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8644 | static void skylake_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 8645 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8646 | struct intel_crtc_state *pipe_config) |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8647 | { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 8648 | u32 temp, dpll_ctl1; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8649 | |
| 8650 | temp = I915_READ(DPLL_CTRL2) & DPLL_CTRL2_DDI_CLK_SEL_MASK(port); |
| 8651 | pipe_config->ddi_pll_sel = temp >> (port * 3 + 1); |
| 8652 | |
| 8653 | switch (pipe_config->ddi_pll_sel) { |
Damien Lespiau | 3148ade | 2014-11-21 16:14:56 +0000 | [diff] [blame] | 8654 | case SKL_DPLL0: |
| 8655 | /* |
| 8656 | * On SKL the eDP DPLL (DPLL0 as we don't use SSC) is not part |
| 8657 | * of the shared DPLL framework and thus needs to be read out |
| 8658 | * separately |
| 8659 | */ |
| 8660 | dpll_ctl1 = I915_READ(DPLL_CTRL1); |
| 8661 | pipe_config->dpll_hw_state.ctrl1 = dpll_ctl1 & 0x3f; |
| 8662 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8663 | case SKL_DPLL1: |
| 8664 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL1; |
| 8665 | break; |
| 8666 | case SKL_DPLL2: |
| 8667 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL2; |
| 8668 | break; |
| 8669 | case SKL_DPLL3: |
| 8670 | pipe_config->shared_dpll = DPLL_ID_SKL_DPLL3; |
| 8671 | break; |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8672 | } |
| 8673 | } |
| 8674 | |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 8675 | static void haswell_get_ddi_pll(struct drm_i915_private *dev_priv, |
| 8676 | enum port port, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8677 | struct intel_crtc_state *pipe_config) |
Damien Lespiau | 7d2c817 | 2014-07-29 18:06:18 +0100 | [diff] [blame] | 8678 | { |
| 8679 | pipe_config->ddi_pll_sel = I915_READ(PORT_CLK_SEL(port)); |
| 8680 | |
| 8681 | switch (pipe_config->ddi_pll_sel) { |
| 8682 | case PORT_CLK_SEL_WRPLL1: |
| 8683 | pipe_config->shared_dpll = DPLL_ID_WRPLL1; |
| 8684 | break; |
| 8685 | case PORT_CLK_SEL_WRPLL2: |
| 8686 | pipe_config->shared_dpll = DPLL_ID_WRPLL2; |
| 8687 | break; |
| 8688 | } |
| 8689 | } |
| 8690 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8691 | 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] | 8692 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8693 | { |
| 8694 | struct drm_device *dev = crtc->base.dev; |
| 8695 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 8696 | struct intel_shared_dpll *pll; |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8697 | enum port port; |
| 8698 | uint32_t tmp; |
| 8699 | |
| 8700 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(pipe_config->cpu_transcoder)); |
| 8701 | |
| 8702 | port = (tmp & TRANS_DDI_PORT_MASK) >> TRANS_DDI_PORT_SHIFT; |
| 8703 | |
Satheeshakrishna M | 96b7dfb | 2014-11-13 14:55:17 +0000 | [diff] [blame] | 8704 | if (IS_SKYLAKE(dev)) |
| 8705 | skylake_get_ddi_pll(dev_priv, port, pipe_config); |
| 8706 | else |
| 8707 | haswell_get_ddi_pll(dev_priv, port, pipe_config); |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 8708 | |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 8709 | if (pipe_config->shared_dpll >= 0) { |
| 8710 | pll = &dev_priv->shared_dplls[pipe_config->shared_dpll]; |
| 8711 | |
| 8712 | WARN_ON(!pll->get_hw_state(dev_priv, pll, |
| 8713 | &pipe_config->dpll_hw_state)); |
| 8714 | } |
| 8715 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8716 | /* |
| 8717 | * Haswell has only FDI/PCH transcoder A. It is which is connected to |
| 8718 | * DDI E. So just check whether this pipe is wired to DDI E and whether |
| 8719 | * the PCH transcoder is on. |
| 8720 | */ |
Damien Lespiau | ca37045 | 2013-12-03 13:56:24 +0000 | [diff] [blame] | 8721 | if (INTEL_INFO(dev)->gen < 9 && |
| 8722 | (port == PORT_E) && I915_READ(LPT_TRANSCONF) & TRANS_ENABLE) { |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8723 | pipe_config->has_pch_encoder = true; |
| 8724 | |
| 8725 | tmp = I915_READ(FDI_RX_CTL(PIPE_A)); |
| 8726 | pipe_config->fdi_lanes = ((FDI_DP_PORT_WIDTH_MASK & tmp) >> |
| 8727 | FDI_DP_PORT_WIDTH_SHIFT) + 1; |
| 8728 | |
| 8729 | ironlake_get_fdi_m_n_config(crtc, pipe_config); |
| 8730 | } |
| 8731 | } |
| 8732 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8733 | static bool haswell_get_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 8734 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8735 | { |
| 8736 | struct drm_device *dev = crtc->base.dev; |
| 8737 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8738 | enum intel_display_power_domain pfit_domain; |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8739 | uint32_t tmp; |
| 8740 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8741 | if (!intel_display_power_is_enabled(dev_priv, |
Imre Deak | b5482bd | 2014-03-05 16:20:55 +0200 | [diff] [blame] | 8742 | POWER_DOMAIN_PIPE(crtc->pipe))) |
| 8743 | return false; |
| 8744 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 8745 | pipe_config->cpu_transcoder = (enum transcoder) crtc->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 8746 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
| 8747 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8748 | tmp = I915_READ(TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)); |
| 8749 | if (tmp & TRANS_DDI_FUNC_ENABLE) { |
| 8750 | enum pipe trans_edp_pipe; |
| 8751 | switch (tmp & TRANS_DDI_EDP_INPUT_MASK) { |
| 8752 | default: |
| 8753 | WARN(1, "unknown pipe linked to edp transcoder\n"); |
| 8754 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 8755 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 8756 | trans_edp_pipe = PIPE_A; |
| 8757 | break; |
| 8758 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 8759 | trans_edp_pipe = PIPE_B; |
| 8760 | break; |
| 8761 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 8762 | trans_edp_pipe = PIPE_C; |
| 8763 | break; |
| 8764 | } |
| 8765 | |
| 8766 | if (trans_edp_pipe == crtc->pipe) |
| 8767 | pipe_config->cpu_transcoder = TRANSCODER_EDP; |
| 8768 | } |
| 8769 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 8770 | if (!intel_display_power_is_enabled(dev_priv, |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8771 | POWER_DOMAIN_TRANSCODER(pipe_config->cpu_transcoder))) |
Paulo Zanoni | 2bfce95 | 2013-04-18 16:35:40 -0300 | [diff] [blame] | 8772 | return false; |
| 8773 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 8774 | tmp = I915_READ(PIPECONF(pipe_config->cpu_transcoder)); |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8775 | if (!(tmp & PIPECONF_ENABLE)) |
| 8776 | return false; |
| 8777 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 8778 | haswell_get_ddi_port_state(crtc, pipe_config); |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 8779 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 8780 | intel_get_pipe_timings(crtc, pipe_config); |
| 8781 | |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 8782 | pfit_domain = POWER_DOMAIN_PIPE_PANEL_FITTER(crtc->pipe); |
Jesse Barnes | bd2e244 | 2014-11-13 17:51:47 +0000 | [diff] [blame] | 8783 | if (intel_display_power_is_enabled(dev_priv, pfit_domain)) { |
| 8784 | if (IS_SKYLAKE(dev)) |
| 8785 | skylake_get_pfit_config(crtc, pipe_config); |
| 8786 | else |
| 8787 | ironlake_get_pfit_config(crtc, pipe_config); |
| 8788 | } |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 8789 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 8790 | if (IS_HASWELL(dev)) |
| 8791 | pipe_config->ips_enabled = hsw_crtc_supports_ips(crtc) && |
| 8792 | (I915_READ(IPS_CTL) & IPS_ENABLE); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 8793 | |
Clint Taylor | ebb69c9 | 2014-09-30 10:30:22 -0700 | [diff] [blame] | 8794 | if (pipe_config->cpu_transcoder != TRANSCODER_EDP) { |
| 8795 | pipe_config->pixel_multiplier = |
| 8796 | I915_READ(PIPE_MULT(pipe_config->cpu_transcoder)) + 1; |
| 8797 | } else { |
| 8798 | pipe_config->pixel_multiplier = 1; |
| 8799 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 8800 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 8801 | return true; |
| 8802 | } |
| 8803 | |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8804 | static void i845_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8805 | { |
| 8806 | struct drm_device *dev = crtc->dev; |
| 8807 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8808 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8809 | uint32_t cntl = 0, size = 0; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8810 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8811 | if (base) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8812 | unsigned int width = intel_crtc->base.cursor->state->crtc_w; |
| 8813 | unsigned int height = intel_crtc->base.cursor->state->crtc_h; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8814 | unsigned int stride = roundup_pow_of_two(width) * 4; |
| 8815 | |
| 8816 | switch (stride) { |
| 8817 | default: |
| 8818 | WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n", |
| 8819 | width, stride); |
| 8820 | stride = 256; |
| 8821 | /* fallthrough */ |
| 8822 | case 256: |
| 8823 | case 512: |
| 8824 | case 1024: |
| 8825 | case 2048: |
| 8826 | break; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8827 | } |
| 8828 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8829 | cntl |= CURSOR_ENABLE | |
| 8830 | CURSOR_GAMMA_ENABLE | |
| 8831 | CURSOR_FORMAT_ARGB | |
| 8832 | CURSOR_STRIDE(stride); |
| 8833 | |
| 8834 | size = (height << 12) | width; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8835 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8836 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8837 | if (intel_crtc->cursor_cntl != 0 && |
| 8838 | (intel_crtc->cursor_base != base || |
| 8839 | intel_crtc->cursor_size != size || |
| 8840 | intel_crtc->cursor_cntl != cntl)) { |
| 8841 | /* On these chipsets we can only modify the base/size/stride |
| 8842 | * whilst the cursor is disabled. |
| 8843 | */ |
| 8844 | I915_WRITE(_CURACNTR, 0); |
| 8845 | POSTING_READ(_CURACNTR); |
| 8846 | intel_crtc->cursor_cntl = 0; |
| 8847 | } |
| 8848 | |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8849 | if (intel_crtc->cursor_base != base) { |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8850 | I915_WRITE(_CURABASE, base); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8851 | intel_crtc->cursor_base = base; |
| 8852 | } |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8853 | |
| 8854 | if (intel_crtc->cursor_size != size) { |
| 8855 | I915_WRITE(CURSIZE, size); |
| 8856 | intel_crtc->cursor_size = size; |
| 8857 | } |
| 8858 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8859 | if (intel_crtc->cursor_cntl != cntl) { |
| 8860 | I915_WRITE(_CURACNTR, cntl); |
| 8861 | POSTING_READ(_CURACNTR); |
| 8862 | intel_crtc->cursor_cntl = cntl; |
| 8863 | } |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8864 | } |
| 8865 | |
| 8866 | static void i9xx_update_cursor(struct drm_crtc *crtc, u32 base) |
| 8867 | { |
| 8868 | struct drm_device *dev = crtc->dev; |
| 8869 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8870 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8871 | int pipe = intel_crtc->pipe; |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8872 | uint32_t cntl; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8873 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8874 | cntl = 0; |
| 8875 | if (base) { |
| 8876 | cntl = MCURSOR_GAMMA_ENABLE; |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8877 | switch (intel_crtc->base.cursor->state->crtc_w) { |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8878 | case 64: |
| 8879 | cntl |= CURSOR_MODE_64_ARGB_AX; |
| 8880 | break; |
| 8881 | case 128: |
| 8882 | cntl |= CURSOR_MODE_128_ARGB_AX; |
| 8883 | break; |
| 8884 | case 256: |
| 8885 | cntl |= CURSOR_MODE_256_ARGB_AX; |
| 8886 | break; |
| 8887 | default: |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8888 | MISSING_CASE(intel_crtc->base.cursor->state->crtc_w); |
Sagar Kamble | 4726e0b | 2014-03-10 17:06:23 +0530 | [diff] [blame] | 8889 | return; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8890 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8891 | cntl |= pipe << 28; /* Connect to correct pipe */ |
Ville Syrjälä | 47bf17a | 2014-09-12 20:53:33 +0300 | [diff] [blame] | 8892 | |
| 8893 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
| 8894 | cntl |= CURSOR_PIPE_CSC_ENABLE; |
Chris Wilson | 560b85b | 2010-08-07 11:01:38 +0100 | [diff] [blame] | 8895 | } |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8896 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 8897 | if (crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 8898 | cntl |= CURSOR_ROTATE_180; |
| 8899 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8900 | if (intel_crtc->cursor_cntl != cntl) { |
| 8901 | I915_WRITE(CURCNTR(pipe), cntl); |
| 8902 | POSTING_READ(CURCNTR(pipe)); |
| 8903 | intel_crtc->cursor_cntl = cntl; |
| 8904 | } |
| 8905 | |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8906 | /* and commit changes on next vblank */ |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8907 | I915_WRITE(CURBASE(pipe), base); |
| 8908 | POSTING_READ(CURBASE(pipe)); |
Ville Syrjälä | 99d1f38 | 2014-09-12 20:53:32 +0300 | [diff] [blame] | 8909 | |
| 8910 | intel_crtc->cursor_base = base; |
Jesse Barnes | 65a21cd | 2011-10-12 11:10:21 -0700 | [diff] [blame] | 8911 | } |
| 8912 | |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8913 | /* 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] | 8914 | static void intel_crtc_update_cursor(struct drm_crtc *crtc, |
| 8915 | bool on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8916 | { |
| 8917 | struct drm_device *dev = crtc->dev; |
| 8918 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 8919 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 8920 | int pipe = intel_crtc->pipe; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 8921 | int x = crtc->cursor_x; |
| 8922 | int y = crtc->cursor_y; |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8923 | u32 base = 0, pos = 0; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8924 | |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8925 | if (on) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8926 | base = intel_crtc->cursor_addr; |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8927 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8928 | if (x >= intel_crtc->config->pipe_src_w) |
Ville Syrjälä | d6e4db1 | 2013-09-04 18:25:31 +0300 | [diff] [blame] | 8929 | base = 0; |
| 8930 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 8931 | if (y >= intel_crtc->config->pipe_src_h) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8932 | base = 0; |
| 8933 | |
| 8934 | if (x < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8935 | if (x + intel_crtc->base.cursor->state->crtc_w <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8936 | base = 0; |
| 8937 | |
| 8938 | pos |= CURSOR_POS_SIGN << CURSOR_X_SHIFT; |
| 8939 | x = -x; |
| 8940 | } |
| 8941 | pos |= x << CURSOR_X_SHIFT; |
| 8942 | |
| 8943 | if (y < 0) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8944 | if (y + intel_crtc->base.cursor->state->crtc_h <= 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8945 | base = 0; |
| 8946 | |
| 8947 | pos |= CURSOR_POS_SIGN << CURSOR_Y_SHIFT; |
| 8948 | y = -y; |
| 8949 | } |
| 8950 | pos |= y << CURSOR_Y_SHIFT; |
| 8951 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 8952 | if (base == 0 && intel_crtc->cursor_base == 0) |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8953 | return; |
| 8954 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8955 | I915_WRITE(CURPOS(pipe), pos); |
| 8956 | |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 8957 | /* ILK+ do this automagically */ |
| 8958 | if (HAS_GMCH_DISPLAY(dev) && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 8959 | crtc->cursor->state->rotation == BIT(DRM_ROTATE_180)) { |
Matt Roper | 3dd512f | 2015-02-27 10:12:00 -0800 | [diff] [blame] | 8960 | base += (intel_crtc->base.cursor->state->crtc_h * |
| 8961 | intel_crtc->base.cursor->state->crtc_w - 1) * 4; |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 8962 | } |
| 8963 | |
Ville Syrjälä | 8ac5466 | 2014-08-12 19:39:54 +0300 | [diff] [blame] | 8964 | if (IS_845G(dev) || IS_I865G(dev)) |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 8965 | i845_update_cursor(crtc, base); |
| 8966 | else |
| 8967 | i9xx_update_cursor(crtc, base); |
Chris Wilson | cda4b7d | 2010-07-09 08:45:04 +0100 | [diff] [blame] | 8968 | } |
| 8969 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 8970 | static bool cursor_size_ok(struct drm_device *dev, |
| 8971 | uint32_t width, uint32_t height) |
| 8972 | { |
| 8973 | if (width == 0 || height == 0) |
| 8974 | return false; |
| 8975 | |
| 8976 | /* |
| 8977 | * 845g/865g are special in that they are only limited by |
| 8978 | * the width of their cursors, the height is arbitrary up to |
| 8979 | * the precision of the register. Everything else requires |
| 8980 | * square cursors, limited to a few power-of-two sizes. |
| 8981 | */ |
| 8982 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 8983 | if ((width & 63) != 0) |
| 8984 | return false; |
| 8985 | |
| 8986 | if (width > (IS_845G(dev) ? 64 : 512)) |
| 8987 | return false; |
| 8988 | |
| 8989 | if (height > 1023) |
| 8990 | return false; |
| 8991 | } else { |
| 8992 | switch (width | height) { |
| 8993 | case 256: |
| 8994 | case 128: |
| 8995 | if (IS_GEN2(dev)) |
| 8996 | return false; |
| 8997 | case 64: |
| 8998 | break; |
| 8999 | default: |
| 9000 | return false; |
| 9001 | } |
| 9002 | } |
| 9003 | |
| 9004 | return true; |
| 9005 | } |
| 9006 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9007 | 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] | 9008 | u16 *blue, uint32_t start, uint32_t size) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9009 | { |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 9010 | int end = (start + size > 256) ? 256 : start + size, i; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9011 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9012 | |
James Simmons | 7203425 | 2010-08-03 01:33:19 +0100 | [diff] [blame] | 9013 | for (i = start; i < end; i++) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9014 | intel_crtc->lut_r[i] = red[i] >> 8; |
| 9015 | intel_crtc->lut_g[i] = green[i] >> 8; |
| 9016 | intel_crtc->lut_b[i] = blue[i] >> 8; |
| 9017 | } |
| 9018 | |
| 9019 | intel_crtc_load_lut(crtc); |
| 9020 | } |
| 9021 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9022 | /* VESA 640x480x72Hz mode to set on the pipe */ |
| 9023 | static struct drm_display_mode load_detect_mode = { |
| 9024 | DRM_MODE("640x480", DRM_MODE_TYPE_DEFAULT, 31500, 640, 664, |
| 9025 | 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), |
| 9026 | }; |
| 9027 | |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 9028 | struct drm_framebuffer * |
| 9029 | __intel_framebuffer_create(struct drm_device *dev, |
| 9030 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 9031 | struct drm_i915_gem_object *obj) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9032 | { |
| 9033 | struct intel_framebuffer *intel_fb; |
| 9034 | int ret; |
| 9035 | |
| 9036 | intel_fb = kzalloc(sizeof(*intel_fb), GFP_KERNEL); |
| 9037 | if (!intel_fb) { |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 9038 | drm_gem_object_unreference(&obj->base); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9039 | return ERR_PTR(-ENOMEM); |
| 9040 | } |
| 9041 | |
| 9042 | ret = intel_framebuffer_init(dev, intel_fb, mode_cmd, obj); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 9043 | if (ret) |
| 9044 | goto err; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9045 | |
| 9046 | return &intel_fb->base; |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 9047 | err: |
Alexey Khoroshilov | 6ccb81f | 2014-11-08 01:41:23 +0300 | [diff] [blame] | 9048 | drm_gem_object_unreference(&obj->base); |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 9049 | kfree(intel_fb); |
| 9050 | |
| 9051 | return ERR_PTR(ret); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9052 | } |
| 9053 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 9054 | static struct drm_framebuffer * |
Daniel Vetter | a8bb681 | 2014-02-10 18:00:39 +0100 | [diff] [blame] | 9055 | intel_framebuffer_create(struct drm_device *dev, |
| 9056 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 9057 | struct drm_i915_gem_object *obj) |
| 9058 | { |
| 9059 | struct drm_framebuffer *fb; |
| 9060 | int ret; |
| 9061 | |
| 9062 | ret = i915_mutex_lock_interruptible(dev); |
| 9063 | if (ret) |
| 9064 | return ERR_PTR(ret); |
| 9065 | fb = __intel_framebuffer_create(dev, mode_cmd, obj); |
| 9066 | mutex_unlock(&dev->struct_mutex); |
| 9067 | |
| 9068 | return fb; |
| 9069 | } |
| 9070 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9071 | static u32 |
| 9072 | intel_framebuffer_pitch_for_width(int width, int bpp) |
| 9073 | { |
| 9074 | u32 pitch = DIV_ROUND_UP(width * bpp, 8); |
| 9075 | return ALIGN(pitch, 64); |
| 9076 | } |
| 9077 | |
| 9078 | static u32 |
| 9079 | intel_framebuffer_size_for_mode(struct drm_display_mode *mode, int bpp) |
| 9080 | { |
| 9081 | u32 pitch = intel_framebuffer_pitch_for_width(mode->hdisplay, bpp); |
Fabian Frederick | 1267a26 | 2014-07-01 20:39:41 +0200 | [diff] [blame] | 9082 | return PAGE_ALIGN(pitch * mode->vdisplay); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9083 | } |
| 9084 | |
| 9085 | static struct drm_framebuffer * |
| 9086 | intel_framebuffer_create_for_mode(struct drm_device *dev, |
| 9087 | struct drm_display_mode *mode, |
| 9088 | int depth, int bpp) |
| 9089 | { |
| 9090 | struct drm_i915_gem_object *obj; |
Chris Wilson | 0fed39b | 2012-11-05 22:25:07 +0000 | [diff] [blame] | 9091 | struct drm_mode_fb_cmd2 mode_cmd = { 0 }; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9092 | |
| 9093 | obj = i915_gem_alloc_object(dev, |
| 9094 | intel_framebuffer_size_for_mode(mode, bpp)); |
| 9095 | if (obj == NULL) |
| 9096 | return ERR_PTR(-ENOMEM); |
| 9097 | |
| 9098 | mode_cmd.width = mode->hdisplay; |
| 9099 | mode_cmd.height = mode->vdisplay; |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 9100 | mode_cmd.pitches[0] = intel_framebuffer_pitch_for_width(mode_cmd.width, |
| 9101 | bpp); |
Dave Airlie | 5ca0c34 | 2012-02-23 15:33:40 +0000 | [diff] [blame] | 9102 | mode_cmd.pixel_format = drm_mode_legacy_fb_format(bpp, depth); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9103 | |
| 9104 | return intel_framebuffer_create(dev, &mode_cmd, obj); |
| 9105 | } |
| 9106 | |
| 9107 | static struct drm_framebuffer * |
| 9108 | mode_fits_in_fbdev(struct drm_device *dev, |
| 9109 | struct drm_display_mode *mode) |
| 9110 | { |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 9111 | #ifdef CONFIG_DRM_I915_FBDEV |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9112 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9113 | struct drm_i915_gem_object *obj; |
| 9114 | struct drm_framebuffer *fb; |
| 9115 | |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 9116 | if (!dev_priv->fbdev) |
| 9117 | return NULL; |
| 9118 | |
| 9119 | if (!dev_priv->fbdev->fb) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9120 | return NULL; |
| 9121 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 9122 | obj = dev_priv->fbdev->fb->obj; |
Daniel Vetter | 4c0e552 | 2014-02-14 16:35:54 +0100 | [diff] [blame] | 9123 | BUG_ON(!obj); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9124 | |
Jesse Barnes | 8bcd455 | 2014-02-07 12:10:38 -0800 | [diff] [blame] | 9125 | fb = &dev_priv->fbdev->fb->base; |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 9126 | if (fb->pitches[0] < intel_framebuffer_pitch_for_width(mode->hdisplay, |
| 9127 | fb->bits_per_pixel)) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9128 | return NULL; |
| 9129 | |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 9130 | if (obj->base.size < mode->vdisplay * fb->pitches[0]) |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9131 | return NULL; |
| 9132 | |
| 9133 | return fb; |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 9134 | #else |
| 9135 | return NULL; |
| 9136 | #endif |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9137 | } |
| 9138 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9139 | bool intel_get_load_detect_pipe(struct drm_connector *connector, |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9140 | struct drm_display_mode *mode, |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9141 | struct intel_load_detect_pipe *old, |
| 9142 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9143 | { |
| 9144 | struct intel_crtc *intel_crtc; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9145 | struct intel_encoder *intel_encoder = |
| 9146 | intel_attached_encoder(connector); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9147 | struct drm_crtc *possible_crtc; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 9148 | struct drm_encoder *encoder = &intel_encoder->base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9149 | struct drm_crtc *crtc = NULL; |
| 9150 | struct drm_device *dev = encoder->dev; |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9151 | struct drm_framebuffer *fb; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9152 | struct drm_mode_config *config = &dev->mode_config; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9153 | struct drm_atomic_state *state = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9154 | struct drm_connector_state *connector_state; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9155 | int ret, i = -1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9156 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9157 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 9158 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 9159 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9160 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9161 | retry: |
| 9162 | ret = drm_modeset_lock(&config->connection_mutex, ctx); |
| 9163 | if (ret) |
| 9164 | goto fail_unlock; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 9165 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9166 | /* |
| 9167 | * Algorithm gets a little messy: |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 9168 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9169 | * - if the connector already has an assigned crtc, use it (but make |
| 9170 | * sure it's on first) |
Chris Wilson | 7a5e480 | 2011-04-19 23:21:12 +0100 | [diff] [blame] | 9171 | * |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9172 | * - try to find the first unused crtc that can drive this connector, |
| 9173 | * and use that if we find one |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9174 | */ |
| 9175 | |
| 9176 | /* See if we already have a CRTC for this connector */ |
| 9177 | if (encoder->crtc) { |
| 9178 | crtc = encoder->crtc; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9179 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9180 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 9181 | if (ret) |
| 9182 | goto fail_unlock; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 9183 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 9184 | if (ret) |
| 9185 | goto fail_unlock; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 9186 | |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9187 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9188 | old->load_detect_temp = false; |
| 9189 | |
| 9190 | /* Make sure the crtc and connector are running */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9191 | if (connector->dpms != DRM_MODE_DPMS_ON) |
| 9192 | connector->funcs->dpms(connector, DRM_MODE_DPMS_ON); |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9193 | |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9194 | return true; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9195 | } |
| 9196 | |
| 9197 | /* Find an unused one (if possible) */ |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 9198 | for_each_crtc(dev, possible_crtc) { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9199 | i++; |
| 9200 | if (!(encoder->possible_crtcs & (1 << i))) |
| 9201 | continue; |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 9202 | if (possible_crtc->state->enable) |
Ville Syrjälä | a459249 | 2014-08-11 13:15:36 +0300 | [diff] [blame] | 9203 | continue; |
| 9204 | /* This can occur when applying the pipe A quirk on resume. */ |
| 9205 | if (to_intel_crtc(possible_crtc)->new_enabled) |
| 9206 | continue; |
| 9207 | |
| 9208 | crtc = possible_crtc; |
| 9209 | break; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9210 | } |
| 9211 | |
| 9212 | /* |
| 9213 | * If we didn't find an unused CRTC, don't use any. |
| 9214 | */ |
| 9215 | if (!crtc) { |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9216 | DRM_DEBUG_KMS("no pipe available for load-detect\n"); |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9217 | goto fail_unlock; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9218 | } |
| 9219 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9220 | ret = drm_modeset_lock(&crtc->mutex, ctx); |
| 9221 | if (ret) |
| 9222 | goto fail_unlock; |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 9223 | ret = drm_modeset_lock(&crtc->primary->mutex, ctx); |
| 9224 | if (ret) |
| 9225 | goto fail_unlock; |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 9226 | intel_encoder->new_crtc = to_intel_crtc(crtc); |
| 9227 | to_intel_connector(connector)->new_encoder = intel_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9228 | |
| 9229 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9230 | intel_crtc->new_enabled = true; |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9231 | old->dpms_mode = connector->dpms; |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9232 | old->load_detect_temp = true; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9233 | old->release_fb = NULL; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9234 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9235 | state = drm_atomic_state_alloc(dev); |
| 9236 | if (!state) |
| 9237 | return false; |
| 9238 | |
| 9239 | state->acquire_ctx = ctx; |
| 9240 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9241 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 9242 | if (IS_ERR(connector_state)) { |
| 9243 | ret = PTR_ERR(connector_state); |
| 9244 | goto fail; |
| 9245 | } |
| 9246 | |
| 9247 | connector_state->crtc = crtc; |
| 9248 | connector_state->best_encoder = &intel_encoder->base; |
| 9249 | |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 9250 | if (!mode) |
| 9251 | mode = &load_detect_mode; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9252 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9253 | /* We need a framebuffer large enough to accommodate all accesses |
| 9254 | * that the plane may generate whilst we perform load detection. |
| 9255 | * We can not rely on the fbcon either being present (we get called |
| 9256 | * during its initialisation to detect all boot displays, or it may |
| 9257 | * not even exist) or that it is large enough to satisfy the |
| 9258 | * requested mode. |
| 9259 | */ |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9260 | fb = mode_fits_in_fbdev(dev, mode); |
| 9261 | if (fb == NULL) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9262 | DRM_DEBUG_KMS("creating tmp fb for load-detection\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9263 | fb = intel_framebuffer_create_for_mode(dev, mode, 24, 32); |
| 9264 | old->release_fb = fb; |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9265 | } else |
| 9266 | DRM_DEBUG_KMS("reusing fbdev for load-detection framebuffer\n"); |
Daniel Vetter | 94352cf | 2012-07-05 22:51:56 +0200 | [diff] [blame] | 9267 | if (IS_ERR(fb)) { |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9268 | DRM_DEBUG_KMS("failed to allocate framebuffer for load-detection\n"); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9269 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9270 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9271 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9272 | if (intel_set_mode(crtc, mode, 0, 0, fb, state)) { |
Chris Wilson | 6492711 | 2011-04-20 07:25:26 +0100 | [diff] [blame] | 9273 | DRM_DEBUG_KMS("failed to set mode on load-detect pipe\n"); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9274 | if (old->release_fb) |
| 9275 | old->release_fb->funcs->destroy(old->release_fb); |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9276 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9277 | } |
Daniel Vetter | 9128b04 | 2015-03-03 17:31:21 +0100 | [diff] [blame] | 9278 | crtc->primary->crtc = crtc; |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9279 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9280 | /* let the connector get through one full cycle before testing */ |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 9281 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
Chris Wilson | 7173188 | 2011-04-19 23:10:58 +0100 | [diff] [blame] | 9282 | return true; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9283 | |
| 9284 | fail: |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 9285 | intel_crtc->new_enabled = crtc->state->enable; |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9286 | fail_unlock: |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9287 | if (state) { |
| 9288 | drm_atomic_state_free(state); |
| 9289 | state = NULL; |
| 9290 | } |
| 9291 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 9292 | if (ret == -EDEADLK) { |
| 9293 | drm_modeset_backoff(ctx); |
| 9294 | goto retry; |
| 9295 | } |
| 9296 | |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9297 | return false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9298 | } |
| 9299 | |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9300 | void intel_release_load_detect_pipe(struct drm_connector *connector, |
Ander Conselvan de Oliveira | 49172fe | 2015-03-20 16:18:02 +0200 | [diff] [blame] | 9301 | struct intel_load_detect_pipe *old, |
| 9302 | struct drm_modeset_acquire_ctx *ctx) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9303 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9304 | struct drm_device *dev = connector->dev; |
Daniel Vetter | d2434ab | 2012-08-12 21:20:10 +0200 | [diff] [blame] | 9305 | struct intel_encoder *intel_encoder = |
| 9306 | intel_attached_encoder(connector); |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 9307 | struct drm_encoder *encoder = &intel_encoder->base; |
Daniel Vetter | 7b24056 | 2012-12-12 00:35:33 +0100 | [diff] [blame] | 9308 | struct drm_crtc *crtc = encoder->crtc; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9309 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9310 | struct drm_atomic_state *state; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9311 | struct drm_connector_state *connector_state; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9312 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9313 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s], [ENCODER:%d:%s]\n", |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 9314 | connector->base.id, connector->name, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 9315 | encoder->base.id, encoder->name); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9316 | |
Chris Wilson | 8261b19 | 2011-04-19 23:18:09 +0100 | [diff] [blame] | 9317 | if (old->load_detect_temp) { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9318 | state = drm_atomic_state_alloc(dev); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9319 | if (!state) |
| 9320 | goto fail; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9321 | |
| 9322 | state->acquire_ctx = ctx; |
| 9323 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9324 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 9325 | if (IS_ERR(connector_state)) |
| 9326 | goto fail; |
| 9327 | |
Daniel Vetter | fc30310 | 2012-07-09 10:40:58 +0200 | [diff] [blame] | 9328 | to_intel_connector(connector)->new_encoder = NULL; |
| 9329 | intel_encoder->new_crtc = NULL; |
Ville Syrjälä | 412b61d | 2014-01-17 15:59:39 +0200 | [diff] [blame] | 9330 | intel_crtc->new_enabled = false; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9331 | |
| 9332 | connector_state->best_encoder = NULL; |
| 9333 | connector_state->crtc = NULL; |
| 9334 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 9335 | intel_set_mode(crtc, NULL, 0, 0, NULL, state); |
| 9336 | |
| 9337 | drm_atomic_state_free(state); |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9338 | |
Daniel Vetter | 3620636 | 2012-12-10 20:42:17 +0100 | [diff] [blame] | 9339 | if (old->release_fb) { |
| 9340 | drm_framebuffer_unregister_private(old->release_fb); |
| 9341 | drm_framebuffer_unreference(old->release_fb); |
| 9342 | } |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 9343 | |
Chris Wilson | 0622a53 | 2011-04-21 09:32:11 +0100 | [diff] [blame] | 9344 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9345 | } |
| 9346 | |
Eric Anholt | c751ce4 | 2010-03-25 11:48:48 -0700 | [diff] [blame] | 9347 | /* Switch crtc and encoder back off if necessary */ |
Daniel Vetter | 24218aa | 2012-08-12 19:27:11 +0200 | [diff] [blame] | 9348 | if (old->dpms_mode != DRM_MODE_DPMS_ON) |
| 9349 | connector->funcs->dpms(connector, old->dpms_mode); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 9350 | |
| 9351 | return; |
| 9352 | fail: |
| 9353 | DRM_DEBUG_KMS("Couldn't release load detect pipe.\n"); |
| 9354 | drm_atomic_state_free(state); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9355 | } |
| 9356 | |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9357 | static int i9xx_pll_refclk(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9358 | const struct intel_crtc_state *pipe_config) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9359 | { |
| 9360 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9361 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
| 9362 | |
| 9363 | if ((dpll & PLL_REF_INPUT_MASK) == PLLB_REF_INPUT_SPREADSPECTRUMIN) |
Ville Syrjälä | e91e941 | 2013-12-09 18:54:16 +0200 | [diff] [blame] | 9364 | return dev_priv->vbt.lvds_ssc_freq; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9365 | else if (HAS_PCH_SPLIT(dev)) |
| 9366 | return 120000; |
| 9367 | else if (!IS_GEN2(dev)) |
| 9368 | return 96000; |
| 9369 | else |
| 9370 | return 48000; |
| 9371 | } |
| 9372 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9373 | /* Returns the clock of the currently programmed mode of the given pipe. */ |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9374 | static void i9xx_crtc_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9375 | struct intel_crtc_state *pipe_config) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9376 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9377 | struct drm_device *dev = crtc->base.dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9378 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9379 | int pipe = pipe_config->cpu_transcoder; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9380 | u32 dpll = pipe_config->dpll_hw_state.dpll; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9381 | u32 fp; |
| 9382 | intel_clock_t clock; |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9383 | int refclk = i9xx_pll_refclk(dev, pipe_config); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9384 | |
| 9385 | if ((dpll & DISPLAY_RATE_SELECT_FPA1) == 0) |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9386 | fp = pipe_config->dpll_hw_state.fp0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9387 | else |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9388 | fp = pipe_config->dpll_hw_state.fp1; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9389 | |
| 9390 | clock.m1 = (fp & FP_M1_DIV_MASK) >> FP_M1_DIV_SHIFT; |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 9391 | if (IS_PINEVIEW(dev)) { |
| 9392 | clock.n = ffs((fp & FP_N_PINEVIEW_DIV_MASK) >> FP_N_DIV_SHIFT) - 1; |
| 9393 | clock.m2 = (fp & FP_M2_PINEVIEW_DIV_MASK) >> FP_M2_DIV_SHIFT; |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 9394 | } else { |
| 9395 | clock.n = (fp & FP_N_DIV_MASK) >> FP_N_DIV_SHIFT; |
| 9396 | clock.m2 = (fp & FP_M2_DIV_MASK) >> FP_M2_DIV_SHIFT; |
| 9397 | } |
| 9398 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 9399 | if (!IS_GEN2(dev)) { |
Adam Jackson | f2b115e | 2009-12-03 17:14:42 -0500 | [diff] [blame] | 9400 | if (IS_PINEVIEW(dev)) |
| 9401 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_PINEVIEW) >> |
| 9402 | DPLL_FPA01_P1_POST_DIV_SHIFT_PINEVIEW); |
Shaohua Li | 2177832 | 2009-02-23 15:19:16 +0800 | [diff] [blame] | 9403 | else |
| 9404 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK) >> |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9405 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
| 9406 | |
| 9407 | switch (dpll & DPLL_MODE_MASK) { |
| 9408 | case DPLLB_MODE_DAC_SERIAL: |
| 9409 | clock.p2 = dpll & DPLL_DAC_SERIAL_P2_CLOCK_DIV_5 ? |
| 9410 | 5 : 10; |
| 9411 | break; |
| 9412 | case DPLLB_MODE_LVDS: |
| 9413 | clock.p2 = dpll & DPLLB_LVDS_P2_CLOCK_DIV_7 ? |
| 9414 | 7 : 14; |
| 9415 | break; |
| 9416 | default: |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 9417 | DRM_DEBUG_KMS("Unknown DPLL mode %08x in programmed " |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9418 | "mode\n", (int)(dpll & DPLL_MODE_MASK)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9419 | return; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9420 | } |
| 9421 | |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 9422 | if (IS_PINEVIEW(dev)) |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9423 | pineview_clock(refclk, &clock); |
Daniel Vetter | ac58c3f | 2013-06-01 17:16:17 +0200 | [diff] [blame] | 9424 | else |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9425 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9426 | } else { |
Ville Syrjälä | 0fb5822 | 2014-01-10 14:06:46 +0200 | [diff] [blame] | 9427 | u32 lvds = IS_I830(dev) ? 0 : I915_READ(LVDS); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 9428 | bool is_lvds = (pipe == 1) && (lvds & LVDS_PORT_EN); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9429 | |
| 9430 | if (is_lvds) { |
| 9431 | clock.p1 = ffs((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830_LVDS) >> |
| 9432 | DPLL_FPA01_P1_POST_DIV_SHIFT); |
Ville Syrjälä | b1c560d | 2013-12-09 18:54:13 +0200 | [diff] [blame] | 9433 | |
| 9434 | if (lvds & LVDS_CLKB_POWER_UP) |
| 9435 | clock.p2 = 7; |
| 9436 | else |
| 9437 | clock.p2 = 14; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9438 | } else { |
| 9439 | if (dpll & PLL_P1_DIVIDE_BY_TWO) |
| 9440 | clock.p1 = 2; |
| 9441 | else { |
| 9442 | clock.p1 = ((dpll & DPLL_FPA01_P1_POST_DIV_MASK_I830) >> |
| 9443 | DPLL_FPA01_P1_POST_DIV_SHIFT) + 2; |
| 9444 | } |
| 9445 | if (dpll & PLL_P2_DIVIDE_BY_4) |
| 9446 | clock.p2 = 4; |
| 9447 | else |
| 9448 | clock.p2 = 2; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9449 | } |
Ville Syrjälä | da4a1ef | 2013-09-09 14:06:37 +0300 | [diff] [blame] | 9450 | |
| 9451 | i9xx_clock(refclk, &clock); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9452 | } |
| 9453 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9454 | /* |
| 9455 | * This value includes pixel_multiplier. We will use |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 9456 | * port_clock to compute adjusted_mode.crtc_clock in the |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9457 | * encoder's get_config() function. |
| 9458 | */ |
| 9459 | pipe_config->port_clock = clock.dot; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9460 | } |
| 9461 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9462 | int intel_dotclock_calculate(int link_freq, |
| 9463 | const struct intel_link_m_n *m_n) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9464 | { |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9465 | /* |
| 9466 | * The calculation for the data clock is: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 9467 | * pixel_clock = ((m/n)*(link_clock * nr_lanes))/bpp |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9468 | * But we want to avoid losing precison if possible, so: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 9469 | * pixel_clock = ((m * link_clock * nr_lanes)/(n*bpp)) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9470 | * |
| 9471 | * and the link clock is simpler: |
Ville Syrjälä | 1041a02 | 2013-09-06 23:28:58 +0300 | [diff] [blame] | 9472 | * link_clock = (m * link_clock) / n |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9473 | */ |
| 9474 | |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9475 | if (!m_n->link_n) |
| 9476 | return 0; |
| 9477 | |
| 9478 | return div_u64((u64)m_n->link_m * link_freq, m_n->link_n); |
| 9479 | } |
| 9480 | |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9481 | static void ironlake_pch_clock_get(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9482 | struct intel_crtc_state *pipe_config) |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9483 | { |
| 9484 | struct drm_device *dev = crtc->base.dev; |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9485 | |
| 9486 | /* read out port_clock from the DPLL */ |
| 9487 | i9xx_crtc_clock_get(crtc, pipe_config); |
Ville Syrjälä | 6878da0 | 2013-09-13 15:59:11 +0300 | [diff] [blame] | 9488 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9489 | /* |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9490 | * This value does not include pixel_multiplier. |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 9491 | * We will check that port_clock and adjusted_mode.crtc_clock |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9492 | * agree once we know their relationship in the encoder's |
| 9493 | * get_config() function. |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9494 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 9495 | pipe_config->base.adjusted_mode.crtc_clock = |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 9496 | intel_dotclock_calculate(intel_fdi_link_freq(dev) * 10000, |
| 9497 | &pipe_config->fdi_m_n); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9498 | } |
| 9499 | |
| 9500 | /** Returns the currently programmed mode of the given pipe. */ |
| 9501 | struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, |
| 9502 | struct drm_crtc *crtc) |
| 9503 | { |
Jesse Barnes | 548f245 | 2011-02-17 10:40:53 -0800 | [diff] [blame] | 9504 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9505 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 9506 | enum transcoder cpu_transcoder = intel_crtc->config->cpu_transcoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9507 | struct drm_display_mode *mode; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 9508 | struct intel_crtc_state pipe_config; |
Paulo Zanoni | fe2b8f9 | 2012-10-23 18:30:02 -0200 | [diff] [blame] | 9509 | int htot = I915_READ(HTOTAL(cpu_transcoder)); |
| 9510 | int hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 9511 | int vtot = I915_READ(VTOTAL(cpu_transcoder)); |
| 9512 | int vsync = I915_READ(VSYNC(cpu_transcoder)); |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9513 | enum pipe pipe = intel_crtc->pipe; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9514 | |
| 9515 | mode = kzalloc(sizeof(*mode), GFP_KERNEL); |
| 9516 | if (!mode) |
| 9517 | return NULL; |
| 9518 | |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9519 | /* |
| 9520 | * Construct a pipe_config sufficient for getting the clock info |
| 9521 | * back out of crtc_clock_get. |
| 9522 | * |
| 9523 | * Note, if LVDS ever uses a non-1 pixel multiplier, we'll need |
| 9524 | * to use a real value here instead. |
| 9525 | */ |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9526 | pipe_config.cpu_transcoder = (enum transcoder) pipe; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9527 | pipe_config.pixel_multiplier = 1; |
Ville Syrjälä | 293623f | 2013-09-13 16:18:46 +0300 | [diff] [blame] | 9528 | pipe_config.dpll_hw_state.dpll = I915_READ(DPLL(pipe)); |
| 9529 | pipe_config.dpll_hw_state.fp0 = I915_READ(FP0(pipe)); |
| 9530 | pipe_config.dpll_hw_state.fp1 = I915_READ(FP1(pipe)); |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 9531 | i9xx_crtc_clock_get(intel_crtc, &pipe_config); |
| 9532 | |
Ville Syrjälä | 773ae03 | 2013-09-23 17:48:20 +0300 | [diff] [blame] | 9533 | mode->clock = pipe_config.port_clock / pipe_config.pixel_multiplier; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9534 | mode->hdisplay = (htot & 0xffff) + 1; |
| 9535 | mode->htotal = ((htot & 0xffff0000) >> 16) + 1; |
| 9536 | mode->hsync_start = (hsync & 0xffff) + 1; |
| 9537 | mode->hsync_end = ((hsync & 0xffff0000) >> 16) + 1; |
| 9538 | mode->vdisplay = (vtot & 0xffff) + 1; |
| 9539 | mode->vtotal = ((vtot & 0xffff0000) >> 16) + 1; |
| 9540 | mode->vsync_start = (vsync & 0xffff) + 1; |
| 9541 | mode->vsync_end = ((vsync & 0xffff0000) >> 16) + 1; |
| 9542 | |
| 9543 | drm_mode_set_name(mode); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9544 | |
| 9545 | return mode; |
| 9546 | } |
| 9547 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9548 | static void intel_decrease_pllclock(struct drm_crtc *crtc) |
| 9549 | { |
| 9550 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9551 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9552 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9553 | |
Sonika Jindal | baff296 | 2014-07-22 11:16:35 +0530 | [diff] [blame] | 9554 | if (!HAS_GMCH_DISPLAY(dev)) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9555 | return; |
| 9556 | |
| 9557 | if (!dev_priv->lvds_downclock_avail) |
| 9558 | return; |
| 9559 | |
| 9560 | /* |
| 9561 | * Since this is called by a timer, we should never get here in |
| 9562 | * the manual case. |
| 9563 | */ |
| 9564 | if (!HAS_PIPE_CXSR(dev) && intel_crtc->lowfreq_avail) { |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9565 | int pipe = intel_crtc->pipe; |
| 9566 | int dpll_reg = DPLL(pipe); |
Daniel Vetter | dc257cf | 2012-05-07 11:30:46 +0200 | [diff] [blame] | 9567 | int dpll; |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9568 | |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9569 | DRM_DEBUG_DRIVER("downclocking LVDS\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9570 | |
Sean Paul | 8ac5a6d | 2012-02-13 13:14:51 -0500 | [diff] [blame] | 9571 | assert_panel_unlocked(dev_priv, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9572 | |
Chris Wilson | 074b5e1 | 2012-05-02 12:07:06 +0100 | [diff] [blame] | 9573 | dpll = I915_READ(dpll_reg); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9574 | dpll |= DISPLAY_RATE_SELECT_FPA1; |
| 9575 | I915_WRITE(dpll_reg, dpll); |
Jesse Barnes | 9d0498a | 2010-08-18 13:20:54 -0700 | [diff] [blame] | 9576 | intel_wait_for_vblank(dev, pipe); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9577 | dpll = I915_READ(dpll_reg); |
| 9578 | if (!(dpll & DISPLAY_RATE_SELECT_FPA1)) |
Zhao Yakui | 44d98a6 | 2009-10-09 11:39:40 +0800 | [diff] [blame] | 9579 | DRM_DEBUG_DRIVER("failed to downclock LVDS!\n"); |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9580 | } |
| 9581 | |
| 9582 | } |
| 9583 | |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9584 | void intel_mark_busy(struct drm_device *dev) |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 9585 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9586 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9587 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9588 | if (dev_priv->mm.busy) |
| 9589 | return; |
| 9590 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 9591 | intel_runtime_pm_get(dev_priv); |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9592 | i915_update_gfx_val(dev_priv); |
Chris Wilson | 43cf3bf | 2015-03-18 09:48:22 +0000 | [diff] [blame] | 9593 | if (INTEL_INFO(dev)->gen >= 6) |
| 9594 | gen6_rps_busy(dev_priv); |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9595 | dev_priv->mm.busy = true; |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9596 | } |
| 9597 | |
| 9598 | void intel_mark_idle(struct drm_device *dev) |
| 9599 | { |
Paulo Zanoni | c67a470 | 2013-08-19 13:18:09 -0300 | [diff] [blame] | 9600 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9601 | struct drm_crtc *crtc; |
| 9602 | |
Chris Wilson | f62a007 | 2014-02-21 17:55:39 +0000 | [diff] [blame] | 9603 | if (!dev_priv->mm.busy) |
| 9604 | return; |
| 9605 | |
| 9606 | dev_priv->mm.busy = false; |
| 9607 | |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 9608 | for_each_crtc(dev, crtc) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 9609 | if (!crtc->primary->fb) |
Chris Wilson | 725a5b5 | 2013-01-08 11:02:57 +0000 | [diff] [blame] | 9610 | continue; |
| 9611 | |
| 9612 | intel_decrease_pllclock(crtc); |
| 9613 | } |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9614 | |
Damien Lespiau | 3d13ef2 | 2014-02-07 19:12:47 +0000 | [diff] [blame] | 9615 | if (INTEL_INFO(dev)->gen >= 6) |
Chris Wilson | b29c19b | 2013-09-25 17:34:56 +0100 | [diff] [blame] | 9616 | gen6_rps_idle(dev->dev_private); |
Paulo Zanoni | bb4cdd5 | 2014-02-21 13:52:19 -0300 | [diff] [blame] | 9617 | |
Paulo Zanoni | 43694d6 | 2014-03-07 20:08:08 -0300 | [diff] [blame] | 9618 | intel_runtime_pm_put(dev_priv); |
Chris Wilson | f047e39 | 2012-07-21 12:31:41 +0100 | [diff] [blame] | 9619 | } |
| 9620 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 9621 | static void intel_crtc_set_state(struct intel_crtc *crtc, |
| 9622 | struct intel_crtc_state *crtc_state) |
| 9623 | { |
| 9624 | kfree(crtc->config); |
| 9625 | crtc->config = crtc_state; |
Ander Conselvan de Oliveira | 16f3f65 | 2015-01-15 14:55:27 +0200 | [diff] [blame] | 9626 | crtc->base.state = &crtc_state->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 9627 | } |
| 9628 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9629 | static void intel_crtc_destroy(struct drm_crtc *crtc) |
| 9630 | { |
| 9631 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9632 | struct drm_device *dev = crtc->dev; |
| 9633 | struct intel_unpin_work *work; |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9634 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 9635 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9636 | work = intel_crtc->unpin_work; |
| 9637 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 9638 | spin_unlock_irq(&dev->event_lock); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9639 | |
| 9640 | if (work) { |
| 9641 | cancel_work_sync(&work->work); |
| 9642 | kfree(work); |
| 9643 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9644 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 9645 | intel_crtc_set_state(intel_crtc, NULL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9646 | drm_crtc_cleanup(crtc); |
Daniel Vetter | 67e77c5 | 2010-08-20 22:26:30 +0200 | [diff] [blame] | 9647 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 9648 | kfree(intel_crtc); |
| 9649 | } |
| 9650 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9651 | static void intel_unpin_work_fn(struct work_struct *__work) |
| 9652 | { |
| 9653 | struct intel_unpin_work *work = |
| 9654 | container_of(__work, struct intel_unpin_work, work); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9655 | struct drm_device *dev = work->crtc->dev; |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9656 | enum pipe pipe = to_intel_crtc(work->crtc)->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9657 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9658 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 9659 | intel_unpin_fb_obj(work->old_fb, work->crtc->primary->state); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 9660 | drm_gem_object_unreference(&work->pending_flip_obj->base); |
Chris Wilson | d9e86c0 | 2010-11-10 16:40:20 +0000 | [diff] [blame] | 9661 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 9662 | intel_fbc_update(dev); |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 9663 | |
| 9664 | if (work->flip_queued_req) |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 9665 | i915_gem_request_assign(&work->flip_queued_req, NULL); |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9666 | mutex_unlock(&dev->struct_mutex); |
| 9667 | |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9668 | intel_frontbuffer_flip_complete(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 9669 | drm_framebuffer_unreference(work->old_fb); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 9670 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 9671 | BUG_ON(atomic_read(&to_intel_crtc(work->crtc)->unpin_work_count) == 0); |
| 9672 | atomic_dec(&to_intel_crtc(work->crtc)->unpin_work_count); |
| 9673 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9674 | kfree(work); |
| 9675 | } |
| 9676 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9677 | static void do_intel_finish_page_flip(struct drm_device *dev, |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9678 | struct drm_crtc *crtc) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9679 | { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9680 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9681 | struct intel_unpin_work *work; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9682 | unsigned long flags; |
| 9683 | |
| 9684 | /* Ignore early vblank irqs */ |
| 9685 | if (intel_crtc == NULL) |
| 9686 | return; |
| 9687 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 9688 | /* |
| 9689 | * This is called both by irq handlers and the reset code (to complete |
| 9690 | * lost pageflips) so needs the full irqsave spinlocks. |
| 9691 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9692 | spin_lock_irqsave(&dev->event_lock, flags); |
| 9693 | work = intel_crtc->unpin_work; |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9694 | |
| 9695 | /* Ensure we don't miss a work->pending update ... */ |
| 9696 | smp_rmb(); |
| 9697 | |
| 9698 | if (work == NULL || atomic_read(&work->pending) < INTEL_FLIP_COMPLETE) { |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9699 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9700 | return; |
| 9701 | } |
| 9702 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 9703 | page_flip_completed(intel_crtc); |
Mario Kleiner | 0af7e4d | 2010-12-08 04:07:19 +0100 | [diff] [blame] | 9704 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9705 | spin_unlock_irqrestore(&dev->event_lock, flags); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9706 | } |
| 9707 | |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9708 | void intel_finish_page_flip(struct drm_device *dev, int pipe) |
| 9709 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9710 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9711 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 9712 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9713 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9714 | } |
| 9715 | |
| 9716 | void intel_finish_page_flip_plane(struct drm_device *dev, int plane) |
| 9717 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9718 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9719 | struct drm_crtc *crtc = dev_priv->plane_to_crtc_mapping[plane]; |
| 9720 | |
Mario Kleiner | 49b14a5 | 2010-12-09 07:00:07 +0100 | [diff] [blame] | 9721 | do_intel_finish_page_flip(dev, crtc); |
Jesse Barnes | 1afe3e9 | 2010-03-26 10:35:20 -0700 | [diff] [blame] | 9722 | } |
| 9723 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9724 | /* Is 'a' after or equal to 'b'? */ |
| 9725 | static bool g4x_flip_count_after_eq(u32 a, u32 b) |
| 9726 | { |
| 9727 | return !((a - b) & 0x80000000); |
| 9728 | } |
| 9729 | |
| 9730 | static bool page_flip_finished(struct intel_crtc *crtc) |
| 9731 | { |
| 9732 | struct drm_device *dev = crtc->base.dev; |
| 9733 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9734 | |
Ville Syrjälä | bdfa754 | 2014-05-27 21:33:09 +0300 | [diff] [blame] | 9735 | if (i915_reset_in_progress(&dev_priv->gpu_error) || |
| 9736 | crtc->reset_counter != atomic_read(&dev_priv->gpu_error.reset_counter)) |
| 9737 | return true; |
| 9738 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9739 | /* |
| 9740 | * The relevant registers doen't exist on pre-ctg. |
| 9741 | * As the flip done interrupt doesn't trigger for mmio |
| 9742 | * flips on gmch platforms, a flip count check isn't |
| 9743 | * really needed there. But since ctg has the registers, |
| 9744 | * include it in the check anyway. |
| 9745 | */ |
| 9746 | if (INTEL_INFO(dev)->gen < 5 && !IS_G4X(dev)) |
| 9747 | return true; |
| 9748 | |
| 9749 | /* |
| 9750 | * A DSPSURFLIVE check isn't enough in case the mmio and CS flips |
| 9751 | * used the same base address. In that case the mmio flip might |
| 9752 | * have completed, but the CS hasn't even executed the flip yet. |
| 9753 | * |
| 9754 | * A flip count check isn't enough as the CS might have updated |
| 9755 | * the base address just after start of vblank, but before we |
| 9756 | * managed to process the interrupt. This means we'd complete the |
| 9757 | * CS flip too soon. |
| 9758 | * |
| 9759 | * Combining both checks should get us a good enough result. It may |
| 9760 | * still happen that the CS flip has been executed, but has not |
| 9761 | * yet actually completed. But in case the base address is the same |
| 9762 | * anyway, we don't really care. |
| 9763 | */ |
| 9764 | return (I915_READ(DSPSURFLIVE(crtc->plane)) & ~0xfff) == |
| 9765 | crtc->unpin_work->gtt_offset && |
| 9766 | g4x_flip_count_after_eq(I915_READ(PIPE_FLIPCOUNT_GM45(crtc->pipe)), |
| 9767 | crtc->unpin_work->flip_count); |
| 9768 | } |
| 9769 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9770 | void intel_prepare_page_flip(struct drm_device *dev, int plane) |
| 9771 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 9772 | struct drm_i915_private *dev_priv = dev->dev_private; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9773 | struct intel_crtc *intel_crtc = |
| 9774 | to_intel_crtc(dev_priv->plane_to_crtc_mapping[plane]); |
| 9775 | unsigned long flags; |
| 9776 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 9777 | |
| 9778 | /* |
| 9779 | * This is called both by irq handlers and the reset code (to complete |
| 9780 | * lost pageflips) so needs the full irqsave spinlocks. |
| 9781 | * |
| 9782 | * NB: An MMIO update of the plane base pointer will also |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9783 | * generate a page-flip completion irq, i.e. every modeset |
| 9784 | * is also accompanied by a spurious intel_prepare_page_flip(). |
| 9785 | */ |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9786 | spin_lock_irqsave(&dev->event_lock, flags); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9787 | if (intel_crtc->unpin_work && page_flip_finished(intel_crtc)) |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9788 | atomic_inc_not_zero(&intel_crtc->unpin_work->pending); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 9789 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 9790 | } |
| 9791 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9792 | 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] | 9793 | { |
| 9794 | /* Ensure that the work item is consistent when activating it ... */ |
| 9795 | smp_wmb(); |
| 9796 | atomic_set(&intel_crtc->unpin_work->pending, INTEL_FLIP_PENDING); |
| 9797 | /* and that it is marked active as soon as the irq could fire. */ |
| 9798 | smp_wmb(); |
| 9799 | } |
| 9800 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9801 | static int intel_gen2_queue_flip(struct drm_device *dev, |
| 9802 | struct drm_crtc *crtc, |
| 9803 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9804 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9805 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9806 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9807 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9808 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9809 | u32 flip_mask; |
| 9810 | int ret; |
| 9811 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9812 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9813 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9814 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9815 | |
| 9816 | /* Can't queue multiple flips, so wait for the previous |
| 9817 | * one to finish before executing the next. |
| 9818 | */ |
| 9819 | if (intel_crtc->plane) |
| 9820 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9821 | else |
| 9822 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9823 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9824 | intel_ring_emit(ring, MI_NOOP); |
| 9825 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9826 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9827 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9828 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9829 | intel_ring_emit(ring, 0); /* aux display base address, unused */ |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9830 | |
| 9831 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9832 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9833 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9834 | } |
| 9835 | |
| 9836 | static int intel_gen3_queue_flip(struct drm_device *dev, |
| 9837 | struct drm_crtc *crtc, |
| 9838 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9839 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9840 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9841 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9842 | { |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9843 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9844 | u32 flip_mask; |
| 9845 | int ret; |
| 9846 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9847 | ret = intel_ring_begin(ring, 6); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9848 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9849 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9850 | |
| 9851 | if (intel_crtc->plane) |
| 9852 | flip_mask = MI_WAIT_FOR_PLANE_B_FLIP; |
| 9853 | else |
| 9854 | flip_mask = MI_WAIT_FOR_PLANE_A_FLIP; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9855 | intel_ring_emit(ring, MI_WAIT_FOR_EVENT | flip_mask); |
| 9856 | intel_ring_emit(ring, MI_NOOP); |
| 9857 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | |
| 9858 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9859 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9860 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9861 | intel_ring_emit(ring, MI_NOOP); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9862 | |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9863 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9864 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9865 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9866 | } |
| 9867 | |
| 9868 | static int intel_gen4_queue_flip(struct drm_device *dev, |
| 9869 | struct drm_crtc *crtc, |
| 9870 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9871 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9872 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9873 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9874 | { |
| 9875 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9876 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9877 | uint32_t pf, pipesrc; |
| 9878 | int ret; |
| 9879 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9880 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9881 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9882 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9883 | |
| 9884 | /* i965+ uses the linear or tiled offsets from the |
| 9885 | * Display Registers (which do not change across a page-flip) |
| 9886 | * so we need only reprogram the base address. |
| 9887 | */ |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9888 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9889 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9890 | intel_ring_emit(ring, fb->pitches[0]); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9891 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset | |
Daniel Vetter | c2c7513 | 2012-07-05 12:17:30 +0200 | [diff] [blame] | 9892 | obj->tiling_mode); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9893 | |
| 9894 | /* XXX Enabling the panel-fitter across page-flip is so far |
| 9895 | * untested on non-native modes, so ignore it for now. |
| 9896 | * pf = I915_READ(pipe == 0 ? PFA_CTL_1 : PFB_CTL_1) & PF_ENABLE; |
| 9897 | */ |
| 9898 | pf = 0; |
| 9899 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9900 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9901 | |
| 9902 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9903 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9904 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9905 | } |
| 9906 | |
| 9907 | static int intel_gen6_queue_flip(struct drm_device *dev, |
| 9908 | struct drm_crtc *crtc, |
| 9909 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9910 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9911 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9912 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9913 | { |
| 9914 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 9915 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 9916 | uint32_t pf, pipesrc; |
| 9917 | int ret; |
| 9918 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9919 | ret = intel_ring_begin(ring, 4); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9920 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9921 | return ret; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9922 | |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9923 | intel_ring_emit(ring, MI_DISPLAY_FLIP | |
| 9924 | MI_DISPLAY_FLIP_PLANE(intel_crtc->plane)); |
| 9925 | intel_ring_emit(ring, fb->pitches[0] | obj->tiling_mode); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 9926 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9927 | |
Chris Wilson | 99d9acd | 2012-04-17 20:37:00 +0100 | [diff] [blame] | 9928 | /* Contrary to the suggestions in the documentation, |
| 9929 | * "Enable Panel Fitter" does not seem to be required when page |
| 9930 | * flipping with a non-native mode, and worse causes a normal |
| 9931 | * modeset to fail. |
| 9932 | * pf = I915_READ(PF_CTL(intel_crtc->pipe)) & PF_ENABLE; |
| 9933 | */ |
| 9934 | pf = 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9935 | pipesrc = I915_READ(PIPESRC(intel_crtc->pipe)) & 0x0fff0fff; |
Daniel Vetter | 6d90c95 | 2012-04-26 23:28:05 +0200 | [diff] [blame] | 9936 | intel_ring_emit(ring, pf | pipesrc); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 9937 | |
| 9938 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 9939 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 9940 | return 0; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 9941 | } |
| 9942 | |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9943 | static int intel_gen7_queue_flip(struct drm_device *dev, |
| 9944 | struct drm_crtc *crtc, |
| 9945 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9946 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 9947 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 9948 | uint32_t flags) |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9949 | { |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9950 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9951 | uint32_t plane_bit = 0; |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9952 | int len, ret; |
| 9953 | |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 9954 | switch (intel_crtc->plane) { |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9955 | case PLANE_A: |
| 9956 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_A; |
| 9957 | break; |
| 9958 | case PLANE_B: |
| 9959 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_B; |
| 9960 | break; |
| 9961 | case PLANE_C: |
| 9962 | plane_bit = MI_DISPLAY_FLIP_IVB_PLANE_C; |
| 9963 | break; |
| 9964 | default: |
| 9965 | WARN_ONCE(1, "unknown plane in flip command\n"); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9966 | return -ENODEV; |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 9967 | } |
| 9968 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9969 | len = 4; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9970 | if (ring->id == RCS) { |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9971 | len += 6; |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 9972 | /* |
| 9973 | * On Gen 8, SRM is now taking an extra dword to accommodate |
| 9974 | * 48bits addresses, and we need a NOOP for the batch size to |
| 9975 | * stay even. |
| 9976 | */ |
| 9977 | if (IS_GEN8(dev)) |
| 9978 | len += 2; |
| 9979 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9980 | |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9981 | /* |
| 9982 | * BSpec MI_DISPLAY_FLIP for IVB: |
| 9983 | * "The full packet must be contained within the same cache line." |
| 9984 | * |
| 9985 | * Currently the LRI+SRM+MI_DISPLAY_FLIP all fit within the same |
| 9986 | * cacheline, if we ever start emitting more commands before |
| 9987 | * the MI_DISPLAY_FLIP we may need to first emit everything else, |
| 9988 | * then do the cacheline alignment, and finally emit the |
| 9989 | * MI_DISPLAY_FLIP. |
| 9990 | */ |
| 9991 | ret = intel_ring_cacheline_align(ring); |
| 9992 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9993 | return ret; |
Ville Syrjälä | f66fab8 | 2014-02-11 19:52:06 +0200 | [diff] [blame] | 9994 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9995 | ret = intel_ring_begin(ring, len); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9996 | if (ret) |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 9997 | return ret; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 9998 | |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 9999 | /* Unmask the flip-done completion message. Note that the bspec says that |
| 10000 | * we should do this for both the BCS and RCS, and that we must not unmask |
| 10001 | * more than one flip event at any time (or ensure that one flip message |
| 10002 | * can be sent by waiting for flip-done prior to queueing new flips). |
| 10003 | * Experimentation says that BCS works despite DERRMR masking all |
| 10004 | * flip-done completion events and that unmasking all planes at once |
| 10005 | * for the RCS also doesn't appear to drop events. Setting the DERRMR |
| 10006 | * to zero does lead to lockups within MI_DISPLAY_FLIP. |
| 10007 | */ |
| 10008 | if (ring->id == RCS) { |
| 10009 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
| 10010 | intel_ring_emit(ring, DERRMR); |
| 10011 | intel_ring_emit(ring, ~(DERRMR_PIPEA_PRI_FLIP_DONE | |
| 10012 | DERRMR_PIPEB_PRI_FLIP_DONE | |
| 10013 | DERRMR_PIPEC_PRI_FLIP_DONE)); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10014 | if (IS_GEN8(dev)) |
| 10015 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM_GEN8(1) | |
| 10016 | MI_SRM_LRM_GLOBAL_GTT); |
| 10017 | else |
| 10018 | intel_ring_emit(ring, MI_STORE_REGISTER_MEM(1) | |
| 10019 | MI_SRM_LRM_GLOBAL_GTT); |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10020 | intel_ring_emit(ring, DERRMR); |
| 10021 | intel_ring_emit(ring, ring->scratch.gtt_offset + 256); |
Damien Lespiau | f476828 | 2014-04-07 20:24:34 +0100 | [diff] [blame] | 10022 | if (IS_GEN8(dev)) { |
| 10023 | intel_ring_emit(ring, 0); |
| 10024 | intel_ring_emit(ring, MI_NOOP); |
| 10025 | } |
Chris Wilson | ffe74d7 | 2013-08-26 20:58:12 +0100 | [diff] [blame] | 10026 | } |
| 10027 | |
Daniel Vetter | cb05d8d | 2012-05-23 14:02:00 +0200 | [diff] [blame] | 10028 | intel_ring_emit(ring, MI_DISPLAY_FLIP_I915 | plane_bit); |
Ville Syrjälä | 01f2c77 | 2011-12-20 00:06:49 +0200 | [diff] [blame] | 10029 | intel_ring_emit(ring, (fb->pitches[0] | obj->tiling_mode)); |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10030 | intel_ring_emit(ring, intel_crtc->unpin_work->gtt_offset); |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10031 | intel_ring_emit(ring, (MI_NOOP)); |
Chris Wilson | e7d841c | 2012-12-03 11:36:30 +0000 | [diff] [blame] | 10032 | |
| 10033 | intel_mark_page_flip_active(intel_crtc); |
Chris Wilson | 0924673 | 2013-08-10 22:16:32 +0100 | [diff] [blame] | 10034 | __intel_ring_advance(ring); |
Chris Wilson | 83d4092 | 2012-04-17 19:35:53 +0100 | [diff] [blame] | 10035 | return 0; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 10036 | } |
| 10037 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10038 | static bool use_mmio_flip(struct intel_engine_cs *ring, |
| 10039 | struct drm_i915_gem_object *obj) |
| 10040 | { |
| 10041 | /* |
| 10042 | * This is not being used for older platforms, because |
| 10043 | * non-availability of flip done interrupt forces us to use |
| 10044 | * CS flips. Older platforms derive flip done using some clever |
| 10045 | * tricks involving the flip_pending status bits and vblank irqs. |
| 10046 | * So using MMIO flips there would disrupt this mechanism. |
| 10047 | */ |
| 10048 | |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 10049 | if (ring == NULL) |
| 10050 | return true; |
| 10051 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10052 | if (INTEL_INFO(ring->dev)->gen < 5) |
| 10053 | return false; |
| 10054 | |
| 10055 | if (i915.use_mmio_flip < 0) |
| 10056 | return false; |
| 10057 | else if (i915.use_mmio_flip > 0) |
| 10058 | return true; |
Oscar Mateo | 14bf993 | 2014-07-24 17:04:34 +0100 | [diff] [blame] | 10059 | else if (i915.enable_execlists) |
| 10060 | return true; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10061 | else |
John Harrison | 41c5241 | 2014-11-24 18:49:43 +0000 | [diff] [blame] | 10062 | return ring != i915_gem_request_get_ring(obj->last_read_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10063 | } |
| 10064 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 10065 | static void skl_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 10066 | { |
| 10067 | struct drm_device *dev = intel_crtc->base.dev; |
| 10068 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10069 | struct drm_framebuffer *fb = intel_crtc->base.primary->fb; |
| 10070 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
| 10071 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 10072 | const enum pipe pipe = intel_crtc->pipe; |
| 10073 | u32 ctl, stride; |
| 10074 | |
| 10075 | ctl = I915_READ(PLANE_CTL(pipe, 0)); |
| 10076 | ctl &= ~PLANE_CTL_TILED_MASK; |
| 10077 | if (obj->tiling_mode == I915_TILING_X) |
| 10078 | ctl |= PLANE_CTL_TILED_X; |
| 10079 | |
| 10080 | /* |
| 10081 | * The stride is either expressed as a multiple of 64 bytes chunks for |
| 10082 | * linear buffers or in number of tiles for tiled buffers. |
| 10083 | */ |
| 10084 | stride = fb->pitches[0] >> 6; |
| 10085 | if (obj->tiling_mode == I915_TILING_X) |
| 10086 | stride = fb->pitches[0] >> 9; /* X tiles are 512 bytes wide */ |
| 10087 | |
| 10088 | /* |
| 10089 | * Both PLANE_CTL and PLANE_STRIDE are not updated on vblank but on |
| 10090 | * PLANE_SURF updates, the update is then guaranteed to be atomic. |
| 10091 | */ |
| 10092 | I915_WRITE(PLANE_CTL(pipe, 0), ctl); |
| 10093 | I915_WRITE(PLANE_STRIDE(pipe, 0), stride); |
| 10094 | |
| 10095 | I915_WRITE(PLANE_SURF(pipe, 0), intel_crtc->unpin_work->gtt_offset); |
| 10096 | POSTING_READ(PLANE_SURF(pipe, 0)); |
| 10097 | } |
| 10098 | |
| 10099 | static void ilk_do_mmio_flip(struct intel_crtc *intel_crtc) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10100 | { |
| 10101 | struct drm_device *dev = intel_crtc->base.dev; |
| 10102 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10103 | struct intel_framebuffer *intel_fb = |
| 10104 | to_intel_framebuffer(intel_crtc->base.primary->fb); |
| 10105 | struct drm_i915_gem_object *obj = intel_fb->obj; |
| 10106 | u32 dspcntr; |
| 10107 | u32 reg; |
| 10108 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10109 | reg = DSPCNTR(intel_crtc->plane); |
| 10110 | dspcntr = I915_READ(reg); |
| 10111 | |
Damien Lespiau | c5d9747 | 2014-10-25 00:11:11 +0100 | [diff] [blame] | 10112 | if (obj->tiling_mode != I915_TILING_NONE) |
| 10113 | dspcntr |= DISPPLANE_TILED; |
| 10114 | else |
| 10115 | dspcntr &= ~DISPPLANE_TILED; |
| 10116 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10117 | I915_WRITE(reg, dspcntr); |
| 10118 | |
| 10119 | I915_WRITE(DSPSURF(intel_crtc->plane), |
| 10120 | intel_crtc->unpin_work->gtt_offset); |
| 10121 | POSTING_READ(DSPSURF(intel_crtc->plane)); |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 10122 | |
Damien Lespiau | ff94456 | 2014-11-20 14:58:16 +0000 | [diff] [blame] | 10123 | } |
| 10124 | |
| 10125 | /* |
| 10126 | * XXX: This is the temporary way to update the plane registers until we get |
| 10127 | * around to using the usual plane update functions for MMIO flips |
| 10128 | */ |
| 10129 | static void intel_do_mmio_flip(struct intel_crtc *intel_crtc) |
| 10130 | { |
| 10131 | struct drm_device *dev = intel_crtc->base.dev; |
| 10132 | bool atomic_update; |
| 10133 | u32 start_vbl_count; |
| 10134 | |
| 10135 | intel_mark_page_flip_active(intel_crtc); |
| 10136 | |
| 10137 | atomic_update = intel_pipe_update_start(intel_crtc, &start_vbl_count); |
| 10138 | |
| 10139 | if (INTEL_INFO(dev)->gen >= 9) |
| 10140 | skl_do_mmio_flip(intel_crtc); |
| 10141 | else |
| 10142 | /* use_mmio_flip() retricts MMIO flips to ilk+ */ |
| 10143 | ilk_do_mmio_flip(intel_crtc); |
| 10144 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 10145 | if (atomic_update) |
| 10146 | intel_pipe_update_end(intel_crtc, start_vbl_count); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10147 | } |
| 10148 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 10149 | static void intel_mmio_flip_work_func(struct work_struct *work) |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10150 | { |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10151 | struct intel_crtc *crtc = |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 10152 | container_of(work, struct intel_crtc, mmio_flip.work); |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10153 | struct intel_mmio_flip *mmio_flip; |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10154 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10155 | mmio_flip = &crtc->mmio_flip; |
| 10156 | if (mmio_flip->req) |
John Harrison | 9c65481 | 2014-11-24 18:49:35 +0000 | [diff] [blame] | 10157 | WARN_ON(__i915_wait_request(mmio_flip->req, |
| 10158 | crtc->reset_counter, |
| 10159 | false, NULL, NULL) != 0); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10160 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10161 | intel_do_mmio_flip(crtc); |
| 10162 | if (mmio_flip->req) { |
| 10163 | mutex_lock(&crtc->base.dev->struct_mutex); |
John Harrison | 146d84f | 2014-12-05 13:49:33 +0000 | [diff] [blame] | 10164 | i915_gem_request_assign(&mmio_flip->req, NULL); |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10165 | mutex_unlock(&crtc->base.dev->struct_mutex); |
| 10166 | } |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10167 | } |
| 10168 | |
| 10169 | static int intel_queue_mmio_flip(struct drm_device *dev, |
| 10170 | struct drm_crtc *crtc, |
| 10171 | struct drm_framebuffer *fb, |
| 10172 | struct drm_i915_gem_object *obj, |
| 10173 | struct intel_engine_cs *ring, |
| 10174 | uint32_t flags) |
| 10175 | { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10176 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10177 | |
John Harrison | cc8c4cc | 2014-11-24 18:49:34 +0000 | [diff] [blame] | 10178 | i915_gem_request_assign(&intel_crtc->mmio_flip.req, |
| 10179 | obj->last_write_req); |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10180 | |
Ander Conselvan de Oliveira | 536f5b5 | 2014-11-06 11:03:40 +0200 | [diff] [blame] | 10181 | schedule_work(&intel_crtc->mmio_flip.work); |
| 10182 | |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10183 | return 0; |
| 10184 | } |
| 10185 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10186 | static int intel_default_queue_flip(struct drm_device *dev, |
| 10187 | struct drm_crtc *crtc, |
| 10188 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10189 | struct drm_i915_gem_object *obj, |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10190 | struct intel_engine_cs *ring, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10191 | uint32_t flags) |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10192 | { |
| 10193 | return -ENODEV; |
| 10194 | } |
| 10195 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10196 | static bool __intel_pageflip_stall_check(struct drm_device *dev, |
| 10197 | struct drm_crtc *crtc) |
| 10198 | { |
| 10199 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10200 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 10201 | struct intel_unpin_work *work = intel_crtc->unpin_work; |
| 10202 | u32 addr; |
| 10203 | |
| 10204 | if (atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE) |
| 10205 | return true; |
| 10206 | |
| 10207 | if (!work->enable_stall_check) |
| 10208 | return false; |
| 10209 | |
| 10210 | if (work->flip_ready_vblank == 0) { |
Daniel Vetter | 3a8a946 | 2014-11-26 14:39:48 +0100 | [diff] [blame] | 10211 | if (work->flip_queued_req && |
| 10212 | !i915_gem_request_completed(work->flip_queued_req, true)) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10213 | return false; |
| 10214 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 10215 | work->flip_ready_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10216 | } |
| 10217 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 10218 | if (drm_crtc_vblank_count(crtc) - work->flip_ready_vblank < 3) |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10219 | return false; |
| 10220 | |
| 10221 | /* Potential stall - if we see that the flip has happened, |
| 10222 | * assume a missed interrupt. */ |
| 10223 | if (INTEL_INFO(dev)->gen >= 4) |
| 10224 | addr = I915_HI_DISPBASE(I915_READ(DSPSURF(intel_crtc->plane))); |
| 10225 | else |
| 10226 | addr = I915_READ(DSPADDR(intel_crtc->plane)); |
| 10227 | |
| 10228 | /* There is a potential issue here with a false positive after a flip |
| 10229 | * to the same address. We could address this by checking for a |
| 10230 | * non-incrementing frame counter. |
| 10231 | */ |
| 10232 | return addr == work->gtt_offset; |
| 10233 | } |
| 10234 | |
| 10235 | void intel_check_page_flip(struct drm_device *dev, int pipe) |
| 10236 | { |
| 10237 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 10238 | struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe]; |
| 10239 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 10240 | struct intel_unpin_work *work; |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10241 | |
Dave Gordon | 6c51d46 | 2015-03-06 15:34:26 +0000 | [diff] [blame] | 10242 | WARN_ON(!in_interrupt()); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10243 | |
| 10244 | if (crtc == NULL) |
| 10245 | return; |
| 10246 | |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10247 | spin_lock(&dev->event_lock); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 10248 | work = intel_crtc->unpin_work; |
| 10249 | if (work != NULL && __intel_pageflip_stall_check(dev, crtc)) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10250 | WARN_ONCE(1, "Kicking stuck page flip: queued at %d, now %d\n", |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 10251 | work->flip_queued_vblank, drm_vblank_count(dev, pipe)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10252 | page_flip_completed(intel_crtc); |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 10253 | work = NULL; |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10254 | } |
Chris Wilson | 6ad790c | 2015-04-07 16:20:31 +0100 | [diff] [blame] | 10255 | if (work != NULL && |
| 10256 | drm_vblank_count(dev, pipe) - work->flip_queued_vblank > 1) |
| 10257 | intel_queue_rps_boost_for_request(dev, work->flip_queued_req); |
Daniel Vetter | f326038 | 2014-09-15 14:55:23 +0200 | [diff] [blame] | 10258 | spin_unlock(&dev->event_lock); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10259 | } |
| 10260 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10261 | static int intel_crtc_page_flip(struct drm_crtc *crtc, |
| 10262 | struct drm_framebuffer *fb, |
Keith Packard | ed8d197 | 2013-07-22 18:49:58 -0700 | [diff] [blame] | 10263 | struct drm_pending_vblank_event *event, |
| 10264 | uint32_t page_flip_flags) |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10265 | { |
| 10266 | struct drm_device *dev = crtc->dev; |
| 10267 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10268 | struct drm_framebuffer *old_fb = crtc->primary->fb; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 10269 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10270 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 10271 | struct drm_plane *primary = crtc->primary; |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10272 | enum pipe pipe = intel_crtc->pipe; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10273 | struct intel_unpin_work *work; |
Oscar Mateo | a4872ba | 2014-05-22 14:13:33 +0100 | [diff] [blame] | 10274 | struct intel_engine_cs *ring; |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 10275 | bool mmio_flip; |
Chris Wilson | 52e6863 | 2010-08-08 10:15:59 +0100 | [diff] [blame] | 10276 | int ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10277 | |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 10278 | /* |
| 10279 | * drm_mode_page_flip_ioctl() should already catch this, but double |
| 10280 | * check to be safe. In the future we may enable pageflipping from |
| 10281 | * a disabled primary plane. |
| 10282 | */ |
| 10283 | if (WARN_ON(intel_fb_obj(old_fb) == NULL)) |
| 10284 | return -EBUSY; |
| 10285 | |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 10286 | /* Can't change pixel format via MI display flips. */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10287 | if (fb->pixel_format != crtc->primary->fb->pixel_format) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 10288 | return -EINVAL; |
| 10289 | |
| 10290 | /* |
| 10291 | * TILEOFF/LINOFF registers can't be changed via MI display flips. |
| 10292 | * Note that pitch changes could also affect these register. |
| 10293 | */ |
| 10294 | if (INTEL_INFO(dev)->gen > 3 && |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10295 | (fb->offsets[0] != crtc->primary->fb->offsets[0] || |
| 10296 | fb->pitches[0] != crtc->primary->fb->pitches[0])) |
Ville Syrjälä | e6a595d | 2012-05-24 21:08:59 +0300 | [diff] [blame] | 10297 | return -EINVAL; |
| 10298 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10299 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 10300 | goto out_hang; |
| 10301 | |
Daniel Vetter | b14c567 | 2013-09-19 12:18:32 +0200 | [diff] [blame] | 10302 | work = kzalloc(sizeof(*work), GFP_KERNEL); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10303 | if (work == NULL) |
| 10304 | return -ENOMEM; |
| 10305 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10306 | work->event = event; |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10307 | work->crtc = crtc; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10308 | work->old_fb = old_fb; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10309 | INIT_WORK(&work->work, intel_unpin_work_fn); |
| 10310 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 10311 | ret = drm_crtc_vblank_get(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 10312 | if (ret) |
| 10313 | goto free_work; |
| 10314 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10315 | /* We borrow the event spin lock for protecting unpin_work */ |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10316 | spin_lock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10317 | if (intel_crtc->unpin_work) { |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10318 | /* Before declaring the flip queue wedged, check if |
| 10319 | * the hardware completed the operation behind our backs. |
| 10320 | */ |
| 10321 | if (__intel_pageflip_stall_check(dev, crtc)) { |
| 10322 | DRM_DEBUG_DRIVER("flip queue: previous flip completed, continuing\n"); |
| 10323 | page_flip_completed(intel_crtc); |
| 10324 | } else { |
| 10325 | DRM_DEBUG_DRIVER("flip queue: crtc already busy\n"); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10326 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 468f0b4 | 2010-05-27 13:18:13 +0100 | [diff] [blame] | 10327 | |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10328 | drm_crtc_vblank_put(crtc); |
| 10329 | kfree(work); |
| 10330 | return -EBUSY; |
| 10331 | } |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10332 | } |
| 10333 | intel_crtc->unpin_work = work; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10334 | spin_unlock_irq(&dev->event_lock); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10335 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10336 | if (atomic_read(&intel_crtc->unpin_work_count) >= 2) |
| 10337 | flush_workqueue(dev_priv->wq); |
| 10338 | |
Jesse Barnes | 75dfca8 | 2010-02-10 15:09:44 -0800 | [diff] [blame] | 10339 | /* Reference the objects for the scheduled work. */ |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10340 | drm_framebuffer_reference(work->old_fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 10341 | drm_gem_object_reference(&obj->base); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10342 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10343 | crtc->primary->fb = fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 10344 | update_state_fb(crtc->primary); |
Matt Roper | 1ed1f96 | 2015-01-30 16:22:36 -0800 | [diff] [blame] | 10345 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10346 | work->pending_flip_obj = obj; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10347 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10348 | ret = i915_mutex_lock_interruptible(dev); |
| 10349 | if (ret) |
| 10350 | goto cleanup; |
| 10351 | |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10352 | atomic_inc(&intel_crtc->unpin_work_count); |
Ville Syrjälä | 10d8373 | 2013-01-29 18:13:34 +0200 | [diff] [blame] | 10353 | intel_crtc->reset_counter = atomic_read(&dev_priv->gpu_error.reset_counter); |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 10354 | |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10355 | if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev)) |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10356 | work->flip_count = I915_READ(PIPE_FLIPCOUNT_GM45(pipe)) + 1; |
Ville Syrjälä | 75f7f3e | 2014-04-15 21:41:34 +0300 | [diff] [blame] | 10357 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10358 | if (IS_VALLEYVIEW(dev)) { |
| 10359 | ring = &dev_priv->ring[BCS]; |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10360 | if (obj->tiling_mode != intel_fb_obj(work->old_fb)->tiling_mode) |
Chris Wilson | 8e09bf8 | 2014-07-08 10:40:30 +0100 | [diff] [blame] | 10361 | /* vlv: DISPLAY_FLIP fails to change tiling */ |
| 10362 | ring = NULL; |
Chris Wilson | 48bf5b2 | 2014-12-27 09:48:28 +0000 | [diff] [blame] | 10363 | } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) { |
Chris Wilson | 2a92d5b | 2014-07-08 10:40:29 +0100 | [diff] [blame] | 10364 | ring = &dev_priv->ring[BCS]; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10365 | } else if (INTEL_INFO(dev)->gen >= 7) { |
John Harrison | 41c5241 | 2014-11-24 18:49:43 +0000 | [diff] [blame] | 10366 | ring = i915_gem_request_get_ring(obj->last_read_req); |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10367 | if (ring == NULL || ring->id != RCS) |
| 10368 | ring = &dev_priv->ring[BCS]; |
| 10369 | } else { |
| 10370 | ring = &dev_priv->ring[RCS]; |
| 10371 | } |
| 10372 | |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 10373 | mmio_flip = use_mmio_flip(ring, obj); |
| 10374 | |
| 10375 | /* When using CS flips, we want to emit semaphores between rings. |
| 10376 | * However, when using mmio flips we will create a task to do the |
| 10377 | * synchronisation, so all we want here is to pin the framebuffer |
| 10378 | * into the display plane and skip any waits. |
| 10379 | */ |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 10380 | ret = intel_pin_and_fence_fb_obj(crtc->primary, fb, |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 10381 | crtc->primary->state, |
| 10382 | mmio_flip ? i915_gem_request_get_ring(obj->last_read_req) : ring); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10383 | if (ret) |
| 10384 | goto cleanup_pending; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10385 | |
Tvrtko Ursulin | 121920f | 2015-03-23 11:10:37 +0000 | [diff] [blame] | 10386 | work->gtt_offset = intel_plane_obj_offset(to_intel_plane(primary), obj) |
| 10387 | + intel_crtc->dspaddr_offset; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10388 | |
Chris Wilson | cf5d8a4 | 2015-04-07 16:20:26 +0100 | [diff] [blame] | 10389 | if (mmio_flip) { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10390 | ret = intel_queue_mmio_flip(dev, crtc, fb, obj, ring, |
| 10391 | page_flip_flags); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10392 | if (ret) |
| 10393 | goto cleanup_unpin; |
| 10394 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10395 | i915_gem_request_assign(&work->flip_queued_req, |
| 10396 | obj->last_write_req); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10397 | } else { |
Sourab Gupta | 84c33a6 | 2014-06-02 16:47:17 +0530 | [diff] [blame] | 10398 | ret = dev_priv->display.queue_flip(dev, crtc, fb, obj, ring, |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10399 | page_flip_flags); |
| 10400 | if (ret) |
| 10401 | goto cleanup_unpin; |
| 10402 | |
John Harrison | f06cc1b | 2014-11-24 18:49:37 +0000 | [diff] [blame] | 10403 | i915_gem_request_assign(&work->flip_queued_req, |
| 10404 | intel_ring_get_request(ring)); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10405 | } |
| 10406 | |
Daniel Vetter | 1e3feef | 2015-02-13 21:03:45 +0100 | [diff] [blame] | 10407 | work->flip_queued_vblank = drm_crtc_vblank_count(crtc); |
Chris Wilson | d6bbafa | 2014-09-05 07:13:24 +0100 | [diff] [blame] | 10408 | work->enable_stall_check = true; |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10409 | |
Tvrtko Ursulin | ab8d667 | 2015-02-02 15:44:15 +0000 | [diff] [blame] | 10410 | i915_gem_track_fb(intel_fb_obj(work->old_fb), obj, |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10411 | INTEL_FRONTBUFFER_PRIMARY(pipe)); |
| 10412 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 10413 | intel_fbc_disable(dev); |
Daniel Vetter | f99d706 | 2014-06-19 16:01:59 +0200 | [diff] [blame] | 10414 | intel_frontbuffer_flip_prepare(dev, INTEL_FRONTBUFFER_PRIMARY(pipe)); |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10415 | mutex_unlock(&dev->struct_mutex); |
| 10416 | |
Jesse Barnes | e5510fa | 2010-07-01 16:48:37 -0700 | [diff] [blame] | 10417 | trace_i915_flip_request(intel_crtc->plane, obj); |
| 10418 | |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10419 | return 0; |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10420 | |
Ville Syrjälä | 4fa62c8 | 2014-04-15 21:41:38 +0300 | [diff] [blame] | 10421 | cleanup_unpin: |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 10422 | intel_unpin_fb_obj(fb, crtc->primary->state); |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 10423 | cleanup_pending: |
Chris Wilson | b4a98e5 | 2012-11-01 09:26:26 +0000 | [diff] [blame] | 10424 | atomic_dec(&intel_crtc->unpin_work_count); |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10425 | mutex_unlock(&dev->struct_mutex); |
| 10426 | cleanup: |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 10427 | crtc->primary->fb = old_fb; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 10428 | update_state_fb(crtc->primary); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10429 | |
Chris Wilson | 89ed88b | 2015-02-16 14:31:49 +0000 | [diff] [blame] | 10430 | drm_gem_object_unreference_unlocked(&obj->base); |
| 10431 | drm_framebuffer_unreference(work->old_fb); |
| 10432 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10433 | spin_lock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10434 | intel_crtc->unpin_work = NULL; |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10435 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10436 | |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 10437 | drm_crtc_vblank_put(crtc); |
Jesse Barnes | 7317c75e6 | 2011-08-29 09:45:28 -0700 | [diff] [blame] | 10438 | free_work: |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10439 | kfree(work); |
| 10440 | |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10441 | if (ret == -EIO) { |
| 10442 | out_hang: |
Matt Roper | 53a366b | 2014-12-23 10:41:53 -0800 | [diff] [blame] | 10443 | ret = intel_plane_restore(primary); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 10444 | if (ret == 0 && event) { |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10445 | spin_lock_irq(&dev->event_lock); |
Daniel Vetter | a071fa0 | 2014-06-18 23:28:09 +0200 | [diff] [blame] | 10446 | drm_send_vblank_event(dev, pipe, event); |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 10447 | spin_unlock_irq(&dev->event_lock); |
Chris Wilson | f0d3dad | 2014-09-07 16:51:12 +0100 | [diff] [blame] | 10448 | } |
Chris Wilson | f900db4 | 2014-02-20 09:26:13 +0000 | [diff] [blame] | 10449 | } |
Chris Wilson | 96b099f | 2010-06-07 14:03:04 +0100 | [diff] [blame] | 10450 | return ret; |
Kristian Høgsberg | 6b95a20 | 2009-11-18 11:25:18 -0500 | [diff] [blame] | 10451 | } |
| 10452 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10453 | static struct drm_crtc_helper_funcs intel_helper_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10454 | .mode_set_base_atomic = intel_pipe_set_base_atomic, |
| 10455 | .load_lut = intel_crtc_load_lut, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 10456 | .atomic_begin = intel_begin_crtc_commit, |
| 10457 | .atomic_flush = intel_finish_crtc_commit, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 10458 | }; |
| 10459 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10460 | /** |
| 10461 | * intel_modeset_update_staged_output_state |
| 10462 | * |
| 10463 | * Updates the staged output configuration state, e.g. after we've read out the |
| 10464 | * current hw state. |
| 10465 | */ |
| 10466 | static void intel_modeset_update_staged_output_state(struct drm_device *dev) |
| 10467 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10468 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10469 | struct intel_encoder *encoder; |
| 10470 | struct intel_connector *connector; |
| 10471 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10472 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10473 | connector->new_encoder = |
| 10474 | to_intel_encoder(connector->base.encoder); |
| 10475 | } |
| 10476 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10477 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10478 | encoder->new_crtc = |
| 10479 | to_intel_crtc(encoder->base.crtc); |
| 10480 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10481 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10482 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10483 | crtc->new_enabled = crtc->base.state->enable; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10484 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10485 | } |
| 10486 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10487 | /* Transitional helper to copy current connector/encoder state to |
| 10488 | * connector->state. This is needed so that code that is partially |
| 10489 | * converted to atomic does the right thing. |
| 10490 | */ |
| 10491 | static void intel_modeset_update_connector_atomic_state(struct drm_device *dev) |
| 10492 | { |
| 10493 | struct intel_connector *connector; |
| 10494 | |
| 10495 | for_each_intel_connector(dev, connector) { |
| 10496 | if (connector->base.encoder) { |
| 10497 | connector->base.state->best_encoder = |
| 10498 | connector->base.encoder; |
| 10499 | connector->base.state->crtc = |
| 10500 | connector->base.encoder->crtc; |
| 10501 | } else { |
| 10502 | connector->base.state->best_encoder = NULL; |
| 10503 | connector->base.state->crtc = NULL; |
| 10504 | } |
| 10505 | } |
| 10506 | } |
| 10507 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10508 | /** |
| 10509 | * intel_modeset_commit_output_state |
| 10510 | * |
| 10511 | * This function copies the stage display pipe configuration to the real one. |
| 10512 | */ |
| 10513 | static void intel_modeset_commit_output_state(struct drm_device *dev) |
| 10514 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10515 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10516 | struct intel_encoder *encoder; |
| 10517 | struct intel_connector *connector; |
| 10518 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 10519 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10520 | connector->base.encoder = &connector->new_encoder->base; |
| 10521 | } |
| 10522 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 10523 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10524 | encoder->base.crtc = &encoder->new_crtc->base; |
| 10525 | } |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10526 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 10527 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 10528 | crtc->base.state->enable = crtc->new_enabled; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 10529 | crtc->base.enabled = crtc->new_enabled; |
| 10530 | } |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 10531 | |
| 10532 | intel_modeset_update_connector_atomic_state(dev); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 10533 | } |
| 10534 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10535 | static void |
Robin Schroer | eba905b | 2014-05-18 02:24:50 +0200 | [diff] [blame] | 10536 | connected_sink_compute_bpp(struct intel_connector *connector, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10537 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10538 | { |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10539 | int bpp = pipe_config->pipe_bpp; |
| 10540 | |
| 10541 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] checking for sink bpp constrains\n", |
| 10542 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 10543 | connector->base.name); |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10544 | |
| 10545 | /* Don't use an invalid EDID bpc value */ |
| 10546 | if (connector->base.display_info.bpc && |
| 10547 | connector->base.display_info.bpc * 3 < bpp) { |
| 10548 | DRM_DEBUG_KMS("clamping display bpp (was %d) to EDID reported max of %d\n", |
| 10549 | bpp, connector->base.display_info.bpc*3); |
| 10550 | pipe_config->pipe_bpp = connector->base.display_info.bpc*3; |
| 10551 | } |
| 10552 | |
| 10553 | /* Clamp bpp to 8 on screens without EDID 1.4 */ |
| 10554 | if (connector->base.display_info.bpc == 0 && bpp > 24) { |
| 10555 | DRM_DEBUG_KMS("clamping display bpp (was %d) to default limit of 24\n", |
| 10556 | bpp); |
| 10557 | pipe_config->pipe_bpp = 24; |
| 10558 | } |
| 10559 | } |
| 10560 | |
| 10561 | static int |
| 10562 | compute_baseline_pipe_bpp(struct intel_crtc *crtc, |
| 10563 | struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10564 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10565 | { |
| 10566 | struct drm_device *dev = crtc->base.dev; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10567 | struct drm_atomic_state *state; |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10568 | struct intel_connector *connector; |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10569 | int bpp, i; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10570 | |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10571 | switch (fb->pixel_format) { |
| 10572 | case DRM_FORMAT_C8: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10573 | bpp = 8*3; /* since we go through a colormap */ |
| 10574 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10575 | case DRM_FORMAT_XRGB1555: |
| 10576 | case DRM_FORMAT_ARGB1555: |
| 10577 | /* checked in intel_framebuffer_init already */ |
| 10578 | if (WARN_ON(INTEL_INFO(dev)->gen > 3)) |
| 10579 | return -EINVAL; |
| 10580 | case DRM_FORMAT_RGB565: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10581 | bpp = 6*3; /* min is 18bpp */ |
| 10582 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10583 | case DRM_FORMAT_XBGR8888: |
| 10584 | case DRM_FORMAT_ABGR8888: |
| 10585 | /* checked in intel_framebuffer_init already */ |
| 10586 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
| 10587 | return -EINVAL; |
| 10588 | case DRM_FORMAT_XRGB8888: |
| 10589 | case DRM_FORMAT_ARGB8888: |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10590 | bpp = 8*3; |
| 10591 | break; |
Daniel Vetter | d42264b | 2013-03-28 16:38:08 +0100 | [diff] [blame] | 10592 | case DRM_FORMAT_XRGB2101010: |
| 10593 | case DRM_FORMAT_ARGB2101010: |
| 10594 | case DRM_FORMAT_XBGR2101010: |
| 10595 | case DRM_FORMAT_ABGR2101010: |
| 10596 | /* checked in intel_framebuffer_init already */ |
| 10597 | if (WARN_ON(INTEL_INFO(dev)->gen < 4)) |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10598 | return -EINVAL; |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10599 | bpp = 10*3; |
| 10600 | break; |
Daniel Vetter | baba133 | 2013-03-27 00:45:00 +0100 | [diff] [blame] | 10601 | /* TODO: gen4+ supports 16 bpc floating point, too. */ |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10602 | default: |
| 10603 | DRM_DEBUG_KMS("unsupported depth\n"); |
| 10604 | return -EINVAL; |
| 10605 | } |
| 10606 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10607 | pipe_config->pipe_bpp = bpp; |
| 10608 | |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10609 | state = pipe_config->base.state; |
| 10610 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10611 | /* Clamp display bpp to EDID value */ |
Ander Conselvan de Oliveira | 1486017 | 2015-03-20 16:18:09 +0200 | [diff] [blame] | 10612 | for (i = 0; i < state->num_connector; i++) { |
| 10613 | if (!state->connectors[i]) |
| 10614 | continue; |
| 10615 | |
| 10616 | connector = to_intel_connector(state->connectors[i]); |
| 10617 | if (state->connector_states[i]->crtc != &crtc->base) |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10618 | continue; |
| 10619 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10620 | connected_sink_compute_bpp(connector, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10621 | } |
| 10622 | |
| 10623 | return bpp; |
| 10624 | } |
| 10625 | |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10626 | static void intel_dump_crtc_timings(const struct drm_display_mode *mode) |
| 10627 | { |
| 10628 | DRM_DEBUG_KMS("crtc timings: %d %d %d %d %d %d %d %d %d, " |
| 10629 | "type: 0x%x flags: 0x%x\n", |
Damien Lespiau | 1342830 | 2013-09-25 16:45:36 +0100 | [diff] [blame] | 10630 | mode->crtc_clock, |
Daniel Vetter | 644db71 | 2013-09-19 14:53:58 +0200 | [diff] [blame] | 10631 | mode->crtc_hdisplay, mode->crtc_hsync_start, |
| 10632 | mode->crtc_hsync_end, mode->crtc_htotal, |
| 10633 | mode->crtc_vdisplay, mode->crtc_vsync_start, |
| 10634 | mode->crtc_vsync_end, mode->crtc_vtotal, mode->type, mode->flags); |
| 10635 | } |
| 10636 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10637 | static void intel_dump_pipe_config(struct intel_crtc *crtc, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10638 | struct intel_crtc_state *pipe_config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10639 | const char *context) |
| 10640 | { |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10641 | struct drm_device *dev = crtc->base.dev; |
| 10642 | struct drm_plane *plane; |
| 10643 | struct intel_plane *intel_plane; |
| 10644 | struct intel_plane_state *state; |
| 10645 | struct drm_framebuffer *fb; |
| 10646 | |
| 10647 | DRM_DEBUG_KMS("[CRTC:%d]%s config %p for pipe %c\n", crtc->base.base.id, |
| 10648 | context, pipe_config, pipe_name(crtc->pipe)); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10649 | |
| 10650 | DRM_DEBUG_KMS("cpu_transcoder: %c\n", transcoder_name(pipe_config->cpu_transcoder)); |
| 10651 | DRM_DEBUG_KMS("pipe bpp: %i, dithering: %i\n", |
| 10652 | pipe_config->pipe_bpp, pipe_config->dither); |
| 10653 | DRM_DEBUG_KMS("fdi/pch: %i, lanes: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10654 | pipe_config->has_pch_encoder, |
| 10655 | pipe_config->fdi_lanes, |
| 10656 | pipe_config->fdi_m_n.gmch_m, pipe_config->fdi_m_n.gmch_n, |
| 10657 | pipe_config->fdi_m_n.link_m, pipe_config->fdi_m_n.link_n, |
| 10658 | pipe_config->fdi_m_n.tu); |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 10659 | DRM_DEBUG_KMS("dp: %i, gmch_m: %u, gmch_n: %u, link_m: %u, link_n: %u, tu: %u\n", |
| 10660 | pipe_config->has_dp_encoder, |
| 10661 | pipe_config->dp_m_n.gmch_m, pipe_config->dp_m_n.gmch_n, |
| 10662 | pipe_config->dp_m_n.link_m, pipe_config->dp_m_n.link_n, |
| 10663 | pipe_config->dp_m_n.tu); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 10664 | |
| 10665 | DRM_DEBUG_KMS("dp: %i, gmch_m2: %u, gmch_n2: %u, link_m2: %u, link_n2: %u, tu2: %u\n", |
| 10666 | pipe_config->has_dp_encoder, |
| 10667 | pipe_config->dp_m2_n2.gmch_m, |
| 10668 | pipe_config->dp_m2_n2.gmch_n, |
| 10669 | pipe_config->dp_m2_n2.link_m, |
| 10670 | pipe_config->dp_m2_n2.link_n, |
| 10671 | pipe_config->dp_m2_n2.tu); |
| 10672 | |
Daniel Vetter | 55072d1 | 2014-11-20 16:10:28 +0100 | [diff] [blame] | 10673 | DRM_DEBUG_KMS("audio: %i, infoframes: %i\n", |
| 10674 | pipe_config->has_audio, |
| 10675 | pipe_config->has_infoframe); |
| 10676 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10677 | DRM_DEBUG_KMS("requested mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10678 | drm_mode_debug_printmodeline(&pipe_config->base.mode); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10679 | DRM_DEBUG_KMS("adjusted mode:\n"); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10680 | drm_mode_debug_printmodeline(&pipe_config->base.adjusted_mode); |
| 10681 | intel_dump_crtc_timings(&pipe_config->base.adjusted_mode); |
Ville Syrjälä | d71b8d4 | 2013-09-06 23:29:08 +0300 | [diff] [blame] | 10682 | DRM_DEBUG_KMS("port clock: %d\n", pipe_config->port_clock); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10683 | DRM_DEBUG_KMS("pipe src size: %dx%d\n", |
| 10684 | pipe_config->pipe_src_w, pipe_config->pipe_src_h); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10685 | DRM_DEBUG_KMS("num_scalers: %d\n", crtc->num_scalers); |
| 10686 | DRM_DEBUG_KMS("scaler_users: 0x%x\n", pipe_config->scaler_state.scaler_users); |
| 10687 | DRM_DEBUG_KMS("scaler id: %d\n", pipe_config->scaler_state.scaler_id); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10688 | DRM_DEBUG_KMS("gmch pfit: control: 0x%08x, ratios: 0x%08x, lvds border: 0x%08x\n", |
| 10689 | pipe_config->gmch_pfit.control, |
| 10690 | pipe_config->gmch_pfit.pgm_ratios, |
| 10691 | pipe_config->gmch_pfit.lvds_border_bits); |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10692 | 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] | 10693 | pipe_config->pch_pfit.pos, |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 10694 | pipe_config->pch_pfit.size, |
| 10695 | pipe_config->pch_pfit.enabled ? "enabled" : "disabled"); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 10696 | DRM_DEBUG_KMS("ips: %i\n", pipe_config->ips_enabled); |
Ville Syrjälä | cf532bb | 2013-09-04 18:30:02 +0300 | [diff] [blame] | 10697 | DRM_DEBUG_KMS("double wide: %i\n", pipe_config->double_wide); |
Chandra Konduru | 6a60cd8 | 2015-04-07 15:28:40 -0700 | [diff] [blame] | 10698 | |
| 10699 | DRM_DEBUG_KMS("planes on this crtc\n"); |
| 10700 | list_for_each_entry(plane, &dev->mode_config.plane_list, head) { |
| 10701 | intel_plane = to_intel_plane(plane); |
| 10702 | if (intel_plane->pipe != crtc->pipe) |
| 10703 | continue; |
| 10704 | |
| 10705 | state = to_intel_plane_state(plane->state); |
| 10706 | fb = state->base.fb; |
| 10707 | if (!fb) { |
| 10708 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d " |
| 10709 | "disabled, scaler_id = %d\n", |
| 10710 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 10711 | plane->base.id, intel_plane->pipe, |
| 10712 | (crtc->base.primary == plane) ? 0 : intel_plane->plane + 1, |
| 10713 | drm_plane_index(plane), state->scaler_id); |
| 10714 | continue; |
| 10715 | } |
| 10716 | |
| 10717 | DRM_DEBUG_KMS("%s PLANE:%d plane: %u.%u idx: %d enabled", |
| 10718 | plane->type == DRM_PLANE_TYPE_CURSOR ? "CURSOR" : "STANDARD", |
| 10719 | plane->base.id, intel_plane->pipe, |
| 10720 | crtc->base.primary == plane ? 0 : intel_plane->plane + 1, |
| 10721 | drm_plane_index(plane)); |
| 10722 | DRM_DEBUG_KMS("\tFB:%d, fb = %ux%u format = 0x%x", |
| 10723 | fb->base.id, fb->width, fb->height, fb->pixel_format); |
| 10724 | DRM_DEBUG_KMS("\tscaler:%d src (%u, %u) %ux%u dst (%u, %u) %ux%u\n", |
| 10725 | state->scaler_id, |
| 10726 | state->src.x1 >> 16, state->src.y1 >> 16, |
| 10727 | drm_rect_width(&state->src) >> 16, |
| 10728 | drm_rect_height(&state->src) >> 16, |
| 10729 | state->dst.x1, state->dst.y1, |
| 10730 | drm_rect_width(&state->dst), drm_rect_height(&state->dst)); |
| 10731 | } |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 10732 | } |
| 10733 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10734 | static bool encoders_cloneable(const struct intel_encoder *a, |
| 10735 | const struct intel_encoder *b) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10736 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10737 | /* masks could be asymmetric, so check both ways */ |
| 10738 | return a == b || (a->cloneable & (1 << b->type) && |
| 10739 | b->cloneable & (1 << a->type)); |
| 10740 | } |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10741 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 10742 | static bool check_single_encoder_cloning(struct drm_atomic_state *state, |
| 10743 | struct intel_crtc *crtc, |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10744 | struct intel_encoder *encoder) |
| 10745 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10746 | struct intel_encoder *source_encoder; |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 10747 | struct drm_connector_state *connector_state; |
| 10748 | int i; |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10749 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 10750 | for (i = 0; i < state->num_connector; i++) { |
| 10751 | if (!state->connectors[i]) |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10752 | continue; |
| 10753 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 10754 | connector_state = state->connector_states[i]; |
| 10755 | if (connector_state->crtc != &crtc->base) |
| 10756 | continue; |
| 10757 | |
| 10758 | source_encoder = |
| 10759 | to_intel_encoder(connector_state->best_encoder); |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10760 | if (!encoders_cloneable(encoder, source_encoder)) |
| 10761 | return false; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10762 | } |
| 10763 | |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10764 | return true; |
| 10765 | } |
| 10766 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 10767 | static bool check_encoder_cloning(struct drm_atomic_state *state, |
| 10768 | struct intel_crtc *crtc) |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10769 | { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10770 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 10771 | struct drm_connector_state *connector_state; |
| 10772 | int i; |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10773 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 10774 | for (i = 0; i < state->num_connector; i++) { |
| 10775 | if (!state->connectors[i]) |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10776 | continue; |
| 10777 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 10778 | connector_state = state->connector_states[i]; |
| 10779 | if (connector_state->crtc != &crtc->base) |
| 10780 | continue; |
| 10781 | |
| 10782 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 10783 | if (!check_single_encoder_cloning(state, crtc, encoder)) |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 10784 | return false; |
| 10785 | } |
| 10786 | |
| 10787 | return true; |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10788 | } |
| 10789 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 10790 | static bool check_digital_port_conflicts(struct drm_atomic_state *state) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10791 | { |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 10792 | struct drm_device *dev = state->dev; |
| 10793 | struct intel_encoder *encoder; |
| 10794 | struct drm_connector_state *connector_state; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10795 | unsigned int used_ports = 0; |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 10796 | int i; |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10797 | |
| 10798 | /* |
| 10799 | * Walk the connector list instead of the encoder |
| 10800 | * list to detect the problem on ddi platforms |
| 10801 | * where there's just one encoder per digital port. |
| 10802 | */ |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 10803 | for (i = 0; i < state->num_connector; i++) { |
| 10804 | if (!state->connectors[i]) |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10805 | continue; |
| 10806 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 10807 | connector_state = state->connector_states[i]; |
| 10808 | if (!connector_state->best_encoder) |
| 10809 | continue; |
| 10810 | |
| 10811 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 10812 | |
| 10813 | WARN_ON(!connector_state->crtc); |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10814 | |
| 10815 | switch (encoder->type) { |
| 10816 | unsigned int port_mask; |
| 10817 | case INTEL_OUTPUT_UNKNOWN: |
| 10818 | if (WARN_ON(!HAS_DDI(dev))) |
| 10819 | break; |
| 10820 | case INTEL_OUTPUT_DISPLAYPORT: |
| 10821 | case INTEL_OUTPUT_HDMI: |
| 10822 | case INTEL_OUTPUT_EDP: |
| 10823 | port_mask = 1 << enc_to_dig_port(&encoder->base)->port; |
| 10824 | |
| 10825 | /* the same port mustn't appear more than once */ |
| 10826 | if (used_ports & port_mask) |
| 10827 | return false; |
| 10828 | |
| 10829 | used_ports |= port_mask; |
| 10830 | default: |
| 10831 | break; |
| 10832 | } |
| 10833 | } |
| 10834 | |
| 10835 | return true; |
| 10836 | } |
| 10837 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10838 | static void |
| 10839 | clear_intel_crtc_state(struct intel_crtc_state *crtc_state) |
| 10840 | { |
| 10841 | struct drm_crtc_state tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame^] | 10842 | struct intel_crtc_scaler_state scaler_state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10843 | |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame^] | 10844 | /* Clear only the intel specific part of the crtc state excluding scalers */ |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10845 | tmp_state = crtc_state->base; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame^] | 10846 | scaler_state = crtc_state->scaler_state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10847 | memset(crtc_state, 0, sizeof *crtc_state); |
| 10848 | crtc_state->base = tmp_state; |
Chandra Konduru | 663a364 | 2015-04-07 15:28:41 -0700 | [diff] [blame^] | 10849 | crtc_state->scaler_state = scaler_state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10850 | } |
| 10851 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10852 | static struct intel_crtc_state * |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10853 | intel_modeset_pipe_config(struct drm_crtc *crtc, |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10854 | struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10855 | struct drm_display_mode *mode, |
| 10856 | struct drm_atomic_state *state) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10857 | { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10858 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10859 | struct intel_connector *connector; |
| 10860 | struct drm_connector_state *connector_state; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 10861 | struct intel_crtc_state *pipe_config; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10862 | int plane_bpp, ret = -EINVAL; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10863 | int i; |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10864 | bool retry = true; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10865 | |
Ander Conselvan de Oliveira | 98a221d | 2015-04-02 14:48:00 +0300 | [diff] [blame] | 10866 | if (!check_encoder_cloning(state, to_intel_crtc(crtc))) { |
Daniel Vetter | accfc0c | 2013-05-30 15:04:25 +0200 | [diff] [blame] | 10867 | DRM_DEBUG_KMS("rejecting invalid cloning configuration\n"); |
| 10868 | return ERR_PTR(-EINVAL); |
| 10869 | } |
| 10870 | |
Ander Conselvan de Oliveira | 5448a00 | 2015-04-02 14:47:59 +0300 | [diff] [blame] | 10871 | if (!check_digital_port_conflicts(state)) { |
Ville Syrjälä | 00f0b37 | 2014-12-02 14:10:46 +0200 | [diff] [blame] | 10872 | DRM_DEBUG_KMS("rejecting conflicting digital port configuration\n"); |
| 10873 | return ERR_PTR(-EINVAL); |
| 10874 | } |
| 10875 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 10876 | pipe_config = intel_atomic_get_crtc_state(state, to_intel_crtc(crtc)); |
| 10877 | if (IS_ERR(pipe_config)) |
| 10878 | return pipe_config; |
| 10879 | |
| 10880 | clear_intel_crtc_state(pipe_config); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10881 | |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 10882 | pipe_config->base.crtc = crtc; |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10883 | drm_mode_copy(&pipe_config->base.adjusted_mode, mode); |
| 10884 | drm_mode_copy(&pipe_config->base.mode, mode); |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 10885 | |
Daniel Vetter | e143a21 | 2013-07-04 12:01:15 +0200 | [diff] [blame] | 10886 | pipe_config->cpu_transcoder = |
| 10887 | (enum transcoder) to_intel_crtc(crtc)->pipe; |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 10888 | pipe_config->shared_dpll = DPLL_ID_PRIVATE; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10889 | |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10890 | /* |
| 10891 | * Sanitize sync polarity flags based on requested ones. If neither |
| 10892 | * positive or negative polarity is requested, treat this as meaning |
| 10893 | * negative polarity. |
| 10894 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10895 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10896 | (DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NHSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10897 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NHSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10898 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10899 | if (!(pipe_config->base.adjusted_mode.flags & |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10900 | (DRM_MODE_FLAG_PVSYNC | DRM_MODE_FLAG_NVSYNC))) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10901 | pipe_config->base.adjusted_mode.flags |= DRM_MODE_FLAG_NVSYNC; |
Imre Deak | 2960bc9 | 2013-07-30 13:36:32 +0300 | [diff] [blame] | 10902 | |
Daniel Vetter | 050f7ae | 2013-06-02 13:26:23 +0200 | [diff] [blame] | 10903 | /* Compute a starting value for pipe_config->pipe_bpp taking the source |
| 10904 | * plane pixel format and any sink constraints into account. Returns the |
| 10905 | * source plane bpp so that dithering can be selected on mismatches |
| 10906 | * after encoders and crtc also have had their say. */ |
| 10907 | plane_bpp = compute_baseline_pipe_bpp(to_intel_crtc(crtc), |
| 10908 | fb, pipe_config); |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10909 | if (plane_bpp < 0) |
| 10910 | goto fail; |
| 10911 | |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10912 | /* |
| 10913 | * Determine the real pipe dimensions. Note that stereo modes can |
| 10914 | * increase the actual pipe size due to the frame doubling and |
| 10915 | * insertion of additional space for blanks between the frame. This |
| 10916 | * is stored in the crtc timings. We use the requested mode to do this |
| 10917 | * computation to clearly distinguish it from the adjusted mode, which |
| 10918 | * can be changed by the connectors in the below retry loop. |
| 10919 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10920 | drm_crtc_get_hv_timing(&pipe_config->base.mode, |
Gustavo Padovan | ecb7e16 | 2014-12-01 15:40:09 -0800 | [diff] [blame] | 10921 | &pipe_config->pipe_src_w, |
| 10922 | &pipe_config->pipe_src_h); |
Ville Syrjälä | e41a56b | 2013-10-01 22:52:14 +0300 | [diff] [blame] | 10923 | |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10924 | encoder_retry: |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10925 | /* Ensure the port clock defaults are reset when retrying. */ |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10926 | pipe_config->port_clock = 0; |
Daniel Vetter | ef1b460 | 2013-06-01 17:17:04 +0200 | [diff] [blame] | 10927 | pipe_config->pixel_multiplier = 1; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10928 | |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10929 | /* Fill in default crtc timings, allow encoders to overwrite them. */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10930 | drm_mode_set_crtcinfo(&pipe_config->base.adjusted_mode, |
| 10931 | CRTC_STEREO_DOUBLE); |
Daniel Vetter | 135c81b | 2013-07-21 21:37:09 +0200 | [diff] [blame] | 10932 | |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10933 | /* Pass our mode to the connectors and the CRTC to give them a chance to |
| 10934 | * adjust it according to limitations or connector properties, and also |
| 10935 | * a chance to reject the mode entirely. |
| 10936 | */ |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10937 | for (i = 0; i < state->num_connector; i++) { |
| 10938 | connector = to_intel_connector(state->connectors[i]); |
| 10939 | if (!connector) |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10940 | continue; |
Daniel Vetter | 7ae8923 | 2013-03-27 00:44:52 +0100 | [diff] [blame] | 10941 | |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 10942 | connector_state = state->connector_states[i]; |
| 10943 | if (connector_state->crtc != crtc) |
| 10944 | continue; |
| 10945 | |
| 10946 | encoder = to_intel_encoder(connector_state->best_encoder); |
| 10947 | |
Daniel Vetter | efea6e8 | 2013-07-21 21:36:59 +0200 | [diff] [blame] | 10948 | if (!(encoder->compute_config(encoder, pipe_config))) { |
| 10949 | DRM_DEBUG_KMS("Encoder config failure\n"); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10950 | goto fail; |
| 10951 | } |
| 10952 | } |
| 10953 | |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10954 | /* Set default port clock if not overwritten by the encoder. Needs to be |
| 10955 | * done afterwards in case the encoder adjusts the mode. */ |
| 10956 | if (!pipe_config->port_clock) |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 10957 | pipe_config->port_clock = pipe_config->base.adjusted_mode.crtc_clock |
Damien Lespiau | 241bfc3 | 2013-09-25 16:45:37 +0100 | [diff] [blame] | 10958 | * pipe_config->pixel_multiplier; |
Daniel Vetter | ff9a675 | 2013-06-01 17:16:21 +0200 | [diff] [blame] | 10959 | |
Daniel Vetter | a43f6e0 | 2013-06-07 23:10:32 +0200 | [diff] [blame] | 10960 | ret = intel_crtc_compute_config(to_intel_crtc(crtc), pipe_config); |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10961 | if (ret < 0) { |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10962 | DRM_DEBUG_KMS("CRTC fixup failed\n"); |
| 10963 | goto fail; |
| 10964 | } |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10965 | |
| 10966 | if (ret == RETRY) { |
| 10967 | if (WARN(!retry, "loop in pipe configuration computation\n")) { |
| 10968 | ret = -EINVAL; |
| 10969 | goto fail; |
| 10970 | } |
| 10971 | |
| 10972 | DRM_DEBUG_KMS("CRTC bw constrained, retrying\n"); |
| 10973 | retry = false; |
| 10974 | goto encoder_retry; |
| 10975 | } |
| 10976 | |
Daniel Vetter | 4e53c2e | 2013-03-27 00:44:58 +0100 | [diff] [blame] | 10977 | pipe_config->dither = pipe_config->pipe_bpp != plane_bpp; |
| 10978 | DRM_DEBUG_KMS("plane bpp: %i, pipe bpp: %i, dithering: %i\n", |
| 10979 | plane_bpp, pipe_config->pipe_bpp, pipe_config->dither); |
| 10980 | |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 10981 | return pipe_config; |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10982 | fail: |
Daniel Vetter | e29c22c | 2013-02-21 00:00:16 +0100 | [diff] [blame] | 10983 | return ERR_PTR(ret); |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 10984 | } |
| 10985 | |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 10986 | /* Computes which crtcs are affected and sets the relevant bits in the mask. For |
| 10987 | * simplicity we use the crtc's pipe number (because it's easier to obtain). */ |
| 10988 | static void |
| 10989 | intel_modeset_affected_pipes(struct drm_crtc *crtc, unsigned *modeset_pipes, |
| 10990 | unsigned *prepare_pipes, unsigned *disable_pipes) |
| 10991 | { |
| 10992 | struct intel_crtc *intel_crtc; |
| 10993 | struct drm_device *dev = crtc->dev; |
| 10994 | struct intel_encoder *encoder; |
| 10995 | struct intel_connector *connector; |
| 10996 | struct drm_crtc *tmp_crtc; |
| 10997 | |
| 10998 | *disable_pipes = *modeset_pipes = *prepare_pipes = 0; |
| 10999 | |
| 11000 | /* Check which crtcs have changed outputs connected to them, these need |
| 11001 | * to be part of the prepare_pipes mask. We don't (yet) support global |
| 11002 | * modeset across multiple crtcs, so modeset_pipes will only have one |
| 11003 | * bit set at most. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11004 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 11005 | if (connector->base.encoder == &connector->new_encoder->base) |
| 11006 | continue; |
| 11007 | |
| 11008 | if (connector->base.encoder) { |
| 11009 | tmp_crtc = connector->base.encoder->crtc; |
| 11010 | |
| 11011 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 11012 | } |
| 11013 | |
| 11014 | if (connector->new_encoder) |
| 11015 | *prepare_pipes |= |
| 11016 | 1 << connector->new_encoder->new_crtc->pipe; |
| 11017 | } |
| 11018 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11019 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 11020 | if (encoder->base.crtc == &encoder->new_crtc->base) |
| 11021 | continue; |
| 11022 | |
| 11023 | if (encoder->base.crtc) { |
| 11024 | tmp_crtc = encoder->base.crtc; |
| 11025 | |
| 11026 | *prepare_pipes |= 1 << to_intel_crtc(tmp_crtc)->pipe; |
| 11027 | } |
| 11028 | |
| 11029 | if (encoder->new_crtc) |
| 11030 | *prepare_pipes |= 1 << encoder->new_crtc->pipe; |
| 11031 | } |
| 11032 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11033 | /* Check for pipes that will be enabled/disabled ... */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11034 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11035 | if (intel_crtc->base.state->enable == intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 11036 | continue; |
| 11037 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11038 | if (!intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 11039 | *disable_pipes |= 1 << intel_crtc->pipe; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11040 | else |
| 11041 | *prepare_pipes |= 1 << intel_crtc->pipe; |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 11042 | } |
| 11043 | |
| 11044 | |
| 11045 | /* set_mode is also used to update properties on life display pipes. */ |
| 11046 | intel_crtc = to_intel_crtc(crtc); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11047 | if (intel_crtc->new_enabled) |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 11048 | *prepare_pipes |= 1 << intel_crtc->pipe; |
| 11049 | |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 11050 | /* |
| 11051 | * For simplicity do a full modeset on any pipe where the output routing |
| 11052 | * changed. We could be more clever, but that would require us to be |
| 11053 | * more careful with calling the relevant encoder->mode_set functions. |
| 11054 | */ |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 11055 | if (*prepare_pipes) |
| 11056 | *modeset_pipes = *prepare_pipes; |
| 11057 | |
| 11058 | /* ... and mask these out. */ |
| 11059 | *modeset_pipes &= ~(*disable_pipes); |
| 11060 | *prepare_pipes &= ~(*disable_pipes); |
Daniel Vetter | b6c5164 | 2013-04-12 18:48:43 +0200 | [diff] [blame] | 11061 | |
| 11062 | /* |
| 11063 | * HACK: We don't (yet) fully support global modesets. intel_set_config |
| 11064 | * obies this rule, but the modeset restore mode of |
| 11065 | * intel_modeset_setup_hw_state does not. |
| 11066 | */ |
| 11067 | *modeset_pipes &= 1 << intel_crtc->pipe; |
| 11068 | *prepare_pipes &= 1 << intel_crtc->pipe; |
Daniel Vetter | e3641d3 | 2013-04-11 19:49:07 +0200 | [diff] [blame] | 11069 | |
| 11070 | DRM_DEBUG_KMS("set mode pipe masks: modeset: %x, prepare: %x, disable: %x\n", |
| 11071 | *modeset_pipes, *prepare_pipes, *disable_pipes); |
Daniel Vetter | e2e1ed4 | 2012-07-08 21:14:38 +0200 | [diff] [blame] | 11072 | } |
| 11073 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11074 | static bool intel_crtc_in_use(struct drm_crtc *crtc) |
| 11075 | { |
| 11076 | struct drm_encoder *encoder; |
| 11077 | struct drm_device *dev = crtc->dev; |
| 11078 | |
| 11079 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) |
| 11080 | if (encoder->crtc == crtc) |
| 11081 | return true; |
| 11082 | |
| 11083 | return false; |
| 11084 | } |
| 11085 | |
| 11086 | static void |
| 11087 | intel_modeset_update_state(struct drm_device *dev, unsigned prepare_pipes) |
| 11088 | { |
Daniel Vetter | ba41c0de | 2014-11-03 15:04:55 +0100 | [diff] [blame] | 11089 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11090 | struct intel_encoder *intel_encoder; |
| 11091 | struct intel_crtc *intel_crtc; |
| 11092 | struct drm_connector *connector; |
| 11093 | |
Daniel Vetter | ba41c0de | 2014-11-03 15:04:55 +0100 | [diff] [blame] | 11094 | intel_shared_dpll_commit(dev_priv); |
| 11095 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11096 | for_each_intel_encoder(dev, intel_encoder) { |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11097 | if (!intel_encoder->base.crtc) |
| 11098 | continue; |
| 11099 | |
| 11100 | intel_crtc = to_intel_crtc(intel_encoder->base.crtc); |
| 11101 | |
| 11102 | if (prepare_pipes & (1 << intel_crtc->pipe)) |
| 11103 | intel_encoder->connectors_active = false; |
| 11104 | } |
| 11105 | |
| 11106 | intel_modeset_commit_output_state(dev); |
| 11107 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11108 | /* Double check state. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11109 | for_each_intel_crtc(dev, intel_crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11110 | WARN_ON(intel_crtc->base.state->enable != intel_crtc_in_use(&intel_crtc->base)); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11111 | } |
| 11112 | |
| 11113 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
| 11114 | if (!connector->encoder || !connector->encoder->crtc) |
| 11115 | continue; |
| 11116 | |
| 11117 | intel_crtc = to_intel_crtc(connector->encoder->crtc); |
| 11118 | |
| 11119 | if (prepare_pipes & (1 << intel_crtc->pipe)) { |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 11120 | struct drm_property *dpms_property = |
| 11121 | dev->mode_config.dpms_property; |
| 11122 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11123 | connector->dpms = DRM_MODE_DPMS_ON; |
Rob Clark | 662595d | 2012-10-11 20:36:04 -0500 | [diff] [blame] | 11124 | drm_object_property_set_value(&connector->base, |
Daniel Vetter | 68d3472 | 2012-09-06 22:08:35 +0200 | [diff] [blame] | 11125 | dpms_property, |
| 11126 | DRM_MODE_DPMS_ON); |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11127 | |
| 11128 | intel_encoder = to_intel_encoder(connector->encoder); |
| 11129 | intel_encoder->connectors_active = true; |
| 11130 | } |
| 11131 | } |
| 11132 | |
| 11133 | } |
| 11134 | |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11135 | static bool intel_fuzzy_clock_check(int clock1, int clock2) |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11136 | { |
Ville Syrjälä | 3bd2626 | 2013-09-06 23:29:02 +0300 | [diff] [blame] | 11137 | int diff; |
Jesse Barnes | f1f644d | 2013-06-27 00:39:25 +0300 | [diff] [blame] | 11138 | |
| 11139 | if (clock1 == clock2) |
| 11140 | return true; |
| 11141 | |
| 11142 | if (!clock1 || !clock2) |
| 11143 | return false; |
| 11144 | |
| 11145 | diff = abs(clock1 - clock2); |
| 11146 | |
| 11147 | if (((((diff + clock1 + clock2) * 100)) / (clock1 + clock2)) < 105) |
| 11148 | return true; |
| 11149 | |
| 11150 | return false; |
| 11151 | } |
| 11152 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11153 | #define for_each_intel_crtc_masked(dev, mask, intel_crtc) \ |
| 11154 | list_for_each_entry((intel_crtc), \ |
| 11155 | &(dev)->mode_config.crtc_list, \ |
| 11156 | base.head) \ |
Daniel Vetter | 0973f18 | 2013-04-19 11:25:33 +0200 | [diff] [blame] | 11157 | if (mask & (1 <<(intel_crtc)->pipe)) |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11158 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11159 | static bool |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11160 | intel_pipe_config_compare(struct drm_device *dev, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11161 | struct intel_crtc_state *current_config, |
| 11162 | struct intel_crtc_state *pipe_config) |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11163 | { |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11164 | #define PIPE_CONF_CHECK_X(name) \ |
| 11165 | if (current_config->name != pipe_config->name) { \ |
| 11166 | DRM_ERROR("mismatch in " #name " " \ |
| 11167 | "(expected 0x%08x, found 0x%08x)\n", \ |
| 11168 | current_config->name, \ |
| 11169 | pipe_config->name); \ |
| 11170 | return false; \ |
| 11171 | } |
| 11172 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11173 | #define PIPE_CONF_CHECK_I(name) \ |
| 11174 | if (current_config->name != pipe_config->name) { \ |
| 11175 | DRM_ERROR("mismatch in " #name " " \ |
| 11176 | "(expected %i, found %i)\n", \ |
| 11177 | current_config->name, \ |
| 11178 | pipe_config->name); \ |
| 11179 | return false; \ |
Daniel Vetter | 88adfff | 2013-03-28 10:42:01 +0100 | [diff] [blame] | 11180 | } |
| 11181 | |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11182 | /* This is required for BDW+ where there is only one set of registers for |
| 11183 | * switching between high and low RR. |
| 11184 | * This macro can be used whenever a comparison has to be made between one |
| 11185 | * hw state and multiple sw state variables. |
| 11186 | */ |
| 11187 | #define PIPE_CONF_CHECK_I_ALT(name, alt_name) \ |
| 11188 | if ((current_config->name != pipe_config->name) && \ |
| 11189 | (current_config->alt_name != pipe_config->name)) { \ |
| 11190 | DRM_ERROR("mismatch in " #name " " \ |
| 11191 | "(expected %i or %i, found %i)\n", \ |
| 11192 | current_config->name, \ |
| 11193 | current_config->alt_name, \ |
| 11194 | pipe_config->name); \ |
| 11195 | return false; \ |
| 11196 | } |
| 11197 | |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11198 | #define PIPE_CONF_CHECK_FLAGS(name, mask) \ |
| 11199 | if ((current_config->name ^ pipe_config->name) & (mask)) { \ |
Jesse Barnes | 6f02488 | 2013-07-01 10:19:09 -0700 | [diff] [blame] | 11200 | DRM_ERROR("mismatch in " #name "(" #mask ") " \ |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11201 | "(expected %i, found %i)\n", \ |
| 11202 | current_config->name & (mask), \ |
| 11203 | pipe_config->name & (mask)); \ |
| 11204 | return false; \ |
| 11205 | } |
| 11206 | |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11207 | #define PIPE_CONF_CHECK_CLOCK_FUZZY(name) \ |
| 11208 | if (!intel_fuzzy_clock_check(current_config->name, pipe_config->name)) { \ |
| 11209 | DRM_ERROR("mismatch in " #name " " \ |
| 11210 | "(expected %i, found %i)\n", \ |
| 11211 | current_config->name, \ |
| 11212 | pipe_config->name); \ |
| 11213 | return false; \ |
| 11214 | } |
| 11215 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11216 | #define PIPE_CONF_QUIRK(quirk) \ |
| 11217 | ((current_config->quirks | pipe_config->quirks) & (quirk)) |
| 11218 | |
Daniel Vetter | eccb140 | 2013-05-22 00:50:22 +0200 | [diff] [blame] | 11219 | PIPE_CONF_CHECK_I(cpu_transcoder); |
| 11220 | |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11221 | PIPE_CONF_CHECK_I(has_pch_encoder); |
| 11222 | PIPE_CONF_CHECK_I(fdi_lanes); |
Daniel Vetter | 7241920 | 2013-04-04 13:28:53 +0200 | [diff] [blame] | 11223 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_m); |
| 11224 | PIPE_CONF_CHECK_I(fdi_m_n.gmch_n); |
| 11225 | PIPE_CONF_CHECK_I(fdi_m_n.link_m); |
| 11226 | PIPE_CONF_CHECK_I(fdi_m_n.link_n); |
| 11227 | PIPE_CONF_CHECK_I(fdi_m_n.tu); |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11228 | |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 11229 | PIPE_CONF_CHECK_I(has_dp_encoder); |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11230 | |
| 11231 | if (INTEL_INFO(dev)->gen < 8) { |
| 11232 | PIPE_CONF_CHECK_I(dp_m_n.gmch_m); |
| 11233 | PIPE_CONF_CHECK_I(dp_m_n.gmch_n); |
| 11234 | PIPE_CONF_CHECK_I(dp_m_n.link_m); |
| 11235 | PIPE_CONF_CHECK_I(dp_m_n.link_n); |
| 11236 | PIPE_CONF_CHECK_I(dp_m_n.tu); |
| 11237 | |
| 11238 | if (current_config->has_drrs) { |
| 11239 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_m); |
| 11240 | PIPE_CONF_CHECK_I(dp_m2_n2.gmch_n); |
| 11241 | PIPE_CONF_CHECK_I(dp_m2_n2.link_m); |
| 11242 | PIPE_CONF_CHECK_I(dp_m2_n2.link_n); |
| 11243 | PIPE_CONF_CHECK_I(dp_m2_n2.tu); |
| 11244 | } |
| 11245 | } else { |
| 11246 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_m, dp_m2_n2.gmch_m); |
| 11247 | PIPE_CONF_CHECK_I_ALT(dp_m_n.gmch_n, dp_m2_n2.gmch_n); |
| 11248 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_m, dp_m2_n2.link_m); |
| 11249 | PIPE_CONF_CHECK_I_ALT(dp_m_n.link_n, dp_m2_n2.link_n); |
| 11250 | PIPE_CONF_CHECK_I_ALT(dp_m_n.tu, dp_m2_n2.tu); |
| 11251 | } |
Ville Syrjälä | eb14cb7 | 2013-09-10 17:02:54 +0300 | [diff] [blame] | 11252 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11253 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hdisplay); |
| 11254 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_htotal); |
| 11255 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_start); |
| 11256 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hblank_end); |
| 11257 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_start); |
| 11258 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_hsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11259 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11260 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vdisplay); |
| 11261 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vtotal); |
| 11262 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_start); |
| 11263 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vblank_end); |
| 11264 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_start); |
| 11265 | PIPE_CONF_CHECK_I(base.adjusted_mode.crtc_vsync_end); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11266 | |
Daniel Vetter | c93f54c | 2013-06-27 19:47:19 +0200 | [diff] [blame] | 11267 | PIPE_CONF_CHECK_I(pixel_multiplier); |
Daniel Vetter | 6897b4b | 2014-04-24 23:54:47 +0200 | [diff] [blame] | 11268 | PIPE_CONF_CHECK_I(has_hdmi_sink); |
Daniel Vetter | b5a9fa0 | 2014-04-24 23:54:49 +0200 | [diff] [blame] | 11269 | if ((INTEL_INFO(dev)->gen < 8 && !IS_HASWELL(dev)) || |
| 11270 | IS_VALLEYVIEW(dev)) |
| 11271 | PIPE_CONF_CHECK_I(limited_color_range); |
Jesse Barnes | e43823e | 2014-11-05 14:26:08 -0800 | [diff] [blame] | 11272 | PIPE_CONF_CHECK_I(has_infoframe); |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11273 | |
Daniel Vetter | 9ed109a | 2014-04-24 23:54:52 +0200 | [diff] [blame] | 11274 | PIPE_CONF_CHECK_I(has_audio); |
| 11275 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11276 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11277 | DRM_MODE_FLAG_INTERLACE); |
| 11278 | |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11279 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_MODE_SYNC_FLAGS)) { |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11280 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11281 | DRM_MODE_FLAG_PHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11282 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11283 | DRM_MODE_FLAG_NHSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11284 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11285 | DRM_MODE_FLAG_PVSYNC); |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11286 | PIPE_CONF_CHECK_FLAGS(base.adjusted_mode.flags, |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11287 | DRM_MODE_FLAG_NVSYNC); |
| 11288 | } |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11289 | |
Ville Syrjälä | 37327ab | 2013-09-04 18:25:28 +0300 | [diff] [blame] | 11290 | PIPE_CONF_CHECK_I(pipe_src_w); |
| 11291 | PIPE_CONF_CHECK_I(pipe_src_h); |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11292 | |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 11293 | /* |
| 11294 | * FIXME: BIOS likes to set up a cloned config with lvds+external |
| 11295 | * screen. Since we don't yet re-compute the pipe config when moving |
| 11296 | * just the lvds port away to another pipe the sw tracking won't match. |
| 11297 | * |
| 11298 | * Proper atomic modesets with recomputed global state will fix this. |
| 11299 | * Until then just don't check gmch state for inherited modes. |
| 11300 | */ |
| 11301 | if (!PIPE_CONF_QUIRK(PIPE_CONFIG_QUIRK_INHERITED_MODE)) { |
| 11302 | PIPE_CONF_CHECK_I(gmch_pfit.control); |
| 11303 | /* pfit ratios are autocomputed by the hw on gen4+ */ |
| 11304 | if (INTEL_INFO(dev)->gen < 4) |
| 11305 | PIPE_CONF_CHECK_I(gmch_pfit.pgm_ratios); |
| 11306 | PIPE_CONF_CHECK_I(gmch_pfit.lvds_border_bits); |
| 11307 | } |
| 11308 | |
Chris Wilson | fd4daa9 | 2013-08-27 17:04:17 +0100 | [diff] [blame] | 11309 | PIPE_CONF_CHECK_I(pch_pfit.enabled); |
| 11310 | if (current_config->pch_pfit.enabled) { |
| 11311 | PIPE_CONF_CHECK_I(pch_pfit.pos); |
| 11312 | PIPE_CONF_CHECK_I(pch_pfit.size); |
| 11313 | } |
Daniel Vetter | 2fa2fe9 | 2013-05-07 23:34:16 +0200 | [diff] [blame] | 11314 | |
Jesse Barnes | e59150d | 2014-01-07 13:30:45 -0800 | [diff] [blame] | 11315 | /* BDW+ don't expose a synchronous way to read the state */ |
| 11316 | if (IS_HASWELL(dev)) |
| 11317 | PIPE_CONF_CHECK_I(ips_enabled); |
Paulo Zanoni | 42db64e | 2013-05-31 16:33:22 -0300 | [diff] [blame] | 11318 | |
Ville Syrjälä | 282740f | 2013-09-04 18:30:03 +0300 | [diff] [blame] | 11319 | PIPE_CONF_CHECK_I(double_wide); |
| 11320 | |
Daniel Vetter | 26804af | 2014-06-25 22:01:55 +0300 | [diff] [blame] | 11321 | PIPE_CONF_CHECK_X(ddi_pll_sel); |
| 11322 | |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11323 | PIPE_CONF_CHECK_I(shared_dpll); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11324 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll); |
Daniel Vetter | 8bcc279 | 2013-06-05 13:34:28 +0200 | [diff] [blame] | 11325 | PIPE_CONF_CHECK_X(dpll_hw_state.dpll_md); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11326 | PIPE_CONF_CHECK_X(dpll_hw_state.fp0); |
| 11327 | PIPE_CONF_CHECK_X(dpll_hw_state.fp1); |
Daniel Vetter | d452c5b | 2014-07-04 11:27:39 -0300 | [diff] [blame] | 11328 | PIPE_CONF_CHECK_X(dpll_hw_state.wrpll); |
Damien Lespiau | 3f4cd19 | 2014-11-13 14:55:21 +0000 | [diff] [blame] | 11329 | PIPE_CONF_CHECK_X(dpll_hw_state.ctrl1); |
| 11330 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr1); |
| 11331 | PIPE_CONF_CHECK_X(dpll_hw_state.cfgcr2); |
Daniel Vetter | c0d43d6 | 2013-06-07 23:11:08 +0200 | [diff] [blame] | 11332 | |
Ville Syrjälä | 42571ae | 2013-09-06 23:29:00 +0300 | [diff] [blame] | 11333 | if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) |
| 11334 | PIPE_CONF_CHECK_I(pipe_bpp); |
| 11335 | |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11336 | PIPE_CONF_CHECK_CLOCK_FUZZY(base.adjusted_mode.crtc_clock); |
Jesse Barnes | a9a7e98 | 2014-01-20 14:18:04 -0800 | [diff] [blame] | 11337 | PIPE_CONF_CHECK_CLOCK_FUZZY(port_clock); |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11338 | |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11339 | #undef PIPE_CONF_CHECK_X |
Daniel Vetter | 08a2403 | 2013-04-19 11:25:34 +0200 | [diff] [blame] | 11340 | #undef PIPE_CONF_CHECK_I |
Vandana Kannan | b95af8b | 2014-08-05 07:51:23 -0700 | [diff] [blame] | 11341 | #undef PIPE_CONF_CHECK_I_ALT |
Daniel Vetter | 1bd1bd8 | 2013-04-29 21:56:12 +0200 | [diff] [blame] | 11342 | #undef PIPE_CONF_CHECK_FLAGS |
Ville Syrjälä | 5e55065 | 2013-09-06 23:29:07 +0300 | [diff] [blame] | 11343 | #undef PIPE_CONF_CHECK_CLOCK_FUZZY |
Daniel Vetter | bb76006 | 2013-06-06 14:55:52 +0200 | [diff] [blame] | 11344 | #undef PIPE_CONF_QUIRK |
Daniel Vetter | 627eb5a | 2013-04-29 19:33:42 +0200 | [diff] [blame] | 11345 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11346 | return true; |
| 11347 | } |
| 11348 | |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11349 | static void check_wm_state(struct drm_device *dev) |
| 11350 | { |
| 11351 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 11352 | struct skl_ddb_allocation hw_ddb, *sw_ddb; |
| 11353 | struct intel_crtc *intel_crtc; |
| 11354 | int plane; |
| 11355 | |
| 11356 | if (INTEL_INFO(dev)->gen < 9) |
| 11357 | return; |
| 11358 | |
| 11359 | skl_ddb_get_hw_state(dev_priv, &hw_ddb); |
| 11360 | sw_ddb = &dev_priv->wm.skl_hw.ddb; |
| 11361 | |
| 11362 | for_each_intel_crtc(dev, intel_crtc) { |
| 11363 | struct skl_ddb_entry *hw_entry, *sw_entry; |
| 11364 | const enum pipe pipe = intel_crtc->pipe; |
| 11365 | |
| 11366 | if (!intel_crtc->active) |
| 11367 | continue; |
| 11368 | |
| 11369 | /* planes */ |
Damien Lespiau | dd74078 | 2015-02-28 14:54:08 +0000 | [diff] [blame] | 11370 | for_each_plane(dev_priv, pipe, plane) { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11371 | hw_entry = &hw_ddb.plane[pipe][plane]; |
| 11372 | sw_entry = &sw_ddb->plane[pipe][plane]; |
| 11373 | |
| 11374 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 11375 | continue; |
| 11376 | |
| 11377 | DRM_ERROR("mismatch in DDB state pipe %c plane %d " |
| 11378 | "(expected (%u,%u), found (%u,%u))\n", |
| 11379 | pipe_name(pipe), plane + 1, |
| 11380 | sw_entry->start, sw_entry->end, |
| 11381 | hw_entry->start, hw_entry->end); |
| 11382 | } |
| 11383 | |
| 11384 | /* cursor */ |
| 11385 | hw_entry = &hw_ddb.cursor[pipe]; |
| 11386 | sw_entry = &sw_ddb->cursor[pipe]; |
| 11387 | |
| 11388 | if (skl_ddb_entry_equal(hw_entry, sw_entry)) |
| 11389 | continue; |
| 11390 | |
| 11391 | DRM_ERROR("mismatch in DDB state pipe %c cursor " |
| 11392 | "(expected (%u,%u), found (%u,%u))\n", |
| 11393 | pipe_name(pipe), |
| 11394 | sw_entry->start, sw_entry->end, |
| 11395 | hw_entry->start, hw_entry->end); |
| 11396 | } |
| 11397 | } |
| 11398 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11399 | static void |
| 11400 | check_connector_state(struct drm_device *dev) |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11401 | { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11402 | struct intel_connector *connector; |
| 11403 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11404 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11405 | /* This also checks the encoder/connector hw state with the |
| 11406 | * ->get_hw_state callbacks. */ |
| 11407 | intel_connector_check_state(connector); |
| 11408 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11409 | I915_STATE_WARN(&connector->new_encoder->base != connector->base.encoder, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11410 | "connector's staged encoder doesn't match current encoder\n"); |
| 11411 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11412 | } |
| 11413 | |
| 11414 | static void |
| 11415 | check_encoder_state(struct drm_device *dev) |
| 11416 | { |
| 11417 | struct intel_encoder *encoder; |
| 11418 | struct intel_connector *connector; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11419 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11420 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11421 | bool enabled = false; |
| 11422 | bool active = false; |
| 11423 | enum pipe pipe, tracked_pipe; |
| 11424 | |
| 11425 | DRM_DEBUG_KMS("[ENCODER:%d:%s]\n", |
| 11426 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 11427 | encoder->base.name); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11428 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11429 | I915_STATE_WARN(&encoder->new_crtc->base != encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11430 | "encoder's stage crtc doesn't match current crtc\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11431 | I915_STATE_WARN(encoder->connectors_active && !encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11432 | "encoder's active_connectors set, but no crtc\n"); |
| 11433 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 11434 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11435 | if (connector->base.encoder != &encoder->base) |
| 11436 | continue; |
| 11437 | enabled = true; |
| 11438 | if (connector->base.dpms != DRM_MODE_DPMS_OFF) |
| 11439 | active = true; |
| 11440 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 11441 | /* |
| 11442 | * for MST connectors if we unplug the connector is gone |
| 11443 | * away but the encoder is still connected to a crtc |
| 11444 | * until a modeset happens in response to the hotplug. |
| 11445 | */ |
| 11446 | if (!enabled && encoder->base.encoder_type == DRM_MODE_ENCODER_DPMST) |
| 11447 | continue; |
| 11448 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11449 | I915_STATE_WARN(!!encoder->base.crtc != enabled, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11450 | "encoder's enabled state mismatch " |
| 11451 | "(expected %i, found %i)\n", |
| 11452 | !!encoder->base.crtc, enabled); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11453 | I915_STATE_WARN(active && !encoder->base.crtc, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11454 | "active encoder with no crtc\n"); |
| 11455 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11456 | I915_STATE_WARN(encoder->connectors_active != active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11457 | "encoder's computed active state doesn't match tracked active state " |
| 11458 | "(expected %i, found %i)\n", active, encoder->connectors_active); |
| 11459 | |
| 11460 | active = encoder->get_hw_state(encoder, &pipe); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11461 | I915_STATE_WARN(active != encoder->connectors_active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11462 | "encoder's hw state doesn't match sw tracking " |
| 11463 | "(expected %i, found %i)\n", |
| 11464 | encoder->connectors_active, active); |
| 11465 | |
| 11466 | if (!encoder->base.crtc) |
| 11467 | continue; |
| 11468 | |
| 11469 | tracked_pipe = to_intel_crtc(encoder->base.crtc)->pipe; |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11470 | I915_STATE_WARN(active && pipe != tracked_pipe, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11471 | "active encoder's pipe doesn't match" |
| 11472 | "(expected %i, found %i)\n", |
| 11473 | tracked_pipe, pipe); |
| 11474 | |
| 11475 | } |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11476 | } |
| 11477 | |
| 11478 | static void |
| 11479 | check_crtc_state(struct drm_device *dev) |
| 11480 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11481 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11482 | struct intel_crtc *crtc; |
| 11483 | struct intel_encoder *encoder; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11484 | struct intel_crtc_state pipe_config; |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11485 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11486 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11487 | bool enabled = false; |
| 11488 | bool active = false; |
| 11489 | |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 11490 | memset(&pipe_config, 0, sizeof(pipe_config)); |
| 11491 | |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11492 | DRM_DEBUG_KMS("[CRTC:%d]\n", |
| 11493 | crtc->base.base.id); |
| 11494 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11495 | I915_STATE_WARN(crtc->active && !crtc->base.state->enable, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11496 | "active crtc, but not enabled in sw tracking\n"); |
| 11497 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11498 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11499 | if (encoder->base.crtc != &crtc->base) |
| 11500 | continue; |
| 11501 | enabled = true; |
| 11502 | if (encoder->connectors_active) |
| 11503 | active = true; |
| 11504 | } |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11505 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11506 | I915_STATE_WARN(active != crtc->active, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11507 | "crtc's computed active state doesn't match tracked active state " |
| 11508 | "(expected %i, found %i)\n", active, crtc->active); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11509 | I915_STATE_WARN(enabled != crtc->base.state->enable, |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11510 | "crtc's computed enabled state doesn't match tracked enabled state " |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11511 | "(expected %i, found %i)\n", enabled, |
| 11512 | crtc->base.state->enable); |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11513 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11514 | active = dev_priv->display.get_pipe_config(crtc, |
| 11515 | &pipe_config); |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 11516 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 11517 | /* hw state is inconsistent with the pipe quirk */ |
| 11518 | if ((crtc->pipe == PIPE_A && dev_priv->quirks & QUIRK_PIPEA_FORCE) || |
| 11519 | (crtc->pipe == PIPE_B && dev_priv->quirks & QUIRK_PIPEB_FORCE)) |
Daniel Vetter | d62cf62 | 2013-05-29 10:41:29 +0200 | [diff] [blame] | 11520 | active = crtc->active; |
| 11521 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 11522 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 3eaba51 | 2013-08-05 17:57:48 +0300 | [diff] [blame] | 11523 | enum pipe pipe; |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11524 | if (encoder->base.crtc != &crtc->base) |
| 11525 | continue; |
Daniel Vetter | 1d37b68 | 2013-11-18 09:00:59 +0100 | [diff] [blame] | 11526 | if (encoder->get_hw_state(encoder, &pipe)) |
Daniel Vetter | 6c49f24 | 2013-06-06 12:45:25 +0200 | [diff] [blame] | 11527 | encoder->get_config(encoder, &pipe_config); |
| 11528 | } |
| 11529 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11530 | I915_STATE_WARN(crtc->active != active, |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 11531 | "crtc active state doesn't match with hw state " |
| 11532 | "(expected %i, found %i)\n", crtc->active, active); |
| 11533 | |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11534 | if (active && |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11535 | !intel_pipe_config_compare(dev, crtc->config, &pipe_config)) { |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11536 | I915_STATE_WARN(1, "pipe state doesn't match!\n"); |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11537 | intel_dump_pipe_config(crtc, &pipe_config, |
| 11538 | "[hw state]"); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11539 | intel_dump_pipe_config(crtc, crtc->config, |
Daniel Vetter | c0b0341 | 2013-05-28 12:05:54 +0200 | [diff] [blame] | 11540 | "[sw state]"); |
| 11541 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 11542 | } |
| 11543 | } |
| 11544 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11545 | static void |
| 11546 | check_shared_dpll_state(struct drm_device *dev) |
| 11547 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11548 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11549 | struct intel_crtc *crtc; |
| 11550 | struct intel_dpll_hw_state dpll_hw_state; |
| 11551 | int i; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11552 | |
| 11553 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 11554 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 11555 | int enabled_crtcs = 0, active_crtcs = 0; |
| 11556 | bool active; |
| 11557 | |
| 11558 | memset(&dpll_hw_state, 0, sizeof(dpll_hw_state)); |
| 11559 | |
| 11560 | DRM_DEBUG_KMS("%s\n", pll->name); |
| 11561 | |
| 11562 | active = pll->get_hw_state(dev_priv, pll, &dpll_hw_state); |
| 11563 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11564 | I915_STATE_WARN(pll->active > hweight32(pll->config.crtc_mask), |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11565 | "more active pll users than references: %i vs %i\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 11566 | pll->active, hweight32(pll->config.crtc_mask)); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11567 | I915_STATE_WARN(pll->active && !pll->on, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11568 | "pll in active use but not on in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11569 | I915_STATE_WARN(pll->on && !pll->active, |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 11570 | "pll in on but not on in use in sw tracking\n"); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11571 | I915_STATE_WARN(pll->on != active, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11572 | "pll on state mismatch (expected %i, found %i)\n", |
| 11573 | pll->on, active); |
| 11574 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 11575 | for_each_intel_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11576 | if (crtc->base.state->enable && intel_crtc_to_shared_dpll(crtc) == pll) |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11577 | enabled_crtcs++; |
| 11578 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) |
| 11579 | active_crtcs++; |
| 11580 | } |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11581 | I915_STATE_WARN(pll->active != active_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11582 | "pll active crtcs mismatch (expected %i, found %i)\n", |
| 11583 | pll->active, active_crtcs); |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11584 | I915_STATE_WARN(hweight32(pll->config.crtc_mask) != enabled_crtcs, |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11585 | "pll enabled crtcs mismatch (expected %i, found %i)\n", |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 11586 | hweight32(pll->config.crtc_mask), enabled_crtcs); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 11587 | |
Rob Clark | e2c719b | 2014-12-15 13:56:32 -0500 | [diff] [blame] | 11588 | 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] | 11589 | sizeof(dpll_hw_state)), |
| 11590 | "pll hw state mismatch\n"); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 11591 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11592 | } |
| 11593 | |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11594 | void |
| 11595 | intel_modeset_check_state(struct drm_device *dev) |
| 11596 | { |
Damien Lespiau | 08db665 | 2014-11-04 17:06:52 +0000 | [diff] [blame] | 11597 | check_wm_state(dev); |
Daniel Vetter | 91d1b4b | 2013-06-05 13:34:18 +0200 | [diff] [blame] | 11598 | check_connector_state(dev); |
| 11599 | check_encoder_state(dev); |
| 11600 | check_crtc_state(dev); |
| 11601 | check_shared_dpll_state(dev); |
| 11602 | } |
| 11603 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11604 | 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] | 11605 | int dotclock) |
| 11606 | { |
| 11607 | /* |
| 11608 | * FDI already provided one idea for the dotclock. |
| 11609 | * Yell if the encoder disagrees. |
| 11610 | */ |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11611 | 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] | 11612 | "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] | 11613 | pipe_config->base.adjusted_mode.crtc_clock, dotclock); |
Ville Syrjälä | 18442d0 | 2013-09-13 16:00:08 +0300 | [diff] [blame] | 11614 | } |
| 11615 | |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11616 | static void update_scanline_offset(struct intel_crtc *crtc) |
| 11617 | { |
| 11618 | struct drm_device *dev = crtc->base.dev; |
| 11619 | |
| 11620 | /* |
| 11621 | * The scanline counter increments at the leading edge of hsync. |
| 11622 | * |
| 11623 | * On most platforms it starts counting from vtotal-1 on the |
| 11624 | * first active line. That means the scanline counter value is |
| 11625 | * always one less than what we would expect. Ie. just after |
| 11626 | * start of vblank, which also occurs at start of hsync (on the |
| 11627 | * last active line), the scanline counter will read vblank_start-1. |
| 11628 | * |
| 11629 | * On gen2 the scanline counter starts counting from 1 instead |
| 11630 | * of vtotal-1, so we have to subtract one (or rather add vtotal-1 |
| 11631 | * to keep the value positive), instead of adding one. |
| 11632 | * |
| 11633 | * On HSW+ the behaviour of the scanline counter depends on the output |
| 11634 | * type. For DP ports it behaves like most other platforms, but on HDMI |
| 11635 | * there's an extra 1 line difference. So we need to add two instead of |
| 11636 | * one to the value. |
| 11637 | */ |
| 11638 | if (IS_GEN2(dev)) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 11639 | const struct drm_display_mode *mode = &crtc->config->base.adjusted_mode; |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11640 | int vtotal; |
| 11641 | |
| 11642 | vtotal = mode->crtc_vtotal; |
| 11643 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 11644 | vtotal /= 2; |
| 11645 | |
| 11646 | crtc->scanline_offset = vtotal - 1; |
| 11647 | } else if (HAS_DDI(dev) && |
Ander Conselvan de Oliveira | 409ee76 | 2014-10-20 13:46:45 +0300 | [diff] [blame] | 11648 | intel_pipe_has_type(crtc, INTEL_OUTPUT_HDMI)) { |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11649 | crtc->scanline_offset = 2; |
| 11650 | } else |
| 11651 | crtc->scanline_offset = 1; |
| 11652 | } |
| 11653 | |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11654 | static struct intel_crtc_state * |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11655 | intel_modeset_compute_config(struct drm_crtc *crtc, |
| 11656 | struct drm_display_mode *mode, |
| 11657 | struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11658 | struct drm_atomic_state *state, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11659 | unsigned *modeset_pipes, |
| 11660 | unsigned *prepare_pipes, |
| 11661 | unsigned *disable_pipes) |
| 11662 | { |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11663 | struct drm_device *dev = crtc->dev; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11664 | struct intel_crtc_state *pipe_config = NULL; |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11665 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | 0b90187 | 2015-03-20 16:18:08 +0200 | [diff] [blame] | 11666 | int ret = 0; |
| 11667 | |
| 11668 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 11669 | if (ret) |
| 11670 | return ERR_PTR(ret); |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11671 | |
| 11672 | intel_modeset_affected_pipes(crtc, modeset_pipes, |
| 11673 | prepare_pipes, disable_pipes); |
| 11674 | |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11675 | for_each_intel_crtc_masked(dev, *disable_pipes, intel_crtc) { |
| 11676 | pipe_config = intel_atomic_get_crtc_state(state, intel_crtc); |
| 11677 | if (IS_ERR(pipe_config)) |
| 11678 | return pipe_config; |
| 11679 | |
| 11680 | pipe_config->base.enable = false; |
| 11681 | } |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11682 | |
| 11683 | /* |
| 11684 | * Note this needs changes when we start tracking multiple modes |
| 11685 | * and crtcs. At that point we'll need to compute the whole config |
| 11686 | * (i.e. one pipe_config for each crtc) rather than just the one |
| 11687 | * for this crtc. |
| 11688 | */ |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11689 | for_each_intel_crtc_masked(dev, *modeset_pipes, intel_crtc) { |
| 11690 | /* FIXME: For now we still expect modeset_pipes has at most |
| 11691 | * one bit set. */ |
| 11692 | if (WARN_ON(&intel_crtc->base != crtc)) |
| 11693 | continue; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11694 | |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11695 | pipe_config = intel_modeset_pipe_config(crtc, fb, mode, state); |
| 11696 | if (IS_ERR(pipe_config)) |
| 11697 | return pipe_config; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11698 | |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 11699 | pipe_config->base.enable = true; |
| 11700 | |
Ander Conselvan de Oliveira | db7542d | 2015-03-20 16:18:04 +0200 | [diff] [blame] | 11701 | intel_dump_pipe_config(to_intel_crtc(crtc), pipe_config, |
| 11702 | "[modeset]"); |
| 11703 | } |
| 11704 | |
| 11705 | return intel_atomic_get_crtc_state(state, to_intel_crtc(crtc));; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11706 | } |
| 11707 | |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 11708 | static int __intel_set_mode_setup_plls(struct drm_atomic_state *state, |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11709 | unsigned modeset_pipes, |
| 11710 | unsigned disable_pipes) |
| 11711 | { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 11712 | struct drm_device *dev = state->dev; |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11713 | struct drm_i915_private *dev_priv = to_i915(dev); |
| 11714 | unsigned clear_pipes = modeset_pipes | disable_pipes; |
| 11715 | struct intel_crtc *intel_crtc; |
| 11716 | int ret = 0; |
| 11717 | |
| 11718 | if (!dev_priv->display.crtc_compute_clock) |
| 11719 | return 0; |
| 11720 | |
| 11721 | ret = intel_shared_dpll_start_config(dev_priv, clear_pipes); |
| 11722 | if (ret) |
| 11723 | goto done; |
| 11724 | |
| 11725 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 11726 | struct intel_crtc_state *crtc_state = |
| 11727 | intel_atomic_get_crtc_state(state, intel_crtc); |
| 11728 | |
| 11729 | /* Modeset pipes should have a new state by now */ |
| 11730 | if (WARN_ON(IS_ERR(crtc_state))) |
| 11731 | continue; |
| 11732 | |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11733 | ret = dev_priv->display.crtc_compute_clock(intel_crtc, |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 11734 | crtc_state); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11735 | if (ret) { |
| 11736 | intel_shared_dpll_abort_config(dev_priv); |
| 11737 | goto done; |
| 11738 | } |
| 11739 | } |
| 11740 | |
| 11741 | done: |
| 11742 | return ret; |
| 11743 | } |
| 11744 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11745 | static int __intel_set_mode(struct drm_crtc *crtc, |
| 11746 | struct drm_display_mode *mode, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11747 | int x, int y, struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11748 | struct intel_crtc_state *pipe_config, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11749 | unsigned modeset_pipes, |
| 11750 | unsigned prepare_pipes, |
| 11751 | unsigned disable_pipes) |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11752 | { |
| 11753 | struct drm_device *dev = crtc->dev; |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 11754 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11755 | struct drm_display_mode *saved_mode; |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 11756 | struct drm_atomic_state *state = pipe_config->base.state; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11757 | struct intel_crtc_state *crtc_state_copy = NULL; |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11758 | struct intel_crtc *intel_crtc; |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11759 | int ret = 0; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11760 | |
Ville Syrjälä | 4b4b923 | 2013-10-26 17:59:30 +0300 | [diff] [blame] | 11761 | saved_mode = kmalloc(sizeof(*saved_mode), GFP_KERNEL); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11762 | if (!saved_mode) |
| 11763 | return -ENOMEM; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11764 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11765 | crtc_state_copy = kmalloc(sizeof(*crtc_state_copy), GFP_KERNEL); |
| 11766 | if (!crtc_state_copy) { |
| 11767 | ret = -ENOMEM; |
| 11768 | goto done; |
| 11769 | } |
| 11770 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11771 | *saved_mode = crtc->mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11772 | |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 11773 | /* |
| 11774 | * See if the config requires any additional preparation, e.g. |
| 11775 | * to adjust global state with pipes off. We need to do this |
| 11776 | * here so we can get the modeset_pipe updated config for the new |
| 11777 | * mode set on this crtc. For other crtcs we need to use the |
| 11778 | * adjusted_mode bits in the crtc directly. |
| 11779 | */ |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 11780 | if (IS_VALLEYVIEW(dev)) { |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 11781 | ret = valleyview_modeset_global_pipes(state, &prepare_pipes); |
| 11782 | if (ret) |
| 11783 | goto done; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 11784 | |
Ville Syrjälä | c164f83 | 2013-11-05 22:34:12 +0200 | [diff] [blame] | 11785 | /* may have added more to prepare_pipes than we should */ |
| 11786 | prepare_pipes &= ~disable_pipes; |
| 11787 | } |
| 11788 | |
Ander Conselvan de Oliveira | 225da59 | 2015-04-02 14:47:57 +0300 | [diff] [blame] | 11789 | ret = __intel_set_mode_setup_plls(state, modeset_pipes, disable_pipes); |
Ander Conselvan de Oliveira | ed6739e | 2015-01-29 16:55:08 +0200 | [diff] [blame] | 11790 | if (ret) |
| 11791 | goto done; |
Ander Conselvan de Oliveira | 8bd31e6 | 2014-10-29 11:32:33 +0200 | [diff] [blame] | 11792 | |
Daniel Vetter | 460da916 | 2013-03-27 00:44:51 +0100 | [diff] [blame] | 11793 | for_each_intel_crtc_masked(dev, disable_pipes, intel_crtc) |
| 11794 | intel_crtc_disable(&intel_crtc->base); |
| 11795 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11796 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11797 | if (intel_crtc->base.state->enable) |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11798 | dev_priv->display.crtc_disable(&intel_crtc->base); |
| 11799 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11800 | |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 11801 | /* crtc->mode is already used by the ->mode_set callbacks, hence we need |
| 11802 | * 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] | 11803 | * |
| 11804 | * Note we'll need to fix this up when we start tracking multiple |
| 11805 | * pipes; here we assume a single modeset_pipe and only track the |
| 11806 | * single crtc and mode. |
Daniel Vetter | 6c4c86f | 2012-09-10 21:58:30 +0200 | [diff] [blame] | 11807 | */ |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11808 | if (modeset_pipes) { |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11809 | crtc->mode = *mode; |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11810 | /* mode_set/enable/disable functions rely on a correct pipe |
| 11811 | * config. */ |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 11812 | intel_crtc_set_state(to_intel_crtc(crtc), pipe_config); |
Ville Syrjälä | c326c0a | 2013-10-28 12:53:41 +0200 | [diff] [blame] | 11813 | |
| 11814 | /* |
| 11815 | * Calculate and store various constants which |
| 11816 | * are later needed by vblank and swap-completion |
| 11817 | * timestamping. They are derived from true hwmode. |
| 11818 | */ |
| 11819 | drm_calc_timestamping_constants(crtc, |
Ander Conselvan de Oliveira | 2d112de | 2015-01-15 14:55:22 +0200 | [diff] [blame] | 11820 | &pipe_config->base.adjusted_mode); |
Daniel Vetter | b8cecdf | 2013-03-27 00:44:50 +0100 | [diff] [blame] | 11821 | } |
Daniel Vetter | 7758a11 | 2012-07-08 19:40:39 +0200 | [diff] [blame] | 11822 | |
Daniel Vetter | ea9d758 | 2012-07-10 10:42:52 +0200 | [diff] [blame] | 11823 | /* Only after disabling all output pipelines that will be changed can we |
| 11824 | * update the the output configuration. */ |
| 11825 | intel_modeset_update_state(dev, prepare_pipes); |
| 11826 | |
Ander Conselvan de Oliveira | 304603f | 2015-04-02 14:47:56 +0300 | [diff] [blame] | 11827 | modeset_update_crtc_power_domains(state); |
Daniel Vetter | 47fab73 | 2012-10-26 10:58:18 +0200 | [diff] [blame] | 11828 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11829 | for_each_intel_crtc_masked(dev, modeset_pipes, intel_crtc) { |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11830 | struct drm_plane *primary = intel_crtc->base.primary; |
| 11831 | int vdisplay, hdisplay; |
Daniel Vetter | 4c10794 | 2014-04-24 23:55:05 +0200 | [diff] [blame] | 11832 | |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 11833 | drm_crtc_get_hv_timing(mode, &hdisplay, &vdisplay); |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 11834 | ret = drm_plane_helper_update(primary, &intel_crtc->base, |
| 11835 | fb, 0, 0, |
| 11836 | hdisplay, vdisplay, |
| 11837 | x << 16, y << 16, |
| 11838 | hdisplay << 16, vdisplay << 16); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11839 | } |
| 11840 | |
| 11841 | /* 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] | 11842 | for_each_intel_crtc_masked(dev, prepare_pipes, intel_crtc) { |
| 11843 | update_scanline_offset(intel_crtc); |
| 11844 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11845 | dev_priv->display.crtc_enable(&intel_crtc->base); |
Ville Syrjälä | 80715b2 | 2014-05-15 20:23:23 +0300 | [diff] [blame] | 11846 | } |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11847 | |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11848 | /* FIXME: add subpixel order */ |
| 11849 | done: |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 11850 | if (ret && crtc->state->enable) |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11851 | crtc->mode = *saved_mode; |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11852 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11853 | if (ret == 0 && pipe_config) { |
| 11854 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 11855 | |
| 11856 | /* The pipe_config will be freed with the atomic state, so |
| 11857 | * make a copy. */ |
| 11858 | memcpy(crtc_state_copy, intel_crtc->config, |
| 11859 | sizeof *crtc_state_copy); |
| 11860 | intel_crtc->config = crtc_state_copy; |
| 11861 | intel_crtc->base.state = &crtc_state_copy->base; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11862 | } else { |
| 11863 | kfree(crtc_state_copy); |
| 11864 | } |
| 11865 | |
Tim Gardner | 3ac1823 | 2012-12-07 07:54:26 -0700 | [diff] [blame] | 11866 | kfree(saved_mode); |
Daniel Vetter | a6778b3 | 2012-07-02 09:56:42 +0200 | [diff] [blame] | 11867 | return ret; |
| 11868 | } |
| 11869 | |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11870 | static int intel_set_mode_pipes(struct drm_crtc *crtc, |
| 11871 | struct drm_display_mode *mode, |
| 11872 | int x, int y, struct drm_framebuffer *fb, |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11873 | struct intel_crtc_state *pipe_config, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11874 | unsigned modeset_pipes, |
| 11875 | unsigned prepare_pipes, |
| 11876 | unsigned disable_pipes) |
| 11877 | { |
| 11878 | int ret; |
| 11879 | |
| 11880 | ret = __intel_set_mode(crtc, mode, x, y, fb, pipe_config, modeset_pipes, |
| 11881 | prepare_pipes, disable_pipes); |
| 11882 | |
| 11883 | if (ret == 0) |
| 11884 | intel_modeset_check_state(crtc->dev); |
| 11885 | |
| 11886 | return ret; |
| 11887 | } |
| 11888 | |
Damien Lespiau | e7457a9 | 2013-08-08 22:28:59 +0100 | [diff] [blame] | 11889 | static int intel_set_mode(struct drm_crtc *crtc, |
| 11890 | struct drm_display_mode *mode, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11891 | int x, int y, struct drm_framebuffer *fb, |
| 11892 | struct drm_atomic_state *state) |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11893 | { |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 11894 | struct intel_crtc_state *pipe_config; |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11895 | unsigned modeset_pipes, prepare_pipes, disable_pipes; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11896 | int ret = 0; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11897 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11898 | pipe_config = intel_modeset_compute_config(crtc, mode, fb, state, |
Jesse Barnes | 7f27126e | 2014-11-05 14:26:06 -0800 | [diff] [blame] | 11899 | &modeset_pipes, |
| 11900 | &prepare_pipes, |
| 11901 | &disable_pipes); |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11902 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11903 | if (IS_ERR(pipe_config)) { |
| 11904 | ret = PTR_ERR(pipe_config); |
| 11905 | goto out; |
| 11906 | } |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11907 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11908 | ret = intel_set_mode_pipes(crtc, mode, x, y, fb, pipe_config, |
| 11909 | modeset_pipes, prepare_pipes, |
| 11910 | disable_pipes); |
| 11911 | if (ret) |
| 11912 | goto out; |
| 11913 | |
| 11914 | out: |
| 11915 | return ret; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 11916 | } |
| 11917 | |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11918 | void intel_crtc_restore_mode(struct drm_crtc *crtc) |
| 11919 | { |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 11920 | struct drm_device *dev = crtc->dev; |
| 11921 | struct drm_atomic_state *state; |
| 11922 | struct intel_encoder *encoder; |
| 11923 | struct intel_connector *connector; |
| 11924 | struct drm_connector_state *connector_state; |
| 11925 | |
| 11926 | state = drm_atomic_state_alloc(dev); |
| 11927 | if (!state) { |
| 11928 | DRM_DEBUG_KMS("[CRTC:%d] mode restore failed, out of memory", |
| 11929 | crtc->base.id); |
| 11930 | return; |
| 11931 | } |
| 11932 | |
| 11933 | state->acquire_ctx = dev->mode_config.acquire_ctx; |
| 11934 | |
| 11935 | /* The force restore path in the HW readout code relies on the staged |
| 11936 | * config still keeping the user requested config while the actual |
| 11937 | * state has been overwritten by the configuration read from HW. We |
| 11938 | * need to copy the staged config to the atomic state, otherwise the |
| 11939 | * mode set will just reapply the state the HW is already in. */ |
| 11940 | for_each_intel_encoder(dev, encoder) { |
| 11941 | if (&encoder->new_crtc->base != crtc) |
| 11942 | continue; |
| 11943 | |
| 11944 | for_each_intel_connector(dev, connector) { |
| 11945 | if (connector->new_encoder != encoder) |
| 11946 | continue; |
| 11947 | |
| 11948 | connector_state = drm_atomic_get_connector_state(state, &connector->base); |
| 11949 | if (IS_ERR(connector_state)) { |
| 11950 | DRM_DEBUG_KMS("Failed to add [CONNECTOR:%d:%s] to state: %ld\n", |
| 11951 | connector->base.base.id, |
| 11952 | connector->base.name, |
| 11953 | PTR_ERR(connector_state)); |
| 11954 | continue; |
| 11955 | } |
| 11956 | |
| 11957 | connector_state->crtc = crtc; |
| 11958 | connector_state->best_encoder = &encoder->base; |
| 11959 | } |
| 11960 | } |
| 11961 | |
| 11962 | intel_set_mode(crtc, &crtc->mode, crtc->x, crtc->y, crtc->primary->fb, |
| 11963 | state); |
| 11964 | |
| 11965 | drm_atomic_state_free(state); |
Chris Wilson | c0c36b94 | 2012-12-19 16:08:43 +0000 | [diff] [blame] | 11966 | } |
| 11967 | |
Daniel Vetter | 25c5b26 | 2012-07-08 22:08:04 +0200 | [diff] [blame] | 11968 | #undef for_each_intel_crtc_masked |
| 11969 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11970 | static void intel_set_config_free(struct intel_set_config *config) |
| 11971 | { |
| 11972 | if (!config) |
| 11973 | return; |
| 11974 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11975 | kfree(config->save_connector_encoders); |
| 11976 | kfree(config->save_encoder_crtcs); |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11977 | kfree(config->save_crtc_enabled); |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 11978 | kfree(config); |
| 11979 | } |
| 11980 | |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11981 | static int intel_set_config_save_state(struct drm_device *dev, |
| 11982 | struct intel_set_config *config) |
| 11983 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11984 | struct drm_crtc *crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11985 | struct drm_encoder *encoder; |
| 11986 | struct drm_connector *connector; |
| 11987 | int count; |
| 11988 | |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 11989 | config->save_crtc_enabled = |
| 11990 | kcalloc(dev->mode_config.num_crtc, |
| 11991 | sizeof(bool), GFP_KERNEL); |
| 11992 | if (!config->save_crtc_enabled) |
| 11993 | return -ENOMEM; |
| 11994 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 11995 | config->save_encoder_crtcs = |
| 11996 | kcalloc(dev->mode_config.num_encoder, |
| 11997 | sizeof(struct drm_crtc *), GFP_KERNEL); |
| 11998 | if (!config->save_encoder_crtcs) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 11999 | return -ENOMEM; |
| 12000 | |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 12001 | config->save_connector_encoders = |
| 12002 | kcalloc(dev->mode_config.num_connector, |
| 12003 | sizeof(struct drm_encoder *), GFP_KERNEL); |
| 12004 | if (!config->save_connector_encoders) |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 12005 | return -ENOMEM; |
| 12006 | |
| 12007 | /* Copy data. Note that driver private data is not affected. |
| 12008 | * Should anything bad happen only the expected state is |
| 12009 | * restored, not the drivers personal bookkeeping. |
| 12010 | */ |
| 12011 | count = 0; |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 12012 | for_each_crtc(dev, crtc) { |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 12013 | config->save_crtc_enabled[count++] = crtc->state->enable; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12014 | } |
| 12015 | |
| 12016 | count = 0; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 12017 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 12018 | config->save_encoder_crtcs[count++] = encoder->crtc; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 12019 | } |
| 12020 | |
| 12021 | count = 0; |
| 12022 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Daniel Vetter | 1aa4b62 | 2012-07-05 16:20:48 +0200 | [diff] [blame] | 12023 | config->save_connector_encoders[count++] = connector->encoder; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 12024 | } |
| 12025 | |
| 12026 | return 0; |
| 12027 | } |
| 12028 | |
| 12029 | static void intel_set_config_restore_state(struct drm_device *dev, |
| 12030 | struct intel_set_config *config) |
| 12031 | { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12032 | struct intel_crtc *crtc; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12033 | struct intel_encoder *encoder; |
| 12034 | struct intel_connector *connector; |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 12035 | int count; |
| 12036 | |
| 12037 | count = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12038 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12039 | crtc->new_enabled = config->save_crtc_enabled[count++]; |
| 12040 | } |
| 12041 | |
| 12042 | count = 0; |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12043 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12044 | encoder->new_crtc = |
| 12045 | to_intel_crtc(config->save_encoder_crtcs[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 12046 | } |
| 12047 | |
| 12048 | count = 0; |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12049 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12050 | connector->new_encoder = |
| 12051 | to_intel_encoder(config->save_connector_encoders[count++]); |
Daniel Vetter | 85f9eb7 | 2012-07-04 22:24:08 +0200 | [diff] [blame] | 12052 | } |
| 12053 | } |
| 12054 | |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 12055 | static bool |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 12056 | is_crtc_connector_off(struct drm_mode_set *set) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 12057 | { |
| 12058 | int i; |
| 12059 | |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 12060 | if (set->num_connectors == 0) |
| 12061 | return false; |
| 12062 | |
| 12063 | if (WARN_ON(set->connectors == NULL)) |
| 12064 | return false; |
| 12065 | |
| 12066 | for (i = 0; i < set->num_connectors; i++) |
| 12067 | if (set->connectors[i]->encoder && |
| 12068 | set->connectors[i]->encoder->crtc == set->crtc && |
| 12069 | set->connectors[i]->dpms != DRM_MODE_DPMS_ON) |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 12070 | return true; |
| 12071 | |
| 12072 | return false; |
| 12073 | } |
| 12074 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12075 | static void |
| 12076 | intel_set_config_compute_mode_changes(struct drm_mode_set *set, |
| 12077 | struct intel_set_config *config) |
| 12078 | { |
| 12079 | |
| 12080 | /* We should be able to check here if the fb has the same properties |
| 12081 | * and then just flip_or_move it */ |
Chris Wilson | 2e57f47 | 2013-07-17 12:14:40 +0100 | [diff] [blame] | 12082 | if (is_crtc_connector_off(set)) { |
| 12083 | config->mode_changed = true; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 12084 | } else if (set->crtc->primary->fb != set->fb) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12085 | /* |
| 12086 | * If we have no fb, we can only flip as long as the crtc is |
| 12087 | * active, otherwise we need a full mode set. The crtc may |
| 12088 | * be active if we've only disabled the primary plane, or |
| 12089 | * in fastboot situations. |
| 12090 | */ |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 12091 | if (set->crtc->primary->fb == NULL) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 12092 | struct intel_crtc *intel_crtc = |
| 12093 | to_intel_crtc(set->crtc); |
| 12094 | |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12095 | if (intel_crtc->active) { |
Jesse Barnes | 319d982 | 2013-06-26 01:38:19 +0300 | [diff] [blame] | 12096 | DRM_DEBUG_KMS("crtc has no fb, will flip\n"); |
| 12097 | config->fb_changed = true; |
| 12098 | } else { |
| 12099 | DRM_DEBUG_KMS("inactive crtc, full mode set\n"); |
| 12100 | config->mode_changed = true; |
| 12101 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12102 | } else if (set->fb == NULL) { |
| 12103 | config->mode_changed = true; |
Daniel Vetter | 72f4901 | 2013-03-28 16:01:35 +0100 | [diff] [blame] | 12104 | } else if (set->fb->pixel_format != |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 12105 | set->crtc->primary->fb->pixel_format) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12106 | config->mode_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 12107 | } else { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12108 | config->fb_changed = true; |
Imre Deak | e3de42b | 2013-05-03 19:44:07 +0200 | [diff] [blame] | 12109 | } |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12110 | } |
| 12111 | |
Daniel Vetter | 835c587 | 2012-07-10 18:11:08 +0200 | [diff] [blame] | 12112 | 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] | 12113 | config->fb_changed = true; |
| 12114 | |
| 12115 | if (set->mode && !drm_mode_equal(set->mode, &set->crtc->mode)) { |
| 12116 | DRM_DEBUG_KMS("modes are different, full mode set\n"); |
| 12117 | drm_mode_debug_printmodeline(&set->crtc->mode); |
| 12118 | drm_mode_debug_printmodeline(set->mode); |
| 12119 | config->mode_changed = true; |
| 12120 | } |
Chris Wilson | a1d9570 | 2013-08-13 18:48:47 +0100 | [diff] [blame] | 12121 | |
| 12122 | DRM_DEBUG_KMS("computed changes for [CRTC:%d], mode_changed=%d, fb_changed=%d\n", |
| 12123 | set->crtc->base.id, config->mode_changed, config->fb_changed); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12124 | } |
| 12125 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12126 | static int |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12127 | intel_modeset_stage_output_state(struct drm_device *dev, |
| 12128 | struct drm_mode_set *set, |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12129 | struct intel_set_config *config, |
| 12130 | struct drm_atomic_state *state) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12131 | { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12132 | struct intel_connector *connector; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12133 | struct drm_connector_state *connector_state; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12134 | struct intel_encoder *encoder; |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12135 | struct intel_crtc *crtc; |
Paulo Zanoni | f3f0857 | 2013-08-12 14:56:53 -0300 | [diff] [blame] | 12136 | int ro; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12137 | |
Damien Lespiau | 9abdda7 | 2013-02-13 13:29:23 +0000 | [diff] [blame] | 12138 | /* 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] | 12139 | * of connectors. For paranoia, double-check this. */ |
| 12140 | WARN_ON(!set->fb && (set->num_connectors != 0)); |
| 12141 | WARN_ON(set->fb && (set->num_connectors == 0)); |
| 12142 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12143 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12144 | /* Otherwise traverse passed in connector list and get encoders |
| 12145 | * for them. */ |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12146 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12147 | if (set->connectors[ro] == &connector->base) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12148 | 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] | 12149 | break; |
| 12150 | } |
| 12151 | } |
| 12152 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12153 | /* If we disable the crtc, disable all its connectors. Also, if |
| 12154 | * the connector is on the changing crtc but not on the new |
| 12155 | * connector list, disable it. */ |
| 12156 | if ((!set->fb || ro == set->num_connectors) && |
| 12157 | connector->base.encoder && |
| 12158 | connector->base.encoder->crtc == set->crtc) { |
| 12159 | connector->new_encoder = NULL; |
| 12160 | |
| 12161 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [NOCRTC]\n", |
| 12162 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 12163 | connector->base.name); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12164 | } |
| 12165 | |
| 12166 | |
| 12167 | if (&connector->new_encoder->base != connector->base.encoder) { |
Ander Conselvan de Oliveira | 1063418 | 2015-03-03 15:21:57 +0200 | [diff] [blame] | 12168 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] encoder changed, full mode switch\n", |
| 12169 | connector->base.base.id, |
| 12170 | connector->base.name); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12171 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12172 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12173 | } |
| 12174 | /* connector->new_encoder is now updated for all connectors. */ |
| 12175 | |
| 12176 | /* Update crtc of enabled connectors. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12177 | for_each_intel_connector(dev, connector) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12178 | struct drm_crtc *new_crtc; |
| 12179 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12180 | if (!connector->new_encoder) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12181 | continue; |
| 12182 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12183 | new_crtc = connector->new_encoder->base.crtc; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12184 | |
| 12185 | for (ro = 0; ro < set->num_connectors; ro++) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12186 | if (set->connectors[ro] == &connector->base) |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12187 | new_crtc = set->crtc; |
| 12188 | } |
| 12189 | |
| 12190 | /* Make sure the new CRTC will work with the encoder */ |
Thierry Reding | 1450991 | 2014-01-13 12:00:22 +0100 | [diff] [blame] | 12191 | if (!drm_encoder_crtc_ok(&connector->new_encoder->base, |
| 12192 | new_crtc)) { |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12193 | return -EINVAL; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12194 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12195 | connector->new_encoder->new_crtc = to_intel_crtc(new_crtc); |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12196 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12197 | connector_state = |
| 12198 | drm_atomic_get_connector_state(state, &connector->base); |
| 12199 | if (IS_ERR(connector_state)) |
| 12200 | return PTR_ERR(connector_state); |
| 12201 | |
| 12202 | connector_state->crtc = new_crtc; |
| 12203 | connector_state->best_encoder = &connector->new_encoder->base; |
| 12204 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12205 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] to [CRTC:%d]\n", |
| 12206 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 12207 | connector->base.name, |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12208 | new_crtc->base.id); |
| 12209 | } |
| 12210 | |
| 12211 | /* Check for any encoders that needs to be disabled. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12212 | for_each_intel_encoder(dev, encoder) { |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 12213 | int num_connectors = 0; |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12214 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12215 | if (connector->new_encoder == encoder) { |
| 12216 | WARN_ON(!connector->new_encoder->new_crtc); |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 12217 | num_connectors++; |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12218 | } |
| 12219 | } |
Paulo Zanoni | 5a65f35 | 2014-01-07 14:55:53 -0200 | [diff] [blame] | 12220 | |
| 12221 | if (num_connectors == 0) |
| 12222 | encoder->new_crtc = NULL; |
| 12223 | else if (num_connectors > 1) |
| 12224 | return -EINVAL; |
| 12225 | |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12226 | /* Only now check for crtc changes so we don't miss encoders |
| 12227 | * that will be disabled. */ |
| 12228 | if (&encoder->new_crtc->base != encoder->base.crtc) { |
Ander Conselvan de Oliveira | 1063418 | 2015-03-03 15:21:57 +0200 | [diff] [blame] | 12229 | DRM_DEBUG_KMS("[ENCODER:%d:%s] crtc changed, full mode switch\n", |
| 12230 | encoder->base.base.id, |
| 12231 | encoder->base.name); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12232 | config->mode_changed = true; |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12233 | } |
| 12234 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 12235 | /* 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] | 12236 | for_each_intel_connector(dev, connector) { |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12237 | connector_state = |
| 12238 | drm_atomic_get_connector_state(state, &connector->base); |
Ander Conselvan de Oliveira | 9d918c1 | 2015-03-27 15:33:51 +0200 | [diff] [blame] | 12239 | if (IS_ERR(connector_state)) |
| 12240 | return PTR_ERR(connector_state); |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12241 | |
| 12242 | if (connector->new_encoder) { |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12243 | if (connector->new_encoder != connector->encoder) |
| 12244 | connector->encoder = connector->new_encoder; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12245 | } else { |
| 12246 | connector_state->crtc = NULL; |
Ander Conselvan de Oliveira | f61cccf | 2015-03-31 11:35:00 +0300 | [diff] [blame] | 12247 | connector_state->best_encoder = NULL; |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12248 | } |
Dave Airlie | 0e32b39 | 2014-05-02 14:02:48 +1000 | [diff] [blame] | 12249 | } |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12250 | for_each_intel_crtc(dev, crtc) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12251 | crtc->new_enabled = false; |
| 12252 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12253 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12254 | if (encoder->new_crtc == crtc) { |
| 12255 | crtc->new_enabled = true; |
| 12256 | break; |
| 12257 | } |
| 12258 | } |
| 12259 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 12260 | if (crtc->new_enabled != crtc->base.state->enable) { |
Ander Conselvan de Oliveira | 1063418 | 2015-03-03 15:21:57 +0200 | [diff] [blame] | 12261 | DRM_DEBUG_KMS("[CRTC:%d] %sabled, full mode switch\n", |
| 12262 | crtc->base.base.id, |
Ville Syrjälä | 7668851 | 2014-01-10 11:28:06 +0200 | [diff] [blame] | 12263 | crtc->new_enabled ? "en" : "dis"); |
| 12264 | config->mode_changed = true; |
| 12265 | } |
| 12266 | } |
| 12267 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12268 | return 0; |
| 12269 | } |
| 12270 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 12271 | static void disable_crtc_nofb(struct intel_crtc *crtc) |
| 12272 | { |
| 12273 | struct drm_device *dev = crtc->base.dev; |
| 12274 | struct intel_encoder *encoder; |
| 12275 | struct intel_connector *connector; |
| 12276 | |
| 12277 | DRM_DEBUG_KMS("Trying to restore without FB -> disabling pipe %c\n", |
| 12278 | pipe_name(crtc->pipe)); |
| 12279 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 12280 | for_each_intel_connector(dev, connector) { |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 12281 | if (connector->new_encoder && |
| 12282 | connector->new_encoder->new_crtc == crtc) |
| 12283 | connector->new_encoder = NULL; |
| 12284 | } |
| 12285 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 12286 | for_each_intel_encoder(dev, encoder) { |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 12287 | if (encoder->new_crtc == crtc) |
| 12288 | encoder->new_crtc = NULL; |
| 12289 | } |
| 12290 | |
| 12291 | crtc->new_enabled = false; |
| 12292 | } |
| 12293 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12294 | static int intel_crtc_set_config(struct drm_mode_set *set) |
| 12295 | { |
| 12296 | struct drm_device *dev; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12297 | struct drm_mode_set save_set; |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12298 | struct drm_atomic_state *state = NULL; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12299 | struct intel_set_config *config; |
Ander Conselvan de Oliveira | 5cec258 | 2015-01-15 14:55:21 +0200 | [diff] [blame] | 12300 | struct intel_crtc_state *pipe_config; |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12301 | unsigned modeset_pipes, prepare_pipes, disable_pipes; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12302 | int ret; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12303 | |
Daniel Vetter | 8d3e375 | 2012-07-05 16:09:09 +0200 | [diff] [blame] | 12304 | BUG_ON(!set); |
| 12305 | BUG_ON(!set->crtc); |
| 12306 | BUG_ON(!set->crtc->helper_private); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12307 | |
Daniel Vetter | 7e53f3a | 2013-01-21 10:52:17 +0100 | [diff] [blame] | 12308 | /* Enforce sane interface api - has been abused by the fb helper. */ |
| 12309 | BUG_ON(!set->mode && set->fb); |
| 12310 | BUG_ON(set->fb && set->num_connectors == 0); |
Daniel Vetter | 431e50f | 2012-07-10 17:53:42 +0200 | [diff] [blame] | 12311 | |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12312 | if (set->fb) { |
| 12313 | DRM_DEBUG_KMS("[CRTC:%d] [FB:%d] #connectors=%d (x y) (%i %i)\n", |
| 12314 | set->crtc->base.id, set->fb->base.id, |
| 12315 | (int)set->num_connectors, set->x, set->y); |
| 12316 | } else { |
| 12317 | DRM_DEBUG_KMS("[CRTC:%d] [NOFB]\n", set->crtc->base.id); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12318 | } |
| 12319 | |
| 12320 | dev = set->crtc->dev; |
| 12321 | |
| 12322 | ret = -ENOMEM; |
| 12323 | config = kzalloc(sizeof(*config), GFP_KERNEL); |
| 12324 | if (!config) |
| 12325 | goto out_config; |
| 12326 | |
| 12327 | ret = intel_set_config_save_state(dev, config); |
| 12328 | if (ret) |
| 12329 | goto out_config; |
| 12330 | |
| 12331 | save_set.crtc = set->crtc; |
| 12332 | save_set.mode = &set->crtc->mode; |
| 12333 | save_set.x = set->crtc->x; |
| 12334 | save_set.y = set->crtc->y; |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 12335 | save_set.fb = set->crtc->primary->fb; |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12336 | |
| 12337 | /* Compute whether we need a full modeset, only an fb base update or no |
| 12338 | * change at all. In the future we might also check whether only the |
| 12339 | * mode changed, e.g. for LVDS where we only change the panel fitter in |
| 12340 | * such cases. */ |
| 12341 | intel_set_config_compute_mode_changes(set, config); |
| 12342 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12343 | state = drm_atomic_state_alloc(dev); |
| 12344 | if (!state) { |
| 12345 | ret = -ENOMEM; |
| 12346 | goto out_config; |
| 12347 | } |
| 12348 | |
| 12349 | state->acquire_ctx = dev->mode_config.acquire_ctx; |
| 12350 | |
Ander Conselvan de Oliveira | 944b0c7 | 2015-03-20 16:18:07 +0200 | [diff] [blame] | 12351 | ret = intel_modeset_stage_output_state(dev, set, config, state); |
Daniel Vetter | 2e43105 | 2012-07-04 22:42:15 +0200 | [diff] [blame] | 12352 | if (ret) |
| 12353 | goto fail; |
| 12354 | |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12355 | pipe_config = intel_modeset_compute_config(set->crtc, set->mode, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12356 | set->fb, state, |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12357 | &modeset_pipes, |
| 12358 | &prepare_pipes, |
| 12359 | &disable_pipes); |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12360 | if (IS_ERR(pipe_config)) { |
Matt Roper | 6ac0483 | 2014-11-17 09:59:28 -0800 | [diff] [blame] | 12361 | ret = PTR_ERR(pipe_config); |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12362 | goto fail; |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12363 | } else if (pipe_config) { |
Ville Syrjälä | b9950a1 | 2014-11-21 21:00:36 +0200 | [diff] [blame] | 12364 | if (pipe_config->has_audio != |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 12365 | to_intel_crtc(set->crtc)->config->has_audio) |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12366 | config->mode_changed = true; |
| 12367 | |
Jesse Barnes | af15d2c | 2014-12-01 09:54:28 -0800 | [diff] [blame] | 12368 | /* |
| 12369 | * Note we have an issue here with infoframes: current code |
| 12370 | * only updates them on the full mode set path per hw |
| 12371 | * requirements. So here we should be checking for any |
| 12372 | * required changes and forcing a mode set. |
| 12373 | */ |
Jesse Barnes | 2066459 | 2014-11-05 14:26:09 -0800 | [diff] [blame] | 12374 | } |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12375 | |
Jesse Barnes | 1f9954d | 2014-11-05 14:26:10 -0800 | [diff] [blame] | 12376 | intel_update_pipe_size(to_intel_crtc(set->crtc)); |
| 12377 | |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12378 | if (config->mode_changed) { |
Jesse Barnes | 50f5275 | 2014-11-07 13:11:00 -0800 | [diff] [blame] | 12379 | ret = intel_set_mode_pipes(set->crtc, set->mode, |
| 12380 | set->x, set->y, set->fb, pipe_config, |
| 12381 | modeset_pipes, prepare_pipes, |
| 12382 | disable_pipes); |
Daniel Vetter | 5e2b584 | 2012-07-04 22:41:29 +0200 | [diff] [blame] | 12383 | } else if (config->fb_changed) { |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12384 | struct intel_crtc *intel_crtc = to_intel_crtc(set->crtc); |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 12385 | struct drm_plane *primary = set->crtc->primary; |
| 12386 | int vdisplay, hdisplay; |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12387 | |
Gustavo Padovan | 455a680 | 2014-12-01 15:40:11 -0800 | [diff] [blame] | 12388 | drm_crtc_get_hv_timing(set->mode, &hdisplay, &vdisplay); |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 12389 | ret = drm_plane_helper_update(primary, set->crtc, set->fb, |
| 12390 | 0, 0, hdisplay, vdisplay, |
| 12391 | set->x << 16, set->y << 16, |
| 12392 | hdisplay << 16, vdisplay << 16); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12393 | |
| 12394 | /* |
| 12395 | * We need to make sure the primary plane is re-enabled if it |
| 12396 | * has previously been turned off. |
| 12397 | */ |
| 12398 | if (!intel_crtc->primary_enabled && ret == 0) { |
| 12399 | WARN_ON(!intel_crtc->active); |
Ville Syrjälä | fdd508a | 2014-08-08 21:51:11 +0300 | [diff] [blame] | 12400 | intel_enable_primary_hw_plane(set->crtc->primary, set->crtc); |
Matt Roper | 3b150f0 | 2014-05-29 08:06:53 -0700 | [diff] [blame] | 12401 | } |
| 12402 | |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 12403 | /* |
| 12404 | * In the fastboot case this may be our only check of the |
| 12405 | * state after boot. It would be better to only do it on |
| 12406 | * the first update, but we don't have a nice way of doing that |
| 12407 | * (and really, set_config isn't used much for high freq page |
| 12408 | * flipping, so increasing its cost here shouldn't be a big |
| 12409 | * deal). |
| 12410 | */ |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 12411 | if (i915.fastboot && ret == 0) |
Jesse Barnes | 7ca51a3 | 2014-01-07 13:50:49 -0800 | [diff] [blame] | 12412 | intel_modeset_check_state(set->crtc->dev); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12413 | } |
| 12414 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12415 | if (ret) { |
Daniel Vetter | bf67dfe | 2013-06-25 11:06:52 +0200 | [diff] [blame] | 12416 | DRM_DEBUG_KMS("failed to set mode on [CRTC:%d], err = %d\n", |
| 12417 | set->crtc->base.id, ret); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12418 | fail: |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12419 | intel_set_config_restore_state(dev, config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12420 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12421 | drm_atomic_state_clear(state); |
| 12422 | |
Ville Syrjälä | 7d00a1f | 2014-01-10 11:28:09 +0200 | [diff] [blame] | 12423 | /* |
| 12424 | * HACK: if the pipe was on, but we didn't have a framebuffer, |
| 12425 | * force the pipe off to avoid oopsing in the modeset code |
| 12426 | * due to fb==NULL. This should only happen during boot since |
| 12427 | * we don't yet reconstruct the FB from the hardware state. |
| 12428 | */ |
| 12429 | if (to_intel_crtc(save_set.crtc)->new_enabled && !save_set.fb) |
| 12430 | disable_crtc_nofb(to_intel_crtc(save_set.crtc)); |
| 12431 | |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12432 | /* Try to restore the config */ |
| 12433 | if (config->mode_changed && |
| 12434 | intel_set_mode(save_set.crtc, save_set.mode, |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12435 | save_set.x, save_set.y, save_set.fb, |
| 12436 | state)) |
Chris Wilson | 2d05eae | 2013-05-03 17:36:25 +0100 | [diff] [blame] | 12437 | DRM_ERROR("failed to restore config after modeset failure\n"); |
| 12438 | } |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12439 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 12440 | out_config: |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 12441 | if (state) |
| 12442 | drm_atomic_state_free(state); |
| 12443 | |
Daniel Vetter | d9e5560 | 2012-07-04 22:16:09 +0200 | [diff] [blame] | 12444 | intel_set_config_free(config); |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12445 | return ret; |
| 12446 | } |
| 12447 | |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12448 | static const struct drm_crtc_funcs intel_crtc_funcs = { |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12449 | .gamma_set = intel_crtc_gamma_set, |
Daniel Vetter | 50f5611 | 2012-07-02 09:35:43 +0200 | [diff] [blame] | 12450 | .set_config = intel_crtc_set_config, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12451 | .destroy = intel_crtc_destroy, |
| 12452 | .page_flip = intel_crtc_page_flip, |
Matt Roper | 1356837 | 2015-01-21 16:35:47 -0800 | [diff] [blame] | 12453 | .atomic_duplicate_state = intel_crtc_duplicate_state, |
| 12454 | .atomic_destroy_state = intel_crtc_destroy_state, |
Chris Wilson | f6e5b16 | 2011-04-12 18:06:51 +0100 | [diff] [blame] | 12455 | }; |
| 12456 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12457 | static bool ibx_pch_dpll_get_hw_state(struct drm_i915_private *dev_priv, |
| 12458 | struct intel_shared_dpll *pll, |
| 12459 | struct intel_dpll_hw_state *hw_state) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12460 | { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12461 | uint32_t val; |
| 12462 | |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 12463 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_PLLS)) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 12464 | return false; |
| 12465 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12466 | val = I915_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | 66e985c | 2013-06-05 13:34:20 +0200 | [diff] [blame] | 12467 | hw_state->dpll = val; |
| 12468 | hw_state->fp0 = I915_READ(PCH_FP0(pll->id)); |
| 12469 | hw_state->fp1 = I915_READ(PCH_FP1(pll->id)); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12470 | |
| 12471 | return val & DPLL_VCO_ENABLE; |
| 12472 | } |
| 12473 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12474 | static void ibx_pch_dpll_mode_set(struct drm_i915_private *dev_priv, |
| 12475 | struct intel_shared_dpll *pll) |
| 12476 | { |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12477 | I915_WRITE(PCH_FP0(pll->id), pll->config.hw_state.fp0); |
| 12478 | I915_WRITE(PCH_FP1(pll->id), pll->config.hw_state.fp1); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12479 | } |
| 12480 | |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12481 | static void ibx_pch_dpll_enable(struct drm_i915_private *dev_priv, |
| 12482 | struct intel_shared_dpll *pll) |
| 12483 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12484 | /* PCH refclock must be enabled first */ |
Paulo Zanoni | 89eff4b | 2014-01-08 11:12:28 -0200 | [diff] [blame] | 12485 | ibx_assert_pch_refclk_enabled(dev_priv); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12486 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12487 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12488 | |
| 12489 | /* Wait for the clocks to stabilize. */ |
| 12490 | POSTING_READ(PCH_DPLL(pll->id)); |
| 12491 | udelay(150); |
| 12492 | |
| 12493 | /* The pixel multiplier can only be updated once the |
| 12494 | * DPLL is enabled and the clocks are stable. |
| 12495 | * |
| 12496 | * So write it again. |
| 12497 | */ |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 12498 | I915_WRITE(PCH_DPLL(pll->id), pll->config.hw_state.dpll); |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12499 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12500 | udelay(200); |
| 12501 | } |
| 12502 | |
| 12503 | static void ibx_pch_dpll_disable(struct drm_i915_private *dev_priv, |
| 12504 | struct intel_shared_dpll *pll) |
| 12505 | { |
| 12506 | struct drm_device *dev = dev_priv->dev; |
| 12507 | struct intel_crtc *crtc; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12508 | |
| 12509 | /* Make sure no transcoder isn't still depending on us. */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 12510 | for_each_intel_crtc(dev, crtc) { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12511 | if (intel_crtc_to_shared_dpll(crtc) == pll) |
| 12512 | assert_pch_transcoder_disabled(dev_priv, crtc->pipe); |
| 12513 | } |
| 12514 | |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12515 | I915_WRITE(PCH_DPLL(pll->id), 0); |
| 12516 | POSTING_READ(PCH_DPLL(pll->id)); |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12517 | udelay(200); |
| 12518 | } |
| 12519 | |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 12520 | static char *ibx_pch_dpll_names[] = { |
| 12521 | "PCH DPLL A", |
| 12522 | "PCH DPLL B", |
| 12523 | }; |
| 12524 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12525 | static void ibx_pch_dpll_init(struct drm_device *dev) |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12526 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12527 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12528 | int i; |
| 12529 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12530 | dev_priv->num_shared_dpll = 2; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12531 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 12532 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
Daniel Vetter | 46edb02 | 2013-06-05 13:34:12 +0200 | [diff] [blame] | 12533 | dev_priv->shared_dplls[i].id = i; |
| 12534 | dev_priv->shared_dplls[i].name = ibx_pch_dpll_names[i]; |
Daniel Vetter | 15bdd4c | 2013-06-05 13:34:23 +0200 | [diff] [blame] | 12535 | dev_priv->shared_dplls[i].mode_set = ibx_pch_dpll_mode_set; |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12536 | dev_priv->shared_dplls[i].enable = ibx_pch_dpll_enable; |
| 12537 | dev_priv->shared_dplls[i].disable = ibx_pch_dpll_disable; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 12538 | dev_priv->shared_dplls[i].get_hw_state = |
| 12539 | ibx_pch_dpll_get_hw_state; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 12540 | } |
| 12541 | } |
| 12542 | |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12543 | static void intel_shared_dpll_init(struct drm_device *dev) |
| 12544 | { |
Daniel Vetter | e7b903d | 2013-06-05 13:34:14 +0200 | [diff] [blame] | 12545 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12546 | |
Daniel Vetter | 9cd8693 | 2014-06-25 22:01:57 +0300 | [diff] [blame] | 12547 | if (HAS_DDI(dev)) |
| 12548 | intel_ddi_pll_init(dev); |
| 12549 | else if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12550 | ibx_pch_dpll_init(dev); |
| 12551 | else |
| 12552 | dev_priv->num_shared_dpll = 0; |
| 12553 | |
| 12554 | BUG_ON(dev_priv->num_shared_dpll > I915_NUM_PLLS); |
Daniel Vetter | 7c74ade | 2013-06-05 13:34:11 +0200 | [diff] [blame] | 12555 | } |
| 12556 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12557 | /** |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 12558 | * intel_wm_need_update - Check whether watermarks need updating |
| 12559 | * @plane: drm plane |
| 12560 | * @state: new plane state |
| 12561 | * |
| 12562 | * Check current plane state versus the new one to determine whether |
| 12563 | * watermarks need to be recalculated. |
| 12564 | * |
| 12565 | * Returns true or false. |
| 12566 | */ |
| 12567 | bool intel_wm_need_update(struct drm_plane *plane, |
| 12568 | struct drm_plane_state *state) |
| 12569 | { |
| 12570 | /* Update watermarks on tiling changes. */ |
| 12571 | if (!plane->state->fb || !state->fb || |
| 12572 | plane->state->fb->modifier[0] != state->fb->modifier[0] || |
| 12573 | plane->state->rotation != state->rotation) |
| 12574 | return true; |
| 12575 | |
| 12576 | return false; |
| 12577 | } |
| 12578 | |
| 12579 | /** |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12580 | * intel_prepare_plane_fb - Prepare fb for usage on plane |
| 12581 | * @plane: drm plane to prepare for |
| 12582 | * @fb: framebuffer to prepare for presentation |
| 12583 | * |
| 12584 | * Prepares a framebuffer for usage on a display plane. Generally this |
| 12585 | * involves pinning the underlying object and updating the frontbuffer tracking |
| 12586 | * bits. Some older platforms need special physical address handling for |
| 12587 | * cursor planes. |
| 12588 | * |
| 12589 | * Returns 0 on success, negative error code on failure. |
| 12590 | */ |
| 12591 | int |
| 12592 | intel_prepare_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 12593 | struct drm_framebuffer *fb, |
| 12594 | const struct drm_plane_state *new_state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12595 | { |
| 12596 | struct drm_device *dev = plane->dev; |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12597 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 12598 | enum pipe pipe = intel_plane->pipe; |
| 12599 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 12600 | struct drm_i915_gem_object *old_obj = intel_fb_obj(plane->fb); |
| 12601 | unsigned frontbuffer_bits = 0; |
| 12602 | int ret = 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12603 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12604 | if (!obj) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12605 | return 0; |
| 12606 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12607 | switch (plane->type) { |
| 12608 | case DRM_PLANE_TYPE_PRIMARY: |
| 12609 | frontbuffer_bits = INTEL_FRONTBUFFER_PRIMARY(pipe); |
| 12610 | break; |
| 12611 | case DRM_PLANE_TYPE_CURSOR: |
| 12612 | frontbuffer_bits = INTEL_FRONTBUFFER_CURSOR(pipe); |
| 12613 | break; |
| 12614 | case DRM_PLANE_TYPE_OVERLAY: |
| 12615 | frontbuffer_bits = INTEL_FRONTBUFFER_SPRITE(pipe); |
| 12616 | break; |
| 12617 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12618 | |
Matt Roper | 4c34574 | 2014-07-09 16:22:10 -0700 | [diff] [blame] | 12619 | mutex_lock(&dev->struct_mutex); |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12620 | |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12621 | if (plane->type == DRM_PLANE_TYPE_CURSOR && |
| 12622 | INTEL_INFO(dev)->cursor_needs_physical) { |
| 12623 | int align = IS_I830(dev) ? 16 * 1024 : 256; |
| 12624 | ret = i915_gem_object_attach_phys(obj, align); |
| 12625 | if (ret) |
| 12626 | DRM_DEBUG_KMS("failed to attach phys object\n"); |
| 12627 | } else { |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 12628 | ret = intel_pin_and_fence_fb_obj(plane, fb, new_state, NULL); |
Matt Roper | 6beb8c23 | 2014-12-01 15:40:14 -0800 | [diff] [blame] | 12629 | } |
| 12630 | |
| 12631 | if (ret == 0) |
| 12632 | i915_gem_track_fb(old_obj, obj, frontbuffer_bits); |
| 12633 | |
| 12634 | mutex_unlock(&dev->struct_mutex); |
| 12635 | |
| 12636 | return ret; |
| 12637 | } |
| 12638 | |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12639 | /** |
| 12640 | * intel_cleanup_plane_fb - Cleans up an fb after plane use |
| 12641 | * @plane: drm plane to clean up for |
| 12642 | * @fb: old framebuffer that was on plane |
| 12643 | * |
| 12644 | * Cleans up a framebuffer that has just been removed from a plane. |
| 12645 | */ |
| 12646 | void |
| 12647 | intel_cleanup_plane_fb(struct drm_plane *plane, |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 12648 | struct drm_framebuffer *fb, |
| 12649 | const struct drm_plane_state *old_state) |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12650 | { |
| 12651 | struct drm_device *dev = plane->dev; |
| 12652 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
| 12653 | |
| 12654 | if (WARN_ON(!obj)) |
| 12655 | return; |
| 12656 | |
| 12657 | if (plane->type != DRM_PLANE_TYPE_CURSOR || |
| 12658 | !INTEL_INFO(dev)->cursor_needs_physical) { |
| 12659 | mutex_lock(&dev->struct_mutex); |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 12660 | intel_unpin_fb_obj(fb, old_state); |
Matt Roper | 38f3ce3 | 2014-12-02 07:45:25 -0800 | [diff] [blame] | 12661 | mutex_unlock(&dev->struct_mutex); |
| 12662 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12663 | } |
| 12664 | |
| 12665 | static int |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12666 | intel_check_primary_plane(struct drm_plane *plane, |
| 12667 | struct intel_plane_state *state) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12668 | { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12669 | struct drm_device *dev = plane->dev; |
| 12670 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12671 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12672 | struct intel_crtc *intel_crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12673 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12674 | struct drm_rect *dest = &state->dst; |
| 12675 | struct drm_rect *src = &state->src; |
| 12676 | const struct drm_rect *clip = &state->clip; |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 12677 | bool can_position = false; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12678 | int ret; |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12679 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12680 | crtc = crtc ? crtc : plane->crtc; |
| 12681 | intel_crtc = to_intel_crtc(crtc); |
| 12682 | |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 12683 | if (INTEL_INFO(dev)->gen >= 9) |
| 12684 | can_position = true; |
| 12685 | |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12686 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
| 12687 | src, dest, clip, |
| 12688 | DRM_PLANE_HELPER_NO_SCALING, |
| 12689 | DRM_PLANE_HELPER_NO_SCALING, |
Sonika Jindal | d810636 | 2015-04-10 14:37:28 +0530 | [diff] [blame] | 12690 | can_position, true, |
| 12691 | &state->visible); |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12692 | if (ret) |
| 12693 | return ret; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12694 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12695 | if (intel_crtc->active) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12696 | intel_crtc->atomic.wait_for_flips = true; |
| 12697 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12698 | /* |
| 12699 | * FBC does not work on some platforms for rotated |
| 12700 | * planes, so disable it when rotation is not 0 and |
| 12701 | * update it when rotation is set back to 0. |
| 12702 | * |
| 12703 | * FIXME: This is redundant with the fbc update done in |
| 12704 | * the primary plane enable function except that that |
| 12705 | * one is done too late. We eventually need to unify |
| 12706 | * this. |
| 12707 | */ |
| 12708 | if (intel_crtc->primary_enabled && |
| 12709 | INTEL_INFO(dev)->gen <= 4 && !IS_G4X(dev) && |
Paulo Zanoni | e35fef2 | 2015-02-09 14:46:29 -0200 | [diff] [blame] | 12710 | dev_priv->fbc.crtc == intel_crtc && |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12711 | state->base.rotation != BIT(DRM_ROTATE_0)) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12712 | intel_crtc->atomic.disable_fbc = true; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12713 | } |
| 12714 | |
| 12715 | if (state->visible) { |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12716 | /* |
| 12717 | * BDW signals flip done immediately if the plane |
| 12718 | * is disabled, even if the plane enable is already |
| 12719 | * armed to occur at the next vblank :( |
| 12720 | */ |
| 12721 | if (IS_BROADWELL(dev) && !intel_crtc->primary_enabled) |
| 12722 | intel_crtc->atomic.wait_vblank = true; |
| 12723 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12724 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12725 | intel_crtc->atomic.fb_bits |= |
| 12726 | INTEL_FRONTBUFFER_PRIMARY(intel_crtc->pipe); |
| 12727 | |
| 12728 | intel_crtc->atomic.update_fbc = true; |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 12729 | |
Tvrtko Ursulin | 1fc0a8f | 2015-03-23 11:10:38 +0000 | [diff] [blame] | 12730 | if (intel_wm_need_update(plane, &state->base)) |
Tvrtko Ursulin | 0fda656 | 2015-02-27 15:12:35 +0000 | [diff] [blame] | 12731 | intel_crtc->atomic.update_wm = true; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12732 | } |
| 12733 | |
| 12734 | return 0; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12735 | } |
| 12736 | |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12737 | static void |
| 12738 | intel_commit_primary_plane(struct drm_plane *plane, |
| 12739 | struct intel_plane_state *state) |
| 12740 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12741 | struct drm_crtc *crtc = state->base.crtc; |
| 12742 | struct drm_framebuffer *fb = state->base.fb; |
| 12743 | struct drm_device *dev = plane->dev; |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12744 | struct drm_i915_private *dev_priv = dev->dev_private; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12745 | struct intel_crtc *intel_crtc; |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 12746 | struct drm_rect *src = &state->src; |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12747 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12748 | crtc = crtc ? crtc : plane->crtc; |
| 12749 | intel_crtc = to_intel_crtc(crtc); |
| 12750 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12751 | plane->fb = fb; |
Sonika Jindal | ce54d85 | 2014-08-21 11:44:39 +0530 | [diff] [blame] | 12752 | crtc->x = src->x1 >> 16; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12753 | crtc->y = src->y1 >> 16; |
| 12754 | |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12755 | if (intel_crtc->active) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12756 | if (state->visible) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12757 | /* FIXME: kill this fastboot hack */ |
| 12758 | intel_update_pipe_size(intel_crtc); |
| 12759 | |
| 12760 | intel_crtc->primary_enabled = true; |
| 12761 | |
| 12762 | dev_priv->display.update_primary_plane(crtc, plane->fb, |
| 12763 | crtc->x, crtc->y); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12764 | } else { |
| 12765 | /* |
| 12766 | * If clipping results in a non-visible primary plane, |
| 12767 | * we'll disable the primary plane. Note that this is |
| 12768 | * a bit different than what happens if userspace |
| 12769 | * explicitly disables the plane by passing fb=0 |
| 12770 | * because plane->fb still gets set and pinned. |
| 12771 | */ |
| 12772 | intel_disable_primary_hw_plane(plane, crtc); |
| 12773 | } |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12774 | } |
| 12775 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12776 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12777 | static void intel_begin_crtc_commit(struct drm_crtc *crtc) |
| 12778 | { |
| 12779 | struct drm_device *dev = crtc->dev; |
| 12780 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12781 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12782 | struct intel_plane *intel_plane; |
| 12783 | struct drm_plane *p; |
| 12784 | unsigned fb_bits = 0; |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12785 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12786 | /* Track fb's for any planes being disabled */ |
| 12787 | list_for_each_entry(p, &dev->mode_config.plane_list, head) { |
| 12788 | intel_plane = to_intel_plane(p); |
| 12789 | |
| 12790 | if (intel_crtc->atomic.disabled_planes & |
| 12791 | (1 << drm_plane_index(p))) { |
| 12792 | switch (p->type) { |
| 12793 | case DRM_PLANE_TYPE_PRIMARY: |
| 12794 | fb_bits = INTEL_FRONTBUFFER_PRIMARY(intel_plane->pipe); |
| 12795 | break; |
| 12796 | case DRM_PLANE_TYPE_CURSOR: |
| 12797 | fb_bits = INTEL_FRONTBUFFER_CURSOR(intel_plane->pipe); |
| 12798 | break; |
| 12799 | case DRM_PLANE_TYPE_OVERLAY: |
| 12800 | fb_bits = INTEL_FRONTBUFFER_SPRITE(intel_plane->pipe); |
| 12801 | break; |
| 12802 | } |
| 12803 | |
| 12804 | mutex_lock(&dev->struct_mutex); |
| 12805 | i915_gem_track_fb(intel_fb_obj(p->fb), NULL, fb_bits); |
| 12806 | mutex_unlock(&dev->struct_mutex); |
| 12807 | } |
| 12808 | } |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12809 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12810 | if (intel_crtc->atomic.wait_for_flips) |
| 12811 | intel_crtc_wait_for_pending_flips(crtc); |
| 12812 | |
| 12813 | if (intel_crtc->atomic.disable_fbc) |
| 12814 | intel_fbc_disable(dev); |
| 12815 | |
| 12816 | if (intel_crtc->atomic.pre_disable_primary) |
| 12817 | intel_pre_disable_primary(crtc); |
| 12818 | |
| 12819 | if (intel_crtc->atomic.update_wm) |
| 12820 | intel_update_watermarks(crtc); |
| 12821 | |
| 12822 | intel_runtime_pm_get(dev_priv); |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 12823 | |
| 12824 | /* Perform vblank evasion around commit operation */ |
| 12825 | if (intel_crtc->active) |
| 12826 | intel_crtc->atomic.evade = |
| 12827 | intel_pipe_update_start(intel_crtc, |
| 12828 | &intel_crtc->atomic.start_vbl_count); |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12829 | } |
| 12830 | |
| 12831 | static void intel_finish_crtc_commit(struct drm_crtc *crtc) |
| 12832 | { |
| 12833 | struct drm_device *dev = crtc->dev; |
| 12834 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 12835 | struct intel_crtc *intel_crtc = to_intel_crtc(crtc); |
| 12836 | struct drm_plane *p; |
| 12837 | |
Matt Roper | c34c9ee | 2014-12-23 10:41:50 -0800 | [diff] [blame] | 12838 | if (intel_crtc->atomic.evade) |
| 12839 | intel_pipe_update_end(intel_crtc, |
| 12840 | intel_crtc->atomic.start_vbl_count); |
| 12841 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12842 | intel_runtime_pm_put(dev_priv); |
| 12843 | |
| 12844 | if (intel_crtc->atomic.wait_vblank) |
| 12845 | intel_wait_for_vblank(dev, intel_crtc->pipe); |
| 12846 | |
| 12847 | intel_frontbuffer_flip(dev, intel_crtc->atomic.fb_bits); |
| 12848 | |
| 12849 | if (intel_crtc->atomic.update_fbc) { |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12850 | mutex_lock(&dev->struct_mutex); |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 12851 | intel_fbc_update(dev); |
Gustavo Padovan | ccc759dc | 2014-09-24 14:20:22 -0300 | [diff] [blame] | 12852 | mutex_unlock(&dev->struct_mutex); |
| 12853 | } |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12854 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12855 | if (intel_crtc->atomic.post_enable_primary) |
| 12856 | intel_post_enable_primary(crtc); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12857 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12858 | drm_for_each_legacy_plane(p, &dev->mode_config.plane_list) |
| 12859 | if (intel_crtc->atomic.update_sprite_watermarks & drm_plane_index(p)) |
| 12860 | intel_update_sprite_watermarks(p, crtc, 0, 0, 0, |
| 12861 | false, false); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12862 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12863 | memset(&intel_crtc->atomic, 0, sizeof(intel_crtc->atomic)); |
Gustavo Padovan | 3c692a4 | 2014-09-05 17:04:49 -0300 | [diff] [blame] | 12864 | } |
| 12865 | |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12866 | /** |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 12867 | * intel_plane_destroy - destroy a plane |
| 12868 | * @plane: plane to destroy |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12869 | * |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 12870 | * Common destruction function for all types of planes (primary, cursor, |
| 12871 | * sprite). |
Matt Roper | cf4c7c1 | 2014-12-04 10:27:42 -0800 | [diff] [blame] | 12872 | */ |
Matt Roper | 4a3b876 | 2014-12-23 10:41:51 -0800 | [diff] [blame] | 12873 | void intel_plane_destroy(struct drm_plane *plane) |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12874 | { |
| 12875 | struct intel_plane *intel_plane = to_intel_plane(plane); |
| 12876 | drm_plane_cleanup(plane); |
| 12877 | kfree(intel_plane); |
| 12878 | } |
| 12879 | |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 12880 | const struct drm_plane_funcs intel_plane_funcs = { |
Matt Roper | 70a101f | 2015-04-08 18:56:53 -0700 | [diff] [blame] | 12881 | .update_plane = drm_atomic_helper_update_plane, |
| 12882 | .disable_plane = drm_atomic_helper_disable_plane, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12883 | .destroy = intel_plane_destroy, |
Matt Roper | c196e1d | 2015-01-21 16:35:48 -0800 | [diff] [blame] | 12884 | .set_property = drm_atomic_helper_plane_set_property, |
Matt Roper | a98b343 | 2015-01-21 16:35:43 -0800 | [diff] [blame] | 12885 | .atomic_get_property = intel_plane_atomic_get_property, |
| 12886 | .atomic_set_property = intel_plane_atomic_set_property, |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12887 | .atomic_duplicate_state = intel_plane_duplicate_state, |
| 12888 | .atomic_destroy_state = intel_plane_destroy_state, |
| 12889 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12890 | }; |
| 12891 | |
| 12892 | static struct drm_plane *intel_primary_plane_create(struct drm_device *dev, |
| 12893 | int pipe) |
| 12894 | { |
| 12895 | struct intel_plane *primary; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12896 | struct intel_plane_state *state; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12897 | const uint32_t *intel_primary_formats; |
| 12898 | int num_formats; |
| 12899 | |
| 12900 | primary = kzalloc(sizeof(*primary), GFP_KERNEL); |
| 12901 | if (primary == NULL) |
| 12902 | return NULL; |
| 12903 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12904 | state = intel_create_plane_state(&primary->base); |
| 12905 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12906 | kfree(primary); |
| 12907 | return NULL; |
| 12908 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 12909 | primary->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12910 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12911 | primary->can_scale = false; |
| 12912 | primary->max_downscale = 1; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 12913 | state->scaler_id = -1; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12914 | primary->pipe = pipe; |
| 12915 | primary->plane = pipe; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 12916 | primary->check_plane = intel_check_primary_plane; |
| 12917 | primary->commit_plane = intel_commit_primary_plane; |
Chandra Konduru | 08e221f | 2015-04-07 15:28:37 -0700 | [diff] [blame] | 12918 | primary->ckey.flags = I915_SET_COLORKEY_NONE; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12919 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) |
| 12920 | primary->plane = !pipe; |
| 12921 | |
| 12922 | if (INTEL_INFO(dev)->gen <= 3) { |
| 12923 | intel_primary_formats = intel_primary_formats_gen2; |
| 12924 | num_formats = ARRAY_SIZE(intel_primary_formats_gen2); |
| 12925 | } else { |
| 12926 | intel_primary_formats = intel_primary_formats_gen4; |
| 12927 | num_formats = ARRAY_SIZE(intel_primary_formats_gen4); |
| 12928 | } |
| 12929 | |
| 12930 | drm_universal_plane_init(dev, &primary->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 12931 | &intel_plane_funcs, |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12932 | intel_primary_formats, num_formats, |
| 12933 | DRM_PLANE_TYPE_PRIMARY); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12934 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 12935 | if (INTEL_INFO(dev)->gen >= 4) |
| 12936 | intel_create_rotation_property(dev, primary); |
Sonika Jindal | 48404c1 | 2014-08-22 14:06:04 +0530 | [diff] [blame] | 12937 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12938 | drm_plane_helper_add(&primary->base, &intel_plane_helper_funcs); |
| 12939 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 12940 | return &primary->base; |
| 12941 | } |
| 12942 | |
Sonika Jindal | 3b7a511 | 2015-04-10 14:37:29 +0530 | [diff] [blame] | 12943 | void intel_create_rotation_property(struct drm_device *dev, struct intel_plane *plane) |
| 12944 | { |
| 12945 | if (!dev->mode_config.rotation_property) { |
| 12946 | unsigned long flags = BIT(DRM_ROTATE_0) | |
| 12947 | BIT(DRM_ROTATE_180); |
| 12948 | |
| 12949 | if (INTEL_INFO(dev)->gen >= 9) |
| 12950 | flags |= BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270); |
| 12951 | |
| 12952 | dev->mode_config.rotation_property = |
| 12953 | drm_mode_create_rotation_property(dev, flags); |
| 12954 | } |
| 12955 | if (dev->mode_config.rotation_property) |
| 12956 | drm_object_attach_property(&plane->base.base, |
| 12957 | dev->mode_config.rotation_property, |
| 12958 | plane->base.state->rotation); |
| 12959 | } |
| 12960 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12961 | static int |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12962 | intel_check_cursor_plane(struct drm_plane *plane, |
| 12963 | struct intel_plane_state *state) |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 12964 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12965 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12966 | struct drm_device *dev = plane->dev; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 12967 | struct drm_framebuffer *fb = state->base.fb; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12968 | struct drm_rect *dest = &state->dst; |
| 12969 | struct drm_rect *src = &state->src; |
| 12970 | const struct drm_rect *clip = &state->clip; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12971 | struct drm_i915_gem_object *obj = intel_fb_obj(fb); |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12972 | struct intel_crtc *intel_crtc; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12973 | unsigned stride; |
| 12974 | int ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12975 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12976 | crtc = crtc ? crtc : plane->crtc; |
| 12977 | intel_crtc = to_intel_crtc(crtc); |
| 12978 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12979 | ret = drm_plane_helper_check_update(plane, crtc, fb, |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 12980 | src, dest, clip, |
| 12981 | DRM_PLANE_HELPER_NO_SCALING, |
| 12982 | DRM_PLANE_HELPER_NO_SCALING, |
| 12983 | true, true, &state->visible); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12984 | if (ret) |
| 12985 | return ret; |
| 12986 | |
| 12987 | |
| 12988 | /* if we want to turn off the cursor ignore width and height */ |
| 12989 | if (!obj) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 12990 | goto finish; |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12991 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12992 | /* Check for which cursor types we support */ |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12993 | if (!cursor_size_ok(dev, state->base.crtc_w, state->base.crtc_h)) { |
| 12994 | DRM_DEBUG("Cursor dimension %dx%d not supported\n", |
| 12995 | state->base.crtc_w, state->base.crtc_h); |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 12996 | return -EINVAL; |
| 12997 | } |
| 12998 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 12999 | stride = roundup_pow_of_two(state->base.crtc_w) * 4; |
| 13000 | if (obj->base.size < stride * state->base.crtc_h) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13001 | DRM_DEBUG_KMS("buffer is too small\n"); |
| 13002 | return -ENOMEM; |
| 13003 | } |
| 13004 | |
Ville Syrjälä | 3a656b5 | 2015-03-09 21:08:37 +0200 | [diff] [blame] | 13005 | if (fb->modifier[0] != DRM_FORMAT_MOD_NONE) { |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13006 | DRM_DEBUG_KMS("cursor cannot be tiled\n"); |
| 13007 | ret = -EINVAL; |
| 13008 | } |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13009 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13010 | finish: |
| 13011 | if (intel_crtc->active) { |
Ville Syrjälä | 3749f46 | 2015-03-10 13:15:22 +0200 | [diff] [blame] | 13012 | if (plane->state->crtc_w != state->base.crtc_w) |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13013 | intel_crtc->atomic.update_wm = true; |
| 13014 | |
| 13015 | intel_crtc->atomic.fb_bits |= |
| 13016 | INTEL_FRONTBUFFER_CURSOR(intel_crtc->pipe); |
| 13017 | } |
| 13018 | |
Gustavo Padovan | 757f9a3 | 2014-09-24 14:20:24 -0300 | [diff] [blame] | 13019 | return ret; |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13020 | } |
| 13021 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13022 | static void |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13023 | intel_commit_cursor_plane(struct drm_plane *plane, |
| 13024 | struct intel_plane_state *state) |
| 13025 | { |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13026 | struct drm_crtc *crtc = state->base.crtc; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13027 | struct drm_device *dev = plane->dev; |
| 13028 | struct intel_crtc *intel_crtc; |
Matt Roper | 2b875c2 | 2014-12-01 15:40:13 -0800 | [diff] [blame] | 13029 | struct drm_i915_gem_object *obj = intel_fb_obj(state->base.fb); |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13030 | uint32_t addr; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13031 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13032 | crtc = crtc ? crtc : plane->crtc; |
| 13033 | intel_crtc = to_intel_crtc(crtc); |
Sonika Jindal | a919db9 | 2014-10-23 07:41:33 -0700 | [diff] [blame] | 13034 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13035 | plane->fb = state->base.fb; |
| 13036 | crtc->cursor_x = state->base.crtc_x; |
| 13037 | crtc->cursor_y = state->base.crtc_y; |
| 13038 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13039 | if (intel_crtc->cursor_bo == obj) |
| 13040 | goto update; |
| 13041 | |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13042 | if (!obj) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13043 | addr = 0; |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13044 | else if (!INTEL_INFO(dev)->cursor_needs_physical) |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13045 | addr = i915_gem_obj_ggtt_offset(obj); |
Matt Roper | f4a2cf2 | 2014-12-01 15:40:12 -0800 | [diff] [blame] | 13046 | else |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13047 | addr = obj->phys_handle->busaddr; |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13048 | |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13049 | intel_crtc->cursor_addr = addr; |
| 13050 | intel_crtc->cursor_bo = obj; |
| 13051 | update: |
Gustavo Padovan | a912f12 | 2014-12-01 15:40:10 -0800 | [diff] [blame] | 13052 | |
Matt Roper | 32b7eee | 2014-12-24 07:59:06 -0800 | [diff] [blame] | 13053 | if (intel_crtc->active) |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13054 | intel_crtc_update_cursor(crtc, state->visible); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13055 | } |
Gustavo Padovan | 852e787 | 2014-09-05 17:22:31 -0300 | [diff] [blame] | 13056 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13057 | static struct drm_plane *intel_cursor_plane_create(struct drm_device *dev, |
| 13058 | int pipe) |
| 13059 | { |
| 13060 | struct intel_plane *cursor; |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13061 | struct intel_plane_state *state; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13062 | |
| 13063 | cursor = kzalloc(sizeof(*cursor), GFP_KERNEL); |
| 13064 | if (cursor == NULL) |
| 13065 | return NULL; |
| 13066 | |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13067 | state = intel_create_plane_state(&cursor->base); |
| 13068 | if (!state) { |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13069 | kfree(cursor); |
| 13070 | return NULL; |
| 13071 | } |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13072 | cursor->base.state = &state->base; |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13073 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13074 | cursor->can_scale = false; |
| 13075 | cursor->max_downscale = 1; |
| 13076 | cursor->pipe = pipe; |
| 13077 | cursor->plane = pipe; |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13078 | state->scaler_id = -1; |
Matt Roper | c59cb17 | 2014-12-01 15:40:16 -0800 | [diff] [blame] | 13079 | cursor->check_plane = intel_check_cursor_plane; |
| 13080 | cursor->commit_plane = intel_commit_cursor_plane; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13081 | |
| 13082 | drm_universal_plane_init(dev, &cursor->base, 0, |
Matt Roper | 65a3fea | 2015-01-21 16:35:42 -0800 | [diff] [blame] | 13083 | &intel_plane_funcs, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13084 | intel_cursor_formats, |
| 13085 | ARRAY_SIZE(intel_cursor_formats), |
| 13086 | DRM_PLANE_TYPE_CURSOR); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13087 | |
| 13088 | if (INTEL_INFO(dev)->gen >= 4) { |
| 13089 | if (!dev->mode_config.rotation_property) |
| 13090 | dev->mode_config.rotation_property = |
| 13091 | drm_mode_create_rotation_property(dev, |
| 13092 | BIT(DRM_ROTATE_0) | |
| 13093 | BIT(DRM_ROTATE_180)); |
| 13094 | if (dev->mode_config.rotation_property) |
| 13095 | drm_object_attach_property(&cursor->base.base, |
| 13096 | dev->mode_config.rotation_property, |
Matt Roper | 8e7d688 | 2015-01-21 16:35:41 -0800 | [diff] [blame] | 13097 | state->base.rotation); |
Ville Syrjälä | 4398ad4 | 2014-10-23 07:41:34 -0700 | [diff] [blame] | 13098 | } |
| 13099 | |
Matt Roper | ea2c67b | 2014-12-23 10:41:52 -0800 | [diff] [blame] | 13100 | drm_plane_helper_add(&cursor->base, &intel_plane_helper_funcs); |
| 13101 | |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13102 | return &cursor->base; |
| 13103 | } |
| 13104 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13105 | static void skl_init_scalers(struct drm_device *dev, struct intel_crtc *intel_crtc, |
| 13106 | struct intel_crtc_state *crtc_state) |
| 13107 | { |
| 13108 | int i; |
| 13109 | struct intel_scaler *intel_scaler; |
| 13110 | struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; |
| 13111 | |
| 13112 | for (i = 0; i < intel_crtc->num_scalers; i++) { |
| 13113 | intel_scaler = &scaler_state->scalers[i]; |
| 13114 | intel_scaler->in_use = 0; |
| 13115 | intel_scaler->id = i; |
| 13116 | |
| 13117 | intel_scaler->mode = PS_SCALER_MODE_DYN; |
| 13118 | } |
| 13119 | |
| 13120 | scaler_state->scaler_id = -1; |
| 13121 | } |
| 13122 | |
Hannes Eder | b358d0a | 2008-12-18 21:18:47 +0100 | [diff] [blame] | 13123 | static void intel_crtc_init(struct drm_device *dev, int pipe) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13124 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 13125 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13126 | struct intel_crtc *intel_crtc; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13127 | struct intel_crtc_state *crtc_state = NULL; |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13128 | struct drm_plane *primary = NULL; |
| 13129 | struct drm_plane *cursor = NULL; |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13130 | int i, ret; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13131 | |
Daniel Vetter | 955382f | 2013-09-19 14:05:45 +0200 | [diff] [blame] | 13132 | intel_crtc = kzalloc(sizeof(*intel_crtc), GFP_KERNEL); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13133 | if (intel_crtc == NULL) |
| 13134 | return; |
| 13135 | |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13136 | crtc_state = kzalloc(sizeof(*crtc_state), GFP_KERNEL); |
| 13137 | if (!crtc_state) |
| 13138 | goto fail; |
| 13139 | intel_crtc_set_state(intel_crtc, crtc_state); |
Matt Roper | 0787824 | 2015-02-25 11:43:26 -0800 | [diff] [blame] | 13140 | crtc_state->base.crtc = &intel_crtc->base; |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13141 | |
Chandra Konduru | 549e2bf | 2015-04-07 15:28:38 -0700 | [diff] [blame] | 13142 | /* initialize shared scalers */ |
| 13143 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13144 | if (pipe == PIPE_C) |
| 13145 | intel_crtc->num_scalers = 1; |
| 13146 | else |
| 13147 | intel_crtc->num_scalers = SKL_NUM_SCALERS; |
| 13148 | |
| 13149 | skl_init_scalers(dev, intel_crtc, crtc_state); |
| 13150 | } |
| 13151 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13152 | primary = intel_primary_plane_create(dev, pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13153 | if (!primary) |
| 13154 | goto fail; |
| 13155 | |
| 13156 | cursor = intel_cursor_plane_create(dev, pipe); |
| 13157 | if (!cursor) |
| 13158 | goto fail; |
| 13159 | |
Matt Roper | 465c120 | 2014-05-29 08:06:54 -0700 | [diff] [blame] | 13160 | ret = drm_crtc_init_with_planes(dev, &intel_crtc->base, primary, |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13161 | cursor, &intel_crtc_funcs); |
| 13162 | if (ret) |
| 13163 | goto fail; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13164 | |
| 13165 | drm_mode_crtc_set_gamma_size(&intel_crtc->base, 256); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13166 | for (i = 0; i < 256; i++) { |
| 13167 | intel_crtc->lut_r[i] = i; |
| 13168 | intel_crtc->lut_g[i] = i; |
| 13169 | intel_crtc->lut_b[i] = i; |
| 13170 | } |
| 13171 | |
Ville Syrjälä | 1f1c2e2 | 2013-11-28 17:30:01 +0200 | [diff] [blame] | 13172 | /* |
| 13173 | * 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] | 13174 | * 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] | 13175 | */ |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13176 | intel_crtc->pipe = pipe; |
| 13177 | intel_crtc->plane = pipe; |
Daniel Vetter | 3a77c4c | 2014-01-10 08:50:12 +0100 | [diff] [blame] | 13178 | if (HAS_FBC(dev) && INTEL_INFO(dev)->gen < 4) { |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 13179 | DRM_DEBUG_KMS("swapping pipes & planes for FBC\n"); |
Chris Wilson | e2e767a | 2010-09-13 16:53:12 +0100 | [diff] [blame] | 13180 | intel_crtc->plane = !pipe; |
Jesse Barnes | 8082400 | 2009-09-10 15:28:06 -0700 | [diff] [blame] | 13181 | } |
| 13182 | |
Chris Wilson | 4b0e333 | 2014-05-30 16:35:26 +0300 | [diff] [blame] | 13183 | intel_crtc->cursor_base = ~0; |
| 13184 | intel_crtc->cursor_cntl = ~0; |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 13185 | intel_crtc->cursor_size = ~0; |
Ville Syrjälä | 8d7849d | 2014-04-29 13:35:46 +0300 | [diff] [blame] | 13186 | |
Jesse Barnes | 22fd0fa | 2009-12-02 13:42:53 -0800 | [diff] [blame] | 13187 | BUG_ON(pipe >= ARRAY_SIZE(dev_priv->plane_to_crtc_mapping) || |
| 13188 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] != NULL); |
| 13189 | dev_priv->plane_to_crtc_mapping[intel_crtc->plane] = &intel_crtc->base; |
| 13190 | dev_priv->pipe_to_crtc_mapping[intel_crtc->pipe] = &intel_crtc->base; |
| 13191 | |
Ander Conselvan de Oliveira | 9362c7c | 2014-10-28 15:10:14 +0200 | [diff] [blame] | 13192 | INIT_WORK(&intel_crtc->mmio_flip.work, intel_mmio_flip_work_func); |
| 13193 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13194 | drm_crtc_helper_add(&intel_crtc->base, &intel_helper_funcs); |
Daniel Vetter | 87b6b10 | 2014-05-15 15:33:46 +0200 | [diff] [blame] | 13195 | |
| 13196 | WARN_ON(drm_crtc_index(&intel_crtc->base) != intel_crtc->pipe); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13197 | return; |
| 13198 | |
| 13199 | fail: |
| 13200 | if (primary) |
| 13201 | drm_plane_cleanup(primary); |
| 13202 | if (cursor) |
| 13203 | drm_plane_cleanup(cursor); |
Ander Conselvan de Oliveira | f5de6e0 | 2015-01-15 14:55:26 +0200 | [diff] [blame] | 13204 | kfree(crtc_state); |
Matt Roper | 3d7d651 | 2014-06-10 08:28:13 -0700 | [diff] [blame] | 13205 | kfree(intel_crtc); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13206 | } |
| 13207 | |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13208 | enum pipe intel_get_pipe_from_connector(struct intel_connector *connector) |
| 13209 | { |
| 13210 | struct drm_encoder *encoder = connector->base.encoder; |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 13211 | struct drm_device *dev = connector->base.dev; |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13212 | |
Rob Clark | 51fd371 | 2013-11-19 12:10:12 -0500 | [diff] [blame] | 13213 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13214 | |
Ville Syrjälä | d3babd3 | 2014-11-07 11:16:01 +0200 | [diff] [blame] | 13215 | if (!encoder || WARN_ON(!encoder->crtc)) |
Jesse Barnes | 752aa88 | 2013-10-31 18:55:49 +0200 | [diff] [blame] | 13216 | return INVALID_PIPE; |
| 13217 | |
| 13218 | return to_intel_crtc(encoder->crtc)->pipe; |
| 13219 | } |
| 13220 | |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13221 | 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] | 13222 | struct drm_file *file) |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13223 | { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13224 | 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] | 13225 | struct drm_crtc *drmmode_crtc; |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13226 | struct intel_crtc *crtc; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13227 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13228 | drmmode_crtc = drm_crtc_find(dev, pipe_from_crtc_id->crtc_id); |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13229 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13230 | if (!drmmode_crtc) { |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13231 | DRM_ERROR("no such CRTC id\n"); |
Ville Syrjälä | 3f2c205 | 2013-10-17 13:35:03 +0300 | [diff] [blame] | 13232 | return -ENOENT; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13233 | } |
| 13234 | |
Rob Clark | 7707e65 | 2014-07-17 23:30:04 -0400 | [diff] [blame] | 13235 | crtc = to_intel_crtc(drmmode_crtc); |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13236 | pipe_from_crtc_id->pipe = crtc->pipe; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13237 | |
Daniel Vetter | c05422d | 2009-08-11 16:05:30 +0200 | [diff] [blame] | 13238 | return 0; |
Carl Worth | 08d7b3d | 2009-04-29 14:43:54 -0700 | [diff] [blame] | 13239 | } |
| 13240 | |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13241 | static int intel_encoder_clones(struct intel_encoder *encoder) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13242 | { |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13243 | struct drm_device *dev = encoder->base.dev; |
| 13244 | struct intel_encoder *source_encoder; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13245 | int index_mask = 0; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13246 | int entry = 0; |
| 13247 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13248 | for_each_intel_encoder(dev, source_encoder) { |
Ville Syrjälä | bc079e8 | 2014-03-03 16:15:28 +0200 | [diff] [blame] | 13249 | if (encoders_cloneable(encoder, source_encoder)) |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13250 | index_mask |= (1 << entry); |
| 13251 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13252 | entry++; |
| 13253 | } |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13254 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13255 | return index_mask; |
| 13256 | } |
| 13257 | |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13258 | static bool has_edp_a(struct drm_device *dev) |
| 13259 | { |
| 13260 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13261 | |
| 13262 | if (!IS_MOBILE(dev)) |
| 13263 | return false; |
| 13264 | |
| 13265 | if ((I915_READ(DP_A) & DP_DETECTED) == 0) |
| 13266 | return false; |
| 13267 | |
Damien Lespiau | e358990 | 2014-02-07 19:12:50 +0000 | [diff] [blame] | 13268 | if (IS_GEN5(dev) && (I915_READ(FUSE_STRAP) & ILK_eDP_A_DISABLE)) |
Chris Wilson | 4d30244 | 2010-12-14 19:21:29 +0000 | [diff] [blame] | 13269 | return false; |
| 13270 | |
| 13271 | return true; |
| 13272 | } |
| 13273 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13274 | static bool intel_crt_present(struct drm_device *dev) |
| 13275 | { |
| 13276 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13277 | |
Damien Lespiau | 884497e | 2013-12-03 13:56:23 +0000 | [diff] [blame] | 13278 | if (INTEL_INFO(dev)->gen >= 9) |
| 13279 | return false; |
| 13280 | |
Damien Lespiau | cf404ce | 2014-10-01 20:04:15 +0100 | [diff] [blame] | 13281 | if (IS_HSW_ULT(dev) || IS_BDW_ULT(dev)) |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13282 | return false; |
| 13283 | |
| 13284 | if (IS_CHERRYVIEW(dev)) |
| 13285 | return false; |
| 13286 | |
| 13287 | if (IS_VALLEYVIEW(dev) && !dev_priv->vbt.int_crt_support) |
| 13288 | return false; |
| 13289 | |
| 13290 | return true; |
| 13291 | } |
| 13292 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13293 | static void intel_setup_outputs(struct drm_device *dev) |
| 13294 | { |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13295 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13296 | struct intel_encoder *encoder; |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13297 | bool dpd_is_edp = false; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13298 | |
Daniel Vetter | c909335 | 2013-06-06 22:22:47 +0200 | [diff] [blame] | 13299 | intel_lvds_init(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13300 | |
Jesse Barnes | 84b4e04 | 2014-06-25 08:24:29 -0700 | [diff] [blame] | 13301 | if (intel_crt_present(dev)) |
Paulo Zanoni | 79935fc | 2012-11-20 13:27:40 -0200 | [diff] [blame] | 13302 | intel_crt_init(dev); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13303 | |
Paulo Zanoni | affa935 | 2012-11-23 15:30:39 -0200 | [diff] [blame] | 13304 | if (HAS_DDI(dev)) { |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13305 | int found; |
| 13306 | |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13307 | /* |
| 13308 | * Haswell uses DDI functions to detect digital outputs. |
| 13309 | * On SKL pre-D0 the strap isn't connected, so we assume |
| 13310 | * it's there. |
| 13311 | */ |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13312 | found = I915_READ(DDI_BUF_CTL_A) & DDI_INIT_DISPLAY_DETECTED; |
Jesse Barnes | de31fac | 2015-03-06 15:53:32 -0800 | [diff] [blame] | 13313 | /* WaIgnoreDDIAStrap: skl */ |
| 13314 | if (found || |
| 13315 | (IS_SKYLAKE(dev) && INTEL_REVID(dev) < SKL_REVID_D0)) |
Eugeni Dodonov | 0e72a5b | 2012-05-09 15:37:27 -0300 | [diff] [blame] | 13316 | intel_ddi_init(dev, PORT_A); |
| 13317 | |
| 13318 | /* DDI B, C and D detection is indicated by the SFUSE_STRAP |
| 13319 | * register */ |
| 13320 | found = I915_READ(SFUSE_STRAP); |
| 13321 | |
| 13322 | if (found & SFUSE_STRAP_DDIB_DETECTED) |
| 13323 | intel_ddi_init(dev, PORT_B); |
| 13324 | if (found & SFUSE_STRAP_DDIC_DETECTED) |
| 13325 | intel_ddi_init(dev, PORT_C); |
| 13326 | if (found & SFUSE_STRAP_DDID_DETECTED) |
| 13327 | intel_ddi_init(dev, PORT_D); |
| 13328 | } else if (HAS_PCH_SPLIT(dev)) { |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13329 | int found; |
Ville Syrjälä | 5d8a775 | 2013-11-01 18:22:39 +0200 | [diff] [blame] | 13330 | dpd_is_edp = intel_dp_is_edp(dev, PORT_D); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13331 | |
| 13332 | if (has_edp_a(dev)) |
| 13333 | intel_dp_init(dev, DP_A, PORT_A); |
Adam Jackson | cb0953d | 2010-07-16 14:46:29 -0400 | [diff] [blame] | 13334 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13335 | if (I915_READ(PCH_HDMIB) & SDVO_DETECTED) { |
Zhao Yakui | 461ed3c | 2010-03-30 15:11:33 +0800 | [diff] [blame] | 13336 | /* PCH SDVOB multiplex with HDMIB */ |
Daniel Vetter | eef4eac | 2012-03-23 23:43:35 +0100 | [diff] [blame] | 13337 | found = intel_sdvo_init(dev, PCH_SDVOB, true); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13338 | if (!found) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13339 | intel_hdmi_init(dev, PCH_HDMIB, PORT_B); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13340 | if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13341 | intel_dp_init(dev, PCH_DP_B, PORT_B); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13342 | } |
| 13343 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13344 | if (I915_READ(PCH_HDMIC) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13345 | intel_hdmi_init(dev, PCH_HDMIC, PORT_C); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13346 | |
Paulo Zanoni | dc0fa71 | 2013-02-19 16:21:46 -0300 | [diff] [blame] | 13347 | if (!dpd_is_edp && I915_READ(PCH_HDMID) & SDVO_DETECTED) |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13348 | intel_hdmi_init(dev, PCH_HDMID, PORT_D); |
Zhenyu Wang | 30ad48b | 2009-06-05 15:38:43 +0800 | [diff] [blame] | 13349 | |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13350 | if (I915_READ(PCH_DP_C) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13351 | intel_dp_init(dev, PCH_DP_C, PORT_C); |
Zhenyu Wang | 5eb08b6 | 2009-07-24 01:00:31 +0800 | [diff] [blame] | 13352 | |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13353 | if (I915_READ(PCH_DP_D) & DP_DETECTED) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13354 | intel_dp_init(dev, PCH_DP_D, PORT_D); |
Jesse Barnes | 4a87d65 | 2012-06-15 11:55:16 -0700 | [diff] [blame] | 13355 | } else if (IS_VALLEYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13356 | /* |
| 13357 | * The DP_DETECTED bit is the latched state of the DDC |
| 13358 | * SDA pin at boot. However since eDP doesn't require DDC |
| 13359 | * (no way to plug in a DP->HDMI dongle) the DDC pins for |
| 13360 | * eDP ports may have been muxed to an alternate function. |
| 13361 | * Thus we can't rely on the DP_DETECTED bit alone to detect |
| 13362 | * eDP ports. Consult the VBT as well as DP_DETECTED to |
| 13363 | * detect eDP ports. |
| 13364 | */ |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 13365 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIB) & SDVO_DETECTED && |
| 13366 | !intel_dp_is_edp(dev, PORT_B)) |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 13367 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIB, |
| 13368 | PORT_B); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13369 | if (I915_READ(VLV_DISPLAY_BASE + DP_B) & DP_DETECTED || |
| 13370 | intel_dp_is_edp(dev, PORT_B)) |
| 13371 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_B, PORT_B); |
Artem Bityutskiy | 585a94b | 2013-10-16 18:10:41 +0300 | [diff] [blame] | 13372 | |
Ville Syrjälä | d2182a6 | 2015-01-09 14:21:14 +0200 | [diff] [blame] | 13373 | if (I915_READ(VLV_DISPLAY_BASE + GEN4_HDMIC) & SDVO_DETECTED && |
| 13374 | !intel_dp_is_edp(dev, PORT_C)) |
Jesse Barnes | 6f6005a | 2013-08-09 09:34:35 -0700 | [diff] [blame] | 13375 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + GEN4_HDMIC, |
| 13376 | PORT_C); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13377 | if (I915_READ(VLV_DISPLAY_BASE + DP_C) & DP_DETECTED || |
| 13378 | intel_dp_is_edp(dev, PORT_C)) |
| 13379 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_C, PORT_C); |
Gajanan Bhat | 19c0392 | 2012-09-27 19:13:07 +0530 | [diff] [blame] | 13380 | |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13381 | if (IS_CHERRYVIEW(dev)) { |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13382 | if (I915_READ(VLV_DISPLAY_BASE + CHV_HDMID) & SDVO_DETECTED) |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13383 | intel_hdmi_init(dev, VLV_DISPLAY_BASE + CHV_HDMID, |
| 13384 | PORT_D); |
Ville Syrjälä | e17ac6d | 2014-10-09 19:37:15 +0300 | [diff] [blame] | 13385 | /* eDP not supported on port D, so don't check VBT */ |
| 13386 | if (I915_READ(VLV_DISPLAY_BASE + DP_D) & DP_DETECTED) |
| 13387 | intel_dp_init(dev, VLV_DISPLAY_BASE + DP_D, PORT_D); |
Ville Syrjälä | 9418c1f | 2014-04-09 13:28:56 +0300 | [diff] [blame] | 13388 | } |
| 13389 | |
Jani Nikula | 3cfca97 | 2013-08-27 15:12:26 +0300 | [diff] [blame] | 13390 | intel_dsi_init(dev); |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 13391 | } else if (SUPPORTS_DIGITAL_OUTPUTS(dev)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13392 | bool found = false; |
Eric Anholt | 7d57382 | 2009-01-02 13:33:00 -0800 | [diff] [blame] | 13393 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13394 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13395 | DRM_DEBUG_KMS("probing SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13396 | found = intel_sdvo_init(dev, GEN3_SDVOB, true); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13397 | if (!found && SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 13398 | DRM_DEBUG_KMS("probing HDMI on SDVOB\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13399 | intel_hdmi_init(dev, GEN4_HDMIB, PORT_B); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13400 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13401 | |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 13402 | if (!found && SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13403 | intel_dp_init(dev, DP_B, PORT_B); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13404 | } |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 13405 | |
| 13406 | /* Before G4X SDVOC doesn't have its own detect register */ |
Kristian Høgsberg | 13520b0 | 2009-03-13 15:42:14 -0400 | [diff] [blame] | 13407 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13408 | if (I915_READ(GEN3_SDVOB) & SDVO_DETECTED) { |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13409 | DRM_DEBUG_KMS("probing SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13410 | found = intel_sdvo_init(dev, GEN3_SDVOC, false); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13411 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13412 | |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13413 | if (!found && (I915_READ(GEN3_SDVOC) & SDVO_DETECTED)) { |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13414 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13415 | if (SUPPORTS_INTEGRATED_HDMI(dev)) { |
| 13416 | DRM_DEBUG_KMS("probing HDMI on SDVOC\n"); |
Paulo Zanoni | e2debe9 | 2013-02-18 19:00:27 -0300 | [diff] [blame] | 13417 | intel_hdmi_init(dev, GEN4_HDMIC, PORT_C); |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13418 | } |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 13419 | if (SUPPORTS_INTEGRATED_DP(dev)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13420 | intel_dp_init(dev, DP_C, PORT_C); |
Eric Anholt | 725e30a | 2009-01-22 13:01:02 -0800 | [diff] [blame] | 13421 | } |
Ma Ling | 27185ae | 2009-08-24 13:50:23 +0800 | [diff] [blame] | 13422 | |
Jesse Barnes | b01f2c3 | 2009-12-11 11:07:17 -0800 | [diff] [blame] | 13423 | if (SUPPORTS_INTEGRATED_DP(dev) && |
Imre Deak | e7281ea | 2013-05-08 13:14:08 +0300 | [diff] [blame] | 13424 | (I915_READ(DP_D) & DP_DETECTED)) |
Paulo Zanoni | ab9d7c3 | 2012-07-17 17:53:45 -0300 | [diff] [blame] | 13425 | intel_dp_init(dev, DP_D, PORT_D); |
Eric Anholt | bad720f | 2009-10-22 16:11:14 -0700 | [diff] [blame] | 13426 | } else if (IS_GEN2(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13427 | intel_dvo_init(dev); |
| 13428 | |
Zhenyu Wang | 103a196 | 2009-11-27 11:44:36 +0800 | [diff] [blame] | 13429 | if (SUPPORTS_TV(dev)) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13430 | intel_tv_init(dev); |
| 13431 | |
Rodrigo Vivi | 0bc12bc | 2014-11-14 08:52:28 -0800 | [diff] [blame] | 13432 | intel_psr_init(dev); |
Rodrigo Vivi | 7c8f8a7 | 2014-06-13 05:10:03 -0700 | [diff] [blame] | 13433 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 13434 | for_each_intel_encoder(dev, encoder) { |
Chris Wilson | 4ef69c7 | 2010-09-09 15:14:28 +0100 | [diff] [blame] | 13435 | encoder->base.possible_crtcs = encoder->crtc_mask; |
| 13436 | encoder->base.possible_clones = |
Daniel Vetter | 66a9278 | 2012-07-12 20:08:18 +0200 | [diff] [blame] | 13437 | intel_encoder_clones(encoder); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13438 | } |
Chris Wilson | 47356eb | 2011-01-11 17:06:04 +0000 | [diff] [blame] | 13439 | |
Paulo Zanoni | dde86e2 | 2012-12-01 12:04:25 -0200 | [diff] [blame] | 13440 | intel_init_pch_refclk(dev); |
Daniel Vetter | 270b304 | 2012-10-27 15:52:05 +0200 | [diff] [blame] | 13441 | |
| 13442 | drm_helper_move_panel_connectors_to_head(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13443 | } |
| 13444 | |
| 13445 | static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) |
| 13446 | { |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 13447 | struct drm_device *dev = fb->dev; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13448 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13449 | |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 13450 | drm_framebuffer_cleanup(fb); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 13451 | mutex_lock(&dev->struct_mutex); |
Daniel Vetter | ef2d633 | 2014-02-10 18:00:38 +0100 | [diff] [blame] | 13452 | WARN_ON(!intel_fb->obj->framebuffer_references--); |
Ville Syrjälä | 60a5ca0 | 2014-06-13 11:10:53 +0300 | [diff] [blame] | 13453 | drm_gem_object_unreference(&intel_fb->obj->base); |
| 13454 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13455 | kfree(intel_fb); |
| 13456 | } |
| 13457 | |
| 13458 | static int intel_user_framebuffer_create_handle(struct drm_framebuffer *fb, |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13459 | struct drm_file *file, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13460 | unsigned int *handle) |
| 13461 | { |
| 13462 | struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13463 | struct drm_i915_gem_object *obj = intel_fb->obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13464 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13465 | return drm_gem_handle_create(file, &obj->base, handle); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13466 | } |
| 13467 | |
| 13468 | static const struct drm_framebuffer_funcs intel_fb_funcs = { |
| 13469 | .destroy = intel_user_framebuffer_destroy, |
| 13470 | .create_handle = intel_user_framebuffer_create_handle, |
| 13471 | }; |
| 13472 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13473 | static |
| 13474 | u32 intel_fb_pitch_limit(struct drm_device *dev, uint64_t fb_modifier, |
| 13475 | uint32_t pixel_format) |
| 13476 | { |
| 13477 | u32 gen = INTEL_INFO(dev)->gen; |
| 13478 | |
| 13479 | if (gen >= 9) { |
| 13480 | /* "The stride in bytes must not exceed the of the size of 8K |
| 13481 | * pixels and 32K bytes." |
| 13482 | */ |
| 13483 | return min(8192*drm_format_plane_cpp(pixel_format, 0), 32768); |
| 13484 | } else if (gen >= 5 && !IS_VALLEYVIEW(dev)) { |
| 13485 | return 32*1024; |
| 13486 | } else if (gen >= 4) { |
| 13487 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 13488 | return 16*1024; |
| 13489 | else |
| 13490 | return 32*1024; |
| 13491 | } else if (gen >= 3) { |
| 13492 | if (fb_modifier == I915_FORMAT_MOD_X_TILED) |
| 13493 | return 8*1024; |
| 13494 | else |
| 13495 | return 16*1024; |
| 13496 | } else { |
| 13497 | /* XXX DSPC is limited to 4k tiled */ |
| 13498 | return 8*1024; |
| 13499 | } |
| 13500 | } |
| 13501 | |
Daniel Vetter | b5ea642 | 2014-03-02 21:18:00 +0100 | [diff] [blame] | 13502 | static int intel_framebuffer_init(struct drm_device *dev, |
| 13503 | struct intel_framebuffer *intel_fb, |
| 13504 | struct drm_mode_fb_cmd2 *mode_cmd, |
| 13505 | struct drm_i915_gem_object *obj) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13506 | { |
Tvrtko Ursulin | 6761dd3 | 2015-03-23 11:10:32 +0000 | [diff] [blame] | 13507 | unsigned int aligned_height; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13508 | int ret; |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13509 | u32 pitch_limit, stride_alignment; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13510 | |
Daniel Vetter | dd4916c | 2013-10-09 21:23:51 +0200 | [diff] [blame] | 13511 | WARN_ON(!mutex_is_locked(&dev->struct_mutex)); |
| 13512 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 13513 | if (mode_cmd->flags & DRM_MODE_FB_MODIFIERS) { |
| 13514 | /* Enforce that fb modifier and tiling mode match, but only for |
| 13515 | * X-tiled. This is needed for FBC. */ |
| 13516 | if (!!(obj->tiling_mode == I915_TILING_X) != |
| 13517 | !!(mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED)) { |
| 13518 | DRM_DEBUG("tiling_mode doesn't match fb modifier\n"); |
| 13519 | return -EINVAL; |
| 13520 | } |
| 13521 | } else { |
| 13522 | if (obj->tiling_mode == I915_TILING_X) |
| 13523 | mode_cmd->modifier[0] = I915_FORMAT_MOD_X_TILED; |
| 13524 | else if (obj->tiling_mode == I915_TILING_Y) { |
| 13525 | DRM_DEBUG("No Y tiling for legacy addfb\n"); |
| 13526 | return -EINVAL; |
| 13527 | } |
| 13528 | } |
| 13529 | |
Tvrtko Ursulin | 9a8f0a1 | 2015-02-27 11:15:24 +0000 | [diff] [blame] | 13530 | /* Passed in modifier sanity checking. */ |
| 13531 | switch (mode_cmd->modifier[0]) { |
| 13532 | case I915_FORMAT_MOD_Y_TILED: |
| 13533 | case I915_FORMAT_MOD_Yf_TILED: |
| 13534 | if (INTEL_INFO(dev)->gen < 9) { |
| 13535 | DRM_DEBUG("Unsupported tiling 0x%llx!\n", |
| 13536 | mode_cmd->modifier[0]); |
| 13537 | return -EINVAL; |
| 13538 | } |
| 13539 | case DRM_FORMAT_MOD_NONE: |
| 13540 | case I915_FORMAT_MOD_X_TILED: |
| 13541 | break; |
| 13542 | default: |
Jesse Barnes | c0f4042 | 2015-03-23 12:43:50 -0700 | [diff] [blame] | 13543 | DRM_DEBUG("Unsupported fb modifier 0x%llx!\n", |
| 13544 | mode_cmd->modifier[0]); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13545 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13546 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13547 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13548 | stride_alignment = intel_fb_stride_alignment(dev, mode_cmd->modifier[0], |
| 13549 | mode_cmd->pixel_format); |
| 13550 | if (mode_cmd->pitches[0] & (stride_alignment - 1)) { |
| 13551 | DRM_DEBUG("pitch (%d) must be at least %u byte aligned\n", |
| 13552 | mode_cmd->pitches[0], stride_alignment); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13553 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13554 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13555 | |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13556 | pitch_limit = intel_fb_pitch_limit(dev, mode_cmd->modifier[0], |
| 13557 | mode_cmd->pixel_format); |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 13558 | if (mode_cmd->pitches[0] > pitch_limit) { |
Damien Lespiau | b321803 | 2015-02-27 11:15:18 +0000 | [diff] [blame] | 13559 | DRM_DEBUG("%s pitch (%u) must be at less than %d\n", |
| 13560 | mode_cmd->modifier[0] != DRM_FORMAT_MOD_NONE ? |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 13561 | "tiled" : "linear", |
Chris Wilson | a35cdaa | 2013-06-25 17:26:45 +0100 | [diff] [blame] | 13562 | mode_cmd->pitches[0], pitch_limit); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13563 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13564 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13565 | |
Daniel Vetter | 2a80ead | 2015-02-10 17:16:06 +0000 | [diff] [blame] | 13566 | if (mode_cmd->modifier[0] == I915_FORMAT_MOD_X_TILED && |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13567 | mode_cmd->pitches[0] != obj->stride) { |
| 13568 | DRM_DEBUG("pitch (%d) must match tiling stride (%d)\n", |
| 13569 | mode_cmd->pitches[0], obj->stride); |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13570 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13571 | } |
Ville Syrjälä | 5d7bd70 | 2012-10-31 17:50:18 +0200 | [diff] [blame] | 13572 | |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13573 | /* Reject formats not supported by any plane early. */ |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 13574 | switch (mode_cmd->pixel_format) { |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13575 | case DRM_FORMAT_C8: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 13576 | case DRM_FORMAT_RGB565: |
| 13577 | case DRM_FORMAT_XRGB8888: |
| 13578 | case DRM_FORMAT_ARGB8888: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13579 | break; |
| 13580 | case DRM_FORMAT_XRGB1555: |
| 13581 | case DRM_FORMAT_ARGB1555: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13582 | if (INTEL_INFO(dev)->gen > 3) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13583 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13584 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13585 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13586 | } |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13587 | break; |
| 13588 | case DRM_FORMAT_XBGR8888: |
| 13589 | case DRM_FORMAT_ABGR8888: |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 13590 | case DRM_FORMAT_XRGB2101010: |
| 13591 | case DRM_FORMAT_ARGB2101010: |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13592 | case DRM_FORMAT_XBGR2101010: |
| 13593 | case DRM_FORMAT_ABGR2101010: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13594 | if (INTEL_INFO(dev)->gen < 4) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13595 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13596 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13597 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13598 | } |
Jesse Barnes | b562674 | 2011-06-24 12:19:27 -0700 | [diff] [blame] | 13599 | break; |
Ville Syrjälä | 04b3924 | 2011-11-17 18:05:13 +0200 | [diff] [blame] | 13600 | case DRM_FORMAT_YUYV: |
| 13601 | case DRM_FORMAT_UYVY: |
| 13602 | case DRM_FORMAT_YVYU: |
| 13603 | case DRM_FORMAT_VYUY: |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13604 | if (INTEL_INFO(dev)->gen < 5) { |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13605 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13606 | drm_get_format_name(mode_cmd->pixel_format)); |
Ville Syrjälä | 57779d0 | 2012-10-31 17:50:14 +0200 | [diff] [blame] | 13607 | return -EINVAL; |
Chris Wilson | c16ed4b | 2012-12-18 22:13:14 +0000 | [diff] [blame] | 13608 | } |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13609 | break; |
| 13610 | default: |
Ville Syrjälä | 4ee62c7 | 2013-06-07 15:43:05 +0000 | [diff] [blame] | 13611 | DRM_DEBUG("unsupported pixel format: %s\n", |
| 13612 | drm_get_format_name(mode_cmd->pixel_format)); |
Chris Wilson | 57cd650 | 2010-08-08 12:34:44 +0100 | [diff] [blame] | 13613 | return -EINVAL; |
| 13614 | } |
| 13615 | |
Ville Syrjälä | 90f9a33 | 2012-10-31 17:50:19 +0200 | [diff] [blame] | 13616 | /* FIXME need to adjust LINOFF/TILEOFF accordingly. */ |
| 13617 | if (mode_cmd->offsets[0] != 0) |
| 13618 | return -EINVAL; |
| 13619 | |
Damien Lespiau | ec2c981 | 2015-01-20 12:51:45 +0000 | [diff] [blame] | 13620 | aligned_height = intel_fb_align_height(dev, mode_cmd->height, |
Daniel Vetter | 091df6c | 2015-02-10 17:16:10 +0000 | [diff] [blame] | 13621 | mode_cmd->pixel_format, |
| 13622 | mode_cmd->modifier[0]); |
Daniel Vetter | 53155c0 | 2013-10-09 21:55:33 +0200 | [diff] [blame] | 13623 | /* FIXME drm helper for size checks (especially planar formats)? */ |
| 13624 | if (obj->base.size < aligned_height * mode_cmd->pitches[0]) |
| 13625 | return -EINVAL; |
| 13626 | |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 13627 | drm_helper_mode_fill_fb_struct(&intel_fb->base, mode_cmd); |
| 13628 | intel_fb->obj = obj; |
Daniel Vetter | 80075d4 | 2013-10-09 21:23:52 +0200 | [diff] [blame] | 13629 | intel_fb->obj->framebuffer_references++; |
Daniel Vetter | c7d73f6 | 2012-12-13 23:38:38 +0100 | [diff] [blame] | 13630 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13631 | ret = drm_framebuffer_init(dev, &intel_fb->base, &intel_fb_funcs); |
| 13632 | if (ret) { |
| 13633 | DRM_ERROR("framebuffer init failed %d\n", ret); |
| 13634 | return ret; |
| 13635 | } |
| 13636 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13637 | return 0; |
| 13638 | } |
| 13639 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13640 | static struct drm_framebuffer * |
| 13641 | intel_user_framebuffer_create(struct drm_device *dev, |
| 13642 | struct drm_file *filp, |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 13643 | struct drm_mode_fb_cmd2 *mode_cmd) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13644 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 13645 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13646 | |
Jesse Barnes | 308e5bc | 2011-11-14 14:51:28 -0800 | [diff] [blame] | 13647 | obj = to_intel_bo(drm_gem_object_lookup(dev, filp, |
| 13648 | mode_cmd->handles[0])); |
Chris Wilson | c872522 | 2011-02-19 11:31:06 +0000 | [diff] [blame] | 13649 | if (&obj->base == NULL) |
Chris Wilson | cce13ff | 2010-08-08 13:36:38 +0100 | [diff] [blame] | 13650 | return ERR_PTR(-ENOENT); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13651 | |
Chris Wilson | d2dff87 | 2011-04-19 08:36:26 +0100 | [diff] [blame] | 13652 | return intel_framebuffer_create(dev, mode_cmd, obj); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13653 | } |
| 13654 | |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 13655 | #ifndef CONFIG_DRM_I915_FBDEV |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 13656 | static inline void intel_fbdev_output_poll_changed(struct drm_device *dev) |
Daniel Vetter | 4520f53 | 2013-10-09 09:18:51 +0200 | [diff] [blame] | 13657 | { |
| 13658 | } |
| 13659 | #endif |
| 13660 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13661 | static const struct drm_mode_config_funcs intel_mode_funcs = { |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13662 | .fb_create = intel_user_framebuffer_create, |
Daniel Vetter | 0632fef | 2013-10-08 17:44:49 +0200 | [diff] [blame] | 13663 | .output_poll_changed = intel_fbdev_output_poll_changed, |
Matt Roper | 5ee67f1 | 2015-01-21 16:35:44 -0800 | [diff] [blame] | 13664 | .atomic_check = intel_atomic_check, |
| 13665 | .atomic_commit = intel_atomic_commit, |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 13666 | }; |
| 13667 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13668 | /* Set up chip specific display functions */ |
| 13669 | static void intel_init_display(struct drm_device *dev) |
| 13670 | { |
| 13671 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13672 | |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 13673 | if (HAS_PCH_SPLIT(dev) || IS_G4X(dev)) |
| 13674 | dev_priv->display.find_dpll = g4x_find_best_dpll; |
Chon Ming Lee | ef9348c | 2014-04-09 13:28:18 +0300 | [diff] [blame] | 13675 | else if (IS_CHERRYVIEW(dev)) |
| 13676 | dev_priv->display.find_dpll = chv_find_best_dpll; |
Daniel Vetter | ee9300b | 2013-06-03 22:40:22 +0200 | [diff] [blame] | 13677 | else if (IS_VALLEYVIEW(dev)) |
| 13678 | dev_priv->display.find_dpll = vlv_find_best_dpll; |
| 13679 | else if (IS_PINEVIEW(dev)) |
| 13680 | dev_priv->display.find_dpll = pnv_find_best_dpll; |
| 13681 | else |
| 13682 | dev_priv->display.find_dpll = i9xx_find_best_dpll; |
| 13683 | |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 13684 | if (INTEL_INFO(dev)->gen >= 9) { |
| 13685 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13686 | dev_priv->display.get_initial_plane_config = |
| 13687 | skylake_get_initial_plane_config; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 13688 | dev_priv->display.crtc_compute_clock = |
| 13689 | haswell_crtc_compute_clock; |
| 13690 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 13691 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
| 13692 | dev_priv->display.off = ironlake_crtc_off; |
| 13693 | dev_priv->display.update_primary_plane = |
| 13694 | skylake_update_primary_plane; |
| 13695 | } else if (HAS_DDI(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13696 | dev_priv->display.get_pipe_config = haswell_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13697 | dev_priv->display.get_initial_plane_config = |
| 13698 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 797d025 | 2014-10-29 11:32:34 +0200 | [diff] [blame] | 13699 | dev_priv->display.crtc_compute_clock = |
| 13700 | haswell_crtc_compute_clock; |
Paulo Zanoni | 4f771f1 | 2012-10-23 18:29:51 -0200 | [diff] [blame] | 13701 | dev_priv->display.crtc_enable = haswell_crtc_enable; |
| 13702 | dev_priv->display.crtc_disable = haswell_crtc_disable; |
Daniel Vetter | df8ad70 | 2014-06-25 22:02:03 +0300 | [diff] [blame] | 13703 | dev_priv->display.off = ironlake_crtc_off; |
Damien Lespiau | bc8d7df | 2015-01-20 12:51:51 +0000 | [diff] [blame] | 13704 | dev_priv->display.update_primary_plane = |
| 13705 | ironlake_update_primary_plane; |
Paulo Zanoni | 09b4ddf | 2012-10-05 12:05:55 -0300 | [diff] [blame] | 13706 | } else if (HAS_PCH_SPLIT(dev)) { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13707 | dev_priv->display.get_pipe_config = ironlake_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13708 | dev_priv->display.get_initial_plane_config = |
| 13709 | ironlake_get_initial_plane_config; |
Ander Conselvan de Oliveira | 3fb3770 | 2014-10-29 11:32:35 +0200 | [diff] [blame] | 13710 | dev_priv->display.crtc_compute_clock = |
| 13711 | ironlake_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 13712 | dev_priv->display.crtc_enable = ironlake_crtc_enable; |
| 13713 | dev_priv->display.crtc_disable = ironlake_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13714 | dev_priv->display.off = ironlake_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 13715 | dev_priv->display.update_primary_plane = |
| 13716 | ironlake_update_primary_plane; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 13717 | } else if (IS_VALLEYVIEW(dev)) { |
| 13718 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13719 | dev_priv->display.get_initial_plane_config = |
| 13720 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 13721 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Jesse Barnes | 89b667f | 2013-04-18 14:51:36 -0700 | [diff] [blame] | 13722 | dev_priv->display.crtc_enable = valleyview_crtc_enable; |
| 13723 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
| 13724 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 13725 | dev_priv->display.update_primary_plane = |
| 13726 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 13727 | } else { |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 13728 | dev_priv->display.get_pipe_config = i9xx_get_pipe_config; |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 13729 | dev_priv->display.get_initial_plane_config = |
| 13730 | i9xx_get_initial_plane_config; |
Ander Conselvan de Oliveira | d6dfee7 | 2014-10-29 11:32:36 +0200 | [diff] [blame] | 13731 | dev_priv->display.crtc_compute_clock = i9xx_crtc_compute_clock; |
Daniel Vetter | 76e5a89 | 2012-06-29 22:39:33 +0200 | [diff] [blame] | 13732 | dev_priv->display.crtc_enable = i9xx_crtc_enable; |
| 13733 | dev_priv->display.crtc_disable = i9xx_crtc_disable; |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 13734 | dev_priv->display.off = i9xx_crtc_off; |
Matt Roper | 262ca2b | 2014-03-18 17:22:55 -0700 | [diff] [blame] | 13735 | dev_priv->display.update_primary_plane = |
| 13736 | i9xx_update_primary_plane; |
Eric Anholt | f564048e | 2011-03-30 13:01:02 -0700 | [diff] [blame] | 13737 | } |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13738 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13739 | /* Returns the core display clock speed */ |
Ville Syrjälä | 1652d19 | 2015-03-31 14:12:01 +0300 | [diff] [blame] | 13740 | if (IS_SKYLAKE(dev)) |
| 13741 | dev_priv->display.get_display_clock_speed = |
| 13742 | skylake_get_display_clock_speed; |
| 13743 | else if (IS_BROADWELL(dev)) |
| 13744 | dev_priv->display.get_display_clock_speed = |
| 13745 | broadwell_get_display_clock_speed; |
| 13746 | else if (IS_HASWELL(dev)) |
| 13747 | dev_priv->display.get_display_clock_speed = |
| 13748 | haswell_get_display_clock_speed; |
| 13749 | else if (IS_VALLEYVIEW(dev)) |
Jesse Barnes | 25eb05fc | 2012-03-28 13:39:23 -0700 | [diff] [blame] | 13750 | dev_priv->display.get_display_clock_speed = |
| 13751 | valleyview_get_display_clock_speed; |
Ville Syrjälä | b37a643 | 2015-03-31 14:11:54 +0300 | [diff] [blame] | 13752 | else if (IS_GEN5(dev)) |
| 13753 | dev_priv->display.get_display_clock_speed = |
| 13754 | ilk_get_display_clock_speed; |
Ville Syrjälä | a7c66cd | 2015-03-31 14:11:56 +0300 | [diff] [blame] | 13755 | else if (IS_I945G(dev) || IS_BROADWATER(dev) || |
| 13756 | IS_GEN6(dev) || IS_IVYBRIDGE(dev) || (IS_G33(dev) && !IS_PINEVIEW_M(dev))) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13757 | dev_priv->display.get_display_clock_speed = |
| 13758 | i945_get_display_clock_speed; |
| 13759 | else if (IS_I915G(dev)) |
| 13760 | dev_priv->display.get_display_clock_speed = |
| 13761 | i915_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 13762 | else if (IS_I945GM(dev) || IS_845G(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13763 | dev_priv->display.get_display_clock_speed = |
| 13764 | i9xx_misc_get_display_clock_speed; |
Daniel Vetter | 257a7ff | 2013-07-26 08:35:42 +0200 | [diff] [blame] | 13765 | else if (IS_PINEVIEW(dev)) |
| 13766 | dev_priv->display.get_display_clock_speed = |
| 13767 | pnv_get_display_clock_speed; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13768 | else if (IS_I915GM(dev)) |
| 13769 | dev_priv->display.get_display_clock_speed = |
| 13770 | i915gm_get_display_clock_speed; |
| 13771 | else if (IS_I865G(dev)) |
| 13772 | dev_priv->display.get_display_clock_speed = |
| 13773 | i865_get_display_clock_speed; |
Daniel Vetter | f0f8a9c | 2009-09-15 22:57:33 +0200 | [diff] [blame] | 13774 | else if (IS_I85X(dev)) |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13775 | dev_priv->display.get_display_clock_speed = |
| 13776 | i855_get_display_clock_speed; |
| 13777 | else /* 852, 830 */ |
| 13778 | dev_priv->display.get_display_clock_speed = |
| 13779 | i830_get_display_clock_speed; |
| 13780 | |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 13781 | if (IS_GEN5(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13782 | dev_priv->display.fdi_link_train = ironlake_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13783 | } else if (IS_GEN6(dev)) { |
| 13784 | dev_priv->display.fdi_link_train = gen6_fdi_link_train; |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13785 | } else if (IS_IVYBRIDGE(dev)) { |
| 13786 | /* FIXME: detect B0+ stepping and use auto training */ |
| 13787 | dev_priv->display.fdi_link_train = ivb_manual_fdi_link_train; |
Paulo Zanoni | 059b2fe | 2014-09-02 16:53:57 -0300 | [diff] [blame] | 13788 | } else if (IS_HASWELL(dev) || IS_BROADWELL(dev)) { |
Sonika Jindal | 3bb11b5 | 2014-08-11 09:06:39 +0530 | [diff] [blame] | 13789 | dev_priv->display.fdi_link_train = hsw_fdi_link_train; |
Jesse Barnes | 30a970c | 2013-11-04 13:48:12 -0800 | [diff] [blame] | 13790 | } else if (IS_VALLEYVIEW(dev)) { |
| 13791 | dev_priv->display.modeset_global_resources = |
| 13792 | valleyview_modeset_global_resources; |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13793 | } |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 13794 | |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 13795 | switch (INTEL_INFO(dev)->gen) { |
| 13796 | case 2: |
| 13797 | dev_priv->display.queue_flip = intel_gen2_queue_flip; |
| 13798 | break; |
| 13799 | |
| 13800 | case 3: |
| 13801 | dev_priv->display.queue_flip = intel_gen3_queue_flip; |
| 13802 | break; |
| 13803 | |
| 13804 | case 4: |
| 13805 | case 5: |
| 13806 | dev_priv->display.queue_flip = intel_gen4_queue_flip; |
| 13807 | break; |
| 13808 | |
| 13809 | case 6: |
| 13810 | dev_priv->display.queue_flip = intel_gen6_queue_flip; |
| 13811 | break; |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 13812 | case 7: |
Ben Widawsky | 4e0bbc3 | 2013-11-02 21:07:07 -0700 | [diff] [blame] | 13813 | case 8: /* FIXME(BDW): Check that the gen8 RCS flip works. */ |
Jesse Barnes | 7c9017e | 2011-06-16 12:18:54 -0700 | [diff] [blame] | 13814 | dev_priv->display.queue_flip = intel_gen7_queue_flip; |
| 13815 | break; |
Damien Lespiau | 830c81d | 2014-11-13 17:51:46 +0000 | [diff] [blame] | 13816 | case 9: |
Tvrtko Ursulin | ba343e0 | 2015-02-10 17:16:12 +0000 | [diff] [blame] | 13817 | /* Drop through - unsupported since execlist only. */ |
| 13818 | default: |
| 13819 | /* Default just returns -ENODEV to indicate unsupported */ |
| 13820 | dev_priv->display.queue_flip = intel_default_queue_flip; |
Jesse Barnes | 8c9f3aa | 2011-06-16 09:19:13 -0700 | [diff] [blame] | 13821 | } |
Jani Nikula | 7bd688c | 2013-11-08 16:48:56 +0200 | [diff] [blame] | 13822 | |
| 13823 | intel_panel_init_backlight_funcs(dev); |
Ville Syrjälä | e39b999 | 2014-09-04 14:53:14 +0300 | [diff] [blame] | 13824 | |
| 13825 | mutex_init(&dev_priv->pps_mutex); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 13826 | } |
| 13827 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13828 | /* |
| 13829 | * Some BIOSes insist on assuming the GPU's pipe A is enabled at suspend, |
| 13830 | * resume, or other times. This quirk makes sure that's the case for |
| 13831 | * affected systems. |
| 13832 | */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 13833 | static void quirk_pipea_force(struct drm_device *dev) |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13834 | { |
| 13835 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13836 | |
| 13837 | dev_priv->quirks |= QUIRK_PIPEA_FORCE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 13838 | DRM_INFO("applying pipe a force quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13839 | } |
| 13840 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 13841 | static void quirk_pipeb_force(struct drm_device *dev) |
| 13842 | { |
| 13843 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13844 | |
| 13845 | dev_priv->quirks |= QUIRK_PIPEB_FORCE; |
| 13846 | DRM_INFO("applying pipe b force quirk\n"); |
| 13847 | } |
| 13848 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 13849 | /* |
| 13850 | * Some machines (Lenovo U160) do not work with SSC on LVDS for some reason |
| 13851 | */ |
| 13852 | static void quirk_ssc_force_disable(struct drm_device *dev) |
| 13853 | { |
| 13854 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13855 | dev_priv->quirks |= QUIRK_LVDS_SSC_DISABLE; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 13856 | DRM_INFO("applying lvds SSC disable quirk\n"); |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 13857 | } |
| 13858 | |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 13859 | /* |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 13860 | * A machine (e.g. Acer Aspire 5734Z) may need to invert the panel backlight |
| 13861 | * brightness value |
Carsten Emde | 4dca20e | 2012-03-15 15:56:26 +0100 | [diff] [blame] | 13862 | */ |
| 13863 | static void quirk_invert_brightness(struct drm_device *dev) |
| 13864 | { |
| 13865 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13866 | dev_priv->quirks |= QUIRK_INVERT_BRIGHTNESS; |
Daniel Vetter | bc0daf4 | 2012-04-01 13:16:49 +0200 | [diff] [blame] | 13867 | DRM_INFO("applying inverted panel brightness quirk\n"); |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13868 | } |
| 13869 | |
Scot Doyle | 9c72cc6 | 2014-07-03 23:27:50 +0000 | [diff] [blame] | 13870 | /* Some VBT's incorrectly indicate no backlight is present */ |
| 13871 | static void quirk_backlight_present(struct drm_device *dev) |
| 13872 | { |
| 13873 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13874 | dev_priv->quirks |= QUIRK_BACKLIGHT_PRESENT; |
| 13875 | DRM_INFO("applying backlight present quirk\n"); |
| 13876 | } |
| 13877 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13878 | struct intel_quirk { |
| 13879 | int device; |
| 13880 | int subsystem_vendor; |
| 13881 | int subsystem_device; |
| 13882 | void (*hook)(struct drm_device *dev); |
| 13883 | }; |
| 13884 | |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 13885 | /* For systems that don't have a meaningful PCI subdevice/subvendor ID */ |
| 13886 | struct intel_dmi_quirk { |
| 13887 | void (*hook)(struct drm_device *dev); |
| 13888 | const struct dmi_system_id (*dmi_id_list)[]; |
| 13889 | }; |
| 13890 | |
| 13891 | static int intel_dmi_reverse_brightness(const struct dmi_system_id *id) |
| 13892 | { |
| 13893 | DRM_INFO("Backlight polarity reversed on %s\n", id->ident); |
| 13894 | return 1; |
| 13895 | } |
| 13896 | |
| 13897 | static const struct intel_dmi_quirk intel_dmi_quirks[] = { |
| 13898 | { |
| 13899 | .dmi_id_list = &(const struct dmi_system_id[]) { |
| 13900 | { |
| 13901 | .callback = intel_dmi_reverse_brightness, |
| 13902 | .ident = "NCR Corporation", |
| 13903 | .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"), |
| 13904 | DMI_MATCH(DMI_PRODUCT_NAME, ""), |
| 13905 | }, |
| 13906 | }, |
| 13907 | { } /* terminating entry */ |
| 13908 | }, |
| 13909 | .hook = quirk_invert_brightness, |
| 13910 | }, |
| 13911 | }; |
| 13912 | |
Ben Widawsky | c43b563 | 2012-04-16 14:07:40 -0700 | [diff] [blame] | 13913 | static struct intel_quirk intel_quirks[] = { |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13914 | /* HP Mini needs pipe A force quirk (LP: #322104) */ |
Akshay Joshi | 0206e35 | 2011-08-16 15:34:10 -0400 | [diff] [blame] | 13915 | { 0x27ae, 0x103c, 0x361a, quirk_pipea_force }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13916 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13917 | /* Toshiba Protege R-205, S-209 needs pipe A force quirk */ |
| 13918 | { 0x2592, 0x1179, 0x0001, quirk_pipea_force }, |
| 13919 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13920 | /* ThinkPad T60 needs pipe A force quirk (bug #16494) */ |
| 13921 | { 0x2782, 0x17aa, 0x201a, quirk_pipea_force }, |
| 13922 | |
Ville Syrjälä | 5f080c0 | 2014-08-15 01:22:06 +0300 | [diff] [blame] | 13923 | /* 830 needs to leave pipe A & dpll A up */ |
| 13924 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipea_force }, |
| 13925 | |
Ville Syrjälä | b6b5d04 | 2014-08-15 01:22:07 +0300 | [diff] [blame] | 13926 | /* 830 needs to leave pipe B & dpll B up */ |
| 13927 | { 0x3577, PCI_ANY_ID, PCI_ANY_ID, quirk_pipeb_force }, |
| 13928 | |
Keith Packard | 435793d | 2011-07-12 14:56:22 -0700 | [diff] [blame] | 13929 | /* Lenovo U160 cannot use SSC on LVDS */ |
| 13930 | { 0x0046, 0x17aa, 0x3920, quirk_ssc_force_disable }, |
Michel Alexandre Salim | 070d329 | 2011-07-28 18:52:06 +0200 | [diff] [blame] | 13931 | |
| 13932 | /* Sony Vaio Y cannot use SSC on LVDS */ |
| 13933 | { 0x0046, 0x104d, 0x9076, quirk_ssc_force_disable }, |
Carsten Emde | 5a15ab5 | 2012-03-15 15:56:27 +0100 | [diff] [blame] | 13934 | |
Alexander van Heukelum | be505f6 | 2013-12-28 21:00:39 +0100 | [diff] [blame] | 13935 | /* Acer Aspire 5734Z must invert backlight brightness */ |
| 13936 | { 0x2a42, 0x1025, 0x0459, quirk_invert_brightness }, |
| 13937 | |
| 13938 | /* Acer/eMachines G725 */ |
| 13939 | { 0x2a42, 0x1025, 0x0210, quirk_invert_brightness }, |
| 13940 | |
| 13941 | /* Acer/eMachines e725 */ |
| 13942 | { 0x2a42, 0x1025, 0x0212, quirk_invert_brightness }, |
| 13943 | |
| 13944 | /* Acer/Packard Bell NCL20 */ |
| 13945 | { 0x2a42, 0x1025, 0x034b, quirk_invert_brightness }, |
| 13946 | |
| 13947 | /* Acer Aspire 4736Z */ |
| 13948 | { 0x2a42, 0x1025, 0x0260, quirk_invert_brightness }, |
Jani Nikula | 0f540c3 | 2014-01-13 17:30:34 +0200 | [diff] [blame] | 13949 | |
| 13950 | /* Acer Aspire 5336 */ |
| 13951 | { 0x2a42, 0x1025, 0x048a, quirk_invert_brightness }, |
Scot Doyle | 2e93a1a | 2014-07-03 23:27:51 +0000 | [diff] [blame] | 13952 | |
| 13953 | /* Acer C720 and C720P Chromebooks (Celeron 2955U) have backlights */ |
| 13954 | { 0x0a06, 0x1025, 0x0a11, quirk_backlight_present }, |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 13955 | |
Scot Doyle | dfb3d47b | 2014-08-21 16:08:02 +0000 | [diff] [blame] | 13956 | /* Acer C720 Chromebook (Core i3 4005U) */ |
| 13957 | { 0x0a16, 0x1025, 0x0a11, quirk_backlight_present }, |
| 13958 | |
jens stein | b2a9601 | 2014-10-28 20:25:53 +0100 | [diff] [blame] | 13959 | /* Apple Macbook 2,1 (Core 2 T7400) */ |
| 13960 | { 0x27a2, 0x8086, 0x7270, quirk_backlight_present }, |
| 13961 | |
Scot Doyle | d4967d8 | 2014-07-03 23:27:52 +0000 | [diff] [blame] | 13962 | /* Toshiba CB35 Chromebook (Celeron 2955U) */ |
| 13963 | { 0x0a06, 0x1179, 0x0a88, quirk_backlight_present }, |
Scot Doyle | 724cb06 | 2014-07-11 22:16:30 +0000 | [diff] [blame] | 13964 | |
| 13965 | /* HP Chromebook 14 (Celeron 2955U) */ |
| 13966 | { 0x0a06, 0x103c, 0x21ed, quirk_backlight_present }, |
Jani Nikula | cf6f0af | 2015-02-19 10:53:39 +0200 | [diff] [blame] | 13967 | |
| 13968 | /* Dell Chromebook 11 */ |
| 13969 | { 0x0a06, 0x1028, 0x0a35, quirk_backlight_present }, |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13970 | }; |
| 13971 | |
| 13972 | static void intel_init_quirks(struct drm_device *dev) |
| 13973 | { |
| 13974 | struct pci_dev *d = dev->pdev; |
| 13975 | int i; |
| 13976 | |
| 13977 | for (i = 0; i < ARRAY_SIZE(intel_quirks); i++) { |
| 13978 | struct intel_quirk *q = &intel_quirks[i]; |
| 13979 | |
| 13980 | if (d->device == q->device && |
| 13981 | (d->subsystem_vendor == q->subsystem_vendor || |
| 13982 | q->subsystem_vendor == PCI_ANY_ID) && |
| 13983 | (d->subsystem_device == q->subsystem_device || |
| 13984 | q->subsystem_device == PCI_ANY_ID)) |
| 13985 | q->hook(dev); |
| 13986 | } |
Egbert Eich | 5f85f17 | 2012-10-14 15:46:38 +0200 | [diff] [blame] | 13987 | for (i = 0; i < ARRAY_SIZE(intel_dmi_quirks); i++) { |
| 13988 | if (dmi_check_system(*intel_dmi_quirks[i].dmi_id_list) != 0) |
| 13989 | intel_dmi_quirks[i].hook(dev); |
| 13990 | } |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 13991 | } |
| 13992 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13993 | /* Disable the VGA plane that we never use */ |
| 13994 | static void i915_disable_vga(struct drm_device *dev) |
| 13995 | { |
| 13996 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 13997 | u8 sr1; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 13998 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 13999 | |
Ville Syrjälä | 2b37c61 | 2014-01-22 21:32:38 +0200 | [diff] [blame] | 14000 | /* WaEnableVGAAccessThroughIOPort:ctg,elk,ilk,snb,ivb,vlv,hsw */ |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14001 | vga_get_uninterruptible(dev->pdev, VGA_RSRC_LEGACY_IO); |
Jesse Barnes | 3fdcf43 | 2012-04-06 11:46:27 -0700 | [diff] [blame] | 14002 | outb(SR01, VGA_SR_INDEX); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14003 | sr1 = inb(VGA_SR_DATA); |
| 14004 | outb(sr1 | 1<<5, VGA_SR_DATA); |
| 14005 | vga_put(dev->pdev, VGA_RSRC_LEGACY_IO); |
| 14006 | udelay(300); |
| 14007 | |
Ville Syrjälä | 01f5a62 | 2014-12-16 18:38:37 +0200 | [diff] [blame] | 14008 | I915_WRITE(vga_reg, VGA_DISP_DISABLE); |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14009 | POSTING_READ(vga_reg); |
| 14010 | } |
| 14011 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14012 | void intel_modeset_init_hw(struct drm_device *dev) |
| 14013 | { |
Eugeni Dodonov | a8f78b5 | 2012-06-28 15:55:35 -0300 | [diff] [blame] | 14014 | intel_prepare_ddi(dev); |
| 14015 | |
Ville Syrjälä | f8bf63f | 2014-06-13 13:37:54 +0300 | [diff] [blame] | 14016 | if (IS_VALLEYVIEW(dev)) |
| 14017 | vlv_update_cdclk(dev); |
| 14018 | |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14019 | intel_init_clock_gating(dev); |
| 14020 | |
Daniel Vetter | 8090c6b | 2012-06-24 16:42:32 +0200 | [diff] [blame] | 14021 | intel_enable_gt_powersave(dev); |
Daniel Vetter | f817586 | 2012-04-10 15:50:11 +0200 | [diff] [blame] | 14022 | } |
| 14023 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14024 | void intel_modeset_init(struct drm_device *dev) |
| 14025 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14026 | struct drm_i915_private *dev_priv = dev->dev_private; |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 14027 | int sprite, ret; |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 14028 | enum pipe pipe; |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14029 | struct intel_crtc *crtc; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14030 | |
| 14031 | drm_mode_config_init(dev); |
| 14032 | |
| 14033 | dev->mode_config.min_width = 0; |
| 14034 | dev->mode_config.min_height = 0; |
| 14035 | |
Dave Airlie | 019d96c | 2011-09-29 16:20:42 +0100 | [diff] [blame] | 14036 | dev->mode_config.preferred_depth = 24; |
| 14037 | dev->mode_config.prefer_shadow = 1; |
| 14038 | |
Tvrtko Ursulin | 25bab38 | 2015-02-10 17:16:16 +0000 | [diff] [blame] | 14039 | dev->mode_config.allow_fb_modifiers = true; |
| 14040 | |
Laurent Pinchart | e6ecefa | 2012-05-17 13:27:23 +0200 | [diff] [blame] | 14041 | dev->mode_config.funcs = &intel_mode_funcs; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14042 | |
Jesse Barnes | b690e96 | 2010-07-19 13:53:12 -0700 | [diff] [blame] | 14043 | intel_init_quirks(dev); |
| 14044 | |
Eugeni Dodonov | 1fa6110 | 2012-04-18 15:29:26 -0300 | [diff] [blame] | 14045 | intel_init_pm(dev); |
| 14046 | |
Ben Widawsky | e3c7475 | 2013-04-05 13:12:39 -0700 | [diff] [blame] | 14047 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 14048 | return; |
| 14049 | |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14050 | intel_init_display(dev); |
Jani Nikula | 7c10a2b | 2014-10-27 16:26:43 +0200 | [diff] [blame] | 14051 | intel_init_audio(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14052 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 14053 | if (IS_GEN2(dev)) { |
| 14054 | dev->mode_config.max_width = 2048; |
| 14055 | dev->mode_config.max_height = 2048; |
| 14056 | } else if (IS_GEN3(dev)) { |
Keith Packard | 5e4d6fa | 2009-07-12 23:53:17 -0700 | [diff] [blame] | 14057 | dev->mode_config.max_width = 4096; |
| 14058 | dev->mode_config.max_height = 4096; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14059 | } else { |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 14060 | dev->mode_config.max_width = 8192; |
| 14061 | dev->mode_config.max_height = 8192; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14062 | } |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 14063 | |
Ville Syrjälä | dc41c15 | 2014-08-13 11:57:05 +0300 | [diff] [blame] | 14064 | if (IS_845G(dev) || IS_I865G(dev)) { |
| 14065 | dev->mode_config.cursor_width = IS_845G(dev) ? 64 : 512; |
| 14066 | dev->mode_config.cursor_height = 1023; |
| 14067 | } else if (IS_GEN2(dev)) { |
Damien Lespiau | 068be56 | 2014-03-28 14:17:49 +0000 | [diff] [blame] | 14068 | dev->mode_config.cursor_width = GEN2_CURSOR_WIDTH; |
| 14069 | dev->mode_config.cursor_height = GEN2_CURSOR_HEIGHT; |
| 14070 | } else { |
| 14071 | dev->mode_config.cursor_width = MAX_CURSOR_WIDTH; |
| 14072 | dev->mode_config.cursor_height = MAX_CURSOR_HEIGHT; |
| 14073 | } |
| 14074 | |
Ben Widawsky | 5d4545a | 2013-01-17 12:45:15 -0800 | [diff] [blame] | 14075 | dev->mode_config.fb_base = dev_priv->gtt.mappable_base; |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14076 | |
Zhao Yakui | 28c9773 | 2009-10-09 11:39:41 +0800 | [diff] [blame] | 14077 | DRM_DEBUG_KMS("%d display pipe%s available.\n", |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 14078 | INTEL_INFO(dev)->num_pipes, |
| 14079 | INTEL_INFO(dev)->num_pipes > 1 ? "s" : ""); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14080 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14081 | for_each_pipe(dev_priv, pipe) { |
Damien Lespiau | 8cc87b7 | 2014-03-03 17:31:44 +0000 | [diff] [blame] | 14082 | intel_crtc_init(dev, pipe); |
Damien Lespiau | 3bdcfc0 | 2015-02-28 14:54:09 +0000 | [diff] [blame] | 14083 | for_each_sprite(dev_priv, pipe, sprite) { |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 14084 | ret = intel_plane_init(dev, pipe, sprite); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 14085 | if (ret) |
Ville Syrjälä | 06da8da | 2013-04-17 17:48:51 +0300 | [diff] [blame] | 14086 | DRM_DEBUG_KMS("pipe %c sprite %c init failed: %d\n", |
Damien Lespiau | 1fe4778 | 2014-03-03 17:31:47 +0000 | [diff] [blame] | 14087 | pipe_name(pipe), sprite_name(pipe, sprite), ret); |
Jesse Barnes | 7f1f385 | 2013-04-02 11:22:20 -0700 | [diff] [blame] | 14088 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14089 | } |
| 14090 | |
Jesse Barnes | f42bb70 | 2013-12-16 16:34:23 -0800 | [diff] [blame] | 14091 | intel_init_dpio(dev); |
| 14092 | |
Daniel Vetter | e72f9fb | 2013-06-05 13:34:06 +0200 | [diff] [blame] | 14093 | intel_shared_dpll_init(dev); |
Jesse Barnes | ee7b9f9 | 2012-04-20 17:11:53 +0100 | [diff] [blame] | 14094 | |
Jesse Barnes | 9cce37f | 2010-08-13 15:11:26 -0700 | [diff] [blame] | 14095 | /* Just disable it once at startup */ |
| 14096 | i915_disable_vga(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14097 | intel_setup_outputs(dev); |
Chris Wilson | 11be49e | 2012-11-15 11:32:20 +0000 | [diff] [blame] | 14098 | |
| 14099 | /* Just in case the BIOS is doing something questionable. */ |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 14100 | intel_fbc_disable(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 14101 | |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14102 | drm_modeset_lock_all(dev); |
Jesse Barnes | fa9fa08 | 2014-02-11 15:28:56 -0800 | [diff] [blame] | 14103 | intel_modeset_setup_hw_state(dev, false); |
Daniel Vetter | 6e9f798 | 2014-05-29 23:54:47 +0200 | [diff] [blame] | 14104 | drm_modeset_unlock_all(dev); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14105 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14106 | for_each_intel_crtc(dev, crtc) { |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14107 | if (!crtc->active) |
| 14108 | continue; |
| 14109 | |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14110 | /* |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14111 | * Note that reserving the BIOS fb up front prevents us |
| 14112 | * from stuffing other stolen allocations like the ring |
| 14113 | * on top. This prevents some ugliness at boot time, and |
| 14114 | * can even allow for smooth boot transitions if the BIOS |
| 14115 | * fb is large enough for the active pipe configuration. |
| 14116 | */ |
Damien Lespiau | 5724dbd | 2015-01-20 12:51:52 +0000 | [diff] [blame] | 14117 | if (dev_priv->display.get_initial_plane_config) { |
| 14118 | dev_priv->display.get_initial_plane_config(crtc, |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14119 | &crtc->plane_config); |
| 14120 | /* |
| 14121 | * If the fb is shared between multiple heads, we'll |
| 14122 | * just get the first one. |
| 14123 | */ |
Daniel Vetter | f6936e2 | 2015-03-26 12:17:05 +0100 | [diff] [blame] | 14124 | intel_find_initial_plane_obj(crtc, &crtc->plane_config); |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14125 | } |
Jesse Barnes | 46f297f | 2014-03-07 08:57:48 -0800 | [diff] [blame] | 14126 | } |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 14127 | } |
Jesse Barnes | d5bb081 | 2011-01-05 12:01:26 -0800 | [diff] [blame] | 14128 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14129 | static void intel_enable_pipe_a(struct drm_device *dev) |
| 14130 | { |
| 14131 | struct intel_connector *connector; |
| 14132 | struct drm_connector *crt = NULL; |
| 14133 | struct intel_load_detect_pipe load_detect_temp; |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 14134 | struct drm_modeset_acquire_ctx *ctx = dev->mode_config.acquire_ctx; |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14135 | |
| 14136 | /* We can't just switch on the pipe A, we need to set things up with a |
| 14137 | * proper mode and output configuration. As a gross hack, enable pipe A |
| 14138 | * by enabling the load detect pipe once. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14139 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14140 | if (connector->encoder->type == INTEL_OUTPUT_ANALOG) { |
| 14141 | crt = &connector->base; |
| 14142 | break; |
| 14143 | } |
| 14144 | } |
| 14145 | |
| 14146 | if (!crt) |
| 14147 | return; |
| 14148 | |
Ville Syrjälä | 208bf9f | 2014-08-11 13:15:35 +0300 | [diff] [blame] | 14149 | 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] | 14150 | intel_release_load_detect_pipe(crt, &load_detect_temp, ctx); |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14151 | } |
| 14152 | |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14153 | static bool |
| 14154 | intel_check_plane_mapping(struct intel_crtc *crtc) |
| 14155 | { |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 14156 | struct drm_device *dev = crtc->base.dev; |
| 14157 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14158 | u32 reg, val; |
| 14159 | |
Ben Widawsky | 7eb552a | 2013-03-13 14:05:41 -0700 | [diff] [blame] | 14160 | if (INTEL_INFO(dev)->num_pipes == 1) |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14161 | return true; |
| 14162 | |
| 14163 | reg = DSPCNTR(!crtc->plane); |
| 14164 | val = I915_READ(reg); |
| 14165 | |
| 14166 | if ((val & DISPLAY_PLANE_ENABLE) && |
| 14167 | (!!(val & DISPPLANE_SEL_PIPE_MASK) == crtc->pipe)) |
| 14168 | return false; |
| 14169 | |
| 14170 | return true; |
| 14171 | } |
| 14172 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14173 | static void intel_sanitize_crtc(struct intel_crtc *crtc) |
| 14174 | { |
| 14175 | struct drm_device *dev = crtc->base.dev; |
| 14176 | struct drm_i915_private *dev_priv = dev->dev_private; |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14177 | u32 reg; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14178 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14179 | /* 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] | 14180 | reg = PIPECONF(crtc->config->cpu_transcoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14181 | I915_WRITE(reg, I915_READ(reg) & ~PIPECONF_FRAME_START_DELAY_MASK); |
| 14182 | |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 14183 | /* restore vblank interrupts to correct state */ |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 14184 | drm_crtc_vblank_reset(&crtc->base); |
Ville Syrjälä | d297e10 | 2014-08-06 14:50:01 +0300 | [diff] [blame] | 14185 | if (crtc->active) { |
| 14186 | update_scanline_offset(crtc); |
Daniel Vetter | 9625604 | 2015-02-13 21:03:42 +0100 | [diff] [blame] | 14187 | drm_crtc_vblank_on(&crtc->base); |
| 14188 | } |
Ville Syrjälä | d3eaf88 | 2014-05-20 17:20:05 +0300 | [diff] [blame] | 14189 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14190 | /* We need to sanitize the plane -> pipe mapping first because this will |
Daniel Vetter | fa55583 | 2012-10-10 23:14:00 +0200 | [diff] [blame] | 14191 | * disable the crtc (and hence change the state) if it is wrong. Note |
| 14192 | * that gen4+ has a fixed plane -> pipe mapping. */ |
| 14193 | if (INTEL_INFO(dev)->gen < 4 && !intel_check_plane_mapping(crtc)) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14194 | struct intel_connector *connector; |
| 14195 | bool plane; |
| 14196 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14197 | DRM_DEBUG_KMS("[CRTC:%d] wrong plane connection detected!\n", |
| 14198 | crtc->base.base.id); |
| 14199 | |
| 14200 | /* Pipe has the wrong plane attached and the plane is active. |
| 14201 | * Temporarily change the plane mapping and disable everything |
| 14202 | * ... */ |
| 14203 | plane = crtc->plane; |
| 14204 | crtc->plane = !plane; |
Daniel Vetter | 9c8958b | 2014-07-14 19:35:31 +0200 | [diff] [blame] | 14205 | crtc->primary_enabled = true; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14206 | dev_priv->display.crtc_disable(&crtc->base); |
| 14207 | crtc->plane = plane; |
| 14208 | |
| 14209 | /* ... and break all links. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14210 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14211 | if (connector->encoder->base.crtc != &crtc->base) |
| 14212 | continue; |
| 14213 | |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14214 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 14215 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14216 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14217 | /* multiple connectors may have the same encoder: |
| 14218 | * handle them and break crtc link separately */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14219 | for_each_intel_connector(dev, connector) |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14220 | if (connector->encoder->base.crtc == &crtc->base) { |
| 14221 | connector->encoder->base.crtc = NULL; |
| 14222 | connector->encoder->connectors_active = false; |
| 14223 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14224 | |
| 14225 | WARN_ON(crtc->active); |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14226 | crtc->base.state->enable = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14227 | crtc->base.enabled = false; |
| 14228 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14229 | |
Daniel Vetter | 7fad798 | 2012-07-04 17:51:47 +0200 | [diff] [blame] | 14230 | if (dev_priv->quirks & QUIRK_PIPEA_FORCE && |
| 14231 | crtc->pipe == PIPE_A && !crtc->active) { |
| 14232 | /* BIOS forgot to enable pipe A, this mostly happens after |
| 14233 | * resume. Force-enable the pipe to fix this, the update_dpms |
| 14234 | * call below we restore the pipe to the right state, but leave |
| 14235 | * the required bits on. */ |
| 14236 | intel_enable_pipe_a(dev); |
| 14237 | } |
| 14238 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14239 | /* Adjust the state of the output pipe according to whether we |
| 14240 | * have active connectors/encoders. */ |
| 14241 | intel_crtc_update_dpms(&crtc->base); |
| 14242 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14243 | if (crtc->active != crtc->base.state->enable) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14244 | struct intel_encoder *encoder; |
| 14245 | |
| 14246 | /* This can happen either due to bugs in the get_hw_state |
| 14247 | * functions or because the pipe is force-enabled due to the |
| 14248 | * pipe A quirk. */ |
| 14249 | DRM_DEBUG_KMS("[CRTC:%d] hw state adjusted, was %s, now %s\n", |
| 14250 | crtc->base.base.id, |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14251 | crtc->base.state->enable ? "enabled" : "disabled", |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14252 | crtc->active ? "enabled" : "disabled"); |
| 14253 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14254 | crtc->base.state->enable = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14255 | crtc->base.enabled = crtc->active; |
| 14256 | |
| 14257 | /* Because we only establish the connector -> encoder -> |
| 14258 | * crtc links if something is active, this means the |
| 14259 | * crtc is now deactivated. Break the links. connector |
| 14260 | * -> encoder links are only establish when things are |
| 14261 | * actually up, hence no need to break them. */ |
| 14262 | WARN_ON(crtc->active); |
| 14263 | |
| 14264 | for_each_encoder_on_crtc(dev, &crtc->base, encoder) { |
| 14265 | WARN_ON(encoder->connectors_active); |
| 14266 | encoder->base.crtc = NULL; |
| 14267 | } |
| 14268 | } |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 14269 | |
Ville Syrjälä | a3ed6aa | 2014-09-03 14:09:52 +0300 | [diff] [blame] | 14270 | if (crtc->active || HAS_GMCH_DISPLAY(dev)) { |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 14271 | /* |
| 14272 | * We start out with underrun reporting disabled to avoid races. |
| 14273 | * For correct bookkeeping mark this on active crtcs. |
| 14274 | * |
Daniel Vetter | c5ab3bc | 2014-05-14 15:40:34 +0200 | [diff] [blame] | 14275 | * Also on gmch platforms we dont have any hardware bits to |
| 14276 | * disable the underrun reporting. Which means we need to start |
| 14277 | * out with underrun reporting disabled also on inactive pipes, |
| 14278 | * since otherwise we'll complain about the garbage we read when |
| 14279 | * e.g. coming up after runtime pm. |
| 14280 | * |
Daniel Vetter | 4cc3148 | 2014-03-24 00:01:41 +0100 | [diff] [blame] | 14281 | * No protection against concurrent access is required - at |
| 14282 | * worst a fifo underrun happens which also sets this to false. |
| 14283 | */ |
| 14284 | crtc->cpu_fifo_underrun_disabled = true; |
| 14285 | crtc->pch_fifo_underrun_disabled = true; |
| 14286 | } |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14287 | } |
| 14288 | |
| 14289 | static void intel_sanitize_encoder(struct intel_encoder *encoder) |
| 14290 | { |
| 14291 | struct intel_connector *connector; |
| 14292 | struct drm_device *dev = encoder->base.dev; |
| 14293 | |
| 14294 | /* We need to check both for a crtc link (meaning that the |
| 14295 | * encoder is active and trying to read from a pipe) and the |
| 14296 | * pipe itself being active. */ |
| 14297 | bool has_active_crtc = encoder->base.crtc && |
| 14298 | to_intel_crtc(encoder->base.crtc)->active; |
| 14299 | |
| 14300 | if (encoder->connectors_active && !has_active_crtc) { |
| 14301 | DRM_DEBUG_KMS("[ENCODER:%d:%s] has active connectors but no active pipe!\n", |
| 14302 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14303 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14304 | |
| 14305 | /* Connector is active, but has no active pipe. This is |
| 14306 | * fallout from our resume register restoring. Disable |
| 14307 | * the encoder manually again. */ |
| 14308 | if (encoder->base.crtc) { |
| 14309 | DRM_DEBUG_KMS("[ENCODER:%d:%s] manually disabled\n", |
| 14310 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14311 | encoder->base.name); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14312 | encoder->disable(encoder); |
Ville Syrjälä | a62d149 | 2014-06-28 02:04:01 +0300 | [diff] [blame] | 14313 | if (encoder->post_disable) |
| 14314 | encoder->post_disable(encoder); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14315 | } |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14316 | encoder->base.crtc = NULL; |
| 14317 | encoder->connectors_active = false; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14318 | |
| 14319 | /* Inconsistent output/port/pipe state happens presumably due to |
| 14320 | * a bug in one of the get_hw_state functions. Or someplace else |
| 14321 | * in our code, like the register restore mess on resume. Clamp |
| 14322 | * things to off as a safer default. */ |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14323 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14324 | if (connector->encoder != encoder) |
| 14325 | continue; |
Egbert Eich | 7f1950f | 2014-04-25 10:56:22 +0200 | [diff] [blame] | 14326 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 14327 | connector->base.encoder = NULL; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14328 | } |
| 14329 | } |
| 14330 | /* Enabled encoders without active connectors will be fixed in |
| 14331 | * the crtc fixup. */ |
| 14332 | } |
| 14333 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14334 | void i915_redisable_vga_power_on(struct drm_device *dev) |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14335 | { |
| 14336 | struct drm_i915_private *dev_priv = dev->dev_private; |
Ville Syrjälä | 766aa1c | 2013-01-25 21:44:46 +0200 | [diff] [blame] | 14337 | u32 vga_reg = i915_vgacntrl_reg(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14338 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14339 | if (!(I915_READ(vga_reg) & VGA_DISP_DISABLE)) { |
| 14340 | DRM_DEBUG_KMS("Something enabled VGA plane, disabling it\n"); |
| 14341 | i915_disable_vga(dev); |
| 14342 | } |
| 14343 | } |
| 14344 | |
| 14345 | void i915_redisable_vga(struct drm_device *dev) |
| 14346 | { |
| 14347 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14348 | |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 14349 | /* This function can be called both from intel_modeset_setup_hw_state or |
| 14350 | * at a very early point in our resume sequence, where the power well |
| 14351 | * structures are not yet restored. Since this function is at a very |
| 14352 | * paranoid "someone might have enabled VGA while we were not looking" |
| 14353 | * level, just check if the power well is enabled instead of trying to |
| 14354 | * follow the "don't touch the power well if we don't need it" policy |
| 14355 | * the rest of the driver uses. */ |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14356 | if (!intel_display_power_is_enabled(dev_priv, POWER_DOMAIN_VGA)) |
Paulo Zanoni | 8dc8a27 | 2013-08-02 16:22:24 -0300 | [diff] [blame] | 14357 | return; |
| 14358 | |
Imre Deak | 0409875 | 2014-02-18 00:02:16 +0200 | [diff] [blame] | 14359 | i915_redisable_vga_power_on(dev); |
Krzysztof Mazur | 0fde901 | 2012-12-19 11:03:41 +0100 | [diff] [blame] | 14360 | } |
| 14361 | |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 14362 | static bool primary_get_hw_state(struct intel_crtc *crtc) |
| 14363 | { |
| 14364 | struct drm_i915_private *dev_priv = crtc->base.dev->dev_private; |
| 14365 | |
| 14366 | if (!crtc->active) |
| 14367 | return false; |
| 14368 | |
| 14369 | return I915_READ(DSPCNTR(crtc->plane)) & DISPLAY_PLANE_ENABLE; |
| 14370 | } |
| 14371 | |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14372 | static void intel_modeset_readout_hw_state(struct drm_device *dev) |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14373 | { |
| 14374 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14375 | enum pipe pipe; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14376 | struct intel_crtc *crtc; |
| 14377 | struct intel_encoder *encoder; |
| 14378 | struct intel_connector *connector; |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14379 | int i; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14380 | |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14381 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14382 | memset(crtc->config, 0, sizeof(*crtc->config)); |
Daniel Vetter | 3b117c8 | 2013-04-17 20:15:07 +0200 | [diff] [blame] | 14383 | |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14384 | crtc->config->quirks |= PIPE_CONFIG_QUIRK_INHERITED_MODE; |
Daniel Vetter | 9953599 | 2014-04-13 12:00:33 +0200 | [diff] [blame] | 14385 | |
Daniel Vetter | 0e8ffe1 | 2013-03-28 10:42:00 +0100 | [diff] [blame] | 14386 | crtc->active = dev_priv->display.get_pipe_config(crtc, |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14387 | crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14388 | |
Matt Roper | 83d6573 | 2015-02-25 13:12:16 -0800 | [diff] [blame] | 14389 | crtc->base.state->enable = crtc->active; |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14390 | crtc->base.enabled = crtc->active; |
Ville Syrjälä | 98ec773 | 2014-04-30 17:43:01 +0300 | [diff] [blame] | 14391 | crtc->primary_enabled = primary_get_hw_state(crtc); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14392 | |
| 14393 | DRM_DEBUG_KMS("[CRTC:%d] hw state readout: %s\n", |
| 14394 | crtc->base.base.id, |
| 14395 | crtc->active ? "enabled" : "disabled"); |
| 14396 | } |
| 14397 | |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14398 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 14399 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 14400 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14401 | pll->on = pll->get_hw_state(dev_priv, pll, |
| 14402 | &pll->config.hw_state); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14403 | pll->active = 0; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14404 | pll->config.crtc_mask = 0; |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14405 | for_each_intel_crtc(dev, crtc) { |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 14406 | if (crtc->active && intel_crtc_to_shared_dpll(crtc) == pll) { |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14407 | pll->active++; |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14408 | pll->config.crtc_mask |= 1 << crtc->pipe; |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 14409 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14410 | } |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14411 | |
Ander Conselvan de Oliveira | 1e6f2dd | 2014-10-29 11:32:31 +0200 | [diff] [blame] | 14412 | 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] | 14413 | pll->name, pll->config.crtc_mask, pll->on); |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 14414 | |
Ander Conselvan de Oliveira | 3e369b7 | 2014-10-29 11:32:32 +0200 | [diff] [blame] | 14415 | if (pll->config.crtc_mask) |
Paulo Zanoni | bd2bb1b | 2014-07-04 11:27:38 -0300 | [diff] [blame] | 14416 | intel_display_power_get(dev_priv, POWER_DOMAIN_PLLS); |
Daniel Vetter | 5358901 | 2013-06-05 13:34:16 +0200 | [diff] [blame] | 14417 | } |
| 14418 | |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14419 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14420 | pipe = 0; |
| 14421 | |
| 14422 | if (encoder->get_hw_state(encoder, &pipe)) { |
Jesse Barnes | 045ac3b | 2013-05-14 17:08:26 -0700 | [diff] [blame] | 14423 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 14424 | encoder->base.crtc = &crtc->base; |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14425 | encoder->get_config(encoder, crtc->config); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14426 | } else { |
| 14427 | encoder->base.crtc = NULL; |
| 14428 | } |
| 14429 | |
| 14430 | encoder->connectors_active = false; |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 14431 | 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] | 14432 | encoder->base.base.id, |
Jani Nikula | 8e329a03 | 2014-06-03 14:56:21 +0300 | [diff] [blame] | 14433 | encoder->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14434 | encoder->base.crtc ? "enabled" : "disabled", |
Damien Lespiau | 6f2bcce | 2013-10-16 12:29:54 +0100 | [diff] [blame] | 14435 | pipe_name(pipe)); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14436 | } |
| 14437 | |
Ander Conselvan de Oliveira | 3a3371f | 2015-03-03 15:21:56 +0200 | [diff] [blame] | 14438 | for_each_intel_connector(dev, connector) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14439 | if (connector->get_hw_state(connector)) { |
| 14440 | connector->base.dpms = DRM_MODE_DPMS_ON; |
| 14441 | connector->encoder->connectors_active = true; |
| 14442 | connector->base.encoder = &connector->encoder->base; |
| 14443 | } else { |
| 14444 | connector->base.dpms = DRM_MODE_DPMS_OFF; |
| 14445 | connector->base.encoder = NULL; |
| 14446 | } |
| 14447 | DRM_DEBUG_KMS("[CONNECTOR:%d:%s] hw state readout: %s\n", |
| 14448 | connector->base.base.id, |
Jani Nikula | c23cc41 | 2014-06-03 14:56:17 +0300 | [diff] [blame] | 14449 | connector->base.name, |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14450 | connector->base.encoder ? "enabled" : "disabled"); |
| 14451 | } |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14452 | } |
| 14453 | |
| 14454 | /* Scan out the current hw modeset state, sanitizes it and maps it into the drm |
| 14455 | * and i915 state tracking structures. */ |
| 14456 | void intel_modeset_setup_hw_state(struct drm_device *dev, |
| 14457 | bool force_restore) |
| 14458 | { |
| 14459 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 14460 | enum pipe pipe; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14461 | struct intel_crtc *crtc; |
| 14462 | struct intel_encoder *encoder; |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 14463 | int i; |
Daniel Vetter | 30e984d | 2013-06-05 13:34:17 +0200 | [diff] [blame] | 14464 | |
| 14465 | intel_modeset_readout_hw_state(dev); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14466 | |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 14467 | /* |
| 14468 | * Now that we have the config, copy it to each CRTC struct |
| 14469 | * Note that this could go away if we move to using crtc_config |
| 14470 | * checking everywhere. |
| 14471 | */ |
Damien Lespiau | d3fcc80 | 2014-05-13 23:32:22 +0100 | [diff] [blame] | 14472 | for_each_intel_crtc(dev, crtc) { |
Jani Nikula | d330a95 | 2014-01-21 11:24:25 +0200 | [diff] [blame] | 14473 | if (crtc->active && i915.fastboot) { |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14474 | intel_mode_from_pipe_config(&crtc->base.mode, |
| 14475 | crtc->config); |
Jesse Barnes | babea61 | 2013-06-26 18:57:38 +0300 | [diff] [blame] | 14476 | DRM_DEBUG_KMS("[CRTC:%d] found active mode: ", |
| 14477 | crtc->base.base.id); |
| 14478 | drm_mode_debug_printmodeline(&crtc->base.mode); |
| 14479 | } |
| 14480 | } |
| 14481 | |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14482 | /* HW state is read out, now we need to sanitize this mess. */ |
Damien Lespiau | b2784e1 | 2014-08-05 11:29:37 +0100 | [diff] [blame] | 14483 | for_each_intel_encoder(dev, encoder) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14484 | intel_sanitize_encoder(encoder); |
| 14485 | } |
| 14486 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14487 | for_each_pipe(dev_priv, pipe) { |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14488 | crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]); |
| 14489 | intel_sanitize_crtc(crtc); |
Ander Conselvan de Oliveira | 6e3c971 | 2015-01-15 14:55:25 +0200 | [diff] [blame] | 14490 | intel_dump_pipe_config(crtc, crtc->config, |
| 14491 | "[setup_hw_state]"); |
Daniel Vetter | 2492935 | 2012-07-02 20:28:59 +0200 | [diff] [blame] | 14492 | } |
Daniel Vetter | 9a93585 | 2012-07-05 22:34:27 +0200 | [diff] [blame] | 14493 | |
Ander Conselvan de Oliveira | d29b2f9 | 2015-03-20 16:18:05 +0200 | [diff] [blame] | 14494 | intel_modeset_update_connector_atomic_state(dev); |
| 14495 | |
Daniel Vetter | 35c9537 | 2013-07-17 06:55:04 +0200 | [diff] [blame] | 14496 | for (i = 0; i < dev_priv->num_shared_dpll; i++) { |
| 14497 | struct intel_shared_dpll *pll = &dev_priv->shared_dplls[i]; |
| 14498 | |
| 14499 | if (!pll->on || pll->active) |
| 14500 | continue; |
| 14501 | |
| 14502 | DRM_DEBUG_KMS("%s enabled but not in use, disabling\n", pll->name); |
| 14503 | |
| 14504 | pll->disable(dev_priv, pll); |
| 14505 | pll->on = false; |
| 14506 | } |
| 14507 | |
Pradeep Bhat | 3078999 | 2014-11-04 17:06:45 +0000 | [diff] [blame] | 14508 | if (IS_GEN9(dev)) |
| 14509 | skl_wm_get_hw_state(dev); |
| 14510 | else if (HAS_PCH_SPLIT(dev)) |
Ville Syrjälä | 243e6a4 | 2013-10-14 14:55:24 +0300 | [diff] [blame] | 14511 | ilk_wm_get_hw_state(dev); |
| 14512 | |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 14513 | if (force_restore) { |
Ville Syrjälä | 7d0bc1e | 2013-09-16 17:38:33 +0300 | [diff] [blame] | 14514 | i915_redisable_vga(dev); |
| 14515 | |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 14516 | /* |
| 14517 | * We need to use raw interfaces for restoring state to avoid |
| 14518 | * checking (bogus) intermediate states. |
| 14519 | */ |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14520 | for_each_pipe(dev_priv, pipe) { |
Jesse Barnes | b5644d0 | 2013-03-26 13:25:27 -0700 | [diff] [blame] | 14521 | struct drm_crtc *crtc = |
| 14522 | dev_priv->pipe_to_crtc_mapping[pipe]; |
Daniel Vetter | f30da18 | 2013-04-11 20:22:50 +0200 | [diff] [blame] | 14523 | |
Ander Conselvan de Oliveira | 83a5715 | 2015-03-20 16:18:03 +0200 | [diff] [blame] | 14524 | intel_crtc_restore_mode(crtc); |
Daniel Vetter | 45e2b5f | 2012-11-23 18:16:34 +0100 | [diff] [blame] | 14525 | } |
| 14526 | } else { |
| 14527 | intel_modeset_update_staged_output_state(dev); |
| 14528 | } |
Daniel Vetter | 8af6cf8 | 2012-07-10 09:50:11 +0200 | [diff] [blame] | 14529 | |
| 14530 | intel_modeset_check_state(dev); |
Chris Wilson | 2c7111d | 2011-03-29 10:40:27 +0100 | [diff] [blame] | 14531 | } |
| 14532 | |
| 14533 | void intel_modeset_gem_init(struct drm_device *dev) |
| 14534 | { |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 14535 | struct drm_i915_private *dev_priv = dev->dev_private; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14536 | struct drm_crtc *c; |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 14537 | struct drm_i915_gem_object *obj; |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14538 | |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 14539 | mutex_lock(&dev->struct_mutex); |
| 14540 | intel_init_gt_powersave(dev); |
| 14541 | mutex_unlock(&dev->struct_mutex); |
| 14542 | |
Jesse Barnes | 9212278 | 2014-10-09 12:57:42 -0700 | [diff] [blame] | 14543 | /* |
| 14544 | * There may be no VBT; and if the BIOS enabled SSC we can |
| 14545 | * just keep using it to avoid unnecessary flicker. Whereas if the |
| 14546 | * BIOS isn't using it, don't assume it will work even if the VBT |
| 14547 | * indicates as much. |
| 14548 | */ |
| 14549 | if (HAS_PCH_IBX(dev) || HAS_PCH_CPT(dev)) |
| 14550 | dev_priv->vbt.lvds_use_ssc = !!(I915_READ(PCH_DREF_CONTROL) & |
| 14551 | DREF_SSC1_ENABLE); |
| 14552 | |
Chris Wilson | 1833b13 | 2012-05-09 11:56:28 +0100 | [diff] [blame] | 14553 | intel_modeset_init_hw(dev); |
Daniel Vetter | 02e792f | 2009-09-15 22:57:34 +0200 | [diff] [blame] | 14554 | |
| 14555 | intel_setup_overlay(dev); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14556 | |
| 14557 | /* |
| 14558 | * Make sure any fbs we allocated at startup are properly |
| 14559 | * pinned & fenced. When we do the allocation it's too early |
| 14560 | * for this. |
| 14561 | */ |
| 14562 | mutex_lock(&dev->struct_mutex); |
Damien Lespiau | 70e1e0e | 2014-05-13 23:32:24 +0100 | [diff] [blame] | 14563 | for_each_crtc(dev, c) { |
Matt Roper | 2ff8fde | 2014-07-08 07:50:07 -0700 | [diff] [blame] | 14564 | obj = intel_fb_obj(c->primary->fb); |
| 14565 | if (obj == NULL) |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14566 | continue; |
| 14567 | |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 14568 | if (intel_pin_and_fence_fb_obj(c->primary, |
| 14569 | c->primary->fb, |
Tvrtko Ursulin | 82bc3b2 | 2015-03-23 11:10:34 +0000 | [diff] [blame] | 14570 | c->primary->state, |
Tvrtko Ursulin | 850c4cd | 2014-10-30 16:39:38 +0000 | [diff] [blame] | 14571 | NULL)) { |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14572 | DRM_ERROR("failed to pin boot fb on pipe %d\n", |
| 14573 | to_intel_crtc(c)->pipe); |
Dave Airlie | 66e514c | 2014-04-03 07:51:54 +1000 | [diff] [blame] | 14574 | drm_framebuffer_unreference(c->primary->fb); |
| 14575 | c->primary->fb = NULL; |
Matt Roper | afd65eb | 2015-02-03 13:10:04 -0800 | [diff] [blame] | 14576 | update_state_fb(c->primary); |
Jesse Barnes | 484b41d | 2014-03-07 08:57:55 -0800 | [diff] [blame] | 14577 | } |
| 14578 | } |
| 14579 | mutex_unlock(&dev->struct_mutex); |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 14580 | |
| 14581 | intel_backlight_register(dev); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14582 | } |
| 14583 | |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 14584 | void intel_connector_unregister(struct intel_connector *intel_connector) |
| 14585 | { |
| 14586 | struct drm_connector *connector = &intel_connector->base; |
| 14587 | |
| 14588 | intel_panel_destroy_backlight(connector); |
Thomas Wood | 34ea3d3 | 2014-05-29 16:57:41 +0100 | [diff] [blame] | 14589 | drm_connector_unregister(connector); |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 14590 | } |
| 14591 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14592 | void intel_modeset_cleanup(struct drm_device *dev) |
| 14593 | { |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14594 | struct drm_i915_private *dev_priv = dev->dev_private; |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 14595 | struct drm_connector *connector; |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14596 | |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 14597 | intel_disable_gt_powersave(dev); |
| 14598 | |
Ville Syrjälä | 0962c3c | 2014-11-07 15:19:46 +0200 | [diff] [blame] | 14599 | intel_backlight_unregister(dev); |
| 14600 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14601 | /* |
| 14602 | * Interrupts and polling as the first thing to avoid creating havoc. |
Imre Deak | 2eb5252 | 2014-11-19 15:30:05 +0200 | [diff] [blame] | 14603 | * Too much stuff here (turning of connectors, ...) would |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14604 | * experience fancy races otherwise. |
| 14605 | */ |
Daniel Vetter | 2aeb7d3 | 2014-09-30 10:56:43 +0200 | [diff] [blame] | 14606 | intel_irq_uninstall(dev_priv); |
Jesse Barnes | eb21b92 | 2014-06-20 11:57:33 -0700 | [diff] [blame] | 14607 | |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14608 | /* |
| 14609 | * Due to the hpd irq storm handling the hotplug work can re-arm the |
| 14610 | * poll handlers. Hence disable polling after hpd handling is shut down. |
| 14611 | */ |
Keith Packard | f87ea76 | 2010-10-03 19:36:26 -0700 | [diff] [blame] | 14612 | drm_kms_helper_poll_fini(dev); |
Daniel Vetter | fd0c064 | 2013-04-24 11:13:35 +0200 | [diff] [blame] | 14613 | |
Jesse Barnes | 652c393 | 2009-08-17 13:31:43 -0700 | [diff] [blame] | 14614 | mutex_lock(&dev->struct_mutex); |
| 14615 | |
Jesse Barnes | 723bfd7 | 2010-10-07 16:01:13 -0700 | [diff] [blame] | 14616 | intel_unregister_dsm_handler(); |
| 14617 | |
Rodrigo Vivi | 7ff0ebc | 2014-12-08 14:09:10 -0200 | [diff] [blame] | 14618 | intel_fbc_disable(dev); |
Jesse Barnes | e70236a | 2009-09-21 10:42:27 -0700 | [diff] [blame] | 14619 | |
Kristian Høgsberg | 69341a5 | 2009-11-11 12:19:17 -0500 | [diff] [blame] | 14620 | mutex_unlock(&dev->struct_mutex); |
| 14621 | |
Chris Wilson | 1630fe7 | 2011-07-08 12:22:42 +0100 | [diff] [blame] | 14622 | /* flush any delayed tasks or pending work */ |
| 14623 | flush_scheduled_work(); |
| 14624 | |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 14625 | /* destroy the backlight and sysfs files before encoders/connectors */ |
| 14626 | list_for_each_entry(connector, &dev->mode_config.connector_list, head) { |
Imre Deak | 4932e2c | 2014-02-11 17:12:48 +0200 | [diff] [blame] | 14627 | struct intel_connector *intel_connector; |
| 14628 | |
| 14629 | intel_connector = to_intel_connector(connector); |
| 14630 | intel_connector->unregister(intel_connector); |
Jani Nikula | db31af1d | 2013-11-08 16:48:53 +0200 | [diff] [blame] | 14631 | } |
Paulo Zanoni | d9255d5 | 2013-09-26 20:05:59 -0300 | [diff] [blame] | 14632 | |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14633 | drm_mode_config_cleanup(dev); |
Daniel Vetter | 4d7bb01 | 2012-12-18 15:24:37 +0100 | [diff] [blame] | 14634 | |
| 14635 | intel_cleanup_overlay(dev); |
Imre Deak | ae48434 | 2014-03-31 15:10:44 +0300 | [diff] [blame] | 14636 | |
| 14637 | mutex_lock(&dev->struct_mutex); |
| 14638 | intel_cleanup_gt_powersave(dev); |
| 14639 | mutex_unlock(&dev->struct_mutex); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14640 | } |
| 14641 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14642 | /* |
Zhenyu Wang | f1c79df | 2010-03-30 14:39:29 +0800 | [diff] [blame] | 14643 | * Return which encoder is currently attached for connector. |
| 14644 | */ |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 14645 | struct drm_encoder *intel_best_encoder(struct drm_connector *connector) |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14646 | { |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 14647 | return &intel_attached_encoder(connector)->base; |
| 14648 | } |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14649 | |
Chris Wilson | df0e924 | 2010-09-09 16:20:55 +0100 | [diff] [blame] | 14650 | void intel_connector_attach_encoder(struct intel_connector *connector, |
| 14651 | struct intel_encoder *encoder) |
| 14652 | { |
| 14653 | connector->encoder = encoder; |
| 14654 | drm_mode_connector_attach_encoder(&connector->base, |
| 14655 | &encoder->base); |
Jesse Barnes | 79e5394 | 2008-11-07 14:24:08 -0800 | [diff] [blame] | 14656 | } |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14657 | |
| 14658 | /* |
| 14659 | * set vga decode state - true == enable VGA decode |
| 14660 | */ |
| 14661 | int intel_modeset_vga_set_state(struct drm_device *dev, bool state) |
| 14662 | { |
| 14663 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | a885b3c | 2013-12-17 14:34:50 +0000 | [diff] [blame] | 14664 | 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] | 14665 | u16 gmch_ctrl; |
| 14666 | |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 14667 | if (pci_read_config_word(dev_priv->bridge_dev, reg, &gmch_ctrl)) { |
| 14668 | DRM_ERROR("failed to read control word\n"); |
| 14669 | return -EIO; |
| 14670 | } |
| 14671 | |
Chris Wilson | c0cc8a5 | 2014-02-07 18:37:03 -0200 | [diff] [blame] | 14672 | if (!!(gmch_ctrl & INTEL_GMCH_VGA_DISABLE) == !state) |
| 14673 | return 0; |
| 14674 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14675 | if (state) |
| 14676 | gmch_ctrl &= ~INTEL_GMCH_VGA_DISABLE; |
| 14677 | else |
| 14678 | gmch_ctrl |= INTEL_GMCH_VGA_DISABLE; |
Chris Wilson | 75fa041 | 2014-02-07 18:37:02 -0200 | [diff] [blame] | 14679 | |
| 14680 | if (pci_write_config_word(dev_priv->bridge_dev, reg, gmch_ctrl)) { |
| 14681 | DRM_ERROR("failed to write control word\n"); |
| 14682 | return -EIO; |
| 14683 | } |
| 14684 | |
Dave Airlie | 28d5204 | 2009-09-21 14:33:58 +1000 | [diff] [blame] | 14685 | return 0; |
| 14686 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14687 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14688 | struct intel_display_error_state { |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 14689 | |
| 14690 | u32 power_well_driver; |
| 14691 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14692 | int num_transcoders; |
| 14693 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14694 | struct intel_cursor_error_state { |
| 14695 | u32 control; |
| 14696 | u32 position; |
| 14697 | u32 base; |
| 14698 | u32 size; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 14699 | } cursor[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14700 | |
| 14701 | struct intel_pipe_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14702 | bool power_domain_on; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14703 | u32 source; |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14704 | u32 stat; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 14705 | } pipe[I915_MAX_PIPES]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14706 | |
| 14707 | struct intel_plane_error_state { |
| 14708 | u32 control; |
| 14709 | u32 stride; |
| 14710 | u32 size; |
| 14711 | u32 pos; |
| 14712 | u32 addr; |
| 14713 | u32 surface; |
| 14714 | u32 tile_offset; |
Damien Lespiau | 5233130 | 2012-08-15 19:23:25 +0100 | [diff] [blame] | 14715 | } plane[I915_MAX_PIPES]; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14716 | |
| 14717 | struct intel_transcoder_error_state { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14718 | bool power_domain_on; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14719 | enum transcoder cpu_transcoder; |
| 14720 | |
| 14721 | u32 conf; |
| 14722 | |
| 14723 | u32 htotal; |
| 14724 | u32 hblank; |
| 14725 | u32 hsync; |
| 14726 | u32 vtotal; |
| 14727 | u32 vblank; |
| 14728 | u32 vsync; |
| 14729 | } transcoder[4]; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14730 | }; |
| 14731 | |
| 14732 | struct intel_display_error_state * |
| 14733 | intel_display_capture_error_state(struct drm_device *dev) |
| 14734 | { |
Jani Nikula | fbee40d | 2014-03-31 14:27:18 +0300 | [diff] [blame] | 14735 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14736 | struct intel_display_error_state *error; |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14737 | int transcoders[] = { |
| 14738 | TRANSCODER_A, |
| 14739 | TRANSCODER_B, |
| 14740 | TRANSCODER_C, |
| 14741 | TRANSCODER_EDP, |
| 14742 | }; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14743 | int i; |
| 14744 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14745 | if (INTEL_INFO(dev)->num_pipes == 0) |
| 14746 | return NULL; |
| 14747 | |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 14748 | error = kzalloc(sizeof(*error), GFP_ATOMIC); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14749 | if (error == NULL) |
| 14750 | return NULL; |
| 14751 | |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 14752 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 14753 | error->power_well_driver = I915_READ(HSW_PWR_WELL_DRIVER); |
| 14754 | |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14755 | for_each_pipe(dev_priv, i) { |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14756 | error->pipe[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14757 | __intel_display_power_is_enabled(dev_priv, |
| 14758 | POWER_DOMAIN_PIPE(i)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14759 | if (!error->pipe[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 14760 | continue; |
| 14761 | |
Ville Syrjälä | 5efb3e2 | 2014-04-09 13:28:53 +0300 | [diff] [blame] | 14762 | error->cursor[i].control = I915_READ(CURCNTR(i)); |
| 14763 | error->cursor[i].position = I915_READ(CURPOS(i)); |
| 14764 | error->cursor[i].base = I915_READ(CURBASE(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14765 | |
| 14766 | error->plane[i].control = I915_READ(DSPCNTR(i)); |
| 14767 | error->plane[i].stride = I915_READ(DSPSTRIDE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14768 | if (INTEL_INFO(dev)->gen <= 3) { |
Paulo Zanoni | 51889b3 | 2013-03-06 20:03:13 -0300 | [diff] [blame] | 14769 | error->plane[i].size = I915_READ(DSPSIZE(i)); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14770 | error->plane[i].pos = I915_READ(DSPPOS(i)); |
| 14771 | } |
Paulo Zanoni | ca29136 | 2013-03-06 20:03:14 -0300 | [diff] [blame] | 14772 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
| 14773 | error->plane[i].addr = I915_READ(DSPADDR(i)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14774 | if (INTEL_INFO(dev)->gen >= 4) { |
| 14775 | error->plane[i].surface = I915_READ(DSPSURF(i)); |
| 14776 | error->plane[i].tile_offset = I915_READ(DSPTILEOFF(i)); |
| 14777 | } |
| 14778 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14779 | error->pipe[i].source = I915_READ(PIPESRC(i)); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14780 | |
Sonika Jindal | 3abfce7 | 2014-07-21 15:23:43 +0530 | [diff] [blame] | 14781 | if (HAS_GMCH_DISPLAY(dev)) |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14782 | error->pipe[i].stat = I915_READ(PIPESTAT(i)); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14783 | } |
| 14784 | |
| 14785 | error->num_transcoders = INTEL_INFO(dev)->num_pipes; |
| 14786 | if (HAS_DDI(dev_priv->dev)) |
| 14787 | error->num_transcoders++; /* Account for eDP. */ |
| 14788 | |
| 14789 | for (i = 0; i < error->num_transcoders; i++) { |
| 14790 | enum transcoder cpu_transcoder = transcoders[i]; |
| 14791 | |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14792 | error->transcoder[i].power_domain_on = |
Daniel Vetter | f458ebb | 2014-09-30 10:56:39 +0200 | [diff] [blame] | 14793 | __intel_display_power_is_enabled(dev_priv, |
Paulo Zanoni | 38cc1da | 2013-12-20 15:09:41 -0200 | [diff] [blame] | 14794 | POWER_DOMAIN_TRANSCODER(cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14795 | if (!error->transcoder[i].power_domain_on) |
Paulo Zanoni | 9d1cb91 | 2013-11-01 13:32:08 -0200 | [diff] [blame] | 14796 | continue; |
| 14797 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14798 | error->transcoder[i].cpu_transcoder = cpu_transcoder; |
| 14799 | |
| 14800 | error->transcoder[i].conf = I915_READ(PIPECONF(cpu_transcoder)); |
| 14801 | error->transcoder[i].htotal = I915_READ(HTOTAL(cpu_transcoder)); |
| 14802 | error->transcoder[i].hblank = I915_READ(HBLANK(cpu_transcoder)); |
| 14803 | error->transcoder[i].hsync = I915_READ(HSYNC(cpu_transcoder)); |
| 14804 | error->transcoder[i].vtotal = I915_READ(VTOTAL(cpu_transcoder)); |
| 14805 | error->transcoder[i].vblank = I915_READ(VBLANK(cpu_transcoder)); |
| 14806 | error->transcoder[i].vsync = I915_READ(VSYNC(cpu_transcoder)); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14807 | } |
| 14808 | |
| 14809 | return error; |
| 14810 | } |
| 14811 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14812 | #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__) |
| 14813 | |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14814 | void |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14815 | intel_display_print_error_state(struct drm_i915_error_state_buf *m, |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14816 | struct drm_device *dev, |
| 14817 | struct intel_display_error_state *error) |
| 14818 | { |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14819 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14820 | int i; |
| 14821 | |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14822 | if (!error) |
| 14823 | return; |
| 14824 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14825 | err_printf(m, "Num Pipes: %d\n", INTEL_INFO(dev)->num_pipes); |
Imre Deak | 190be11 | 2013-11-25 17:15:31 +0200 | [diff] [blame] | 14826 | if (IS_HASWELL(dev) || IS_BROADWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14827 | err_printf(m, "PWR_WELL_CTL2: %08x\n", |
Paulo Zanoni | ff57f1b | 2013-05-03 12:15:37 -0300 | [diff] [blame] | 14828 | error->power_well_driver); |
Damien Lespiau | 055e393 | 2014-08-18 13:49:10 +0100 | [diff] [blame] | 14829 | for_each_pipe(dev_priv, i) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14830 | err_printf(m, "Pipe [%d]:\n", i); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14831 | err_printf(m, " Power: %s\n", |
| 14832 | error->pipe[i].power_domain_on ? "on" : "off"); |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14833 | err_printf(m, " SRC: %08x\n", error->pipe[i].source); |
Imre Deak | f301b1e | 2014-04-18 15:55:04 +0300 | [diff] [blame] | 14834 | err_printf(m, " STAT: %08x\n", error->pipe[i].stat); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14835 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14836 | err_printf(m, "Plane [%d]:\n", i); |
| 14837 | err_printf(m, " CNTR: %08x\n", error->plane[i].control); |
| 14838 | err_printf(m, " STRIDE: %08x\n", error->plane[i].stride); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14839 | if (INTEL_INFO(dev)->gen <= 3) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14840 | err_printf(m, " SIZE: %08x\n", error->plane[i].size); |
| 14841 | err_printf(m, " POS: %08x\n", error->plane[i].pos); |
Paulo Zanoni | 80ca378 | 2013-03-22 14:20:57 -0300 | [diff] [blame] | 14842 | } |
Paulo Zanoni | 4b71a57 | 2013-03-22 14:19:21 -0300 | [diff] [blame] | 14843 | if (INTEL_INFO(dev)->gen <= 7 && !IS_HASWELL(dev)) |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14844 | err_printf(m, " ADDR: %08x\n", error->plane[i].addr); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14845 | if (INTEL_INFO(dev)->gen >= 4) { |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14846 | err_printf(m, " SURF: %08x\n", error->plane[i].surface); |
| 14847 | err_printf(m, " TILEOFF: %08x\n", error->plane[i].tile_offset); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14848 | } |
| 14849 | |
Mika Kuoppala | edc3d88 | 2013-05-23 13:55:35 +0300 | [diff] [blame] | 14850 | err_printf(m, "Cursor [%d]:\n", i); |
| 14851 | err_printf(m, " CNTR: %08x\n", error->cursor[i].control); |
| 14852 | err_printf(m, " POS: %08x\n", error->cursor[i].position); |
| 14853 | err_printf(m, " BASE: %08x\n", error->cursor[i].base); |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14854 | } |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14855 | |
| 14856 | for (i = 0; i < error->num_transcoders; i++) { |
Chris Wilson | 1cf84bb | 2013-10-21 09:10:33 +0100 | [diff] [blame] | 14857 | err_printf(m, "CPU transcoder: %c\n", |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14858 | transcoder_name(error->transcoder[i].cpu_transcoder)); |
Imre Deak | ddf9c53 | 2013-11-27 22:02:02 +0200 | [diff] [blame] | 14859 | err_printf(m, " Power: %s\n", |
| 14860 | error->transcoder[i].power_domain_on ? "on" : "off"); |
Chris Wilson | 63b66e5 | 2013-08-08 15:12:06 +0200 | [diff] [blame] | 14861 | err_printf(m, " CONF: %08x\n", error->transcoder[i].conf); |
| 14862 | err_printf(m, " HTOTAL: %08x\n", error->transcoder[i].htotal); |
| 14863 | err_printf(m, " HBLANK: %08x\n", error->transcoder[i].hblank); |
| 14864 | err_printf(m, " HSYNC: %08x\n", error->transcoder[i].hsync); |
| 14865 | err_printf(m, " VTOTAL: %08x\n", error->transcoder[i].vtotal); |
| 14866 | err_printf(m, " VBLANK: %08x\n", error->transcoder[i].vblank); |
| 14867 | err_printf(m, " VSYNC: %08x\n", error->transcoder[i].vsync); |
| 14868 | } |
Chris Wilson | c4a1d9e | 2010-11-21 13:12:35 +0000 | [diff] [blame] | 14869 | } |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14870 | |
| 14871 | void intel_modeset_preclose(struct drm_device *dev, struct drm_file *file) |
| 14872 | { |
| 14873 | struct intel_crtc *crtc; |
| 14874 | |
| 14875 | for_each_intel_crtc(dev, crtc) { |
| 14876 | struct intel_unpin_work *work; |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14877 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 14878 | spin_lock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14879 | |
| 14880 | work = crtc->unpin_work; |
| 14881 | |
| 14882 | if (work && work->event && |
| 14883 | work->event->base.file_priv == file) { |
| 14884 | kfree(work->event); |
| 14885 | work->event = NULL; |
| 14886 | } |
| 14887 | |
Daniel Vetter | 5e2d7af | 2014-09-15 14:55:22 +0200 | [diff] [blame] | 14888 | spin_unlock_irq(&dev->event_lock); |
Ville Syrjälä | e2fcdaa | 2014-08-06 14:02:51 +0300 | [diff] [blame] | 14889 | } |
| 14890 | } |